Changeset 388 for python/vendor/current/Doc/c-api
- Timestamp:
- Mar 19, 2014, 11:11:30 AM (11 years ago)
- Location:
- python/vendor/current/Doc/c-api
- Files:
-
- 3 added
- 54 edited
Legend:
- Unmodified
- Added
- Removed
-
python/vendor/current/Doc/c-api/abstract.rst
r2 r388 14 14 15 15 It is not possible to use these functions on objects that are not properly 16 initialized, such as a list object that has been created by :c func:`PyList_New`,16 initialized, such as a list object that has been created by :c:func:`PyList_New`, 17 17 but whose items have not been set to some non-\ ``NULL`` value yet. 18 18 -
python/vendor/current/Doc/c-api/allocation.rst
r2 r388 7 7 8 8 9 .. c function:: PyObject* _PyObject_New(PyTypeObject *type)9 .. c:function:: PyObject* _PyObject_New(PyTypeObject *type) 10 10 11 11 12 .. c function:: PyVarObject* _PyObject_NewVar(PyTypeObject *type, Py_ssize_t size)12 .. c:function:: PyVarObject* _PyObject_NewVar(PyTypeObject *type, Py_ssize_t size) 13 13 14 14 .. versionchanged:: 2.5 15 This function used an :c type:`int` type for *size*. This might require15 This function used an :c:type:`int` type for *size*. This might require 16 16 changes in your code for properly supporting 64-bit systems. 17 17 18 18 19 .. c function:: void _PyObject_Del(PyObject *op)19 .. c:function:: void _PyObject_Del(PyObject *op) 20 20 21 21 22 .. c function:: PyObject* PyObject_Init(PyObject *op, PyTypeObject *type)22 .. c:function:: PyObject* PyObject_Init(PyObject *op, PyTypeObject *type) 23 23 24 24 Initialize a newly-allocated object *op* with its type and initial … … 29 29 30 30 31 .. c function:: PyVarObject* PyObject_InitVar(PyVarObject *op, PyTypeObject *type, Py_ssize_t size)31 .. c:function:: PyVarObject* PyObject_InitVar(PyVarObject *op, PyTypeObject *type, Py_ssize_t size) 32 32 33 This does everything :c func:`PyObject_Init` does, and also initializes the33 This does everything :c:func:`PyObject_Init` does, and also initializes the 34 34 length information for a variable-size object. 35 35 36 36 .. versionchanged:: 2.5 37 This function used an :c type:`int` type for *size*. This might require37 This function used an :c:type:`int` type for *size*. This might require 38 38 changes in your code for properly supporting 64-bit systems. 39 39 40 40 41 .. c function:: TYPE* PyObject_New(TYPE, PyTypeObject *type)41 .. c:function:: TYPE* PyObject_New(TYPE, PyTypeObject *type) 42 42 43 43 Allocate a new Python object using the C structure type *TYPE* and the 44 44 Python type object *type*. Fields not defined by the Python object header 45 45 are not initialized; the object's reference count will be one. The size of 46 the memory allocation is determined from the : attr:`tp_basicsize` field of46 the memory allocation is determined from the :c:member:`~PyTypeObject.tp_basicsize` field of 47 47 the type object. 48 48 49 49 50 .. c function:: TYPE* PyObject_NewVar(TYPE, PyTypeObject *type, Py_ssize_t size)50 .. c:function:: TYPE* PyObject_NewVar(TYPE, PyTypeObject *type, Py_ssize_t size) 51 51 52 52 Allocate a new Python object using the C structure type *TYPE* and the 53 53 Python type object *type*. Fields not defined by the Python object header 54 54 are not initialized. The allocated memory allows for the *TYPE* structure 55 plus *size* fields of the size given by the : attr:`tp_itemsize` field of55 plus *size* fields of the size given by the :c:member:`~PyTypeObject.tp_itemsize` field of 56 56 *type*. This is useful for implementing objects like tuples, which are 57 57 able to determine their size at construction time. Embedding the array of … … 60 60 61 61 .. versionchanged:: 2.5 62 This function used an :c type:`int` type for *size*. This might require62 This function used an :c:type:`int` type for *size*. This might require 63 63 changes in your code for properly supporting 64-bit systems. 64 64 65 65 66 .. c function:: void PyObject_Del(PyObject *op)66 .. c:function:: void PyObject_Del(PyObject *op) 67 67 68 Releases memory allocated to an object using :c func:`PyObject_New` or69 :c func:`PyObject_NewVar`. This is normally called from the70 : attr:`tp_dealloc` handler specified in the object's type. The fields of68 Releases memory allocated to an object using :c:func:`PyObject_New` or 69 :c:func:`PyObject_NewVar`. This is normally called from the 70 :c:member:`~PyTypeObject.tp_dealloc` handler specified in the object's type. The fields of 71 71 the object should not be accessed after this call as the memory is no 72 72 longer a valid Python object. 73 73 74 74 75 .. c function:: PyObject* Py_InitModule(char *name, PyMethodDef *methods)75 .. c:function:: PyObject* Py_InitModule(char *name, PyMethodDef *methods) 76 76 77 77 Create a new module object based on a name and table of functions, … … 83 83 84 84 85 .. c function:: PyObject* Py_InitModule3(char *name, PyMethodDef *methods, char *doc)85 .. c:function:: PyObject* Py_InitModule3(char *name, PyMethodDef *methods, char *doc) 86 86 87 87 Create a new module object based on a name and table of functions, … … 94 94 95 95 96 .. c function:: PyObject* Py_InitModule4(char *name, PyMethodDef *methods, char *doc, PyObject *self, int apiver)96 .. c:function:: PyObject* Py_InitModule4(char *name, PyMethodDef *methods, char *doc, PyObject *self, int apiver) 97 97 98 98 Create a new module object based on a name and table of functions, … … 108 108 109 109 Most uses of this function should probably be using the 110 :c func:`Py_InitModule3` instead; only use this if you are sure you need110 :c:func:`Py_InitModule3` instead; only use this if you are sure you need 111 111 it. 112 112 … … 116 116 117 117 118 .. c var:: PyObject _Py_NoneStruct118 .. c:var:: PyObject _Py_NoneStruct 119 119 120 120 Object which is visible in Python as ``None``. This should only be -
python/vendor/current/Doc/c-api/arg.rst
r2 r388 10 10 :ref:`extending-index`. 11 11 12 The first three of these functions described, :c func:`PyArg_ParseTuple`,13 :c func:`PyArg_ParseTupleAndKeywords`, and :cfunc:`PyArg_Parse`, all use12 The first three of these functions described, :c:func:`PyArg_ParseTuple`, 13 :c:func:`PyArg_ParseTupleAndKeywords`, and :c:func:`PyArg_Parse`, all use 14 14 *format strings* which are used to tell the function about the expected 15 15 arguments. The format strings use the same syntax for each of these … … 25 25 of the C variable(s) whose address should be passed. 26 26 27 ``s`` (string or Unicode object) [const char \*] 27 These formats allow to access an object as a contiguous chunk of memory. 28 You don't have to provide raw storage for the returned unicode or bytes 29 area. Also, you won't have to release any memory yourself, except with the 30 ``es``, ``es#``, ``et`` and ``et#`` formats. 31 32 ``s`` (string or Unicode) [const char \*] 28 33 Convert a Python string or Unicode object to a C pointer to a character 29 34 string. You must not provide storage for the string itself; a pointer to … … 34 39 encoding. If this conversion fails, a :exc:`UnicodeError` is raised. 35 40 36 ``s#`` (string, Unicode or any read buffer compatible object) [const char \*, int (or :c type:`Py_ssize_t`, see below)]41 ``s#`` (string, Unicode or any read buffer compatible object) [const char \*, int (or :c:type:`Py_ssize_t`, see below)] 37 42 This variant on ``s`` stores into two C variables, the first one a pointer 38 43 to a character string, the second one its length. In this case the Python … … 43 48 44 49 Starting with Python 2.5 the type of the length argument can be controlled 45 by defining the macro :c macro:`PY_SSIZE_T_CLEAN` before including46 :file:`Python.h`. If the macro is defined, length is a :c type:`Py_ssize_t`50 by defining the macro :c:macro:`PY_SSIZE_T_CLEAN` before including 51 :file:`Python.h`. If the macro is defined, length is a :c:type:`Py_ssize_t` 47 52 rather than an int. 48 53 … … 56 61 .. versionadded:: 2.6 57 62 58 ``z`` (string or ``None``) [const char \*]63 ``z`` (string, Unicode or ``None``) [const char \*] 59 64 Like ``s``, but the Python object may also be ``None``, in which case the C 60 65 pointer is set to *NULL*. 61 66 62 ``z#`` (string or``None`` or any read buffer compatible object) [const char \*, int]67 ``z#`` (string, Unicode, ``None`` or any read buffer compatible object) [const char \*, int] 63 68 This is to ``s#`` as ``z`` is to ``s``. 64 69 65 ``z*`` (string or``None`` or any buffer compatible object) [Py_buffer]70 ``z*`` (string, Unicode, ``None`` or any buffer compatible object) [Py_buffer] 66 71 This is to ``s*`` as ``z`` is to ``s``. 67 72 68 73 .. versionadded:: 2.6 69 74 70 ``u`` (Unicode object) [Py_UNICODE \*]75 ``u`` (Unicode) [Py_UNICODE \*] 71 76 Convert a Python Unicode object to a C pointer to a NUL-terminated buffer 72 77 of 16-bit Unicode (UTF-16) data. As with ``s``, there is no need to 73 78 provide storage for the Unicode data buffer; a pointer to the existing 74 Unicode data is stored into the :c type:`Py_UNICODE` pointer variable whose79 Unicode data is stored into the :c:type:`Py_UNICODE` pointer variable whose 75 80 address you pass. 76 81 77 ``u#`` (Unicode object) [Py_UNICODE \*, int]82 ``u#`` (Unicode) [Py_UNICODE \*, int] 78 83 This variant on ``u`` stores into two C variables, the first one a pointer 79 84 to a Unicode data buffer, the second one its length. Non-Unicode objects 80 85 are handled by interpreting their read-buffer pointer as pointer to a 81 :c type:`Py_UNICODE` array.82 83 ``es`` (string, Unicode o bject or character buffer compatible object) [const char \*encoding, char \*\*buffer]86 :c:type:`Py_UNICODE` array. 87 88 ``es`` (string, Unicode or character buffer compatible object) [const char \*encoding, char \*\*buffer] 84 89 This variant on ``s`` is used for encoding Unicode and objects convertible 85 90 to Unicode into a character buffer. It only works for encoded data without … … 87 92 88 93 This format requires two arguments. The first is only used as input, and 89 must be a :c type:`const char\*` which points to the name of an encoding as94 must be a :c:type:`const char\*` which points to the name of an encoding as 90 95 a NUL-terminated string, or *NULL*, in which case the default encoding is 91 96 used. An exception is raised if the named encoding is not known to Python. 92 The second argument must be a :c type:`char\*\*`; the value of the pointer97 The second argument must be a :c:type:`char\*\*`; the value of the pointer 93 98 it references will be set to a buffer with the contents of the argument 94 99 text. The text will be encoded in the encoding specified by the first 95 100 argument. 96 101 97 :c func:`PyArg_ParseTuple` will allocate a buffer of the needed size, copy102 :c:func:`PyArg_ParseTuple` will allocate a buffer of the needed size, copy 98 103 the encoded data into this buffer and adjust *\*buffer* to reference the 99 104 newly allocated storage. The caller is responsible for calling 100 :c func:`PyMem_Free` to free the allocated buffer after use.101 102 ``et`` (string, Unicode o bject or character buffer compatible object) [const char \*encoding, char \*\*buffer]105 :c:func:`PyMem_Free` to free the allocated buffer after use. 106 107 ``et`` (string, Unicode or character buffer compatible object) [const char \*encoding, char \*\*buffer] 103 108 Same as ``es`` except that 8-bit string objects are passed through without 104 109 recoding them. Instead, the implementation assumes that the string object 105 110 uses the encoding passed in as parameter. 106 111 107 ``es#`` (string, Unicode o bject or character buffer compatible object) [const char \*encoding, char \*\*buffer, int \*buffer_length]112 ``es#`` (string, Unicode or character buffer compatible object) [const char \*encoding, char \*\*buffer, int \*buffer_length] 108 113 This variant on ``s#`` is used for encoding Unicode and objects convertible 109 114 to Unicode into a character buffer. Unlike the ``es`` format, this variant … … 111 116 112 117 It requires three arguments. The first is only used as input, and must be 113 a :c type:`const char\*` which points to the name of an encoding as a118 a :c:type:`const char\*` which points to the name of an encoding as a 114 119 NUL-terminated string, or *NULL*, in which case the default encoding is 115 120 used. An exception is raised if the named encoding is not known to Python. 116 The second argument must be a :c type:`char\*\*`; the value of the pointer121 The second argument must be a :c:type:`char\*\*`; the value of the pointer 117 122 it references will be set to a buffer with the contents of the argument 118 123 text. The text will be encoded in the encoding specified by the first … … 125 130 of the needed size, copy the encoded data into this buffer and set 126 131 *\*buffer* to reference the newly allocated storage. The caller is 127 responsible for calling :c func:`PyMem_Free` to free the allocated buffer132 responsible for calling :c:func:`PyMem_Free` to free the allocated buffer 128 133 after usage. 129 134 130 135 If *\*buffer* points to a non-*NULL* pointer (an already allocated buffer), 131 :c func:`PyArg_ParseTuple` will use this location as the buffer and136 :c:func:`PyArg_ParseTuple` will use this location as the buffer and 132 137 interpret the initial value of *\*buffer_length* as the buffer size. It 133 138 will then copy the encoded data into the buffer and NUL-terminate it. If … … 137 142 without the trailing NUL byte. 138 143 139 ``et#`` (string, Unicode o bject or character buffer compatible object) [const char \*encoding, char \*\*buffer, int \*buffer_length]144 ``et#`` (string, Unicode or character buffer compatible object) [const char \*encoding, char \*\*buffer, int \*buffer_length] 140 145 Same as ``es#`` except that string objects are passed through without 141 146 recoding them. Instead, the implementation assumes that the string object … … 144 149 ``b`` (integer) [unsigned char] 145 150 Convert a nonnegative Python integer to an unsigned tiny int, stored in a C 146 :c type:`unsigned char`.151 :c:type:`unsigned char`. 147 152 148 153 ``B`` (integer) [unsigned char] 149 154 Convert a Python integer to a tiny int without overflow checking, stored in 150 a C :c type:`unsigned char`.155 a C :c:type:`unsigned char`. 151 156 152 157 .. versionadded:: 2.3 153 158 154 159 ``h`` (integer) [short int] 155 Convert a Python integer to a C :c type:`short int`.160 Convert a Python integer to a C :c:type:`short int`. 156 161 157 162 ``H`` (integer) [unsigned short int] 158 Convert a Python integer to a C :c type:`unsigned short int`, without163 Convert a Python integer to a C :c:type:`unsigned short int`, without 159 164 overflow checking. 160 165 … … 162 167 163 168 ``i`` (integer) [int] 164 Convert a Python integer to a plain C :c type:`int`.169 Convert a Python integer to a plain C :c:type:`int`. 165 170 166 171 ``I`` (integer) [unsigned int] 167 Convert a Python integer to a C :c type:`unsigned int`, without overflow172 Convert a Python integer to a C :c:type:`unsigned int`, without overflow 168 173 checking. 169 174 … … 171 176 172 177 ``l`` (integer) [long int] 173 Convert a Python integer to a C :c type:`long int`.178 Convert a Python integer to a C :c:type:`long int`. 174 179 175 180 ``k`` (integer) [unsigned long] 176 Convert a Python integer or long integer to a C :c type:`unsigned long`181 Convert a Python integer or long integer to a C :c:type:`unsigned long` 177 182 without overflow checking. 178 183 … … 180 185 181 186 ``L`` (integer) [PY_LONG_LONG] 182 Convert a Python integer to a C :c type:`long long`. This format is only183 available on platforms that support :c type:`long long` (or :ctype:`_int64`187 Convert a Python integer to a C :c:type:`long long`. This format is only 188 available on platforms that support :c:type:`long long` (or :c:type:`_int64` 184 189 on Windows). 185 190 186 191 ``K`` (integer) [unsigned PY_LONG_LONG] 187 Convert a Python integer or long integer to a C :c type:`unsigned long long`192 Convert a Python integer or long integer to a C :c:type:`unsigned long long` 188 193 without overflow checking. This format is only available on platforms that 189 support :c type:`unsigned long long` (or :ctype:`unsigned _int64` on194 support :c:type:`unsigned long long` (or :c:type:`unsigned _int64` on 190 195 Windows). 191 196 … … 193 198 194 199 ``n`` (integer) [Py_ssize_t] 195 Convert a Python integer or long integer to a C :c type:`Py_ssize_t`.200 Convert a Python integer or long integer to a C :c:type:`Py_ssize_t`. 196 201 197 202 .. versionadded:: 2.5 … … 199 204 ``c`` (string of length 1) [char] 200 205 Convert a Python character, represented as a string of length 1, to a C 201 :c type:`char`.206 :c:type:`char`. 202 207 203 208 ``f`` (float) [float] 204 Convert a Python floating point number to a C :c type:`float`.209 Convert a Python floating point number to a C :c:type:`float`. 205 210 206 211 ``d`` (float) [double] 207 Convert a Python floating point number to a C :c type:`double`.212 Convert a Python floating point number to a C :c:type:`double`. 208 213 209 214 ``D`` (complex) [Py_complex] 210 Convert a Python complex number to a C :c type:`Py_complex` structure.215 Convert a Python complex number to a C :c:type:`Py_complex` structure. 211 216 212 217 ``O`` (object) [PyObject \*] … … 218 223 Store a Python object in a C object pointer. This is similar to ``O``, but 219 224 takes two C arguments: the first is the address of a Python type object, 220 the second is the address of the C variable (of type :c type:`PyObject\*`)225 the second is the address of the C variable (of type :c:type:`PyObject\*`) 221 226 into which the object pointer is stored. If the Python object does not 222 227 have the required type, :exc:`TypeError` is raised. … … 225 230 Convert a Python object to a C variable through a *converter* function. 226 231 This takes two arguments: the first is a function, the second is the 227 address of a C variable (of arbitrary type), converted to :c type:`void \*`.232 address of a C variable (of arbitrary type), converted to :c:type:`void \*`. 228 233 The *converter* function in turn is called as follows:: 229 234 … … 231 236 232 237 where *object* is the Python object to be converted and *address* is the 233 :c type:`void\*` argument that was passed to the :cfunc:`PyArg_Parse\*`238 :c:type:`void\*` argument that was passed to the :c:func:`PyArg_Parse\*` 234 239 function. The returned *status* should be ``1`` for a successful 235 240 conversion and ``0`` if the conversion has failed. When the conversion … … 240 245 Like ``O`` but requires that the Python object is a string object. Raises 241 246 :exc:`TypeError` if the object is not a string object. The C variable may 242 also be declared as :c type:`PyObject\*`.247 also be declared as :c:type:`PyObject\*`. 243 248 244 249 ``U`` (Unicode string) [PyUnicodeObject \*] 245 250 Like ``O`` but requires that the Python object is a Unicode object. Raises 246 251 :exc:`TypeError` if the object is not a Unicode object. The C variable may 247 also be declared as :c type:`PyObject\*`.252 also be declared as :c:type:`PyObject\*`. 248 253 249 254 ``t#`` (read-only character buffer) [char \*, int] 250 255 Like ``s#``, but accepts any object which implements the read-only buffer 251 interface. The :c type:`char\*` variable is set to point to the first byte252 of the buffer, and the :c type:`int` is set to the length of the buffer.256 interface. The :c:type:`char\*` variable is set to point to the first byte 257 of the buffer, and the :c:type:`int` is set to the length of the buffer. 253 258 Only single-segment buffer objects are accepted; :exc:`TypeError` is raised 254 259 for all others. … … 262 267 ``w#`` (read-write character buffer) [char \*, Py_ssize_t] 263 268 Like ``s#``, but accepts any object which implements the read-write buffer 264 interface. The :c type:`char \*` variable is set to point to the first byte265 of the buffer, and the :c type:`Py_ssize_t` is set to the length of the269 interface. The :c:type:`char \*` variable is set to point to the first byte 270 of the buffer, and the :c:type:`Py_ssize_t` is set to the length of the 266 271 buffer. Only single-segment buffer objects are accepted; :exc:`TypeError` 267 272 is raised for all others. … … 298 303 optional. The C variables corresponding to optional arguments should be 299 304 initialized to their default value --- when an optional argument is not 300 specified, :c func:`PyArg_ParseTuple` does not touch the contents of the305 specified, :c:func:`PyArg_ParseTuple` does not touch the contents of the 301 306 corresponding C variable(s). 302 307 … … 304 309 The list of format units ends here; the string after the colon is used as 305 310 the function name in error messages (the "associated value" of the 306 exception that :c func:`PyArg_ParseTuple` raises).311 exception that :c:func:`PyArg_ParseTuple` raises). 307 312 308 313 ``;`` … … 321 326 322 327 For the conversion to succeed, the *arg* object must match the format and the 323 format must be exhausted. On success, the :c func:`PyArg_Parse\*` functions328 format must be exhausted. On success, the :c:func:`PyArg_Parse\*` functions 324 329 return true, otherwise they return false and raise an appropriate exception. 325 When the :c func:`PyArg_Parse\*` functions fail due to conversion failure in330 When the :c:func:`PyArg_Parse\*` functions fail due to conversion failure in 326 331 one of the format units, the variables at the addresses corresponding to that 327 332 and the following format units are left untouched. 328 333 329 334 330 .. c function:: int PyArg_ParseTuple(PyObject *args, const char *format, ...)335 .. c:function:: int PyArg_ParseTuple(PyObject *args, const char *format, ...) 331 336 332 337 Parse the parameters of a function that takes only positional parameters … … 335 340 336 341 337 .. c function:: int PyArg_VaParse(PyObject *args, const char *format, va_list vargs)338 339 Identical to :c func:`PyArg_ParseTuple`, except that it accepts a va_list342 .. c:function:: int PyArg_VaParse(PyObject *args, const char *format, va_list vargs) 343 344 Identical to :c:func:`PyArg_ParseTuple`, except that it accepts a va_list 340 345 rather than a variable number of arguments. 341 346 342 347 343 .. c function:: int PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, char *keywords[], ...)348 .. c:function:: int PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, char *keywords[], ...) 344 349 345 350 Parse the parameters of a function that takes both positional and keyword … … 348 353 349 354 350 .. c function:: int PyArg_VaParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, char *keywords[], va_list vargs)351 352 Identical to :c func:`PyArg_ParseTupleAndKeywords`, except that it accepts a355 .. c:function:: int PyArg_VaParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, char *keywords[], va_list vargs) 356 357 Identical to :c:func:`PyArg_ParseTupleAndKeywords`, except that it accepts a 353 358 va_list rather than a variable number of arguments. 354 359 355 360 356 .. c function:: int PyArg_Parse(PyObject *args, const char *format, ...)361 .. c:function:: int PyArg_Parse(PyObject *args, const char *format, ...) 357 362 358 363 Function used to deconstruct the argument lists of "old-style" functions … … 365 370 366 371 367 .. c function:: int PyArg_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, ...)372 .. c:function:: int PyArg_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, ...) 368 373 369 374 A simpler form of parameter retrieval which does not use a format string to … … 374 379 tuple must be at least *min* and no more than *max*; *min* and *max* may be 375 380 equal. Additional arguments must be passed to the function, each of which 376 should be a pointer to a :c type:`PyObject\*` variable; these will be filled381 should be a pointer to a :c:type:`PyObject\*` variable; these will be filled 377 382 in with the values from *args*; they will contain borrowed references. The 378 383 variables which correspond to optional parameters not given by *args* will … … 397 402 } 398 403 399 The call to :c func:`PyArg_UnpackTuple` in this example is entirely400 equivalent to this call to :c func:`PyArg_ParseTuple`::404 The call to :c:func:`PyArg_UnpackTuple` in this example is entirely 405 equivalent to this call to :c:func:`PyArg_ParseTuple`:: 401 406 402 407 PyArg_ParseTuple(args, "O|O:ref", &object, &callback) … … 405 410 406 411 .. versionchanged:: 2.5 407 This function used an :c type:`int` type for *min* and *max*. This might412 This function used an :c:type:`int` type for *min* and *max*. This might 408 413 require changes in your code for properly supporting 64-bit systems. 409 414 410 415 411 .. c function:: PyObject* Py_BuildValue(const char *format, ...)416 .. c:function:: PyObject* Py_BuildValue(const char *format, ...) 412 417 413 418 Create a new value based on a format string similar to those accepted by 414 the :c func:`PyArg_Parse\*` family of functions and a sequence of values.419 the :c:func:`PyArg_Parse\*` family of functions and a sequence of values. 415 420 Returns the value or *NULL* in the case of an error; an exception will be 416 421 raised if *NULL* is returned. 417 422 418 :c func:`Py_BuildValue` does not always build a tuple. It builds a tuple423 :c:func:`Py_BuildValue` does not always build a tuple. It builds a tuple 419 424 only if its format string contains two or more format units. If the format 420 425 string is empty, it returns ``None``; if it contains exactly one format … … 426 431 objects, as for the ``s`` and ``s#`` formats, the required data is copied. 427 432 Buffers provided by the caller are never referenced by the objects created 428 by :c func:`Py_BuildValue`. In other words, if your code invokes429 :c func:`malloc` and passes the allocated memory to :cfunc:`Py_BuildValue`,430 your code is responsible for calling :c func:`free` for that memory once431 :c func:`Py_BuildValue` returns.433 by :c:func:`Py_BuildValue`. In other words, if your code invokes 434 :c:func:`malloc` and passes the allocated memory to :c:func:`Py_BuildValue`, 435 your code is responsible for calling :c:func:`free` for that memory once 436 :c:func:`Py_BuildValue` returns. 432 437 433 438 In the following description, the quoted form is the format unit; the entry … … 465 470 466 471 ``i`` (integer) [int] 467 Convert a plain C :c type:`int` to a Python integer object.472 Convert a plain C :c:type:`int` to a Python integer object. 468 473 469 474 ``b`` (integer) [char] 470 Convert a plain C :c type:`char` to a Python integer object.475 Convert a plain C :c:type:`char` to a Python integer object. 471 476 472 477 ``h`` (integer) [short int] 473 Convert a plain C :c type:`short int` to a Python integer object.478 Convert a plain C :c:type:`short int` to a Python integer object. 474 479 475 480 ``l`` (integer) [long int] 476 Convert a C :c type:`long int` to a Python integer object.481 Convert a C :c:type:`long int` to a Python integer object. 477 482 478 483 ``B`` (integer) [unsigned char] 479 Convert a C :c type:`unsigned char` to a Python integer object.484 Convert a C :c:type:`unsigned char` to a Python integer object. 480 485 481 486 ``H`` (integer) [unsigned short int] 482 Convert a C :c type:`unsigned short int` to a Python integer object.487 Convert a C :c:type:`unsigned short int` to a Python integer object. 483 488 484 489 ``I`` (integer/long) [unsigned int] 485 Convert a C :c type:`unsigned int` to a Python integer object or a Python490 Convert a C :c:type:`unsigned int` to a Python integer object or a Python 486 491 long integer object, if it is larger than ``sys.maxint``. 487 492 488 493 ``k`` (integer/long) [unsigned long] 489 Convert a C :c type:`unsigned long` to a Python integer object or a494 Convert a C :c:type:`unsigned long` to a Python integer object or a 490 495 Python long integer object, if it is larger than ``sys.maxint``. 491 496 492 497 ``L`` (long) [PY_LONG_LONG] 493 Convert a C :c type:`long long` to a Python long integer object. Only494 available on platforms that support :c type:`long long`.498 Convert a C :c:type:`long long` to a Python long integer object. Only 499 available on platforms that support :c:type:`long long`. 495 500 496 501 ``K`` (long) [unsigned PY_LONG_LONG] 497 Convert a C :c type:`unsigned long long` to a Python long integer object.498 Only available on platforms that support :c type:`unsigned long long`.502 Convert a C :c:type:`unsigned long long` to a Python long integer object. 503 Only available on platforms that support :c:type:`unsigned long long`. 499 504 500 505 ``n`` (int) [Py_ssize_t] 501 Convert a C :c type:`Py_ssize_t` to a Python integer or long integer.506 Convert a C :c:type:`Py_ssize_t` to a Python integer or long integer. 502 507 503 508 .. versionadded:: 2.5 504 509 505 510 ``c`` (string of length 1) [char] 506 Convert a C :c type:`int` representing a character to a Python string of511 Convert a C :c:type:`int` representing a character to a Python string of 507 512 length 1. 508 513 509 514 ``d`` (float) [double] 510 Convert a C :c type:`double` to a Python floating point number.515 Convert a C :c:type:`double` to a Python floating point number. 511 516 512 517 ``f`` (float) [float] … … 514 519 515 520 ``D`` (complex) [Py_complex \*] 516 Convert a C :c type:`Py_complex` structure to a Python complex number.521 Convert a C :c:type:`Py_complex` structure to a Python complex number. 517 522 518 523 ``O`` (object) [PyObject \*] … … 520 525 incremented by one). If the object passed in is a *NULL* pointer, it is 521 526 assumed that this was caused because the call producing the argument 522 found an error and set an exception. Therefore, :c func:`Py_BuildValue`527 found an error and set an exception. Therefore, :c:func:`Py_BuildValue` 523 528 will return *NULL* but won't raise an exception. If no exception has 524 529 been raised yet, :exc:`SystemError` is set. … … 535 540 Convert *anything* to a Python object through a *converter* function. 536 541 The function is called with *anything* (which should be compatible with 537 :c type:`void \*`) as its argument and should return a "new" Python542 :c:type:`void \*`) as its argument and should return a "new" Python 538 543 object, or *NULL* if an error occurred. 539 544 … … 554 559 is set and *NULL* returned. 555 560 556 .. c function:: PyObject* Py_VaBuildValue(const char *format, va_list vargs)557 558 Identical to :c func:`Py_BuildValue`, except that it accepts a va_list561 .. c:function:: PyObject* Py_VaBuildValue(const char *format, va_list vargs) 562 563 Identical to :c:func:`Py_BuildValue`, except that it accepts a va_list 559 564 rather than a variable number of arguments. -
python/vendor/current/Doc/c-api/bool.rst
r2 r388 12 12 13 13 14 .. c function:: int PyBool_Check(PyObject *o)14 .. c:function:: int PyBool_Check(PyObject *o) 15 15 16 Return true if *o* is of type :c data:`PyBool_Type`.16 Return true if *o* is of type :c:data:`PyBool_Type`. 17 17 18 18 .. versionadded:: 2.3 19 19 20 20 21 .. c var:: PyObject* Py_False21 .. c:var:: PyObject* Py_False 22 22 23 23 The Python ``False`` object. This object has no methods. It needs to be … … 25 25 26 26 27 .. c var:: PyObject* Py_True27 .. c:var:: PyObject* Py_True 28 28 29 29 The Python ``True`` object. This object has no methods. It needs to be treated … … 31 31 32 32 33 .. c macro:: Py_RETURN_FALSE33 .. c:macro:: Py_RETURN_FALSE 34 34 35 35 Return :const:`Py_False` from a function, properly incrementing its reference … … 39 39 40 40 41 .. c macro:: Py_RETURN_TRUE41 .. c:macro:: Py_RETURN_TRUE 42 42 43 43 Return :const:`Py_True` from a function, properly incrementing its reference … … 47 47 48 48 49 .. c function:: PyObject* PyBool_FromLong(long v)49 .. c:function:: PyObject* PyBool_FromLong(long v) 50 50 51 51 Return a new reference to :const:`Py_True` or :const:`Py_False` depending on the -
python/vendor/current/Doc/c-api/buffer.rst
r2 r388 3 3 .. _bufferobjects: 4 4 5 Buffer Objects6 -------------- 5 Buffers and Memoryview Objects 6 ------------------------------ 7 7 8 8 .. sectionauthor:: Greg Stein <gstein@lyra.org> 9 .. sectionauthor:: Benjamin Peterson 9 10 10 11 … … 27 28 method. Any object that can export a series of bytes through the buffer 28 29 interface can be written to a file. There are a number of format codes to 29 :c func:`PyArg_ParseTuple` that operate against an object's buffer interface,30 :c:func:`PyArg_ParseTuple` that operate against an object's buffer interface, 30 31 returning data from the target object. 31 32 … … 33 34 objects and a C-level buffer API so that any built-in or used-defined type can 34 35 expose its characteristics. Both, however, have been deprecated because of 35 various shortcomings, and have been officially removed in Python 3 .0in favour36 various shortcomings, and have been officially removed in Python 3 in favour 36 37 of a new C-level buffer API and a new Python-level object named 37 38 :class:`memoryview`. … … 47 48 48 49 49 .. c type:: Py_buffer50 51 .. c member:: void *buf50 .. c:type:: Py_buffer 51 52 .. c:member:: void *buf 52 53 53 54 A pointer to the start of the memory for the object. 54 55 55 .. c member:: Py_ssize_t len56 .. c:member:: Py_ssize_t len 56 57 :noindex: 57 58 58 59 The total length of the memory in bytes. 59 60 60 .. c member:: int readonly61 .. c:member:: int readonly 61 62 62 63 An indicator of whether the buffer is read only. 63 64 64 .. c member:: const char *format65 .. c:member:: const char *format 65 66 :noindex: 66 67 … … 69 70 *NULL*, ``"B"`` (unsigned bytes) is assumed. 70 71 71 .. c member:: int ndim72 .. c:member:: int ndim 72 73 73 74 The number of dimensions the memory represents as a multi-dimensional 74 array. If it is 0, :c data:`strides` and :cdata:`suboffsets` must be75 array. If it is 0, :c:data:`strides` and :c:data:`suboffsets` must be 75 76 *NULL*. 76 77 77 .. c member:: Py_ssize_t *shape78 79 An array of :c type:`Py_ssize_t`\s the length of :cdata:`ndim` giving the78 .. c:member:: Py_ssize_t *shape 79 80 An array of :c:type:`Py_ssize_t`\s the length of :c:data:`ndim` giving the 80 81 shape of the memory as a multi-dimensional array. Note that 81 82 ``((*shape)[0] * ... * (*shape)[ndims-1])*itemsize`` should be equal to 82 :c data:`len`.83 84 .. c member:: Py_ssize_t *strides85 86 An array of :c type:`Py_ssize_t`\s the length of :cdata:`ndim` giving the83 :c:data:`len`. 84 85 .. c:member:: Py_ssize_t *strides 86 87 An array of :c:type:`Py_ssize_t`\s the length of :c:data:`ndim` giving the 87 88 number of bytes to skip to get to a new element in each dimension. 88 89 89 .. c member:: Py_ssize_t *suboffsets90 91 An array of :c type:`Py_ssize_t`\s the length of :cdata:`ndim`. If these90 .. c:member:: Py_ssize_t *suboffsets 91 92 An array of :c:type:`Py_ssize_t`\s the length of :c:data:`ndim`. If these 92 93 suboffset numbers are greater than or equal to 0, then the value stored 93 94 along the indicated dimension is a pointer and the suboffset value … … 114 115 115 116 116 .. c member:: Py_ssize_t itemsize117 .. c:member:: Py_ssize_t itemsize 117 118 118 119 This is a storage for the itemsize (in bytes) of each element of the 119 120 shared memory. It is technically un-necessary as it can be obtained 120 using :c func:`PyBuffer_SizeFromFormat`, however an exporter may know121 using :c:func:`PyBuffer_SizeFromFormat`, however an exporter may know 121 122 this information without parsing the format string and it is necessary 122 123 to know the itemsize for proper interpretation of striding. Therefore, 123 124 storing it is more convenient and faster. 124 125 125 .. c member:: void *internal126 .. c:member:: void *internal 126 127 127 128 This is for use internally by the exporting object. For example, this … … 136 137 137 138 138 .. c function:: int PyObject_CheckBuffer(PyObject *obj)139 .. c:function:: int PyObject_CheckBuffer(PyObject *obj) 139 140 140 141 Return 1 if *obj* supports the buffer interface otherwise 0. 141 142 142 143 143 .. c function:: int PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags)144 145 Export *obj* into a :c type:`Py_buffer`, *view*. These arguments must144 .. c:function:: int PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags) 145 146 Export *obj* into a :c:type:`Py_buffer`, *view*. These arguments must 146 147 never be *NULL*. The *flags* argument is a bit field indicating what 147 148 kind of buffer the caller is prepared to deal with and therefore what … … 156 157 there is another error that is actually causing the problem. The 157 158 exporter can use flags information to simplify how much of the 158 :c data:`Py_buffer` structure is filled in with non-default values and/or159 :c:data:`Py_buffer` structure is filled in with non-default values and/or 159 160 raise an error if the object can't support a simpler view of its memory. 160 161 … … 163 164 The following table gives possible values to the *flags* arguments. 164 165 165 +------------------------------ +---------------------------------------------------+166 | Flag | Description |167 +============================== +===================================================+168 | :c macro:`PyBUF_SIMPLE` | This is the default flag state. The returned |169 | | buffer may or may not have writable memory. The |170 | | format of the data will be assumed to be unsigned |171 | | bytes. This is a "stand-alone" flag constant. It |172 | | never needs to be '|'d to the others. The exporter|173 | | will raise an error if it cannot provide such a |174 | | contiguous buffer of bytes. |175 | | |176 +------------------------------ +---------------------------------------------------+177 | :c macro:`PyBUF_WRITABLE` | The returned buffer must be writable. If it is |178 | | not writable, then raise an error. |179 +------------------------------ +---------------------------------------------------+180 | :c macro:`PyBUF_STRIDES` | This implies :cmacro:`PyBUF_ND`. The returned|181 | | buffer must provide strides information (i.e. the |182 | | strides cannot be NULL). This would be used when |183 | | the consumer can handle strided, discontiguous |184 | | arrays. Handling strides automatically assumes |185 | | you can handle shape. The exporter can raise an |186 | | error if a strided representation of the data is |187 | | not possible (i.e. without the suboffsets). |188 | | |189 +------------------------------ +---------------------------------------------------+190 | :c macro:`PyBUF_ND` | The returned buffer must provide shape |191 | | information. The memory will be assumed C-style |192 | | contiguous (last dimension varies the |193 | | fastest). The exporter may raise an error if it |194 | | cannot provide this kind of contiguous buffer. If |195 | | this is not given then shape will be *NULL*. |196 | | |197 | | |198 | | |199 +------------------------------ +---------------------------------------------------+200 |:c macro:`PyBUF_C_CONTIGUOUS` | These flags indicate that the contiguity returned |201 |:c macro:`PyBUF_F_CONTIGUOUS` | buffer must be respectively, C-contiguous (last |202 |:c macro:`PyBUF_ANY_CONTIGUOUS`| dimension varies the fastest), Fortran contiguous |203 | | (first dimension varies the fastest) or either |204 | | one. All of these flags imply |205 | | :cmacro:`PyBUF_STRIDES` and guarantee that the|206 | | strides buffer info structure will be filled in |207 | | correctly. |208 | | |209 +------------------------------ +---------------------------------------------------+210 | :c macro:`PyBUF_INDIRECT` | This flag indicates the returned buffer must have |211 | | suboffsets information (which can be NULL if no |212 | | suboffsets are needed). This can be used when |213 | | the consumer can handle indirect array |214 | | referencing implied by these suboffsets. This |215 | | implies :cmacro:`PyBUF_STRIDES`.|216 | | |217 | | |218 | | |219 +------------------------------ +---------------------------------------------------+220 | :c macro:`PyBUF_FORMAT` | The returned buffer must have true format |221 | | information if this flag is provided. This would |222 | | be used when the consumer is going to be checking |223 | | for what 'kind' of data is actually stored. An |224 | | exporter should always be able to provide this |225 | | information if requested. If format is not |226 | | explicitly requested then the format must be |227 | | returned as *NULL* (which means ``'B'``, or |228 | | unsigned bytes) |229 +------------------------------ +---------------------------------------------------+230 | :c macro:`PyBUF_STRIDED` | This is equivalent to ``(PyBUF_STRIDES | |231 | | PyBUF_WRITABLE)``. |232 +------------------------------ +---------------------------------------------------+233 | :c macro:`PyBUF_STRIDED_RO` | This is equivalent to ``(PyBUF_STRIDES)``. |234 | | |235 +------------------------------ +---------------------------------------------------+236 | :c macro:`PyBUF_RECORDS` | This is equivalent to ``(PyBUF_STRIDES | |237 | | PyBUF_FORMAT | PyBUF_WRITABLE)``. |238 +------------------------------ +---------------------------------------------------+239 | :c macro:`PyBUF_RECORDS_RO` | This is equivalent to ``(PyBUF_STRIDES | |240 | | PyBUF_FORMAT)``. |241 +------------------------------ +---------------------------------------------------+242 | :c macro:`PyBUF_FULL` | This is equivalent to ``(PyBUF_INDIRECT | |243 | | PyBUF_FORMAT | PyBUF_WRITABLE)``. |244 +------------------------------ +---------------------------------------------------+245 | :c macro:`PyBUF_FULL_RO` | This is equivalent to ``(PyBUF_INDIRECT | |246 | | PyBUF_FORMAT)``. |247 +------------------------------ +---------------------------------------------------+248 | :c macro:`PyBUF_CONTIG` | This is equivalent to ``(PyBUF_ND | |249 | | PyBUF_WRITABLE)``. |250 +------------------------------ +---------------------------------------------------+251 | :c macro:`PyBUF_CONTIG_RO` | This is equivalent to ``(PyBUF_ND)``. |252 | | |253 +------------------------------ +---------------------------------------------------+254 255 256 .. c function:: void PyBuffer_Release(Py_buffer *view)166 +-------------------------------+---------------------------------------------------+ 167 | Flag | Description | 168 +===============================+===================================================+ 169 | :c:macro:`PyBUF_SIMPLE` | This is the default flag state. The returned | 170 | | buffer may or may not have writable memory. The | 171 | | format of the data will be assumed to be unsigned | 172 | | bytes. This is a "stand-alone" flag constant. It | 173 | | never needs to be '|'d to the others. The exporter| 174 | | will raise an error if it cannot provide such a | 175 | | contiguous buffer of bytes. | 176 | | | 177 +-------------------------------+---------------------------------------------------+ 178 | :c:macro:`PyBUF_WRITABLE` | The returned buffer must be writable. If it is | 179 | | not writable, then raise an error. | 180 +-------------------------------+---------------------------------------------------+ 181 | :c:macro:`PyBUF_STRIDES` | This implies :c:macro:`PyBUF_ND`. The returned | 182 | | buffer must provide strides information (i.e. the | 183 | | strides cannot be NULL). This would be used when | 184 | | the consumer can handle strided, discontiguous | 185 | | arrays. Handling strides automatically assumes | 186 | | you can handle shape. The exporter can raise an | 187 | | error if a strided representation of the data is | 188 | | not possible (i.e. without the suboffsets). | 189 | | | 190 +-------------------------------+---------------------------------------------------+ 191 | :c:macro:`PyBUF_ND` | The returned buffer must provide shape | 192 | | information. The memory will be assumed C-style | 193 | | contiguous (last dimension varies the | 194 | | fastest). The exporter may raise an error if it | 195 | | cannot provide this kind of contiguous buffer. If | 196 | | this is not given then shape will be *NULL*. | 197 | | | 198 | | | 199 | | | 200 +-------------------------------+---------------------------------------------------+ 201 |:c:macro:`PyBUF_C_CONTIGUOUS` | These flags indicate that the contiguity returned | 202 |:c:macro:`PyBUF_F_CONTIGUOUS` | buffer must be respectively, C-contiguous (last | 203 |:c:macro:`PyBUF_ANY_CONTIGUOUS`| dimension varies the fastest), Fortran contiguous | 204 | | (first dimension varies the fastest) or either | 205 | | one. All of these flags imply | 206 | | :c:macro:`PyBUF_STRIDES` and guarantee that the | 207 | | strides buffer info structure will be filled in | 208 | | correctly. | 209 | | | 210 +-------------------------------+---------------------------------------------------+ 211 | :c:macro:`PyBUF_INDIRECT` | This flag indicates the returned buffer must have | 212 | | suboffsets information (which can be NULL if no | 213 | | suboffsets are needed). This can be used when | 214 | | the consumer can handle indirect array | 215 | | referencing implied by these suboffsets. This | 216 | | implies :c:macro:`PyBUF_STRIDES`. | 217 | | | 218 | | | 219 | | | 220 +-------------------------------+---------------------------------------------------+ 221 | :c:macro:`PyBUF_FORMAT` | The returned buffer must have true format | 222 | | information if this flag is provided. This would | 223 | | be used when the consumer is going to be checking | 224 | | for what 'kind' of data is actually stored. An | 225 | | exporter should always be able to provide this | 226 | | information if requested. If format is not | 227 | | explicitly requested then the format must be | 228 | | returned as *NULL* (which means ``'B'``, or | 229 | | unsigned bytes) | 230 +-------------------------------+---------------------------------------------------+ 231 | :c:macro:`PyBUF_STRIDED` | This is equivalent to ``(PyBUF_STRIDES | | 232 | | PyBUF_WRITABLE)``. | 233 +-------------------------------+---------------------------------------------------+ 234 | :c:macro:`PyBUF_STRIDED_RO` | This is equivalent to ``(PyBUF_STRIDES)``. | 235 | | | 236 +-------------------------------+---------------------------------------------------+ 237 | :c:macro:`PyBUF_RECORDS` | This is equivalent to ``(PyBUF_STRIDES | | 238 | | PyBUF_FORMAT | PyBUF_WRITABLE)``. | 239 +-------------------------------+---------------------------------------------------+ 240 | :c:macro:`PyBUF_RECORDS_RO` | This is equivalent to ``(PyBUF_STRIDES | | 241 | | PyBUF_FORMAT)``. | 242 +-------------------------------+---------------------------------------------------+ 243 | :c:macro:`PyBUF_FULL` | This is equivalent to ``(PyBUF_INDIRECT | | 244 | | PyBUF_FORMAT | PyBUF_WRITABLE)``. | 245 +-------------------------------+---------------------------------------------------+ 246 | :c:macro:`PyBUF_FULL_RO` | This is equivalent to ``(PyBUF_INDIRECT | | 247 | | PyBUF_FORMAT)``. | 248 +-------------------------------+---------------------------------------------------+ 249 | :c:macro:`PyBUF_CONTIG` | This is equivalent to ``(PyBUF_ND | | 250 | | PyBUF_WRITABLE)``. | 251 +-------------------------------+---------------------------------------------------+ 252 | :c:macro:`PyBUF_CONTIG_RO` | This is equivalent to ``(PyBUF_ND)``. | 253 | | | 254 +-------------------------------+---------------------------------------------------+ 255 256 257 .. c:function:: void PyBuffer_Release(Py_buffer *view) 257 258 258 259 Release the buffer *view*. This should be called when the buffer … … 260 261 261 262 262 .. cfunction:: Py_ssize_t PyBuffer_SizeFromFormat(const char *) 263 264 Return the implied :cdata:`~Py_buffer.itemsize` from the struct-stype 265 :cdata:`~Py_buffer.format`. 266 267 268 .. cfunction:: int PyObject_CopyToObject(PyObject *obj, void *buf, Py_ssize_t len, char fortran) 269 270 Copy *len* bytes of data pointed to by the contiguous chunk of memory 271 pointed to by *buf* into the buffer exported by obj. The buffer must of 272 course be writable. Return 0 on success and return -1 and raise an error 273 on failure. If the object does not have a writable buffer, then an error 274 is raised. If *fortran* is ``'F'``, then if the object is 275 multi-dimensional, then the data will be copied into the array in 276 Fortran-style (first dimension varies the fastest). If *fortran* is 277 ``'C'``, then the data will be copied into the array in C-style (last 278 dimension varies the fastest). If *fortran* is ``'A'``, then it does not 279 matter and the copy will be made in whatever way is more efficient. 280 281 282 .. cfunction:: int PyBuffer_IsContiguous(Py_buffer *view, char fortran) 263 .. c:function:: Py_ssize_t PyBuffer_SizeFromFormat(const char *) 264 265 Return the implied :c:data:`~Py_buffer.itemsize` from the struct-stype 266 :c:data:`~Py_buffer.format`. 267 268 269 .. c:function:: int PyBuffer_IsContiguous(Py_buffer *view, char fortran) 283 270 284 271 Return 1 if the memory defined by the *view* is C-style (*fortran* is … … 287 274 288 275 289 .. c function:: void PyBuffer_FillContiguousStrides(int ndim, Py_ssize_t *shape, Py_ssize_t *strides, Py_ssize_t itemsize, char fortran)276 .. c:function:: void PyBuffer_FillContiguousStrides(int ndim, Py_ssize_t *shape, Py_ssize_t *strides, Py_ssize_t itemsize, char fortran) 290 277 291 278 Fill the *strides* array with byte-strides of a contiguous (C-style if 292 *fortran* is ``'C'`` or Fortran-style if *fortran* is ``'F'`` array of the279 *fortran* is ``'C'`` or Fortran-style if *fortran* is ``'F'``) array of the 293 280 given shape with the given number of bytes per element. 294 281 295 282 296 .. c function:: int PyBuffer_FillInfo(Py_buffer *view, void *buf, Py_ssize_t len, int readonly, int infoflags)283 .. c:function:: int PyBuffer_FillInfo(Py_buffer *view, PyObject *obj, void *buf, Py_ssize_t len, int readonly, int infoflags) 297 284 298 285 Fill in a buffer-info structure, *view*, correctly for an exporter that can … … 301 288 302 289 290 MemoryView objects 291 ================== 292 293 .. versionadded:: 2.7 294 295 A :class:`memoryview` object exposes the new C level buffer interface as a 296 Python object which can then be passed around like any other object. 297 298 .. c:function:: PyObject *PyMemoryView_FromObject(PyObject *obj) 299 300 Create a memoryview object from an object that defines the new buffer 301 interface. 302 303 304 .. c:function:: PyObject *PyMemoryView_FromBuffer(Py_buffer *view) 305 306 Create a memoryview object wrapping the given buffer-info structure *view*. 307 The memoryview object then owns the buffer, which means you shouldn't 308 try to release it yourself: it will be released on deallocation of the 309 memoryview object. 310 311 312 .. c:function:: PyObject *PyMemoryView_GetContiguous(PyObject *obj, int buffertype, char order) 313 314 Create a memoryview object to a contiguous chunk of memory (in either 315 'C' or 'F'ortran *order*) from an object that defines the buffer 316 interface. If memory is contiguous, the memoryview object points to the 317 original memory. Otherwise copy is made and the memoryview points to a 318 new bytes object. 319 320 321 .. c:function:: int PyMemoryView_Check(PyObject *obj) 322 323 Return true if the object *obj* is a memoryview object. It is not 324 currently allowed to create subclasses of :class:`memoryview`. 325 326 327 .. c:function:: Py_buffer *PyMemoryView_GET_BUFFER(PyObject *obj) 328 329 Return a pointer to the buffer-info structure wrapped by the given 330 object. The object **must** be a memoryview instance; this macro doesn't 331 check its type, you must do it yourself or you will risk crashes. 332 333 303 334 Old-style buffer objects 304 335 ======================== … … 306 337 .. index:: single: PyBufferProcs 307 338 308 More information on the buffer interface is provided in the section309 :ref:`buffer-structs`, under the description for :c type:`PyBufferProcs`.339 More information on the old buffer interface is provided in the section 340 :ref:`buffer-structs`, under the description for :c:type:`PyBufferProcs`. 310 341 311 342 A "buffer object" is defined in the :file:`bufferobject.h` header (included by … … 326 357 327 358 328 .. c type:: PyBufferObject329 330 This subtype of :c type:`PyObject` represents a buffer object.331 332 333 .. c var:: PyTypeObject PyBuffer_Type359 .. c:type:: PyBufferObject 360 361 This subtype of :c:type:`PyObject` represents a buffer object. 362 363 364 .. c:var:: PyTypeObject PyBuffer_Type 334 365 335 366 .. index:: single: BufferType (in module types) 336 367 337 The instance of :c type:`PyTypeObject` which represents the Python buffer type;368 The instance of :c:type:`PyTypeObject` which represents the Python buffer type; 338 369 it is the same object as ``buffer`` and ``types.BufferType`` in the Python 339 370 layer. . 340 371 341 372 342 .. c var:: int Py_END_OF_BUFFER373 .. c:var:: int Py_END_OF_BUFFER 343 374 344 375 This constant may be passed as the *size* parameter to 345 :c func:`PyBuffer_FromObject` or :cfunc:`PyBuffer_FromReadWriteObject`. It346 indicates that the new :c type:`PyBufferObject` should refer to *base*376 :c:func:`PyBuffer_FromObject` or :c:func:`PyBuffer_FromReadWriteObject`. It 377 indicates that the new :c:type:`PyBufferObject` should refer to *base* 347 378 object from the specified *offset* to the end of its exported buffer. 348 379 Using this enables the caller to avoid querying the *base* object for its … … 350 381 351 382 352 .. c function:: int PyBuffer_Check(PyObject *p)353 354 Return true if the argument has type :c data:`PyBuffer_Type`.355 356 357 .. c function:: PyObject* PyBuffer_FromObject(PyObject *base, Py_ssize_t offset, Py_ssize_t size)383 .. c:function:: int PyBuffer_Check(PyObject *p) 384 385 Return true if the argument has type :c:data:`PyBuffer_Type`. 386 387 388 .. c:function:: PyObject* PyBuffer_FromObject(PyObject *base, Py_ssize_t offset, Py_ssize_t size) 358 389 359 390 Return a new read-only buffer object. This raises :exc:`TypeError` if … … 367 398 368 399 .. versionchanged:: 2.5 369 This function used an :c type:`int` type for *offset* and *size*. This400 This function used an :c:type:`int` type for *offset* and *size*. This 370 401 might require changes in your code for properly supporting 64-bit 371 402 systems. 372 403 373 404 374 .. c function:: PyObject* PyBuffer_FromReadWriteObject(PyObject *base, Py_ssize_t offset, Py_ssize_t size)405 .. c:function:: PyObject* PyBuffer_FromReadWriteObject(PyObject *base, Py_ssize_t offset, Py_ssize_t size) 375 406 376 407 Return a new writable buffer object. Parameters and exceptions are similar 377 to those for :c func:`PyBuffer_FromObject`. If the *base* object does not408 to those for :c:func:`PyBuffer_FromObject`. If the *base* object does not 378 409 export the writeable buffer protocol, then :exc:`TypeError` is raised. 379 410 380 411 .. versionchanged:: 2.5 381 This function used an :c type:`int` type for *offset* and *size*. This412 This function used an :c:type:`int` type for *offset* and *size*. This 382 413 might require changes in your code for properly supporting 64-bit 383 414 systems. 384 415 385 416 386 .. c function:: PyObject* PyBuffer_FromMemory(void *ptr, Py_ssize_t size)417 .. c:function:: PyObject* PyBuffer_FromMemory(void *ptr, Py_ssize_t size) 387 418 388 419 Return a new read-only buffer object that reads from a specified location … … 394 425 395 426 .. versionchanged:: 2.5 396 This function used an :c type:`int` type for *size*. This might require427 This function used an :c:type:`int` type for *size*. This might require 397 428 changes in your code for properly supporting 64-bit systems. 398 429 399 430 400 .. c function:: PyObject* PyBuffer_FromReadWriteMemory(void *ptr, Py_ssize_t size)401 402 Similar to :c func:`PyBuffer_FromMemory`, but the returned buffer is431 .. c:function:: PyObject* PyBuffer_FromReadWriteMemory(void *ptr, Py_ssize_t size) 432 433 Similar to :c:func:`PyBuffer_FromMemory`, but the returned buffer is 403 434 writable. 404 435 405 436 .. versionchanged:: 2.5 406 This function used an :c type:`int` type for *size*. This might require437 This function used an :c:type:`int` type for *size*. This might require 407 438 changes in your code for properly supporting 64-bit systems. 408 439 409 440 410 .. c function:: PyObject* PyBuffer_New(Py_ssize_t size)441 .. c:function:: PyObject* PyBuffer_New(Py_ssize_t size) 411 442 412 443 Return a new writable buffer object that maintains its own memory buffer of 413 444 *size* bytes. :exc:`ValueError` is returned if *size* is not zero or 414 445 positive. Note that the memory buffer (as returned by 415 :c func:`PyObject_AsWriteBuffer`) is not specifically aligned.446 :c:func:`PyObject_AsWriteBuffer`) is not specifically aligned. 416 447 417 448 .. versionchanged:: 2.5 418 This function used an :c type:`int` type for *size*. This might require449 This function used an :c:type:`int` type for *size*. This might require 419 450 changes in your code for properly supporting 64-bit systems. -
python/vendor/current/Doc/c-api/bytearray.rst
r2 r388 11 11 12 12 13 .. c type:: PyByteArrayObject13 .. c:type:: PyByteArrayObject 14 14 15 This subtype of :c type:`PyObject` represents a Python bytearray object.15 This subtype of :c:type:`PyObject` represents a Python bytearray object. 16 16 17 17 18 .. c var:: PyTypeObject PyByteArray_Type18 .. c:var:: PyTypeObject PyByteArray_Type 19 19 20 This instance of :c type:`PyTypeObject` represents the Python bytearray type;20 This instance of :c:type:`PyTypeObject` represents the Python bytearray type; 21 21 it is the same object as ``bytearray`` in the Python layer. 22 22 … … 24 24 ^^^^^^^^^^^^^^^^^ 25 25 26 .. c function:: int PyByteArray_Check(PyObject *o)26 .. c:function:: int PyByteArray_Check(PyObject *o) 27 27 28 28 Return true if the object *o* is a bytearray object or an instance of a … … 30 30 31 31 32 .. c function:: int PyByteArray_CheckExact(PyObject *o)32 .. c:function:: int PyByteArray_CheckExact(PyObject *o) 33 33 34 34 Return true if the object *o* is a bytearray object, but not an instance of a … … 39 39 ^^^^^^^^^^^^^^^^^^^^ 40 40 41 .. c function:: PyObject* PyByteArray_FromObject(PyObject *o)41 .. c:function:: PyObject* PyByteArray_FromObject(PyObject *o) 42 42 43 43 Return a new bytearray object from any object, *o*, that implements the … … 47 47 48 48 49 .. c function:: PyObject* PyByteArray_FromStringAndSize(const char *string, Py_ssize_t len)49 .. c:function:: PyObject* PyByteArray_FromStringAndSize(const char *string, Py_ssize_t len) 50 50 51 51 Create a new bytearray object from *string* and its length, *len*. On … … 53 53 54 54 55 .. c function:: PyObject* PyByteArray_Concat(PyObject *a, PyObject *b)55 .. c:function:: PyObject* PyByteArray_Concat(PyObject *a, PyObject *b) 56 56 57 57 Concat bytearrays *a* and *b* and return a new bytearray with the result. 58 58 59 59 60 .. c function:: Py_ssize_t PyByteArray_Size(PyObject *bytearray)60 .. c:function:: Py_ssize_t PyByteArray_Size(PyObject *bytearray) 61 61 62 62 Return the size of *bytearray* after checking for a *NULL* pointer. 63 63 64 64 65 .. c function:: char* PyByteArray_AsString(PyObject *bytearray)65 .. c:function:: char* PyByteArray_AsString(PyObject *bytearray) 66 66 67 67 Return the contents of *bytearray* as a char array after checking for a … … 69 69 70 70 71 .. c function:: int PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len)71 .. c:function:: int PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len) 72 72 73 73 Resize the internal buffer of *bytearray* to *len*. … … 78 78 These macros trade safety for speed and they don't check pointers. 79 79 80 .. c function:: char* PyByteArray_AS_STRING(PyObject *bytearray)80 .. c:function:: char* PyByteArray_AS_STRING(PyObject *bytearray) 81 81 82 Macro version of :c func:`PyByteArray_AsString`.82 Macro version of :c:func:`PyByteArray_AsString`. 83 83 84 84 85 .. c function:: Py_ssize_t PyByteArray_GET_SIZE(PyObject *bytearray)85 .. c:function:: Py_ssize_t PyByteArray_GET_SIZE(PyObject *bytearray) 86 86 87 Macro version of :c func:`PyByteArray_Size`.87 Macro version of :c:func:`PyByteArray_Size`. -
python/vendor/current/Doc/c-api/cell.rst
r2 r388 16 16 17 17 18 .. c type:: PyCellObject18 .. c:type:: PyCellObject 19 19 20 20 The C structure used for cell objects. 21 21 22 22 23 .. c var:: PyTypeObject PyCell_Type23 .. c:var:: PyTypeObject PyCell_Type 24 24 25 25 The type object corresponding to cell objects. 26 26 27 27 28 .. c function:: int PyCell_Check(ob)28 .. c:function:: int PyCell_Check(ob) 29 29 30 30 Return true if *ob* is a cell object; *ob* must not be *NULL*. 31 31 32 32 33 .. c function:: PyObject* PyCell_New(PyObject *ob)33 .. c:function:: PyObject* PyCell_New(PyObject *ob) 34 34 35 35 Create and return a new cell object containing the value *ob*. The parameter may … … 37 37 38 38 39 .. c function:: PyObject* PyCell_Get(PyObject *cell)39 .. c:function:: PyObject* PyCell_Get(PyObject *cell) 40 40 41 41 Return the contents of the cell *cell*. 42 42 43 43 44 .. c function:: PyObject* PyCell_GET(PyObject *cell)44 .. c:function:: PyObject* PyCell_GET(PyObject *cell) 45 45 46 46 Return the contents of the cell *cell*, but without checking that *cell* is … … 48 48 49 49 50 .. c function:: int PyCell_Set(PyObject *cell, PyObject *value)50 .. c:function:: int PyCell_Set(PyObject *cell, PyObject *value) 51 51 52 52 Set the contents of the cell object *cell* to *value*. This releases the … … 56 56 57 57 58 .. c function:: void PyCell_SET(PyObject *cell, PyObject *value)58 .. c:function:: void PyCell_SET(PyObject *cell, PyObject *value) 59 59 60 60 Sets the value of the cell object *cell* to *value*. No reference counts are -
python/vendor/current/Doc/c-api/class.rst
r2 r388 13 13 14 14 15 .. c type:: PyClassObject15 .. c:type:: PyClassObject 16 16 17 17 The C structure of the objects used to describe built-in classes. 18 18 19 19 20 .. c var:: PyObject* PyClass_Type20 .. c:var:: PyObject* PyClass_Type 21 21 22 22 .. index:: single: ClassType (in module types) … … 26 26 27 27 28 .. c function:: int PyClass_Check(PyObject *o)28 .. c:function:: int PyClass_Check(PyObject *o) 29 29 30 30 Return true if the object *o* is a class object, including instances of types … … 32 32 33 33 34 .. c function:: int PyClass_IsSubclass(PyObject *klass, PyObject *base)34 .. c:function:: int PyClass_IsSubclass(PyObject *klass, PyObject *base) 35 35 36 36 Return true if *klass* is a subclass of *base*. Return false in all other cases. … … 42 42 43 43 44 .. c var:: PyTypeObject PyInstance_Type44 .. c:var:: PyTypeObject PyInstance_Type 45 45 46 46 Type object for class instances. 47 47 48 48 49 .. c function:: int PyInstance_Check(PyObject *obj)49 .. c:function:: int PyInstance_Check(PyObject *obj) 50 50 51 51 Return true if *obj* is an instance. 52 52 53 53 54 .. c function:: PyObject* PyInstance_New(PyObject *class, PyObject *arg, PyObject *kw)54 .. c:function:: PyObject* PyInstance_New(PyObject *class, PyObject *arg, PyObject *kw) 55 55 56 56 Create a new instance of a specific class. The parameters *arg* and *kw* are … … 58 58 59 59 60 .. c function:: PyObject* PyInstance_NewRaw(PyObject *class, PyObject *dict)60 .. c:function:: PyObject* PyInstance_NewRaw(PyObject *class, PyObject *dict) 61 61 62 62 Create a new instance of a specific class without calling its constructor. -
python/vendor/current/Doc/c-api/cobject.rst
r2 r388 8 8 .. index:: object: CObject 9 9 10 Refer to :ref:`using-cobjects` for more information on using these objects.11 10 11 .. warning:: 12 12 13 .. ctype:: PyCObject 13 The CObject API is deprecated as of Python 2.7. Please switch to the new 14 :ref:`capsules` API. 14 15 15 This subtype of :ctype:`PyObject` represents an opaque value, useful for C 16 extension modules who need to pass an opaque value (as a :ctype:`void\*` 16 .. c:type:: PyCObject 17 18 This subtype of :c:type:`PyObject` represents an opaque value, useful for C 19 extension modules who need to pass an opaque value (as a :c:type:`void\*` 17 20 pointer) through Python code to other C code. It is often used to make a C 18 21 function pointer defined in one module available to other modules, so the … … 21 24 22 25 23 .. c function:: int PyCObject_Check(PyObject *p)26 .. c:function:: int PyCObject_Check(PyObject *p) 24 27 25 Return true if its argument is a :c type:`PyCObject`.28 Return true if its argument is a :c:type:`PyCObject`. 26 29 27 30 28 .. c function:: PyObject* PyCObject_FromVoidPtr(void* cobj, void (*destr)(void *))31 .. c:function:: PyObject* PyCObject_FromVoidPtr(void* cobj, void (*destr)(void *)) 29 32 30 Create a :c type:`PyCObject` from the ``void *`` *cobj*. The *destr* function33 Create a :c:type:`PyCObject` from the ``void *`` *cobj*. The *destr* function 31 34 will be called when the object is reclaimed, unless it is *NULL*. 32 35 33 36 34 .. c function:: PyObject* PyCObject_FromVoidPtrAndDesc(void* cobj, void* desc, void (*destr)(void *, void *))37 .. c:function:: PyObject* PyCObject_FromVoidPtrAndDesc(void* cobj, void* desc, void (*destr)(void *, void *)) 35 38 36 Create a :c type:`PyCObject` from the :ctype:`void \*` *cobj*. The *destr*39 Create a :c:type:`PyCObject` from the :c:type:`void \*` *cobj*. The *destr* 37 40 function will be called when the object is reclaimed. The *desc* argument can 38 41 be used to pass extra callback data for the destructor function. 39 42 40 43 41 .. c function:: void* PyCObject_AsVoidPtr(PyObject* self)44 .. c:function:: void* PyCObject_AsVoidPtr(PyObject* self) 42 45 43 Return the object :c type:`void \*` that the :ctype:`PyCObject` *self* was46 Return the object :c:type:`void \*` that the :c:type:`PyCObject` *self* was 44 47 created with. 45 48 46 49 47 .. c function:: void* PyCObject_GetDesc(PyObject* self)50 .. c:function:: void* PyCObject_GetDesc(PyObject* self) 48 51 49 Return the description :c type:`void \*` that the :ctype:`PyCObject` *self* was52 Return the description :c:type:`void \*` that the :c:type:`PyCObject` *self* was 50 53 created with. 51 54 52 55 53 .. c function:: int PyCObject_SetVoidPtr(PyObject* self, void* cobj)56 .. c:function:: int PyCObject_SetVoidPtr(PyObject* self, void* cobj) 54 57 55 Set the void pointer inside *self* to *cobj*. The :c type:`PyCObject` must not58 Set the void pointer inside *self* to *cobj*. The :c:type:`PyCObject` must not 56 59 have an associated destructor. Return true on success, false on failure. -
python/vendor/current/Doc/c-api/complex.rst
r2 r388 22 22 23 23 24 .. c type:: Py_complex24 .. c:type:: Py_complex 25 25 26 26 The C structure which corresponds to the value portion of a Python complex … … 35 35 36 36 37 .. c function:: Py_complex _Py_c_sum(Py_complex left, Py_complex right)37 .. c:function:: Py_complex _Py_c_sum(Py_complex left, Py_complex right) 38 38 39 Return the sum of two complex numbers, using the C :c type:`Py_complex`39 Return the sum of two complex numbers, using the C :c:type:`Py_complex` 40 40 representation. 41 41 42 42 43 .. c function:: Py_complex _Py_c_diff(Py_complex left, Py_complex right)43 .. c:function:: Py_complex _Py_c_diff(Py_complex left, Py_complex right) 44 44 45 45 Return the difference between two complex numbers, using the C 46 :c type:`Py_complex` representation.46 :c:type:`Py_complex` representation. 47 47 48 48 49 .. c function:: Py_complex _Py_c_neg(Py_complex complex)49 .. c:function:: Py_complex _Py_c_neg(Py_complex complex) 50 50 51 51 Return the negation of the complex number *complex*, using the C 52 :c type:`Py_complex` representation.52 :c:type:`Py_complex` representation. 53 53 54 54 55 .. c function:: Py_complex _Py_c_prod(Py_complex left, Py_complex right)55 .. c:function:: Py_complex _Py_c_prod(Py_complex left, Py_complex right) 56 56 57 Return the product of two complex numbers, using the C :c type:`Py_complex`57 Return the product of two complex numbers, using the C :c:type:`Py_complex` 58 58 representation. 59 59 60 60 61 .. c function:: Py_complex _Py_c_quot(Py_complex dividend, Py_complex divisor)61 .. c:function:: Py_complex _Py_c_quot(Py_complex dividend, Py_complex divisor) 62 62 63 Return the quotient of two complex numbers, using the C :c type:`Py_complex`63 Return the quotient of two complex numbers, using the C :c:type:`Py_complex` 64 64 representation. 65 65 66 If *divisor* is null, this method returns zero and sets 67 :c:data:`errno` to :c:data:`EDOM`. 66 68 67 .. cfunction:: Py_complex _Py_c_pow(Py_complex num, Py_complex exp)68 69 69 Return the exponentiation of *num* by *exp*, using the C :ctype:`Py_complex` 70 .. c:function:: Py_complex _Py_c_pow(Py_complex num, Py_complex exp) 71 72 Return the exponentiation of *num* by *exp*, using the C :c:type:`Py_complex` 70 73 representation. 74 75 If *num* is null and *exp* is not a positive real number, 76 this method returns zero and sets :c:data:`errno` to :c:data:`EDOM`. 71 77 72 78 … … 75 81 76 82 77 .. c type:: PyComplexObject83 .. c:type:: PyComplexObject 78 84 79 This subtype of :c type:`PyObject` represents a Python complex number object.85 This subtype of :c:type:`PyObject` represents a Python complex number object. 80 86 81 87 82 .. c var:: PyTypeObject PyComplex_Type88 .. c:var:: PyTypeObject PyComplex_Type 83 89 84 This instance of :c type:`PyTypeObject` represents the Python complex number90 This instance of :c:type:`PyTypeObject` represents the Python complex number 85 91 type. It is the same object as ``complex`` and ``types.ComplexType``. 86 92 87 93 88 .. c function:: int PyComplex_Check(PyObject *p)94 .. c:function:: int PyComplex_Check(PyObject *p) 89 95 90 Return true if its argument is a :c type:`PyComplexObject` or a subtype of91 :c type:`PyComplexObject`.96 Return true if its argument is a :c:type:`PyComplexObject` or a subtype of 97 :c:type:`PyComplexObject`. 92 98 93 99 .. versionchanged:: 2.2 … … 95 101 96 102 97 .. c function:: int PyComplex_CheckExact(PyObject *p)103 .. c:function:: int PyComplex_CheckExact(PyObject *p) 98 104 99 Return true if its argument is a :c type:`PyComplexObject`, but not a subtype of100 :c type:`PyComplexObject`.105 Return true if its argument is a :c:type:`PyComplexObject`, but not a subtype of 106 :c:type:`PyComplexObject`. 101 107 102 108 .. versionadded:: 2.2 103 109 104 110 105 .. c function:: PyObject* PyComplex_FromCComplex(Py_complex v)111 .. c:function:: PyObject* PyComplex_FromCComplex(Py_complex v) 106 112 107 Create a new Python complex number object from a C :c type:`Py_complex` value.113 Create a new Python complex number object from a C :c:type:`Py_complex` value. 108 114 109 115 110 .. c function:: PyObject* PyComplex_FromDoubles(double real, double imag)116 .. c:function:: PyObject* PyComplex_FromDoubles(double real, double imag) 111 117 112 Return a new :c type:`PyComplexObject` object from *real* and *imag*.118 Return a new :c:type:`PyComplexObject` object from *real* and *imag*. 113 119 114 120 115 .. c function:: double PyComplex_RealAsDouble(PyObject *op)121 .. c:function:: double PyComplex_RealAsDouble(PyObject *op) 116 122 117 Return the real part of *op* as a C :c type:`double`.123 Return the real part of *op* as a C :c:type:`double`. 118 124 119 125 120 .. c function:: double PyComplex_ImagAsDouble(PyObject *op)126 .. c:function:: double PyComplex_ImagAsDouble(PyObject *op) 121 127 122 Return the imaginary part of *op* as a C :c type:`double`.128 Return the imaginary part of *op* as a C :c:type:`double`. 123 129 124 130 125 .. c function:: Py_complex PyComplex_AsCComplex(PyObject *op)131 .. c:function:: Py_complex PyComplex_AsCComplex(PyObject *op) 126 132 127 Return the :ctype:`Py_complex` value of the complex number *op*. 133 Return the :c:type:`Py_complex` value of the complex number *op*. 134 Upon failure, this method returns ``-1.0`` as a real value. 128 135 129 136 .. versionchanged:: 2.6 -
python/vendor/current/Doc/c-api/concrete.rst
r2 r388 12 12 object from a Python program and you are not sure that it has the right type, 13 13 you must perform a type check first; for example, to check that an object is a 14 dictionary, use :c func:`PyDict_Check`. The chapter is structured like the14 dictionary, use :c:func:`PyDict_Check`. The chapter is structured like the 15 15 "family tree" of Python object types. 16 16 … … 101 101 slice.rst 102 102 weakref.rst 103 capsule.rst 103 104 cobject.rst 104 105 cell.rst … … 106 107 datetime.rst 107 108 set.rst 109 code.rst -
python/vendor/current/Doc/c-api/conversion.rst
r2 r388 9 9 10 10 11 .. c function:: int PyOS_snprintf(char *str, size_t size, const char *format, ...)11 .. c:function:: int PyOS_snprintf(char *str, size_t size, const char *format, ...) 12 12 13 13 Output not more than *size* bytes to *str* according to the format string … … 15 15 16 16 17 .. c function:: int PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va)17 .. c:function:: int PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va) 18 18 19 19 Output not more than *size* bytes to *str* according to the format string … … 21 21 :manpage:`vsnprintf(2)`. 22 22 23 :c func:`PyOS_snprintf` and :cfunc:`PyOS_vsnprintf` wrap the Standard C library24 functions :c func:`snprintf` and :cfunc:`vsnprintf`. Their purpose is to23 :c:func:`PyOS_snprintf` and :c:func:`PyOS_vsnprintf` wrap the Standard C library 24 functions :c:func:`snprintf` and :c:func:`vsnprintf`. Their purpose is to 25 25 guarantee consistent behavior in corner cases, which the Standard C functions do 26 26 not. … … 31 31 NULL``. 32 32 33 If the platform doesn't have :c func:`vsnprintf` and the buffer size needed to33 If the platform doesn't have :c:func:`vsnprintf` and the buffer size needed to 34 34 avoid truncation exceeds *size* by more than 512 bytes, Python aborts with a 35 35 *Py_FatalError*. … … 52 52 53 53 54 .. c function:: double PyOS_ascii_strtod(const char *nptr, char **endptr)54 .. c:function:: double PyOS_string_to_double(const char *s, char **endptr, PyObject *overflow_exception) 55 55 56 Convert a string to a :ctype:`double`. This function behaves like the Standard C 57 function :cfunc:`strtod` does in the C locale. It does this without changing the 56 Convert a string ``s`` to a :c:type:`double`, raising a Python 57 exception on failure. The set of accepted strings corresponds to 58 the set of strings accepted by Python's :func:`float` constructor, 59 except that ``s`` must not have leading or trailing whitespace. 60 The conversion is independent of the current locale. 61 62 If ``endptr`` is ``NULL``, convert the whole string. Raise 63 ValueError and return ``-1.0`` if the string is not a valid 64 representation of a floating-point number. 65 66 If endptr is not ``NULL``, convert as much of the string as 67 possible and set ``*endptr`` to point to the first unconverted 68 character. If no initial segment of the string is the valid 69 representation of a floating-point number, set ``*endptr`` to point 70 to the beginning of the string, raise ValueError, and return 71 ``-1.0``. 72 73 If ``s`` represents a value that is too large to store in a float 74 (for example, ``"1e500"`` is such a string on many platforms) then 75 if ``overflow_exception`` is ``NULL`` return ``Py_HUGE_VAL`` (with 76 an appropriate sign) and don't set any exception. Otherwise, 77 ``overflow_exception`` must point to a Python exception object; 78 raise that exception and return ``-1.0``. In both cases, set 79 ``*endptr`` to point to the first character after the converted value. 80 81 If any other error occurs during the conversion (for example an 82 out-of-memory error), set the appropriate Python exception and 83 return ``-1.0``. 84 85 .. versionadded:: 2.7 86 87 88 .. c:function:: double PyOS_ascii_strtod(const char *nptr, char **endptr) 89 90 Convert a string to a :c:type:`double`. This function behaves like the Standard C 91 function :c:func:`strtod` does in the C locale. It does this without changing the 58 92 current locale, since that would not be thread-safe. 59 93 60 :c func:`PyOS_ascii_strtod` should typically be used for reading configuration94 :c:func:`PyOS_ascii_strtod` should typically be used for reading configuration 61 95 files or other non-user input that should be locale independent. 96 97 See the Unix man page :manpage:`strtod(2)` for details. 62 98 63 99 .. versionadded:: 2.4 64 100 65 See the Unix man page :manpage:`strtod(2)` for details. 101 .. deprecated:: 2.7 102 Use :c:func:`PyOS_string_to_double` instead. 66 103 67 104 68 .. cfunction:: char * PyOS_ascii_formatd(char *buffer, size_t buf_len, const char *format, double d)69 105 70 Convert a :ctype:`double` to a string using the ``'.'`` as the decimal 71 separator. *format* is a :cfunc:`printf`\ -style format string specifying the 106 .. c:function:: char* PyOS_ascii_formatd(char *buffer, size_t buf_len, const char *format, double d) 107 108 Convert a :c:type:`double` to a string using the ``'.'`` as the decimal 109 separator. *format* is a :c:func:`printf`\ -style format string specifying the 72 110 number format. Allowed conversion characters are ``'e'``, ``'E'``, ``'f'``, 73 111 ``'F'``, ``'g'`` and ``'G'``. … … 77 115 78 116 .. versionadded:: 2.4 117 .. deprecated:: 2.7 118 This function is removed in Python 2.7 and 3.1. Use :func:`PyOS_double_to_string` 119 instead. 79 120 80 121 81 .. c function:: double PyOS_ascii_atof(const char *nptr)122 .. c:function:: char* PyOS_double_to_string(double val, char format_code, int precision, int flags, int *ptype) 82 123 83 Convert a string to a :ctype:`double` in a locale-independent way. 124 Convert a :c:type:`double` *val* to a string using supplied 125 *format_code*, *precision*, and *flags*. 126 127 *format_code* must be one of ``'e'``, ``'E'``, ``'f'``, ``'F'``, 128 ``'g'``, ``'G'`` or ``'r'``. For ``'r'``, the supplied *precision* 129 must be 0 and is ignored. The ``'r'`` format code specifies the 130 standard :func:`repr` format. 131 132 *flags* can be zero or more of the values *Py_DTSF_SIGN*, 133 *Py_DTSF_ADD_DOT_0*, or *Py_DTSF_ALT*, or-ed together: 134 135 * *Py_DTSF_SIGN* means to always precede the returned string with a sign 136 character, even if *val* is non-negative. 137 138 * *Py_DTSF_ADD_DOT_0* means to ensure that the returned string will not look 139 like an integer. 140 141 * *Py_DTSF_ALT* means to apply "alternate" formatting rules. See the 142 documentation for the :c:func:`PyOS_snprintf` ``'#'`` specifier for 143 details. 144 145 If *ptype* is non-NULL, then the value it points to will be set to one of 146 *Py_DTST_FINITE*, *Py_DTST_INFINITE*, or *Py_DTST_NAN*, signifying that 147 *val* is a finite number, an infinite number, or not a number, respectively. 148 149 The return value is a pointer to *buffer* with the converted string or 150 *NULL* if the conversion failed. The caller is responsible for freeing the 151 returned string by calling :c:func:`PyMem_Free`. 152 153 .. versionadded:: 2.7 154 155 156 .. c:function:: double PyOS_ascii_atof(const char *nptr) 157 158 Convert a string to a :c:type:`double` in a locale-independent way. 159 160 See the Unix man page :manpage:`atof(2)` for details. 84 161 85 162 .. versionadded:: 2.4 86 163 87 See the Unix man page :manpage:`atof(2)` for details. 164 .. deprecated:: 3.1 165 Use :c:func:`PyOS_string_to_double` instead. 88 166 89 167 90 .. c function:: char* PyOS_stricmp(char *s1, char *s2)168 .. c:function:: char* PyOS_stricmp(char *s1, char *s2) 91 169 92 170 Case insensitive comparison of strings. The function works almost 93 identically to :c func:`strcmp` except that it ignores the case.171 identically to :c:func:`strcmp` except that it ignores the case. 94 172 95 173 .. versionadded:: 2.6 96 174 97 175 98 .. c function:: char* PyOS_strnicmp(char *s1, char *s2, Py_ssize_t size)176 .. c:function:: char* PyOS_strnicmp(char *s1, char *s2, Py_ssize_t size) 99 177 100 178 Case insensitive comparison of strings. The function works almost 101 identically to :c func:`strncmp` except that it ignores the case.179 identically to :c:func:`strncmp` except that it ignores the case. 102 180 103 181 .. versionadded:: 2.6 -
python/vendor/current/Doc/c-api/datetime.rst
r2 r388 9 9 Before using any of these functions, the header file :file:`datetime.h` must be 10 10 included in your source (note that this is not included by :file:`Python.h`), 11 and the macro :cfunc:`PyDateTime_IMPORT` must be invoked. The macro puts a 12 pointer to a C structure into a static variable, ``PyDateTimeAPI``, that is 13 used by the following macros. 11 and the macro :c:macro:`PyDateTime_IMPORT` must be invoked, usually as part of 12 the module initialisation function. The macro puts a pointer to a C structure 13 into a static variable, :c:data:`PyDateTimeAPI`, that is used by the following 14 macros. 14 15 15 16 Type-check macros: 16 17 17 18 18 .. c function:: int PyDate_Check(PyObject *ob)19 20 Return true if *ob* is of type :c data:`PyDateTime_DateType` or a subtype of21 :c data:`PyDateTime_DateType`. *ob* must not be *NULL*.22 23 .. versionadded:: 2.4 24 25 26 .. c function:: int PyDate_CheckExact(PyObject *ob)27 28 Return true if *ob* is of type :c data:`PyDateTime_DateType`. *ob* must not be29 *NULL*. 30 31 .. versionadded:: 2.4 32 33 34 .. c function:: int PyDateTime_Check(PyObject *ob)35 36 Return true if *ob* is of type :c data:`PyDateTime_DateTimeType` or a subtype of37 :c data:`PyDateTime_DateTimeType`. *ob* must not be *NULL*.38 39 .. versionadded:: 2.4 40 41 42 .. c function:: int PyDateTime_CheckExact(PyObject *ob)43 44 Return true if *ob* is of type :c data:`PyDateTime_DateTimeType`. *ob* must not19 .. c:function:: int PyDate_Check(PyObject *ob) 20 21 Return true if *ob* is of type :c:data:`PyDateTime_DateType` or a subtype of 22 :c:data:`PyDateTime_DateType`. *ob* must not be *NULL*. 23 24 .. versionadded:: 2.4 25 26 27 .. c:function:: int PyDate_CheckExact(PyObject *ob) 28 29 Return true if *ob* is of type :c:data:`PyDateTime_DateType`. *ob* must not be 30 *NULL*. 31 32 .. versionadded:: 2.4 33 34 35 .. c:function:: int PyDateTime_Check(PyObject *ob) 36 37 Return true if *ob* is of type :c:data:`PyDateTime_DateTimeType` or a subtype of 38 :c:data:`PyDateTime_DateTimeType`. *ob* must not be *NULL*. 39 40 .. versionadded:: 2.4 41 42 43 .. c:function:: int PyDateTime_CheckExact(PyObject *ob) 44 45 Return true if *ob* is of type :c:data:`PyDateTime_DateTimeType`. *ob* must not 45 46 be *NULL*. 46 47 … … 48 49 49 50 50 .. c function:: int PyTime_Check(PyObject *ob)51 52 Return true if *ob* is of type :c data:`PyDateTime_TimeType` or a subtype of53 :c data:`PyDateTime_TimeType`. *ob* must not be *NULL*.54 55 .. versionadded:: 2.4 56 57 58 .. c function:: int PyTime_CheckExact(PyObject *ob)59 60 Return true if *ob* is of type :c data:`PyDateTime_TimeType`. *ob* must not be61 *NULL*. 62 63 .. versionadded:: 2.4 64 65 66 .. c function:: int PyDelta_Check(PyObject *ob)67 68 Return true if *ob* is of type :c data:`PyDateTime_DeltaType` or a subtype of69 :c data:`PyDateTime_DeltaType`. *ob* must not be *NULL*.70 71 .. versionadded:: 2.4 72 73 74 .. c function:: int PyDelta_CheckExact(PyObject *ob)75 76 Return true if *ob* is of type :c data:`PyDateTime_DeltaType`. *ob* must not be77 *NULL*. 78 79 .. versionadded:: 2.4 80 81 82 .. c function:: int PyTZInfo_Check(PyObject *ob)83 84 Return true if *ob* is of type :c data:`PyDateTime_TZInfoType` or a subtype of85 :c data:`PyDateTime_TZInfoType`. *ob* must not be *NULL*.86 87 .. versionadded:: 2.4 88 89 90 .. c function:: int PyTZInfo_CheckExact(PyObject *ob)91 92 Return true if *ob* is of type :c data:`PyDateTime_TZInfoType`. *ob* must not be51 .. c:function:: int PyTime_Check(PyObject *ob) 52 53 Return true if *ob* is of type :c:data:`PyDateTime_TimeType` or a subtype of 54 :c:data:`PyDateTime_TimeType`. *ob* must not be *NULL*. 55 56 .. versionadded:: 2.4 57 58 59 .. c:function:: int PyTime_CheckExact(PyObject *ob) 60 61 Return true if *ob* is of type :c:data:`PyDateTime_TimeType`. *ob* must not be 62 *NULL*. 63 64 .. versionadded:: 2.4 65 66 67 .. c:function:: int PyDelta_Check(PyObject *ob) 68 69 Return true if *ob* is of type :c:data:`PyDateTime_DeltaType` or a subtype of 70 :c:data:`PyDateTime_DeltaType`. *ob* must not be *NULL*. 71 72 .. versionadded:: 2.4 73 74 75 .. c:function:: int PyDelta_CheckExact(PyObject *ob) 76 77 Return true if *ob* is of type :c:data:`PyDateTime_DeltaType`. *ob* must not be 78 *NULL*. 79 80 .. versionadded:: 2.4 81 82 83 .. c:function:: int PyTZInfo_Check(PyObject *ob) 84 85 Return true if *ob* is of type :c:data:`PyDateTime_TZInfoType` or a subtype of 86 :c:data:`PyDateTime_TZInfoType`. *ob* must not be *NULL*. 87 88 .. versionadded:: 2.4 89 90 91 .. c:function:: int PyTZInfo_CheckExact(PyObject *ob) 92 93 Return true if *ob* is of type :c:data:`PyDateTime_TZInfoType`. *ob* must not be 93 94 *NULL*. 94 95 … … 98 99 99 100 100 .. c function:: PyObject* PyDate_FromDate(int year, int month, int day)101 .. c:function:: PyObject* PyDate_FromDate(int year, int month, int day) 101 102 102 103 Return a ``datetime.date`` object with the specified year, month and day. … … 105 106 106 107 107 .. c function:: PyObject* PyDateTime_FromDateAndTime(int year, int month, int day, int hour, int minute, int second, int usecond)108 .. c:function:: PyObject* PyDateTime_FromDateAndTime(int year, int month, int day, int hour, int minute, int second, int usecond) 108 109 109 110 Return a ``datetime.datetime`` object with the specified year, month, day, hour, … … 113 114 114 115 115 .. c function:: PyObject* PyTime_FromTime(int hour, int minute, int second, int usecond)116 .. c:function:: PyObject* PyTime_FromTime(int hour, int minute, int second, int usecond) 116 117 117 118 Return a ``datetime.time`` object with the specified hour, minute, second and … … 121 122 122 123 123 .. c function:: PyObject* PyDelta_FromDSU(int days, int seconds, int useconds)124 .. c:function:: PyObject* PyDelta_FromDSU(int days, int seconds, int useconds) 124 125 125 126 Return a ``datetime.timedelta`` object representing the given number of days, … … 131 132 132 133 Macros to extract fields from date objects. The argument must be an instance of 133 :c data:`PyDateTime_Date`, including subclasses (such as134 :c data:`PyDateTime_DateTime`). The argument must not be *NULL*, and the type is134 :c:data:`PyDateTime_Date`, including subclasses (such as 135 :c:data:`PyDateTime_DateTime`). The argument must not be *NULL*, and the type is 135 136 not checked: 136 137 137 138 138 .. c function:: int PyDateTime_GET_YEAR(PyDateTime_Date *o)139 .. c:function:: int PyDateTime_GET_YEAR(PyDateTime_Date *o) 139 140 140 141 Return the year, as a positive int. … … 143 144 144 145 145 .. c function:: int PyDateTime_GET_MONTH(PyDateTime_Date *o)146 .. c:function:: int PyDateTime_GET_MONTH(PyDateTime_Date *o) 146 147 147 148 Return the month, as an int from 1 through 12. … … 150 151 151 152 152 .. c function:: int PyDateTime_GET_DAY(PyDateTime_Date *o)153 .. c:function:: int PyDateTime_GET_DAY(PyDateTime_Date *o) 153 154 154 155 Return the day, as an int from 1 through 31. … … 157 158 158 159 Macros to extract fields from datetime objects. The argument must be an 159 instance of :c data:`PyDateTime_DateTime`, including subclasses. The argument160 instance of :c:data:`PyDateTime_DateTime`, including subclasses. The argument 160 161 must not be *NULL*, and the type is not checked: 161 162 162 163 163 .. c function:: int PyDateTime_DATE_GET_HOUR(PyDateTime_DateTime *o)164 .. c:function:: int PyDateTime_DATE_GET_HOUR(PyDateTime_DateTime *o) 164 165 165 166 Return the hour, as an int from 0 through 23. … … 168 169 169 170 170 .. c function:: int PyDateTime_DATE_GET_MINUTE(PyDateTime_DateTime *o)171 .. c:function:: int PyDateTime_DATE_GET_MINUTE(PyDateTime_DateTime *o) 171 172 172 173 Return the minute, as an int from 0 through 59. … … 175 176 176 177 177 .. c function:: int PyDateTime_DATE_GET_SECOND(PyDateTime_DateTime *o)178 .. c:function:: int PyDateTime_DATE_GET_SECOND(PyDateTime_DateTime *o) 178 179 179 180 Return the second, as an int from 0 through 59. … … 182 183 183 184 184 .. c function:: int PyDateTime_DATE_GET_MICROSECOND(PyDateTime_DateTime *o)185 .. c:function:: int PyDateTime_DATE_GET_MICROSECOND(PyDateTime_DateTime *o) 185 186 186 187 Return the microsecond, as an int from 0 through 999999. … … 189 190 190 191 Macros to extract fields from time objects. The argument must be an instance of 191 :c data:`PyDateTime_Time`, including subclasses. The argument must not be *NULL*,192 :c:data:`PyDateTime_Time`, including subclasses. The argument must not be *NULL*, 192 193 and the type is not checked: 193 194 194 195 195 .. c function:: int PyDateTime_TIME_GET_HOUR(PyDateTime_Time *o)196 .. c:function:: int PyDateTime_TIME_GET_HOUR(PyDateTime_Time *o) 196 197 197 198 Return the hour, as an int from 0 through 23. … … 200 201 201 202 202 .. c function:: int PyDateTime_TIME_GET_MINUTE(PyDateTime_Time *o)203 .. c:function:: int PyDateTime_TIME_GET_MINUTE(PyDateTime_Time *o) 203 204 204 205 Return the minute, as an int from 0 through 59. … … 207 208 208 209 209 .. c function:: int PyDateTime_TIME_GET_SECOND(PyDateTime_Time *o)210 .. c:function:: int PyDateTime_TIME_GET_SECOND(PyDateTime_Time *o) 210 211 211 212 Return the second, as an int from 0 through 59. … … 214 215 215 216 216 .. c function:: int PyDateTime_TIME_GET_MICROSECOND(PyDateTime_Time *o)217 .. c:function:: int PyDateTime_TIME_GET_MICROSECOND(PyDateTime_Time *o) 217 218 218 219 Return the microsecond, as an int from 0 through 999999. … … 223 224 224 225 225 .. c function:: PyObject* PyDateTime_FromTimestamp(PyObject *args)226 .. c:function:: PyObject* PyDateTime_FromTimestamp(PyObject *args) 226 227 227 228 Create and return a new ``datetime.datetime`` object given an argument tuple … … 231 232 232 233 233 .. c function:: PyObject* PyDate_FromTimestamp(PyObject *args)234 .. c:function:: PyObject* PyDate_FromTimestamp(PyObject *args) 234 235 235 236 Create and return a new ``datetime.date`` object given an argument tuple -
python/vendor/current/Doc/c-api/descriptor.rst
r2 r388 10 10 11 11 12 .. c var:: PyTypeObject PyProperty_Type12 .. c:var:: PyTypeObject PyProperty_Type 13 13 14 14 The type object for the built-in descriptor types. … … 17 17 18 18 19 .. c function:: PyObject* PyDescr_NewGetSet(PyTypeObject *type, struct PyGetSetDef *getset)19 .. c:function:: PyObject* PyDescr_NewGetSet(PyTypeObject *type, struct PyGetSetDef *getset) 20 20 21 21 .. versionadded:: 2.2 22 22 23 23 24 .. c function:: PyObject* PyDescr_NewMember(PyTypeObject *type, struct PyMemberDef *meth)24 .. c:function:: PyObject* PyDescr_NewMember(PyTypeObject *type, struct PyMemberDef *meth) 25 25 26 26 .. versionadded:: 2.2 27 27 28 28 29 .. c function:: PyObject* PyDescr_NewMethod(PyTypeObject *type, struct PyMethodDef *meth)29 .. c:function:: PyObject* PyDescr_NewMethod(PyTypeObject *type, struct PyMethodDef *meth) 30 30 31 31 .. versionadded:: 2.2 32 32 33 33 34 .. c function:: PyObject* PyDescr_NewWrapper(PyTypeObject *type, struct wrapperbase *wrapper, void *wrapped)34 .. c:function:: PyObject* PyDescr_NewWrapper(PyTypeObject *type, struct wrapperbase *wrapper, void *wrapped) 35 35 36 36 .. versionadded:: 2.2 37 37 38 38 39 .. c function:: PyObject* PyDescr_NewClassMethod(PyTypeObject *type, PyMethodDef *method)39 .. c:function:: PyObject* PyDescr_NewClassMethod(PyTypeObject *type, PyMethodDef *method) 40 40 41 41 .. versionadded:: 2.3 42 42 43 43 44 .. c function:: int PyDescr_IsData(PyObject *descr)44 .. c:function:: int PyDescr_IsData(PyObject *descr) 45 45 46 46 Return true if the descriptor objects *descr* describes a data attribute, or … … 51 51 52 52 53 .. c function:: PyObject* PyWrapper_New(PyObject *, PyObject *)53 .. c:function:: PyObject* PyWrapper_New(PyObject *, PyObject *) 54 54 55 55 .. versionadded:: 2.2 -
python/vendor/current/Doc/c-api/dict.rst
r2 r388 9 9 10 10 11 .. c type:: PyDictObject12 13 This subtype of :c type:`PyObject` represents a Python dictionary object.14 15 16 .. c var:: PyTypeObject PyDict_Type11 .. c:type:: PyDictObject 12 13 This subtype of :c:type:`PyObject` represents a Python dictionary object. 14 15 16 .. c:var:: PyTypeObject PyDict_Type 17 17 18 18 .. index:: … … 20 20 single: DictionaryType (in module types) 21 21 22 This instance of :c type:`PyTypeObject` represents the Python dictionary22 This instance of :c:type:`PyTypeObject` represents the Python dictionary 23 23 type. This is exposed to Python programs as ``dict`` and 24 24 ``types.DictType``. 25 25 26 26 27 .. c function:: int PyDict_Check(PyObject *p)27 .. c:function:: int PyDict_Check(PyObject *p) 28 28 29 29 Return true if *p* is a dict object or an instance of a subtype of the dict … … 34 34 35 35 36 .. c function:: int PyDict_CheckExact(PyObject *p)36 .. c:function:: int PyDict_CheckExact(PyObject *p) 37 37 38 38 Return true if *p* is a dict object, but not an instance of a subtype of … … 42 42 43 43 44 .. c function:: PyObject* PyDict_New()44 .. c:function:: PyObject* PyDict_New() 45 45 46 46 Return a new empty dictionary, or *NULL* on failure. 47 47 48 48 49 .. c function:: PyObject* PyDictProxy_New(PyObject *dict)49 .. c:function:: PyObject* PyDictProxy_New(PyObject *dict) 50 50 51 51 Return a proxy object for a mapping which enforces read-only behavior. … … 56 56 57 57 58 .. c function:: void PyDict_Clear(PyObject *p)58 .. c:function:: void PyDict_Clear(PyObject *p) 59 59 60 60 Empty an existing dictionary of all key-value pairs. 61 61 62 62 63 .. c function:: int PyDict_Contains(PyObject *p, PyObject *key)63 .. c:function:: int PyDict_Contains(PyObject *p, PyObject *key) 64 64 65 65 Determine if dictionary *p* contains *key*. If an item in *p* is matches … … 70 70 71 71 72 .. c function:: PyObject* PyDict_Copy(PyObject *p)72 .. c:function:: PyObject* PyDict_Copy(PyObject *p) 73 73 74 74 Return a new dictionary that contains the same key-value pairs as *p*. … … 77 77 78 78 79 .. c function:: int PyDict_SetItem(PyObject *p, PyObject *key, PyObject *val)79 .. c:function:: int PyDict_SetItem(PyObject *p, PyObject *key, PyObject *val) 80 80 81 81 Insert *value* into the dictionary *p* with a key of *key*. *key* must be … … 84 84 85 85 86 .. c function:: int PyDict_SetItemString(PyObject *p, const char *key, PyObject *val)86 .. c:function:: int PyDict_SetItemString(PyObject *p, const char *key, PyObject *val) 87 87 88 88 .. index:: single: PyString_FromString() 89 89 90 90 Insert *value* into the dictionary *p* using *key* as a key. *key* should 91 be a :c type:`char\*`. The key object is created using91 be a :c:type:`char\*`. The key object is created using 92 92 ``PyString_FromString(key)``. Return ``0`` on success or ``-1`` on 93 93 failure. 94 94 95 95 96 .. c function:: int PyDict_DelItem(PyObject *p, PyObject *key)96 .. c:function:: int PyDict_DelItem(PyObject *p, PyObject *key) 97 97 98 98 Remove the entry in dictionary *p* with key *key*. *key* must be hashable; … … 101 101 102 102 103 .. c function:: int PyDict_DelItemString(PyObject *p, char *key)103 .. c:function:: int PyDict_DelItemString(PyObject *p, char *key) 104 104 105 105 Remove the entry in dictionary *p* which has a key specified by the string … … 107 107 108 108 109 .. c function:: PyObject* PyDict_GetItem(PyObject *p, PyObject *key)109 .. c:function:: PyObject* PyDict_GetItem(PyObject *p, PyObject *key) 110 110 111 111 Return the object from dictionary *p* which has a key *key*. Return *NULL* … … 113 113 114 114 115 .. c function:: PyObject* PyDict_GetItemString(PyObject *p, const char *key)116 117 This is the same as :c func:`PyDict_GetItem`, but *key* is specified as a118 :c type:`char\*`, rather than a :ctype:`PyObject\*`.119 120 121 .. c function:: PyObject* PyDict_Items(PyObject *p)122 123 Return a :c type:`PyListObject` containing all the items from the115 .. c:function:: PyObject* PyDict_GetItemString(PyObject *p, const char *key) 116 117 This is the same as :c:func:`PyDict_GetItem`, but *key* is specified as a 118 :c:type:`char\*`, rather than a :c:type:`PyObject\*`. 119 120 121 .. c:function:: PyObject* PyDict_Items(PyObject *p) 122 123 Return a :c:type:`PyListObject` containing all the items from the 124 124 dictionary, as in the dictionary method :meth:`dict.items`. 125 125 126 126 127 .. c function:: PyObject* PyDict_Keys(PyObject *p)128 129 Return a :c type:`PyListObject` containing all the keys from the dictionary,127 .. c:function:: PyObject* PyDict_Keys(PyObject *p) 128 129 Return a :c:type:`PyListObject` containing all the keys from the dictionary, 130 130 as in the dictionary method :meth:`dict.keys`. 131 131 132 132 133 .. c function:: PyObject* PyDict_Values(PyObject *p)134 135 Return a :c type:`PyListObject` containing all the values from the133 .. c:function:: PyObject* PyDict_Values(PyObject *p) 134 135 Return a :c:type:`PyListObject` containing all the values from the 136 136 dictionary *p*, as in the dictionary method :meth:`dict.values`. 137 137 138 138 139 .. c function:: Py_ssize_t PyDict_Size(PyObject *p)139 .. c:function:: Py_ssize_t PyDict_Size(PyObject *p) 140 140 141 141 .. index:: builtin: len … … 145 145 146 146 .. versionchanged:: 2.5 147 This function returned an :c type:`int` type. This might require changes147 This function returned an :c:type:`int` type. This might require changes 148 148 in your code for properly supporting 64-bit systems. 149 149 150 150 151 .. c function:: int PyDict_Next(PyObject *p, Py_ssize_t *ppos, PyObject **pkey, PyObject **pvalue)151 .. c:function:: int PyDict_Next(PyObject *p, Py_ssize_t *ppos, PyObject **pkey, PyObject **pvalue) 152 152 153 153 Iterate over all key-value pairs in the dictionary *p*. The 154 :c type:`Py_ssize_t` referred to by *ppos* must be initialized to ``0``154 :c:type:`Py_ssize_t` referred to by *ppos* must be initialized to ``0`` 155 155 prior to the first call to this function to start the iteration; the 156 156 function returns true for each pair in the dictionary, and false once all 157 157 pairs have been reported. The parameters *pkey* and *pvalue* should either 158 point to :c type:`PyObject\*` variables that will be filled in with each key158 point to :c:type:`PyObject\*` variables that will be filled in with each key 159 159 and value, respectively, or may be *NULL*. Any references returned through 160 160 them are borrowed. *ppos* should not be altered during iteration. Its … … 193 193 194 194 .. versionchanged:: 2.5 195 This function used an :c type:`int *` type for *ppos*. This might require195 This function used an :c:type:`int *` type for *ppos*. This might require 196 196 changes in your code for properly supporting 64-bit systems. 197 197 198 198 199 .. c function:: int PyDict_Merge(PyObject *a, PyObject *b, int override)199 .. c:function:: int PyDict_Merge(PyObject *a, PyObject *b, int override) 200 200 201 201 Iterate over mapping object *b* adding key-value pairs to dictionary *a*. 202 *b* may be a dictionary, or any object supporting : func:`PyMapping_Keys`203 and : func:`PyObject_GetItem`. If *override* is true, existing pairs in *a*202 *b* may be a dictionary, or any object supporting :c:func:`PyMapping_Keys` 203 and :c:func:`PyObject_GetItem`. If *override* is true, existing pairs in *a* 204 204 will be replaced if a matching key is found in *b*, otherwise pairs will 205 205 only be added if there is not a matching key in *a*. Return ``0`` on … … 209 209 210 210 211 .. c function:: int PyDict_Update(PyObject *a, PyObject *b)211 .. c:function:: int PyDict_Update(PyObject *a, PyObject *b) 212 212 213 213 This is the same as ``PyDict_Merge(a, b, 1)`` in C, or ``a.update(b)`` in … … 217 217 218 218 219 .. c function:: int PyDict_MergeFromSeq2(PyObject *a, PyObject *seq2, int override)219 .. c:function:: int PyDict_MergeFromSeq2(PyObject *a, PyObject *seq2, int override) 220 220 221 221 Update or merge into dictionary *a*, from the key-value pairs in *seq2*. -
python/vendor/current/Doc/c-api/exceptions.rst
r2 r388 10 10 The functions described in this chapter will let you handle and raise Python 11 11 exceptions. It is important to understand some of the basics of Python 12 exception handling. It works somewhat like the Unix :c data:`errno` variable:12 exception handling. It works somewhat like the Unix :c:data:`errno` variable: 13 13 there is a global indicator (per thread) of the last error that occurred. Most 14 14 functions don't clear this on success, but will set it to indicate the cause of 15 15 the error on failure. Most functions also return an error indicator, usually 16 16 *NULL* if they are supposed to return a pointer, or ``-1`` if they return an 17 integer (exception: the :c func:`PyArg_\*` functions return ``1`` for success and17 integer (exception: the :c:func:`PyArg_\*` functions return ``1`` for success and 18 18 ``0`` for failure). 19 19 … … 42 42 43 43 44 .. c function:: void PyErr_PrintEx(int set_sys_last_vars)44 .. c:function:: void PyErr_PrintEx(int set_sys_last_vars) 45 45 46 46 Print a standard traceback to ``sys.stderr`` and clear the error indicator. … … 53 53 54 54 55 .. c function:: void PyErr_Print()55 .. c:function:: void PyErr_Print() 56 56 57 57 Alias for ``PyErr_PrintEx(1)``. 58 58 59 59 60 .. c function:: PyObject* PyErr_Occurred()60 .. c:function:: PyObject* PyErr_Occurred() 61 61 62 62 Test whether the error indicator is set. If set, return the exception *type* 63 (the first argument to the last call to one of the :c func:`PyErr_Set\*`64 functions or to :c func:`PyErr_Restore`). If not set, return *NULL*. You do not65 own a reference to the return value, so you do not need to :c func:`Py_DECREF`63 (the first argument to the last call to one of the :c:func:`PyErr_Set\*` 64 functions or to :c:func:`PyErr_Restore`). If not set, return *NULL*. You do not 65 own a reference to the return value, so you do not need to :c:func:`Py_DECREF` 66 66 it. 67 67 … … 69 69 70 70 Do not compare the return value to a specific exception; use 71 :c func:`PyErr_ExceptionMatches` instead, shown below. (The comparison could71 :c:func:`PyErr_ExceptionMatches` instead, shown below. (The comparison could 72 72 easily fail since the exception may be an instance instead of a class, in the 73 73 case of a class exception, or it may the a subclass of the expected exception.) 74 74 75 75 76 .. c function:: int PyErr_ExceptionMatches(PyObject *exc)76 .. c:function:: int PyErr_ExceptionMatches(PyObject *exc) 77 77 78 78 Equivalent to ``PyErr_GivenExceptionMatches(PyErr_Occurred(), exc)``. This … … 81 81 82 82 83 .. c function:: int PyErr_GivenExceptionMatches(PyObject *given, PyObject *exc)83 .. c:function:: int PyErr_GivenExceptionMatches(PyObject *given, PyObject *exc) 84 84 85 85 Return true if the *given* exception matches the exception in *exc*. If … … 89 89 90 90 91 .. c function:: void PyErr_NormalizeException(PyObject**exc, PyObject**val, PyObject**tb)92 93 Under certain circumstances, the values returned by :c func:`PyErr_Fetch` below91 .. c:function:: void PyErr_NormalizeException(PyObject**exc, PyObject**val, PyObject**tb) 92 93 Under certain circumstances, the values returned by :c:func:`PyErr_Fetch` below 94 94 can be "unnormalized", meaning that ``*exc`` is a class object but ``*val`` is 95 95 not an instance of the same class. This function can be used to instantiate … … 98 98 99 99 100 .. c function:: void PyErr_Clear()100 .. c:function:: void PyErr_Clear() 101 101 102 102 Clear the error indicator. If the error indicator is not set, there is no … … 104 104 105 105 106 .. c function:: void PyErr_Fetch(PyObject **ptype, PyObject **pvalue, PyObject **ptraceback)106 .. c:function:: void PyErr_Fetch(PyObject **ptype, PyObject **pvalue, PyObject **ptraceback) 107 107 108 108 Retrieve the error indicator into three variables whose addresses are passed. … … 117 117 118 118 119 .. c function:: void PyErr_Restore(PyObject *type, PyObject *value, PyObject *traceback)119 .. c:function:: void PyErr_Restore(PyObject *type, PyObject *value, PyObject *traceback) 120 120 121 121 Set the error indicator from the three objects. If the error indicator is … … 132 132 133 133 This function is normally only used by code that needs to save and restore the 134 error indicator temporarily; use :c func:`PyErr_Fetch` to save the current134 error indicator temporarily; use :c:func:`PyErr_Fetch` to save the current 135 135 exception state. 136 136 137 137 138 .. c function:: void PyErr_SetString(PyObject *type, const char *message)138 .. c:function:: void PyErr_SetString(PyObject *type, const char *message) 139 139 140 140 This is the most common way to set the error indicator. The first argument 141 141 specifies the exception type; it is normally one of the standard exceptions, 142 e.g. :c data:`PyExc_RuntimeError`. You need not increment its reference count.142 e.g. :c:data:`PyExc_RuntimeError`. You need not increment its reference count. 143 143 The second argument is an error message; it is converted to a string object. 144 144 145 145 146 .. c function:: void PyErr_SetObject(PyObject *type, PyObject *value)147 148 This function is similar to :c func:`PyErr_SetString` but lets you specify an146 .. c:function:: void PyErr_SetObject(PyObject *type, PyObject *value) 147 148 This function is similar to :c:func:`PyErr_SetString` but lets you specify an 149 149 arbitrary Python object for the "value" of the exception. 150 150 151 151 152 .. cfunction:: PyObject* PyErr_Format(PyObject *exception, const char *format, ...) 153 154 This function sets the error indicator and returns *NULL*. *exception* should be 155 a Python exception (class, not an instance). *format* should be a string, 156 containing format codes, similar to :cfunc:`printf`. The ``width.precision`` 157 before a format code is parsed, but the width part is ignored. 158 159 .. % This should be exactly the same as the table in PyString_FromFormat. 160 .. % One should just refer to the other. 161 .. % The descriptions for %zd and %zu are wrong, but the truth is complicated 162 .. % because not all compilers support the %z width modifier -- we fake it 163 .. % when necessary via interpolating PY_FORMAT_SIZE_T. 164 .. % %u, %lu, %zu should have "new in Python 2.5" blurbs. 165 166 +-------------------+---------------+--------------------------------+ 167 | Format Characters | Type | Comment | 168 +===================+===============+================================+ 169 | :attr:`%%` | *n/a* | The literal % character. | 170 +-------------------+---------------+--------------------------------+ 171 | :attr:`%c` | int | A single character, | 172 | | | represented as an C int. | 173 +-------------------+---------------+--------------------------------+ 174 | :attr:`%d` | int | Exactly equivalent to | 175 | | | ``printf("%d")``. | 176 +-------------------+---------------+--------------------------------+ 177 | :attr:`%u` | unsigned int | Exactly equivalent to | 178 | | | ``printf("%u")``. | 179 +-------------------+---------------+--------------------------------+ 180 | :attr:`%ld` | long | Exactly equivalent to | 181 | | | ``printf("%ld")``. | 182 +-------------------+---------------+--------------------------------+ 183 | :attr:`%lu` | unsigned long | Exactly equivalent to | 184 | | | ``printf("%lu")``. | 185 +-------------------+---------------+--------------------------------+ 186 | :attr:`%zd` | Py_ssize_t | Exactly equivalent to | 187 | | | ``printf("%zd")``. | 188 +-------------------+---------------+--------------------------------+ 189 | :attr:`%zu` | size_t | Exactly equivalent to | 190 | | | ``printf("%zu")``. | 191 +-------------------+---------------+--------------------------------+ 192 | :attr:`%i` | int | Exactly equivalent to | 193 | | | ``printf("%i")``. | 194 +-------------------+---------------+--------------------------------+ 195 | :attr:`%x` | int | Exactly equivalent to | 196 | | | ``printf("%x")``. | 197 +-------------------+---------------+--------------------------------+ 198 | :attr:`%s` | char\* | A null-terminated C character | 199 | | | array. | 200 +-------------------+---------------+--------------------------------+ 201 | :attr:`%p` | void\* | The hex representation of a C | 202 | | | pointer. Mostly equivalent to | 203 | | | ``printf("%p")`` except that | 204 | | | it is guaranteed to start with | 205 | | | the literal ``0x`` regardless | 206 | | | of what the platform's | 207 | | | ``printf`` yields. | 208 +-------------------+---------------+--------------------------------+ 209 210 An unrecognized format character causes all the rest of the format string to be 211 copied as-is to the result string, and any extra arguments discarded. 212 213 214 .. cfunction:: void PyErr_SetNone(PyObject *type) 152 .. c:function:: PyObject* PyErr_Format(PyObject *exception, const char *format, ...) 153 154 This function sets the error indicator and returns *NULL*. *exception* 155 should be a Python exception class. The *format* and subsequent 156 parameters help format the error message; they have the same meaning and 157 values as in :c:func:`PyString_FromFormat`. 158 159 160 .. c:function:: void PyErr_SetNone(PyObject *type) 215 161 216 162 This is a shorthand for ``PyErr_SetObject(type, Py_None)``. 217 163 218 164 219 .. c function:: int PyErr_BadArgument()165 .. c:function:: int PyErr_BadArgument() 220 166 221 167 This is a shorthand for ``PyErr_SetString(PyExc_TypeError, message)``, where … … 224 170 225 171 226 .. c function:: PyObject* PyErr_NoMemory()172 .. c:function:: PyObject* PyErr_NoMemory() 227 173 228 174 This is a shorthand for ``PyErr_SetNone(PyExc_MemoryError)``; it returns *NULL* … … 231 177 232 178 233 .. c function:: PyObject* PyErr_SetFromErrno(PyObject *type)179 .. c:function:: PyObject* PyErr_SetFromErrno(PyObject *type) 234 180 235 181 .. index:: single: strerror() 236 182 237 183 This is a convenience function to raise an exception when a C library function 238 has returned an error and set the C variable :c data:`errno`. It constructs a239 tuple object whose first item is the integer :c data:`errno` value and whose240 second item is the corresponding error message (gotten from :c func:`strerror`),184 has returned an error and set the C variable :c:data:`errno`. It constructs a 185 tuple object whose first item is the integer :c:data:`errno` value and whose 186 second item is the corresponding error message (gotten from :c:func:`strerror`), 241 187 and then calls ``PyErr_SetObject(type, object)``. On Unix, when the 242 :c data:`errno` value is :const:`EINTR`, indicating an interrupted system call,243 this calls :c func:`PyErr_CheckSignals`, and if that set the error indicator,188 :c:data:`errno` value is :const:`EINTR`, indicating an interrupted system call, 189 this calls :c:func:`PyErr_CheckSignals`, and if that set the error indicator, 244 190 leaves it set to that. The function always returns *NULL*, so a wrapper 245 191 function around a system call can write ``return PyErr_SetFromErrno(type);`` … … 247 193 248 194 249 .. cfunction:: PyObject* PyErr_SetFromErrnoWithFilename(PyObject *type, const char *filename) 250 251 Similar to :cfunc:`PyErr_SetFromErrno`, with the additional behavior that if 252 *filename* is not *NULL*, it is passed to the constructor of *type* as a third 253 parameter. In the case of exceptions such as :exc:`IOError` and :exc:`OSError`, 254 this is used to define the :attr:`filename` attribute of the exception instance. 255 256 257 .. cfunction:: PyObject* PyErr_SetFromWindowsErr(int ierr) 195 .. c:function:: PyObject* PyErr_SetFromErrnoWithFilenameObject(PyObject *type, PyObject *filenameObject) 196 197 Similar to :c:func:`PyErr_SetFromErrno`, with the additional behavior that if 198 *filenameObject* is not *NULL*, it is passed to the constructor of *type* as 199 a third parameter. In the case of exceptions such as :exc:`IOError` and 200 :exc:`OSError`, this is used to define the :attr:`filename` attribute of the 201 exception instance. 202 203 204 .. c:function:: PyObject* PyErr_SetFromErrnoWithFilename(PyObject *type, const char *filename) 205 206 Similar to :c:func:`PyErr_SetFromErrnoWithFilenameObject`, but the filename 207 is given as a C string. 208 209 210 .. c:function:: PyObject* PyErr_SetFromWindowsErr(int ierr) 258 211 259 212 This is a convenience function to raise :exc:`WindowsError`. If called with 260 *ierr* of :c data:`0`, the error code returned by a call to :cfunc:`GetLastError`261 is used instead. It calls the Win32 function :c func:`FormatMessage` to retrieve262 the Windows description of error code given by *ierr* or :c func:`GetLastError`,213 *ierr* of :c:data:`0`, the error code returned by a call to :c:func:`GetLastError` 214 is used instead. It calls the Win32 function :c:func:`FormatMessage` to retrieve 215 the Windows description of error code given by *ierr* or :c:func:`GetLastError`, 263 216 then it constructs a tuple object whose first item is the *ierr* value and whose 264 217 second item is the corresponding error message (gotten from 265 :c func:`FormatMessage`), and then calls ``PyErr_SetObject(PyExc_WindowsError,218 :c:func:`FormatMessage`), and then calls ``PyErr_SetObject(PyExc_WindowsError, 266 219 object)``. This function always returns *NULL*. Availability: Windows. 267 220 268 221 269 .. c function:: PyObject* PyErr_SetExcFromWindowsErr(PyObject *type, int ierr)270 271 Similar to :c func:`PyErr_SetFromWindowsErr`, with an additional parameter222 .. c:function:: PyObject* PyErr_SetExcFromWindowsErr(PyObject *type, int ierr) 223 224 Similar to :c:func:`PyErr_SetFromWindowsErr`, with an additional parameter 272 225 specifying the exception type to be raised. Availability: Windows. 273 226 … … 275 228 276 229 277 .. c function:: PyObject* PyErr_SetFromWindowsErrWithFilename(int ierr, const char *filename)278 279 Similar to :c func:`PyErr_SetFromWindowsErr`, with the additional behavior that280 if *filename * is not *NULL*, it is passed to the constructor of230 .. c:function:: PyObject* PyErr_SetFromWindowsErrWithFilenameObject(int ierr, PyObject *filenameObject) 231 232 Similar to :c:func:`PyErr_SetFromWindowsErr`, with the additional behavior that 233 if *filenameObject* is not *NULL*, it is passed to the constructor of 281 234 :exc:`WindowsError` as a third parameter. Availability: Windows. 282 235 283 236 284 .. cfunction:: PyObject* PyErr_SetExcFromWindowsErrWithFilename(PyObject *type, int ierr, char *filename) 285 286 Similar to :cfunc:`PyErr_SetFromWindowsErrWithFilename`, with an additional 237 .. c:function:: PyObject* PyErr_SetFromWindowsErrWithFilename(int ierr, const char *filename) 238 239 Similar to :c:func:`PyErr_SetFromWindowsErrWithFilenameObject`, but the 240 filename is given as a C string. Availability: Windows. 241 242 243 .. c:function:: PyObject* PyErr_SetExcFromWindowsErrWithFilenameObject(PyObject *type, int ierr, PyObject *filename) 244 245 Similar to :c:func:`PyErr_SetFromWindowsErrWithFilenameObject`, with an 246 additional parameter specifying the exception type to be raised. 247 Availability: Windows. 248 249 .. versionadded:: 2.3 250 251 252 .. c:function:: PyObject* PyErr_SetExcFromWindowsErrWithFilename(PyObject *type, int ierr, const char *filename) 253 254 Similar to :c:func:`PyErr_SetFromWindowsErrWithFilename`, with an additional 287 255 parameter specifying the exception type to be raised. Availability: Windows. 288 256 … … 290 258 291 259 292 .. c function:: void PyErr_BadInternalCall()260 .. c:function:: void PyErr_BadInternalCall() 293 261 294 262 This is a shorthand for ``PyErr_SetString(PyExc_SystemError, message)``, … … 298 266 299 267 300 .. c function:: int PyErr_WarnEx(PyObject *category, char *message, int stacklevel)268 .. c:function:: int PyErr_WarnEx(PyObject *category, char *message, int stacklevel) 301 269 302 270 Issue a warning message. The *category* argument is a warning category (see … … 304 272 positive number giving a number of stack frames; the warning will be issued from 305 273 the currently executing line of code in that stack frame. A *stacklevel* of 1 306 is the function calling :c func:`PyErr_WarnEx`, 2 is the function above that,274 is the function calling :c:func:`PyErr_WarnEx`, 2 is the function above that, 307 275 and so forth. 308 276 … … 316 284 actually printed, nor what the reason is for the exception; this is 317 285 intentional.) If an exception is raised, the caller should do its normal 318 exception handling (for example, :c func:`Py_DECREF` owned references and return286 exception handling (for example, :c:func:`Py_DECREF` owned references and return 319 287 an error value). 320 288 321 Warning categories must be subclasses of :c data:`Warning`; the default warning322 category is :c data:`RuntimeWarning`. The standard Python warning categories are289 Warning categories must be subclasses of :c:data:`Warning`; the default warning 290 category is :c:data:`RuntimeWarning`. The standard Python warning categories are 323 291 available as global variables whose names are ``PyExc_`` followed by the Python 324 exception name. These have the type :c type:`PyObject\*`; they are all class325 objects. Their names are :c data:`PyExc_Warning`, :cdata:`PyExc_UserWarning`,326 :c data:`PyExc_UnicodeWarning`, :cdata:`PyExc_DeprecationWarning`,327 :c data:`PyExc_SyntaxWarning`, :cdata:`PyExc_RuntimeWarning`, and328 :c data:`PyExc_FutureWarning`. :cdata:`PyExc_Warning` is a subclass of329 :c data:`PyExc_Exception`; the other warning categories are subclasses of330 :c data:`PyExc_Warning`.292 exception name. These have the type :c:type:`PyObject\*`; they are all class 293 objects. Their names are :c:data:`PyExc_Warning`, :c:data:`PyExc_UserWarning`, 294 :c:data:`PyExc_UnicodeWarning`, :c:data:`PyExc_DeprecationWarning`, 295 :c:data:`PyExc_SyntaxWarning`, :c:data:`PyExc_RuntimeWarning`, and 296 :c:data:`PyExc_FutureWarning`. :c:data:`PyExc_Warning` is a subclass of 297 :c:data:`PyExc_Exception`; the other warning categories are subclasses of 298 :c:data:`PyExc_Warning`. 331 299 332 300 For information about warning control, see the documentation for the … … 335 303 336 304 337 .. c function:: int PyErr_Warn(PyObject *category, char *message)305 .. c:function:: int PyErr_Warn(PyObject *category, char *message) 338 306 339 307 Issue a warning message. The *category* argument is a warning category (see 340 308 below) or *NULL*; the *message* argument is a message string. The warning will 341 appear to be issued from the function calling :c func:`PyErr_Warn`, equivalent to342 calling :c func:`PyErr_WarnEx` with a *stacklevel* of 1.343 344 Deprecated; use :c func:`PyErr_WarnEx` instead.345 346 347 .. c function:: int PyErr_WarnExplicit(PyObject *category, const char *message, const char *filename, int lineno, const char *module, PyObject *registry)309 appear to be issued from the function calling :c:func:`PyErr_Warn`, equivalent to 310 calling :c:func:`PyErr_WarnEx` with a *stacklevel* of 1. 311 312 Deprecated; use :c:func:`PyErr_WarnEx` instead. 313 314 315 .. c:function:: int PyErr_WarnExplicit(PyObject *category, const char *message, const char *filename, int lineno, const char *module, PyObject *registry) 348 316 349 317 Issue a warning message with explicit control over all warning attributes. This … … 354 322 355 323 356 .. c function:: int PyErr_WarnPy3k(char *message, int stacklevel)324 .. c:function:: int PyErr_WarnPy3k(char *message, int stacklevel) 357 325 358 326 Issue a :exc:`DeprecationWarning` with the given *message* and *stacklevel* 359 if the :c data:`Py_Py3kWarningFlag` flag is enabled.327 if the :c:data:`Py_Py3kWarningFlag` flag is enabled. 360 328 361 329 .. versionadded:: 2.6 362 330 363 331 364 .. c function:: int PyErr_CheckSignals()332 .. c:function:: int PyErr_CheckSignals() 365 333 366 334 .. index:: … … 379 347 380 348 381 .. c function:: void PyErr_SetInterrupt()349 .. c:function:: void PyErr_SetInterrupt() 382 350 383 351 .. index:: … … 386 354 387 355 This function simulates the effect of a :const:`SIGINT` signal arriving --- the 388 next time :c func:`PyErr_CheckSignals` is called, :exc:`KeyboardInterrupt` will356 next time :c:func:`PyErr_CheckSignals` is called, :exc:`KeyboardInterrupt` will 389 357 be raised. It may be called without holding the interpreter lock. 390 358 … … 393 361 394 362 395 .. c function:: int PySignal_SetWakeupFd(int fd)363 .. c:function:: int PySignal_SetWakeupFd(int fd) 396 364 397 365 This utility function specifies a file descriptor to which a ``'\0'`` byte will … … 402 370 only be called from the main thread. 403 371 404 405 .. cfunction:: PyObject* PyErr_NewException(char *name, PyObject *base, PyObject *dict) 406 407 This utility function creates and returns a new exception object. The *name* 372 .. versionadded:: 2.6 373 374 375 .. c:function:: PyObject* PyErr_NewException(char *name, PyObject *base, PyObject *dict) 376 377 This utility function creates and returns a new exception class. The *name* 408 378 argument must be the name of the new exception, a C string of the form 409 ``module.class ``. The *base* and *dict* arguments are normally *NULL*. This410 creates a class object derived from :exc:`Exception` (accessible in C as411 :c data:`PyExc_Exception`).379 ``module.classname``. The *base* and *dict* arguments are normally *NULL*. 380 This creates a class object derived from :exc:`Exception` (accessible in C as 381 :c:data:`PyExc_Exception`). 412 382 413 383 The :attr:`__module__` attribute of the new class is set to the first part (up … … 418 388 419 389 420 .. cfunction:: void PyErr_WriteUnraisable(PyObject *obj) 390 .. c:function:: PyObject* PyErr_NewExceptionWithDoc(char *name, char *doc, PyObject *base, PyObject *dict) 391 392 Same as :c:func:`PyErr_NewException`, except that the new exception class can 393 easily be given a docstring: If *doc* is non-*NULL*, it will be used as the 394 docstring for the exception class. 395 396 .. versionadded:: 2.7 397 398 399 .. c:function:: void PyErr_WriteUnraisable(PyObject *obj) 421 400 422 401 This utility function prints a warning message to ``sys.stderr`` when an … … 430 409 431 410 411 .. _unicodeexceptions: 412 413 Unicode Exception Objects 414 ========================= 415 416 The following functions are used to create and modify Unicode exceptions from C. 417 418 .. c:function:: PyObject* PyUnicodeDecodeError_Create(const char *encoding, const char *object, Py_ssize_t length, Py_ssize_t start, Py_ssize_t end, const char *reason) 419 420 Create a :class:`UnicodeDecodeError` object with the attributes *encoding*, 421 *object*, *length*, *start*, *end* and *reason*. 422 423 .. c:function:: PyObject* PyUnicodeEncodeError_Create(const char *encoding, const Py_UNICODE *object, Py_ssize_t length, Py_ssize_t start, Py_ssize_t end, const char *reason) 424 425 Create a :class:`UnicodeEncodeError` object with the attributes *encoding*, 426 *object*, *length*, *start*, *end* and *reason*. 427 428 .. c:function:: PyObject* PyUnicodeTranslateError_Create(const Py_UNICODE *object, Py_ssize_t length, Py_ssize_t start, Py_ssize_t end, const char *reason) 429 430 Create a :class:`UnicodeTranslateError` object with the attributes *object*, 431 *length*, *start*, *end* and *reason*. 432 433 .. c:function:: PyObject* PyUnicodeDecodeError_GetEncoding(PyObject *exc) 434 PyObject* PyUnicodeEncodeError_GetEncoding(PyObject *exc) 435 436 Return the *encoding* attribute of the given exception object. 437 438 .. c:function:: PyObject* PyUnicodeDecodeError_GetObject(PyObject *exc) 439 PyObject* PyUnicodeEncodeError_GetObject(PyObject *exc) 440 PyObject* PyUnicodeTranslateError_GetObject(PyObject *exc) 441 442 Return the *object* attribute of the given exception object. 443 444 .. c:function:: int PyUnicodeDecodeError_GetStart(PyObject *exc, Py_ssize_t *start) 445 int PyUnicodeEncodeError_GetStart(PyObject *exc, Py_ssize_t *start) 446 int PyUnicodeTranslateError_GetStart(PyObject *exc, Py_ssize_t *start) 447 448 Get the *start* attribute of the given exception object and place it into 449 *\*start*. *start* must not be *NULL*. Return ``0`` on success, ``-1`` on 450 failure. 451 452 .. c:function:: int PyUnicodeDecodeError_SetStart(PyObject *exc, Py_ssize_t start) 453 int PyUnicodeEncodeError_SetStart(PyObject *exc, Py_ssize_t start) 454 int PyUnicodeTranslateError_SetStart(PyObject *exc, Py_ssize_t start) 455 456 Set the *start* attribute of the given exception object to *start*. Return 457 ``0`` on success, ``-1`` on failure. 458 459 .. c:function:: int PyUnicodeDecodeError_GetEnd(PyObject *exc, Py_ssize_t *end) 460 int PyUnicodeEncodeError_GetEnd(PyObject *exc, Py_ssize_t *end) 461 int PyUnicodeTranslateError_GetEnd(PyObject *exc, Py_ssize_t *end) 462 463 Get the *end* attribute of the given exception object and place it into 464 *\*end*. *end* must not be *NULL*. Return ``0`` on success, ``-1`` on 465 failure. 466 467 .. c:function:: int PyUnicodeDecodeError_SetEnd(PyObject *exc, Py_ssize_t end) 468 int PyUnicodeEncodeError_SetEnd(PyObject *exc, Py_ssize_t end) 469 int PyUnicodeTranslateError_SetEnd(PyObject *exc, Py_ssize_t end) 470 471 Set the *end* attribute of the given exception object to *end*. Return ``0`` 472 on success, ``-1`` on failure. 473 474 .. c:function:: PyObject* PyUnicodeDecodeError_GetReason(PyObject *exc) 475 PyObject* PyUnicodeEncodeError_GetReason(PyObject *exc) 476 PyObject* PyUnicodeTranslateError_GetReason(PyObject *exc) 477 478 Return the *reason* attribute of the given exception object. 479 480 .. c:function:: int PyUnicodeDecodeError_SetReason(PyObject *exc, const char *reason) 481 int PyUnicodeEncodeError_SetReason(PyObject *exc, const char *reason) 482 int PyUnicodeTranslateError_SetReason(PyObject *exc, const char *reason) 483 484 Set the *reason* attribute of the given exception object to *reason*. Return 485 ``0`` on success, ``-1`` on failure. 486 487 488 Recursion Control 489 ================= 490 491 These two functions provide a way to perform safe recursive calls at the C 492 level, both in the core and in extension modules. They are needed if the 493 recursive code does not necessarily invoke Python code (which tracks its 494 recursion depth automatically). 495 496 .. c:function:: int Py_EnterRecursiveCall(char *where) 497 498 Marks a point where a recursive C-level call is about to be performed. 499 500 If :const:`USE_STACKCHECK` is defined, this function checks if the OS 501 stack overflowed using :c:func:`PyOS_CheckStack`. In this is the case, it 502 sets a :exc:`MemoryError` and returns a nonzero value. 503 504 The function then checks if the recursion limit is reached. If this is the 505 case, a :exc:`RuntimeError` is set and a nonzero value is returned. 506 Otherwise, zero is returned. 507 508 *where* should be a string such as ``" in instance check"`` to be 509 concatenated to the :exc:`RuntimeError` message caused by the recursion depth 510 limit. 511 512 .. c:function:: void Py_LeaveRecursiveCall() 513 514 Ends a :c:func:`Py_EnterRecursiveCall`. Must be called once for each 515 *successful* invocation of :c:func:`Py_EnterRecursiveCall`. 516 517 432 518 .. _standardexceptions: 433 519 … … 437 523 All standard Python exceptions are available as global variables whose names are 438 524 ``PyExc_`` followed by the Python exception name. These have the type 439 :c type:`PyObject\*`; they are all class objects. For completeness, here are all525 :c:type:`PyObject\*`; they are all class objects. For completeness, here are all 440 526 the variables: 441 527 442 +------------------------------------ +----------------------------+----------+443 | C Name | Python Name | Notes |444 +==================================== +============================+==========+445 | :c data:`PyExc_BaseException` | :exc:`BaseException` | (1), (4) |446 +------------------------------------ +----------------------------+----------+447 | :c data:`PyExc_Exception` | :exc:`Exception` | \(1) |448 +------------------------------------ +----------------------------+----------+449 | :c data:`PyExc_StandardError` | :exc:`StandardError` | \(1) |450 +------------------------------------ +----------------------------+----------+451 | :c data:`PyExc_ArithmeticError` | :exc:`ArithmeticError` | \(1) |452 +------------------------------------ +----------------------------+----------+453 | :c data:`PyExc_LookupError` | :exc:`LookupError` | \(1) |454 +------------------------------------ +----------------------------+----------+455 | :c data:`PyExc_AssertionError` | :exc:`AssertionError` | |456 +------------------------------------ +----------------------------+----------+457 | :c data:`PyExc_AttributeError` | :exc:`AttributeError` | |458 +------------------------------------ +----------------------------+----------+459 | :c data:`PyExc_EOFError` | :exc:`EOFError` | |460 +------------------------------------ +----------------------------+----------+461 | :c data:`PyExc_EnvironmentError` | :exc:`EnvironmentError` | \(1) |462 +------------------------------------ +----------------------------+----------+463 | :c data:`PyExc_FloatingPointError` | :exc:`FloatingPointError` | |464 +------------------------------------ +----------------------------+----------+465 | :c data:`PyExc_IOError` | :exc:`IOError` | |466 +------------------------------------ +----------------------------+----------+467 | :c data:`PyExc_ImportError` | :exc:`ImportError` | |468 +------------------------------------ +----------------------------+----------+469 | :c data:`PyExc_IndexError` | :exc:`IndexError` | |470 +------------------------------------ +----------------------------+----------+471 | :c data:`PyExc_KeyError` | :exc:`KeyError` | |472 +------------------------------------ +----------------------------+----------+473 | :c data:`PyExc_KeyboardInterrupt` | :exc:`KeyboardInterrupt` | |474 +------------------------------------ +----------------------------+----------+475 | :c data:`PyExc_MemoryError` | :exc:`MemoryError` | |476 +------------------------------------ +----------------------------+----------+477 | :c data:`PyExc_NameError` | :exc:`NameError` | |478 +------------------------------------ +----------------------------+----------+479 | :c data:`PyExc_NotImplementedError` | :exc:`NotImplementedError` | |480 +------------------------------------ +----------------------------+----------+481 | :c data:`PyExc_OSError` | :exc:`OSError` | |482 +------------------------------------ +----------------------------+----------+483 | :c data:`PyExc_OverflowError` | :exc:`OverflowError` | |484 +------------------------------------ +----------------------------+----------+485 | :c data:`PyExc_ReferenceError` | :exc:`ReferenceError` | \(2) |486 +------------------------------------ +----------------------------+----------+487 | :c data:`PyExc_RuntimeError` | :exc:`RuntimeError` | |488 +------------------------------------ +----------------------------+----------+489 | :c data:`PyExc_SyntaxError` | :exc:`SyntaxError` | |490 +------------------------------------ +----------------------------+----------+491 | :c data:`PyExc_SystemError` | :exc:`SystemError` | |492 +------------------------------------ +----------------------------+----------+493 | :c data:`PyExc_SystemExit` | :exc:`SystemExit` | |494 +------------------------------------ +----------------------------+----------+495 | :c data:`PyExc_TypeError` | :exc:`TypeError` | |496 +------------------------------------ +----------------------------+----------+497 | :c data:`PyExc_ValueError` | :exc:`ValueError` | |498 +------------------------------------ +----------------------------+----------+499 | :c data:`PyExc_WindowsError` | :exc:`WindowsError` | \(3) |500 +------------------------------------ +----------------------------+----------+501 | :c data:`PyExc_ZeroDivisionError` | :exc:`ZeroDivisionError` | |502 +------------------------------------ +----------------------------+----------+528 +-------------------------------------+----------------------------+----------+ 529 | C Name | Python Name | Notes | 530 +=====================================+============================+==========+ 531 | :c:data:`PyExc_BaseException` | :exc:`BaseException` | (1), (4) | 532 +-------------------------------------+----------------------------+----------+ 533 | :c:data:`PyExc_Exception` | :exc:`Exception` | \(1) | 534 +-------------------------------------+----------------------------+----------+ 535 | :c:data:`PyExc_StandardError` | :exc:`StandardError` | \(1) | 536 +-------------------------------------+----------------------------+----------+ 537 | :c:data:`PyExc_ArithmeticError` | :exc:`ArithmeticError` | \(1) | 538 +-------------------------------------+----------------------------+----------+ 539 | :c:data:`PyExc_LookupError` | :exc:`LookupError` | \(1) | 540 +-------------------------------------+----------------------------+----------+ 541 | :c:data:`PyExc_AssertionError` | :exc:`AssertionError` | | 542 +-------------------------------------+----------------------------+----------+ 543 | :c:data:`PyExc_AttributeError` | :exc:`AttributeError` | | 544 +-------------------------------------+----------------------------+----------+ 545 | :c:data:`PyExc_EOFError` | :exc:`EOFError` | | 546 +-------------------------------------+----------------------------+----------+ 547 | :c:data:`PyExc_EnvironmentError` | :exc:`EnvironmentError` | \(1) | 548 +-------------------------------------+----------------------------+----------+ 549 | :c:data:`PyExc_FloatingPointError` | :exc:`FloatingPointError` | | 550 +-------------------------------------+----------------------------+----------+ 551 | :c:data:`PyExc_IOError` | :exc:`IOError` | | 552 +-------------------------------------+----------------------------+----------+ 553 | :c:data:`PyExc_ImportError` | :exc:`ImportError` | | 554 +-------------------------------------+----------------------------+----------+ 555 | :c:data:`PyExc_IndexError` | :exc:`IndexError` | | 556 +-------------------------------------+----------------------------+----------+ 557 | :c:data:`PyExc_KeyError` | :exc:`KeyError` | | 558 +-------------------------------------+----------------------------+----------+ 559 | :c:data:`PyExc_KeyboardInterrupt` | :exc:`KeyboardInterrupt` | | 560 +-------------------------------------+----------------------------+----------+ 561 | :c:data:`PyExc_MemoryError` | :exc:`MemoryError` | | 562 +-------------------------------------+----------------------------+----------+ 563 | :c:data:`PyExc_NameError` | :exc:`NameError` | | 564 +-------------------------------------+----------------------------+----------+ 565 | :c:data:`PyExc_NotImplementedError` | :exc:`NotImplementedError` | | 566 +-------------------------------------+----------------------------+----------+ 567 | :c:data:`PyExc_OSError` | :exc:`OSError` | | 568 +-------------------------------------+----------------------------+----------+ 569 | :c:data:`PyExc_OverflowError` | :exc:`OverflowError` | | 570 +-------------------------------------+----------------------------+----------+ 571 | :c:data:`PyExc_ReferenceError` | :exc:`ReferenceError` | \(2) | 572 +-------------------------------------+----------------------------+----------+ 573 | :c:data:`PyExc_RuntimeError` | :exc:`RuntimeError` | | 574 +-------------------------------------+----------------------------+----------+ 575 | :c:data:`PyExc_SyntaxError` | :exc:`SyntaxError` | | 576 +-------------------------------------+----------------------------+----------+ 577 | :c:data:`PyExc_SystemError` | :exc:`SystemError` | | 578 +-------------------------------------+----------------------------+----------+ 579 | :c:data:`PyExc_SystemExit` | :exc:`SystemExit` | | 580 +-------------------------------------+----------------------------+----------+ 581 | :c:data:`PyExc_TypeError` | :exc:`TypeError` | | 582 +-------------------------------------+----------------------------+----------+ 583 | :c:data:`PyExc_ValueError` | :exc:`ValueError` | | 584 +-------------------------------------+----------------------------+----------+ 585 | :c:data:`PyExc_WindowsError` | :exc:`WindowsError` | \(3) | 586 +-------------------------------------+----------------------------+----------+ 587 | :c:data:`PyExc_ZeroDivisionError` | :exc:`ZeroDivisionError` | | 588 +-------------------------------------+----------------------------+----------+ 503 589 504 590 .. index:: … … 549 635 550 636 551 Deprecation of String Exceptions 552 ================================ 553 554 .. index:: single: BaseException (built-in exception) 555 556 All exceptions built into Python or provided in the standard library are derived 557 from :exc:`BaseException`. 558 559 String exceptions are still supported in the interpreter to allow existing code 560 to run unmodified, but this will also change in a future release. 561 637 String Exceptions 638 ================= 639 640 .. versionchanged:: 2.6 641 All exceptions to be raised or caught must be derived from :exc:`BaseException`. 642 Trying to raise a string exception now raises :exc:`TypeError`. 643 -
python/vendor/current/Doc/c-api/file.rst
r2 r388 8 8 .. index:: object: file 9 9 10 Python's built-in file objects are implemented entirely on the :c type:`FILE\*`10 Python's built-in file objects are implemented entirely on the :c:type:`FILE\*` 11 11 support from the C standard library. This is an implementation detail and may 12 12 change in future releases of Python. 13 13 14 14 15 .. c type:: PyFileObject15 .. c:type:: PyFileObject 16 16 17 This subtype of :c type:`PyObject` represents a Python file object.17 This subtype of :c:type:`PyObject` represents a Python file object. 18 18 19 19 20 .. c var:: PyTypeObject PyFile_Type20 .. c:var:: PyTypeObject PyFile_Type 21 21 22 22 .. index:: single: FileType (in module types) 23 23 24 This instance of :c type:`PyTypeObject` represents the Python file type. This is24 This instance of :c:type:`PyTypeObject` represents the Python file type. This is 25 25 exposed to Python programs as ``file`` and ``types.FileType``. 26 26 27 27 28 .. c function:: int PyFile_Check(PyObject *p)28 .. c:function:: int PyFile_Check(PyObject *p) 29 29 30 Return true if its argument is a :c type:`PyFileObject` or a subtype of31 :c type:`PyFileObject`.30 Return true if its argument is a :c:type:`PyFileObject` or a subtype of 31 :c:type:`PyFileObject`. 32 32 33 33 .. versionchanged:: 2.2 … … 35 35 36 36 37 .. c function:: int PyFile_CheckExact(PyObject *p)37 .. c:function:: int PyFile_CheckExact(PyObject *p) 38 38 39 Return true if its argument is a :c type:`PyFileObject`, but not a subtype of40 :c type:`PyFileObject`.39 Return true if its argument is a :c:type:`PyFileObject`, but not a subtype of 40 :c:type:`PyFileObject`. 41 41 42 42 .. versionadded:: 2.2 43 43 44 44 45 .. c function:: PyObject* PyFile_FromString(char *filename, char *mode)45 .. c:function:: PyObject* PyFile_FromString(char *filename, char *mode) 46 46 47 47 .. index:: single: fopen() … … 49 49 On success, return a new file object that is opened on the file given by 50 50 *filename*, with a file mode given by *mode*, where *mode* has the same 51 semantics as the standard C routine :c func:`fopen`. On failure, return *NULL*.51 semantics as the standard C routine :c:func:`fopen`. On failure, return *NULL*. 52 52 53 53 54 .. c function:: PyObject* PyFile_FromFile(FILE *fp, char *name, char *mode, int (*close)(FILE*))54 .. c:function:: PyObject* PyFile_FromFile(FILE *fp, char *name, char *mode, int (*close)(FILE*)) 55 55 56 Create a new :c type:`PyFileObject` from the already-open standard C file56 Create a new :c:type:`PyFileObject` from the already-open standard C file 57 57 pointer, *fp*. The function *close* will be called when the file should be 58 closed. Return *NULL* on failure. 58 closed. Return *NULL* and close the file using *close* on failure. 59 *close* is optional and can be set to *NULL*. 59 60 60 61 61 .. c function:: FILE* PyFile_AsFile(PyObject \*p)62 .. c:function:: FILE* PyFile_AsFile(PyObject \*p) 62 63 63 Return the file object associated with *p* as a :c type:`FILE\*`.64 Return the file object associated with *p* as a :c:type:`FILE\*`. 64 65 65 If the caller will ever use the returned :c type:`FILE\*` object while66 the GIL is released it must also call the :cfunc:`PyFile_IncUseCount` and67 :c func:`PyFile_DecUseCount` functions described below as appropriate.66 If the caller will ever use the returned :c:type:`FILE\*` object while 67 the :term:`GIL` is released it must also call the :c:func:`PyFile_IncUseCount` and 68 :c:func:`PyFile_DecUseCount` functions described below as appropriate. 68 69 69 70 70 .. c function:: void PyFile_IncUseCount(PyFileObject \*p)71 .. c:function:: void PyFile_IncUseCount(PyFileObject \*p) 71 72 72 73 Increments the PyFileObject's internal use count to indicate 73 that the underlying :c type:`FILE\*` is being used.74 that the underlying :c:type:`FILE\*` is being used. 74 75 This prevents Python from calling f_close() on it from another thread. 75 Callers of this must call :c func:`PyFile_DecUseCount` when they are76 finished with the :c type:`FILE\*`. Otherwise the file object will76 Callers of this must call :c:func:`PyFile_DecUseCount` when they are 77 finished with the :c:type:`FILE\*`. Otherwise the file object will 77 78 never be closed by Python. 78 79 79 The GILmust be held while calling this function.80 The :term:`GIL` must be held while calling this function. 80 81 81 The suggested use is to call this after :cfunc:`PyFile_AsFile` just before 82 you release the GIL. 82 The suggested use is to call this after :c:func:`PyFile_AsFile` and before 83 you release the GIL:: 84 85 FILE *fp = PyFile_AsFile(p); 86 PyFile_IncUseCount(p); 87 /* ... */ 88 Py_BEGIN_ALLOW_THREADS 89 do_something(fp); 90 Py_END_ALLOW_THREADS 91 /* ... */ 92 PyFile_DecUseCount(p); 83 93 84 94 .. versionadded:: 2.6 85 95 86 96 87 .. c function:: void PyFile_DecUseCount(PyFileObject \*p)97 .. c:function:: void PyFile_DecUseCount(PyFileObject \*p) 88 98 89 99 Decrements the PyFileObject's internal unlocked_count member to 90 indicate that the caller is done with its own use of the :c type:`FILE\*`.91 This may only be called to undo a prior call to :c func:`PyFile_IncUseCount`.100 indicate that the caller is done with its own use of the :c:type:`FILE\*`. 101 This may only be called to undo a prior call to :c:func:`PyFile_IncUseCount`. 92 102 93 The GIL must be held while calling this function. 103 The :term:`GIL` must be held while calling this function (see the example 104 above). 94 105 95 106 .. versionadded:: 2.6 96 107 97 108 98 .. c function:: PyObject* PyFile_GetLine(PyObject *p, int n)109 .. c:function:: PyObject* PyFile_GetLine(PyObject *p, int n) 99 110 100 111 .. index:: single: EOFError (built-in exception) 101 112 102 113 Equivalent to ``p.readline([n])``, this function reads one line from the 103 object *p*. *p* may be a file object or any object with a :meth:`readline` 114 object *p*. *p* may be a file object or any object with a 115 :meth:`~io.IOBase.readline` 104 116 method. If *n* is ``0``, exactly one line is read, regardless of the length of 105 117 the line. If *n* is greater than ``0``, no more than *n* bytes will be read … … 110 122 111 123 112 .. c function:: PyObject* PyFile_Name(PyObject *p)124 .. c:function:: PyObject* PyFile_Name(PyObject *p) 113 125 114 126 Return the name of the file specified by *p* as a string object. 115 127 116 128 117 .. c function:: void PyFile_SetBufSize(PyFileObject *p, int n)129 .. c:function:: void PyFile_SetBufSize(PyFileObject *p, int n) 118 130 119 131 .. index:: single: setvbuf() 120 132 121 Available on systems with :c func:`setvbuf` only. This should only be called133 Available on systems with :c:func:`setvbuf` only. This should only be called 122 134 immediately after file object creation. 123 135 124 136 125 .. c function:: int PyFile_SetEncoding(PyFileObject *p, const char *enc)137 .. c:function:: int PyFile_SetEncoding(PyFileObject *p, const char *enc) 126 138 127 139 Set the file's encoding for Unicode output to *enc*. Return 1 on success and 0 … … 131 143 132 144 133 .. c function:: int PyFile_SetEncodingAndErrors(PyFileObject *p, const char *enc, *errors)145 .. c:function:: int PyFile_SetEncodingAndErrors(PyFileObject *p, const char *enc, *errors) 134 146 135 147 Set the file's encoding for Unicode output to *enc*, and its error … … 139 151 140 152 141 .. c function:: int PyFile_SoftSpace(PyObject *p, int newflag)153 .. c:function:: int PyFile_SoftSpace(PyObject *p, int newflag) 142 154 143 155 .. index:: single: softspace (file attribute) … … 153 165 154 166 155 .. c function:: int PyFile_WriteObject(PyObject *obj, PyObject *p, int flags)167 .. c:function:: int PyFile_WriteObject(PyObject *obj, PyObject *p, int flags) 156 168 157 169 .. index:: single: Py_PRINT_RAW … … 163 175 164 176 165 .. c function:: int PyFile_WriteString(const char *s, PyObject *p)177 .. c:function:: int PyFile_WriteString(const char *s, PyObject *p) 166 178 167 179 Write string *s* to file object *p*. Return ``0`` on success or ``-1`` on -
python/vendor/current/Doc/c-api/float.rst
r2 r388 9 9 10 10 11 .. c type:: PyFloatObject11 .. c:type:: PyFloatObject 12 12 13 This subtype of :c type:`PyObject` represents a Python floating point object.13 This subtype of :c:type:`PyObject` represents a Python floating point object. 14 14 15 15 16 .. c var:: PyTypeObject PyFloat_Type16 .. c:var:: PyTypeObject PyFloat_Type 17 17 18 18 .. index:: single: FloatType (in modules types) 19 19 20 This instance of :c type:`PyTypeObject` represents the Python floating point20 This instance of :c:type:`PyTypeObject` represents the Python floating point 21 21 type. This is the same object as ``float`` and ``types.FloatType``. 22 22 23 23 24 .. c function:: int PyFloat_Check(PyObject *p)24 .. c:function:: int PyFloat_Check(PyObject *p) 25 25 26 Return true if its argument is a :c type:`PyFloatObject` or a subtype of27 :c type:`PyFloatObject`.26 Return true if its argument is a :c:type:`PyFloatObject` or a subtype of 27 :c:type:`PyFloatObject`. 28 28 29 29 .. versionchanged:: 2.2 … … 31 31 32 32 33 .. c function:: int PyFloat_CheckExact(PyObject *p)33 .. c:function:: int PyFloat_CheckExact(PyObject *p) 34 34 35 Return true if its argument is a :c type:`PyFloatObject`, but not a subtype of36 :c type:`PyFloatObject`.35 Return true if its argument is a :c:type:`PyFloatObject`, but not a subtype of 36 :c:type:`PyFloatObject`. 37 37 38 38 .. versionadded:: 2.2 39 39 40 40 41 .. c function:: PyObject* PyFloat_FromString(PyObject *str, char **pend)41 .. c:function:: PyObject* PyFloat_FromString(PyObject *str, char **pend) 42 42 43 Create a :c type:`PyFloatObject` object based on the string value in *str*, or43 Create a :c:type:`PyFloatObject` object based on the string value in *str*, or 44 44 *NULL* on failure. The *pend* argument is ignored. It remains only for 45 45 backward compatibility. 46 46 47 47 48 .. c function:: PyObject* PyFloat_FromDouble(double v)48 .. c:function:: PyObject* PyFloat_FromDouble(double v) 49 49 50 Create a :c type:`PyFloatObject` object from *v*, or *NULL* on failure.50 Create a :c:type:`PyFloatObject` object from *v*, or *NULL* on failure. 51 51 52 52 53 .. c function:: double PyFloat_AsDouble(PyObject *pyfloat)53 .. c:function:: double PyFloat_AsDouble(PyObject *pyfloat) 54 54 55 Return a C :c type:`double` representation of the contents of *pyfloat*. If55 Return a C :c:type:`double` representation of the contents of *pyfloat*. If 56 56 *pyfloat* is not a Python floating point object but has a :meth:`__float__` 57 57 method, this method will first be called to convert *pyfloat* into a float. 58 This method returns ``-1.0`` upon failure, so one should call 59 :c:func:`PyErr_Occurred` to check for errors. 58 60 59 61 60 .. c function:: double PyFloat_AS_DOUBLE(PyObject *pyfloat)62 .. c:function:: double PyFloat_AS_DOUBLE(PyObject *pyfloat) 61 63 62 Return a C :c type:`double` representation of the contents of *pyfloat*, but64 Return a C :c:type:`double` representation of the contents of *pyfloat*, but 63 65 without error checking. 64 66 65 67 66 .. c function:: PyObject* PyFloat_GetInfo(void)68 .. c:function:: PyObject* PyFloat_GetInfo(void) 67 69 68 70 Return a structseq instance which contains information about the … … 73 75 74 76 75 .. c function:: double PyFloat_GetMax()77 .. c:function:: double PyFloat_GetMax() 76 78 77 Return the maximum representable finite float *DBL_MAX* as C :c type:`double`.79 Return the maximum representable finite float *DBL_MAX* as C :c:type:`double`. 78 80 79 81 .. versionadded:: 2.6 80 82 81 83 82 .. c function:: double PyFloat_GetMin()84 .. c:function:: double PyFloat_GetMin() 83 85 84 Return the minimum normalized positive float *DBL_MIN* as C :c type:`double`.86 Return the minimum normalized positive float *DBL_MIN* as C :c:type:`double`. 85 87 86 88 .. versionadded:: 2.6 87 89 88 90 89 .. c function:: int PyFloat_ClearFreeList()91 .. c:function:: int PyFloat_ClearFreeList() 90 92 91 93 Clear the float free list. Return the number of items that could not … … 93 95 94 96 .. versionadded:: 2.6 97 98 99 .. c:function:: void PyFloat_AsString(char *buf, PyFloatObject *v) 100 101 Convert the argument *v* to a string, using the same rules as 102 :func:`str`. The length of *buf* should be at least 100. 103 104 This function is unsafe to call because it writes to a buffer whose 105 length it does not know. 106 107 .. deprecated:: 2.7 108 Use :func:`PyObject_Str` or :func:`PyOS_double_to_string` instead. 109 110 111 .. c:function:: void PyFloat_AsReprString(char *buf, PyFloatObject *v) 112 113 Same as PyFloat_AsString, except uses the same rules as 114 :func:`repr`. The length of *buf* should be at least 100. 115 116 This function is unsafe to call because it writes to a buffer whose 117 length it does not know. 118 119 .. deprecated:: 2.7 120 Use :func:`PyObject_Repr` or :func:`PyOS_double_to_string` instead. -
python/vendor/current/Doc/c-api/function.rst
r2 r388 11 11 12 12 13 .. c type:: PyFunctionObject13 .. c:type:: PyFunctionObject 14 14 15 15 The C structure used for functions. 16 16 17 17 18 .. c var:: PyTypeObject PyFunction_Type18 .. c:var:: PyTypeObject PyFunction_Type 19 19 20 20 .. index:: single: MethodType (in module types) 21 21 22 This is an instance of :c type:`PyTypeObject` and represents the Python function22 This is an instance of :c:type:`PyTypeObject` and represents the Python function 23 23 type. It is exposed to Python programmers as ``types.FunctionType``. 24 24 25 25 26 .. c function:: int PyFunction_Check(PyObject *o)26 .. c:function:: int PyFunction_Check(PyObject *o) 27 27 28 Return true if *o* is a function object (has type :c data:`PyFunction_Type`).28 Return true if *o* is a function object (has type :c:data:`PyFunction_Type`). 29 29 The parameter must not be *NULL*. 30 30 31 31 32 .. c function:: PyObject* PyFunction_New(PyObject *code, PyObject *globals)32 .. c:function:: PyObject* PyFunction_New(PyObject *code, PyObject *globals) 33 33 34 34 Return a new function object associated with the code object *code*. *globals* … … 39 39 40 40 41 .. c function:: PyObject* PyFunction_GetCode(PyObject *op)41 .. c:function:: PyObject* PyFunction_GetCode(PyObject *op) 42 42 43 43 Return the code object associated with the function object *op*. 44 44 45 45 46 .. c function:: PyObject* PyFunction_GetGlobals(PyObject *op)46 .. c:function:: PyObject* PyFunction_GetGlobals(PyObject *op) 47 47 48 48 Return the globals dictionary associated with the function object *op*. 49 49 50 50 51 .. c function:: PyObject* PyFunction_GetModule(PyObject *op)51 .. c:function:: PyObject* PyFunction_GetModule(PyObject *op) 52 52 53 53 Return the *__module__* attribute of the function object *op*. This is normally … … 56 56 57 57 58 .. c function:: PyObject* PyFunction_GetDefaults(PyObject *op)58 .. c:function:: PyObject* PyFunction_GetDefaults(PyObject *op) 59 59 60 60 Return the argument default values of the function object *op*. This can be a … … 62 62 63 63 64 .. c function:: int PyFunction_SetDefaults(PyObject *op, PyObject *defaults)64 .. c:function:: int PyFunction_SetDefaults(PyObject *op, PyObject *defaults) 65 65 66 66 Set the argument default values for the function object *op*. *defaults* must be … … 70 70 71 71 72 .. c function:: PyObject* PyFunction_GetClosure(PyObject *op)72 .. c:function:: PyObject* PyFunction_GetClosure(PyObject *op) 73 73 74 74 Return the closure associated with the function object *op*. This can be *NULL* … … 76 76 77 77 78 .. c function:: int PyFunction_SetClosure(PyObject *op, PyObject *closure)78 .. c:function:: int PyFunction_SetClosure(PyObject *op, PyObject *closure) 79 79 80 80 Set the closure associated with the function object *op*. *closure* must be -
python/vendor/current/Doc/c-api/gcsupport.rst
r2 r388 16 16 .. Cycle Collector (XXX not found: ../ext/example-cycle-support.html)". 17 17 18 To create a container type, the : attr:`tp_flags` field of the type object must18 To create a container type, the :c:member:`~PyTypeObject.tp_flags` field of the type object must 19 19 include the :const:`Py_TPFLAGS_HAVE_GC` and provide an implementation of the 20 : attr:`tp_traverse` handler. If instances of the type are mutable, a21 : attr:`tp_clear` implementation must also be provided.20 :c:member:`~PyTypeObject.tp_traverse` handler. If instances of the type are mutable, a 21 :c:member:`~PyTypeObject.tp_clear` implementation must also be provided. 22 22 23 23 … … 31 31 Constructors for container types must conform to two rules: 32 32 33 #. The memory for the object must be allocated using :c func:`PyObject_GC_New`34 or :c func:`PyObject_GC_VarNew`.33 #. The memory for the object must be allocated using :c:func:`PyObject_GC_New` 34 or :c:func:`PyObject_GC_NewVar`. 35 35 36 36 #. Once all the fields which may contain references to other containers are 37 initialized, it must call :c func:`PyObject_GC_Track`.37 initialized, it must call :c:func:`PyObject_GC_Track`. 38 38 39 39 40 .. c function:: TYPE* PyObject_GC_New(TYPE, PyTypeObject *type)40 .. c:function:: TYPE* PyObject_GC_New(TYPE, PyTypeObject *type) 41 41 42 Analogous to :c func:`PyObject_New` but for container objects with the42 Analogous to :c:func:`PyObject_New` but for container objects with the 43 43 :const:`Py_TPFLAGS_HAVE_GC` flag set. 44 44 45 45 46 .. c function:: TYPE* PyObject_GC_NewVar(TYPE, PyTypeObject *type, Py_ssize_t size)46 .. c:function:: TYPE* PyObject_GC_NewVar(TYPE, PyTypeObject *type, Py_ssize_t size) 47 47 48 Analogous to :c func:`PyObject_NewVar` but for container objects with the48 Analogous to :c:func:`PyObject_NewVar` but for container objects with the 49 49 :const:`Py_TPFLAGS_HAVE_GC` flag set. 50 50 51 51 .. versionchanged:: 2.5 52 This function used an :c type:`int` type for *size*. This might require52 This function used an :c:type:`int` type for *size*. This might require 53 53 changes in your code for properly supporting 64-bit systems. 54 54 55 55 56 .. c function:: TYPE* PyObject_GC_Resize(TYPE, PyVarObject *op, Py_ssize_t newsize)56 .. c:function:: TYPE* PyObject_GC_Resize(TYPE, PyVarObject *op, Py_ssize_t newsize) 57 57 58 Resize an object allocated by :c func:`PyObject_NewVar`. Returns the58 Resize an object allocated by :c:func:`PyObject_NewVar`. Returns the 59 59 resized object or *NULL* on failure. 60 60 61 61 .. versionchanged:: 2.5 62 This function used an :c type:`int` type for *newsize*. This might62 This function used an :c:type:`int` type for *newsize*. This might 63 63 require changes in your code for properly supporting 64-bit systems. 64 64 65 65 66 .. c function:: void PyObject_GC_Track(PyObject *op)66 .. c:function:: void PyObject_GC_Track(PyObject *op) 67 67 68 68 Adds the object *op* to the set of container objects tracked by the 69 69 collector. The collector can run at unexpected times so objects must be 70 70 valid while being tracked. This should be called once all the fields 71 followed by the : attr:`tp_traverse` handler become valid, usually near the71 followed by the :c:member:`~PyTypeObject.tp_traverse` handler become valid, usually near the 72 72 end of the constructor. 73 73 74 74 75 .. c function:: void _PyObject_GC_TRACK(PyObject *op)75 .. c:function:: void _PyObject_GC_TRACK(PyObject *op) 76 76 77 A macro version of :c func:`PyObject_GC_Track`. It should not be used for77 A macro version of :c:func:`PyObject_GC_Track`. It should not be used for 78 78 extension modules. 79 79 … … 82 82 83 83 #. Before fields which refer to other containers are invalidated, 84 :c func:`PyObject_GC_UnTrack` must be called.84 :c:func:`PyObject_GC_UnTrack` must be called. 85 85 86 #. The object's memory must be deallocated using :c func:`PyObject_GC_Del`.86 #. The object's memory must be deallocated using :c:func:`PyObject_GC_Del`. 87 87 88 88 89 .. c function:: void PyObject_GC_Del(void *op)89 .. c:function:: void PyObject_GC_Del(void *op) 90 90 91 Releases memory allocated to an object using :c func:`PyObject_GC_New` or92 :c func:`PyObject_GC_NewVar`.91 Releases memory allocated to an object using :c:func:`PyObject_GC_New` or 92 :c:func:`PyObject_GC_NewVar`. 93 93 94 94 95 .. c function:: void PyObject_GC_UnTrack(void *op)95 .. c:function:: void PyObject_GC_UnTrack(void *op) 96 96 97 97 Remove the object *op* from the set of container objects tracked by the 98 collector. Note that :c func:`PyObject_GC_Track` can be called again on98 collector. Note that :c:func:`PyObject_GC_Track` can be called again on 99 99 this object to add it back to the set of tracked objects. The deallocator 100 (: attr:`tp_dealloc` handler) should call this for the object before any of101 the fields used by the : attr:`tp_traverse` handler become invalid.100 (:c:member:`~PyTypeObject.tp_dealloc` handler) should call this for the object before any of 101 the fields used by the :c:member:`~PyTypeObject.tp_traverse` handler become invalid. 102 102 103 103 104 .. c function:: void _PyObject_GC_UNTRACK(PyObject *op)104 .. c:function:: void _PyObject_GC_UNTRACK(PyObject *op) 105 105 106 A macro version of :c func:`PyObject_GC_UnTrack`. It should not be used for106 A macro version of :c:func:`PyObject_GC_UnTrack`. It should not be used for 107 107 extension modules. 108 108 109 The : attr:`tp_traverse` handler accepts a function parameter of this type:109 The :c:member:`~PyTypeObject.tp_traverse` handler accepts a function parameter of this type: 110 110 111 111 112 .. c type:: int (*visitproc)(PyObject *object, void *arg)112 .. c:type:: int (*visitproc)(PyObject *object, void *arg) 113 113 114 Type of the visitor function passed to the : attr:`tp_traverse` handler.114 Type of the visitor function passed to the :c:member:`~PyTypeObject.tp_traverse` handler. 115 115 The function should be called with an object to traverse as *object* and 116 the third parameter to the : attr:`tp_traverse` handler as *arg*. The116 the third parameter to the :c:member:`~PyTypeObject.tp_traverse` handler as *arg*. The 117 117 Python core uses several visitor functions to implement cyclic garbage 118 118 detection; it's not expected that users will need to write their own 119 119 visitor functions. 120 120 121 The : attr:`tp_traverse` handler must have the following type:121 The :c:member:`~PyTypeObject.tp_traverse` handler must have the following type: 122 122 123 123 124 .. c type:: int (*traverseproc)(PyObject *self, visitproc visit, void *arg)124 .. c:type:: int (*traverseproc)(PyObject *self, visitproc visit, void *arg) 125 125 126 126 Traversal function for a container object. Implementations must call the … … 131 131 returned immediately. 132 132 133 To simplify writing : attr:`tp_traverse` handlers, a :cfunc:`Py_VISIT` macro is134 provided. In order to use this macro, the : attr:`tp_traverse` implementation133 To simplify writing :c:member:`~PyTypeObject.tp_traverse` handlers, a :c:func:`Py_VISIT` macro is 134 provided. In order to use this macro, the :c:member:`~PyTypeObject.tp_traverse` implementation 135 135 must name its arguments exactly *visit* and *arg*: 136 136 137 137 138 .. c function:: void Py_VISIT(PyObject *o)138 .. c:function:: void Py_VISIT(PyObject *o) 139 139 140 140 Call the *visit* callback, with arguments *o* and *arg*. If *visit* returns 141 a non-zero value, then return it. Using this macro, : attr:`tp_traverse`141 a non-zero value, then return it. Using this macro, :c:member:`~PyTypeObject.tp_traverse` 142 142 handlers look like:: 143 143 … … 152 152 .. versionadded:: 2.4 153 153 154 The : attr:`tp_clear` handler must be of the :ctype:`inquiry` type, or *NULL*154 The :c:member:`~PyTypeObject.tp_clear` handler must be of the :c:type:`inquiry` type, or *NULL* 155 155 if the object is immutable. 156 156 157 157 158 .. c type:: int (*inquiry)(PyObject *self)158 .. c:type:: int (*inquiry)(PyObject *self) 159 159 160 160 Drop references that may have created reference cycles. Immutable objects 161 161 do not have to define this method since they can never directly create 162 162 reference cycles. Note that the object must still be valid after calling 163 this method (don't just call :c func:`Py_DECREF` on a reference). The163 this method (don't just call :c:func:`Py_DECREF` on a reference). The 164 164 collector will call this method if it detects that this object is involved 165 165 in a reference cycle. -
python/vendor/current/Doc/c-api/gen.rst
r2 r388 8 8 Generator objects are what Python uses to implement generator iterators. They 9 9 are normally created by iterating over a function that yields values, rather 10 than explicitly calling :c func:`PyGen_New`.10 than explicitly calling :c:func:`PyGen_New`. 11 11 12 12 13 .. c type:: PyGenObject13 .. c:type:: PyGenObject 14 14 15 15 The C structure used for generator objects. 16 16 17 17 18 .. c var:: PyTypeObject PyGen_Type18 .. c:var:: PyTypeObject PyGen_Type 19 19 20 20 The type object corresponding to generator objects 21 21 22 22 23 .. c function:: int PyGen_Check(ob)23 .. c:function:: int PyGen_Check(ob) 24 24 25 25 Return true if *ob* is a generator object; *ob* must not be *NULL*. 26 26 27 27 28 .. c function:: int PyGen_CheckExact(ob)28 .. c:function:: int PyGen_CheckExact(ob) 29 29 30 30 Return true if *ob*'s type is *PyGen_Type* is a generator object; *ob* must not … … 32 32 33 33 34 .. c function:: PyObject* PyGen_New(PyFrameObject *frame)34 .. c:function:: PyObject* PyGen_New(PyFrameObject *frame) 35 35 36 36 Create and return a new generator object based on the *frame* object. A -
python/vendor/current/Doc/c-api/import.rst
r2 r388 7 7 8 8 9 .. c function:: PyObject* PyImport_ImportModule(const char *name)9 .. c:function:: PyObject* PyImport_ImportModule(const char *name) 10 10 11 11 .. index:: … … 14 14 single: modules (in module sys) 15 15 16 This is a simplified interface to :c func:`PyImport_ImportModuleEx` below,16 This is a simplified interface to :c:func:`PyImport_ImportModuleEx` below, 17 17 leaving the *globals* and *locals* arguments set to *NULL* and *level* set 18 18 to 0. When the *name* … … 35 35 36 36 37 .. c function:: PyObject* PyImport_ImportModuleNoBlock(const char *name)38 39 This version of :c func:`PyImport_ImportModule` does not block. It's intended37 .. c:function:: PyObject* PyImport_ImportModuleNoBlock(const char *name) 38 39 This version of :c:func:`PyImport_ImportModule` does not block. It's intended 40 40 to be used in C functions that import other modules to execute a function. 41 41 The import may block if another thread holds the import lock. The function 42 :c func:`PyImport_ImportModuleNoBlock` never blocks. It first tries to fetch43 the module from sys.modules and falls back to :c func:`PyImport_ImportModule`42 :c:func:`PyImport_ImportModuleNoBlock` never blocks. It first tries to fetch 43 the module from sys.modules and falls back to :c:func:`PyImport_ImportModule` 44 44 unless the lock is held, in which case the function will raise an 45 45 :exc:`ImportError`. … … 48 48 49 49 50 .. c function:: PyObject* PyImport_ImportModuleEx(char *name, PyObject *globals, PyObject *locals, PyObject *fromlist)50 .. c:function:: PyObject* PyImport_ImportModuleEx(char *name, PyObject *globals, PyObject *locals, PyObject *fromlist) 51 51 52 52 .. index:: builtin: __import__ … … 66 66 67 67 .. versionchanged:: 2.6 68 The function is an alias for :c func:`PyImport_ImportModuleLevel` with68 The function is an alias for :c:func:`PyImport_ImportModuleLevel` with 69 69 -1 as level, meaning relative import. 70 70 71 71 72 .. c function:: PyObject* PyImport_ImportModuleLevel(char *name, PyObject *globals, PyObject *locals, PyObject *fromlist, int level)72 .. c:function:: PyObject* PyImport_ImportModuleLevel(char *name, PyObject *globals, PyObject *locals, PyObject *fromlist, int level) 73 73 74 74 Import a module. This is best described by referring to the built-in Python … … 84 84 85 85 86 .. c function:: PyObject* PyImport_Import(PyObject *name)86 .. c:function:: PyObject* PyImport_Import(PyObject *name) 87 87 88 88 .. index:: … … 99 99 100 100 101 .. c function:: PyObject* PyImport_ReloadModule(PyObject *m)101 .. c:function:: PyObject* PyImport_ReloadModule(PyObject *m) 102 102 103 103 .. index:: builtin: reload … … 109 109 110 110 111 .. c function:: PyObject* PyImport_AddModule(const char *name)111 .. c:function:: PyObject* PyImport_AddModule(const char *name) 112 112 113 113 Return the module object corresponding to a module name. The *name* argument … … 119 119 120 120 This function does not load or import the module; if the module wasn't already 121 loaded, you will get an empty module object. Use :c func:`PyImport_ImportModule`121 loaded, you will get an empty module object. Use :c:func:`PyImport_ImportModule` 122 122 or one of its variants to import a module. Package structures implied by a 123 123 dotted name for *name* are not created if not already present. 124 124 125 125 126 .. c function:: PyObject* PyImport_ExecCodeModule(char *name, PyObject *co)126 .. c:function:: PyObject* PyImport_ExecCodeModule(char *name, PyObject *co) 127 127 128 128 .. index:: builtin: compile … … 134 134 module could still be created in error cases. Starting with Python 2.4, *name* 135 135 is removed from :attr:`sys.modules` in error cases, and even if *name* was already 136 in :attr:`sys.modules` on entry to :c func:`PyImport_ExecCodeModule`. Leaving136 in :attr:`sys.modules` on entry to :c:func:`PyImport_ExecCodeModule`. Leaving 137 137 incompletely initialized modules in :attr:`sys.modules` is dangerous, as imports of 138 138 such modules have no way to know that the module object is an unknown (and 139 139 probably damaged with respect to the module author's intents) state. 140 140 141 The module's :attr:`__file__` attribute will be set to the code object's 142 :c:member:`co_filename`. 143 141 144 This function will reload the module if it was already imported. See 142 :c func:`PyImport_ReloadModule` for the intended way to reload a module.145 :c:func:`PyImport_ReloadModule` for the intended way to reload a module. 143 146 144 147 If *name* points to a dotted name of the form ``package.module``, any package … … 149 152 150 153 151 .. cfunction:: long PyImport_GetMagicNumber() 154 .. c:function:: PyObject* PyImport_ExecCodeModuleEx(char *name, PyObject *co, char *pathname) 155 156 Like :c:func:`PyImport_ExecCodeModule`, but the :attr:`__file__` attribute of 157 the module object is set to *pathname* if it is non-``NULL``. 158 159 160 .. c:function:: long PyImport_GetMagicNumber() 152 161 153 162 Return the magic number for Python bytecode files (a.k.a. :file:`.pyc` and … … 156 165 157 166 158 .. c function:: PyObject* PyImport_GetModuleDict()167 .. c:function:: PyObject* PyImport_GetModuleDict() 159 168 160 169 Return the dictionary used for the module administration (a.k.a. … … 162 171 163 172 164 .. c function:: PyObject* PyImport_GetImporter(PyObject *path)173 .. c:function:: PyObject* PyImport_GetImporter(PyObject *path) 165 174 166 175 Return an importer object for a :data:`sys.path`/:attr:`pkg.__path__` item … … 175 184 176 185 177 .. c function:: void _PyImport_Init()186 .. c:function:: void _PyImport_Init() 178 187 179 188 Initialize the import mechanism. For internal use only. 180 189 181 190 182 .. c function:: void PyImport_Cleanup()191 .. c:function:: void PyImport_Cleanup() 183 192 184 193 Empty the module table. For internal use only. 185 194 186 195 187 .. c function:: void _PyImport_Fini()196 .. c:function:: void _PyImport_Fini() 188 197 189 198 Finalize the import mechanism. For internal use only. 190 199 191 200 192 .. c function:: PyObject* _PyImport_FindExtension(char *, char *)201 .. c:function:: PyObject* _PyImport_FindExtension(char *, char *) 193 202 194 203 For internal use only. 195 204 196 205 197 .. c function:: PyObject* _PyImport_FixupExtension(char *, char *)206 .. c:function:: PyObject* _PyImport_FixupExtension(char *, char *) 198 207 199 208 For internal use only. 200 209 201 210 202 .. c function:: int PyImport_ImportFrozenModule(char *name)211 .. c:function:: int PyImport_ImportFrozenModule(char *name) 203 212 204 213 Load a frozen module named *name*. Return ``1`` for success, ``0`` if the 205 214 module is not found, and ``-1`` with an exception set if the initialization 206 215 failed. To access the imported module on a successful load, use 207 :c func:`PyImport_ImportModule`. (Note the misnomer --- this function would216 :c:func:`PyImport_ImportModule`. (Note the misnomer --- this function would 208 217 reload the module if it was already imported.) 209 218 210 219 211 .. c type:: struct _frozen220 .. c:type:: struct _frozen 212 221 213 222 .. index:: single: freeze utility … … 225 234 226 235 227 .. c var:: struct _frozen* PyImport_FrozenModules228 229 This pointer is initialized to point to an array of :c type:`struct _frozen`236 .. c:var:: struct _frozen* PyImport_FrozenModules 237 238 This pointer is initialized to point to an array of :c:type:`struct _frozen` 230 239 records, terminated by one whose members are all *NULL* or zero. When a frozen 231 240 module is imported, it is searched in this table. Third-party code could play … … 233 242 234 243 235 .. c function:: int PyImport_AppendInittab(char *name, void (*initfunc)(void))244 .. c:function:: int PyImport_AppendInittab(const char *name, void (*initfunc)(void)) 236 245 237 246 Add a single module to the existing table of built-in modules. This is a 238 convenience wrapper around :c func:`PyImport_ExtendInittab`, returning ``-1`` if247 convenience wrapper around :c:func:`PyImport_ExtendInittab`, returning ``-1`` if 239 248 the table could not be extended. The new module can be imported by the name 240 249 *name*, and uses the function *initfunc* as the initialization function called 241 250 on the first attempted import. This should be called before 242 :c func:`Py_Initialize`.243 244 245 .. c type:: struct _inittab251 :c:func:`Py_Initialize`. 252 253 254 .. c:type:: struct _inittab 246 255 247 256 Structure describing a single entry in the list of built-in modules. Each of 248 257 these structures gives the name and initialization function for a module built 249 258 into the interpreter. Programs which embed Python may use an array of these 250 structures in conjunction with :c func:`PyImport_ExtendInittab` to provide259 structures in conjunction with :c:func:`PyImport_ExtendInittab` to provide 251 260 additional built-in modules. The structure is defined in 252 261 :file:`Include/import.h` as:: … … 258 267 259 268 260 .. c function:: int PyImport_ExtendInittab(struct _inittab *newtab)269 .. c:function:: int PyImport_ExtendInittab(struct _inittab *newtab) 261 270 262 271 Add a collection of modules to the table of built-in modules. The *newtab* … … 265 274 Returns ``0`` on success or ``-1`` if insufficient memory could be allocated to 266 275 extend the internal table. In the event of failure, no modules are added to the 267 internal table. This should be called before :c func:`Py_Initialize`.276 internal table. This should be called before :c:func:`Py_Initialize`. -
python/vendor/current/Doc/c-api/index.rst
r2 r388 4 4 Python/C API Reference Manual 5 5 ################################## 6 7 :Release: |version|8 :Date: |today|9 6 10 7 This manual documents the API used by C and C++ programmers who want to write -
python/vendor/current/Doc/c-api/init.rst
r2 r388 9 9 10 10 11 .. cfunction:: void Py_Initialize() 11 Initializing and finalizing the interpreter 12 =========================================== 13 14 15 .. c:function:: void Py_Initialize() 12 16 13 17 .. index:: … … 23 27 triple: module; search; path 24 28 single: PySys_SetArgv() 29 single: PySys_SetArgvEx() 25 30 single: Py_Finalize() 26 31 27 32 Initialize the Python interpreter. In an application embedding Python, this 28 33 should be called before using any other Python/C API functions; with the 29 exception of :c func:`Py_SetProgramName`, :cfunc:`PyEval_InitThreads`,30 :c func:`PyEval_ReleaseLock`, and :cfunc:`PyEval_AcquireLock`. This initializes34 exception of :c:func:`Py_SetProgramName`, :c:func:`Py_SetPythonHome`, :c:func:`PyEval_InitThreads`, 35 :c:func:`PyEval_ReleaseLock`, and :c:func:`PyEval_AcquireLock`. This initializes 31 36 the table of loaded modules (``sys.modules``), and creates the fundamental 32 37 modules :mod:`__builtin__`, :mod:`__main__` and :mod:`sys`. It also initializes 33 38 the module search path (``sys.path``). It does not set ``sys.argv``; use 34 :c func:`PySys_SetArgv` for that. This is a no-op when called for a second time35 (without calling :c func:`Py_Finalize` first). There is no return value; it is a39 :c:func:`PySys_SetArgvEx` for that. This is a no-op when called for a second time 40 (without calling :c:func:`Py_Finalize` first). There is no return value; it is a 36 41 fatal error if the initialization fails. 37 42 38 43 39 .. c function:: void Py_InitializeEx(int initsigs)40 41 This function works like :c func:`Py_Initialize` if *initsigs* is 1. If44 .. c:function:: void Py_InitializeEx(int initsigs) 45 46 This function works like :c:func:`Py_Initialize` if *initsigs* is 1. If 42 47 *initsigs* is 0, it skips initialization registration of signal handlers, which 43 48 might be useful when Python is embedded. … … 46 51 47 52 48 .. c function:: int Py_IsInitialized()53 .. c:function:: int Py_IsInitialized() 49 54 50 55 Return true (nonzero) when the Python interpreter has been initialized, false 51 (zero) if not. After :c func:`Py_Finalize` is called, this returns false until52 :c func:`Py_Initialize` is called again.53 54 55 .. c function:: void Py_Finalize()56 57 Undo all initializations made by :c func:`Py_Initialize` and subsequent use of56 (zero) if not. After :c:func:`Py_Finalize` is called, this returns false until 57 :c:func:`Py_Initialize` is called again. 58 59 60 .. c:function:: void Py_Finalize() 61 62 Undo all initializations made by :c:func:`Py_Initialize` and subsequent use of 58 63 Python/C API functions, and destroy all sub-interpreters (see 59 :c func:`Py_NewInterpreter` below) that were created and not yet destroyed since60 the last call to :c func:`Py_Initialize`. Ideally, this frees all memory64 :c:func:`Py_NewInterpreter` below) that were created and not yet destroyed since 65 the last call to :c:func:`Py_Initialize`. Ideally, this frees all memory 61 66 allocated by the Python interpreter. This is a no-op when called for a second 62 time (without calling :c func:`Py_Initialize` again first). There is no return67 time (without calling :c:func:`Py_Initialize` again first). There is no return 63 68 value; errors during finalization are ignored. 64 69 … … 79 84 freed. Some memory allocated by extension modules may not be freed. Some 80 85 extensions may not work properly if their initialization routine is called more 81 than once; this can happen if an application calls :cfunc:`Py_Initialize` and 82 :cfunc:`Py_Finalize` more than once. 83 84 85 .. cfunction:: PyThreadState* Py_NewInterpreter() 86 than once; this can happen if an application calls :c:func:`Py_Initialize` and 87 :c:func:`Py_Finalize` more than once. 88 89 90 Process-wide parameters 91 ======================= 92 93 94 .. c:function:: void Py_SetProgramName(char *name) 86 95 87 96 .. index:: 88 module: __builtin__ 97 single: Py_Initialize() 98 single: main() 99 single: Py_GetPath() 100 101 This function should be called before :c:func:`Py_Initialize` is called for 102 the first time, if it is called at all. It tells the interpreter the value 103 of the ``argv[0]`` argument to the :c:func:`main` function of the program. 104 This is used by :c:func:`Py_GetPath` and some other functions below to find 105 the Python run-time libraries relative to the interpreter executable. The 106 default value is ``'python'``. The argument should point to a 107 zero-terminated character string in static storage whose contents will not 108 change for the duration of the program's execution. No code in the Python 109 interpreter will change the contents of this storage. 110 111 112 .. c:function:: char* Py_GetProgramName() 113 114 .. index:: single: Py_SetProgramName() 115 116 Return the program name set with :c:func:`Py_SetProgramName`, or the default. 117 The returned string points into static storage; the caller should not modify its 118 value. 119 120 121 .. c:function:: char* Py_GetPrefix() 122 123 Return the *prefix* for installed platform-independent files. This is derived 124 through a number of complicated rules from the program name set with 125 :c:func:`Py_SetProgramName` and some environment variables; for example, if the 126 program name is ``'/usr/local/bin/python'``, the prefix is ``'/usr/local'``. The 127 returned string points into static storage; the caller should not modify its 128 value. This corresponds to the :makevar:`prefix` variable in the top-level 129 :file:`Makefile` and the ``--prefix`` argument to the :program:`configure` 130 script at build time. The value is available to Python code as ``sys.prefix``. 131 It is only useful on Unix. See also the next function. 132 133 134 .. c:function:: char* Py_GetExecPrefix() 135 136 Return the *exec-prefix* for installed platform-*dependent* files. This is 137 derived through a number of complicated rules from the program name set with 138 :c:func:`Py_SetProgramName` and some environment variables; for example, if the 139 program name is ``'/usr/local/bin/python'``, the exec-prefix is 140 ``'/usr/local'``. The returned string points into static storage; the caller 141 should not modify its value. This corresponds to the :makevar:`exec_prefix` 142 variable in the top-level :file:`Makefile` and the ``--exec-prefix`` 143 argument to the :program:`configure` script at build time. The value is 144 available to Python code as ``sys.exec_prefix``. It is only useful on Unix. 145 146 Background: The exec-prefix differs from the prefix when platform dependent 147 files (such as executables and shared libraries) are installed in a different 148 directory tree. In a typical installation, platform dependent files may be 149 installed in the :file:`/usr/local/plat` subtree while platform independent may 150 be installed in :file:`/usr/local`. 151 152 Generally speaking, a platform is a combination of hardware and software 153 families, e.g. Sparc machines running the Solaris 2.x operating system are 154 considered the same platform, but Intel machines running Solaris 2.x are another 155 platform, and Intel machines running Linux are yet another platform. Different 156 major revisions of the same operating system generally also form different 157 platforms. Non-Unix operating systems are a different story; the installation 158 strategies on those systems are so different that the prefix and exec-prefix are 159 meaningless, and set to the empty string. Note that compiled Python bytecode 160 files are platform independent (but not independent from the Python version by 161 which they were compiled!). 162 163 System administrators will know how to configure the :program:`mount` or 164 :program:`automount` programs to share :file:`/usr/local` between platforms 165 while having :file:`/usr/local/plat` be a different filesystem for each 166 platform. 167 168 169 .. c:function:: char* Py_GetProgramFullPath() 170 171 .. index:: 172 single: Py_SetProgramName() 173 single: executable (in module sys) 174 175 Return the full program name of the Python executable; this is computed as a 176 side-effect of deriving the default module search path from the program name 177 (set by :c:func:`Py_SetProgramName` above). The returned string points into 178 static storage; the caller should not modify its value. The value is available 179 to Python code as ``sys.executable``. 180 181 182 .. c:function:: char* Py_GetPath() 183 184 .. index:: 185 triple: module; search; path 186 single: path (in module sys) 187 188 Return the default module search path; this is computed from the program name 189 (set by :c:func:`Py_SetProgramName` above) and some environment variables. 190 The returned string consists of a series of directory names separated by a 191 platform dependent delimiter character. The delimiter character is ``':'`` 192 on Unix and Mac OS X, ``';'`` on Windows. The returned string points into 193 static storage; the caller should not modify its value. The list 194 :data:`sys.path` is initialized with this value on interpreter startup; it 195 can be (and usually is) modified later to change the search path for loading 196 modules. 197 198 .. XXX should give the exact rules 199 200 201 .. c:function:: const char* Py_GetVersion() 202 203 Return the version of this Python interpreter. This is a string that looks 204 something like :: 205 206 "1.5 (#67, Dec 31 1997, 22:34:28) [GCC 2.7.2.2]" 207 208 .. index:: single: version (in module sys) 209 210 The first word (up to the first space character) is the current Python version; 211 the first three characters are the major and minor version separated by a 212 period. The returned string points into static storage; the caller should not 213 modify its value. The value is available to Python code as ``sys.version``. 214 215 216 .. c:function:: const char* Py_GetPlatform() 217 218 .. index:: single: platform (in module sys) 219 220 Return the platform identifier for the current platform. On Unix, this is 221 formed from the "official" name of the operating system, converted to lower 222 case, followed by the major revision number; e.g., for Solaris 2.x, which is 223 also known as SunOS 5.x, the value is ``'sunos5'``. On Mac OS X, it is 224 ``'darwin'``. On Windows, it is ``'win'``. The returned string points into 225 static storage; the caller should not modify its value. The value is available 226 to Python code as ``sys.platform``. 227 228 229 .. c:function:: const char* Py_GetCopyright() 230 231 Return the official copyright string for the current Python version, for example 232 233 ``'Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam'`` 234 235 .. index:: single: copyright (in module sys) 236 237 The returned string points into static storage; the caller should not modify its 238 value. The value is available to Python code as ``sys.copyright``. 239 240 241 .. c:function:: const char* Py_GetCompiler() 242 243 Return an indication of the compiler used to build the current Python version, 244 in square brackets, for example:: 245 246 "[GCC 2.7.2.2]" 247 248 .. index:: single: version (in module sys) 249 250 The returned string points into static storage; the caller should not modify its 251 value. The value is available to Python code as part of the variable 252 ``sys.version``. 253 254 255 .. c:function:: const char* Py_GetBuildInfo() 256 257 Return information about the sequence number and build date and time of the 258 current Python interpreter instance, for example :: 259 260 "#67, Aug 1 1997, 22:34:28" 261 262 .. index:: single: version (in module sys) 263 264 The returned string points into static storage; the caller should not modify its 265 value. The value is available to Python code as part of the variable 266 ``sys.version``. 267 268 269 .. c:function:: void PySys_SetArgvEx(int argc, char **argv, int updatepath) 270 271 .. index:: 272 single: main() 273 single: Py_FatalError() 274 single: argv (in module sys) 275 276 Set :data:`sys.argv` based on *argc* and *argv*. These parameters are 277 similar to those passed to the program's :c:func:`main` function with the 278 difference that the first entry should refer to the script file to be 279 executed rather than the executable hosting the Python interpreter. If there 280 isn't a script that will be run, the first entry in *argv* can be an empty 281 string. If this function fails to initialize :data:`sys.argv`, a fatal 282 condition is signalled using :c:func:`Py_FatalError`. 283 284 If *updatepath* is zero, this is all the function does. If *updatepath* 285 is non-zero, the function also modifies :data:`sys.path` according to the 286 following algorithm: 287 288 - If the name of an existing script is passed in ``argv[0]``, the absolute 289 path of the directory where the script is located is prepended to 290 :data:`sys.path`. 291 - Otherwise (that is, if *argc* is 0 or ``argv[0]`` doesn't point 292 to an existing file name), an empty string is prepended to 293 :data:`sys.path`, which is the same as prepending the current working 294 directory (``"."``). 295 296 .. note:: 297 It is recommended that applications embedding the Python interpreter 298 for purposes other than executing a single script pass 0 as *updatepath*, 299 and update :data:`sys.path` themselves if desired. 300 See `CVE-2008-5983 <http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-5983>`_. 301 302 On versions before 2.6.6, you can achieve the same effect by manually 303 popping the first :data:`sys.path` element after having called 304 :c:func:`PySys_SetArgv`, for example using:: 305 306 PyRun_SimpleString("import sys; sys.path.pop(0)\n"); 307 308 .. versionadded:: 2.6.6 309 310 .. XXX impl. doesn't seem consistent in allowing 0/NULL for the params; 311 check w/ Guido. 312 313 314 .. c:function:: void PySys_SetArgv(int argc, char **argv) 315 316 This function works like :c:func:`PySys_SetArgvEx` with *updatepath* set to 1. 317 318 319 .. c:function:: void Py_SetPythonHome(char *home) 320 321 Set the default "home" directory, that is, the location of the standard 322 Python libraries. See :envvar:`PYTHONHOME` for the meaning of the 323 argument string. 324 325 The argument should point to a zero-terminated character string in static 326 storage whose contents will not change for the duration of the program's 327 execution. No code in the Python interpreter will change the contents of 328 this storage. 329 330 331 .. c:function:: char* Py_GetPythonHome() 332 333 Return the default "home", that is, the value set by a previous call to 334 :c:func:`Py_SetPythonHome`, or the value of the :envvar:`PYTHONHOME` 335 environment variable if it is set. 336 337 338 .. _threads: 339 340 Thread State and the Global Interpreter Lock 341 ============================================ 342 343 .. index:: 344 single: GIL 345 single: global interpreter lock 346 single: interpreter lock 347 single: lock, interpreter 348 349 The Python interpreter is not fully thread-safe. In order to support 350 multi-threaded Python programs, there's a global lock, called the :term:`global 351 interpreter lock` or :term:`GIL`, that must be held by the current thread before 352 it can safely access Python objects. Without the lock, even the simplest 353 operations could cause problems in a multi-threaded program: for example, when 354 two threads simultaneously increment the reference count of the same object, the 355 reference count could end up being incremented only once instead of twice. 356 357 .. index:: single: setcheckinterval() (in module sys) 358 359 Therefore, the rule exists that only the thread that has acquired the 360 :term:`GIL` may operate on Python objects or call Python/C API functions. 361 In order to emulate concurrency of execution, the interpreter regularly 362 tries to switch threads (see :func:`sys.setcheckinterval`). The lock is also 363 released around potentially blocking I/O operations like reading or writing 364 a file, so that other Python threads can run in the meantime. 365 366 .. index:: 367 single: PyThreadState 368 single: PyThreadState 369 370 The Python interpreter keeps some thread-specific bookkeeping information 371 inside a data structure called :c:type:`PyThreadState`. There's also one 372 global variable pointing to the current :c:type:`PyThreadState`: it can 373 be retrieved using :c:func:`PyThreadState_Get`. 374 375 Releasing the GIL from extension code 376 ------------------------------------- 377 378 Most extension code manipulating the :term:`GIL` has the following simple 379 structure:: 380 381 Save the thread state in a local variable. 382 Release the global interpreter lock. 383 ... Do some blocking I/O operation ... 384 Reacquire the global interpreter lock. 385 Restore the thread state from the local variable. 386 387 This is so common that a pair of macros exists to simplify it:: 388 389 Py_BEGIN_ALLOW_THREADS 390 ... Do some blocking I/O operation ... 391 Py_END_ALLOW_THREADS 392 393 .. index:: 394 single: Py_BEGIN_ALLOW_THREADS 395 single: Py_END_ALLOW_THREADS 396 397 The :c:macro:`Py_BEGIN_ALLOW_THREADS` macro opens a new block and declares a 398 hidden local variable; the :c:macro:`Py_END_ALLOW_THREADS` macro closes the 399 block. These two macros are still available when Python is compiled without 400 thread support (they simply have an empty expansion). 401 402 When thread support is enabled, the block above expands to the following code:: 403 404 PyThreadState *_save; 405 406 _save = PyEval_SaveThread(); 407 ...Do some blocking I/O operation... 408 PyEval_RestoreThread(_save); 409 410 .. index:: 411 single: PyEval_RestoreThread() 412 single: PyEval_SaveThread() 413 414 Here is how these functions work: the global interpreter lock is used to protect the pointer to the 415 current thread state. When releasing the lock and saving the thread state, 416 the current thread state pointer must be retrieved before the lock is released 417 (since another thread could immediately acquire the lock and store its own thread 418 state in the global variable). Conversely, when acquiring the lock and restoring 419 the thread state, the lock must be acquired before storing the thread state 420 pointer. 421 422 .. note:: 423 Calling system I/O functions is the most common use case for releasing 424 the GIL, but it can also be useful before calling long-running computations 425 which don't need access to Python objects, such as compression or 426 cryptographic functions operating over memory buffers. For example, the 427 standard :mod:`zlib` and :mod:`hashlib` modules release the GIL when 428 compressing or hashing data. 429 430 431 .. _gilstate: 432 433 Non-Python created threads 434 -------------------------- 435 436 When threads are created using the dedicated Python APIs (such as the 437 :mod:`threading` module), a thread state is automatically associated to them 438 and the code showed above is therefore correct. However, when threads are 439 created from C (for example by a third-party library with its own thread 440 management), they don't hold the GIL, nor is there a thread state structure 441 for them. 442 443 If you need to call Python code from these threads (often this will be part 444 of a callback API provided by the aforementioned third-party library), 445 you must first register these threads with the interpreter by 446 creating a thread state data structure, then acquiring the GIL, and finally 447 storing their thread state pointer, before you can start using the Python/C 448 API. When you are done, you should reset the thread state pointer, release 449 the GIL, and finally free the thread state data structure. 450 451 The :c:func:`PyGILState_Ensure` and :c:func:`PyGILState_Release` functions do 452 all of the above automatically. The typical idiom for calling into Python 453 from a C thread is:: 454 455 PyGILState_STATE gstate; 456 gstate = PyGILState_Ensure(); 457 458 /* Perform Python actions here. */ 459 result = CallSomeFunction(); 460 /* evaluate result or handle exception */ 461 462 /* Release the thread. No Python API allowed beyond this point. */ 463 PyGILState_Release(gstate); 464 465 Note that the :c:func:`PyGILState_\*` functions assume there is only one global 466 interpreter (created automatically by :c:func:`Py_Initialize`). Python 467 supports the creation of additional interpreters (using 468 :c:func:`Py_NewInterpreter`), but mixing multiple interpreters and the 469 :c:func:`PyGILState_\*` API is unsupported. 470 471 Another important thing to note about threads is their behaviour in the face 472 of the C :c:func:`fork` call. On most systems with :c:func:`fork`, after a 473 process forks only the thread that issued the fork will exist. That also 474 means any locks held by other threads will never be released. Python solves 475 this for :func:`os.fork` by acquiring the locks it uses internally before 476 the fork, and releasing them afterwards. In addition, it resets any 477 :ref:`lock-objects` in the child. When extending or embedding Python, there 478 is no way to inform Python of additional (non-Python) locks that need to be 479 acquired before or reset after a fork. OS facilities such as 480 :c:func:`pthread_atfork` would need to be used to accomplish the same thing. 481 Additionally, when extending or embedding Python, calling :c:func:`fork` 482 directly rather than through :func:`os.fork` (and returning to or calling 483 into Python) may result in a deadlock by one of Python's internal locks 484 being held by a thread that is defunct after the fork. 485 :c:func:`PyOS_AfterFork` tries to reset the necessary locks, but is not 486 always able to. 487 488 489 High-level API 490 -------------- 491 492 These are the most commonly used types and functions when writing C extension 493 code, or when embedding the Python interpreter: 494 495 .. c:type:: PyInterpreterState 496 497 This data structure represents the state shared by a number of cooperating 498 threads. Threads belonging to the same interpreter share their module 499 administration and a few other internal items. There are no public members in 500 this structure. 501 502 Threads belonging to different interpreters initially share nothing, except 503 process state like available memory, open file descriptors and such. The global 504 interpreter lock is also shared by all threads, regardless of to which 505 interpreter they belong. 506 507 508 .. c:type:: PyThreadState 509 510 This data structure represents the state of a single thread. The only public 511 data member is :c:type:`PyInterpreterState \*`:attr:`interp`, which points to 512 this thread's interpreter state. 513 514 515 .. c:function:: void PyEval_InitThreads() 516 517 .. index:: 518 single: PyEval_ReleaseLock() 519 single: PyEval_ReleaseThread() 520 single: PyEval_SaveThread() 521 single: PyEval_RestoreThread() 522 523 Initialize and acquire the global interpreter lock. It should be called in the 524 main thread before creating a second thread or engaging in any other thread 525 operations such as :c:func:`PyEval_ReleaseLock` or 526 ``PyEval_ReleaseThread(tstate)``. It is not needed before calling 527 :c:func:`PyEval_SaveThread` or :c:func:`PyEval_RestoreThread`. 528 529 .. index:: single: Py_Initialize() 530 531 This is a no-op when called for a second time. It is safe to call this function 532 before calling :c:func:`Py_Initialize`. 533 534 .. index:: module: thread 535 536 .. note:: 537 When only the main thread exists, no GIL operations are needed. This is a 538 common situation (most Python programs do not use threads), and the lock 539 operations slow the interpreter down a bit. Therefore, the lock is not 540 created initially. This situation is equivalent to having acquired the lock: 541 when there is only a single thread, all object accesses are safe. Therefore, 542 when this function initializes the global interpreter lock, it also acquires 543 it. Before the Python :mod:`_thread` module creates a new thread, knowing 544 that either it has the lock or the lock hasn't been created yet, it calls 545 :c:func:`PyEval_InitThreads`. When this call returns, it is guaranteed that 546 the lock has been created and that the calling thread has acquired it. 547 548 It is **not** safe to call this function when it is unknown which thread (if 549 any) currently has the global interpreter lock. 550 551 This function is not available when thread support is disabled at compile time. 552 553 554 .. c:function:: int PyEval_ThreadsInitialized() 555 556 Returns a non-zero value if :c:func:`PyEval_InitThreads` has been called. This 557 function can be called without holding the GIL, and therefore can be used to 558 avoid calls to the locking API when running single-threaded. This function is 559 not available when thread support is disabled at compile time. 560 561 .. versionadded:: 2.4 562 563 564 .. c:function:: PyThreadState* PyEval_SaveThread() 565 566 Release the global interpreter lock (if it has been created and thread 567 support is enabled) and reset the thread state to *NULL*, returning the 568 previous thread state (which is not *NULL*). If the lock has been created, 569 the current thread must have acquired it. (This function is available even 570 when thread support is disabled at compile time.) 571 572 573 .. c:function:: void PyEval_RestoreThread(PyThreadState *tstate) 574 575 Acquire the global interpreter lock (if it has been created and thread 576 support is enabled) and set the thread state to *tstate*, which must not be 577 *NULL*. If the lock has been created, the current thread must not have 578 acquired it, otherwise deadlock ensues. (This function is available even 579 when thread support is disabled at compile time.) 580 581 582 .. c:function:: PyThreadState* PyThreadState_Get() 583 584 Return the current thread state. The global interpreter lock must be held. 585 When the current thread state is *NULL*, this issues a fatal error (so that 586 the caller needn't check for *NULL*). 587 588 589 .. c:function:: PyThreadState* PyThreadState_Swap(PyThreadState *tstate) 590 591 Swap the current thread state with the thread state given by the argument 592 *tstate*, which may be *NULL*. The global interpreter lock must be held 593 and is not released. 594 595 596 .. c:function:: void PyEval_ReInitThreads() 597 598 This function is called from :c:func:`PyOS_AfterFork` to ensure that newly 599 created child processes don't hold locks referring to threads which 600 are not running in the child process. 601 602 603 The following functions use thread-local storage, and are not compatible 604 with sub-interpreters: 605 606 .. c:function:: PyGILState_STATE PyGILState_Ensure() 607 608 Ensure that the current thread is ready to call the Python C API regardless 609 of the current state of Python, or of the global interpreter lock. This may 610 be called as many times as desired by a thread as long as each call is 611 matched with a call to :c:func:`PyGILState_Release`. In general, other 612 thread-related APIs may be used between :c:func:`PyGILState_Ensure` and 613 :c:func:`PyGILState_Release` calls as long as the thread state is restored to 614 its previous state before the Release(). For example, normal usage of the 615 :c:macro:`Py_BEGIN_ALLOW_THREADS` and :c:macro:`Py_END_ALLOW_THREADS` macros is 616 acceptable. 617 618 The return value is an opaque "handle" to the thread state when 619 :c:func:`PyGILState_Ensure` was called, and must be passed to 620 :c:func:`PyGILState_Release` to ensure Python is left in the same state. Even 621 though recursive calls are allowed, these handles *cannot* be shared - each 622 unique call to :c:func:`PyGILState_Ensure` must save the handle for its call 623 to :c:func:`PyGILState_Release`. 624 625 When the function returns, the current thread will hold the GIL and be able 626 to call arbitrary Python code. Failure is a fatal error. 627 628 .. versionadded:: 2.3 629 630 631 .. c:function:: void PyGILState_Release(PyGILState_STATE) 632 633 Release any resources previously acquired. After this call, Python's state will 634 be the same as it was prior to the corresponding :c:func:`PyGILState_Ensure` call 635 (but generally this state will be unknown to the caller, hence the use of the 636 GILState API). 637 638 Every call to :c:func:`PyGILState_Ensure` must be matched by a call to 639 :c:func:`PyGILState_Release` on the same thread. 640 641 .. versionadded:: 2.3 642 643 644 .. c:function:: PyThreadState PyGILState_GetThisThreadState() 645 646 Get the current thread state for this thread. May return ``NULL`` if no 647 GILState API has been used on the current thread. Note that the main thread 648 always has such a thread-state, even if no auto-thread-state call has been 649 made on the main thread. This is mainly a helper/diagnostic function. 650 651 .. versionadded:: 2.3 652 653 654 The following macros are normally used without a trailing semicolon; look for 655 example usage in the Python source distribution. 656 657 658 .. c:macro:: Py_BEGIN_ALLOW_THREADS 659 660 This macro expands to ``{ PyThreadState *_save; _save = PyEval_SaveThread();``. 661 Note that it contains an opening brace; it must be matched with a following 662 :c:macro:`Py_END_ALLOW_THREADS` macro. See above for further discussion of this 663 macro. It is a no-op when thread support is disabled at compile time. 664 665 666 .. c:macro:: Py_END_ALLOW_THREADS 667 668 This macro expands to ``PyEval_RestoreThread(_save); }``. Note that it contains 669 a closing brace; it must be matched with an earlier 670 :c:macro:`Py_BEGIN_ALLOW_THREADS` macro. See above for further discussion of 671 this macro. It is a no-op when thread support is disabled at compile time. 672 673 674 .. c:macro:: Py_BLOCK_THREADS 675 676 This macro expands to ``PyEval_RestoreThread(_save);``: it is equivalent to 677 :c:macro:`Py_END_ALLOW_THREADS` without the closing brace. It is a no-op when 678 thread support is disabled at compile time. 679 680 681 .. c:macro:: Py_UNBLOCK_THREADS 682 683 This macro expands to ``_save = PyEval_SaveThread();``: it is equivalent to 684 :c:macro:`Py_BEGIN_ALLOW_THREADS` without the opening brace and variable 685 declaration. It is a no-op when thread support is disabled at compile time. 686 687 688 Low-level API 689 ------------- 690 691 All of the following functions are only available when thread support is enabled 692 at compile time, and must be called only when the global interpreter lock has 693 been created. 694 695 696 .. c:function:: PyInterpreterState* PyInterpreterState_New() 697 698 Create a new interpreter state object. The global interpreter lock need not 699 be held, but may be held if it is necessary to serialize calls to this 700 function. 701 702 703 .. c:function:: void PyInterpreterState_Clear(PyInterpreterState *interp) 704 705 Reset all information in an interpreter state object. The global interpreter 706 lock must be held. 707 708 709 .. c:function:: void PyInterpreterState_Delete(PyInterpreterState *interp) 710 711 Destroy an interpreter state object. The global interpreter lock need not be 712 held. The interpreter state must have been reset with a previous call to 713 :c:func:`PyInterpreterState_Clear`. 714 715 716 .. c:function:: PyThreadState* PyThreadState_New(PyInterpreterState *interp) 717 718 Create a new thread state object belonging to the given interpreter object. 719 The global interpreter lock need not be held, but may be held if it is 720 necessary to serialize calls to this function. 721 722 723 .. c:function:: void PyThreadState_Clear(PyThreadState *tstate) 724 725 Reset all information in a thread state object. The global interpreter lock 726 must be held. 727 728 729 .. c:function:: void PyThreadState_Delete(PyThreadState *tstate) 730 731 Destroy a thread state object. The global interpreter lock need not be held. 732 The thread state must have been reset with a previous call to 733 :c:func:`PyThreadState_Clear`. 734 735 736 .. c:function:: PyObject* PyThreadState_GetDict() 737 738 Return a dictionary in which extensions can store thread-specific state 739 information. Each extension should use a unique key to use to store state in 740 the dictionary. It is okay to call this function when no current thread state 741 is available. If this function returns *NULL*, no exception has been raised and 742 the caller should assume no current thread state is available. 743 744 .. versionchanged:: 2.3 745 Previously this could only be called when a current thread is active, and *NULL* 746 meant that an exception was raised. 747 748 749 .. c:function:: int PyThreadState_SetAsyncExc(long id, PyObject *exc) 750 751 Asynchronously raise an exception in a thread. The *id* argument is the thread 752 id of the target thread; *exc* is the exception object to be raised. This 753 function does not steal any references to *exc*. To prevent naive misuse, you 754 must write your own C extension to call this. Must be called with the GIL held. 755 Returns the number of thread states modified; this is normally one, but will be 756 zero if the thread id isn't found. If *exc* is :const:`NULL`, the pending 757 exception (if any) for the thread is cleared. This raises no exceptions. 758 759 .. versionadded:: 2.3 760 761 762 .. c:function:: void PyEval_AcquireThread(PyThreadState *tstate) 763 764 Acquire the global interpreter lock and set the current thread state to 765 *tstate*, which should not be *NULL*. The lock must have been created earlier. 766 If this thread already has the lock, deadlock ensues. 767 768 :c:func:`PyEval_RestoreThread` is a higher-level function which is always 769 available (even when thread support isn't enabled or when threads have 770 not been initialized). 771 772 773 .. c:function:: void PyEval_ReleaseThread(PyThreadState *tstate) 774 775 Reset the current thread state to *NULL* and release the global interpreter 776 lock. The lock must have been created earlier and must be held by the current 777 thread. The *tstate* argument, which must not be *NULL*, is only used to check 778 that it represents the current thread state --- if it isn't, a fatal error is 779 reported. 780 781 :c:func:`PyEval_SaveThread` is a higher-level function which is always 782 available (even when thread support isn't enabled or when threads have 783 not been initialized). 784 785 786 .. c:function:: void PyEval_AcquireLock() 787 788 Acquire the global interpreter lock. The lock must have been created earlier. 789 If this thread already has the lock, a deadlock ensues. 790 791 .. warning:: 792 This function does not change the current thread state. Please use 793 :c:func:`PyEval_RestoreThread` or :c:func:`PyEval_AcquireThread` 794 instead. 795 796 797 .. c:function:: void PyEval_ReleaseLock() 798 799 Release the global interpreter lock. The lock must have been created earlier. 800 801 .. warning:: 802 This function does not change the current thread state. Please use 803 :c:func:`PyEval_SaveThread` or :c:func:`PyEval_ReleaseThread` 804 instead. 805 806 807 Sub-interpreter support 808 ======================= 809 810 While in most uses, you will only embed a single Python interpreter, there 811 are cases where you need to create several independent interpreters in the 812 same process and perhaps even in the same thread. Sub-interpreters allow 813 you to do that. You can switch between sub-interpreters using the 814 :c:func:`PyThreadState_Swap` function. You can create and destroy them 815 using the following functions: 816 817 818 .. c:function:: PyThreadState* Py_NewInterpreter() 819 820 .. index:: 821 module: builtins 89 822 module: __main__ 90 823 module: sys … … 96 829 for the execution of Python code. In particular, the new interpreter has 97 830 separate, independent versions of all imported modules, including the 98 fundamental modules :mod:` __builtin__`, :mod:`__main__` and :mod:`sys`. The831 fundamental modules :mod:`builtins`, :mod:`__main__` and :mod:`sys`. The 99 832 table of loaded modules (``sys.modules``) and the module search path 100 833 (``sys.path``) are also separate. The new environment has no ``sys.argv`` 101 834 variable. It has new standard I/O stream file objects ``sys.stdin``, 102 835 ``sys.stdout`` and ``sys.stderr`` (however these refer to the same underlying 103 :ctype:`FILE` structures in the C library).836 file descriptors). 104 837 105 838 The return value points to the first thread state created in the new … … 125 858 not called. Note that this is different from what happens when an extension is 126 859 imported after the interpreter has been completely re-initialized by calling 127 :c func:`Py_Finalize` and :cfunc:`Py_Initialize`; in that case, the extension's860 :c:func:`Py_Finalize` and :c:func:`Py_Initialize`; in that case, the extension's 128 861 ``initmodule`` function *is* called again. 129 862 130 863 .. index:: single: close() (in module os) 131 864 132 **Bugs and caveats:** Because sub-interpreters (and the main interpreter) are 133 part of the same process, the insulation between them isn't perfect --- for 134 example, using low-level file operations like :func:`os.close` they can 135 (accidentally or maliciously) affect each other's open files. Because of the 136 way extensions are shared between (sub-)interpreters, some extensions may not 137 work properly; this is especially likely when the extension makes use of 138 (static) global variables, or when the extension manipulates its module's 139 dictionary after its initialization. It is possible to insert objects created 140 in one sub-interpreter into a namespace of another sub-interpreter; this should 141 be done with great care to avoid sharing user-defined functions, methods, 142 instances or classes between sub-interpreters, since import operations executed 143 by such objects may affect the wrong (sub-)interpreter's dictionary of loaded 144 modules. (XXX This is a hard-to-fix bug that will be addressed in a future 145 release.) 146 147 Also note that the use of this functionality is incompatible with extension 148 modules such as PyObjC and ctypes that use the :cfunc:`PyGILState_\*` APIs (and 149 this is inherent in the way the :cfunc:`PyGILState_\*` functions work). Simple 150 things may work, but confusing behavior will always be near. 151 152 153 .. cfunction:: void Py_EndInterpreter(PyThreadState *tstate) 865 866 .. c:function:: void Py_EndInterpreter(PyThreadState *tstate) 154 867 155 868 .. index:: single: Py_Finalize() … … 160 873 thread states associated with this interpreter are destroyed. (The global 161 874 interpreter lock must be held before calling this function and is still held 162 when it returns.) :c func:`Py_Finalize` will destroy all sub-interpreters that875 when it returns.) :c:func:`Py_Finalize` will destroy all sub-interpreters that 163 876 haven't been explicitly destroyed at that point. 164 877 165 878 166 .. cfunction:: void Py_SetProgramName(char *name) 167 168 .. index:: 169 single: Py_Initialize() 170 single: main() 171 single: Py_GetPath() 172 173 This function should be called before :cfunc:`Py_Initialize` is called for 174 the first time, if it is called at all. It tells the interpreter the value 175 of the ``argv[0]`` argument to the :cfunc:`main` function of the program. 176 This is used by :cfunc:`Py_GetPath` and some other functions below to find 177 the Python run-time libraries relative to the interpreter executable. The 178 default value is ``'python'``. The argument should point to a 179 zero-terminated character string in static storage whose contents will not 180 change for the duration of the program's execution. No code in the Python 181 interpreter will change the contents of this storage. 182 183 184 .. cfunction:: char* Py_GetProgramName() 185 186 .. index:: single: Py_SetProgramName() 187 188 Return the program name set with :cfunc:`Py_SetProgramName`, or the default. 189 The returned string points into static storage; the caller should not modify its 190 value. 191 192 193 .. cfunction:: char* Py_GetPrefix() 194 195 Return the *prefix* for installed platform-independent files. This is derived 196 through a number of complicated rules from the program name set with 197 :cfunc:`Py_SetProgramName` and some environment variables; for example, if the 198 program name is ``'/usr/local/bin/python'``, the prefix is ``'/usr/local'``. The 199 returned string points into static storage; the caller should not modify its 200 value. This corresponds to the :makevar:`prefix` variable in the top-level 201 :file:`Makefile` and the :option:`--prefix` argument to the :program:`configure` 202 script at build time. The value is available to Python code as ``sys.prefix``. 203 It is only useful on Unix. See also the next function. 204 205 206 .. cfunction:: char* Py_GetExecPrefix() 207 208 Return the *exec-prefix* for installed platform-*dependent* files. This is 209 derived through a number of complicated rules from the program name set with 210 :cfunc:`Py_SetProgramName` and some environment variables; for example, if the 211 program name is ``'/usr/local/bin/python'``, the exec-prefix is 212 ``'/usr/local'``. The returned string points into static storage; the caller 213 should not modify its value. This corresponds to the :makevar:`exec_prefix` 214 variable in the top-level :file:`Makefile` and the :option:`--exec-prefix` 215 argument to the :program:`configure` script at build time. The value is 216 available to Python code as ``sys.exec_prefix``. It is only useful on Unix. 217 218 Background: The exec-prefix differs from the prefix when platform dependent 219 files (such as executables and shared libraries) are installed in a different 220 directory tree. In a typical installation, platform dependent files may be 221 installed in the :file:`/usr/local/plat` subtree while platform independent may 222 be installed in :file:`/usr/local`. 223 224 Generally speaking, a platform is a combination of hardware and software 225 families, e.g. Sparc machines running the Solaris 2.x operating system are 226 considered the same platform, but Intel machines running Solaris 2.x are another 227 platform, and Intel machines running Linux are yet another platform. Different 228 major revisions of the same operating system generally also form different 229 platforms. Non-Unix operating systems are a different story; the installation 230 strategies on those systems are so different that the prefix and exec-prefix are 231 meaningless, and set to the empty string. Note that compiled Python bytecode 232 files are platform independent (but not independent from the Python version by 233 which they were compiled!). 234 235 System administrators will know how to configure the :program:`mount` or 236 :program:`automount` programs to share :file:`/usr/local` between platforms 237 while having :file:`/usr/local/plat` be a different filesystem for each 238 platform. 239 240 241 .. cfunction:: char* Py_GetProgramFullPath() 242 243 .. index:: 244 single: Py_SetProgramName() 245 single: executable (in module sys) 246 247 Return the full program name of the Python executable; this is computed as a 248 side-effect of deriving the default module search path from the program name 249 (set by :cfunc:`Py_SetProgramName` above). The returned string points into 250 static storage; the caller should not modify its value. The value is available 251 to Python code as ``sys.executable``. 252 253 254 .. cfunction:: char* Py_GetPath() 255 256 .. index:: 257 triple: module; search; path 258 single: path (in module sys) 259 260 Return the default module search path; this is computed from the program name 261 (set by :cfunc:`Py_SetProgramName` above) and some environment variables. The 262 returned string consists of a series of directory names separated by a platform 263 dependent delimiter character. The delimiter character is ``':'`` on Unix and 264 Mac OS X, ``';'`` on Windows. The returned string points into static storage; 265 the caller should not modify its value. The value is available to Python code 266 as the list ``sys.path``, which may be modified to change the future search path 267 for loaded modules. 268 269 .. XXX should give the exact rules 270 271 272 .. cfunction:: const char* Py_GetVersion() 273 274 Return the version of this Python interpreter. This is a string that looks 275 something like :: 276 277 "1.5 (#67, Dec 31 1997, 22:34:28) [GCC 2.7.2.2]" 278 279 .. index:: single: version (in module sys) 280 281 The first word (up to the first space character) is the current Python version; 282 the first three characters are the major and minor version separated by a 283 period. The returned string points into static storage; the caller should not 284 modify its value. The value is available to Python code as ``sys.version``. 285 286 287 .. cfunction:: const char* Py_GetBuildNumber() 288 289 Return a string representing the Subversion revision that this Python executable 290 was built from. This number is a string because it may contain a trailing 'M' 291 if Python was built from a mixed revision source tree. 292 293 .. versionadded:: 2.5 294 295 296 .. cfunction:: const char* Py_GetPlatform() 297 298 .. index:: single: platform (in module sys) 299 300 Return the platform identifier for the current platform. On Unix, this is 301 formed from the "official" name of the operating system, converted to lower 302 case, followed by the major revision number; e.g., for Solaris 2.x, which is 303 also known as SunOS 5.x, the value is ``'sunos5'``. On Mac OS X, it is 304 ``'darwin'``. On Windows, it is ``'win'``. The returned string points into 305 static storage; the caller should not modify its value. The value is available 306 to Python code as ``sys.platform``. 307 308 309 .. cfunction:: const char* Py_GetCopyright() 310 311 Return the official copyright string for the current Python version, for example 312 313 ``'Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam'`` 314 315 .. index:: single: copyright (in module sys) 316 317 The returned string points into static storage; the caller should not modify its 318 value. The value is available to Python code as ``sys.copyright``. 319 320 321 .. cfunction:: const char* Py_GetCompiler() 322 323 Return an indication of the compiler used to build the current Python version, 324 in square brackets, for example:: 325 326 "[GCC 2.7.2.2]" 327 328 .. index:: single: version (in module sys) 329 330 The returned string points into static storage; the caller should not modify its 331 value. The value is available to Python code as part of the variable 332 ``sys.version``. 333 334 335 .. cfunction:: const char* Py_GetBuildInfo() 336 337 Return information about the sequence number and build date and time of the 338 current Python interpreter instance, for example :: 339 340 "#67, Aug 1 1997, 22:34:28" 341 342 .. index:: single: version (in module sys) 343 344 The returned string points into static storage; the caller should not modify its 345 value. The value is available to Python code as part of the variable 346 ``sys.version``. 347 348 349 .. cfunction:: void PySys_SetArgv(int argc, char **argv) 350 351 .. index:: 352 single: main() 353 single: Py_FatalError() 354 single: argv (in module sys) 355 356 Set :data:`sys.argv` based on *argc* and *argv*. These parameters are 357 similar to those passed to the program's :cfunc:`main` function with the 358 difference that the first entry should refer to the script file to be 359 executed rather than the executable hosting the Python interpreter. If there 360 isn't a script that will be run, the first entry in *argv* can be an empty 361 string. If this function fails to initialize :data:`sys.argv`, a fatal 362 condition is signalled using :cfunc:`Py_FatalError`. 363 364 This function also prepends the executed script's path to :data:`sys.path`. 365 If no script is executed (in the case of calling ``python -c`` or just the 366 interactive interpreter), the empty string is used instead. 367 368 .. XXX impl. doesn't seem consistent in allowing 0/NULL for the params; 369 check w/ Guido. 370 371 372 .. cfunction:: void Py_SetPythonHome(char *home) 373 374 Set the default "home" directory, that is, the location of the standard 375 Python libraries. The libraries are searched in 376 :file:`{home}/lib/python{version}` and :file:`{home}/lib/python{version}`. 377 The argument should point to a zero-terminated character string in static 378 storage whose contents will not change for the duration of the program's 379 execution. No code in the Python interpreter will change the contents of 380 this storage. 381 382 383 .. cfunction:: char* Py_GetPythonHome() 384 385 Return the default "home", that is, the value set by a previous call to 386 :cfunc:`Py_SetPythonHome`, or the value of the :envvar:`PYTHONHOME` 387 environment variable if it is set. 388 389 390 .. _threads: 391 392 Thread State and the Global Interpreter Lock 393 ============================================ 394 395 .. index:: 396 single: global interpreter lock 397 single: interpreter lock 398 single: lock, interpreter 399 400 The Python interpreter is not fully thread safe. In order to support 401 multi-threaded Python programs, there's a global lock, called the :dfn:`global 402 interpreter lock` or :dfn:`GIL`, that must be held by the current thread before 403 it can safely access Python objects. Without the lock, even the simplest 404 operations could cause problems in a multi-threaded program: for example, when 405 two threads simultaneously increment the reference count of the same object, the 406 reference count could end up being incremented only once instead of twice. 407 408 .. index:: single: setcheckinterval() (in module sys) 409 410 Therefore, the rule exists that only the thread that has acquired the global 411 interpreter lock may operate on Python objects or call Python/C API functions. 412 In order to support multi-threaded Python programs, the interpreter regularly 413 releases and reacquires the lock --- by default, every 100 bytecode instructions 414 (this can be changed with :func:`sys.setcheckinterval`). The lock is also 415 released and reacquired around potentially blocking I/O operations like reading 416 or writing a file, so that other threads can run while the thread that requests 417 the I/O is waiting for the I/O operation to complete. 418 419 .. index:: 420 single: PyThreadState 421 single: PyThreadState 422 423 The Python interpreter needs to keep some bookkeeping information separate per 424 thread --- for this it uses a data structure called :ctype:`PyThreadState`. 425 There's one global variable, however: the pointer to the current 426 :ctype:`PyThreadState` structure. Before the addition of :dfn:`thread-local 427 storage` (:dfn:`TLS`) the current thread state had to be manipulated 428 explicitly. 429 430 This is easy enough in most cases. Most code manipulating the global 431 interpreter lock has the following simple structure:: 432 433 Save the thread state in a local variable. 434 Release the global interpreter lock. 435 ...Do some blocking I/O operation... 436 Reacquire the global interpreter lock. 437 Restore the thread state from the local variable. 438 439 This is so common that a pair of macros exists to simplify it:: 440 441 Py_BEGIN_ALLOW_THREADS 442 ...Do some blocking I/O operation... 443 Py_END_ALLOW_THREADS 444 445 .. index:: 446 single: Py_BEGIN_ALLOW_THREADS 447 single: Py_END_ALLOW_THREADS 448 449 The :cmacro:`Py_BEGIN_ALLOW_THREADS` macro opens a new block and declares a 450 hidden local variable; the :cmacro:`Py_END_ALLOW_THREADS` macro closes the 451 block. Another advantage of using these two macros is that when Python is 452 compiled without thread support, they are defined empty, thus saving the thread 453 state and GIL manipulations. 454 455 When thread support is enabled, the block above expands to the following code:: 456 457 PyThreadState *_save; 458 459 _save = PyEval_SaveThread(); 460 ...Do some blocking I/O operation... 461 PyEval_RestoreThread(_save); 462 463 Using even lower level primitives, we can get roughly the same effect as 464 follows:: 465 466 PyThreadState *_save; 467 468 _save = PyThreadState_Swap(NULL); 469 PyEval_ReleaseLock(); 470 ...Do some blocking I/O operation... 471 PyEval_AcquireLock(); 472 PyThreadState_Swap(_save); 473 474 .. index:: 475 single: PyEval_RestoreThread() 476 single: errno 477 single: PyEval_SaveThread() 478 single: PyEval_ReleaseLock() 479 single: PyEval_AcquireLock() 480 481 There are some subtle differences; in particular, :cfunc:`PyEval_RestoreThread` 482 saves and restores the value of the global variable :cdata:`errno`, since the 483 lock manipulation does not guarantee that :cdata:`errno` is left alone. Also, 484 when thread support is disabled, :cfunc:`PyEval_SaveThread` and 485 :cfunc:`PyEval_RestoreThread` don't manipulate the GIL; in this case, 486 :cfunc:`PyEval_ReleaseLock` and :cfunc:`PyEval_AcquireLock` are not available. 487 This is done so that dynamically loaded extensions compiled with thread support 488 enabled can be loaded by an interpreter that was compiled with disabled thread 489 support. 490 491 The global interpreter lock is used to protect the pointer to the current thread 492 state. When releasing the lock and saving the thread state, the current thread 493 state pointer must be retrieved before the lock is released (since another 494 thread could immediately acquire the lock and store its own thread state in the 495 global variable). Conversely, when acquiring the lock and restoring the thread 496 state, the lock must be acquired before storing the thread state pointer. 497 498 It is important to note that when threads are created from C, they don't have 499 the global interpreter lock, nor is there a thread state data structure for 500 them. Such threads must bootstrap themselves into existence, by first 501 creating a thread state data structure, then acquiring the lock, and finally 502 storing their thread state pointer, before they can start using the Python/C 503 API. When they are done, they should reset the thread state pointer, release 504 the lock, and finally free their thread state data structure. 505 506 Beginning with version 2.3, threads can now take advantage of the 507 :cfunc:`PyGILState_\*` functions to do all of the above automatically. The 508 typical idiom for calling into Python from a C thread is now:: 509 510 PyGILState_STATE gstate; 511 gstate = PyGILState_Ensure(); 512 513 /* Perform Python actions here. */ 514 result = CallSomeFunction(); 515 /* evaluate result */ 516 517 /* Release the thread. No Python API allowed beyond this point. */ 518 PyGILState_Release(gstate); 519 520 Note that the :cfunc:`PyGILState_\*` functions assume there is only one global 521 interpreter (created automatically by :cfunc:`Py_Initialize`). Python still 522 supports the creation of additional interpreters (using 523 :cfunc:`Py_NewInterpreter`), but mixing multiple interpreters and the 524 :cfunc:`PyGILState_\*` API is unsupported. 525 526 Another important thing to note about threads is their behaviour in the face 527 of the C :cfunc:`fork` call. On most systems with :cfunc:`fork`, after a 528 process forks only the thread that issued the fork will exist. That also 529 means any locks held by other threads will never be released. Python solves 530 this for :func:`os.fork` by acquiring the locks it uses internally before 531 the fork, and releasing them afterwards. In addition, it resets any 532 :ref:`lock-objects` in the child. When extending or embedding Python, there 533 is no way to inform Python of additional (non-Python) locks that need to be 534 acquired before or reset after a fork. OS facilities such as 535 :cfunc:`posix_atfork` would need to be used to accomplish the same thing. 536 Additionally, when extending or embedding Python, calling :cfunc:`fork` 537 directly rather than through :func:`os.fork` (and returning to or calling 538 into Python) may result in a deadlock by one of Python's internal locks 539 being held by a thread that is defunct after the fork. 540 :cfunc:`PyOS_AfterFork` tries to reset the necessary locks, but is not 541 always able to. 542 543 .. ctype:: PyInterpreterState 544 545 This data structure represents the state shared by a number of cooperating 546 threads. Threads belonging to the same interpreter share their module 547 administration and a few other internal items. There are no public members in 548 this structure. 549 550 Threads belonging to different interpreters initially share nothing, except 551 process state like available memory, open file descriptors and such. The global 552 interpreter lock is also shared by all threads, regardless of to which 553 interpreter they belong. 554 555 556 .. ctype:: PyThreadState 557 558 This data structure represents the state of a single thread. The only public 559 data member is :ctype:`PyInterpreterState \*`:attr:`interp`, which points to 560 this thread's interpreter state. 561 562 563 .. cfunction:: void PyEval_InitThreads() 564 565 .. index:: 566 single: PyEval_ReleaseLock() 567 single: PyEval_ReleaseThread() 568 single: PyEval_SaveThread() 569 single: PyEval_RestoreThread() 570 571 Initialize and acquire the global interpreter lock. It should be called in the 572 main thread before creating a second thread or engaging in any other thread 573 operations such as :cfunc:`PyEval_ReleaseLock` or 574 ``PyEval_ReleaseThread(tstate)``. It is not needed before calling 575 :cfunc:`PyEval_SaveThread` or :cfunc:`PyEval_RestoreThread`. 576 577 .. index:: single: Py_Initialize() 578 579 This is a no-op when called for a second time. It is safe to call this function 580 before calling :cfunc:`Py_Initialize`. 581 582 .. index:: module: thread 583 584 When only the main thread exists, no GIL operations are needed. This is a 585 common situation (most Python programs do not use threads), and the lock 586 operations slow the interpreter down a bit. Therefore, the lock is not 587 created initially. This situation is equivalent to having acquired the lock: 588 when there is only a single thread, all object accesses are safe. Therefore, 589 when this function initializes the global interpreter lock, it also acquires 590 it. Before the Python :mod:`thread` module creates a new thread, knowing 591 that either it has the lock or the lock hasn't been created yet, it calls 592 :cfunc:`PyEval_InitThreads`. When this call returns, it is guaranteed that 593 the lock has been created and that the calling thread has acquired it. 594 595 It is **not** safe to call this function when it is unknown which thread (if 596 any) currently has the global interpreter lock. 597 598 This function is not available when thread support is disabled at compile time. 599 600 601 .. cfunction:: int PyEval_ThreadsInitialized() 602 603 Returns a non-zero value if :cfunc:`PyEval_InitThreads` has been called. This 604 function can be called without holding the GIL, and therefore can be used to 605 avoid calls to the locking API when running single-threaded. This function is 606 not available when thread support is disabled at compile time. 607 608 .. versionadded:: 2.4 609 610 611 .. cfunction:: void PyEval_AcquireLock() 612 613 Acquire the global interpreter lock. The lock must have been created earlier. 614 If this thread already has the lock, a deadlock ensues. This function is not 615 available when thread support is disabled at compile time. 616 617 618 .. cfunction:: void PyEval_ReleaseLock() 619 620 Release the global interpreter lock. The lock must have been created earlier. 621 This function is not available when thread support is disabled at compile time. 622 623 624 .. cfunction:: void PyEval_AcquireThread(PyThreadState *tstate) 625 626 Acquire the global interpreter lock and set the current thread state to 627 *tstate*, which should not be *NULL*. The lock must have been created earlier. 628 If this thread already has the lock, deadlock ensues. This function is not 629 available when thread support is disabled at compile time. 630 631 632 .. cfunction:: void PyEval_ReleaseThread(PyThreadState *tstate) 633 634 Reset the current thread state to *NULL* and release the global interpreter 635 lock. The lock must have been created earlier and must be held by the current 636 thread. The *tstate* argument, which must not be *NULL*, is only used to check 637 that it represents the current thread state --- if it isn't, a fatal error is 638 reported. This function is not available when thread support is disabled at 639 compile time. 640 641 642 .. cfunction:: PyThreadState* PyEval_SaveThread() 643 644 Release the global interpreter lock (if it has been created and thread 645 support is enabled) and reset the thread state to *NULL*, returning the 646 previous thread state (which is not *NULL*). If the lock has been created, 647 the current thread must have acquired it. (This function is available even 648 when thread support is disabled at compile time.) 649 650 651 .. cfunction:: void PyEval_RestoreThread(PyThreadState *tstate) 652 653 Acquire the global interpreter lock (if it has been created and thread 654 support is enabled) and set the thread state to *tstate*, which must not be 655 *NULL*. If the lock has been created, the current thread must not have 656 acquired it, otherwise deadlock ensues. (This function is available even 657 when thread support is disabled at compile time.) 658 659 660 .. cfunction:: void PyEval_ReInitThreads() 661 662 This function is called from :cfunc:`PyOS_AfterFork` to ensure that newly 663 created child processes don't hold locks referring to threads which 664 are not running in the child process. 665 666 667 The following macros are normally used without a trailing semicolon; look for 668 example usage in the Python source distribution. 669 670 671 .. cmacro:: Py_BEGIN_ALLOW_THREADS 672 673 This macro expands to ``{ PyThreadState *_save; _save = PyEval_SaveThread();``. 674 Note that it contains an opening brace; it must be matched with a following 675 :cmacro:`Py_END_ALLOW_THREADS` macro. See above for further discussion of this 676 macro. It is a no-op when thread support is disabled at compile time. 677 678 679 .. cmacro:: Py_END_ALLOW_THREADS 680 681 This macro expands to ``PyEval_RestoreThread(_save); }``. Note that it contains 682 a closing brace; it must be matched with an earlier 683 :cmacro:`Py_BEGIN_ALLOW_THREADS` macro. See above for further discussion of 684 this macro. It is a no-op when thread support is disabled at compile time. 685 686 687 .. cmacro:: Py_BLOCK_THREADS 688 689 This macro expands to ``PyEval_RestoreThread(_save);``: it is equivalent to 690 :cmacro:`Py_END_ALLOW_THREADS` without the closing brace. It is a no-op when 691 thread support is disabled at compile time. 692 693 694 .. cmacro:: Py_UNBLOCK_THREADS 695 696 This macro expands to ``_save = PyEval_SaveThread();``: it is equivalent to 697 :cmacro:`Py_BEGIN_ALLOW_THREADS` without the opening brace and variable 698 declaration. It is a no-op when thread support is disabled at compile time. 699 700 All of the following functions are only available when thread support is enabled 701 at compile time, and must be called only when the global interpreter lock has 702 been created. 703 704 705 .. cfunction:: PyInterpreterState* PyInterpreterState_New() 706 707 Create a new interpreter state object. The global interpreter lock need not 708 be held, but may be held if it is necessary to serialize calls to this 709 function. 710 711 712 .. cfunction:: void PyInterpreterState_Clear(PyInterpreterState *interp) 713 714 Reset all information in an interpreter state object. The global interpreter 715 lock must be held. 716 717 718 .. cfunction:: void PyInterpreterState_Delete(PyInterpreterState *interp) 719 720 Destroy an interpreter state object. The global interpreter lock need not be 721 held. The interpreter state must have been reset with a previous call to 722 :cfunc:`PyInterpreterState_Clear`. 723 724 725 .. cfunction:: PyThreadState* PyThreadState_New(PyInterpreterState *interp) 726 727 Create a new thread state object belonging to the given interpreter object. 728 The global interpreter lock need not be held, but may be held if it is 729 necessary to serialize calls to this function. 730 731 732 .. cfunction:: void PyThreadState_Clear(PyThreadState *tstate) 733 734 Reset all information in a thread state object. The global interpreter lock 735 must be held. 736 737 738 .. cfunction:: void PyThreadState_Delete(PyThreadState *tstate) 739 740 Destroy a thread state object. The global interpreter lock need not be held. 741 The thread state must have been reset with a previous call to 742 :cfunc:`PyThreadState_Clear`. 743 744 745 .. cfunction:: PyThreadState* PyThreadState_Get() 746 747 Return the current thread state. The global interpreter lock must be held. 748 When the current thread state is *NULL*, this issues a fatal error (so that 749 the caller needn't check for *NULL*). 750 751 752 .. cfunction:: PyThreadState* PyThreadState_Swap(PyThreadState *tstate) 753 754 Swap the current thread state with the thread state given by the argument 755 *tstate*, which may be *NULL*. The global interpreter lock must be held. 756 757 758 .. cfunction:: PyObject* PyThreadState_GetDict() 759 760 Return a dictionary in which extensions can store thread-specific state 761 information. Each extension should use a unique key to use to store state in 762 the dictionary. It is okay to call this function when no current thread state 763 is available. If this function returns *NULL*, no exception has been raised and 764 the caller should assume no current thread state is available. 765 766 .. versionchanged:: 2.3 767 Previously this could only be called when a current thread is active, and *NULL* 768 meant that an exception was raised. 769 770 771 .. cfunction:: int PyThreadState_SetAsyncExc(long id, PyObject *exc) 772 773 Asynchronously raise an exception in a thread. The *id* argument is the thread 774 id of the target thread; *exc* is the exception object to be raised. This 775 function does not steal any references to *exc*. To prevent naive misuse, you 776 must write your own C extension to call this. Must be called with the GIL held. 777 Returns the number of thread states modified; this is normally one, but will be 778 zero if the thread id isn't found. If *exc* is :const:`NULL`, the pending 779 exception (if any) for the thread is cleared. This raises no exceptions. 780 781 .. versionadded:: 2.3 782 783 784 .. cfunction:: PyGILState_STATE PyGILState_Ensure() 785 786 Ensure that the current thread is ready to call the Python C API regardless 787 of the current state of Python, or of the global interpreter lock. This may 788 be called as many times as desired by a thread as long as each call is 789 matched with a call to :cfunc:`PyGILState_Release`. In general, other 790 thread-related APIs may be used between :cfunc:`PyGILState_Ensure` and 791 :cfunc:`PyGILState_Release` calls as long as the thread state is restored to 792 its previous state before the Release(). For example, normal usage of the 793 :cmacro:`Py_BEGIN_ALLOW_THREADS` and :cmacro:`Py_END_ALLOW_THREADS` macros is 794 acceptable. 795 796 The return value is an opaque "handle" to the thread state when 797 :cfunc:`PyGILState_Ensure` was called, and must be passed to 798 :cfunc:`PyGILState_Release` to ensure Python is left in the same state. Even 799 though recursive calls are allowed, these handles *cannot* be shared - each 800 unique call to :cfunc:`PyGILState_Ensure` must save the handle for its call 801 to :cfunc:`PyGILState_Release`. 802 803 When the function returns, the current thread will hold the GIL. Failure is a 804 fatal error. 805 806 .. versionadded:: 2.3 807 808 809 .. cfunction:: void PyGILState_Release(PyGILState_STATE) 810 811 Release any resources previously acquired. After this call, Python's state will 812 be the same as it was prior to the corresponding :cfunc:`PyGILState_Ensure` call 813 (but generally this state will be unknown to the caller, hence the use of the 814 GILState API.) 815 816 Every call to :cfunc:`PyGILState_Ensure` must be matched by a call to 817 :cfunc:`PyGILState_Release` on the same thread. 818 819 .. versionadded:: 2.3 879 Bugs and caveats 880 ---------------- 881 882 Because sub-interpreters (and the main interpreter) are part of the same 883 process, the insulation between them isn't perfect --- for example, using 884 low-level file operations like :func:`os.close` they can 885 (accidentally or maliciously) affect each other's open files. Because of the 886 way extensions are shared between (sub-)interpreters, some extensions may not 887 work properly; this is especially likely when the extension makes use of 888 (static) global variables, or when the extension manipulates its module's 889 dictionary after its initialization. It is possible to insert objects created 890 in one sub-interpreter into a namespace of another sub-interpreter; this should 891 be done with great care to avoid sharing user-defined functions, methods, 892 instances or classes between sub-interpreters, since import operations executed 893 by such objects may affect the wrong (sub-)interpreter's dictionary of loaded 894 modules. 895 896 Also note that combining this functionality with :c:func:`PyGILState_\*` APIs 897 is delicate, because these APIs assume a bijection between Python thread states 898 and OS-level threads, an assumption broken by the presence of sub-interpreters. 899 It is highly recommended that you don't switch sub-interpreters between a pair 900 of matching :c:func:`PyGILState_Ensure` and :c:func:`PyGILState_Release` calls. 901 Furthermore, extensions (such as :mod:`ctypes`) using these APIs to allow calling 902 of Python code from non-Python created threads will probably be broken when using 903 sub-interpreters. 904 905 906 Asynchronous Notifications 907 ========================== 908 909 A mechanism is provided to make asynchronous notifications to the main 910 interpreter thread. These notifications take the form of a function 911 pointer and a void pointer argument. 912 913 914 .. c:function:: int Py_AddPendingCall(int (*func)(void *), void *arg) 915 916 .. index:: single: Py_AddPendingCall() 917 918 Schedule a function to be called from the main interpreter thread. On 919 success, 0 is returned and *func* is queued for being called in the 920 main thread. On failure, -1 is returned without setting any exception. 921 922 When successfully queued, *func* will be *eventually* called from the 923 main interpreter thread with the argument *arg*. It will be called 924 asynchronously with respect to normally running Python code, but with 925 both these conditions met: 926 927 * on a :term:`bytecode` boundary; 928 * with the main thread holding the :term:`global interpreter lock` 929 (*func* can therefore use the full C API). 930 931 *func* must return 0 on success, or -1 on failure with an exception 932 set. *func* won't be interrupted to perform another asynchronous 933 notification recursively, but it can still be interrupted to switch 934 threads if the global interpreter lock is released. 935 936 This function doesn't need a current thread state to run, and it doesn't 937 need the global interpreter lock. 938 939 .. warning:: 940 This is a low-level function, only useful for very special cases. 941 There is no guarantee that *func* will be called as quick as 942 possible. If the main thread is busy executing a system call, 943 *func* won't be called before the system call returns. This 944 function is generally **not** suitable for calling Python code from 945 arbitrary C threads. Instead, use the :ref:`PyGILState API<gilstate>`. 946 947 .. versionadded:: 2.7 820 948 821 949 … … 842 970 843 971 844 .. c type:: int (*Py_tracefunc)(PyObject *obj, PyFrameObject *frame, int what, PyObject *arg)845 846 The type of the trace function registered using :c func:`PyEval_SetProfile` and847 :c func:`PyEval_SetTrace`. The first parameter is the object passed to the972 .. c:type:: int (*Py_tracefunc)(PyObject *obj, PyFrameObject *frame, int what, PyObject *arg) 973 974 The type of the trace function registered using :c:func:`PyEval_SetProfile` and 975 :c:func:`PyEval_SetTrace`. The first parameter is the object passed to the 848 976 registration function as *obj*, *frame* is the frame object to which the event 849 977 pertains, *what* is one of the constants :const:`PyTrace_CALL`, … … 862 990 | :const:`PyTrace_LINE` | Always *NULL*. | 863 991 +------------------------------+--------------------------------------+ 864 | :const:`PyTrace_RETURN` | Value being returned to the caller. | 992 | :const:`PyTrace_RETURN` | Value being returned to the caller, | 993 | | or *NULL* if caused by an exception. | 865 994 +------------------------------+--------------------------------------+ 866 | :const:`PyTrace_C_CALL` | Name of function being called.|995 | :const:`PyTrace_C_CALL` | Function object being called. | 867 996 +------------------------------+--------------------------------------+ 868 | :const:`PyTrace_C_EXCEPTION` | Always *NULL*.|997 | :const:`PyTrace_C_EXCEPTION` | Function object being called. | 869 998 +------------------------------+--------------------------------------+ 870 | :const:`PyTrace_C_RETURN` | Always *NULL*.|999 | :const:`PyTrace_C_RETURN` | Function object being called. | 871 1000 +------------------------------+--------------------------------------+ 872 1001 873 1002 874 .. c var:: int PyTrace_CALL875 876 The value of the *what* parameter to a :c type:`Py_tracefunc` function when a new1003 .. c:var:: int PyTrace_CALL 1004 1005 The value of the *what* parameter to a :c:type:`Py_tracefunc` function when a new 877 1006 call to a function or method is being reported, or a new entry into a generator. 878 1007 Note that the creation of the iterator for a generator function is not reported … … 881 1010 882 1011 883 .. c var:: int PyTrace_EXCEPTION884 885 The value of the *what* parameter to a :c type:`Py_tracefunc` function when an1012 .. c:var:: int PyTrace_EXCEPTION 1013 1014 The value of the *what* parameter to a :c:type:`Py_tracefunc` function when an 886 1015 exception has been raised. The callback function is called with this value for 887 1016 *what* when after any bytecode is processed after which the exception becomes … … 892 1021 893 1022 894 .. c var:: int PyTrace_LINE1023 .. c:var:: int PyTrace_LINE 895 1024 896 1025 The value passed as the *what* parameter to a trace function (but not a … … 898 1027 899 1028 900 .. c var:: int PyTrace_RETURN901 902 The value for the *what* parameter to :c type:`Py_tracefunc` functions when a1029 .. c:var:: int PyTrace_RETURN 1030 1031 The value for the *what* parameter to :c:type:`Py_tracefunc` functions when a 903 1032 call is returning without propagating an exception. 904 1033 905 1034 906 .. c var:: int PyTrace_C_CALL907 908 The value for the *what* parameter to :c type:`Py_tracefunc` functions when a C1035 .. c:var:: int PyTrace_C_CALL 1036 1037 The value for the *what* parameter to :c:type:`Py_tracefunc` functions when a C 909 1038 function is about to be called. 910 1039 911 1040 912 .. c var:: int PyTrace_C_EXCEPTION913 914 The value for the *what* parameter to :c type:`Py_tracefunc` functions when a C915 function has thrownan exception.916 917 918 .. c var:: int PyTrace_C_RETURN919 920 The value for the *what* parameter to :c type:`Py_tracefunc` functions when a C1041 .. c:var:: int PyTrace_C_EXCEPTION 1042 1043 The value for the *what* parameter to :c:type:`Py_tracefunc` functions when a C 1044 function has raised an exception. 1045 1046 1047 .. c:var:: int PyTrace_C_RETURN 1048 1049 The value for the *what* parameter to :c:type:`Py_tracefunc` functions when a C 921 1050 function has returned. 922 1051 923 1052 924 .. c function:: void PyEval_SetProfile(Py_tracefunc func, PyObject *obj)1053 .. c:function:: void PyEval_SetProfile(Py_tracefunc func, PyObject *obj) 925 1054 926 1055 Set the profiler function to *func*. The *obj* parameter is passed to the … … 932 1061 933 1062 934 .. c function:: void PyEval_SetTrace(Py_tracefunc func, PyObject *obj)1063 .. c:function:: void PyEval_SetTrace(Py_tracefunc func, PyObject *obj) 935 1064 936 1065 Set the tracing function to *func*. This is similar to 937 :c func:`PyEval_SetProfile`, except the tracing function does receive line-number1066 :c:func:`PyEval_SetProfile`, except the tracing function does receive line-number 938 1067 events. 939 1068 940 .. c function:: PyObject* PyEval_GetCallStats(PyObject *self)1069 .. c:function:: PyObject* PyEval_GetCallStats(PyObject *self) 941 1070 942 1071 Return a tuple of function call counts. There are constants defined for the … … 990 1119 991 1120 992 .. c function:: PyInterpreterState* PyInterpreterState_Head()1121 .. c:function:: PyInterpreterState* PyInterpreterState_Head() 993 1122 994 1123 Return the interpreter state object at the head of the list of all such objects. … … 997 1126 998 1127 999 .. c function:: PyInterpreterState* PyInterpreterState_Next(PyInterpreterState *interp)1128 .. c:function:: PyInterpreterState* PyInterpreterState_Next(PyInterpreterState *interp) 1000 1129 1001 1130 Return the next interpreter state object after *interp* from the list of all … … 1005 1134 1006 1135 1007 .. c function:: PyThreadState * PyInterpreterState_ThreadHead(PyInterpreterState *interp)1008 1009 Return the a pointer to the first :c type:`PyThreadState` object in the list of1136 .. c:function:: PyThreadState * PyInterpreterState_ThreadHead(PyInterpreterState *interp) 1137 1138 Return the a pointer to the first :c:type:`PyThreadState` object in the list of 1010 1139 threads associated with the interpreter *interp*. 1011 1140 … … 1013 1142 1014 1143 1015 .. c function:: PyThreadState* PyThreadState_Next(PyThreadState *tstate)1144 .. c:function:: PyThreadState* PyThreadState_Next(PyThreadState *tstate) 1016 1145 1017 1146 Return the next thread state object after *tstate* from the list of all such 1018 objects belonging to the same :c type:`PyInterpreterState` object.1147 objects belonging to the same :c:type:`PyInterpreterState` object. 1019 1148 1020 1149 .. versionadded:: 2.2 -
python/vendor/current/Doc/c-api/int.rst
r2 r388 9 9 10 10 11 .. c type:: PyIntObject11 .. c:type:: PyIntObject 12 12 13 This subtype of :c type:`PyObject` represents a Python integer object.13 This subtype of :c:type:`PyObject` represents a Python integer object. 14 14 15 15 16 .. c var:: PyTypeObject PyInt_Type16 .. c:var:: PyTypeObject PyInt_Type 17 17 18 18 .. index:: single: IntType (in modules types) 19 19 20 This instance of :c type:`PyTypeObject` represents the Python plain integer type.20 This instance of :c:type:`PyTypeObject` represents the Python plain integer type. 21 21 This is the same object as ``int`` and ``types.IntType``. 22 22 23 23 24 .. c function:: int PyInt_Check(PyObject *o)24 .. c:function:: int PyInt_Check(PyObject *o) 25 25 26 Return true if *o* is of type :c data:`PyInt_Type` or a subtype of27 :c data:`PyInt_Type`.26 Return true if *o* is of type :c:data:`PyInt_Type` or a subtype of 27 :c:data:`PyInt_Type`. 28 28 29 29 .. versionchanged:: 2.2 … … 31 31 32 32 33 .. c function:: int PyInt_CheckExact(PyObject *o)33 .. c:function:: int PyInt_CheckExact(PyObject *o) 34 34 35 Return true if *o* is of type :c data:`PyInt_Type`, but not a subtype of36 :c data:`PyInt_Type`.35 Return true if *o* is of type :c:data:`PyInt_Type`, but not a subtype of 36 :c:data:`PyInt_Type`. 37 37 38 38 .. versionadded:: 2.2 39 39 40 40 41 .. c function:: PyObject* PyInt_FromString(char *str, char **pend, int base)41 .. c:function:: PyObject* PyInt_FromString(char *str, char **pend, int base) 42 42 43 Return a new :c type:`PyIntObject` or :ctype:`PyLongObject` based on the string43 Return a new :c:type:`PyIntObject` or :c:type:`PyLongObject` based on the string 44 44 value in *str*, which is interpreted according to the radix in *base*. If 45 45 *pend* is non-*NULL*, ``*pend`` will point to the first character in *str* which … … 50 50 must be between ``2`` and ``36``, inclusive. Leading spaces are ignored. If 51 51 there are no digits, :exc:`ValueError` will be raised. If the string represents 52 a number too large to be contained within the machine's :c type:`long int` type53 and overflow warnings are being suppressed, a :c type:`PyLongObject` will be52 a number too large to be contained within the machine's :c:type:`long int` type 53 and overflow warnings are being suppressed, a :c:type:`PyLongObject` will be 54 54 returned. If overflow warnings are not being suppressed, *NULL* will be 55 55 returned in this case. 56 56 57 57 58 .. c function:: PyObject* PyInt_FromLong(long ival)58 .. c:function:: PyObject* PyInt_FromLong(long ival) 59 59 60 60 Create a new integer object with a value of *ival*. … … 67 67 68 68 69 .. c function:: PyObject* PyInt_FromSsize_t(Py_ssize_t ival)69 .. c:function:: PyObject* PyInt_FromSsize_t(Py_ssize_t ival) 70 70 71 71 Create a new integer object with a value of *ival*. If the value is larger … … 76 76 77 77 78 .. c function:: PyObject* PyInt_FromSize_t(size_t ival)78 .. c:function:: PyObject* PyInt_FromSize_t(size_t ival) 79 79 80 80 Create a new integer object with a value of *ival*. If the value exceeds … … 84 84 85 85 86 .. c function:: long PyInt_AsLong(PyObject *io)86 .. c:function:: long PyInt_AsLong(PyObject *io) 87 87 88 Will first attempt to cast the object to a :c type:`PyIntObject`, if it is not88 Will first attempt to cast the object to a :c:type:`PyIntObject`, if it is not 89 89 already one, and then return its value. If there is an error, ``-1`` is 90 90 returned, and the caller should check ``PyErr_Occurred()`` to find out whether … … 92 92 93 93 94 .. c function:: long PyInt_AS_LONG(PyObject *io)94 .. c:function:: long PyInt_AS_LONG(PyObject *io) 95 95 96 96 Return the value of the object *io*. No error checking is performed. 97 97 98 98 99 .. c function:: unsigned long PyInt_AsUnsignedLongMask(PyObject *io)99 .. c:function:: unsigned long PyInt_AsUnsignedLongMask(PyObject *io) 100 100 101 Will first attempt to cast the object to a :c type:`PyIntObject` or102 :c type:`PyLongObject`, if it is not already one, and then return its value as101 Will first attempt to cast the object to a :c:type:`PyIntObject` or 102 :c:type:`PyLongObject`, if it is not already one, and then return its value as 103 103 unsigned long. This function does not check for overflow. 104 104 … … 106 106 107 107 108 .. c function:: unsigned PY_LONG_LONG PyInt_AsUnsignedLongLongMask(PyObject *io)108 .. c:function:: unsigned PY_LONG_LONG PyInt_AsUnsignedLongLongMask(PyObject *io) 109 109 110 Will first attempt to cast the object to a :c type:`PyIntObject` or111 :c type:`PyLongObject`, if it is not already one, and then return its value as110 Will first attempt to cast the object to a :c:type:`PyIntObject` or 111 :c:type:`PyLongObject`, if it is not already one, and then return its value as 112 112 unsigned long long, without checking for overflow. 113 113 … … 115 115 116 116 117 .. c function:: Py_ssize_t PyInt_AsSsize_t(PyObject *io)117 .. c:function:: Py_ssize_t PyInt_AsSsize_t(PyObject *io) 118 118 119 Will first attempt to cast the object to a :c type:`PyIntObject` or120 :c type:`PyLongObject`, if it is not already one, and then return its value as121 :c type:`Py_ssize_t`.119 Will first attempt to cast the object to a :c:type:`PyIntObject` or 120 :c:type:`PyLongObject`, if it is not already one, and then return its value as 121 :c:type:`Py_ssize_t`. 122 122 123 123 .. versionadded:: 2.5 124 124 125 125 126 .. c function:: long PyInt_GetMax()126 .. c:function:: long PyInt_GetMax() 127 127 128 128 .. index:: single: LONG_MAX … … 132 132 133 133 134 .. c function:: int PyInt_ClearFreeList()134 .. c:function:: int PyInt_ClearFreeList() 135 135 136 136 Clear the integer free list. Return the number of items that could not -
python/vendor/current/Doc/c-api/intro.rst
r2 r388 42 42 43 43 This implies inclusion of the following standard headers: ``<stdio.h>``, 44 ``<string.h>``, ``<errno.h>``, ``<limits.h>``, and ``<stdlib.h>`` (if45 available).44 ``<string.h>``, ``<errno.h>``, ``<limits.h>``, ``<assert.h>`` and ``<stdlib.h>`` 45 (if available). 46 46 47 47 .. note:: … … 89 89 90 90 Most Python/C API functions have one or more arguments as well as a return value 91 of type :c type:`PyObject\*`. This type is a pointer to an opaque data type91 of type :c:type:`PyObject\*`. This type is a pointer to an opaque data type 92 92 representing an arbitrary Python object. Since all Python object types are 93 93 treated the same way by the Python language in most situations (e.g., … … 95 95 should be represented by a single C type. Almost all Python objects live on the 96 96 heap: you never declare an automatic or static variable of type 97 :c type:`PyObject`, only pointer variables of type :ctype:`PyObject\*` can be97 :c:type:`PyObject`, only pointer variables of type :c:type:`PyObject\*` can be 98 98 declared. The sole exception are the type objects; since these must never be 99 deallocated, they are typically static :c type:`PyTypeObject` objects.99 deallocated, they are typically static :c:type:`PyTypeObject` objects. 100 100 101 101 All Python objects (even Python integers) have a :dfn:`type` and a … … 128 128 129 129 Reference counts are always manipulated explicitly. The normal way is to use 130 the macro :c func:`Py_INCREF` to increment an object's reference count by one,131 and :c func:`Py_DECREF` to decrement it by one. The :cfunc:`Py_DECREF` macro130 the macro :c:func:`Py_INCREF` to increment an object's reference count by one, 131 and :c:func:`Py_DECREF` to decrement it by one. The :c:func:`Py_DECREF` macro 132 132 is considerably more complex than the incref one, since it must check whether 133 133 the reference count becomes zero and then cause the object's deallocator to be … … 160 160 and possible deallocating it. The real danger is that innocent-looking 161 161 operations may invoke arbitrary Python code which could do this; there is a code 162 path which allows control to flow back to the user from a :c func:`Py_DECREF`, so162 path which allows control to flow back to the user from a :c:func:`Py_DECREF`, so 163 163 almost any operation is potentially dangerous. 164 164 … … 166 166 begins with ``PyObject_``, ``PyNumber_``, ``PySequence_`` or ``PyMapping_``). 167 167 These operations always increment the reference count of the object they return. 168 This leaves the caller with the responsibility to call :c func:`Py_DECREF` when168 This leaves the caller with the responsibility to call :c:func:`Py_DECREF` when 169 169 they are done with the result; this soon becomes second nature. 170 170 … … 181 181 reference is no longer needed. Ownership can also be transferred, meaning that 182 182 the code that receives ownership of the reference then becomes responsible for 183 eventually decref'ing it by calling :c func:`Py_DECREF` or :cfunc:`Py_XDECREF`183 eventually decref'ing it by calling :c:func:`Py_DECREF` or :c:func:`Py_XDECREF` 184 184 when it's no longer needed---or passing on this responsibility (usually to its 185 185 caller). When a function passes ownership of a reference on to its caller, the … … 199 199 200 200 Few functions steal references; the two notable exceptions are 201 :c func:`PyList_SetItem` and :cfunc:`PyTuple_SetItem`, which steal a reference201 :c:func:`PyList_SetItem` and :c:func:`PyTuple_SetItem`, which steal a reference 202 202 to the item (but not to the tuple or list into which the item is put!). These 203 203 functions were designed to steal a reference because of a common idiom for … … 213 213 PyTuple_SetItem(t, 2, PyString_FromString("three")); 214 214 215 Here, :c func:`PyInt_FromLong` returns a new reference which is immediately216 stolen by :c func:`PyTuple_SetItem`. When you want to keep using an object217 although the reference to it will be stolen, use :c func:`Py_INCREF` to grab215 Here, :c:func:`PyInt_FromLong` returns a new reference which is immediately 216 stolen by :c:func:`PyTuple_SetItem`. When you want to keep using an object 217 although the reference to it will be stolen, use :c:func:`Py_INCREF` to grab 218 218 another reference before calling the reference-stealing function. 219 219 220 Incidentally, :c func:`PyTuple_SetItem` is the *only* way to set tuple items;221 :c func:`PySequence_SetItem` and :cfunc:`PyObject_SetItem` refuse to do this220 Incidentally, :c:func:`PyTuple_SetItem` is the *only* way to set tuple items; 221 :c:func:`PySequence_SetItem` and :c:func:`PyObject_SetItem` refuse to do this 222 222 since tuples are an immutable data type. You should only use 223 :c func:`PyTuple_SetItem` for tuples that you are creating yourself.224 225 Equivalent code for populating a list can be written using :c func:`PyList_New`226 and :c func:`PyList_SetItem`.223 :c:func:`PyTuple_SetItem` for tuples that you are creating yourself. 224 225 Equivalent code for populating a list can be written using :c:func:`PyList_New` 226 and :c:func:`PyList_SetItem`. 227 227 228 228 However, in practice, you will rarely use these ways of creating and populating 229 a tuple or list. There's a generic function, :c func:`Py_BuildValue`, that can229 a tuple or list. There's a generic function, :c:func:`Py_BuildValue`, that can 230 230 create most common objects from C values, directed by a :dfn:`format string`. 231 231 For example, the above two blocks of code could be replaced by the following … … 237 237 list = Py_BuildValue("[iis]", 1, 2, "three"); 238 238 239 It is much more common to use :c func:`PyObject_SetItem` and friends with items239 It is much more common to use :c:func:`PyObject_SetItem` and friends with items 240 240 whose references you are only borrowing, like arguments that were passed in to 241 241 the function you are writing. In that case, their behaviour regarding reference … … 256 256 if (!index) 257 257 return -1; 258 if (PyObject_SetItem(target, index, item) < 0) 258 if (PyObject_SetItem(target, index, item) < 0) { 259 Py_DECREF(index); 259 260 return -1; 261 } 260 262 Py_DECREF(index); 261 263 } … … 271 273 returned object is created on the fly, and the reference you get is the only 272 274 reference to the object. Therefore, the generic functions that return object 273 references, like :c func:`PyObject_GetItem` and :cfunc:`PySequence_GetItem`,275 references, like :c:func:`PyObject_GetItem` and :c:func:`PySequence_GetItem`, 274 276 always return a new reference (the caller becomes the owner of the reference). 275 277 … … 277 279 function depends on which function you call only --- *the plumage* (the type of 278 280 the object passed as an argument to the function) *doesn't enter into it!* 279 Thus, if you extract an item from a list using :c func:`PyList_GetItem`, you281 Thus, if you extract an item from a list using :c:func:`PyList_GetItem`, you 280 282 don't own the reference --- but if you obtain the same item from the same list 281 using :c func:`PySequence_GetItem` (which happens to take exactly the same283 using :c:func:`PySequence_GetItem` (which happens to take exactly the same 282 284 arguments), you do own a reference to the returned object. 283 285 … … 287 289 288 290 Here is an example of how you could write a function that computes the sum of 289 the items in a list of integers; once using :c func:`PyList_GetItem`, and once290 using :c func:`PySequence_GetItem`. ::291 the items in a list of integers; once using :c:func:`PyList_GetItem`, and once 292 using :c:func:`PySequence_GetItem`. :: 291 293 292 294 long … … 341 343 342 344 There are few other data types that play a significant role in the Python/C 343 API; most are simple C types such as :c type:`int`, :ctype:`long`,344 :c type:`double` and :ctype:`char\*`. A few structure types are used to345 API; most are simple C types such as :c:type:`int`, :c:type:`long`, 346 :c:type:`double` and :c:type:`char\*`. A few structure types are used to 345 347 describe static tables used to list the functions exported by a module or the 346 348 data attributes of a new object type, and another is used to describe the value … … 362 364 .. index:: single: PyErr_Occurred() 363 365 364 For C programmers, however, error checking always has to be explicit. All 365 functions in the Python/C API can raise exceptions, unless an explicit claim is 366 made otherwise in a function's documentation. In general, when a function 367 encounters an error, it sets an exception, discards any object references that 368 it owns, and returns an error indicator --- usually *NULL* or ``-1``. A few 369 functions return a Boolean true/false result, with false indicating an error. 370 Very few functions return no explicit error indicator or have an ambiguous 371 return value, and require explicit testing for errors with 372 :cfunc:`PyErr_Occurred`. 366 For C programmers, however, error checking always has to be explicit. All 367 functions in the Python/C API can raise exceptions, unless an explicit claim is 368 made otherwise in a function's documentation. In general, when a function 369 encounters an error, it sets an exception, discards any object references that 370 it owns, and returns an error indicator. If not documented otherwise, this 371 indicator is either *NULL* or ``-1``, depending on the function's return type. 372 A few functions return a Boolean true/false result, with false indicating an 373 error. Very few functions return no explicit error indicator or have an 374 ambiguous return value, and require explicit testing for errors with 375 :c:func:`PyErr_Occurred`. These exceptions are always explicitly documented. 373 376 374 377 .. index:: … … 379 382 using global storage in an unthreaded application). A thread can be in one of 380 383 two states: an exception has occurred, or not. The function 381 :c func:`PyErr_Occurred` can be used to check for this: it returns a borrowed384 :c:func:`PyErr_Occurred` can be used to check for this: it returns a borrowed 382 385 reference to the exception type object when an exception has occurred, and 383 386 *NULL* otherwise. There are a number of functions to set the exception state: 384 :c func:`PyErr_SetString` is the most common (though not the most general)385 function to set the exception state, and :c func:`PyErr_Clear` clears the387 :c:func:`PyErr_SetString` is the most common (though not the most general) 388 function to set the exception state, and :c:func:`PyErr_Clear` clears the 386 389 exception state. 387 390 … … 424 427 425 428 A simple example of detecting exceptions and passing them on is shown in the 426 :c func:`sum_sequence` example above. It so happens that thatexample doesn't429 :c:func:`sum_sequence` example above. It so happens that this example doesn't 427 430 need to clean up any owned references when it detects an error. The following 428 431 example function shows some error cleanup. First, to remind you why you like … … 491 494 492 495 This example represents an endorsed use of the ``goto`` statement in C! 493 It illustrates the use of :c func:`PyErr_ExceptionMatches` and494 :c func:`PyErr_Clear` to handle specific exceptions, and the use of495 :c func:`Py_XDECREF` to dispose of owned references that may be *NULL* (note the496 ``'X'`` in the name; :c func:`Py_DECREF` would crash when confronted with a496 It illustrates the use of :c:func:`PyErr_ExceptionMatches` and 497 :c:func:`PyErr_Clear` to handle specific exceptions, and the use of 498 :c:func:`Py_XDECREF` to dispose of owned references that may be *NULL* (note the 499 ``'X'`` in the name; :c:func:`Py_DECREF` would crash when confronted with a 497 500 *NULL* reference). It is important that the variables used to hold owned 498 501 references are initialized to *NULL* for this to work; likewise, the proposed … … 520 523 single: path (in module sys) 521 524 522 The basic initialization function is :c func:`Py_Initialize`. This initializes525 The basic initialization function is :c:func:`Py_Initialize`. This initializes 523 526 the table of loaded modules, and creates the fundamental modules 524 527 :mod:`__builtin__`, :mod:`__main__`, :mod:`sys`, and :mod:`exceptions`. It also 525 528 initializes the module search path (``sys.path``). 526 529 527 .. index:: single: PySys_SetArgv ()528 529 :c func:`Py_Initialize` does not set the "script argument list" (``sys.argv``).530 If this variable is needed by Python code that 531 be set explicitly with a call to ``PySys_SetArgv (argc, argv)`` subsequent to532 the call to :cfunc:`Py_Initialize`.530 .. index:: single: PySys_SetArgvEx() 531 532 :c:func:`Py_Initialize` does not set the "script argument list" (``sys.argv``). 533 If this variable is needed by Python code that will be executed later, it must 534 be set explicitly with a call to ``PySys_SetArgvEx(argc, argv, updatepath)`` 535 after the call to :c:func:`Py_Initialize`. 533 536 534 537 On most systems (in particular, on Unix and Windows, although the details are 535 slightly different), :c func:`Py_Initialize` calculates the module search path538 slightly different), :c:func:`Py_Initialize` calculates the module search path 536 539 based upon its best guess for the location of the standard Python interpreter 537 540 executable, assuming that the Python library is found in a fixed location … … 557 560 558 561 The embedding application can steer the search by calling 559 ``Py_SetProgramName(file)`` *before* calling :c func:`Py_Initialize`. Note that562 ``Py_SetProgramName(file)`` *before* calling :c:func:`Py_Initialize`. Note that 560 563 :envvar:`PYTHONHOME` still overrides this and :envvar:`PYTHONPATH` is still 561 564 inserted in front of the standard path. An application that requires total 562 control has to provide its own implementation of :c func:`Py_GetPath`,563 :c func:`Py_GetPrefix`, :cfunc:`Py_GetExecPrefix`, and564 :c func:`Py_GetProgramFullPath` (all defined in :file:`Modules/getpath.c`).565 control has to provide its own implementation of :c:func:`Py_GetPath`, 566 :c:func:`Py_GetPrefix`, :c:func:`Py_GetExecPrefix`, and 567 :c:func:`Py_GetProgramFullPath` (all defined in :file:`Modules/getpath.c`). 565 568 566 569 .. index:: single: Py_IsInitialized() … … 568 571 Sometimes, it is desirable to "uninitialize" Python. For instance, the 569 572 application may want to start over (make another call to 570 :c func:`Py_Initialize`) or the application is simply done with its use of573 :c:func:`Py_Initialize`) or the application is simply done with its use of 571 574 Python and wants to free memory allocated by Python. This can be accomplished 572 by calling :c func:`Py_Finalize`. The function :cfunc:`Py_IsInitialized` returns575 by calling :c:func:`Py_Finalize`. The function :c:func:`Py_IsInitialized` returns 573 576 true if Python is currently in the initialized state. More information about 574 these functions is given in a later chapter. Notice that :c func:`Py_Finalize`577 these functions is given in a later chapter. Notice that :c:func:`Py_Finalize` 575 578 does *not* free all memory allocated by the Python interpreter, e.g. memory 576 579 allocated by extension modules currently cannot be released. … … 592 595 frequently-used builds will be described in the remainder of this section. 593 596 594 Compiling the interpreter with the :c macro:`Py_DEBUG` macro defined produces595 what is generally meant by "a debug build" of Python. :c macro:`Py_DEBUG` is596 enabled in the Unix build by adding :option:`--with-pydebug` to the597 :file:` configure` command. It is also implied by the presence of the598 not-Python-specific :c macro:`_DEBUG` macro. When :cmacro:`Py_DEBUG` is enabled597 Compiling the interpreter with the :c:macro:`Py_DEBUG` macro defined produces 598 what is generally meant by "a debug build" of Python. :c:macro:`Py_DEBUG` is 599 enabled in the Unix build by adding ``--with-pydebug`` to the 600 :file:`./configure` command. It is also implied by the presence of the 601 not-Python-specific :c:macro:`_DEBUG` macro. When :c:macro:`Py_DEBUG` is enabled 599 602 in the Unix build, compiler optimization is disabled. 600 603 … … 625 628 There may be additional checks not mentioned here. 626 629 627 Defining :c macro:`Py_TRACE_REFS` enables reference tracing. When defined, a630 Defining :c:macro:`Py_TRACE_REFS` enables reference tracing. When defined, a 628 631 circular doubly linked list of active objects is maintained by adding two extra 629 fields to every :c type:`PyObject`. Total allocations are tracked as well. Upon632 fields to every :c:type:`PyObject`. Total allocations are tracked as well. Upon 630 633 exit, all existing references are printed. (In interactive mode this happens 631 after every statement run by the interpreter.) Implied by :c macro:`Py_DEBUG`.634 after every statement run by the interpreter.) Implied by :c:macro:`Py_DEBUG`. 632 635 633 636 Please refer to :file:`Misc/SpecialBuilds.txt` in the Python source distribution -
python/vendor/current/Doc/c-api/iter.rst
r2 r388 8 8 .. versionadded:: 2.2 9 9 10 There are only a couple offunctions specifically for working with iterators.10 There are two functions specifically for working with iterators. 11 11 12 12 13 .. c function:: int PyIter_Check(PyObject *o)13 .. c:function:: int PyIter_Check(PyObject *o) 14 14 15 15 Return true if the object *o* supports the iterator protocol. 16 16 17 17 18 .. c function:: PyObject* PyIter_Next(PyObject *o)18 .. c:function:: PyObject* PyIter_Next(PyObject *o) 19 19 20 Return the next value from the iteration *o*. If the object is an iterator, 21 this retrieves the next value from the iteration, and returns *NULL* with no 22 exception set if there are no remaining items. If the object is not an 23 iterator, :exc:`TypeError` is raised, or if there is an error in retrieving the 24 item, returns *NULL* and passes along the exception. 20 Return the next value from the iteration *o*. The object must be an iterator 21 (it is up to the caller to check this). If there are no remaining values, 22 returns *NULL* with no exception set. If an error occurs while retrieving 23 the item, returns *NULL* and passes along the exception. 25 24 26 25 To write a loop which iterates over an iterator, the C code should look -
python/vendor/current/Doc/c-api/iterator.rst
r2 r388 13 13 14 14 15 .. c var:: PyTypeObject PySeqIter_Type15 .. c:var:: PyTypeObject PySeqIter_Type 16 16 17 Type object for iterator objects returned by :c func:`PySeqIter_New` and the17 Type object for iterator objects returned by :c:func:`PySeqIter_New` and the 18 18 one-argument form of the :func:`iter` built-in function for built-in sequence 19 19 types. … … 22 22 23 23 24 .. c function:: int PySeqIter_Check(op)24 .. c:function:: int PySeqIter_Check(op) 25 25 26 Return true if the type of *op* is :c data:`PySeqIter_Type`.26 Return true if the type of *op* is :c:data:`PySeqIter_Type`. 27 27 28 28 .. versionadded:: 2.2 29 29 30 30 31 .. c function:: PyObject* PySeqIter_New(PyObject *seq)31 .. c:function:: PyObject* PySeqIter_New(PyObject *seq) 32 32 33 33 Return an iterator that works with a general sequence object, *seq*. The … … 38 38 39 39 40 .. c var:: PyTypeObject PyCallIter_Type40 .. c:var:: PyTypeObject PyCallIter_Type 41 41 42 Type object for iterator objects returned by :c func:`PyCallIter_New` and the42 Type object for iterator objects returned by :c:func:`PyCallIter_New` and the 43 43 two-argument form of the :func:`iter` built-in function. 44 44 … … 46 46 47 47 48 .. c function:: int PyCallIter_Check(op)48 .. c:function:: int PyCallIter_Check(op) 49 49 50 Return true if the type of *op* is :c data:`PyCallIter_Type`.50 Return true if the type of *op* is :c:data:`PyCallIter_Type`. 51 51 52 52 .. versionadded:: 2.2 53 53 54 54 55 .. c function:: PyObject* PyCallIter_New(PyObject *callable, PyObject *sentinel)55 .. c:function:: PyObject* PyCallIter_New(PyObject *callable, PyObject *sentinel) 56 56 57 57 Return a new iterator. The first parameter, *callable*, can be any Python -
python/vendor/current/Doc/c-api/list.rst
r2 r388 9 9 10 10 11 .. c type:: PyListObject11 .. c:type:: PyListObject 12 12 13 This subtype of :c type:`PyObject` represents a Python list object.13 This subtype of :c:type:`PyObject` represents a Python list object. 14 14 15 15 16 .. c var:: PyTypeObject PyList_Type16 .. c:var:: PyTypeObject PyList_Type 17 17 18 .. index:: single: ListType (in module types) 19 20 This instance of :ctype:`PyTypeObject` represents the Python list type. 21 This is the same object as ``list`` and ``types.ListType`` in the Python 22 layer. 18 This instance of :c:type:`PyTypeObject` represents the Python list type. This 19 is the same object as ``list`` in the Python layer. 23 20 24 21 25 .. c function:: int PyList_Check(PyObject *p)22 .. c:function:: int PyList_Check(PyObject *p) 26 23 27 24 Return true if *p* is a list object or an instance of a subtype of the list … … 32 29 33 30 34 .. c function:: int PyList_CheckExact(PyObject *p)31 .. c:function:: int PyList_CheckExact(PyObject *p) 35 32 36 33 Return true if *p* is a list object, but not an instance of a subtype of … … 40 37 41 38 42 .. c function:: PyObject* PyList_New(Py_ssize_t len)39 .. c:function:: PyObject* PyList_New(Py_ssize_t len) 43 40 44 41 Return a new list of length *len* on success, or *NULL* on failure. … … 46 43 .. note:: 47 44 48 If *len gth* is greater than zero, the returned list object's items are45 If *len* is greater than zero, the returned list object's items are 49 46 set to ``NULL``. Thus you cannot use abstract API functions such as 50 :c func:`PySequence_SetItem` or expose the object to Python code before51 setting all items to a real object with :c func:`PyList_SetItem`.47 :c:func:`PySequence_SetItem` or expose the object to Python code before 48 setting all items to a real object with :c:func:`PyList_SetItem`. 52 49 53 50 .. versionchanged:: 2.5 54 This function used an :c type:`int` for *size*. This might require51 This function used an :c:type:`int` for *size*. This might require 55 52 changes in your code for properly supporting 64-bit systems. 56 53 57 54 58 .. c function:: Py_ssize_t PyList_Size(PyObject *list)55 .. c:function:: Py_ssize_t PyList_Size(PyObject *list) 59 56 60 57 .. index:: builtin: len … … 64 61 65 62 .. versionchanged:: 2.5 66 This function returned an :c type:`int`. This might require changes in63 This function returned an :c:type:`int`. This might require changes in 67 64 your code for properly supporting 64-bit systems. 68 65 69 66 70 .. c function:: Py_ssize_t PyList_GET_SIZE(PyObject *list)67 .. c:function:: Py_ssize_t PyList_GET_SIZE(PyObject *list) 71 68 72 Macro form of :c func:`PyList_Size` without error checking.69 Macro form of :c:func:`PyList_Size` without error checking. 73 70 74 71 .. versionchanged:: 2.5 75 This macro returned an :c type:`int`. This might require changes in your72 This macro returned an :c:type:`int`. This might require changes in your 76 73 code for properly supporting 64-bit systems. 77 74 78 75 79 .. c function:: PyObject* PyList_GetItem(PyObject *list, Py_ssize_t index)76 .. c:function:: PyObject* PyList_GetItem(PyObject *list, Py_ssize_t index) 80 77 81 Return the object at position * pos* in the list pointed to by *p*. The78 Return the object at position *index* in the list pointed to by *list*. The 82 79 position must be positive, indexing from the end of the list is not 83 supported. If * pos* is out of bounds, return *NULL* and set an80 supported. If *index* is out of bounds, return *NULL* and set an 84 81 :exc:`IndexError` exception. 85 82 86 83 .. versionchanged:: 2.5 87 This function used an :c type:`int` for *index*. This might require84 This function used an :c:type:`int` for *index*. This might require 88 85 changes in your code for properly supporting 64-bit systems. 89 86 90 87 91 .. c function:: PyObject* PyList_GET_ITEM(PyObject *list, Py_ssize_t i)88 .. c:function:: PyObject* PyList_GET_ITEM(PyObject *list, Py_ssize_t i) 92 89 93 Macro form of :c func:`PyList_GetItem` without error checking.90 Macro form of :c:func:`PyList_GetItem` without error checking. 94 91 95 92 .. versionchanged:: 2.5 96 This macro used an :c type:`int` for *i*. This might require changes in93 This macro used an :c:type:`int` for *i*. This might require changes in 97 94 your code for properly supporting 64-bit systems. 98 95 99 96 100 .. c function:: int PyList_SetItem(PyObject *list, Py_ssize_t index, PyObject *item)97 .. c:function:: int PyList_SetItem(PyObject *list, Py_ssize_t index, PyObject *item) 101 98 102 99 Set the item at index *index* in list to *item*. Return ``0`` on success … … 109 106 110 107 .. versionchanged:: 2.5 111 This function used an :c type:`int` for *index*. This might require108 This function used an :c:type:`int` for *index*. This might require 112 109 changes in your code for properly supporting 64-bit systems. 113 110 114 111 115 .. c function:: void PyList_SET_ITEM(PyObject *list, Py_ssize_t i, PyObject *o)112 .. c:function:: void PyList_SET_ITEM(PyObject *list, Py_ssize_t i, PyObject *o) 116 113 117 Macro form of :c func:`PyList_SetItem` without error checking. This is114 Macro form of :c:func:`PyList_SetItem` without error checking. This is 118 115 normally only used to fill in new lists where there is no previous content. 119 116 … … 121 118 122 119 This macro "steals" a reference to *item*, and, unlike 123 :c func:`PyList_SetItem`, does *not* discard a reference to any item that120 :c:func:`PyList_SetItem`, does *not* discard a reference to any item that 124 121 it being replaced; any reference in *list* at position *i* will be 125 122 leaked. 126 123 127 124 .. versionchanged:: 2.5 128 This macro used an :c type:`int` for *i*. This might require125 This macro used an :c:type:`int` for *i*. This might require 129 126 changes in your code for properly supporting 64-bit systems. 130 127 131 128 132 .. c function:: int PyList_Insert(PyObject *list, Py_ssize_t index, PyObject *item)129 .. c:function:: int PyList_Insert(PyObject *list, Py_ssize_t index, PyObject *item) 133 130 134 131 Insert the item *item* into list *list* in front of index *index*. Return … … 137 134 138 135 .. versionchanged:: 2.5 139 This function used an :c type:`int` for *index*. This might require136 This function used an :c:type:`int` for *index*. This might require 140 137 changes in your code for properly supporting 64-bit systems. 141 138 142 139 143 .. c function:: int PyList_Append(PyObject *list, PyObject *item)140 .. c:function:: int PyList_Append(PyObject *list, PyObject *item) 144 141 145 142 Append the object *item* at the end of list *list*. Return ``0`` if … … 148 145 149 146 150 .. c function:: PyObject* PyList_GetSlice(PyObject *list, Py_ssize_t low, Py_ssize_t high)147 .. c:function:: PyObject* PyList_GetSlice(PyObject *list, Py_ssize_t low, Py_ssize_t high) 151 148 152 149 Return a list of the objects in *list* containing the objects *between* *low* … … 156 153 157 154 .. versionchanged:: 2.5 158 This function used an :c type:`int` for *low* and *high*. This might155 This function used an :c:type:`int` for *low* and *high*. This might 159 156 require changes in your code for properly supporting 64-bit systems. 160 157 161 158 162 .. c function:: int PyList_SetSlice(PyObject *list, Py_ssize_t low, Py_ssize_t high, PyObject *itemlist)159 .. c:function:: int PyList_SetSlice(PyObject *list, Py_ssize_t low, Py_ssize_t high, PyObject *itemlist) 163 160 164 161 Set the slice of *list* between *low* and *high* to the contents of … … 169 166 170 167 .. versionchanged:: 2.5 171 This function used an :c type:`int` for *low* and *high*. This might168 This function used an :c:type:`int` for *low* and *high*. This might 172 169 require changes in your code for properly supporting 64-bit systems. 173 170 174 171 175 .. c function:: int PyList_Sort(PyObject *list)172 .. c:function:: int PyList_Sort(PyObject *list) 176 173 177 174 Sort the items of *list* in place. Return ``0`` on success, ``-1`` on … … 179 176 180 177 181 .. c function:: int PyList_Reverse(PyObject *list)178 .. c:function:: int PyList_Reverse(PyObject *list) 182 179 183 180 Reverse the items of *list* in place. Return ``0`` on success, ``-1`` on … … 185 182 186 183 187 .. c function:: PyObject* PyList_AsTuple(PyObject *list)184 .. c:function:: PyObject* PyList_AsTuple(PyObject *list) 188 185 189 186 .. index:: builtin: tuple -
python/vendor/current/Doc/c-api/long.rst
r2 r388 9 9 10 10 11 .. c type:: PyLongObject12 13 This subtype of :c type:`PyObject` represents a Python long integer object.14 15 16 .. c var:: PyTypeObject PyLong_Type11 .. c:type:: PyLongObject 12 13 This subtype of :c:type:`PyObject` represents a Python long integer object. 14 15 16 .. c:var:: PyTypeObject PyLong_Type 17 17 18 18 .. index:: single: LongType (in modules types) 19 19 20 This instance of :c type:`PyTypeObject` represents the Python long integer type.20 This instance of :c:type:`PyTypeObject` represents the Python long integer type. 21 21 This is the same object as ``long`` and ``types.LongType``. 22 22 23 23 24 .. c function:: int PyLong_Check(PyObject *p)25 26 Return true if its argument is a :c type:`PyLongObject` or a subtype of27 :c type:`PyLongObject`.24 .. c:function:: int PyLong_Check(PyObject *p) 25 26 Return true if its argument is a :c:type:`PyLongObject` or a subtype of 27 :c:type:`PyLongObject`. 28 28 29 29 .. versionchanged:: 2.2 … … 31 31 32 32 33 .. c function:: int PyLong_CheckExact(PyObject *p)34 35 Return true if its argument is a :c type:`PyLongObject`, but not a subtype of36 :c type:`PyLongObject`.33 .. c:function:: int PyLong_CheckExact(PyObject *p) 34 35 Return true if its argument is a :c:type:`PyLongObject`, but not a subtype of 36 :c:type:`PyLongObject`. 37 37 38 38 .. versionadded:: 2.2 39 39 40 40 41 .. c function:: PyObject* PyLong_FromLong(long v)42 43 Return a new :c type:`PyLongObject` object from *v*, or *NULL* on failure.44 45 46 .. c function:: PyObject* PyLong_FromUnsignedLong(unsigned long v)47 48 Return a new :c type:`PyLongObject` object from a C :ctype:`unsigned long`, or49 *NULL* on failure. 50 51 52 .. c function:: PyObject* PyLong_FromSsize_t(Py_ssize_t v)53 54 Return a new :c type:`PyLongObject` object from a C :ctype:`Py_ssize_t`, or55 *NULL* on failure. 56 57 .. versionadded:: 2.6 58 59 60 .. c function:: PyObject* PyLong_FromSize_t(size_t v)61 62 Return a new :c type:`PyLongObject` object from a C :ctype:`size_t`, or63 *NULL* on failure. 64 65 .. versionadded:: 2.6 66 67 68 .. c function:: PyObject* PyLong_FromLongLong(PY_LONG_LONGv)69 70 Return a new :c type:`PyLongObject` object from a C :ctype:`long long`, or *NULL*41 .. c:function:: PyObject* PyLong_FromLong(long v) 42 43 Return a new :c:type:`PyLongObject` object from *v*, or *NULL* on failure. 44 45 46 .. c:function:: PyObject* PyLong_FromUnsignedLong(unsigned long v) 47 48 Return a new :c:type:`PyLongObject` object from a C :c:type:`unsigned long`, or 49 *NULL* on failure. 50 51 52 .. c:function:: PyObject* PyLong_FromSsize_t(Py_ssize_t v) 53 54 Return a new :c:type:`PyLongObject` object from a C :c:type:`Py_ssize_t`, or 55 *NULL* on failure. 56 57 .. versionadded:: 2.6 58 59 60 .. c:function:: PyObject* PyLong_FromSize_t(size_t v) 61 62 Return a new :c:type:`PyLongObject` object from a C :c:type:`size_t`, or 63 *NULL* on failure. 64 65 .. versionadded:: 2.6 66 67 68 .. c:function:: PyObject* PyLong_FromSsize_t(Py_ssize_t v) 69 70 Return a new :c:type:`PyLongObject` object with a value of *v*, or *NULL* 71 71 on failure. 72 72 73 74 .. cfunction:: PyObject* PyLong_FromUnsignedLongLong(unsigned PY_LONG_LONG v) 75 76 Return a new :ctype:`PyLongObject` object from a C :ctype:`unsigned long long`, 73 .. versionadded:: 2.6 74 75 76 .. c:function:: PyObject* PyLong_FromSize_t(size_t v) 77 78 Return a new :c:type:`PyLongObject` object with a value of *v*, or *NULL* 79 on failure. 80 81 .. versionadded:: 2.6 82 83 84 .. c:function:: PyObject* PyLong_FromLongLong(PY_LONG_LONG v) 85 86 Return a new :c:type:`PyLongObject` object from a C :c:type:`long long`, or *NULL* 87 on failure. 88 89 90 .. c:function:: PyObject* PyLong_FromUnsignedLongLong(unsigned PY_LONG_LONG v) 91 92 Return a new :c:type:`PyLongObject` object from a C :c:type:`unsigned long long`, 77 93 or *NULL* on failure. 78 94 79 95 80 .. c function:: PyObject* PyLong_FromDouble(double v)81 82 Return a new :c type:`PyLongObject` object from the integer part of *v*, or83 *NULL* on failure. 84 85 86 .. c function:: PyObject* PyLong_FromString(char *str, char **pend, int base)87 88 Return a new :c type:`PyLongObject` based on the string value in *str*, which is96 .. c:function:: PyObject* PyLong_FromDouble(double v) 97 98 Return a new :c:type:`PyLongObject` object from the integer part of *v*, or 99 *NULL* on failure. 100 101 102 .. c:function:: PyObject* PyLong_FromString(char *str, char **pend, int base) 103 104 Return a new :c:type:`PyLongObject` based on the string value in *str*, which is 89 105 interpreted according to the radix in *base*. If *pend* is non-*NULL*, 90 ``*pend``will point to the first character in *str* which follows the106 *\*pend* will point to the first character in *str* which follows the 91 107 representation of the number. If *base* is ``0``, the radix will be determined 92 108 based on the leading characters of *str*: if *str* starts with ``'0x'`` or … … 97 113 98 114 99 .. c function:: PyObject* PyLong_FromUnicode(Py_UNICODE *u, Py_ssize_t length, int base)115 .. c:function:: PyObject* PyLong_FromUnicode(Py_UNICODE *u, Py_ssize_t length, int base) 100 116 101 117 Convert a sequence of Unicode digits to a Python long integer value. The first … … 108 124 109 125 .. versionchanged:: 2.5 110 This function used an :c type:`int` for *length*. This might require126 This function used an :c:type:`int` for *length*. This might require 111 127 changes in your code for properly supporting 64-bit systems. 112 128 113 129 114 .. c function:: PyObject* PyLong_FromVoidPtr(void *p)130 .. c:function:: PyObject* PyLong_FromVoidPtr(void *p) 115 131 116 132 Create a Python integer or long integer from the pointer *p*. The pointer value 117 can be retrieved from the resulting value using :c func:`PyLong_AsVoidPtr`.133 can be retrieved from the resulting value using :c:func:`PyLong_AsVoidPtr`. 118 134 119 135 .. versionadded:: 1.5.2 … … 123 139 124 140 125 .. c function:: long PyLong_AsLong(PyObject *pylong)141 .. c:function:: long PyLong_AsLong(PyObject *pylong) 126 142 127 143 .. index:: … … 129 145 single: OverflowError (built-in exception) 130 146 131 Return a C :c type:`long` representation of the contents of *pylong*. If147 Return a C :c:type:`long` representation of the contents of *pylong*. If 132 148 *pylong* is greater than :const:`LONG_MAX`, an :exc:`OverflowError` is raised 133 149 and ``-1`` will be returned. 134 150 135 151 136 .. cfunction:: Py_ssize_t PyLong_AsSsize_t(PyObject *pylong) 152 .. c:function:: long PyLong_AsLongAndOverflow(PyObject *pylong, int *overflow) 153 154 Return a C :c:type:`long` representation of the contents of 155 *pylong*. If *pylong* is greater than :const:`LONG_MAX` or less 156 than :const:`LONG_MIN`, set *\*overflow* to ``1`` or ``-1``, 157 respectively, and return ``-1``; otherwise, set *\*overflow* to 158 ``0``. If any other exception occurs (for example a TypeError or 159 MemoryError), then ``-1`` will be returned and *\*overflow* will 160 be ``0``. 161 162 .. versionadded:: 2.7 163 164 165 .. c:function:: PY_LONG_LONG PyLong_AsLongLongAndOverflow(PyObject *pylong, int *overflow) 166 167 Return a C :c:type:`long long` representation of the contents of 168 *pylong*. If *pylong* is greater than :const:`PY_LLONG_MAX` or less 169 than :const:`PY_LLONG_MIN`, set *\*overflow* to ``1`` or ``-1``, 170 respectively, and return ``-1``; otherwise, set *\*overflow* to 171 ``0``. If any other exception occurs (for example a TypeError or 172 MemoryError), then ``-1`` will be returned and *\*overflow* will 173 be ``0``. 174 175 .. versionadded:: 2.7 176 177 178 .. c:function:: Py_ssize_t PyLong_AsSsize_t(PyObject *pylong) 137 179 138 180 .. index:: … … 140 182 single: OverflowError (built-in exception) 141 183 142 Return a C :c type:`Py_ssize_t` representation of the contents of *pylong*. If184 Return a C :c:type:`Py_ssize_t` representation of the contents of *pylong*. If 143 185 *pylong* is greater than :const:`PY_SSIZE_T_MAX`, an :exc:`OverflowError` is raised 144 186 and ``-1`` will be returned. … … 147 189 148 190 149 .. c function:: unsigned long PyLong_AsUnsignedLong(PyObject *pylong)191 .. c:function:: unsigned long PyLong_AsUnsignedLong(PyObject *pylong) 150 192 151 193 .. index:: … … 153 195 single: OverflowError (built-in exception) 154 196 155 Return a C :c type:`unsigned long` representation of the contents of *pylong*.197 Return a C :c:type:`unsigned long` representation of the contents of *pylong*. 156 198 If *pylong* is greater than :const:`ULONG_MAX`, an :exc:`OverflowError` is 157 199 raised. 158 200 159 201 160 .. cfunction:: PY_LONG_LONG PyLong_AsLongLong(PyObject *pylong) 161 162 Return a C :ctype:`long long` from a Python long integer. If *pylong* cannot be 163 represented as a :ctype:`long long`, an :exc:`OverflowError` will be raised. 202 .. c:function:: Py_ssize_t PyLong_AsSsize_t(PyObject *pylong) 203 204 .. index:: 205 single: PY_SSIZE_T_MAX 206 207 Return a :c:type:`Py_ssize_t` representation of the contents of *pylong*. If 208 *pylong* is greater than :const:`PY_SSIZE_T_MAX`, an :exc:`OverflowError` is 209 raised. 210 211 .. versionadded:: 2.6 212 213 214 .. c:function:: PY_LONG_LONG PyLong_AsLongLong(PyObject *pylong) 215 216 .. index:: 217 single: OverflowError (built-in exception) 218 219 Return a C :c:type:`long long` from a Python long integer. If 220 *pylong* cannot be represented as a :c:type:`long long`, an 221 :exc:`OverflowError` is raised and ``-1`` is returned. 164 222 165 223 .. versionadded:: 2.2 166 224 167 225 168 .. cfunction:: unsigned PY_LONG_LONG PyLong_AsUnsignedLongLong(PyObject *pylong) 169 170 Return a C :ctype:`unsigned long long` from a Python long integer. If *pylong* 171 cannot be represented as an :ctype:`unsigned long long`, an :exc:`OverflowError` 172 will be raised if the value is positive, or a :exc:`TypeError` will be raised if 173 the value is negative. 226 .. c:function:: unsigned PY_LONG_LONG PyLong_AsUnsignedLongLong(PyObject *pylong) 227 228 .. index:: 229 single: OverflowError (built-in exception) 230 231 Return a C :c:type:`unsigned long long` from a Python long integer. If 232 *pylong* cannot be represented as an :c:type:`unsigned long long`, an 233 :exc:`OverflowError` is raised and ``(unsigned long long)-1`` is 234 returned. 174 235 175 236 .. versionadded:: 2.2 176 237 177 178 .. cfunction:: unsigned long PyLong_AsUnsignedLongMask(PyObject *io) 179 180 Return a C :ctype:`unsigned long` from a Python long integer, without checking 238 .. versionchanged:: 2.7 239 A negative *pylong* now raises :exc:`OverflowError`, not 240 :exc:`TypeError`. 241 242 243 .. c:function:: unsigned long PyLong_AsUnsignedLongMask(PyObject *io) 244 245 Return a C :c:type:`unsigned long` from a Python long integer, without checking 181 246 for overflow. 182 247 … … 184 249 185 250 186 .. c function:: unsigned PY_LONG_LONG PyLong_AsUnsignedLongLongMask(PyObject *io)187 188 Return a C :c type:`unsigned long long` from a Python long integer, without251 .. c:function:: unsigned PY_LONG_LONG PyLong_AsUnsignedLongLongMask(PyObject *io) 252 253 Return a C :c:type:`unsigned long long` from a Python long integer, without 189 254 checking for overflow. 190 255 … … 192 257 193 258 194 .. c function:: double PyLong_AsDouble(PyObject *pylong)195 196 Return a C :c type:`double` representation of the contents of *pylong*. If197 *pylong* cannot be approximately represented as a :c type:`double`, an259 .. c:function:: double PyLong_AsDouble(PyObject *pylong) 260 261 Return a C :c:type:`double` representation of the contents of *pylong*. If 262 *pylong* cannot be approximately represented as a :c:type:`double`, an 198 263 :exc:`OverflowError` exception is raised and ``-1.0`` will be returned. 199 264 200 265 201 .. c function:: void* PyLong_AsVoidPtr(PyObject *pylong)202 203 Convert a Python integer or long integer *pylong* to a C :c type:`void` pointer.266 .. c:function:: void* PyLong_AsVoidPtr(PyObject *pylong) 267 268 Convert a Python integer or long integer *pylong* to a C :c:type:`void` pointer. 204 269 If *pylong* cannot be converted, an :exc:`OverflowError` will be raised. This 205 is only assured to produce a usable :c type:`void` pointer for values created206 with :c func:`PyLong_FromVoidPtr`.270 is only assured to produce a usable :c:type:`void` pointer for values created 271 with :c:func:`PyLong_FromVoidPtr`. 207 272 208 273 .. versionadded:: 1.5.2 -
python/vendor/current/Doc/c-api/mapping.rst
r2 r388 7 7 8 8 9 .. c function:: int PyMapping_Check(PyObject *o)9 .. c:function:: int PyMapping_Check(PyObject *o) 10 10 11 11 Return ``1`` if the object provides mapping protocol, and ``0`` otherwise. This … … 13 13 14 14 15 .. c function:: Py_ssize_t PyMapping_Size(PyObject *o)15 .. c:function:: Py_ssize_t PyMapping_Size(PyObject *o) 16 16 Py_ssize_t PyMapping_Length(PyObject *o) 17 17 … … 23 23 24 24 .. versionchanged:: 2.5 25 These functions returned an :c type:`int` type. This might require25 These functions returned an :c:type:`int` type. This might require 26 26 changes in your code for properly supporting 64-bit systems. 27 27 28 28 29 .. c function:: int PyMapping_DelItemString(PyObject *o, char *key)29 .. c:function:: int PyMapping_DelItemString(PyObject *o, char *key) 30 30 31 31 Remove the mapping for object *key* from the object *o*. Return ``-1`` on … … 33 33 34 34 35 .. c function:: int PyMapping_DelItem(PyObject *o, PyObject *key)35 .. c:function:: int PyMapping_DelItem(PyObject *o, PyObject *key) 36 36 37 37 Remove the mapping for object *key* from the object *o*. Return ``-1`` on … … 39 39 40 40 41 .. c function:: int PyMapping_HasKeyString(PyObject *o, char *key)41 .. c:function:: int PyMapping_HasKeyString(PyObject *o, char *key) 42 42 43 43 On success, return ``1`` if the mapping object has the key *key* and ``0`` … … 46 46 47 47 48 .. c function:: int PyMapping_HasKey(PyObject *o, PyObject *key)48 .. c:function:: int PyMapping_HasKey(PyObject *o, PyObject *key) 49 49 50 50 Return ``1`` if the mapping object has the key *key* and ``0`` otherwise. … … 53 53 54 54 55 .. c function:: PyObject* PyMapping_Keys(PyObject *o)55 .. c:function:: PyObject* PyMapping_Keys(PyObject *o) 56 56 57 57 On success, return a list of the keys in object *o*. On failure, return *NULL*. … … 59 59 60 60 61 .. c function:: PyObject* PyMapping_Values(PyObject *o)61 .. c:function:: PyObject* PyMapping_Values(PyObject *o) 62 62 63 63 On success, return a list of the values in object *o*. On failure, return … … 65 65 66 66 67 .. c function:: PyObject* PyMapping_Items(PyObject *o)67 .. c:function:: PyObject* PyMapping_Items(PyObject *o) 68 68 69 69 On success, return a list of the items in object *o*, where each item is a tuple … … 72 72 73 73 74 .. c function:: PyObject* PyMapping_GetItemString(PyObject *o, char *key)74 .. c:function:: PyObject* PyMapping_GetItemString(PyObject *o, char *key) 75 75 76 76 Return element of *o* corresponding to the object *key* or *NULL* on failure. … … 78 78 79 79 80 .. c function:: int PyMapping_SetItemString(PyObject *o, char *key, PyObject *v)80 .. c:function:: int PyMapping_SetItemString(PyObject *o, char *key, PyObject *v) 81 81 82 82 Map the object *key* to the value *v* in object *o*. Returns ``-1`` on failure. -
python/vendor/current/Doc/c-api/marshal.rst
r2 r388 21 21 22 22 23 .. c function:: void PyMarshal_WriteLongToFile(long value, FILE *file, int version)23 .. c:function:: void PyMarshal_WriteLongToFile(long value, FILE *file, int version) 24 24 25 Marshal a :c type:`long` integer, *value*, to *file*. This will only write25 Marshal a :c:type:`long` integer, *value*, to *file*. This will only write 26 26 the least-significant 32 bits of *value*; regardless of the size of the 27 native :c type:`long` type.27 native :c:type:`long` type. 28 28 29 29 .. versionchanged:: 2.4 … … 31 31 32 32 33 .. c function:: void PyMarshal_WriteObjectToFile(PyObject *value, FILE *file, int version)33 .. c:function:: void PyMarshal_WriteObjectToFile(PyObject *value, FILE *file, int version) 34 34 35 35 Marshal a Python object, *value*, to *file*. … … 39 39 40 40 41 .. c function:: PyObject* PyMarshal_WriteObjectToString(PyObject *value, int version)41 .. c:function:: PyObject* PyMarshal_WriteObjectToString(PyObject *value, int version) 42 42 43 43 Return a string object containing the marshalled representation of *value*. … … 56 56 57 57 58 .. c function:: long PyMarshal_ReadLongFromFile(FILE *file)58 .. c:function:: long PyMarshal_ReadLongFromFile(FILE *file) 59 59 60 Return a C :c type:`long` from the data stream in a :ctype:`FILE\*` opened60 Return a C :c:type:`long` from the data stream in a :c:type:`FILE\*` opened 61 61 for reading. Only a 32-bit value can be read in using this function, 62 regardless of the native size of :c type:`long`.62 regardless of the native size of :c:type:`long`. 63 63 64 64 65 .. c function:: int PyMarshal_ReadShortFromFile(FILE *file)65 .. c:function:: int PyMarshal_ReadShortFromFile(FILE *file) 66 66 67 Return a C :c type:`short` from the data stream in a :ctype:`FILE\*` opened67 Return a C :c:type:`short` from the data stream in a :c:type:`FILE\*` opened 68 68 for reading. Only a 16-bit value can be read in using this function, 69 regardless of the native size of :c type:`short`.69 regardless of the native size of :c:type:`short`. 70 70 71 71 72 .. c function:: PyObject* PyMarshal_ReadObjectFromFile(FILE *file)72 .. c:function:: PyObject* PyMarshal_ReadObjectFromFile(FILE *file) 73 73 74 Return a Python object from the data stream in a :c type:`FILE\*` opened for74 Return a Python object from the data stream in a :c:type:`FILE\*` opened for 75 75 reading. On error, sets the appropriate exception (:exc:`EOFError` or 76 76 :exc:`TypeError`) and returns *NULL*. 77 77 78 78 79 .. c function:: PyObject* PyMarshal_ReadLastObjectFromFile(FILE *file)79 .. c:function:: PyObject* PyMarshal_ReadLastObjectFromFile(FILE *file) 80 80 81 Return a Python object from the data stream in a :c type:`FILE\*` opened for82 reading. Unlike :c func:`PyMarshal_ReadObjectFromFile`, this function81 Return a Python object from the data stream in a :c:type:`FILE\*` opened for 82 reading. Unlike :c:func:`PyMarshal_ReadObjectFromFile`, this function 83 83 assumes that no further objects will be read from the file, allowing it to 84 84 aggressively load file data into memory so that the de-serialization can … … 89 89 90 90 91 .. c function:: PyObject* PyMarshal_ReadObjectFromString(char *string, Py_ssize_t len)91 .. c:function:: PyObject* PyMarshal_ReadObjectFromString(char *string, Py_ssize_t len) 92 92 93 93 Return a Python object from the data stream in a character buffer … … 97 97 98 98 .. versionchanged:: 2.5 99 This function used an :c type:`int` type for *len*. This might require99 This function used an :c:type:`int` type for *len*. This might require 100 100 changes in your code for properly supporting 64-bit systems. -
python/vendor/current/Doc/c-api/memory.rst
r2 r388 48 48 49 49 To avoid memory corruption, extension writers should never try to operate on 50 Python objects with the functions exported by the C library: :c func:`malloc`,51 :c func:`calloc`, :cfunc:`realloc` and :cfunc:`free`. This will result in mixed50 Python objects with the functions exported by the C library: :c:func:`malloc`, 51 :c:func:`calloc`, :c:func:`realloc` and :c:func:`free`. This will result in mixed 52 52 calls between the C allocator and the Python memory manager with fatal 53 53 consequences, because they implement different algorithms and operate on … … 95 95 96 96 97 .. c function:: void* PyMem_Malloc(size_t n)98 99 Allocates *n* bytes and returns a pointer of type :c type:`void\*` to the97 .. c:function:: void* PyMem_Malloc(size_t n) 98 99 Allocates *n* bytes and returns a pointer of type :c:type:`void\*` to the 100 100 allocated memory, or *NULL* if the request fails. Requesting zero bytes returns 101 a distinct non-*NULL* pointer if possible, as if :cfunc:`PyMem_Malloc(1)` had101 a distinct non-*NULL* pointer if possible, as if ``PyMem_Malloc(1)`` had 102 102 been called instead. The memory will not have been initialized in any way. 103 103 104 104 105 .. c function:: void* PyMem_Realloc(void *p, size_t n)105 .. c:function:: void* PyMem_Realloc(void *p, size_t n) 106 106 107 107 Resizes the memory block pointed to by *p* to *n* bytes. The contents will be 108 108 unchanged to the minimum of the old and the new sizes. If *p* is *NULL*, the 109 call is equivalent to :cfunc:`PyMem_Malloc(n)`; else if *n* is equal to zero,109 call is equivalent to ``PyMem_Malloc(n)``; else if *n* is equal to zero, 110 110 the memory block is resized but is not freed, and the returned pointer is 111 111 non-*NULL*. Unless *p* is *NULL*, it must have been returned by a previous call 112 to :c func:`PyMem_Malloc` or :cfunc:`PyMem_Realloc`. If the request fails,113 :c func:`PyMem_Realloc` returns *NULL* and *p* remains a valid pointer to the112 to :c:func:`PyMem_Malloc` or :c:func:`PyMem_Realloc`. If the request fails, 113 :c:func:`PyMem_Realloc` returns *NULL* and *p* remains a valid pointer to the 114 114 previous memory area. 115 115 116 116 117 .. c function:: void PyMem_Free(void *p)117 .. c:function:: void PyMem_Free(void *p) 118 118 119 119 Frees the memory block pointed to by *p*, which must have been returned by a 120 previous call to :c func:`PyMem_Malloc` or :cfunc:`PyMem_Realloc`. Otherwise, or121 if :cfunc:`PyMem_Free(p)` has been called before, undefined behavior occurs. If120 previous call to :c:func:`PyMem_Malloc` or :c:func:`PyMem_Realloc`. Otherwise, or 121 if ``PyMem_Free(p)`` has been called before, undefined behavior occurs. If 122 122 *p* is *NULL*, no operation is performed. 123 123 … … 126 126 127 127 128 .. c function:: TYPE* PyMem_New(TYPE, size_t n)129 130 Same as :c func:`PyMem_Malloc`, but allocates ``(n * sizeof(TYPE))`` bytes of131 memory. Returns a pointer cast to :c type:`TYPE\*`. The memory will not have128 .. c:function:: TYPE* PyMem_New(TYPE, size_t n) 129 130 Same as :c:func:`PyMem_Malloc`, but allocates ``(n * sizeof(TYPE))`` bytes of 131 memory. Returns a pointer cast to :c:type:`TYPE\*`. The memory will not have 132 132 been initialized in any way. 133 133 134 134 135 .. c function:: TYPE* PyMem_Resize(void *p, TYPE, size_t n)136 137 Same as :c func:`PyMem_Realloc`, but the memory block is resized to ``(n *138 sizeof(TYPE))`` bytes. Returns a pointer cast to :c type:`TYPE\*`. On return,135 .. c:function:: TYPE* PyMem_Resize(void *p, TYPE, size_t n) 136 137 Same as :c:func:`PyMem_Realloc`, but the memory block is resized to ``(n * 138 sizeof(TYPE))`` bytes. Returns a pointer cast to :c:type:`TYPE\*`. On return, 139 139 *p* will be a pointer to the new memory area, or *NULL* in the event of 140 140 failure. This is a C preprocessor macro; p is always reassigned. Save … … 142 142 143 143 144 .. c function:: void PyMem_Del(void *p)145 146 Same as :c func:`PyMem_Free`.144 .. c:function:: void PyMem_Del(void *p) 145 146 Same as :c:func:`PyMem_Free`. 147 147 148 148 In addition, the following macro sets are provided for calling the Python memory … … 151 151 versions and is therefore deprecated in extension modules. 152 152 153 :c func:`PyMem_MALLOC`, :cfunc:`PyMem_REALLOC`, :cfunc:`PyMem_FREE`.154 155 :c func:`PyMem_NEW`, :cfunc:`PyMem_RESIZE`, :cfunc:`PyMem_DEL`.153 :c:func:`PyMem_MALLOC`, :c:func:`PyMem_REALLOC`, :c:func:`PyMem_FREE`. 154 155 :c:func:`PyMem_NEW`, :c:func:`PyMem_RESIZE`, :c:func:`PyMem_DEL`. 156 156 157 157 … … 202 202 203 203 In addition to the functions aimed at handling raw memory blocks from the Python 204 heap, objects in Python are allocated and released with :c func:`PyObject_New`,205 :c func:`PyObject_NewVar` and :cfunc:`PyObject_Del`.204 heap, objects in Python are allocated and released with :c:func:`PyObject_New`, 205 :c:func:`PyObject_NewVar` and :c:func:`PyObject_Del`. 206 206 207 207 These will be explained in the next chapter on defining and implementing new -
python/vendor/current/Doc/c-api/method.rst
r2 r388 11 11 12 12 13 .. c var:: PyTypeObject PyMethod_Type13 .. c:var:: PyTypeObject PyMethod_Type 14 14 15 15 .. index:: single: MethodType (in module types) 16 16 17 This instance of :c type:`PyTypeObject` represents the Python method type. This17 This instance of :c:type:`PyTypeObject` represents the Python method type. This 18 18 is exposed to Python programs as ``types.MethodType``. 19 19 20 20 21 .. c function:: int PyMethod_Check(PyObject *o)21 .. c:function:: int PyMethod_Check(PyObject *o) 22 22 23 Return true if *o* is a method object (has type :c data:`PyMethod_Type`). The23 Return true if *o* is a method object (has type :c:data:`PyMethod_Type`). The 24 24 parameter must not be *NULL*. 25 25 26 26 27 .. c function:: PyObject* PyMethod_New(PyObject *func, PyObject *self, PyObject *class)27 .. c:function:: PyObject* PyMethod_New(PyObject *func, PyObject *self, PyObject *class) 28 28 29 29 Return a new method object, with *func* being any callable object; this is the … … 34 34 35 35 36 .. c function:: PyObject* PyMethod_Class(PyObject *meth)36 .. c:function:: PyObject* PyMethod_Class(PyObject *meth) 37 37 38 38 Return the class object from which the method *meth* was created; if this was … … 40 40 41 41 42 .. c function:: PyObject* PyMethod_GET_CLASS(PyObject *meth)42 .. c:function:: PyObject* PyMethod_GET_CLASS(PyObject *meth) 43 43 44 Macro version of :c func:`PyMethod_Class` which avoids error checking.44 Macro version of :c:func:`PyMethod_Class` which avoids error checking. 45 45 46 46 47 .. c function:: PyObject* PyMethod_Function(PyObject *meth)47 .. c:function:: PyObject* PyMethod_Function(PyObject *meth) 48 48 49 49 Return the function object associated with the method *meth*. 50 50 51 51 52 .. c function:: PyObject* PyMethod_GET_FUNCTION(PyObject *meth)52 .. c:function:: PyObject* PyMethod_GET_FUNCTION(PyObject *meth) 53 53 54 Macro version of :c func:`PyMethod_Function` which avoids error checking.54 Macro version of :c:func:`PyMethod_Function` which avoids error checking. 55 55 56 56 57 .. c function:: PyObject* PyMethod_Self(PyObject *meth)57 .. c:function:: PyObject* PyMethod_Self(PyObject *meth) 58 58 59 59 Return the instance associated with the method *meth* if it is bound, otherwise … … 61 61 62 62 63 .. c function:: PyObject* PyMethod_GET_SELF(PyObject *meth)63 .. c:function:: PyObject* PyMethod_GET_SELF(PyObject *meth) 64 64 65 Macro version of :c func:`PyMethod_Self` which avoids error checking.65 Macro version of :c:func:`PyMethod_Self` which avoids error checking. 66 66 67 67 68 .. c function:: int PyMethod_ClearFreeList()68 .. c:function:: int PyMethod_ClearFreeList() 69 69 70 70 Clear the free list. Return the total number of freed items. -
python/vendor/current/Doc/c-api/module.rst
r2 r388 11 11 12 12 13 .. c var:: PyTypeObject PyModule_Type13 .. c:var:: PyTypeObject PyModule_Type 14 14 15 15 .. index:: single: ModuleType (in module types) 16 16 17 This instance of :c type:`PyTypeObject` represents the Python module type. This17 This instance of :c:type:`PyTypeObject` represents the Python module type. This 18 18 is exposed to Python programs as ``types.ModuleType``. 19 19 20 20 21 .. c function:: int PyModule_Check(PyObject *p)21 .. c:function:: int PyModule_Check(PyObject *p) 22 22 23 23 Return true if *p* is a module object, or a subtype of a module object. … … 27 27 28 28 29 .. c function:: int PyModule_CheckExact(PyObject *p)29 .. c:function:: int PyModule_CheckExact(PyObject *p) 30 30 31 31 Return true if *p* is a module object, but not a subtype of 32 :c data:`PyModule_Type`.32 :c:data:`PyModule_Type`. 33 33 34 34 .. versionadded:: 2.2 35 35 36 36 37 .. c function:: PyObject* PyModule_New(const char *name)37 .. c:function:: PyObject* PyModule_New(const char *name) 38 38 39 39 .. index:: … … 47 47 48 48 49 .. c function:: PyObject* PyModule_GetDict(PyObject *module)49 .. c:function:: PyObject* PyModule_GetDict(PyObject *module) 50 50 51 51 .. index:: single: __dict__ (module attribute) … … 54 54 is the same as the :attr:`__dict__` attribute of the module object. This 55 55 function never fails. It is recommended extensions use other 56 :c func:`PyModule_\*` and :cfunc:`PyObject_\*` functions rather than directly56 :c:func:`PyModule_\*` and :c:func:`PyObject_\*` functions rather than directly 57 57 manipulate a module's :attr:`__dict__`. 58 58 59 59 60 .. c function:: char* PyModule_GetName(PyObject *module)60 .. c:function:: char* PyModule_GetName(PyObject *module) 61 61 62 62 .. index:: … … 68 68 69 69 70 .. c function:: char* PyModule_GetFilename(PyObject *module)70 .. c:function:: char* PyModule_GetFilename(PyObject *module) 71 71 72 72 .. index:: … … 79 79 80 80 81 .. c function:: int PyModule_AddObject(PyObject *module, const char *name, PyObject *value)81 .. c:function:: int PyModule_AddObject(PyObject *module, const char *name, PyObject *value) 82 82 83 83 Add an object to *module* as *name*. This is a convenience function which can … … 88 88 89 89 90 .. c function:: int PyModule_AddIntConstant(PyObject *module, const char *name, long value)90 .. c:function:: int PyModule_AddIntConstant(PyObject *module, const char *name, long value) 91 91 92 92 Add an integer constant to *module* as *name*. This convenience function can be … … 97 97 98 98 99 .. c function:: int PyModule_AddStringConstant(PyObject *module, const char *name, const char *value)99 .. c:function:: int PyModule_AddStringConstant(PyObject *module, const char *name, const char *value) 100 100 101 101 Add a string constant to *module* as *name*. This convenience function can be … … 105 105 .. versionadded:: 2.0 106 106 107 .. c function:: int PyModule_AddIntMacro(PyObject *module, macro)107 .. c:function:: int PyModule_AddIntMacro(PyObject *module, macro) 108 108 109 109 Add an int constant to *module*. The name and the value are taken from 110 *macro*. For example ``PyModule_Add Constant(module, AF_INET)`` adds the int110 *macro*. For example ``PyModule_AddIntMacro(module, AF_INET)`` adds the int 111 111 constant *AF_INET* with the value of *AF_INET* to *module*. 112 112 Return ``-1`` on error, ``0`` on success. … … 114 114 .. versionadded:: 2.6 115 115 116 .. c function:: int PyModule_AddStringMacro(PyObject *module, macro)116 .. c:function:: int PyModule_AddStringMacro(PyObject *module, macro) 117 117 118 118 Add a string constant to *module*. -
python/vendor/current/Doc/c-api/none.rst
r2 r388 8 8 .. index:: object: None 9 9 10 Note that the :c type:`PyTypeObject` for ``None`` is not directly exposed in the10 Note that the :c:type:`PyTypeObject` for ``None`` is not directly exposed in the 11 11 Python/C API. Since ``None`` is a singleton, testing for object identity (using 12 ``==`` in C) is sufficient. There is no :c func:`PyNone_Check` function for the12 ``==`` in C) is sufficient. There is no :c:func:`PyNone_Check` function for the 13 13 same reason. 14 14 15 15 16 .. c var:: PyObject* Py_None16 .. c:var:: PyObject* Py_None 17 17 18 18 The Python ``None`` object, denoting lack of value. This object has no methods. … … 21 21 22 22 23 .. c macro:: Py_RETURN_NONE23 .. c:macro:: Py_RETURN_NONE 24 24 25 Properly handle returning :c data:`Py_None` from within a C function.25 Properly handle returning :c:data:`Py_None` from within a C function. 26 26 27 27 .. versionadded:: 2.4 -
python/vendor/current/Doc/c-api/number.rst
r2 r388 7 7 8 8 9 .. c function:: int PyNumber_Check(PyObject *o)9 .. c:function:: int PyNumber_Check(PyObject *o) 10 10 11 11 Returns ``1`` if the object *o* provides numeric protocols, and false otherwise. … … 13 13 14 14 15 .. c function:: PyObject* PyNumber_Add(PyObject *o1, PyObject *o2)15 .. c:function:: PyObject* PyNumber_Add(PyObject *o1, PyObject *o2) 16 16 17 17 Returns the result of adding *o1* and *o2*, or *NULL* on failure. This is the … … 19 19 20 20 21 .. c function:: PyObject* PyNumber_Subtract(PyObject *o1, PyObject *o2)21 .. c:function:: PyObject* PyNumber_Subtract(PyObject *o1, PyObject *o2) 22 22 23 23 Returns the result of subtracting *o2* from *o1*, or *NULL* on failure. This is … … 25 25 26 26 27 .. c function:: PyObject* PyNumber_Multiply(PyObject *o1, PyObject *o2)27 .. c:function:: PyObject* PyNumber_Multiply(PyObject *o1, PyObject *o2) 28 28 29 29 Returns the result of multiplying *o1* and *o2*, or *NULL* on failure. This is … … 31 31 32 32 33 .. c function:: PyObject* PyNumber_Divide(PyObject *o1, PyObject *o2)33 .. c:function:: PyObject* PyNumber_Divide(PyObject *o1, PyObject *o2) 34 34 35 35 Returns the result of dividing *o1* by *o2*, or *NULL* on failure. This is the … … 37 37 38 38 39 .. c function:: PyObject* PyNumber_FloorDivide(PyObject *o1, PyObject *o2)39 .. c:function:: PyObject* PyNumber_FloorDivide(PyObject *o1, PyObject *o2) 40 40 41 41 Return the floor of *o1* divided by *o2*, or *NULL* on failure. This is … … 45 45 46 46 47 .. c function:: PyObject* PyNumber_TrueDivide(PyObject *o1, PyObject *o2)47 .. c:function:: PyObject* PyNumber_TrueDivide(PyObject *o1, PyObject *o2) 48 48 49 49 Return a reasonable approximation for the mathematical value of *o1* divided by … … 56 56 57 57 58 .. c function:: PyObject* PyNumber_Remainder(PyObject *o1, PyObject *o2)58 .. c:function:: PyObject* PyNumber_Remainder(PyObject *o1, PyObject *o2) 59 59 60 60 Returns the remainder of dividing *o1* by *o2*, or *NULL* on failure. This is … … 62 62 63 63 64 .. c function:: PyObject* PyNumber_Divmod(PyObject *o1, PyObject *o2)64 .. c:function:: PyObject* PyNumber_Divmod(PyObject *o1, PyObject *o2) 65 65 66 66 .. index:: builtin: divmod … … 70 70 71 71 72 .. c function:: PyObject* PyNumber_Power(PyObject *o1, PyObject *o2, PyObject *o3)72 .. c:function:: PyObject* PyNumber_Power(PyObject *o1, PyObject *o2, PyObject *o3) 73 73 74 74 .. index:: builtin: pow … … 76 76 See the built-in function :func:`pow`. Returns *NULL* on failure. This is the 77 77 equivalent of the Python expression ``pow(o1, o2, o3)``, where *o3* is optional. 78 If *o3* is to be ignored, pass :c data:`Py_None` in its place (passing *NULL* for78 If *o3* is to be ignored, pass :c:data:`Py_None` in its place (passing *NULL* for 79 79 *o3* would cause an illegal memory access). 80 80 81 81 82 .. c function:: PyObject* PyNumber_Negative(PyObject *o)82 .. c:function:: PyObject* PyNumber_Negative(PyObject *o) 83 83 84 84 Returns the negation of *o* on success, or *NULL* on failure. This is the … … 86 86 87 87 88 .. c function:: PyObject* PyNumber_Positive(PyObject *o)88 .. c:function:: PyObject* PyNumber_Positive(PyObject *o) 89 89 90 90 Returns *o* on success, or *NULL* on failure. This is the equivalent of the … … 92 92 93 93 94 .. c function:: PyObject* PyNumber_Absolute(PyObject *o)94 .. c:function:: PyObject* PyNumber_Absolute(PyObject *o) 95 95 96 96 .. index:: builtin: abs … … 100 100 101 101 102 .. c function:: PyObject* PyNumber_Invert(PyObject *o)102 .. c:function:: PyObject* PyNumber_Invert(PyObject *o) 103 103 104 104 Returns the bitwise negation of *o* on success, or *NULL* on failure. This is … … 106 106 107 107 108 .. c function:: PyObject* PyNumber_Lshift(PyObject *o1, PyObject *o2)108 .. c:function:: PyObject* PyNumber_Lshift(PyObject *o1, PyObject *o2) 109 109 110 110 Returns the result of left shifting *o1* by *o2* on success, or *NULL* on … … 112 112 113 113 114 .. c function:: PyObject* PyNumber_Rshift(PyObject *o1, PyObject *o2)114 .. c:function:: PyObject* PyNumber_Rshift(PyObject *o1, PyObject *o2) 115 115 116 116 Returns the result of right shifting *o1* by *o2* on success, or *NULL* on … … 118 118 119 119 120 .. c function:: PyObject* PyNumber_And(PyObject *o1, PyObject *o2)120 .. c:function:: PyObject* PyNumber_And(PyObject *o1, PyObject *o2) 121 121 122 122 Returns the "bitwise and" of *o1* and *o2* on success and *NULL* on failure. … … 124 124 125 125 126 .. c function:: PyObject* PyNumber_Xor(PyObject *o1, PyObject *o2)126 .. c:function:: PyObject* PyNumber_Xor(PyObject *o1, PyObject *o2) 127 127 128 128 Returns the "bitwise exclusive or" of *o1* by *o2* on success, or *NULL* on … … 130 130 131 131 132 .. c function:: PyObject* PyNumber_Or(PyObject *o1, PyObject *o2)132 .. c:function:: PyObject* PyNumber_Or(PyObject *o1, PyObject *o2) 133 133 134 134 Returns the "bitwise or" of *o1* and *o2* on success, or *NULL* on failure. … … 136 136 137 137 138 .. c function:: PyObject* PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2)138 .. c:function:: PyObject* PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2) 139 139 140 140 Returns the result of adding *o1* and *o2*, or *NULL* on failure. The operation … … 143 143 144 144 145 .. c function:: PyObject* PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2)145 .. c:function:: PyObject* PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2) 146 146 147 147 Returns the result of subtracting *o2* from *o1*, or *NULL* on failure. The … … 150 150 151 151 152 .. c function:: PyObject* PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2)152 .. c:function:: PyObject* PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2) 153 153 154 154 Returns the result of multiplying *o1* and *o2*, or *NULL* on failure. The … … 157 157 158 158 159 .. c function:: PyObject* PyNumber_InPlaceDivide(PyObject *o1, PyObject *o2)159 .. c:function:: PyObject* PyNumber_InPlaceDivide(PyObject *o1, PyObject *o2) 160 160 161 161 Returns the result of dividing *o1* by *o2*, or *NULL* on failure. The … … 164 164 165 165 166 .. c function:: PyObject* PyNumber_InPlaceFloorDivide(PyObject *o1, PyObject *o2)166 .. c:function:: PyObject* PyNumber_InPlaceFloorDivide(PyObject *o1, PyObject *o2) 167 167 168 168 Returns the mathematical floor of dividing *o1* by *o2*, or *NULL* on failure. … … 173 173 174 174 175 .. c function:: PyObject* PyNumber_InPlaceTrueDivide(PyObject *o1, PyObject *o2)175 .. c:function:: PyObject* PyNumber_InPlaceTrueDivide(PyObject *o1, PyObject *o2) 176 176 177 177 Return a reasonable approximation for the mathematical value of *o1* divided by … … 184 184 185 185 186 .. c function:: PyObject* PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2)186 .. c:function:: PyObject* PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2) 187 187 188 188 Returns the remainder of dividing *o1* by *o2*, or *NULL* on failure. The … … 191 191 192 192 193 .. c function:: PyObject* PyNumber_InPlacePower(PyObject *o1, PyObject *o2, PyObject *o3)193 .. c:function:: PyObject* PyNumber_InPlacePower(PyObject *o1, PyObject *o2, PyObject *o3) 194 194 195 195 .. index:: builtin: pow … … 197 197 See the built-in function :func:`pow`. Returns *NULL* on failure. The operation 198 198 is done *in-place* when *o1* supports it. This is the equivalent of the Python 199 statement ``o1 **= o2`` when o3 is :c data:`Py_None`, or an in-place variant of200 ``pow(o1, o2, o3)`` otherwise. If *o3* is to be ignored, pass :c data:`Py_None`199 statement ``o1 **= o2`` when o3 is :c:data:`Py_None`, or an in-place variant of 200 ``pow(o1, o2, o3)`` otherwise. If *o3* is to be ignored, pass :c:data:`Py_None` 201 201 in its place (passing *NULL* for *o3* would cause an illegal memory access). 202 202 203 203 204 .. c function:: PyObject* PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2)204 .. c:function:: PyObject* PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2) 205 205 206 206 Returns the result of left shifting *o1* by *o2* on success, or *NULL* on … … 209 209 210 210 211 .. c function:: PyObject* PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2)211 .. c:function:: PyObject* PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2) 212 212 213 213 Returns the result of right shifting *o1* by *o2* on success, or *NULL* on … … 216 216 217 217 218 .. c function:: PyObject* PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2)218 .. c:function:: PyObject* PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2) 219 219 220 220 Returns the "bitwise and" of *o1* and *o2* on success and *NULL* on failure. The … … 223 223 224 224 225 .. c function:: PyObject* PyNumber_InPlaceXor(PyObject *o1, PyObject *o2)225 .. c:function:: PyObject* PyNumber_InPlaceXor(PyObject *o1, PyObject *o2) 226 226 227 227 Returns the "bitwise exclusive or" of *o1* by *o2* on success, or *NULL* on … … 230 230 231 231 232 .. c function:: PyObject* PyNumber_InPlaceOr(PyObject *o1, PyObject *o2)232 .. c:function:: PyObject* PyNumber_InPlaceOr(PyObject *o1, PyObject *o2) 233 233 234 234 Returns the "bitwise or" of *o1* and *o2* on success, or *NULL* on failure. The … … 237 237 238 238 239 .. c function:: int PyNumber_Coerce(PyObject **p1, PyObject **p2)239 .. c:function:: int PyNumber_Coerce(PyObject **p1, PyObject **p2) 240 240 241 241 .. index:: builtin: coerce 242 242 243 This function takes the addresses of two variables of type :c type:`PyObject\*`.243 This function takes the addresses of two variables of type :c:type:`PyObject\*`. 244 244 If the objects pointed to by ``*p1`` and ``*p2`` have the same type, increment 245 245 their reference count and return ``0`` (success). If the objects can be … … 251 251 252 252 253 .. c function:: int PyNumber_CoerceEx(PyObject **p1, PyObject **p2)254 255 This function is similar to :c func:`PyNumber_Coerce`, except that it returns253 .. c:function:: int PyNumber_CoerceEx(PyObject **p1, PyObject **p2) 254 255 This function is similar to :c:func:`PyNumber_Coerce`, except that it returns 256 256 ``1`` when the conversion is not possible and when no error is raised. 257 257 Reference counts are still not increased in this case. 258 258 259 259 260 .. c function:: PyObject* PyNumber_Int(PyObject *o)260 .. c:function:: PyObject* PyNumber_Int(PyObject *o) 261 261 262 262 .. index:: builtin: int … … 267 267 268 268 269 .. c function:: PyObject* PyNumber_Long(PyObject *o)269 .. c:function:: PyObject* PyNumber_Long(PyObject *o) 270 270 271 271 .. index:: builtin: long … … 275 275 276 276 277 .. c function:: PyObject* PyNumber_Float(PyObject *o)277 .. c:function:: PyObject* PyNumber_Float(PyObject *o) 278 278 279 279 .. index:: builtin: float … … 283 283 284 284 285 .. c function:: PyObject* PyNumber_Index(PyObject *o)285 .. c:function:: PyObject* PyNumber_Index(PyObject *o) 286 286 287 287 Returns the *o* converted to a Python int or long on success or *NULL* with a … … 291 291 292 292 293 .. c function:: PyObject* PyNumber_ToBase(PyObject *n, int base)293 .. c:function:: PyObject* PyNumber_ToBase(PyObject *n, int base) 294 294 295 295 Returns the integer *n* converted to *base* as a string with a base … … 297 297 *base* is not 2, 8, 10, or 16, the format is ``'x#num'`` where x is the 298 298 base. If *n* is not an int object, it is converted with 299 :c func:`PyNumber_Index` first.299 :c:func:`PyNumber_Index` first. 300 300 301 301 .. versionadded:: 2.6 302 302 303 303 304 .. c function:: Py_ssize_t PyNumber_AsSsize_t(PyObject *o, PyObject *exc)304 .. c:function:: Py_ssize_t PyNumber_AsSsize_t(PyObject *o, PyObject *exc) 305 305 306 306 Returns *o* converted to a Py_ssize_t value if *o* can be interpreted as an … … 315 315 316 316 317 .. c function:: int PyIndex_Check(PyObject *o)317 .. c:function:: int PyIndex_Check(PyObject *o) 318 318 319 319 Returns True if *o* is an index integer (has the nb_index slot of the -
python/vendor/current/Doc/c-api/objbuffer.rst
r2 r388 3 3 .. _abstract-buffer: 4 4 5 5 6 Old Buffer Protocol 6 7 =================== 7 8 8 9 9 This section describes the legacy buffer protocol, which has been introduced 10 10 in Python 1.6. It is still supported but deprecated in the Python 2.x series. 11 Python 3 .0introduces a new buffer protocol which fixes weaknesses and11 Python 3 introduces a new buffer protocol which fixes weaknesses and 12 12 shortcomings of the protocol, and has been backported to Python 2.6. See 13 13 :ref:`bufferobjects` for more information. 14 14 15 15 16 .. c function:: int PyObject_AsCharBuffer(PyObject *obj, const char **buffer, Py_ssize_t *buffer_len)16 .. c:function:: int PyObject_AsCharBuffer(PyObject *obj, const char **buffer, Py_ssize_t *buffer_len) 17 17 18 18 Returns a pointer to a read-only memory location usable as character-based … … 25 25 26 26 .. versionchanged:: 2.5 27 This function used an :c type:`int *` type for *buffer_len*. This might27 This function used an :c:type:`int *` type for *buffer_len*. This might 28 28 require changes in your code for properly supporting 64-bit systems. 29 29 30 30 31 .. c function:: int PyObject_AsReadBuffer(PyObject *obj, const void **buffer, Py_ssize_t *buffer_len)31 .. c:function:: int PyObject_AsReadBuffer(PyObject *obj, const void **buffer, Py_ssize_t *buffer_len) 32 32 33 33 Returns a pointer to a read-only memory location containing arbitrary data. … … 40 40 41 41 .. versionchanged:: 2.5 42 This function used an :c type:`int *` type for *buffer_len*. This might42 This function used an :c:type:`int *` type for *buffer_len*. This might 43 43 require changes in your code for properly supporting 64-bit systems. 44 44 45 45 46 .. c function:: int PyObject_CheckReadBuffer(PyObject *o)46 .. c:function:: int PyObject_CheckReadBuffer(PyObject *o) 47 47 48 48 Returns ``1`` if *o* supports the single-segment readable buffer interface. … … 52 52 53 53 54 .. c function:: int PyObject_AsWriteBuffer(PyObject *obj, void **buffer, Py_ssize_t *buffer_len)54 .. c:function:: int PyObject_AsWriteBuffer(PyObject *obj, void **buffer, Py_ssize_t *buffer_len) 55 55 56 56 Returns a pointer to a writeable memory location. The *obj* argument must … … 62 62 63 63 .. versionchanged:: 2.5 64 This function used an :c type:`int *` type for *buffer_len*. This might64 This function used an :c:type:`int *` type for *buffer_len*. This might 65 65 require changes in your code for properly supporting 64-bit systems. 66 66 -
python/vendor/current/Doc/c-api/object.rst
r2 r388 7 7 8 8 9 .. c function:: int PyObject_Print(PyObject *o, FILE *fp, int flags)9 .. c:function:: int PyObject_Print(PyObject *o, FILE *fp, int flags) 10 10 11 11 Print an object *o*, on file *fp*. Returns ``-1`` on error. The flags argument … … 15 15 16 16 17 .. c function:: int PyObject_HasAttr(PyObject *o, PyObject *attr_name)17 .. c:function:: int PyObject_HasAttr(PyObject *o, PyObject *attr_name) 18 18 19 19 Returns ``1`` if *o* has the attribute *attr_name*, and ``0`` otherwise. This … … 22 22 23 23 24 .. c function:: int PyObject_HasAttrString(PyObject *o, const char *attr_name)24 .. c:function:: int PyObject_HasAttrString(PyObject *o, const char *attr_name) 25 25 26 26 Returns ``1`` if *o* has the attribute *attr_name*, and ``0`` otherwise. This … … 29 29 30 30 31 .. c function:: PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name)31 .. c:function:: PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name) 32 32 33 33 Retrieve an attribute named *attr_name* from object *o*. Returns the attribute … … 36 36 37 37 38 .. c function:: PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name)38 .. c:function:: PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name) 39 39 40 40 Retrieve an attribute named *attr_name* from object *o*. Returns the attribute … … 43 43 44 44 45 .. c function:: PyObject* PyObject_GenericGetAttr(PyObject *o, PyObject *name)45 .. c:function:: PyObject* PyObject_GenericGetAttr(PyObject *o, PyObject *name) 46 46 47 47 Generic attribute getter function that is meant to be put into a type 48 48 object's ``tp_getattro`` slot. It looks for a descriptor in the dictionary 49 49 of classes in the object's MRO as well as an attribute in the object's 50 :attr:` __dict__` (if present). As outlined in :ref:`descriptors`, data51 d escriptors take preference over instance attributes, while non-data50 :attr:`~object.__dict__` (if present). As outlined in :ref:`descriptors`, 51 data descriptors take preference over instance attributes, while non-data 52 52 descriptors don't. Otherwise, an :exc:`AttributeError` is raised. 53 53 54 54 55 .. c function:: int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v)55 .. c:function:: int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v) 56 56 57 57 Set the value of the attribute named *attr_name*, for object *o*, to the value … … 60 60 61 61 62 .. c function:: int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v)62 .. c:function:: int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v) 63 63 64 64 Set the value of the attribute named *attr_name*, for object *o*, to the value … … 67 67 68 68 69 .. c function:: int PyObject_GenericSetAttr(PyObject *o, PyObject *name, PyObject *value)69 .. c:function:: int PyObject_GenericSetAttr(PyObject *o, PyObject *name, PyObject *value) 70 70 71 71 Generic attribute setter function that is meant to be put into a type … … 73 73 dictionary of classes in the object's MRO, and if found it takes preference 74 74 over setting the attribute in the instance dictionary. Otherwise, the 75 attribute is set in the object's :attr:` __dict__` (if present). Otherwise,76 an :exc:`AttributeError` is raised and ``-1`` is returned.77 78 79 .. c function:: int PyObject_DelAttr(PyObject *o, PyObject *attr_name)75 attribute is set in the object's :attr:`~object.__dict__` (if present). 76 Otherwise, an :exc:`AttributeError` is raised and ``-1`` is returned. 77 78 79 .. c:function:: int PyObject_DelAttr(PyObject *o, PyObject *attr_name) 80 80 81 81 Delete attribute named *attr_name*, for object *o*. Returns ``-1`` on failure. … … 83 83 84 84 85 .. c function:: int PyObject_DelAttrString(PyObject *o, const char *attr_name)85 .. c:function:: int PyObject_DelAttrString(PyObject *o, const char *attr_name) 86 86 87 87 Delete attribute named *attr_name*, for object *o*. Returns ``-1`` on failure. … … 89 89 90 90 91 .. c function:: PyObject* PyObject_RichCompare(PyObject *o1, PyObject *o2, int opid)91 .. c:function:: PyObject* PyObject_RichCompare(PyObject *o1, PyObject *o2, int opid) 92 92 93 93 Compare the values of *o1* and *o2* using the operation specified by *opid*, … … 99 99 100 100 101 .. c function:: int PyObject_RichCompareBool(PyObject *o1, PyObject *o2, int opid)101 .. c:function:: int PyObject_RichCompareBool(PyObject *o1, PyObject *o2, int opid) 102 102 103 103 Compare the values of *o1* and *o2* using the operation specified by *opid*, … … 109 109 *opid*. 110 110 111 112 .. cfunction:: int PyObject_Cmp(PyObject *o1, PyObject *o2, int *result) 111 .. note:: 112 If *o1* and *o2* are the same object, :c:func:`PyObject_RichCompareBool` 113 will always return ``1`` for :const:`Py_EQ` and ``0`` for :const:`Py_NE`. 114 115 .. c:function:: int PyObject_Cmp(PyObject *o1, PyObject *o2, int *result) 113 116 114 117 .. index:: builtin: cmp … … 120 123 121 124 122 .. c function:: int PyObject_Compare(PyObject *o1, PyObject *o2)125 .. c:function:: int PyObject_Compare(PyObject *o1, PyObject *o2) 123 126 124 127 .. index:: builtin: cmp … … 127 130 exists, otherwise with a routine provided by *o2*. Returns the result of the 128 131 comparison on success. On error, the value returned is undefined; use 129 :c func:`PyErr_Occurred` to detect an error. This is equivalent to the Python132 :c:func:`PyErr_Occurred` to detect an error. This is equivalent to the Python 130 133 expression ``cmp(o1, o2)``. 131 134 132 135 133 .. c function:: PyObject* PyObject_Repr(PyObject *o)136 .. c:function:: PyObject* PyObject_Repr(PyObject *o) 134 137 135 138 .. index:: builtin: repr … … 141 144 142 145 143 .. c function:: PyObject* PyObject_Str(PyObject *o)146 .. c:function:: PyObject* PyObject_Str(PyObject *o) 144 147 145 148 .. index:: builtin: str … … 151 154 152 155 153 .. c function:: PyObject* PyObject_Bytes(PyObject *o)156 .. c:function:: PyObject* PyObject_Bytes(PyObject *o) 154 157 155 158 .. index:: builtin: bytes 156 159 157 160 Compute a bytes representation of object *o*. In 2.x, this is just a alias 158 for :c func:`PyObject_Str`.159 160 161 .. c function:: PyObject* PyObject_Unicode(PyObject *o)161 for :c:func:`PyObject_Str`. 162 163 164 .. c:function:: PyObject* PyObject_Unicode(PyObject *o) 162 165 163 166 .. index:: builtin: unicode … … 169 172 170 173 171 .. c function:: int PyObject_IsInstance(PyObject *inst, PyObject *cls)174 .. c:function:: int PyObject_IsInstance(PyObject *inst, PyObject *cls) 172 175 173 176 Returns ``1`` if *inst* is an instance of the class *cls* or a subclass of 174 177 *cls*, or ``0`` if not. On error, returns ``-1`` and sets an exception. If 175 *cls* is a type object rather than a class object, :c func:`PyObject_IsInstance`178 *cls* is a type object rather than a class object, :c:func:`PyObject_IsInstance` 176 179 returns ``1`` if *inst* is of type *cls*. If *cls* is a tuple, the check will 177 180 be done against every entry in *cls*. The result will be ``1`` when at least one 178 181 of the checks returns ``1``, otherwise it will be ``0``. If *inst* is not a 179 182 class instance and *cls* is neither a type object, nor a class object, nor a 180 tuple, *inst* must have a :attr:` __class__` attribute --- the class relationship181 of the value of that attribute with *cls* will be used to determine the result182 of this function.183 tuple, *inst* must have a :attr:`~instance.__class__` attribute --- the 184 class relationship of the value of that attribute with *cls* will be used 185 to determine the result of this function. 183 186 184 187 .. versionadded:: 2.1 … … 193 196 either is not a class object, a more general mechanism is used to determine the 194 197 class relationship of the two objects. When testing if *B* is a subclass of 195 *A*, if *A* is *B*, :c func:`PyObject_IsSubclass` returns true. If *A* and *B*196 are different objects, *B*'s :attr:` __bases__` attribute is searched in a197 depth-first fashion for *A* --- the presence of the :attr:`__bases__` attribute 198 is considered sufficient for this determination.199 200 201 .. c function:: int PyObject_IsSubclass(PyObject *derived, PyObject *cls)198 *A*, if *A* is *B*, :c:func:`PyObject_IsSubclass` returns true. If *A* and *B* 199 are different objects, *B*'s :attr:`~class.__bases__` attribute is searched in 200 a depth-first fashion for *A* --- the presence of the :attr:`~class.__bases__` 201 attribute is considered sufficient for this determination. 202 203 204 .. c:function:: int PyObject_IsSubclass(PyObject *derived, PyObject *cls) 202 205 203 206 Returns ``1`` if the class *derived* is identical to or derived from the class … … 214 217 215 218 216 .. c function:: int PyCallable_Check(PyObject *o)219 .. c:function:: int PyCallable_Check(PyObject *o) 217 220 218 221 Determine if the object *o* is callable. Return ``1`` if the object is callable … … 220 223 221 224 222 .. c function:: PyObject* PyObject_Call(PyObject *callable_object, PyObject *args, PyObject *kw)225 .. c:function:: PyObject* PyObject_Call(PyObject *callable_object, PyObject *args, PyObject *kw) 223 226 224 227 .. index:: builtin: apply … … 234 237 235 238 236 .. c function:: PyObject* PyObject_CallObject(PyObject *callable_object, PyObject *args)239 .. c:function:: PyObject* PyObject_CallObject(PyObject *callable_object, PyObject *args) 237 240 238 241 .. index:: builtin: apply … … 245 248 246 249 247 .. c function:: PyObject* PyObject_CallFunction(PyObject *callable, char *format, ...)250 .. c:function:: PyObject* PyObject_CallFunction(PyObject *callable, char *format, ...) 248 251 249 252 .. index:: builtin: apply 250 253 251 254 Call a callable Python object *callable*, with a variable number of C arguments. 252 The C arguments are described using a :c func:`Py_BuildValue` style format255 The C arguments are described using a :c:func:`Py_BuildValue` style format 253 256 string. The format may be *NULL*, indicating that no arguments are provided. 254 257 Returns the result of the call on success, or *NULL* on failure. This is the 255 258 equivalent of the Python expression ``apply(callable, args)`` or 256 ``callable(*args)``. Note that if you only pass :c type:`PyObject \*` args,257 :c func:`PyObject_CallFunctionObjArgs` is a faster alternative.258 259 260 .. c function:: PyObject* PyObject_CallMethod(PyObject *o, char *method, char *format, ...)259 ``callable(*args)``. Note that if you only pass :c:type:`PyObject \*` args, 260 :c:func:`PyObject_CallFunctionObjArgs` is a faster alternative. 261 262 263 .. c:function:: PyObject* PyObject_CallMethod(PyObject *o, char *method, char *format, ...) 261 264 262 265 Call the method named *method* of object *o* with a variable number of C 263 arguments. The C arguments are described by a :c func:`Py_BuildValue` format266 arguments. The C arguments are described by a :c:func:`Py_BuildValue` format 264 267 string that should produce a tuple. The format may be *NULL*, indicating that 265 268 no arguments are provided. Returns the result of the call on success, or *NULL* 266 269 on failure. This is the equivalent of the Python expression ``o.method(args)``. 267 Note that if you only pass :c type:`PyObject \*` args,268 :c func:`PyObject_CallMethodObjArgs` is a faster alternative.269 270 271 .. c function:: PyObject* PyObject_CallFunctionObjArgs(PyObject *callable, ..., NULL)270 Note that if you only pass :c:type:`PyObject \*` args, 271 :c:func:`PyObject_CallMethodObjArgs` is a faster alternative. 272 273 274 .. c:function:: PyObject* PyObject_CallFunctionObjArgs(PyObject *callable, ..., NULL) 272 275 273 276 Call a callable Python object *callable*, with a variable number of 274 :c type:`PyObject\*` arguments. The arguments are provided as a variable number277 :c:type:`PyObject\*` arguments. The arguments are provided as a variable number 275 278 of parameters followed by *NULL*. Returns the result of the call on success, or 276 279 *NULL* on failure. … … 279 282 280 283 281 .. c function:: PyObject* PyObject_CallMethodObjArgs(PyObject *o, PyObject *name, ..., NULL)284 .. c:function:: PyObject* PyObject_CallMethodObjArgs(PyObject *o, PyObject *name, ..., NULL) 282 285 283 286 Calls a method of the object *o*, where the name of the method is given as a 284 287 Python string object in *name*. It is called with a variable number of 285 :c type:`PyObject\*` arguments. The arguments are provided as a variable number288 :c:type:`PyObject\*` arguments. The arguments are provided as a variable number 286 289 of parameters followed by *NULL*. Returns the result of the call on success, or 287 290 *NULL* on failure. … … 290 293 291 294 292 .. c function:: long PyObject_Hash(PyObject *o)295 .. c:function:: long PyObject_Hash(PyObject *o) 293 296 294 297 .. index:: builtin: hash … … 298 301 299 302 300 .. c function:: long PyObject_HashNotImplemented(PyObject *o)303 .. c:function:: long PyObject_HashNotImplemented(PyObject *o) 301 304 302 305 Set a :exc:`TypeError` indicating that ``type(o)`` is not hashable and return ``-1``. … … 308 311 309 312 310 .. c function:: int PyObject_IsTrue(PyObject *o)313 .. c:function:: int PyObject_IsTrue(PyObject *o) 311 314 312 315 Returns ``1`` if the object *o* is considered to be true, and ``0`` otherwise. … … 315 318 316 319 317 .. c function:: int PyObject_Not(PyObject *o)320 .. c:function:: int PyObject_Not(PyObject *o) 318 321 319 322 Returns ``0`` if the object *o* is considered to be true, and ``1`` otherwise. … … 322 325 323 326 324 .. c function:: PyObject* PyObject_Type(PyObject *o)327 .. c:function:: PyObject* PyObject_Type(PyObject *o) 325 328 326 329 .. index:: builtin: type … … 331 334 reference count of the return value. There's really no reason to use this 332 335 function instead of the common expression ``o->ob_type``, which returns a 333 pointer of type :c type:`PyTypeObject\*`, except when the incremented reference336 pointer of type :c:type:`PyTypeObject\*`, except when the incremented reference 334 337 count is needed. 335 338 336 339 337 .. c function:: int PyObject_TypeCheck(PyObject *o, PyTypeObject *type)340 .. c:function:: int PyObject_TypeCheck(PyObject *o, PyTypeObject *type) 338 341 339 342 Return true if the object *o* is of type *type* or a subtype of *type*. Both … … 343 346 344 347 345 .. c function:: Py_ssize_t PyObject_Length(PyObject *o)348 .. c:function:: Py_ssize_t PyObject_Length(PyObject *o) 346 349 Py_ssize_t PyObject_Size(PyObject *o) 347 350 … … 353 356 354 357 .. versionchanged:: 2.5 355 These functions returned an :c type:`int` type. This might require358 These functions returned an :c:type:`int` type. This might require 356 359 changes in your code for properly supporting 64-bit systems. 357 360 358 361 359 .. c function:: PyObject* PyObject_GetItem(PyObject *o, PyObject *key)362 .. c:function:: PyObject* PyObject_GetItem(PyObject *o, PyObject *key) 360 363 361 364 Return element of *o* corresponding to the object *key* or *NULL* on failure. … … 363 366 364 367 365 .. c function:: int PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v)368 .. c:function:: int PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v) 366 369 367 370 Map the object *key* to the value *v*. Returns ``-1`` on failure. This is the … … 369 372 370 373 371 .. c function:: int PyObject_DelItem(PyObject *o, PyObject *key)374 .. c:function:: int PyObject_DelItem(PyObject *o, PyObject *key) 372 375 373 376 Delete the mapping for *key* from *o*. Returns ``-1`` on failure. This is the … … 375 378 376 379 377 .. c function:: int PyObject_AsFileDescriptor(PyObject *o)380 .. c:function:: int PyObject_AsFileDescriptor(PyObject *o) 378 381 379 382 Derives a file descriptor from a Python object. If the object is an integer or … … 383 386 384 387 385 .. c function:: PyObject* PyObject_Dir(PyObject *o)388 .. c:function:: PyObject* PyObject_Dir(PyObject *o) 386 389 387 390 This is equivalent to the Python expression ``dir(o)``, returning a (possibly … … 389 392 was an error. If the argument is *NULL*, this is like the Python ``dir()``, 390 393 returning the names of the current locals; in this case, if no execution frame 391 is active then *NULL* is returned but :c func:`PyErr_Occurred` will return false.392 393 394 .. c function:: PyObject* PyObject_GetIter(PyObject *o)394 is active then *NULL* is returned but :c:func:`PyErr_Occurred` will return false. 395 396 397 .. c:function:: PyObject* PyObject_GetIter(PyObject *o) 395 398 396 399 This is equivalent to the Python expression ``iter(o)``. It returns a new -
python/vendor/current/Doc/c-api/refcounting.rst
r2 r388 12 12 13 13 14 .. c function:: void Py_INCREF(PyObject *o)14 .. c:function:: void Py_INCREF(PyObject *o) 15 15 16 16 Increment the reference count for object *o*. The object must not be *NULL*; if 17 you aren't sure that it isn't *NULL*, use :c func:`Py_XINCREF`.17 you aren't sure that it isn't *NULL*, use :c:func:`Py_XINCREF`. 18 18 19 19 20 .. c function:: void Py_XINCREF(PyObject *o)20 .. c:function:: void Py_XINCREF(PyObject *o) 21 21 22 22 Increment the reference count for object *o*. The object may be *NULL*, in … … 24 24 25 25 26 .. c function:: void Py_DECREF(PyObject *o)26 .. c:function:: void Py_DECREF(PyObject *o) 27 27 28 28 Decrement the reference count for object *o*. The object must not be *NULL*; if 29 you aren't sure that it isn't *NULL*, use :c func:`Py_XDECREF`. If the reference29 you aren't sure that it isn't *NULL*, use :c:func:`Py_XDECREF`. If the reference 30 30 count reaches zero, the object's type's deallocation function (which must not be 31 31 *NULL*) is invoked. … … 37 37 exceptions in such code are not propagated, the executed code has free access to 38 38 all Python global variables. This means that any object that is reachable from 39 a global variable should be in a consistent state before :c func:`Py_DECREF` is39 a global variable should be in a consistent state before :c:func:`Py_DECREF` is 40 40 invoked. For example, code to delete an object from a list should copy a 41 41 reference to the deleted object in a temporary variable, update the list data 42 structure, and then call :c func:`Py_DECREF` for the temporary variable.42 structure, and then call :c:func:`Py_DECREF` for the temporary variable. 43 43 44 44 45 .. c function:: void Py_XDECREF(PyObject *o)45 .. c:function:: void Py_XDECREF(PyObject *o) 46 46 47 47 Decrement the reference count for object *o*. The object may be *NULL*, in 48 48 which case the macro has no effect; otherwise the effect is the same as for 49 :c func:`Py_DECREF`, and the same warning applies.49 :c:func:`Py_DECREF`, and the same warning applies. 50 50 51 51 52 .. c function:: void Py_CLEAR(PyObject *o)52 .. c:function:: void Py_CLEAR(PyObject *o) 53 53 54 54 Decrement the reference count for object *o*. The object may be *NULL*, in 55 55 which case the macro has no effect; otherwise the effect is the same as for 56 :c func:`Py_DECREF`, except that the argument is also set to *NULL*. The warning57 for :c func:`Py_DECREF` does not apply with respect to the object passed because56 :c:func:`Py_DECREF`, except that the argument is also set to *NULL*. The warning 57 for :c:func:`Py_DECREF` does not apply with respect to the object passed because 58 58 the macro carefully uses a temporary variable and sets the argument to *NULL* 59 59 before decrementing its reference count. … … 66 66 The following functions are for runtime dynamic embedding of Python: 67 67 ``Py_IncRef(PyObject *o)``, ``Py_DecRef(PyObject *o)``. They are 68 simply exported function versions of :c func:`Py_XINCREF` and69 :c func:`Py_XDECREF`, respectively.68 simply exported function versions of :c:func:`Py_XINCREF` and 69 :c:func:`Py_XDECREF`, respectively. 70 70 71 71 The following functions or macros are only for use within the interpreter core: 72 :c func:`_Py_Dealloc`, :cfunc:`_Py_ForgetReference`, :cfunc:`_Py_NewReference`,73 as well as the global variable :c data:`_Py_RefTotal`.72 :c:func:`_Py_Dealloc`, :c:func:`_Py_ForgetReference`, :c:func:`_Py_NewReference`, 73 as well as the global variable :c:data:`_Py_RefTotal`. 74 74 -
python/vendor/current/Doc/c-api/reflection.rst
r2 r388 6 6 ========== 7 7 8 .. c function:: PyObject* PyEval_GetBuiltins()8 .. c:function:: PyObject* PyEval_GetBuiltins() 9 9 10 10 Return a dictionary of the builtins in the current execution frame, … … 12 12 13 13 14 .. c function:: PyObject* PyEval_GetLocals()14 .. c:function:: PyObject* PyEval_GetLocals() 15 15 16 16 Return a dictionary of the local variables in the current execution frame, … … 18 18 19 19 20 .. c function:: PyObject* PyEval_GetGlobals()20 .. c:function:: PyObject* PyEval_GetGlobals() 21 21 22 22 Return a dictionary of the global variables in the current execution frame, … … 24 24 25 25 26 .. c function:: PyFrameObject* PyEval_GetFrame()26 .. c:function:: PyFrameObject* PyEval_GetFrame() 27 27 28 28 Return the current thread state's frame, which is *NULL* if no frame is … … 30 30 31 31 32 .. cfunction:: int PyEval_GetRestricted() 32 .. c:function:: int PyFrame_GetLineNumber(PyFrameObject *frame) 33 34 Return the line number that *frame* is currently executing. 35 36 37 .. c:function:: int PyEval_GetRestricted() 33 38 34 39 If there is a current frame and it is executing in restricted mode, return true, … … 36 41 37 42 38 .. c function:: const char* PyEval_GetFuncName(PyObject *func)43 .. c:function:: const char* PyEval_GetFuncName(PyObject *func) 39 44 40 45 Return the name of *func* if it is a function, class or instance object, else the … … 42 47 43 48 44 .. c function:: const char* PyEval_GetFuncDesc(PyObject *func)49 .. c:function:: const char* PyEval_GetFuncDesc(PyObject *func) 45 50 46 51 Return a description string, depending on the type of *func*. 47 52 Return values include "()" for functions and methods, " constructor", 48 53 " instance", and " object". Concatenated with the result of 49 :c func:`PyEval_GetFuncName`, the result will be a description of54 :c:func:`PyEval_GetFuncName`, the result will be a description of 50 55 *func*. -
python/vendor/current/Doc/c-api/sequence.rst
r2 r388 7 7 8 8 9 .. c function:: int PySequence_Check(PyObject *o)9 .. c:function:: int PySequence_Check(PyObject *o) 10 10 11 11 Return ``1`` if the object provides sequence protocol, and ``0`` otherwise. … … 13 13 14 14 15 .. c function:: Py_ssize_t PySequence_Size(PyObject *o)15 .. c:function:: Py_ssize_t PySequence_Size(PyObject *o) 16 16 Py_ssize_t PySequence_Length(PyObject *o) 17 17 … … 23 23 24 24 .. versionchanged:: 2.5 25 These functions returned an :c type:`int` type. This might require26 changes in your code for properly supporting 64-bit systems. 27 28 29 .. c function:: PyObject* PySequence_Concat(PyObject *o1, PyObject *o2)25 These functions returned an :c:type:`int` type. This might require 26 changes in your code for properly supporting 64-bit systems. 27 28 29 .. c:function:: PyObject* PySequence_Concat(PyObject *o1, PyObject *o2) 30 30 31 31 Return the concatenation of *o1* and *o2* on success, and *NULL* on failure. … … 33 33 34 34 35 .. c function:: PyObject* PySequence_Repeat(PyObject *o, Py_ssize_t count)35 .. c:function:: PyObject* PySequence_Repeat(PyObject *o, Py_ssize_t count) 36 36 37 37 Return the result of repeating sequence object *o* *count* times, or *NULL* on … … 39 39 40 40 .. versionchanged:: 2.5 41 This function used an :c type:`int` type for *count*. This might require42 changes in your code for properly supporting 64-bit systems. 43 44 45 .. c function:: PyObject* PySequence_InPlaceConcat(PyObject *o1, PyObject *o2)41 This function used an :c:type:`int` type for *count*. This might require 42 changes in your code for properly supporting 64-bit systems. 43 44 45 .. c:function:: PyObject* PySequence_InPlaceConcat(PyObject *o1, PyObject *o2) 46 46 47 47 Return the concatenation of *o1* and *o2* on success, and *NULL* on failure. … … 50 50 51 51 52 .. c function:: PyObject* PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count)52 .. c:function:: PyObject* PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count) 53 53 54 54 Return the result of repeating sequence object *o* *count* times, or *NULL* on … … 57 57 58 58 .. versionchanged:: 2.5 59 This function used an :c type:`int` type for *count*. This might require60 changes in your code for properly supporting 64-bit systems. 61 62 63 .. c function:: PyObject* PySequence_GetItem(PyObject *o, Py_ssize_t i)59 This function used an :c:type:`int` type for *count*. This might require 60 changes in your code for properly supporting 64-bit systems. 61 62 63 .. c:function:: PyObject* PySequence_GetItem(PyObject *o, Py_ssize_t i) 64 64 65 65 Return the *i*\ th element of *o*, or *NULL* on failure. This is the equivalent of … … 67 67 68 68 .. versionchanged:: 2.5 69 This function used an :c type:`int` type for *i*. This might require70 changes in your code for properly supporting 64-bit systems. 71 72 73 .. c function:: PyObject* PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2)69 This function used an :c:type:`int` type for *i*. This might require 70 changes in your code for properly supporting 64-bit systems. 71 72 73 .. c:function:: PyObject* PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2) 74 74 75 75 Return the slice of sequence object *o* between *i1* and *i2*, or *NULL* on … … 77 77 78 78 .. versionchanged:: 2.5 79 This function used an :c type:`int` type for *i1* and *i2*. This might79 This function used an :c:type:`int` type for *i1* and *i2*. This might 80 80 require changes in your code for properly supporting 64-bit systems. 81 81 82 82 83 .. c function:: int PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v)83 .. c:function:: int PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v) 84 84 85 85 Assign object *v* to the *i*\ th element of *o*. Returns ``-1`` on failure. This … … 88 88 89 89 .. versionchanged:: 2.5 90 This function used an :c type:`int` type for *i*. This might require91 changes in your code for properly supporting 64-bit systems. 92 93 94 .. c function:: int PySequence_DelItem(PyObject *o, Py_ssize_t i)90 This function used an :c:type:`int` type for *i*. This might require 91 changes in your code for properly supporting 64-bit systems. 92 93 94 .. c:function:: int PySequence_DelItem(PyObject *o, Py_ssize_t i) 95 95 96 96 Delete the *i*\ th element of object *o*. Returns ``-1`` on failure. This is the … … 98 98 99 99 .. versionchanged:: 2.5 100 This function used an :c type:`int` type for *i*. This might require101 changes in your code for properly supporting 64-bit systems. 102 103 104 .. c function:: int PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2, PyObject *v)100 This function used an :c:type:`int` type for *i*. This might require 101 changes in your code for properly supporting 64-bit systems. 102 103 104 .. c:function:: int PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2, PyObject *v) 105 105 106 106 Assign the sequence object *v* to the slice in sequence object *o* from *i1* to … … 108 108 109 109 .. versionchanged:: 2.5 110 This function used an :c type:`int` type for *i1* and *i2*. This might110 This function used an :c:type:`int` type for *i1* and *i2*. This might 111 111 require changes in your code for properly supporting 64-bit systems. 112 112 113 113 114 .. c function:: int PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2)114 .. c:function:: int PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2) 115 115 116 116 Delete the slice in sequence object *o* from *i1* to *i2*. Returns ``-1`` on … … 118 118 119 119 .. versionchanged:: 2.5 120 This function used an :c type:`int` type for *i1* and *i2*. This might120 This function used an :c:type:`int` type for *i1* and *i2*. This might 121 121 require changes in your code for properly supporting 64-bit systems. 122 122 123 123 124 .. c function:: Py_ssize_t PySequence_Count(PyObject *o, PyObject *value)124 .. c:function:: Py_ssize_t PySequence_Count(PyObject *o, PyObject *value) 125 125 126 126 Return the number of occurrences of *value* in *o*, that is, return the number … … 129 129 130 130 .. versionchanged:: 2.5 131 This function returned an :c type:`int` type. This might require changes131 This function returned an :c:type:`int` type. This might require changes 132 132 in your code for properly supporting 64-bit systems. 133 133 134 134 135 .. c function:: int PySequence_Contains(PyObject *o, PyObject *value)135 .. c:function:: int PySequence_Contains(PyObject *o, PyObject *value) 136 136 137 137 Determine if *o* contains *value*. If an item in *o* is equal to *value*, … … 140 140 141 141 142 .. c function:: Py_ssize_t PySequence_Index(PyObject *o, PyObject *value)142 .. c:function:: Py_ssize_t PySequence_Index(PyObject *o, PyObject *value) 143 143 144 144 Return the first index *i* for which ``o[i] == value``. On error, return … … 146 146 147 147 .. versionchanged:: 2.5 148 This function returned an :c type:`int` type. This might require changes148 This function returned an :c:type:`int` type. This might require changes 149 149 in your code for properly supporting 64-bit systems. 150 150 151 151 152 .. c function:: PyObject* PySequence_List(PyObject *o)152 .. c:function:: PyObject* PySequence_List(PyObject *o) 153 153 154 154 Return a list object with the same contents as the arbitrary sequence *o*. The … … 156 156 157 157 158 .. c function:: PyObject* PySequence_Tuple(PyObject *o)158 .. c:function:: PyObject* PySequence_Tuple(PyObject *o) 159 159 160 160 .. index:: builtin: tuple … … 166 166 167 167 168 .. c function:: PyObject* PySequence_Fast(PyObject *o, const char *m)168 .. c:function:: PyObject* PySequence_Fast(PyObject *o, const char *m) 169 169 170 170 Returns the sequence *o* as a tuple, unless it is already a tuple or list, in 171 which case *o* is returned. Use :c func:`PySequence_Fast_GET_ITEM` to access the171 which case *o* is returned. Use :c:func:`PySequence_Fast_GET_ITEM` to access the 172 172 members of the result. Returns *NULL* on failure. If the object is not a 173 173 sequence, raises :exc:`TypeError` with *m* as the message text. 174 174 175 175 176 .. c function:: PyObject* PySequence_Fast_GET_ITEM(PyObject *o, Py_ssize_t i)176 .. c:function:: PyObject* PySequence_Fast_GET_ITEM(PyObject *o, Py_ssize_t i) 177 177 178 178 Return the *i*\ th element of *o*, assuming that *o* was returned by 179 :c func:`PySequence_Fast`, *o* is not *NULL*, and that *i* is within bounds.180 181 .. versionchanged:: 2.5 182 This function used an :c type:`int` type for *i*. This might require183 changes in your code for properly supporting 64-bit systems. 184 185 186 .. c function:: PyObject** PySequence_Fast_ITEMS(PyObject *o)179 :c:func:`PySequence_Fast`, *o* is not *NULL*, and that *i* is within bounds. 180 181 .. versionchanged:: 2.5 182 This function used an :c:type:`int` type for *i*. This might require 183 changes in your code for properly supporting 64-bit systems. 184 185 186 .. c:function:: PyObject** PySequence_Fast_ITEMS(PyObject *o) 187 187 188 188 Return the underlying array of PyObject pointers. Assumes that *o* was returned 189 by :c func:`PySequence_Fast` and *o* is not *NULL*.189 by :c:func:`PySequence_Fast` and *o* is not *NULL*. 190 190 191 191 Note, if a list gets resized, the reallocation may relocate the items array. … … 196 196 197 197 198 .. c function:: PyObject* PySequence_ITEM(PyObject *o, Py_ssize_t i)198 .. c:function:: PyObject* PySequence_ITEM(PyObject *o, Py_ssize_t i) 199 199 200 200 Return the *i*\ th element of *o* or *NULL* on failure. Macro form of 201 :c func:`PySequence_GetItem` but without checking that202 :c func:`PySequence_Check(o)`is true and without adjustment for negative201 :c:func:`PySequence_GetItem` but without checking that 202 :c:func:`PySequence_Check` on *o* is true and without adjustment for negative 203 203 indices. 204 204 … … 206 206 207 207 .. versionchanged:: 2.5 208 This function used an :c type:`int` type for *i*. This might require209 changes in your code for properly supporting 64-bit systems. 210 211 212 .. c function:: Py_ssize_t PySequence_Fast_GET_SIZE(PyObject *o)208 This function used an :c:type:`int` type for *i*. This might require 209 changes in your code for properly supporting 64-bit systems. 210 211 212 .. c:function:: Py_ssize_t PySequence_Fast_GET_SIZE(PyObject *o) 213 213 214 214 Returns the length of *o*, assuming that *o* was returned by 215 :c func:`PySequence_Fast` and that *o* is not *NULL*. The size can also be216 gotten by calling :c func:`PySequence_Size` on *o*, but217 :c func:`PySequence_Fast_GET_SIZE` is faster because it can assume *o* is a list215 :c:func:`PySequence_Fast` and that *o* is not *NULL*. The size can also be 216 gotten by calling :c:func:`PySequence_Size` on *o*, but 217 :c:func:`PySequence_Fast_GET_SIZE` is faster because it can assume *o* is a list 218 218 or tuple. -
python/vendor/current/Doc/c-api/set.rst
r2 r388 17 17 This section details the public API for :class:`set` and :class:`frozenset` 18 18 objects. Any functionality not listed below is best accessed using the either 19 the abstract object protocol (including :c func:`PyObject_CallMethod`,20 :c func:`PyObject_RichCompareBool`, :cfunc:`PyObject_Hash`,21 :c func:`PyObject_Repr`, :cfunc:`PyObject_IsTrue`, :cfunc:`PyObject_Print`, and22 :c func:`PyObject_GetIter`) or the abstract number protocol (including23 :c func:`PyNumber_And`, :cfunc:`PyNumber_Subtract`, :cfunc:`PyNumber_Or`,24 :c func:`PyNumber_Xor`, :cfunc:`PyNumber_InPlaceAnd`,25 :c func:`PyNumber_InPlaceSubtract`, :cfunc:`PyNumber_InPlaceOr`, and26 :c func:`PyNumber_InPlaceXor`).19 the abstract object protocol (including :c:func:`PyObject_CallMethod`, 20 :c:func:`PyObject_RichCompareBool`, :c:func:`PyObject_Hash`, 21 :c:func:`PyObject_Repr`, :c:func:`PyObject_IsTrue`, :c:func:`PyObject_Print`, and 22 :c:func:`PyObject_GetIter`) or the abstract number protocol (including 23 :c:func:`PyNumber_And`, :c:func:`PyNumber_Subtract`, :c:func:`PyNumber_Or`, 24 :c:func:`PyNumber_Xor`, :c:func:`PyNumber_InPlaceAnd`, 25 :c:func:`PyNumber_InPlaceSubtract`, :c:func:`PyNumber_InPlaceOr`, and 26 :c:func:`PyNumber_InPlaceXor`). 27 27 28 28 29 .. c type:: PySetObject29 .. c:type:: PySetObject 30 30 31 This subtype of :c type:`PyObject` is used to hold the internal data for both32 :class:`set` and :class:`frozenset` objects. It is like a :c type:`PyDictObject`31 This subtype of :c:type:`PyObject` is used to hold the internal data for both 32 :class:`set` and :class:`frozenset` objects. It is like a :c:type:`PyDictObject` 33 33 in that it is a fixed size for small sets (much like tuple storage) and will 34 34 point to a separate, variable sized block of memory for medium and large sized … … 38 38 39 39 40 .. c var:: PyTypeObject PySet_Type40 .. c:var:: PyTypeObject PySet_Type 41 41 42 This is an instance of :c type:`PyTypeObject` representing the Python42 This is an instance of :c:type:`PyTypeObject` representing the Python 43 43 :class:`set` type. 44 44 45 45 46 .. c var:: PyTypeObject PyFrozenSet_Type46 .. c:var:: PyTypeObject PyFrozenSet_Type 47 47 48 This is an instance of :c type:`PyTypeObject` representing the Python48 This is an instance of :c:type:`PyTypeObject` representing the Python 49 49 :class:`frozenset` type. 50 50 … … 53 53 54 54 55 .. c function:: int PySet_Check(PyObject *p)55 .. c:function:: int PySet_Check(PyObject *p) 56 56 57 57 Return true if *p* is a :class:`set` object or an instance of a subtype. … … 59 59 .. versionadded:: 2.6 60 60 61 .. c function:: int PyFrozenSet_Check(PyObject *p)61 .. c:function:: int PyFrozenSet_Check(PyObject *p) 62 62 63 63 Return true if *p* is a :class:`frozenset` object or an instance of a … … 66 66 .. versionadded:: 2.6 67 67 68 .. c function:: int PyAnySet_Check(PyObject *p)68 .. c:function:: int PyAnySet_Check(PyObject *p) 69 69 70 70 Return true if *p* is a :class:`set` object, a :class:`frozenset` object, or an … … 72 72 73 73 74 .. c function:: int PyAnySet_CheckExact(PyObject *p)74 .. c:function:: int PyAnySet_CheckExact(PyObject *p) 75 75 76 76 Return true if *p* is a :class:`set` object or a :class:`frozenset` object but … … 78 78 79 79 80 .. c function:: int PyFrozenSet_CheckExact(PyObject *p)80 .. c:function:: int PyFrozenSet_CheckExact(PyObject *p) 81 81 82 82 Return true if *p* is a :class:`frozenset` object but not an instance of a … … 84 84 85 85 86 .. c function:: PyObject* PySet_New(PyObject *iterable)86 .. c:function:: PyObject* PySet_New(PyObject *iterable) 87 87 88 88 Return a new :class:`set` containing objects returned by the *iterable*. The … … 93 93 94 94 95 .. c function:: PyObject* PyFrozenSet_New(PyObject *iterable)95 .. c:function:: PyObject* PyFrozenSet_New(PyObject *iterable) 96 96 97 97 Return a new :class:`frozenset` containing objects returned by the *iterable*. … … 109 109 110 110 111 .. c function:: Py_ssize_t PySet_Size(PyObject *anyset)111 .. c:function:: Py_ssize_t PySet_Size(PyObject *anyset) 112 112 113 113 .. index:: builtin: len … … 118 118 119 119 .. versionchanged:: 2.5 120 This function returned an :c type:`int`. This might require changes in120 This function returned an :c:type:`int`. This might require changes in 121 121 your code for properly supporting 64-bit systems. 122 122 123 123 124 .. c function:: Py_ssize_t PySet_GET_SIZE(PyObject *anyset)124 .. c:function:: Py_ssize_t PySet_GET_SIZE(PyObject *anyset) 125 125 126 Macro form of :c func:`PySet_Size` without error checking.126 Macro form of :c:func:`PySet_Size` without error checking. 127 127 128 128 129 .. c function:: int PySet_Contains(PyObject *anyset, PyObject *key)129 .. c:function:: int PySet_Contains(PyObject *anyset, PyObject *key) 130 130 131 131 Return 1 if found, 0 if not found, and -1 if an error is encountered. Unlike … … 136 136 137 137 138 .. c function:: int PySet_Add(PyObject *set, PyObject *key)138 .. c:function:: int PySet_Add(PyObject *set, PyObject *key) 139 139 140 140 Add *key* to a :class:`set` instance. Does not apply to :class:`frozenset` … … 146 146 .. versionchanged:: 2.6 147 147 Now works with instances of :class:`frozenset` or its subtypes. 148 Like :c func:`PyTuple_SetItem` in that it can be used to fill-in the148 Like :c:func:`PyTuple_SetItem` in that it can be used to fill-in the 149 149 values of brand new frozensets before they are exposed to other code. 150 150 … … 153 153 154 154 155 .. c function:: int PySet_Discard(PyObject *set, PyObject *key)155 .. c:function:: int PySet_Discard(PyObject *set, PyObject *key) 156 156 157 157 Return 1 if found and removed, 0 if not found (no action taken), and -1 if an 158 158 error is encountered. Does not raise :exc:`KeyError` for missing keys. Raise a 159 :exc:`TypeError` if the *key* is unhashable. Unlike the Python :meth:` discard`159 :exc:`TypeError` if the *key* is unhashable. Unlike the Python :meth:`~set.discard` 160 160 method, this function does not automatically convert unhashable sets into 161 161 temporary frozensets. Raise :exc:`PyExc_SystemError` if *set* is an not an … … 163 163 164 164 165 .. c function:: PyObject* PySet_Pop(PyObject *set)165 .. c:function:: PyObject* PySet_Pop(PyObject *set) 166 166 167 167 Return a new reference to an arbitrary object in the *set*, and removes the … … 171 171 172 172 173 .. c function:: int PySet_Clear(PyObject *set)173 .. c:function:: int PySet_Clear(PyObject *set) 174 174 175 175 Empty an existing set of all elements. -
python/vendor/current/Doc/c-api/slice.rst
r2 r388 7 7 8 8 9 .. c var:: PyTypeObject PySlice_Type9 .. c:var:: PyTypeObject PySlice_Type 10 10 11 11 .. index:: single: SliceType (in module types) … … 15 15 16 16 17 .. c function:: int PySlice_Check(PyObject *ob)17 .. c:function:: int PySlice_Check(PyObject *ob) 18 18 19 19 Return true if *ob* is a slice object; *ob* must not be *NULL*. 20 20 21 21 22 .. c function:: PyObject* PySlice_New(PyObject *start, PyObject *stop, PyObject *step)22 .. c:function:: PyObject* PySlice_New(PyObject *start, PyObject *stop, PyObject *step) 23 23 24 24 Return a new slice object with the given values. The *start*, *stop*, and … … 29 29 30 30 31 .. c function:: int PySlice_GetIndices(PySliceObject *slice, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step)31 .. c:function:: int PySlice_GetIndices(PySliceObject *slice, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step) 32 32 33 33 Retrieve the start, stop and step indices from the slice object *slice*, … … 41 41 You probably do not want to use this function. If you want to use slice 42 42 objects in versions of Python prior to 2.3, you would probably do well to 43 incorporate the source of :c func:`PySlice_GetIndicesEx`, suitably renamed,43 incorporate the source of :c:func:`PySlice_GetIndicesEx`, suitably renamed, 44 44 in the source of your extension. 45 45 46 46 .. versionchanged:: 2.5 47 This function used an :c type:`int` type for *length* and an48 :c type:`int *` type for *start*, *stop*, and *step*. This might require47 This function used an :c:type:`int` type for *length* and an 48 :c:type:`int *` type for *start*, *stop*, and *step*. This might require 49 49 changes in your code for properly supporting 64-bit systems. 50 50 51 51 52 .. c function:: int PySlice_GetIndicesEx(PySliceObject *slice, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, Py_ssize_t *slicelength)52 .. c:function:: int PySlice_GetIndicesEx(PySliceObject *slice, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, Py_ssize_t *slicelength) 53 53 54 Usable replacement for :c func:`PySlice_GetIndices`. Retrieve the start,54 Usable replacement for :c:func:`PySlice_GetIndices`. Retrieve the start, 55 55 stop, and step indices from the slice object *slice* assuming a sequence of 56 56 length *length*, and store the length of the slice in *slicelength*. Out … … 63 63 64 64 .. versionchanged:: 2.5 65 This function used an :c type:`int` type for *length* and an66 :c type:`int *` type for *start*, *stop*, *step*, and *slicelength*. This65 This function used an :c:type:`int` type for *length* and an 66 :c:type:`int *` type for *start*, *stop*, *step*, and *slicelength*. This 67 67 might require changes in your code for properly supporting 64-bit 68 68 systems. -
python/vendor/current/Doc/c-api/string.rst
r2 r388 18 18 19 19 20 .. c type:: PyStringObject21 22 This subtype of :c type:`PyObject` represents a Python string object.23 24 25 .. c var:: PyTypeObject PyString_Type20 .. c:type:: PyStringObject 21 22 This subtype of :c:type:`PyObject` represents a Python string object. 23 24 25 .. c:var:: PyTypeObject PyString_Type 26 26 27 27 .. index:: single: StringType (in module types) 28 28 29 This instance of :c type:`PyTypeObject` represents the Python string type; it is29 This instance of :c:type:`PyTypeObject` represents the Python string type; it is 30 30 the same object as ``str`` and ``types.StringType`` in the Python layer. . 31 31 32 32 33 .. c function:: int PyString_Check(PyObject *o)33 .. c:function:: int PyString_Check(PyObject *o) 34 34 35 35 Return true if the object *o* is a string object or an instance of a subtype of … … 40 40 41 41 42 .. c function:: int PyString_CheckExact(PyObject *o)42 .. c:function:: int PyString_CheckExact(PyObject *o) 43 43 44 44 Return true if the object *o* is a string object, but not an instance of a … … 48 48 49 49 50 .. c function:: PyObject* PyString_FromString(const char *v)50 .. c:function:: PyObject* PyString_FromString(const char *v) 51 51 52 52 Return a new string object with a copy of the string *v* as value on success, … … 55 55 56 56 57 .. c function:: PyObject* PyString_FromStringAndSize(const char *v, Py_ssize_t len)57 .. c:function:: PyObject* PyString_FromStringAndSize(const char *v, Py_ssize_t len) 58 58 59 59 Return a new string object with a copy of the string *v* as value and length … … 62 62 63 63 .. versionchanged:: 2.5 64 This function used an :c type:`int` type for *len*. This might require64 This function used an :c:type:`int` type for *len*. This might require 65 65 changes in your code for properly supporting 64-bit systems. 66 66 67 67 68 .. c function:: PyObject* PyString_FromFormat(const char *format, ...)69 70 Take a C :c func:`printf`\ -style *format* string and a variable number of68 .. c:function:: PyObject* PyString_FromFormat(const char *format, ...) 69 70 Take a C :c:func:`printf`\ -style *format* string and a variable number of 71 71 arguments, calculate the size of the resulting Python string and return a string 72 72 with the values formatted into it. The variable arguments must be C types and … … 79 79 .. % because not all compilers support the %z width modifier -- we fake it 80 80 .. % when necessary via interpolating PY_FORMAT_SIZE_T. 81 .. % Similar comments apply to the %ll width modifier and 82 .. % PY_FORMAT_LONG_LONG. 81 83 .. % %u, %lu, %zu should have "new in Python 2.5" blurbs. 82 84 … … 100 102 | :attr:`%lu` | unsigned long | Exactly equivalent to | 101 103 | | | ``printf("%lu")``. | 104 +-------------------+---------------+--------------------------------+ 105 | :attr:`%lld` | long long | Exactly equivalent to | 106 | | | ``printf("%lld")``. | 107 +-------------------+---------------+--------------------------------+ 108 | :attr:`%llu` | unsigned | Exactly equivalent to | 109 | | long long | ``printf("%llu")``. | 102 110 +-------------------+---------------+--------------------------------+ 103 111 | :attr:`%zd` | Py_ssize_t | Exactly equivalent to | … … 128 136 copied as-is to the result string, and any extra arguments discarded. 129 137 130 131 .. cfunction:: PyObject* PyString_FromFormatV(const char *format, va_list vargs) 132 133 Identical to :cfunc:`PyString_FromFormat` except that it takes exactly two 138 .. note:: 139 140 The `"%lld"` and `"%llu"` format specifiers are only available 141 when :const:`HAVE_LONG_LONG` is defined. 142 143 .. versionchanged:: 2.7 144 Support for `"%lld"` and `"%llu"` added. 145 146 147 .. c:function:: PyObject* PyString_FromFormatV(const char *format, va_list vargs) 148 149 Identical to :c:func:`PyString_FromFormat` except that it takes exactly two 134 150 arguments. 135 151 136 152 137 .. c function:: Py_ssize_t PyString_Size(PyObject *string)153 .. c:function:: Py_ssize_t PyString_Size(PyObject *string) 138 154 139 155 Return the length of the string in string object *string*. 140 156 141 157 .. versionchanged:: 2.5 142 This function returned an :c type:`int` type. This might require changes158 This function returned an :c:type:`int` type. This might require changes 143 159 in your code for properly supporting 64-bit systems. 144 160 145 161 146 .. c function:: Py_ssize_t PyString_GET_SIZE(PyObject *string)147 148 Macro form of :c func:`PyString_Size` but without error checking.149 150 .. versionchanged:: 2.5 151 This macro returned an :c type:`int` type. This might require changes in162 .. c:function:: Py_ssize_t PyString_GET_SIZE(PyObject *string) 163 164 Macro form of :c:func:`PyString_Size` but without error checking. 165 166 .. versionchanged:: 2.5 167 This macro returned an :c:type:`int` type. This might require changes in 152 168 your code for properly supporting 64-bit systems. 153 169 154 170 155 .. c function:: char* PyString_AsString(PyObject *string)171 .. c:function:: char* PyString_AsString(PyObject *string) 156 172 157 173 Return a NUL-terminated representation of the contents of *string*. The pointer … … 161 177 *string* is a Unicode object, this function computes the default encoding of 162 178 *string* and operates on that. If *string* is not a string object at all, 163 :c func:`PyString_AsString` returns *NULL* and raises :exc:`TypeError`.164 165 166 .. c function:: char* PyString_AS_STRING(PyObject *string)167 168 Macro form of :c func:`PyString_AsString` but without error checking. Only179 :c:func:`PyString_AsString` returns *NULL* and raises :exc:`TypeError`. 180 181 182 .. c:function:: char* PyString_AS_STRING(PyObject *string) 183 184 Macro form of :c:func:`PyString_AsString` but without error checking. Only 169 185 string objects are supported; no Unicode objects should be passed. 170 186 171 187 172 .. c function:: int PyString_AsStringAndSize(PyObject *obj, char **buffer, Py_ssize_t *length)188 .. c:function:: int PyString_AsStringAndSize(PyObject *obj, char **buffer, Py_ssize_t *length) 173 189 174 190 Return a NUL-terminated representation of the contents of the object *obj* … … 185 201 *string* is a Unicode object, this function computes the default encoding of 186 202 *string* and operates on that. If *string* is not a string object at all, 187 :c func:`PyString_AsStringAndSize` returns ``-1`` and raises :exc:`TypeError`.188 189 .. versionchanged:: 2.5 190 This function used an :c type:`int *` type for *length*. This might203 :c:func:`PyString_AsStringAndSize` returns ``-1`` and raises :exc:`TypeError`. 204 205 .. versionchanged:: 2.5 206 This function used an :c:type:`int *` type for *length*. This might 191 207 require changes in your code for properly supporting 64-bit systems. 192 208 193 209 194 .. c function:: void PyString_Concat(PyObject **string, PyObject *newpart)210 .. c:function:: void PyString_Concat(PyObject **string, PyObject *newpart) 195 211 196 212 Create a new string object in *\*string* containing the contents of *newpart* … … 201 217 202 218 203 .. c function:: void PyString_ConcatAndDel(PyObject **string, PyObject *newpart)219 .. c:function:: void PyString_ConcatAndDel(PyObject **string, PyObject *newpart) 204 220 205 221 Create a new string object in *\*string* containing the contents of *newpart* … … 207 223 208 224 209 .. c function:: int _PyString_Resize(PyObject **string, Py_ssize_t newsize)225 .. c:function:: int _PyString_Resize(PyObject **string, Py_ssize_t newsize) 210 226 211 227 A way to resize a string object even though it is "immutable". Only use this to … … 220 236 221 237 .. versionchanged:: 2.5 222 This function used an :c type:`int` type for *newsize*. This might238 This function used an :c:type:`int` type for *newsize*. This might 223 239 require changes in your code for properly supporting 64-bit systems. 224 240 225 .. c function:: PyObject* PyString_Format(PyObject *format, PyObject *args)241 .. c:function:: PyObject* PyString_Format(PyObject *format, PyObject *args) 226 242 227 243 Return a new string object from *format* and *args*. Analogous to ``format % 228 args``. The *args* argument must be a tuple .229 230 231 .. c function:: void PyString_InternInPlace(PyObject **string)244 args``. The *args* argument must be a tuple or dict. 245 246 247 .. c:function:: void PyString_InternInPlace(PyObject **string) 232 248 233 249 Intern the argument *\*string* in place. The argument must be the address of a … … 246 262 247 263 248 .. c function:: PyObject* PyString_InternFromString(const char *v)249 250 A combination of :c func:`PyString_FromString` and251 :c func:`PyString_InternInPlace`, returning either a new string object that has264 .. c:function:: PyObject* PyString_InternFromString(const char *v) 265 266 A combination of :c:func:`PyString_FromString` and 267 :c:func:`PyString_InternInPlace`, returning either a new string object that has 252 268 been interned, or a new ("owned") reference to an earlier interned string object 253 269 with the same value. … … 258 274 259 275 260 .. c function:: PyObject* PyString_Decode(const char *s, Py_ssize_t size, const char *encoding, const char *errors)276 .. c:function:: PyObject* PyString_Decode(const char *s, Py_ssize_t size, const char *encoding, const char *errors) 261 277 262 278 Create an object by decoding *size* bytes of the encoded buffer *s* using the … … 271 287 272 288 .. versionchanged:: 2.5 273 This function used an :c type:`int` type for *size*. This might require289 This function used an :c:type:`int` type for *size*. This might require 274 290 changes in your code for properly supporting 64-bit systems. 275 291 276 292 277 .. c function:: PyObject* PyString_AsDecodedObject(PyObject *str, const char *encoding, const char *errors)293 .. c:function:: PyObject* PyString_AsDecodedObject(PyObject *str, const char *encoding, const char *errors) 278 294 279 295 Decode a string object by passing it to the codec registered for *encoding* and … … 288 304 289 305 290 .. c function:: PyObject* PyString_Encode(const char *s, Py_ssize_t size, const char *encoding, const char *errors)291 292 Encode the :c type:`char` buffer of the given size by passing it to the codec306 .. c:function:: PyObject* PyString_Encode(const char *s, Py_ssize_t size, const char *encoding, const char *errors) 307 308 Encode the :c:type:`char` buffer of the given size by passing it to the codec 293 309 registered for *encoding* and return a Python object. *encoding* and *errors* 294 310 have the same meaning as the parameters of the same name in the string … … 301 317 302 318 .. versionchanged:: 2.5 303 This function used an :c type:`int` type for *size*. This might require319 This function used an :c:type:`int` type for *size*. This might require 304 320 changes in your code for properly supporting 64-bit systems. 305 321 306 322 307 .. c function:: PyObject* PyString_AsEncodedObject(PyObject *str, const char *encoding, const char *errors)323 .. c:function:: PyObject* PyString_AsEncodedObject(PyObject *str, const char *encoding, const char *errors) 308 324 309 325 Encode a string object using the codec registered for *encoding* and return the -
python/vendor/current/Doc/c-api/structures.rst
r2 r388 12 12 All Python objects ultimately share a small number of fields at the beginning 13 13 of the object's representation in memory. These are represented by the 14 :c type:`PyObject` and :ctype:`PyVarObject` types, which are defined, in turn,14 :c:type:`PyObject` and :c:type:`PyVarObject` types, which are defined, in turn, 15 15 by the expansions of some macros also used, whether directly or indirectly, in 16 16 the definition of all other Python objects. 17 17 18 18 19 .. c type:: PyObject19 .. c:type:: PyObject 20 20 21 21 All object types are extensions of this type. This is a type which … … 27 27 28 28 29 .. c type:: PyVarObject30 31 This is an extension of :c type:`PyObject` that adds the :attr:`ob_size`29 .. c:type:: PyVarObject 30 31 This is an extension of :c:type:`PyObject` that adds the :attr:`ob_size` 32 32 field. This is only used for objects that have some notion of *length*. 33 33 This type does not often appear in the Python/C API. It corresponds to the 34 34 fields defined by the expansion of the ``PyObject_VAR_HEAD`` macro. 35 35 36 These macros are used in the definition of :c type:`PyObject` and37 :c type:`PyVarObject`:38 39 40 .. c macro:: PyObject_HEAD36 These macros are used in the definition of :c:type:`PyObject` and 37 :c:type:`PyVarObject`: 38 39 40 .. c:macro:: PyObject_HEAD 41 41 42 42 This is a macro which expands to the declarations of the fields of the 43 :c type:`PyObject` type; it is used when declaring new types which represent43 :c:type:`PyObject` type; it is used when declaring new types which represent 44 44 objects without a varying length. The specific fields it expands to depend 45 on the definition of :c macro:`Py_TRACE_REFS`. By default, that macro is46 not defined, and :c macro:`PyObject_HEAD` expands to::45 on the definition of :c:macro:`Py_TRACE_REFS`. By default, that macro is 46 not defined, and :c:macro:`PyObject_HEAD` expands to:: 47 47 48 48 Py_ssize_t ob_refcnt; 49 49 PyTypeObject *ob_type; 50 50 51 When :c macro:`Py_TRACE_REFS` is defined, it expands to::51 When :c:macro:`Py_TRACE_REFS` is defined, it expands to:: 52 52 53 53 PyObject *_ob_next, *_ob_prev; … … 56 56 57 57 58 .. c macro:: PyObject_VAR_HEAD58 .. c:macro:: PyObject_VAR_HEAD 59 59 60 60 This is a macro which expands to the declarations of the fields of the 61 :c type:`PyVarObject` type; it is used when declaring new types which61 :c:type:`PyVarObject` type; it is used when declaring new types which 62 62 represent objects with a length that varies from instance to instance. 63 63 This macro always expands to:: … … 66 66 Py_ssize_t ob_size; 67 67 68 Note that :c macro:`PyObject_HEAD` is part of the expansion, and that its own69 expansion varies depending on the definition of :c macro:`Py_TRACE_REFS`.70 71 72 .. c macro:: PyObject_HEAD_INIT(type)68 Note that :c:macro:`PyObject_HEAD` is part of the expansion, and that its own 69 expansion varies depending on the definition of :c:macro:`Py_TRACE_REFS`. 70 71 72 .. c:macro:: PyObject_HEAD_INIT(type) 73 73 74 74 This is a macro which expands to initialization values for a new 75 :c type:`PyObject` type. This macro expands to::75 :c:type:`PyObject` type. This macro expands to:: 76 76 77 77 _PyObject_EXTRA_INIT … … 79 79 80 80 81 .. c macro:: PyVarObject_HEAD_INIT(type, size)81 .. c:macro:: PyVarObject_HEAD_INIT(type, size) 82 82 83 83 This is a macro which expands to initialization values for a new 84 :c type:`PyVarObject` type, including the :attr:`ob_size` field.84 :c:type:`PyVarObject` type, including the :attr:`ob_size` field. 85 85 This macro expands to:: 86 86 … … 89 89 90 90 91 .. c type:: PyCFunction91 .. c:type:: PyCFunction 92 92 93 93 Type of the functions used to implement most Python callables in C. 94 Functions of this type take two :c type:`PyObject\*` parameters and return94 Functions of this type take two :c:type:`PyObject\*` parameters and return 95 95 one such value. If the return value is *NULL*, an exception shall have 96 96 been set. If not *NULL*, the return value is interpreted as the return … … 99 99 100 100 101 .. c type:: PyMethodDef101 .. c:type:: PyMethodDef 102 102 103 103 Structure used to describe a method of an extension type. This structure has … … 120 120 121 121 The :attr:`ml_meth` is a C function pointer. The functions may be of different 122 types, but they always return :c type:`PyObject\*`. If the function is not of123 the :c type:`PyCFunction`, the compiler will require a cast in the method table.124 Even though :c type:`PyCFunction` defines the first parameter as125 :c type:`PyObject\*`, it is common that the method implementation uses a the122 types, but they always return :c:type:`PyObject\*`. If the function is not of 123 the :c:type:`PyCFunction`, the compiler will require a cast in the method table. 124 Even though :c:type:`PyCFunction` defines the first parameter as 125 :c:type:`PyObject\*`, it is common that the method implementation uses a the 126 126 specific C type of the *self* object. 127 127 … … 137 137 138 138 This is the typical calling convention, where the methods have the type 139 :ctype:`PyCFunction`. The function expects two :ctype:`PyObject\*` values. 140 The first one is the *self* object for methods; for module functions, it 141 has the value given to :cfunc:`Py_InitModule4` (or *NULL* if 142 :cfunc:`Py_InitModule` was used). The second parameter (often called 143 *args*) is a tuple object representing all arguments. This parameter is 144 typically processed using :cfunc:`PyArg_ParseTuple` or 145 :cfunc:`PyArg_UnpackTuple`. 139 :c:type:`PyCFunction`. The function expects two :c:type:`PyObject\*` values. 140 The first one is the *self* object for methods; for module functions, it is 141 the module object. The second parameter (often called *args*) is a tuple 142 object representing all arguments. This parameter is typically processed 143 using :c:func:`PyArg_ParseTuple` or :c:func:`PyArg_UnpackTuple`. 146 144 147 145 148 146 .. data:: METH_KEYWORDS 149 147 150 Methods with these flags must be of type :c type:`PyCFunctionWithKeywords`.148 Methods with these flags must be of type :c:type:`PyCFunctionWithKeywords`. 151 149 The function expects three parameters: *self*, *args*, and a dictionary of 152 150 all the keyword arguments. The flag is typically combined with 153 151 :const:`METH_VARARGS`, and the parameters are typically processed using 154 :c func:`PyArg_ParseTupleAndKeywords`.152 :c:func:`PyArg_ParseTupleAndKeywords`. 155 153 156 154 … … 159 157 Methods without parameters don't need to check whether arguments are given if 160 158 they are listed with the :const:`METH_NOARGS` flag. They need to be of type 161 :c type:`PyCFunction`. When used with object methods, the first parameter is162 typically named ``self`` and will hold a reference to the object instance.163 In all cases thesecond parameter will be *NULL*.159 :c:type:`PyCFunction`. The first parameter is typically named ``self`` and 160 will hold a reference to the module or object instance. In all cases the 161 second parameter will be *NULL*. 164 162 165 163 … … 167 165 168 166 Methods with a single object argument can be listed with the :const:`METH_O` 169 flag, instead of invoking :c func:`PyArg_ParseTuple` with a ``"O"`` argument.170 They have the type :c type:`PyCFunction`, with the *self* parameter, and a171 :c type:`PyObject\*` parameter representing the single argument.167 flag, instead of invoking :c:func:`PyArg_ParseTuple` with a ``"O"`` argument. 168 They have the type :c:type:`PyCFunction`, with the *self* parameter, and a 169 :c:type:`PyObject\*` parameter representing the single argument. 172 170 173 171 … … 175 173 176 174 This calling convention is deprecated. The method must be of type 177 :c type:`PyCFunction`. The second argument is *NULL* if no arguments are175 :c:type:`PyCFunction`. The second argument is *NULL* if no arguments are 178 176 given, a single object if exactly one argument is given, and a tuple of 179 177 objects if more than one argument is given. There is no way for a function … … 228 226 229 227 230 .. c type:: PyMemberDef228 .. c:type:: PyMemberDef 231 229 232 230 Structure which describes an attribute of a type which corresponds to a C … … 280 278 =============== ================== 281 279 282 :c macro:`T_OBJECT` and :cmacro:`T_OBJECT_EX` differ in that283 :c macro:`T_OBJECT` returns ``None`` if the member is *NULL* and284 :c macro:`T_OBJECT_EX` raises an :exc:`AttributeError`. Try to use285 :c macro:`T_OBJECT_EX` over :cmacro:`T_OBJECT` because :cmacro:`T_OBJECT_EX`280 :c:macro:`T_OBJECT` and :c:macro:`T_OBJECT_EX` differ in that 281 :c:macro:`T_OBJECT` returns ``None`` if the member is *NULL* and 282 :c:macro:`T_OBJECT_EX` raises an :exc:`AttributeError`. Try to use 283 :c:macro:`T_OBJECT_EX` over :c:macro:`T_OBJECT` because :c:macro:`T_OBJECT_EX` 286 284 handles use of the :keyword:`del` statement on that attribute more correctly 287 than :c macro:`T_OBJECT`.288 289 :attr:`flags` can be 0 for write and read access or :c macro:`READONLY` for290 read-only access. Using :c macro:`T_STRING` for :attr:`type` implies291 :c macro:`READONLY`. Only :cmacro:`T_OBJECT` and :cmacro:`T_OBJECT_EX`285 than :c:macro:`T_OBJECT`. 286 287 :attr:`flags` can be 0 for write and read access or :c:macro:`READONLY` for 288 read-only access. Using :c:macro:`T_STRING` for :attr:`type` implies 289 :c:macro:`READONLY`. Only :c:macro:`T_OBJECT` and :c:macro:`T_OBJECT_EX` 292 290 members can be deleted. (They are set to *NULL*). 293 291 294 292 295 .. c function:: PyObject* Py_FindMethod(PyMethodDef table[], PyObject *ob, char *name)293 .. c:function:: PyObject* Py_FindMethod(PyMethodDef table[], PyObject *ob, char *name) 296 294 297 295 Return a bound method object for an extension type implemented in C. This 298 can be useful in the implementation of a : attr:`tp_getattro` or299 : attr:`tp_getattr` handler that does not use the300 :c func:`PyObject_GenericGetAttr` function.296 can be useful in the implementation of a :c:member:`~PyTypeObject.tp_getattro` or 297 :c:member:`~PyTypeObject.tp_getattr` handler that does not use the 298 :c:func:`PyObject_GenericGetAttr` function. -
python/vendor/current/Doc/c-api/sys.rst
r2 r388 7 7 8 8 9 .. c function:: int Py_FdIsInteractive(FILE *fp, const char *filename)9 .. c:function:: int Py_FdIsInteractive(FILE *fp, const char *filename) 10 10 11 11 Return true (nonzero) if the standard I/O file *fp* with name *filename* is 12 12 deemed interactive. This is the case for files for which ``isatty(fileno(fp))`` 13 is true. If the global flag :c data:`Py_InteractiveFlag` is true, this function13 is true. If the global flag :c:data:`Py_InteractiveFlag` is true, this function 14 14 also returns true if the *filename* pointer is *NULL* or if the name is equal to 15 15 one of the strings ``'<stdin>'`` or ``'???'``. 16 16 17 17 18 .. cfunction:: long PyOS_GetLastModificationTime(char *filename) 19 20 Return the time of last modification of the file *filename*. The result is 21 encoded in the same way as the timestamp returned by the standard C library 22 function :cfunc:`time`. 23 24 25 .. cfunction:: void PyOS_AfterFork() 18 .. c:function:: void PyOS_AfterFork() 26 19 27 20 Function to update some internal state after a process fork; this should be … … 31 24 32 25 33 .. c function:: int PyOS_CheckStack()26 .. c:function:: int PyOS_CheckStack() 34 27 35 28 Return true when the interpreter runs out of stack space. This is a reliable … … 40 33 41 34 42 .. c function:: PyOS_sighandler_t PyOS_getsig(int i)35 .. c:function:: PyOS_sighandler_t PyOS_getsig(int i) 43 36 44 37 Return the current signal handler for signal *i*. This is a thin wrapper around 45 either :c func:`sigaction` or :cfunc:`signal`. Do not call those functions46 directly! :c type:`PyOS_sighandler_t` is a typedef alias for :ctype:`void38 either :c:func:`sigaction` or :c:func:`signal`. Do not call those functions 39 directly! :c:type:`PyOS_sighandler_t` is a typedef alias for :c:type:`void 47 40 (\*)(int)`. 48 41 49 42 50 .. c function:: PyOS_sighandler_t PyOS_setsig(int i, PyOS_sighandler_t h)43 .. c:function:: PyOS_sighandler_t PyOS_setsig(int i, PyOS_sighandler_t h) 51 44 52 45 Set the signal handler for signal *i* to be *h*; return the old signal handler. 53 This is a thin wrapper around either :c func:`sigaction` or :cfunc:`signal`. Do54 not call those functions directly! :c type:`PyOS_sighandler_t` is a typedef55 alias for :c type:`void (\*)(int)`.46 This is a thin wrapper around either :c:func:`sigaction` or :c:func:`signal`. Do 47 not call those functions directly! :c:type:`PyOS_sighandler_t` is a typedef 48 alias for :c:type:`void (\*)(int)`. 56 49 57 50 .. _systemfunctions: … … 64 57 :mod:`sys` module's dict, which is contained in the internal thread state structure. 65 58 66 .. c function:: PyObject *PySys_GetObject(char *name)59 .. c:function:: PyObject *PySys_GetObject(char *name) 67 60 68 61 Return the object *name* from the :mod:`sys` module or *NULL* if it does 69 62 not exist, without setting an exception. 70 63 71 .. c function:: FILE *PySys_GetFile(char *name, FILE *def)64 .. c:function:: FILE *PySys_GetFile(char *name, FILE *def) 72 65 73 Return the :c type:`FILE*` associated with the object *name* in the66 Return the :c:type:`FILE*` associated with the object *name* in the 74 67 :mod:`sys` module, or *def* if *name* is not in the module or is not associated 75 with a :c type:`FILE*`.68 with a :c:type:`FILE*`. 76 69 77 .. c function:: int PySys_SetObject(char *name, PyObject *v)70 .. c:function:: int PySys_SetObject(char *name, PyObject *v) 78 71 79 72 Set *name* in the :mod:`sys` module to *v* unless *v* is *NULL*, in which … … 81 74 on error. 82 75 83 .. c function:: void PySys_ResetWarnOptions()76 .. c:function:: void PySys_ResetWarnOptions() 84 77 85 78 Reset :data:`sys.warnoptions` to an empty list. 86 79 87 .. c function:: void PySys_AddWarnOption(char *s)80 .. c:function:: void PySys_AddWarnOption(char *s) 88 81 89 82 Append *s* to :data:`sys.warnoptions`. 90 83 91 .. c function:: void PySys_SetPath(char *path)84 .. c:function:: void PySys_SetPath(char *path) 92 85 93 86 Set :data:`sys.path` to a list object of paths found in *path* which should … … 95 88 (``:`` on Unix, ``;`` on Windows). 96 89 97 .. c function:: void PySys_WriteStdout(const char *format, ...)90 .. c:function:: void PySys_WriteStdout(const char *format, ...) 98 91 99 92 Write the output string described by *format* to :data:`sys.stdout`. No … … 111 104 is written to the real (C level) *stdout*. 112 105 113 .. c function:: void PySys_WriteStderr(const char *format, ...)106 .. c:function:: void PySys_WriteStderr(const char *format, ...) 114 107 115 108 As above, but write to :data:`sys.stderr` or *stderr* instead. … … 122 115 123 116 124 .. c function:: void Py_FatalError(const char *message)117 .. c:function:: void Py_FatalError(const char *message) 125 118 126 119 .. index:: single: abort() … … 130 123 make it dangerous to continue using the Python interpreter; e.g., when the 131 124 object administration appears to be corrupted. On Unix, the standard C library 132 function :c func:`abort` is called which will attempt to produce a :file:`core`125 function :c:func:`abort` is called which will attempt to produce a :file:`core` 133 126 file. 134 127 135 128 136 .. c function:: void Py_Exit(int status)129 .. c:function:: void Py_Exit(int status) 137 130 138 131 .. index:: … … 140 133 single: exit() 141 134 142 Exit the current process. This calls :c func:`Py_Finalize` and then calls the135 Exit the current process. This calls :c:func:`Py_Finalize` and then calls the 143 136 standard C library function ``exit(status)``. 144 137 145 138 146 .. c function:: int Py_AtExit(void (*func) ())139 .. c:function:: int Py_AtExit(void (*func) ()) 147 140 148 141 .. index:: … … 150 143 single: cleanup functions 151 144 152 Register a cleanup function to be called by :c func:`Py_Finalize`. The cleanup145 Register a cleanup function to be called by :c:func:`Py_Finalize`. The cleanup 153 146 function will be called with no arguments and should return no value. At most 154 147 32 cleanup functions can be registered. When the registration is successful, 155 :c func:`Py_AtExit` returns ``0``; on failure, it returns ``-1``. The cleanup148 :c:func:`Py_AtExit` returns ``0``; on failure, it returns ``-1``. The cleanup 156 149 function registered last is called first. Each cleanup function will be called 157 150 at most once. Since Python's internal finalization will have completed before -
python/vendor/current/Doc/c-api/tuple.rst
r2 r388 9 9 10 10 11 .. c type:: PyTupleObject11 .. c:type:: PyTupleObject 12 12 13 This subtype of :c type:`PyObject` represents a Python tuple object.13 This subtype of :c:type:`PyObject` represents a Python tuple object. 14 14 15 15 16 .. c var:: PyTypeObject PyTuple_Type16 .. c:var:: PyTypeObject PyTuple_Type 17 17 18 18 .. index:: single: TupleType (in module types) 19 19 20 This instance of :c type:`PyTypeObject` represents the Python tuple type; it is20 This instance of :c:type:`PyTypeObject` represents the Python tuple type; it is 21 21 the same object as ``tuple`` and ``types.TupleType`` in the Python layer.. 22 22 23 23 24 .. c function:: int PyTuple_Check(PyObject *p)24 .. c:function:: int PyTuple_Check(PyObject *p) 25 25 26 26 Return true if *p* is a tuple object or an instance of a subtype of the tuple … … 31 31 32 32 33 .. c function:: int PyTuple_CheckExact(PyObject *p)33 .. c:function:: int PyTuple_CheckExact(PyObject *p) 34 34 35 35 Return true if *p* is a tuple object, but not an instance of a subtype of the … … 39 39 40 40 41 .. c function:: PyObject* PyTuple_New(Py_ssize_t len)41 .. c:function:: PyObject* PyTuple_New(Py_ssize_t len) 42 42 43 43 Return a new tuple object of size *len*, or *NULL* on failure. 44 44 45 45 .. versionchanged:: 2.5 46 This function used an :c type:`int` type for *len*. This might require46 This function used an :c:type:`int` type for *len*. This might require 47 47 changes in your code for properly supporting 64-bit systems. 48 48 49 49 50 .. c function:: PyObject* PyTuple_Pack(Py_ssize_t n, ...)50 .. c:function:: PyObject* PyTuple_Pack(Py_ssize_t n, ...) 51 51 52 52 Return a new tuple object of size *n*, or *NULL* on failure. The tuple values … … 57 57 58 58 .. versionchanged:: 2.5 59 This function used an :c type:`int` type for *n*. This might require59 This function used an :c:type:`int` type for *n*. This might require 60 60 changes in your code for properly supporting 64-bit systems. 61 61 62 62 63 .. c function:: Py_ssize_t PyTuple_Size(PyObject *p)63 .. c:function:: Py_ssize_t PyTuple_Size(PyObject *p) 64 64 65 65 Take a pointer to a tuple object, and return the size of that tuple. 66 66 67 67 .. versionchanged:: 2.5 68 This function returned an :c type:`int` type. This might require changes68 This function returned an :c:type:`int` type. This might require changes 69 69 in your code for properly supporting 64-bit systems. 70 70 71 71 72 .. c function:: Py_ssize_t PyTuple_GET_SIZE(PyObject *p)72 .. c:function:: Py_ssize_t PyTuple_GET_SIZE(PyObject *p) 73 73 74 74 Return the size of the tuple *p*, which must be non-*NULL* and point to a tuple; … … 76 76 77 77 .. versionchanged:: 2.5 78 This function returned an :c type:`int` type. This might require changes78 This function returned an :c:type:`int` type. This might require changes 79 79 in your code for properly supporting 64-bit systems. 80 80 81 81 82 .. c function:: PyObject* PyTuple_GetItem(PyObject *p, Py_ssize_t pos)82 .. c:function:: PyObject* PyTuple_GetItem(PyObject *p, Py_ssize_t pos) 83 83 84 84 Return the object at position *pos* in the tuple pointed to by *p*. If *pos* is … … 86 86 87 87 .. versionchanged:: 2.5 88 This function used an :c type:`int` type for *pos*. This might require88 This function used an :c:type:`int` type for *pos*. This might require 89 89 changes in your code for properly supporting 64-bit systems. 90 90 91 91 92 .. c function:: PyObject* PyTuple_GET_ITEM(PyObject *p, Py_ssize_t pos)92 .. c:function:: PyObject* PyTuple_GET_ITEM(PyObject *p, Py_ssize_t pos) 93 93 94 Like :c func:`PyTuple_GetItem`, but does no checking of its arguments.94 Like :c:func:`PyTuple_GetItem`, but does no checking of its arguments. 95 95 96 96 .. versionchanged:: 2.5 97 This function used an :c type:`int` type for *pos*. This might require97 This function used an :c:type:`int` type for *pos*. This might require 98 98 changes in your code for properly supporting 64-bit systems. 99 99 100 100 101 .. c function:: PyObject* PyTuple_GetSlice(PyObject *p, Py_ssize_t low, Py_ssize_t high)101 .. c:function:: PyObject* PyTuple_GetSlice(PyObject *p, Py_ssize_t low, Py_ssize_t high) 102 102 103 103 Take a slice of the tuple pointed to by *p* from *low* to *high* and return it … … 105 105 106 106 .. versionchanged:: 2.5 107 This function used an :c type:`int` type for *low* and *high*. This might107 This function used an :c:type:`int` type for *low* and *high*. This might 108 108 require changes in your code for properly supporting 64-bit systems. 109 109 110 110 111 .. c function:: int PyTuple_SetItem(PyObject *p, Py_ssize_t pos, PyObject *o)111 .. c:function:: int PyTuple_SetItem(PyObject *p, Py_ssize_t pos, PyObject *o) 112 112 113 113 Insert a reference to object *o* at position *pos* of the tuple pointed to by … … 119 119 120 120 .. versionchanged:: 2.5 121 This function used an :c type:`int` type for *pos*. This might require121 This function used an :c:type:`int` type for *pos*. This might require 122 122 changes in your code for properly supporting 64-bit systems. 123 123 124 124 125 .. c function:: void PyTuple_SET_ITEM(PyObject *p, Py_ssize_t pos, PyObject *o)125 .. c:function:: void PyTuple_SET_ITEM(PyObject *p, Py_ssize_t pos, PyObject *o) 126 126 127 Like :c func:`PyTuple_SetItem`, but does no error checking, and should *only* be127 Like :c:func:`PyTuple_SetItem`, but does no error checking, and should *only* be 128 128 used to fill in brand new tuples. 129 129 … … 133 133 134 134 .. versionchanged:: 2.5 135 This function used an :c type:`int` type for *pos*. This might require135 This function used an :c:type:`int` type for *pos*. This might require 136 136 changes in your code for properly supporting 64-bit systems. 137 137 138 138 139 .. c function:: int _PyTuple_Resize(PyObject **p, Py_ssize_t newsize)139 .. c:function:: int _PyTuple_Resize(PyObject **p, Py_ssize_t newsize) 140 140 141 141 Can be used to resize a tuple. *newsize* will be the new length of the tuple. … … 154 154 155 155 .. versionchanged:: 2.5 156 This function used an :c type:`int` type for *newsize*. This might156 This function used an :c:type:`int` type for *newsize*. This might 157 157 require changes in your code for properly supporting 64-bit systems. 158 158 159 159 160 .. c function:: int PyTuple_ClearFreeList()160 .. c:function:: int PyTuple_ClearFreeList() 161 161 162 162 Clear the free list. Return the total number of freed items. -
python/vendor/current/Doc/c-api/type.rst
r2 r388 9 9 10 10 11 .. c type:: PyTypeObject11 .. c:type:: PyTypeObject 12 12 13 13 The C structure of the objects used to describe built-in types. 14 14 15 15 16 .. c var:: PyObject* PyType_Type16 .. c:var:: PyObject* PyType_Type 17 17 18 18 .. index:: single: TypeType (in module types) … … 22 22 23 23 24 .. c function:: int PyType_Check(PyObject *o)24 .. c:function:: int PyType_Check(PyObject *o) 25 25 26 26 Return true if the object *o* is a type object, including instances of types … … 28 28 29 29 30 .. c function:: int PyType_CheckExact(PyObject *o)30 .. c:function:: int PyType_CheckExact(PyObject *o) 31 31 32 32 Return true if the object *o* is a type object, but not a subtype of the … … 36 36 37 37 38 .. c function:: unsigned int PyType_ClearCache()38 .. c:function:: unsigned int PyType_ClearCache() 39 39 40 40 Clear the internal lookup cache. Return the current version tag. … … 43 43 44 44 45 .. c function:: void PyType_Modified(PyTypeObject *type)45 .. c:function:: void PyType_Modified(PyTypeObject *type) 46 46 47 47 Invalidate the internal lookup cache for the type and all of its … … 52 52 53 53 54 .. c function:: int PyType_HasFeature(PyObject *o, int feature)54 .. c:function:: int PyType_HasFeature(PyObject *o, int feature) 55 55 56 56 Return true if the type object *o* sets the feature *feature*. Type features … … 58 58 59 59 60 .. c function:: int PyType_IS_GC(PyObject *o)60 .. c:function:: int PyType_IS_GC(PyObject *o) 61 61 62 62 Return true if the type object includes support for the cycle detector; this … … 66 66 67 67 68 .. c function:: int PyType_IsSubtype(PyTypeObject *a, PyTypeObject *b)68 .. c:function:: int PyType_IsSubtype(PyTypeObject *a, PyTypeObject *b) 69 69 70 70 Return true if *a* is a subtype of *b*. … … 73 73 74 74 75 .. c function:: PyObject* PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)75 .. c:function:: PyObject* PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems) 76 76 77 77 .. versionadded:: 2.2 78 78 79 79 .. versionchanged:: 2.5 80 This function used an :c type:`int` type for *nitems*. This might require80 This function used an :c:type:`int` type for *nitems*. This might require 81 81 changes in your code for properly supporting 64-bit systems. 82 82 83 83 84 .. c function:: PyObject* PyType_GenericNew(PyTypeObject *type, PyObject *args, PyObject *kwds)84 .. c:function:: PyObject* PyType_GenericNew(PyTypeObject *type, PyObject *args, PyObject *kwds) 85 85 86 86 .. versionadded:: 2.2 87 87 88 88 89 .. c function:: int PyType_Ready(PyTypeObject *type)89 .. c:function:: int PyType_Ready(PyTypeObject *type) 90 90 91 91 Finalize a type object. This should be called on all type objects to finish -
python/vendor/current/Doc/c-api/typeobj.rst
r2 r388 7 7 8 8 Perhaps one of the most important structures of the Python object system is the 9 structure that defines a new type: the :c type:`PyTypeObject` structure. Type10 objects can be handled using any of the :c func:`PyObject_\*` or11 :c func:`PyType_\*` functions, but do not offer much that's interesting to most9 structure that defines a new type: the :c:type:`PyTypeObject` structure. Type 10 objects can be handled using any of the :c:func:`PyObject_\*` or 11 :c:func:`PyType_\*` functions, but do not offer much that's interesting to most 12 12 Python applications. These objects are fundamental to how objects behave, so 13 13 they are very important to the interpreter itself and to any extension module … … 26 26 cmpfunc, reprfunc, hashfunc 27 27 28 The structure definition for :c type:`PyTypeObject` can be found in28 The structure definition for :c:type:`PyTypeObject` can be found in 29 29 :file:`Include/object.h`. For convenience of reference, this repeats the 30 30 definition found there: … … 33 33 34 34 35 The type object structure extends the :c type:`PyVarObject` structure. The35 The type object structure extends the :c:type:`PyVarObject` structure. The 36 36 :attr:`ob_size` field is used for dynamic types (created by :func:`type_new`, 37 usually called from a class statement). Note that :c data:`PyType_Type` (the38 metatype) initializes : attr:`tp_itemsize`, which means that its instances (i.e.37 usually called from a class statement). Note that :c:data:`PyType_Type` (the 38 metatype) initializes :c:member:`~PyTypeObject.tp_itemsize`, which means that its instances (i.e. 39 39 type objects) *must* have the :attr:`ob_size` field. 40 40 41 41 42 .. c member:: PyObject* PyObject._ob_next42 .. c:member:: PyObject* PyObject._ob_next 43 43 PyObject* PyObject._ob_prev 44 44 … … 55 55 56 56 57 .. c member:: Py_ssize_t PyObject.ob_refcnt57 .. c:member:: Py_ssize_t PyObject.ob_refcnt 58 58 59 59 This is the type object's reference count, initialized to ``1`` by the … … 66 66 67 67 .. versionchanged:: 2.5 68 This field used to be an :c type:`int` type. This might require changes68 This field used to be an :c:type:`int` type. This might require changes 69 69 in your code for properly supporting 64-bit systems. 70 70 71 71 72 .. c member:: PyTypeObject* PyObject.ob_type72 .. c:member:: PyTypeObject* PyObject.ob_type 73 73 74 74 This is the type's type, in other words its metatype. It is initialized by the … … 84 84 85 85 This should be done before any instances of the type are created. 86 :c func:`PyType_Ready` checks if :attr:`ob_type` is *NULL*, and if so,86 :c:func:`PyType_Ready` checks if :attr:`ob_type` is *NULL*, and if so, 87 87 initializes it: in Python 2.2, it is set to ``&PyType_Type``; in Python 2.2.1 88 88 and later it is initialized to the :attr:`ob_type` field of the base class. 89 :c func:`PyType_Ready` will not change this field if it is non-zero.89 :c:func:`PyType_Ready` will not change this field if it is non-zero. 90 90 91 91 In Python 2.2, this field is not inherited by subtypes. In 2.2.1, and in 2.3 … … 93 93 94 94 95 .. c member:: Py_ssize_t PyVarObject.ob_size95 .. c:member:: Py_ssize_t PyVarObject.ob_size 96 96 97 97 For statically allocated type objects, this should be initialized to zero. For … … 101 101 102 102 103 .. c member:: char* PyTypeObject.tp_name103 .. c:member:: char* PyTypeObject.tp_name 104 104 105 105 Pointer to a NUL-terminated string containing the name of the type. For types … … 109 109 full package name is part of the full module name. For example, a type named 110 110 :class:`T` defined in module :mod:`M` in subpackage :mod:`Q` in package :mod:`P` 111 should have the : attr:`tp_name` initializer ``"P.Q.M.T"``.111 should have the :c:member:`~PyTypeObject.tp_name` initializer ``"P.Q.M.T"``. 112 112 113 113 For dynamically allocated type objects, this should just be the type name, and … … 120 120 :attr:`__name__` attribute. 121 121 122 If no dot is present, the entire : attr:`tp_name` field is made accessible as the122 If no dot is present, the entire :c:member:`~PyTypeObject.tp_name` field is made accessible as the 123 123 :attr:`__name__` attribute, and the :attr:`__module__` attribute is undefined 124 124 (unless explicitly set in the dictionary, as explained above). This means your … … 128 128 129 129 130 .. c member:: Py_ssize_t PyTypeObject.tp_basicsize130 .. c:member:: Py_ssize_t PyTypeObject.tp_basicsize 131 131 Py_ssize_t PyTypeObject.tp_itemsize 132 132 … … 134 134 135 135 There are two kinds of types: types with fixed-length instances have a zero 136 : attr:`tp_itemsize` field, types with variable-length instances have a non-zero137 : attr:`tp_itemsize` field. For a type with fixed-length instances, all138 instances have the same size, given in : attr:`tp_basicsize`.136 :c:member:`~PyTypeObject.tp_itemsize` field, types with variable-length instances have a non-zero 137 :c:member:`~PyTypeObject.tp_itemsize` field. For a type with fixed-length instances, all 138 instances have the same size, given in :c:member:`~PyTypeObject.tp_basicsize`. 139 139 140 140 For a type with variable-length instances, the instances must have an 141 :attr:`ob_size` field, and the instance size is : attr:`tp_basicsize` plus N142 times : attr:`tp_itemsize`, where N is the "length" of the object. The value of141 :attr:`ob_size` field, and the instance size is :c:member:`~PyTypeObject.tp_basicsize` plus N 142 times :c:member:`~PyTypeObject.tp_itemsize`, where N is the "length" of the object. The value of 143 143 N is typically stored in the instance's :attr:`ob_size` field. There are 144 144 exceptions: for example, long ints use a negative :attr:`ob_size` to indicate a … … 150 150 151 151 The basic size includes the fields in the instance declared by the macro 152 :c macro:`PyObject_HEAD` or :cmacro:`PyObject_VAR_HEAD` (whichever is used to152 :c:macro:`PyObject_HEAD` or :c:macro:`PyObject_VAR_HEAD` (whichever is used to 153 153 declare the instance struct) and this in turn includes the :attr:`_ob_prev` and 154 154 :attr:`_ob_next` fields if they are present. This means that the only correct 155 way to get an initializer for the : attr:`tp_basicsize` is to use the155 way to get an initializer for the :c:member:`~PyTypeObject.tp_basicsize` is to use the 156 156 ``sizeof`` operator on the struct used to declare the instance layout. 157 157 The basic size does not include the GC header size (this is new in Python 2.2; 158 in 2.1 and 2.0, the GC header size was included in : attr:`tp_basicsize`).158 in 2.1 and 2.0, the GC header size was included in :c:member:`~PyTypeObject.tp_basicsize`). 159 159 160 160 These fields are inherited separately by subtypes. If the base type has a 161 non-zero : attr:`tp_itemsize`, it is generally not safe to set162 : attr:`tp_itemsize` to a different non-zero value in a subtype (though this161 non-zero :c:member:`~PyTypeObject.tp_itemsize`, it is generally not safe to set 162 :c:member:`~PyTypeObject.tp_itemsize` to a different non-zero value in a subtype (though this 163 163 depends on the implementation of the base type). 164 164 165 165 A note about alignment: if the variable items require a particular alignment, 166 this should be taken care of by the value of : attr:`tp_basicsize`. Example:167 suppose a type implements an array of ``double``. : attr:`tp_itemsize` is166 this should be taken care of by the value of :c:member:`~PyTypeObject.tp_basicsize`. Example: 167 suppose a type implements an array of ``double``. :c:member:`~PyTypeObject.tp_itemsize` is 168 168 ``sizeof(double)``. It is the programmer's responsibility that 169 : attr:`tp_basicsize` is a multiple of ``sizeof(double)`` (assuming this is the169 :c:member:`~PyTypeObject.tp_basicsize` is a multiple of ``sizeof(double)`` (assuming this is the 170 170 alignment requirement for ``double``). 171 171 172 172 173 .. c member:: destructor PyTypeObject.tp_dealloc173 .. c:member:: destructor PyTypeObject.tp_dealloc 174 174 175 175 A pointer to the instance destructor function. This function must be defined … … 177 177 the case for the singletons ``None`` and ``Ellipsis``). 178 178 179 The destructor function is called by the :c func:`Py_DECREF` and180 :c func:`Py_XDECREF` macros when the new reference count is zero. At this point,179 The destructor function is called by the :c:func:`Py_DECREF` and 180 :c:func:`Py_XDECREF` macros when the new reference count is zero. At this point, 181 181 the instance is still in existence, but there are no references to it. The 182 182 destructor function should free all references which the instance owns, free all 183 183 memory buffers owned by the instance (using the freeing function corresponding 184 184 to the allocation function used to allocate the buffer), and finally (as its 185 last action) call the type's : attr:`tp_free` function. If the type is not185 last action) call the type's :c:member:`~PyTypeObject.tp_free` function. If the type is not 186 186 subtypable (doesn't have the :const:`Py_TPFLAGS_BASETYPE` flag bit set), it is 187 187 permissible to call the object deallocator directly instead of via 188 : attr:`tp_free`. The object deallocator should be the one used to allocate the189 instance; this is normally :c func:`PyObject_Del` if the instance was allocated190 using :c func:`PyObject_New` or :cfunc:`PyObject_VarNew`, or191 :c func:`PyObject_GC_Del` if the instance was allocated using192 :c func:`PyObject_GC_New` or :cfunc:`PyObject_GC_VarNew`.188 :c:member:`~PyTypeObject.tp_free`. The object deallocator should be the one used to allocate the 189 instance; this is normally :c:func:`PyObject_Del` if the instance was allocated 190 using :c:func:`PyObject_New` or :c:func:`PyObject_VarNew`, or 191 :c:func:`PyObject_GC_Del` if the instance was allocated using 192 :c:func:`PyObject_GC_New` or :c:func:`PyObject_GC_NewVar`. 193 193 194 194 This field is inherited by subtypes. 195 195 196 196 197 .. c member:: printfunc PyTypeObject.tp_print197 .. c:member:: printfunc PyTypeObject.tp_print 198 198 199 199 An optional pointer to the instance print function. 200 200 201 201 The print function is only called when the instance is printed to a *real* file; 202 when it is printed to a pseudo-file (like a :class:` StringIO` instance), the203 instance's : attr:`tp_repr` or :attr:`tp_str` function is called to convert it to204 a string. These are also called when the type's : attr:`tp_print` field is205 *NULL*. A type should never implement : attr:`tp_print` in a way that produces206 different output than : attr:`tp_repr` or :attr:`tp_str` would.207 208 The print function is called with the same signature as :c func:`PyObject_Print`:202 when it is printed to a pseudo-file (like a :class:`~StringIO.StringIO` instance), the 203 instance's :c:member:`~PyTypeObject.tp_repr` or :c:member:`~PyTypeObject.tp_str` function is called to convert it to 204 a string. These are also called when the type's :c:member:`~PyTypeObject.tp_print` field is 205 *NULL*. A type should never implement :c:member:`~PyTypeObject.tp_print` in a way that produces 206 different output than :c:member:`~PyTypeObject.tp_repr` or :c:member:`~PyTypeObject.tp_str` would. 207 208 The print function is called with the same signature as :c:func:`PyObject_Print`: 209 209 ``int tp_print(PyObject *self, FILE *file, int flags)``. The *self* argument is 210 210 the instance to be printed. The *file* argument is the stdio file to which it 211 211 is to be printed. The *flags* argument is composed of flag bits. The only flag 212 212 bit currently defined is :const:`Py_PRINT_RAW`. When the :const:`Py_PRINT_RAW` 213 flag bit is set, the instance should be printed the same way as : attr:`tp_str`213 flag bit is set, the instance should be printed the same way as :c:member:`~PyTypeObject.tp_str` 214 214 would format it; when the :const:`Py_PRINT_RAW` flag bit is clear, the instance 215 should be printed the same was as : attr:`tp_repr` would format it. It should215 should be printed the same was as :c:member:`~PyTypeObject.tp_repr` would format it. It should 216 216 return ``-1`` and set an exception condition when an error occurred during the 217 217 comparison. 218 218 219 It is possible that the : attr:`tp_print` field will be deprecated. In any case,220 it is recommended not to define : attr:`tp_print`, but instead to rely on221 : attr:`tp_repr` and :attr:`tp_str` for printing.219 It is possible that the :c:member:`~PyTypeObject.tp_print` field will be deprecated. In any case, 220 it is recommended not to define :c:member:`~PyTypeObject.tp_print`, but instead to rely on 221 :c:member:`~PyTypeObject.tp_repr` and :c:member:`~PyTypeObject.tp_str` for printing. 222 222 223 223 This field is inherited by subtypes. 224 224 225 225 226 .. c member:: getattrfunc PyTypeObject.tp_getattr226 .. c:member:: getattrfunc PyTypeObject.tp_getattr 227 227 228 228 An optional pointer to the get-attribute-string function. 229 229 230 230 This field is deprecated. When it is defined, it should point to a function 231 that acts the same as the : attr:`tp_getattro` function, but taking a C string231 that acts the same as the :c:member:`~PyTypeObject.tp_getattro` function, but taking a C string 232 232 instead of a Python string object to give the attribute name. The signature is 233 the same as for :c func:`PyObject_GetAttrString`.234 235 This field is inherited by subtypes together with : attr:`tp_getattro`: a subtype236 inherits both : attr:`tp_getattr` and :attr:`tp_getattro` from its base type when237 the subtype's : attr:`tp_getattr` and :attr:`tp_getattro` are both *NULL*.238 239 240 .. c member:: setattrfunc PyTypeObject.tp_setattr233 the same as for :c:func:`PyObject_GetAttrString`. 234 235 This field is inherited by subtypes together with :c:member:`~PyTypeObject.tp_getattro`: a subtype 236 inherits both :c:member:`~PyTypeObject.tp_getattr` and :c:member:`~PyTypeObject.tp_getattro` from its base type when 237 the subtype's :c:member:`~PyTypeObject.tp_getattr` and :c:member:`~PyTypeObject.tp_getattro` are both *NULL*. 238 239 240 .. c:member:: setattrfunc PyTypeObject.tp_setattr 241 241 242 242 An optional pointer to the set-attribute-string function. 243 243 244 244 This field is deprecated. When it is defined, it should point to a function 245 that acts the same as the : attr:`tp_setattro` function, but taking a C string245 that acts the same as the :c:member:`~PyTypeObject.tp_setattro` function, but taking a C string 246 246 instead of a Python string object to give the attribute name. The signature is 247 the same as for :c func:`PyObject_SetAttrString`.248 249 This field is inherited by subtypes together with : attr:`tp_setattro`: a subtype250 inherits both : attr:`tp_setattr` and :attr:`tp_setattro` from its base type when251 the subtype's : attr:`tp_setattr` and :attr:`tp_setattro` are both *NULL*.252 253 254 .. c member:: cmpfunc PyTypeObject.tp_compare247 the same as for :c:func:`PyObject_SetAttrString`. 248 249 This field is inherited by subtypes together with :c:member:`~PyTypeObject.tp_setattro`: a subtype 250 inherits both :c:member:`~PyTypeObject.tp_setattr` and :c:member:`~PyTypeObject.tp_setattro` from its base type when 251 the subtype's :c:member:`~PyTypeObject.tp_setattr` and :c:member:`~PyTypeObject.tp_setattro` are both *NULL*. 252 253 254 .. c:member:: cmpfunc PyTypeObject.tp_compare 255 255 256 256 An optional pointer to the three-way comparison function. 257 257 258 The signature is the same as for :c func:`PyObject_Compare`. The function should258 The signature is the same as for :c:func:`PyObject_Compare`. The function should 259 259 return ``1`` if *self* greater than *other*, ``0`` if *self* is equal to 260 260 *other*, and ``-1`` if *self* less than *other*. It should return ``-1`` and 261 261 set an exception condition when an error occurred during the comparison. 262 262 263 This field is inherited by subtypes together with : attr:`tp_richcompare` and264 : attr:`tp_hash`: a subtypes inherits all three of :attr:`tp_compare`,265 : attr:`tp_richcompare`, and :attr:`tp_hash` when the subtype's266 : attr:`tp_compare`, :attr:`tp_richcompare`, and :attr:`tp_hash` are all *NULL*.267 268 269 .. c member:: reprfunc PyTypeObject.tp_repr263 This field is inherited by subtypes together with :c:member:`~PyTypeObject.tp_richcompare` and 264 :c:member:`~PyTypeObject.tp_hash`: a subtypes inherits all three of :c:member:`~PyTypeObject.tp_compare`, 265 :c:member:`~PyTypeObject.tp_richcompare`, and :c:member:`~PyTypeObject.tp_hash` when the subtype's 266 :c:member:`~PyTypeObject.tp_compare`, :c:member:`~PyTypeObject.tp_richcompare`, and :c:member:`~PyTypeObject.tp_hash` are all *NULL*. 267 268 269 .. c:member:: reprfunc PyTypeObject.tp_repr 270 270 271 271 .. index:: builtin: repr … … 274 274 :func:`repr`. 275 275 276 The signature is the same as for :c func:`PyObject_Repr`; it must return a string276 The signature is the same as for :c:func:`PyObject_Repr`; it must return a string 277 277 or a Unicode object. Ideally, this function should return a string that, when 278 278 passed to :func:`eval`, given a suitable environment, returns an object with the … … 287 287 This field is inherited by subtypes. 288 288 289 .. c member:: PyNumberMethods* tp_as_number289 .. c:member:: PyNumberMethods* tp_as_number 290 290 291 291 Pointer to an additional structure that contains fields relevant only to … … 293 293 :ref:`number-structs`. 294 294 295 The : attr:`tp_as_number` field is not inherited, but the contained fields are295 The :c:member:`~PyTypeObject.tp_as_number` field is not inherited, but the contained fields are 296 296 inherited individually. 297 297 298 298 299 .. c member:: PySequenceMethods* tp_as_sequence299 .. c:member:: PySequenceMethods* tp_as_sequence 300 300 301 301 Pointer to an additional structure that contains fields relevant only to … … 303 303 in :ref:`sequence-structs`. 304 304 305 The : attr:`tp_as_sequence` field is not inherited, but the contained fields305 The :c:member:`~PyTypeObject.tp_as_sequence` field is not inherited, but the contained fields 306 306 are inherited individually. 307 307 308 308 309 .. c member:: PyMappingMethods* tp_as_mapping309 .. c:member:: PyMappingMethods* tp_as_mapping 310 310 311 311 Pointer to an additional structure that contains fields relevant only to … … 313 313 :ref:`mapping-structs`. 314 314 315 The : attr:`tp_as_mapping` field is not inherited, but the contained fields315 The :c:member:`~PyTypeObject.tp_as_mapping` field is not inherited, but the contained fields 316 316 are inherited individually. 317 317 318 318 319 .. c member:: hashfunc PyTypeObject.tp_hash319 .. c:member:: hashfunc PyTypeObject.tp_hash 320 320 321 321 .. index:: builtin: hash … … 324 324 :func:`hash`. 325 325 326 The signature is the same as for :c func:`PyObject_Hash`; it must return a C326 The signature is the same as for :c:func:`PyObject_Hash`; it must return a C 327 327 long. The value ``-1`` should not be returned as a normal return value; when an 328 328 error occurs during the computation of the hash value, the function should set 329 329 an exception and return ``-1``. 330 330 331 This field can be set explicitly to :c func:`PyObject_HashNotImplemented` to331 This field can be set explicitly to :c:func:`PyObject_HashNotImplemented` to 332 332 block inheritance of the hash method from a parent type. This is interpreted 333 333 as the equivalent of ``__hash__ = None`` at the Python level, causing … … 335 335 that the converse is also true - setting ``__hash__ = None`` on a class at 336 336 the Python level will result in the ``tp_hash`` slot being set to 337 :c func:`PyObject_HashNotImplemented`.338 339 When this field is not set, two possibilities exist: if the : attr:`tp_compare`340 and : attr:`tp_richcompare` fields are both *NULL*, a default hash value based on337 :c:func:`PyObject_HashNotImplemented`. 338 339 When this field is not set, two possibilities exist: if the :c:member:`~PyTypeObject.tp_compare` 340 and :c:member:`~PyTypeObject.tp_richcompare` fields are both *NULL*, a default hash value based on 341 341 the object's address is returned; otherwise, a :exc:`TypeError` is raised. 342 342 343 This field is inherited by subtypes together with : attr:`tp_richcompare` and344 : attr:`tp_compare`: a subtypes inherits all three of :attr:`tp_compare`,345 : attr:`tp_richcompare`, and :attr:`tp_hash`, when the subtype's346 : attr:`tp_compare`, :attr:`tp_richcompare` and :attr:`tp_hash` are all *NULL*.347 348 349 .. c member:: ternaryfunc PyTypeObject.tp_call343 This field is inherited by subtypes together with :c:member:`~PyTypeObject.tp_richcompare` and 344 :c:member:`~PyTypeObject.tp_compare`: a subtypes inherits all three of :c:member:`~PyTypeObject.tp_compare`, 345 :c:member:`~PyTypeObject.tp_richcompare`, and :c:member:`~PyTypeObject.tp_hash`, when the subtype's 346 :c:member:`~PyTypeObject.tp_compare`, :c:member:`~PyTypeObject.tp_richcompare` and :c:member:`~PyTypeObject.tp_hash` are all *NULL*. 347 348 349 .. c:member:: ternaryfunc PyTypeObject.tp_call 350 350 351 351 An optional pointer to a function that implements calling the object. This 352 352 should be *NULL* if the object is not callable. The signature is the same as 353 for :c func:`PyObject_Call`.353 for :c:func:`PyObject_Call`. 354 354 355 355 This field is inherited by subtypes. 356 356 357 357 358 .. c member:: reprfunc PyTypeObject.tp_str358 .. c:member:: reprfunc PyTypeObject.tp_str 359 359 360 360 An optional pointer to a function that implements the built-in operation 361 361 :func:`str`. (Note that :class:`str` is a type now, and :func:`str` calls the 362 constructor for that type. This constructor calls :c func:`PyObject_Str` to do363 the actual work, and :c func:`PyObject_Str` will call this handler.)364 365 The signature is the same as for :c func:`PyObject_Str`; it must return a string362 constructor for that type. This constructor calls :c:func:`PyObject_Str` to do 363 the actual work, and :c:func:`PyObject_Str` will call this handler.) 364 365 The signature is the same as for :c:func:`PyObject_Str`; it must return a string 366 366 or a Unicode object. This function should return a "friendly" string 367 367 representation of the object, as this is the representation that will be used by 368 368 the print statement. 369 369 370 When this field is not set, :c func:`PyObject_Repr` is called to return a string370 When this field is not set, :c:func:`PyObject_Repr` is called to return a string 371 371 representation. 372 372 … … 374 374 375 375 376 .. c member:: getattrofunc PyTypeObject.tp_getattro376 .. c:member:: getattrofunc PyTypeObject.tp_getattro 377 377 378 378 An optional pointer to the get-attribute function. 379 379 380 The signature is the same as for :c func:`PyObject_GetAttr`. It is usually381 convenient to set this field to :c func:`PyObject_GenericGetAttr`, which380 The signature is the same as for :c:func:`PyObject_GetAttr`. It is usually 381 convenient to set this field to :c:func:`PyObject_GenericGetAttr`, which 382 382 implements the normal way of looking for object attributes. 383 383 384 This field is inherited by subtypes together with : attr:`tp_getattr`: a subtype385 inherits both : attr:`tp_getattr` and :attr:`tp_getattro` from its base type when386 the subtype's : attr:`tp_getattr` and :attr:`tp_getattro` are both *NULL*.387 388 389 .. c member:: setattrofunc PyTypeObject.tp_setattro384 This field is inherited by subtypes together with :c:member:`~PyTypeObject.tp_getattr`: a subtype 385 inherits both :c:member:`~PyTypeObject.tp_getattr` and :c:member:`~PyTypeObject.tp_getattro` from its base type when 386 the subtype's :c:member:`~PyTypeObject.tp_getattr` and :c:member:`~PyTypeObject.tp_getattro` are both *NULL*. 387 388 389 .. c:member:: setattrofunc PyTypeObject.tp_setattro 390 390 391 391 An optional pointer to the set-attribute function. 392 392 393 The signature is the same as for :c func:`PyObject_SetAttr`. It is usually394 convenient to set this field to :c func:`PyObject_GenericSetAttr`, which393 The signature is the same as for :c:func:`PyObject_SetAttr`. It is usually 394 convenient to set this field to :c:func:`PyObject_GenericSetAttr`, which 395 395 implements the normal way of setting object attributes. 396 396 397 This field is inherited by subtypes together with : attr:`tp_setattr`: a subtype398 inherits both : attr:`tp_setattr` and :attr:`tp_setattro` from its base type when399 the subtype's : attr:`tp_setattr` and :attr:`tp_setattro` are both *NULL*.400 401 402 .. c member:: PyBufferProcs* PyTypeObject.tp_as_buffer397 This field is inherited by subtypes together with :c:member:`~PyTypeObject.tp_setattr`: a subtype 398 inherits both :c:member:`~PyTypeObject.tp_setattr` and :c:member:`~PyTypeObject.tp_setattro` from its base type when 399 the subtype's :c:member:`~PyTypeObject.tp_setattr` and :c:member:`~PyTypeObject.tp_setattro` are both *NULL*. 400 401 402 .. c:member:: PyBufferProcs* PyTypeObject.tp_as_buffer 403 403 404 404 Pointer to an additional structure that contains fields relevant only to objects … … 406 406 :ref:`buffer-structs`. 407 407 408 The : attr:`tp_as_buffer` field is not inherited, but the contained fields are408 The :c:member:`~PyTypeObject.tp_as_buffer` field is not inherited, but the contained fields are 409 409 inherited individually. 410 410 411 411 412 .. c member:: long PyTypeObject.tp_flags412 .. c:member:: long PyTypeObject.tp_flags 413 413 414 414 This field is a bit mask of various flags. Some flags indicate variant 415 415 semantics for certain situations; others are used to indicate that certain 416 416 fields in the type object (or in the extension structures referenced via 417 : attr:`tp_as_number`, :attr:`tp_as_sequence`, :attr:`tp_as_mapping`, and418 : attr:`tp_as_buffer`) that were historically not always present are valid; if417 :c:member:`~PyTypeObject.tp_as_number`, :c:member:`~PyTypeObject.tp_as_sequence`, :c:member:`~PyTypeObject.tp_as_mapping`, and 418 :c:member:`~PyTypeObject.tp_as_buffer`) that were historically not always present are valid; if 419 419 such a flag bit is clear, the type fields it guards must not be accessed and 420 420 must be considered to have a zero or *NULL* value instead. … … 426 426 the flag bit is copied into the subtype together with a pointer to the extension 427 427 structure. The :const:`Py_TPFLAGS_HAVE_GC` flag bit is inherited together with 428 the : attr:`tp_traverse` and :attr:`tp_clear` fields, i.e. if the428 the :c:member:`~PyTypeObject.tp_traverse` and :c:member:`~PyTypeObject.tp_clear` fields, i.e. if the 429 429 :const:`Py_TPFLAGS_HAVE_GC` flag bit is clear in the subtype and the 430 : attr:`tp_traverse` and :attr:`tp_clear` fields in the subtype exist (as430 :c:member:`~PyTypeObject.tp_traverse` and :c:member:`~PyTypeObject.tp_clear` fields in the subtype exist (as 431 431 indicated by the :const:`Py_TPFLAGS_HAVE_RICHCOMPARE` flag bit) and have *NULL* 432 432 values. 433 433 434 434 The following bit masks are currently defined; these can be ORed together using 435 the ``|`` operator to form the value of the : attr:`tp_flags` field. The macro436 :c func:`PyType_HasFeature` takes a type and a flags value, *tp* and *f*, and435 the ``|`` operator to form the value of the :c:member:`~PyTypeObject.tp_flags` field. The macro 436 :c:func:`PyType_HasFeature` takes a type and a flags value, *tp* and *f*, and 437 437 checks whether ``tp->tp_flags & f`` is non-zero. 438 438 … … 440 440 .. data:: Py_TPFLAGS_HAVE_GETCHARBUFFER 441 441 442 If this bit is set, the :c type:`PyBufferProcs` struct referenced by443 : attr:`tp_as_buffer` has the :attr:`bf_getcharbuffer` field.442 If this bit is set, the :c:type:`PyBufferProcs` struct referenced by 443 :c:member:`~PyTypeObject.tp_as_buffer` has the :attr:`bf_getcharbuffer` field. 444 444 445 445 446 446 .. data:: Py_TPFLAGS_HAVE_SEQUENCE_IN 447 447 448 If this bit is set, the :c type:`PySequenceMethods` struct referenced by449 : attr:`tp_as_sequence` has the :attr:`sq_contains` field.448 If this bit is set, the :c:type:`PySequenceMethods` struct referenced by 449 :c:member:`~PyTypeObject.tp_as_sequence` has the :attr:`sq_contains` field. 450 450 451 451 … … 458 458 .. data:: Py_TPFLAGS_HAVE_INPLACEOPS 459 459 460 If this bit is set, the :c type:`PySequenceMethods` struct referenced by461 : attr:`tp_as_sequence` and the :ctype:`PyNumberMethods` structure referenced by462 : attr:`tp_as_number` contain the fields for in-place operators. In particular,463 this means that the :c type:`PyNumberMethods` structure has the fields460 If this bit is set, the :c:type:`PySequenceMethods` struct referenced by 461 :c:member:`~PyTypeObject.tp_as_sequence` and the :c:type:`PyNumberMethods` structure referenced by 462 :c:member:`~PyTypeObject.tp_as_number` contain the fields for in-place operators. In particular, 463 this means that the :c:type:`PyNumberMethods` structure has the fields 464 464 :attr:`nb_inplace_add`, :attr:`nb_inplace_subtract`, 465 465 :attr:`nb_inplace_multiply`, :attr:`nb_inplace_divide`, … … 467 467 :attr:`nb_inplace_lshift`, :attr:`nb_inplace_rshift`, :attr:`nb_inplace_and`, 468 468 :attr:`nb_inplace_xor`, and :attr:`nb_inplace_or`; and the 469 :c type:`PySequenceMethods` struct has the fields :attr:`sq_inplace_concat` and469 :c:type:`PySequenceMethods` struct has the fields :attr:`sq_inplace_concat` and 470 470 :attr:`sq_inplace_repeat`. 471 471 … … 474 474 475 475 If this bit is set, the binary and ternary operations in the 476 :c type:`PyNumberMethods` structure referenced by :attr:`tp_as_number` accept476 :c:type:`PyNumberMethods` structure referenced by :c:member:`~PyTypeObject.tp_as_number` accept 477 477 arguments of arbitrary object types, and do their own type conversions if 478 478 needed. If this bit is clear, those operations require that all arguments have … … 486 486 .. data:: Py_TPFLAGS_HAVE_RICHCOMPARE 487 487 488 If this bit is set, the type object has the : attr:`tp_richcompare` field, as489 well as the : attr:`tp_traverse` and the :attr:`tp_clear` fields.488 If this bit is set, the type object has the :c:member:`~PyTypeObject.tp_richcompare` field, as 489 well as the :c:member:`~PyTypeObject.tp_traverse` and the :c:member:`~PyTypeObject.tp_clear` fields. 490 490 491 491 492 492 .. data:: Py_TPFLAGS_HAVE_WEAKREFS 493 493 494 If this bit is set, the : attr:`tp_weaklistoffset` field is defined. Instances495 of a type are weakly referenceable if the type's : attr:`tp_weaklistoffset` field494 If this bit is set, the :c:member:`~PyTypeObject.tp_weaklistoffset` field is defined. Instances 495 of a type are weakly referenceable if the type's :c:member:`~PyTypeObject.tp_weaklistoffset` field 496 496 has a value greater than zero. 497 497 … … 499 499 .. data:: Py_TPFLAGS_HAVE_ITER 500 500 501 If this bit is set, the type object has the : attr:`tp_iter` and502 : attr:`tp_iternext` fields.501 If this bit is set, the type object has the :c:member:`~PyTypeObject.tp_iter` and 502 :c:member:`~PyTypeObject.tp_iternext` fields. 503 503 504 504 … … 506 506 507 507 If this bit is set, the type object has several new fields defined starting in 508 Python 2.2: : attr:`tp_methods`, :attr:`tp_members`, :attr:`tp_getset`,509 : attr:`tp_base`, :attr:`tp_dict`, :attr:`tp_descr_get`, :attr:`tp_descr_set`,510 : attr:`tp_dictoffset`, :attr:`tp_init`, :attr:`tp_alloc`, :attr:`tp_new`,511 : attr:`tp_free`, :attr:`tp_is_gc`, :attr:`tp_bases`, :attr:`tp_mro`,512 : attr:`tp_cache`, :attr:`tp_subclasses`, and :attr:`tp_weaklist`.508 Python 2.2: :c:member:`~PyTypeObject.tp_methods`, :c:member:`~PyTypeObject.tp_members`, :c:member:`~PyTypeObject.tp_getset`, 509 :c:member:`~PyTypeObject.tp_base`, :c:member:`~PyTypeObject.tp_dict`, :c:member:`~PyTypeObject.tp_descr_get`, :c:member:`~PyTypeObject.tp_descr_set`, 510 :c:member:`~PyTypeObject.tp_dictoffset`, :c:member:`~PyTypeObject.tp_init`, :c:member:`~PyTypeObject.tp_alloc`, :c:member:`~PyTypeObject.tp_new`, 511 :c:member:`~PyTypeObject.tp_free`, :c:member:`~PyTypeObject.tp_is_gc`, :c:member:`~PyTypeObject.tp_bases`, :c:member:`~PyTypeObject.tp_mro`, 512 :c:member:`~PyTypeObject.tp_cache`, :c:member:`~PyTypeObject.tp_subclasses`, and :c:member:`~PyTypeObject.tp_weaklist`. 513 513 514 514 … … 533 533 534 534 This bit is set when the type object has been fully initialized by 535 :c func:`PyType_Ready`.535 :c:func:`PyType_Ready`. 536 536 537 537 538 538 .. data:: Py_TPFLAGS_READYING 539 539 540 This bit is set while :c func:`PyType_Ready` is in the process of initializing540 This bit is set while :c:func:`PyType_Ready` is in the process of initializing 541 541 the type object. 542 542 … … 545 545 546 546 This bit is set when the object supports garbage collection. If this bit 547 is set, instances must be created using :c func:`PyObject_GC_New` and548 destroyed using :c func:`PyObject_GC_Del`. More information in section547 is set, instances must be created using :c:func:`PyObject_GC_New` and 548 destroyed using :c:func:`PyObject_GC_Del`. More information in section 549 549 :ref:`supporting-cycle-detection`. This bit also implies that the 550 GC-related fields : attr:`tp_traverse` and :attr:`tp_clear` are present in550 GC-related fields :c:member:`~PyTypeObject.tp_traverse` and :c:member:`~PyTypeObject.tp_clear` are present in 551 551 the type object; but those fields also exist when 552 552 :const:`Py_TPFLAGS_HAVE_GC` is clear but … … 564 564 565 565 566 .. c member:: char* PyTypeObject.tp_doc566 .. c:member:: char* PyTypeObject.tp_doc 567 567 568 568 An optional pointer to a NUL-terminated C string giving the docstring for this … … 576 576 577 577 578 .. c member:: traverseproc PyTypeObject.tp_traverse578 .. c:member:: traverseproc PyTypeObject.tp_traverse 579 579 580 580 An optional pointer to a traversal function for the garbage collector. This is … … 583 583 :ref:`supporting-cycle-detection`. 584 584 585 The : attr:`tp_traverse` pointer is used by the garbage collector to detect586 reference cycles. A typical implementation of a : attr:`tp_traverse` function587 simply calls :c func:`Py_VISIT` on each of the instance's members that are Python588 objects. For example, this is function :c func:`local_traverse` from the585 The :c:member:`~PyTypeObject.tp_traverse` pointer is used by the garbage collector to detect 586 reference cycles. A typical implementation of a :c:member:`~PyTypeObject.tp_traverse` function 587 simply calls :c:func:`Py_VISIT` on each of the instance's members that are Python 588 objects. For example, this is function :c:func:`local_traverse` from the 589 589 :mod:`thread` extension module:: 590 590 … … 598 598 } 599 599 600 Note that :c func:`Py_VISIT` is called only on those members that can participate600 Note that :c:func:`Py_VISIT` is called only on those members that can participate 601 601 in reference cycles. Although there is also a ``self->key`` member, it can only 602 602 be *NULL* or a Python string and therefore cannot be part of a reference cycle. … … 604 604 On the other hand, even if you know a member can never be part of a cycle, as a 605 605 debugging aid you may want to visit it anyway just so the :mod:`gc` module's 606 :func:` get_referents` function will include it.607 608 Note that :c func:`Py_VISIT` requires the *visit* and *arg* parameters to609 :c func:`local_traverse` to have these specific names; don't name them just606 :func:`~gc.get_referents` function will include it. 607 608 Note that :c:func:`Py_VISIT` requires the *visit* and *arg* parameters to 609 :c:func:`local_traverse` to have these specific names; don't name them just 610 610 anything. 611 611 612 This field is inherited by subtypes together with : attr:`tp_clear` and the613 :const:`Py_TPFLAGS_HAVE_GC` flag bit: the flag bit, : attr:`tp_traverse`, and614 : attr:`tp_clear` are all inherited from the base type if they are all zero in612 This field is inherited by subtypes together with :c:member:`~PyTypeObject.tp_clear` and the 613 :const:`Py_TPFLAGS_HAVE_GC` flag bit: the flag bit, :c:member:`~PyTypeObject.tp_traverse`, and 614 :c:member:`~PyTypeObject.tp_clear` are all inherited from the base type if they are all zero in 615 615 the subtype *and* the subtype has the :const:`Py_TPFLAGS_HAVE_RICHCOMPARE` flag 616 616 bit set. 617 617 618 618 619 .. c member:: inquiry PyTypeObject.tp_clear619 .. c:member:: inquiry PyTypeObject.tp_clear 620 620 621 621 An optional pointer to a clear function for the garbage collector. This is only 622 622 used if the :const:`Py_TPFLAGS_HAVE_GC` flag bit is set. 623 623 624 The : attr:`tp_clear` member function is used to break reference cycles in cyclic625 garbage detected by the garbage collector. Taken together, all : attr:`tp_clear`624 The :c:member:`~PyTypeObject.tp_clear` member function is used to break reference cycles in cyclic 625 garbage detected by the garbage collector. Taken together, all :c:member:`~PyTypeObject.tp_clear` 626 626 functions in the system must combine to break all reference cycles. This is 627 subtle, and if in any doubt supply a : attr:`tp_clear` function. For example,628 the tuple type does not implement a : attr:`tp_clear` function, because it's627 subtle, and if in any doubt supply a :c:member:`~PyTypeObject.tp_clear` function. For example, 628 the tuple type does not implement a :c:member:`~PyTypeObject.tp_clear` function, because it's 629 629 possible to prove that no reference cycle can be composed entirely of tuples. 630 Therefore the : attr:`tp_clear` functions of other types must be sufficient to630 Therefore the :c:member:`~PyTypeObject.tp_clear` functions of other types must be sufficient to 631 631 break any cycle containing a tuple. This isn't immediately obvious, and there's 632 rarely a good reason to avoid implementing : attr:`tp_clear`.633 634 Implementations of : attr:`tp_clear` should drop the instance's references to632 rarely a good reason to avoid implementing :c:member:`~PyTypeObject.tp_clear`. 633 634 Implementations of :c:member:`~PyTypeObject.tp_clear` should drop the instance's references to 635 635 those of its members that may be Python objects, and set its pointers to those 636 636 members to *NULL*, as in the following example:: … … 646 646 } 647 647 648 The :c func:`Py_CLEAR` macro should be used, because clearing references is648 The :c:func:`Py_CLEAR` macro should be used, because clearing references is 649 649 delicate: the reference to the contained object must not be decremented until 650 650 after the pointer to the contained object is set to *NULL*. This is because … … 655 655 it's important that the pointer to the contained object be *NULL* at that time, 656 656 so that *self* knows the contained object can no longer be used. The 657 :c func:`Py_CLEAR` macro performs the operations in a safe order.658 659 Because the goal of : attr:`tp_clear` functions is to break reference cycles,657 :c:func:`Py_CLEAR` macro performs the operations in a safe order. 658 659 Because the goal of :c:member:`~PyTypeObject.tp_clear` functions is to break reference cycles, 660 660 it's not necessary to clear contained objects like Python strings or Python 661 661 integers, which can't participate in reference cycles. On the other hand, it may 662 662 be convenient to clear all contained Python objects, and write the type's 663 : attr:`tp_dealloc` function to invoke :attr:`tp_clear`.663 :c:member:`~PyTypeObject.tp_dealloc` function to invoke :c:member:`~PyTypeObject.tp_clear`. 664 664 665 665 More information about Python's garbage collection scheme can be found in 666 666 section :ref:`supporting-cycle-detection`. 667 667 668 This field is inherited by subtypes together with : attr:`tp_traverse` and the669 :const:`Py_TPFLAGS_HAVE_GC` flag bit: the flag bit, : attr:`tp_traverse`, and670 : attr:`tp_clear` are all inherited from the base type if they are all zero in668 This field is inherited by subtypes together with :c:member:`~PyTypeObject.tp_traverse` and the 669 :const:`Py_TPFLAGS_HAVE_GC` flag bit: the flag bit, :c:member:`~PyTypeObject.tp_traverse`, and 670 :c:member:`~PyTypeObject.tp_clear` are all inherited from the base type if they are all zero in 671 671 the subtype *and* the subtype has the :const:`Py_TPFLAGS_HAVE_RICHCOMPARE` flag 672 672 bit set. 673 673 674 674 675 .. c member:: richcmpfunc PyTypeObject.tp_richcompare675 .. c:member:: richcmpfunc PyTypeObject.tp_richcompare 676 676 677 677 An optional pointer to the rich comparison function, whose signature is … … 689 689 friends), directly raise :exc:`TypeError` in the rich comparison function. 690 690 691 This field is inherited by subtypes together with : attr:`tp_compare` and692 : attr:`tp_hash`: a subtype inherits all three of :attr:`tp_compare`,693 : attr:`tp_richcompare`, and :attr:`tp_hash`, when the subtype's694 : attr:`tp_compare`, :attr:`tp_richcompare`, and :attr:`tp_hash` are all *NULL*.691 This field is inherited by subtypes together with :c:member:`~PyTypeObject.tp_compare` and 692 :c:member:`~PyTypeObject.tp_hash`: a subtype inherits all three of :c:member:`~PyTypeObject.tp_compare`, 693 :c:member:`~PyTypeObject.tp_richcompare`, and :c:member:`~PyTypeObject.tp_hash`, when the subtype's 694 :c:member:`~PyTypeObject.tp_compare`, :c:member:`~PyTypeObject.tp_richcompare`, and :c:member:`~PyTypeObject.tp_hash` are all *NULL*. 695 695 696 696 The following constants are defined to be used as the third argument for 697 : attr:`tp_richcompare` and for :cfunc:`PyObject_RichCompare`:697 :c:member:`~PyTypeObject.tp_richcompare` and for :c:func:`PyObject_RichCompare`: 698 698 699 699 +----------------+------------+ … … 717 717 set. 718 718 719 .. c member:: long PyTypeObject.tp_weaklistoffset719 .. c:member:: long PyTypeObject.tp_weaklistoffset 720 720 721 721 If the instances of this type are weakly referenceable, this field is greater 722 722 than zero and contains the offset in the instance structure of the weak 723 723 reference list head (ignoring the GC header, if present); this offset is used by 724 :c func:`PyObject_ClearWeakRefs` and the :cfunc:`PyWeakref_\*` functions. The725 instance structure needs to include a field of type :c type:`PyObject\*` which is724 :c:func:`PyObject_ClearWeakRefs` and the :c:func:`PyWeakref_\*` functions. The 725 instance structure needs to include a field of type :c:type:`PyObject\*` which is 726 726 initialized to *NULL*. 727 727 728 Do not confuse this field with : attr:`tp_weaklist`; that is the list head for728 Do not confuse this field with :c:member:`~PyTypeObject.tp_weaklist`; that is the list head for 729 729 weak references to the type object itself. 730 730 … … 732 732 may override this offset; this means that the subtype uses a different weak 733 733 reference list head than the base type. Since the list head is always found via 734 : attr:`tp_weaklistoffset`, this should not be a problem.735 736 When a type defined by a class statement has no :attr:` __slots__` declaration,734 :c:member:`~PyTypeObject.tp_weaklistoffset`, this should not be a problem. 735 736 When a type defined by a class statement has no :attr:`~object.__slots__` declaration, 737 737 and none of its base types are weakly referenceable, the type is made weakly 738 738 referenceable by adding a weak reference list head slot to the instance layout 739 and setting the : attr:`tp_weaklistoffset` of that slot's offset.739 and setting the :c:member:`~PyTypeObject.tp_weaklistoffset` of that slot's offset. 740 740 741 741 When a type's :attr:`__slots__` declaration contains a slot named 742 742 :attr:`__weakref__`, that slot becomes the weak reference list head for 743 743 instances of the type, and the slot's offset is stored in the type's 744 : attr:`tp_weaklistoffset`.744 :c:member:`~PyTypeObject.tp_weaklistoffset`. 745 745 746 746 When a type's :attr:`__slots__` declaration does not contain a slot named 747 :attr:`__weakref__`, the type inherits its : attr:`tp_weaklistoffset` from its747 :attr:`__weakref__`, the type inherits its :c:member:`~PyTypeObject.tp_weaklistoffset` from its 748 748 base type. 749 749 … … 752 752 753 753 754 .. c member:: getiterfunc PyTypeObject.tp_iter754 .. c:member:: getiterfunc PyTypeObject.tp_iter 755 755 756 756 An optional pointer to a function that returns an iterator for the object. Its … … 759 759 have this function, even if they don't define an :meth:`__iter__` method). 760 760 761 This function has the same signature as :c func:`PyObject_GetIter`.761 This function has the same signature as :c:func:`PyObject_GetIter`. 762 762 763 763 This field is inherited by subtypes. 764 764 765 765 766 .. c member:: iternextfunc PyTypeObject.tp_iternext766 .. c:member:: iternextfunc PyTypeObject.tp_iternext 767 767 768 768 An optional pointer to a function that returns the next item in an iterator. … … 773 773 they don't define a :meth:`next` method). 774 774 775 Iterator types should also define the : attr:`tp_iter` function, and that775 Iterator types should also define the :c:member:`~PyTypeObject.tp_iter` function, and that 776 776 function should return the iterator instance itself (not a new iterator 777 777 instance). 778 778 779 This function has the same signature as :c func:`PyIter_Next`.779 This function has the same signature as :c:func:`PyIter_Next`. 780 780 781 781 This field is inherited by subtypes. 782 782 783 The next fields, up to and including : attr:`tp_weaklist`, only exist if the783 The next fields, up to and including :c:member:`~PyTypeObject.tp_weaklist`, only exist if the 784 784 :const:`Py_TPFLAGS_HAVE_CLASS` flag bit is set. 785 785 786 786 787 .. c member:: struct PyMethodDef* PyTypeObject.tp_methods788 789 An optional pointer to a static *NULL*-terminated array of :c type:`PyMethodDef`787 .. c:member:: struct PyMethodDef* PyTypeObject.tp_methods 788 789 An optional pointer to a static *NULL*-terminated array of :c:type:`PyMethodDef` 790 790 structures, declaring regular methods of this type. 791 791 792 792 For each entry in the array, an entry is added to the type's dictionary (see 793 : attr:`tp_dict` below) containing a method descriptor.793 :c:member:`~PyTypeObject.tp_dict` below) containing a method descriptor. 794 794 795 795 This field is not inherited by subtypes (methods are inherited through a … … 797 797 798 798 799 .. c member:: struct PyMemberDef* PyTypeObject.tp_members800 801 An optional pointer to a static *NULL*-terminated array of :c type:`PyMemberDef`799 .. c:member:: struct PyMemberDef* PyTypeObject.tp_members 800 801 An optional pointer to a static *NULL*-terminated array of :c:type:`PyMemberDef` 802 802 structures, declaring regular data members (fields or slots) of instances of 803 803 this type. 804 804 805 805 For each entry in the array, an entry is added to the type's dictionary (see 806 : attr:`tp_dict` below) containing a member descriptor.806 :c:member:`~PyTypeObject.tp_dict` below) containing a member descriptor. 807 807 808 808 This field is not inherited by subtypes (members are inherited through a … … 810 810 811 811 812 .. c member:: struct PyGetSetDef* PyTypeObject.tp_getset813 814 An optional pointer to a static *NULL*-terminated array of :c type:`PyGetSetDef`812 .. c:member:: struct PyGetSetDef* PyTypeObject.tp_getset 813 814 An optional pointer to a static *NULL*-terminated array of :c:type:`PyGetSetDef` 815 815 structures, declaring computed attributes of instances of this type. 816 816 817 817 For each entry in the array, an entry is added to the type's dictionary (see 818 : attr:`tp_dict` below) containing a getset descriptor.818 :c:member:`~PyTypeObject.tp_dict` below) containing a getset descriptor. 819 819 820 820 This field is not inherited by subtypes (computed attributes are inherited 821 821 through a different mechanism). 822 822 823 Docs for PyGetSetDef (XXX belong elsewhere):: 823 .. XXX belongs elsewhere 824 825 Docs for PyGetSetDef:: 824 826 825 827 typedef PyObject *(*getter)(PyObject *, void *); … … 835 837 836 838 837 .. c member:: PyTypeObject* PyTypeObject.tp_base839 .. c:member:: PyTypeObject* PyTypeObject.tp_base 838 840 839 841 An optional pointer to a base type from which type properties are inherited. At … … 846 848 847 849 848 .. c member:: PyObject* PyTypeObject.tp_dict849 850 The type's dictionary is stored here by :c func:`PyType_Ready`.850 .. c:member:: PyObject* PyTypeObject.tp_dict 851 852 The type's dictionary is stored here by :c:func:`PyType_Ready`. 851 853 852 854 This field should normally be initialized to *NULL* before PyType_Ready is 853 855 called; it may also be initialized to a dictionary containing initial attributes 854 for the type. Once :c func:`PyType_Ready` has initialized the type, extra856 for the type. Once :c:func:`PyType_Ready` has initialized the type, extra 855 857 attributes for the type may be added to this dictionary only if they don't 856 858 correspond to overloaded operations (like :meth:`__add__`). … … 860 862 861 863 862 .. c member:: descrgetfunc PyTypeObject.tp_descr_get864 .. c:member:: descrgetfunc PyTypeObject.tp_descr_get 863 865 864 866 An optional pointer to a "descriptor get" function. … … 868 870 PyObject * tp_descr_get(PyObject *self, PyObject *obj, PyObject *type); 869 871 870 XXX explain.872 .. XXX explain. 871 873 872 874 This field is inherited by subtypes. 873 875 874 876 875 .. c member:: descrsetfunc PyTypeObject.tp_descr_set877 .. c:member:: descrsetfunc PyTypeObject.tp_descr_set 876 878 877 879 An optional pointer to a "descriptor set" function. … … 883 885 This field is inherited by subtypes. 884 886 885 XXX explain.886 887 888 .. c member:: long PyTypeObject.tp_dictoffset887 .. XXX explain. 888 889 890 .. c:member:: long PyTypeObject.tp_dictoffset 889 891 890 892 If the instances of this type have a dictionary containing instance variables, 891 893 this field is non-zero and contains the offset in the instances of the type of 892 894 the instance variable dictionary; this offset is used by 893 :c func:`PyObject_GenericGetAttr`.894 895 Do not confuse this field with : attr:`tp_dict`; that is the dictionary for895 :c:func:`PyObject_GenericGetAttr`. 896 897 Do not confuse this field with :c:member:`~PyTypeObject.tp_dict`; that is the dictionary for 896 898 attributes of the type object itself. 897 899 … … 902 904 structure contains a variable-length part. This is used for example to add an 903 905 instance variable dictionary to subtypes of :class:`str` or :class:`tuple`. Note 904 that the : attr:`tp_basicsize` field should account for the dictionary added to906 that the :c:member:`~PyTypeObject.tp_basicsize` field should account for the dictionary added to 905 907 the end in that case, even though the dictionary is not included in the basic 906 908 object layout. On a system with a pointer size of 4 bytes, 907 : attr:`tp_dictoffset` should be set to ``-4`` to indicate that the dictionary is909 :c:member:`~PyTypeObject.tp_dictoffset` should be set to ``-4`` to indicate that the dictionary is 908 910 at the very end of the structure. 909 911 910 912 The real dictionary offset in an instance can be computed from a negative 911 : attr:`tp_dictoffset` as follows::913 :c:member:`~PyTypeObject.tp_dictoffset` as follows:: 912 914 913 915 dictoffset = tp_basicsize + abs(ob_size)*tp_itemsize + tp_dictoffset … … 915 917 round up to sizeof(void*) 916 918 917 where : attr:`tp_basicsize`, :attr:`tp_itemsize` and :attr:`tp_dictoffset` are919 where :c:member:`~PyTypeObject.tp_basicsize`, :c:member:`~PyTypeObject.tp_itemsize` and :c:member:`~PyTypeObject.tp_dictoffset` are 918 920 taken from the type object, and :attr:`ob_size` is taken from the instance. The 919 921 absolute value is taken because long ints use the sign of :attr:`ob_size` to 920 922 store the sign of the number. (There's never a need to do this calculation 921 yourself; it is done for you by :c func:`_PyObject_GetDictPtr`.)923 yourself; it is done for you by :c:func:`_PyObject_GetDictPtr`.) 922 924 923 925 This field is inherited by subtypes, but see the rules listed below. A subtype 924 926 may override this offset; this means that the subtype instances store the 925 927 dictionary at a difference offset than the base type. Since the dictionary is 926 always found via : attr:`tp_dictoffset`, this should not be a problem.927 928 When a type defined by a class statement has no :attr:` __slots__` declaration,928 always found via :c:member:`~PyTypeObject.tp_dictoffset`, this should not be a problem. 929 930 When a type defined by a class statement has no :attr:`~object.__slots__` declaration, 929 931 and none of its base types has an instance variable dictionary, a dictionary 930 slot is added to the instance layout and the : attr:`tp_dictoffset` is set to932 slot is added to the instance layout and the :c:member:`~PyTypeObject.tp_dictoffset` is set to 931 933 that slot's offset. 932 934 933 935 When a type defined by a class statement has a :attr:`__slots__` declaration, 934 the type inherits its : attr:`tp_dictoffset` from its base type.935 936 (Adding a slot named :attr:` __dict__` to the :attr:`__slots__` declaration does936 the type inherits its :c:member:`~PyTypeObject.tp_dictoffset` from its base type. 937 938 (Adding a slot named :attr:`~object.__dict__` to the :attr:`__slots__` declaration does 937 939 not have the expected effect, it just causes confusion. Maybe this should be 938 940 added as a feature just like :attr:`__weakref__` though.) 939 941 940 942 941 .. c member:: initproc PyTypeObject.tp_init943 .. c:member:: initproc PyTypeObject.tp_init 942 944 943 945 An optional pointer to an instance initialization function. … … 956 958 :meth:`__init__`. 957 959 958 The : attr:`tp_init` function, if not *NULL*, is called when an instance is959 created normally by calling its type, after the type's : attr:`tp_new` function960 has returned an instance of the type. If the : attr:`tp_new` function returns an960 The :c:member:`~PyTypeObject.tp_init` function, if not *NULL*, is called when an instance is 961 created normally by calling its type, after the type's :c:member:`~PyTypeObject.tp_new` function 962 has returned an instance of the type. If the :c:member:`~PyTypeObject.tp_new` function returns an 961 963 instance of some other type that is not a subtype of the original type, no 962 : attr:`tp_init` function is called; if :attr:`tp_new` returns an instance of a963 subtype of the original type, the subtype's : attr:`tp_init` is called. (VERSION964 :c:member:`~PyTypeObject.tp_init` function is called; if :c:member:`~PyTypeObject.tp_new` returns an instance of a 965 subtype of the original type, the subtype's :c:member:`~PyTypeObject.tp_init` is called. (VERSION 964 966 NOTE: described here is what is implemented in Python 2.2.1 and later. In 965 Python 2.2, the : attr:`tp_init` of the type of the object returned by966 : attr:`tp_new` was always called, if not *NULL*.)967 Python 2.2, the :c:member:`~PyTypeObject.tp_init` of the type of the object returned by 968 :c:member:`~PyTypeObject.tp_new` was always called, if not *NULL*.) 967 969 968 970 This field is inherited by subtypes. 969 971 970 972 971 .. c member:: allocfunc PyTypeObject.tp_alloc973 .. c:member:: allocfunc PyTypeObject.tp_alloc 972 974 973 975 An optional pointer to an instance allocation function. … … 981 983 length for the instance, suitably aligned, and initialized to zeros, but with 982 984 :attr:`ob_refcnt` set to ``1`` and :attr:`ob_type` set to the type argument. If 983 the type's : attr:`tp_itemsize` is non-zero, the object's :attr:`ob_size` field985 the type's :c:member:`~PyTypeObject.tp_itemsize` is non-zero, the object's :attr:`ob_size` field 984 986 should be initialized to *nitems* and the length of the allocated memory block 985 987 should be ``tp_basicsize + nitems*tp_itemsize``, rounded up to a multiple of 986 988 ``sizeof(void*)``; otherwise, *nitems* is not used and the length of the block 987 should be : attr:`tp_basicsize`.989 should be :c:member:`~PyTypeObject.tp_basicsize`. 988 990 989 991 Do not use this function to do any other instance initialization, not even to 990 allocate additional memory; that should be done by : attr:`tp_new`.992 allocate additional memory; that should be done by :c:member:`~PyTypeObject.tp_new`. 991 993 992 994 This field is inherited by static subtypes, but not by dynamic subtypes 993 995 (subtypes created by a class statement); in the latter, this field is always set 994 to :c func:`PyType_GenericAlloc`, to force a standard heap allocation strategy.996 to :c:func:`PyType_GenericAlloc`, to force a standard heap allocation strategy. 995 997 That is also the recommended value for statically defined types. 996 998 997 999 998 .. c member:: newfunc PyTypeObject.tp_new1000 .. c:member:: newfunc PyTypeObject.tp_new 999 1001 1000 1002 An optional pointer to an instance creation function. … … 1010 1012 The subtype argument is the type of the object being created; the *args* and 1011 1013 *kwds* arguments represent positional and keyword arguments of the call to the 1012 type. Note that subtype doesn't have to equal the type whose : attr:`tp_new`1014 type. Note that subtype doesn't have to equal the type whose :c:member:`~PyTypeObject.tp_new` 1013 1015 function is called; it may be a subtype of that type (but not an unrelated 1014 1016 type). 1015 1017 1016 The : attr:`tp_new` function should call ``subtype->tp_alloc(subtype, nitems)``1018 The :c:member:`~PyTypeObject.tp_new` function should call ``subtype->tp_alloc(subtype, nitems)`` 1017 1019 to allocate space for the object, and then do only as much further 1018 1020 initialization as is absolutely necessary. Initialization that can safely be 1019 ignored or repeated should be placed in the : attr:`tp_init` handler. A good1021 ignored or repeated should be placed in the :c:member:`~PyTypeObject.tp_init` handler. A good 1020 1022 rule of thumb is that for immutable types, all initialization should take place 1021 in : attr:`tp_new`, while for mutable types, most initialization should be1022 deferred to : attr:`tp_init`.1023 in :c:member:`~PyTypeObject.tp_new`, while for mutable types, most initialization should be 1024 deferred to :c:member:`~PyTypeObject.tp_init`. 1023 1025 1024 1026 This field is inherited by subtypes, except it is not inherited by static types 1025 whose : attr:`tp_base` is *NULL* or ``&PyBaseObject_Type``. The latter exception1027 whose :c:member:`~PyTypeObject.tp_base` is *NULL* or ``&PyBaseObject_Type``. The latter exception 1026 1028 is a precaution so that old extension types don't become callable simply by 1027 1029 being linked with Python 2.2. 1028 1030 1029 1031 1030 .. c member:: destructor PyTypeObject.tp_free1032 .. c:member:: destructor PyTypeObject.tp_free 1031 1033 1032 1034 An optional pointer to an instance deallocation function. 1033 1035 1034 1036 The signature of this function has changed slightly: in Python 2.2 and 2.2.1, 1035 its signature is :c type:`destructor`::1037 its signature is :c:type:`destructor`:: 1036 1038 1037 1039 void tp_free(PyObject *) 1038 1040 1039 In Python 2.3 and beyond, its signature is :c type:`freefunc`::1041 In Python 2.3 and beyond, its signature is :c:type:`freefunc`:: 1040 1042 1041 1043 void tp_free(void *) … … 1046 1048 This field is inherited by static subtypes, but not by dynamic subtypes 1047 1049 (subtypes created by a class statement); in the latter, this field is set to a 1048 deallocator suitable to match :c func:`PyType_GenericAlloc` and the value of the1050 deallocator suitable to match :c:func:`PyType_GenericAlloc` and the value of the 1049 1051 :const:`Py_TPFLAGS_HAVE_GC` flag bit. 1050 1052 1051 1053 1052 .. c member:: inquiry PyTypeObject.tp_is_gc1054 .. c:member:: inquiry PyTypeObject.tp_is_gc 1053 1055 1054 1056 An optional pointer to a function called by the garbage collector. … … 1056 1058 The garbage collector needs to know whether a particular object is collectible 1057 1059 or not. Normally, it is sufficient to look at the object's type's 1058 : attr:`tp_flags` field, and check the :const:`Py_TPFLAGS_HAVE_GC` flag bit. But1060 :c:member:`~PyTypeObject.tp_flags` field, and check the :const:`Py_TPFLAGS_HAVE_GC` flag bit. But 1059 1061 some types have a mixture of statically and dynamically allocated instances, and 1060 1062 the statically allocated instances are not collectible. Such types should … … 1065 1067 1066 1068 (The only example of this are types themselves. The metatype, 1067 :c data:`PyType_Type`, defines this function to distinguish between statically1069 :c:data:`PyType_Type`, defines this function to distinguish between statically 1068 1070 and dynamically allocated types.) 1069 1071 … … 1072 1074 1073 1075 1074 .. c member:: PyObject* PyTypeObject.tp_bases1076 .. c:member:: PyObject* PyTypeObject.tp_bases 1075 1077 1076 1078 Tuple of base types. … … 1082 1084 1083 1085 1084 .. c member:: PyObject* PyTypeObject.tp_mro1086 .. c:member:: PyObject* PyTypeObject.tp_mro 1085 1087 1086 1088 Tuple containing the expanded set of base types, starting with the type itself 1087 1089 and ending with :class:`object`, in Method Resolution Order. 1088 1090 1089 This field is not inherited; it is calculated fresh by :c func:`PyType_Ready`.1090 1091 1092 .. c member:: PyObject* PyTypeObject.tp_cache1091 This field is not inherited; it is calculated fresh by :c:func:`PyType_Ready`. 1092 1093 1094 .. c:member:: PyObject* PyTypeObject.tp_cache 1093 1095 1094 1096 Unused. Not inherited. Internal use only. 1095 1097 1096 1098 1097 .. c member:: PyObject* PyTypeObject.tp_subclasses1099 .. c:member:: PyObject* PyTypeObject.tp_subclasses 1098 1100 1099 1101 List of weak references to subclasses. Not inherited. Internal use only. 1100 1102 1101 1103 1102 .. c member:: PyObject* PyTypeObject.tp_weaklist1104 .. c:member:: PyObject* PyTypeObject.tp_weaklist 1103 1105 1104 1106 Weak reference list head, for weak references to this type object. Not … … 1111 1113 1112 1114 1113 .. c member:: Py_ssize_t PyTypeObject.tp_allocs1115 .. c:member:: Py_ssize_t PyTypeObject.tp_allocs 1114 1116 1115 1117 Number of allocations. 1116 1118 1117 1119 1118 .. c member:: Py_ssize_t PyTypeObject.tp_frees1120 .. c:member:: Py_ssize_t PyTypeObject.tp_frees 1119 1121 1120 1122 Number of frees. 1121 1123 1122 1124 1123 .. c member:: Py_ssize_t PyTypeObject.tp_maxalloc1125 .. c:member:: Py_ssize_t PyTypeObject.tp_maxalloc 1124 1126 1125 1127 Maximum simultaneously allocated objects. 1126 1128 1127 1129 1128 .. c member:: PyTypeObject* PyTypeObject.tp_next1129 1130 Pointer to the next type object with a non-zero : attr:`tp_allocs` field.1130 .. c:member:: PyTypeObject* PyTypeObject.tp_next 1131 1132 Pointer to the next type object with a non-zero :c:member:`~PyTypeObject.tp_allocs` field. 1131 1133 1132 1134 Also, note that, in a garbage collected Python, tp_dealloc may be called from … … 1149 1151 1150 1152 1151 .. c type:: PyNumberMethods1153 .. c:type:: PyNumberMethods 1152 1154 1153 1155 This structure holds pointers to the functions which an object uses to … … 1214 1216 arguments: 1215 1217 1216 .. c member:: coercion PyNumberMethods.nb_coerce1217 1218 This function is used by :c func:`PyNumber_CoerceEx` and has the same1218 .. c:member:: coercion PyNumberMethods.nb_coerce 1219 1220 This function is used by :c:func:`PyNumber_CoerceEx` and has the same 1219 1221 signature. The first argument is always a pointer to an object of the 1220 1222 defined type. If the conversion to a common "larger" type is possible, the … … 1226 1228 functions must check the type of all their operands, and implement the 1227 1229 necessary conversions (at least one of the operands is an instance of the 1228 defined type). This is the recommended way; with Python 3 .0coercion will1230 defined type). This is the recommended way; with Python 3 coercion will 1229 1231 disappear completely. 1230 1232 … … 1242 1244 1243 1245 1244 .. c type:: PyMappingMethods1246 .. c:type:: PyMappingMethods 1245 1247 1246 1248 This structure holds pointers to the functions which an object uses to 1247 1249 implement the mapping protocol. It has three members: 1248 1250 1249 .. c member:: lenfunc PyMappingMethods.mp_length1250 1251 This function is used by :c func:`PyMapping_Length` and1252 :c func:`PyObject_Size`, and has the same signature. This slot may be set to1251 .. c:member:: lenfunc PyMappingMethods.mp_length 1252 1253 This function is used by :c:func:`PyMapping_Length` and 1254 :c:func:`PyObject_Size`, and has the same signature. This slot may be set to 1253 1255 *NULL* if the object has no defined length. 1254 1256 1255 .. c member:: binaryfunc PyMappingMethods.mp_subscript1256 1257 This function is used by :c func:`PyObject_GetItem` and has the same1258 signature. This slot must be filled for the :c func:`PyMapping_Check`1257 .. c:member:: binaryfunc PyMappingMethods.mp_subscript 1258 1259 This function is used by :c:func:`PyObject_GetItem` and has the same 1260 signature. This slot must be filled for the :c:func:`PyMapping_Check` 1259 1261 function to return ``1``, it can be *NULL* otherwise. 1260 1262 1261 .. c member:: objobjargproc PyMappingMethods.mp_ass_subscript1262 1263 This function is used by :c func:`PyObject_SetItem` and has the same1263 .. c:member:: objobjargproc PyMappingMethods.mp_ass_subscript 1264 1265 This function is used by :c:func:`PyObject_SetItem` and has the same 1264 1266 signature. If this slot is *NULL*, the object does not support item 1265 1267 assignment. … … 1274 1276 1275 1277 1276 .. c type:: PySequenceMethods1278 .. c:type:: PySequenceMethods 1277 1279 1278 1280 This structure holds pointers to the functions which an object uses to 1279 1281 implement the sequence protocol. 1280 1282 1281 .. c member:: lenfunc PySequenceMethods.sq_length1282 1283 This function is used by :c func:`PySequence_Size` and :cfunc:`PyObject_Size`,1283 .. c:member:: lenfunc PySequenceMethods.sq_length 1284 1285 This function is used by :c:func:`PySequence_Size` and :c:func:`PyObject_Size`, 1284 1286 and has the same signature. 1285 1287 1286 .. c member:: binaryfunc PySequenceMethods.sq_concat1287 1288 This function is used by :c func:`PySequence_Concat` and has the same1288 .. c:member:: binaryfunc PySequenceMethods.sq_concat 1289 1290 This function is used by :c:func:`PySequence_Concat` and has the same 1289 1291 signature. It is also used by the ``+`` operator, after trying the numeric 1290 addition via the : attr:`tp_as_number.nb_add` slot.1291 1292 .. c member:: ssizeargfunc PySequenceMethods.sq_repeat1293 1294 This function is used by :c func:`PySequence_Repeat` and has the same1292 addition via the :c:member:`~PyTypeObject.tp_as_number.nb_add` slot. 1293 1294 .. c:member:: ssizeargfunc PySequenceMethods.sq_repeat 1295 1296 This function is used by :c:func:`PySequence_Repeat` and has the same 1295 1297 signature. It is also used by the ``*`` operator, after trying numeric 1296 multiplication via the : attr:`tp_as_number.nb_mul` slot.1297 1298 .. c member:: ssizeargfunc PySequenceMethods.sq_item1299 1300 This function is used by :c func:`PySequence_GetItem` and has the same1301 signature. This slot must be filled for the :c func:`PySequence_Check`1298 multiplication via the :c:member:`~PyTypeObject.tp_as_number.nb_mul` slot. 1299 1300 .. c:member:: ssizeargfunc PySequenceMethods.sq_item 1301 1302 This function is used by :c:func:`PySequence_GetItem` and has the same 1303 signature. This slot must be filled for the :c:func:`PySequence_Check` 1302 1304 function to return ``1``, it can be *NULL* otherwise. 1303 1305 … … 1307 1309 the index is passed as is to the function. 1308 1310 1309 .. c member:: ssizeobjargproc PySequenceMethods.sq_ass_item1310 1311 This function is used by :c func:`PySequence_SetItem` and has the same1311 .. c:member:: ssizeobjargproc PySequenceMethods.sq_ass_item 1312 1313 This function is used by :c:func:`PySequence_SetItem` and has the same 1312 1314 signature. This slot may be left to *NULL* if the object does not support 1313 1315 item assignment. 1314 1316 1315 .. c member:: objobjproc PySequenceMethods.sq_contains1316 1317 This function may be used by :c func:`PySequence_Contains` and has the same1317 .. c:member:: objobjproc PySequenceMethods.sq_contains 1318 1319 This function may be used by :c:func:`PySequence_Contains` and has the same 1318 1320 signature. This slot may be left to *NULL*, in this case 1319 :c func:`PySequence_Contains` simply traverses the sequence until it finds a1321 :c:func:`PySequence_Contains` simply traverses the sequence until it finds a 1320 1322 match. 1321 1323 1322 .. c member:: binaryfunc PySequenceMethods.sq_inplace_concat1323 1324 This function is used by :c func:`PySequence_InPlaceConcat` and has the same1324 .. c:member:: binaryfunc PySequenceMethods.sq_inplace_concat 1325 1326 This function is used by :c:func:`PySequence_InPlaceConcat` and has the same 1325 1327 signature. It should modify its first operand, and return it. 1326 1328 1327 .. c member:: ssizeargfunc PySequenceMethods.sq_inplace_repeat1328 1329 This function is used by :c func:`PySequence_InPlaceRepeat` and has the same1329 .. c:member:: ssizeargfunc PySequenceMethods.sq_inplace_repeat 1330 1331 This function is used by :c:func:`PySequence_InPlaceRepeat` and has the same 1330 1332 signature. It should modify its first operand, and return it. 1331 1333 … … 1347 1349 to be non-contiguous in memory. 1348 1350 1349 If an object does not export the buffer interface, then its : attr:`tp_as_buffer`1350 member in the :c type:`PyTypeObject` structure should be *NULL*. Otherwise, the1351 : attr:`tp_as_buffer` will point to a :ctype:`PyBufferProcs` structure.1351 If an object does not export the buffer interface, then its :c:member:`~PyTypeObject.tp_as_buffer` 1352 member in the :c:type:`PyTypeObject` structure should be *NULL*. Otherwise, the 1353 :c:member:`~PyTypeObject.tp_as_buffer` will point to a :c:type:`PyBufferProcs` structure. 1352 1354 1353 1355 .. note:: 1354 1356 1355 It is very important that your :c type:`PyTypeObject` structure uses1356 :const:`Py_TPFLAGS_DEFAULT` for the value of the : attr:`tp_flags` member rather1357 than ``0``. This tells the Python runtime that your :c type:`PyBufferProcs`1357 It is very important that your :c:type:`PyTypeObject` structure uses 1358 :const:`Py_TPFLAGS_DEFAULT` for the value of the :c:member:`~PyTypeObject.tp_flags` member rather 1359 than ``0``. This tells the Python runtime that your :c:type:`PyBufferProcs` 1358 1360 structure contains the :attr:`bf_getcharbuffer` slot. Older versions of Python 1359 1361 did not have this member, so a new Python interpreter using an old extension … … 1361 1363 1362 1364 1363 .. c type:: PyBufferProcs1365 .. c:type:: PyBufferProcs 1364 1366 1365 1367 Structure used to hold the function pointers which define an implementation of 1366 1368 the buffer protocol. 1367 1369 1368 The first slot is :attr:`bf_getreadbuffer`, of type :c type:`getreadbufferproc`.1370 The first slot is :attr:`bf_getreadbuffer`, of type :c:type:`getreadbufferproc`. 1369 1371 If this slot is *NULL*, then the object does not support reading from the 1370 1372 internal data. This is non-sensical, so implementors should fill this in, but … … 1372 1374 1373 1375 The next slot is :attr:`bf_getwritebuffer` having type 1374 :c type:`getwritebufferproc`. This slot may be *NULL* if the object does not1376 :c:type:`getwritebufferproc`. This slot may be *NULL* if the object does not 1375 1377 allow writing into its returned buffers. 1376 1378 1377 The third slot is :attr:`bf_getsegcount`, with type :c type:`getsegcountproc`.1379 The third slot is :attr:`bf_getsegcount`, with type :c:type:`getsegcountproc`. 1378 1380 This slot must not be *NULL* and is used to inform the caller how many segments 1379 the object contains. Simple objects such as :c type:`PyString_Type` and1380 :c type:`PyBuffer_Type` objects contain a single segment.1381 the object contains. Simple objects such as :c:type:`PyString_Type` and 1382 :c:type:`PyBuffer_Type` objects contain a single segment. 1381 1383 1382 1384 .. index:: single: PyType_HasFeature() 1383 1385 1384 The last slot is :attr:`bf_getcharbuffer`, of type :c type:`getcharbufferproc`.1386 The last slot is :attr:`bf_getcharbuffer`, of type :c:type:`getcharbufferproc`. 1385 1387 This slot will only be present if the :const:`Py_TPFLAGS_HAVE_GETCHARBUFFER` 1386 flag is present in the : attr:`tp_flags` field of the object's1387 :c type:`PyTypeObject`. Before using this slot, the caller should test whether it1388 is present by using the :c func:`PyType_HasFeature` function. If the flag is1388 flag is present in the :c:member:`~PyTypeObject.tp_flags` field of the object's 1389 :c:type:`PyTypeObject`. Before using this slot, the caller should test whether it 1390 is present by using the :c:func:`PyType_HasFeature` function. If the flag is 1389 1391 present, :attr:`bf_getcharbuffer` may be *NULL*, indicating that the object's 1390 1392 contents cannot be used as *8-bit characters*. The slot function may also raise … … 1410 1412 1411 1413 1412 .. c type:: Py_ssize_t (*readbufferproc) (PyObject *self, Py_ssize_t segment, void **ptrptr)1414 .. c:type:: Py_ssize_t (*readbufferproc) (PyObject *self, Py_ssize_t segment, void **ptrptr) 1413 1415 1414 1416 Return a pointer to a readable segment of the buffer in ``*ptrptr``. This … … 1420 1422 1421 1423 1422 .. c type:: Py_ssize_t (*writebufferproc) (PyObject *self, Py_ssize_t segment, void **ptrptr)1424 .. c:type:: Py_ssize_t (*writebufferproc) (PyObject *self, Py_ssize_t segment, void **ptrptr) 1423 1425 1424 1426 Return a pointer to a writable memory buffer in ``*ptrptr``, and the length of … … 1434 1436 1435 1437 1436 .. c type:: Py_ssize_t (*segcountproc) (PyObject *self, Py_ssize_t *lenp)1438 .. c:type:: Py_ssize_t (*segcountproc) (PyObject *self, Py_ssize_t *lenp) 1437 1439 1438 1440 Return the number of memory segments which comprise the buffer. If *lenp* is … … 1441 1443 1442 1444 1443 .. c type:: Py_ssize_t (*charbufferproc) (PyObject *self, Py_ssize_t segment, const char **ptrptr)1445 .. c:type:: Py_ssize_t (*charbufferproc) (PyObject *self, Py_ssize_t segment, const char **ptrptr) 1444 1446 1445 1447 Return the size of the segment *segment* that *ptrptr* is set to. ``*ptrptr`` -
python/vendor/current/Doc/c-api/unicode.rst
r2 r388 12 12 13 13 14 Unicode Type 15 """""""""""" 16 14 17 These are the basic Unicode object types used for the Unicode implementation in 15 18 Python: 16 19 17 .. % --- Unicode Type ------------------------------------------------------- 18 19 20 .. ctype:: Py_UNICODE 20 21 .. c:type:: Py_UNICODE 21 22 22 23 This type represents the storage type which is used by Python internally as 23 24 basis for holding Unicode ordinals. Python's default builds use a 16-bit type 24 for :c type:`Py_UNICODE` and store Unicode values internally as UCS2. It is also25 for :c:type:`Py_UNICODE` and store Unicode values internally as UCS2. It is also 25 26 possible to build a UCS4 version of Python (most recent Linux distributions come 26 27 with UCS4 builds of Python). These builds then use a 32-bit type for 27 :c type:`Py_UNICODE` and store Unicode data internally as UCS4. On platforms28 where :c type:`wchar_t` is available and compatible with the chosen Python29 Unicode build variant, :c type:`Py_UNICODE` is a typedef alias for30 :c type:`wchar_t` to enhance native platform compatibility. On all other31 platforms, :c type:`Py_UNICODE` is a typedef alias for either :ctype:`unsigned32 short` (UCS2) or :c type:`unsigned long` (UCS4).28 :c:type:`Py_UNICODE` and store Unicode data internally as UCS4. On platforms 29 where :c:type:`wchar_t` is available and compatible with the chosen Python 30 Unicode build variant, :c:type:`Py_UNICODE` is a typedef alias for 31 :c:type:`wchar_t` to enhance native platform compatibility. On all other 32 platforms, :c:type:`Py_UNICODE` is a typedef alias for either :c:type:`unsigned 33 short` (UCS2) or :c:type:`unsigned long` (UCS4). 33 34 34 35 Note that UCS2 and UCS4 Python builds are not binary compatible. Please keep … … 36 37 37 38 38 .. c type:: PyUnicodeObject39 40 This subtype of :c type:`PyObject` represents a Python Unicode object.41 42 43 .. c var:: PyTypeObject PyUnicode_Type44 45 This instance of :c type:`PyTypeObject` represents the Python Unicode type. It39 .. c:type:: PyUnicodeObject 40 41 This subtype of :c:type:`PyObject` represents a Python Unicode object. 42 43 44 .. c:var:: PyTypeObject PyUnicode_Type 45 46 This instance of :c:type:`PyTypeObject` represents the Python Unicode type. It 46 47 is exposed to Python code as ``unicode`` and ``types.UnicodeType``. 47 48 … … 50 51 51 52 52 .. c function:: int PyUnicode_Check(PyObject *o)53 .. c:function:: int PyUnicode_Check(PyObject *o) 53 54 54 55 Return true if the object *o* is a Unicode object or an instance of a Unicode … … 59 60 60 61 61 .. c function:: int PyUnicode_CheckExact(PyObject *o)62 .. c:function:: int PyUnicode_CheckExact(PyObject *o) 62 63 63 64 Return true if the object *o* is a Unicode object, but not an instance of a … … 67 68 68 69 69 .. c function:: Py_ssize_t PyUnicode_GET_SIZE(PyObject *o)70 71 Return the size of the object. *o* has to be a :c type:`PyUnicodeObject` (not70 .. c:function:: Py_ssize_t PyUnicode_GET_SIZE(PyObject *o) 71 72 Return the size of the object. *o* has to be a :c:type:`PyUnicodeObject` (not 72 73 checked). 73 74 74 75 .. versionchanged:: 2.5 75 This function returned an :c type:`int` type. This might require changes76 This function returned an :c:type:`int` type. This might require changes 76 77 in your code for properly supporting 64-bit systems. 77 78 78 79 79 .. c function:: Py_ssize_t PyUnicode_GET_DATA_SIZE(PyObject *o)80 .. c:function:: Py_ssize_t PyUnicode_GET_DATA_SIZE(PyObject *o) 80 81 81 82 Return the size of the object's internal buffer in bytes. *o* has to be a 82 :c type:`PyUnicodeObject` (not checked).83 84 .. versionchanged:: 2.5 85 This function returned an :c type:`int` type. This might require changes83 :c:type:`PyUnicodeObject` (not checked). 84 85 .. versionchanged:: 2.5 86 This function returned an :c:type:`int` type. This might require changes 86 87 in your code for properly supporting 64-bit systems. 87 88 88 89 89 .. c function:: Py_UNICODE* PyUnicode_AS_UNICODE(PyObject *o)90 91 Return a pointer to the internal :c type:`Py_UNICODE` buffer of the object. *o*92 has to be a :c type:`PyUnicodeObject` (not checked).93 94 95 .. c function:: const char* PyUnicode_AS_DATA(PyObject *o)90 .. c:function:: Py_UNICODE* PyUnicode_AS_UNICODE(PyObject *o) 91 92 Return a pointer to the internal :c:type:`Py_UNICODE` buffer of the object. *o* 93 has to be a :c:type:`PyUnicodeObject` (not checked). 94 95 96 .. c:function:: const char* PyUnicode_AS_DATA(PyObject *o) 96 97 97 98 Return a pointer to the internal buffer of the object. *o* has to be a 98 :c type:`PyUnicodeObject` (not checked).99 100 101 .. c function:: int PyUnicode_ClearFreeList()99 :c:type:`PyUnicodeObject` (not checked). 100 101 102 .. c:function:: int PyUnicode_ClearFreeList() 102 103 103 104 Clear the free list. Return the total number of freed items. … … 105 106 .. versionadded:: 2.6 106 107 108 109 Unicode Character Properties 110 """""""""""""""""""""""""""" 107 111 108 112 Unicode provides many different character properties. The most often needed ones … … 110 114 the Python configuration. 111 115 112 .. % --- Unicode character properties --------------------------------------- 113 114 115 .. cfunction:: int Py_UNICODE_ISSPACE(Py_UNICODE ch) 116 117 .. c:function:: int Py_UNICODE_ISSPACE(Py_UNICODE ch) 116 118 117 119 Return 1 or 0 depending on whether *ch* is a whitespace character. 118 120 119 121 120 .. c function:: int Py_UNICODE_ISLOWER(Py_UNICODE ch)122 .. c:function:: int Py_UNICODE_ISLOWER(Py_UNICODE ch) 121 123 122 124 Return 1 or 0 depending on whether *ch* is a lowercase character. 123 125 124 126 125 .. c function:: int Py_UNICODE_ISUPPER(Py_UNICODE ch)127 .. c:function:: int Py_UNICODE_ISUPPER(Py_UNICODE ch) 126 128 127 129 Return 1 or 0 depending on whether *ch* is an uppercase character. 128 130 129 131 130 .. c function:: int Py_UNICODE_ISTITLE(Py_UNICODE ch)132 .. c:function:: int Py_UNICODE_ISTITLE(Py_UNICODE ch) 131 133 132 134 Return 1 or 0 depending on whether *ch* is a titlecase character. 133 135 134 136 135 .. c function:: int Py_UNICODE_ISLINEBREAK(Py_UNICODE ch)137 .. c:function:: int Py_UNICODE_ISLINEBREAK(Py_UNICODE ch) 136 138 137 139 Return 1 or 0 depending on whether *ch* is a linebreak character. 138 140 139 141 140 .. c function:: int Py_UNICODE_ISDECIMAL(Py_UNICODE ch)142 .. c:function:: int Py_UNICODE_ISDECIMAL(Py_UNICODE ch) 141 143 142 144 Return 1 or 0 depending on whether *ch* is a decimal character. 143 145 144 146 145 .. c function:: int Py_UNICODE_ISDIGIT(Py_UNICODE ch)147 .. c:function:: int Py_UNICODE_ISDIGIT(Py_UNICODE ch) 146 148 147 149 Return 1 or 0 depending on whether *ch* is a digit character. 148 150 149 151 150 .. c function:: int Py_UNICODE_ISNUMERIC(Py_UNICODE ch)152 .. c:function:: int Py_UNICODE_ISNUMERIC(Py_UNICODE ch) 151 153 152 154 Return 1 or 0 depending on whether *ch* is a numeric character. 153 155 154 156 155 .. c function:: int Py_UNICODE_ISALPHA(Py_UNICODE ch)157 .. c:function:: int Py_UNICODE_ISALPHA(Py_UNICODE ch) 156 158 157 159 Return 1 or 0 depending on whether *ch* is an alphabetic character. 158 160 159 161 160 .. c function:: int Py_UNICODE_ISALNUM(Py_UNICODE ch)162 .. c:function:: int Py_UNICODE_ISALNUM(Py_UNICODE ch) 161 163 162 164 Return 1 or 0 depending on whether *ch* is an alphanumeric character. … … 165 167 166 168 167 .. c function:: Py_UNICODE Py_UNICODE_TOLOWER(Py_UNICODE ch)169 .. c:function:: Py_UNICODE Py_UNICODE_TOLOWER(Py_UNICODE ch) 168 170 169 171 Return the character *ch* converted to lower case. 170 172 171 173 172 .. c function:: Py_UNICODE Py_UNICODE_TOUPPER(Py_UNICODE ch)174 .. c:function:: Py_UNICODE Py_UNICODE_TOUPPER(Py_UNICODE ch) 173 175 174 176 Return the character *ch* converted to upper case. 175 177 176 178 177 .. c function:: Py_UNICODE Py_UNICODE_TOTITLE(Py_UNICODE ch)179 .. c:function:: Py_UNICODE Py_UNICODE_TOTITLE(Py_UNICODE ch) 178 180 179 181 Return the character *ch* converted to title case. 180 182 181 183 182 .. c function:: int Py_UNICODE_TODECIMAL(Py_UNICODE ch)184 .. c:function:: int Py_UNICODE_TODECIMAL(Py_UNICODE ch) 183 185 184 186 Return the character *ch* converted to a decimal positive integer. Return … … 186 188 187 189 188 .. c function:: int Py_UNICODE_TODIGIT(Py_UNICODE ch)190 .. c:function:: int Py_UNICODE_TODIGIT(Py_UNICODE ch) 189 191 190 192 Return the character *ch* converted to a single digit integer. Return ``-1`` if … … 192 194 193 195 194 .. c function:: double Py_UNICODE_TONUMERIC(Py_UNICODE ch)196 .. c:function:: double Py_UNICODE_TONUMERIC(Py_UNICODE ch) 195 197 196 198 Return the character *ch* converted to a double. Return ``-1.0`` if this is not 197 199 possible. This macro does not raise exceptions. 198 200 201 202 Plain Py_UNICODE 203 """""""""""""""" 204 199 205 To create Unicode objects and access their basic sequence properties, use these 200 206 APIs: 201 207 202 .. % --- Plain Py_UNICODE --------------------------------------------------- 203 204 205 .. cfunction:: PyObject* PyUnicode_FromUnicode(const Py_UNICODE *u, Py_ssize_t size) 206 207 Create a Unicode Object from the Py_UNICODE buffer *u* of the given size. *u* 208 209 .. c:function:: PyObject* PyUnicode_FromUnicode(const Py_UNICODE *u, Py_ssize_t size) 210 211 Create a Unicode object from the Py_UNICODE buffer *u* of the given size. *u* 208 212 may be *NULL* which causes the contents to be undefined. It is the user's 209 213 responsibility to fill in the needed data. The buffer is copied into the new … … 213 217 214 218 .. versionchanged:: 2.5 215 This function used an :ctype:`int` type for *size*. This might require 216 changes in your code for properly supporting 64-bit systems. 217 218 219 .. cfunction:: Py_UNICODE* PyUnicode_AsUnicode(PyObject *unicode) 220 221 Return a read-only pointer to the Unicode object's internal :ctype:`Py_UNICODE` 222 buffer, *NULL* if *unicode* is not a Unicode object. 223 224 225 .. cfunction:: Py_ssize_t PyUnicode_GetSize(PyObject *unicode) 219 This function used an :c:type:`int` type for *size*. This might require 220 changes in your code for properly supporting 64-bit systems. 221 222 223 .. c:function:: PyObject* PyUnicode_FromStringAndSize(const char *u, Py_ssize_t size) 224 225 Create a Unicode object from the char buffer *u*. The bytes will be interpreted 226 as being UTF-8 encoded. *u* may also be *NULL* which 227 causes the contents to be undefined. It is the user's responsibility to fill in 228 the needed data. The buffer is copied into the new object. If the buffer is not 229 *NULL*, the return value might be a shared object. Therefore, modification of 230 the resulting Unicode object is only allowed when *u* is *NULL*. 231 232 .. versionadded:: 2.6 233 234 235 .. c:function:: PyObject *PyUnicode_FromString(const char *u) 236 237 Create a Unicode object from an UTF-8 encoded null-terminated char buffer 238 *u*. 239 240 .. versionadded:: 2.6 241 242 243 .. c:function:: PyObject* PyUnicode_FromFormat(const char *format, ...) 244 245 Take a C :c:func:`printf`\ -style *format* string and a variable number of 246 arguments, calculate the size of the resulting Python unicode string and return 247 a string with the values formatted into it. The variable arguments must be C 248 types and must correspond exactly to the format characters in the *format* 249 string. The following format characters are allowed: 250 251 .. % The descriptions for %zd and %zu are wrong, but the truth is complicated 252 .. % because not all compilers support the %z width modifier -- we fake it 253 .. % when necessary via interpolating PY_FORMAT_SIZE_T. 254 255 .. tabularcolumns:: |l|l|L| 256 257 +-------------------+---------------------+--------------------------------+ 258 | Format Characters | Type | Comment | 259 +===================+=====================+================================+ 260 | :attr:`%%` | *n/a* | The literal % character. | 261 +-------------------+---------------------+--------------------------------+ 262 | :attr:`%c` | int | A single character, | 263 | | | represented as an C int. | 264 +-------------------+---------------------+--------------------------------+ 265 | :attr:`%d` | int | Exactly equivalent to | 266 | | | ``printf("%d")``. | 267 +-------------------+---------------------+--------------------------------+ 268 | :attr:`%u` | unsigned int | Exactly equivalent to | 269 | | | ``printf("%u")``. | 270 +-------------------+---------------------+--------------------------------+ 271 | :attr:`%ld` | long | Exactly equivalent to | 272 | | | ``printf("%ld")``. | 273 +-------------------+---------------------+--------------------------------+ 274 | :attr:`%lu` | unsigned long | Exactly equivalent to | 275 | | | ``printf("%lu")``. | 276 +-------------------+---------------------+--------------------------------+ 277 | :attr:`%zd` | Py_ssize_t | Exactly equivalent to | 278 | | | ``printf("%zd")``. | 279 +-------------------+---------------------+--------------------------------+ 280 | :attr:`%zu` | size_t | Exactly equivalent to | 281 | | | ``printf("%zu")``. | 282 +-------------------+---------------------+--------------------------------+ 283 | :attr:`%i` | int | Exactly equivalent to | 284 | | | ``printf("%i")``. | 285 +-------------------+---------------------+--------------------------------+ 286 | :attr:`%x` | int | Exactly equivalent to | 287 | | | ``printf("%x")``. | 288 +-------------------+---------------------+--------------------------------+ 289 | :attr:`%s` | char\* | A null-terminated C character | 290 | | | array. | 291 +-------------------+---------------------+--------------------------------+ 292 | :attr:`%p` | void\* | The hex representation of a C | 293 | | | pointer. Mostly equivalent to | 294 | | | ``printf("%p")`` except that | 295 | | | it is guaranteed to start with | 296 | | | the literal ``0x`` regardless | 297 | | | of what the platform's | 298 | | | ``printf`` yields. | 299 +-------------------+---------------------+--------------------------------+ 300 | :attr:`%U` | PyObject\* | A unicode object. | 301 +-------------------+---------------------+--------------------------------+ 302 | :attr:`%V` | PyObject\*, char \* | A unicode object (which may be | 303 | | | *NULL*) and a null-terminated | 304 | | | C character array as a second | 305 | | | parameter (which will be used, | 306 | | | if the first parameter is | 307 | | | *NULL*). | 308 +-------------------+---------------------+--------------------------------+ 309 | :attr:`%S` | PyObject\* | The result of calling | 310 | | | :func:`PyObject_Unicode`. | 311 +-------------------+---------------------+--------------------------------+ 312 | :attr:`%R` | PyObject\* | The result of calling | 313 | | | :func:`PyObject_Repr`. | 314 +-------------------+---------------------+--------------------------------+ 315 316 An unrecognized format character causes all the rest of the format string to be 317 copied as-is to the result string, and any extra arguments discarded. 318 319 .. versionadded:: 2.6 320 321 322 .. c:function:: PyObject* PyUnicode_FromFormatV(const char *format, va_list vargs) 323 324 Identical to :func:`PyUnicode_FromFormat` except that it takes exactly two 325 arguments. 326 327 .. versionadded:: 2.6 328 329 330 .. c:function:: Py_UNICODE* PyUnicode_AsUnicode(PyObject *unicode) 331 332 Return a read-only pointer to the Unicode object's internal 333 :c:type:`Py_UNICODE` buffer, *NULL* if *unicode* is not a Unicode object. 334 Note that the resulting :c:type:`Py_UNICODE*` string may contain embedded 335 null characters, which would cause the string to be truncated when used in 336 most C functions. 337 338 339 .. c:function:: Py_ssize_t PyUnicode_GetSize(PyObject *unicode) 226 340 227 341 Return the length of the Unicode object. 228 342 229 343 .. versionchanged:: 2.5 230 This function returned an :c type:`int` type. This might require changes344 This function returned an :c:type:`int` type. This might require changes 231 345 in your code for properly supporting 64-bit systems. 232 346 233 347 234 .. c function:: PyObject* PyUnicode_FromEncodedObject(PyObject *obj, const char *encoding, const char *errors)348 .. c:function:: PyObject* PyUnicode_FromEncodedObject(PyObject *obj, const char *encoding, const char *errors) 235 349 236 350 Coerce an encoded object *obj* to an Unicode object and return a reference with … … 249 363 250 364 251 .. c function:: PyObject* PyUnicode_FromObject(PyObject *obj)365 .. c:function:: PyObject* PyUnicode_FromObject(PyObject *obj) 252 366 253 367 Shortcut for ``PyUnicode_FromEncodedObject(obj, NULL, "strict")`` which is used 254 368 throughout the interpreter whenever coercion to Unicode is needed. 255 369 256 If the platform supports :c type:`wchar_t` and provides a header file wchar.h,370 If the platform supports :c:type:`wchar_t` and provides a header file wchar.h, 257 371 Python can interface directly to this type using the following functions. 258 Support is optimized if Python's own :ctype:`Py_UNICODE` type is identical to 259 the system's :ctype:`wchar_t`. 260 261 .. % --- wchar_t support for platforms which support it --------------------- 262 263 264 .. cfunction:: PyObject* PyUnicode_FromWideChar(const wchar_t *w, Py_ssize_t size) 265 266 Create a Unicode object from the :ctype:`wchar_t` buffer *w* of the given size. 372 Support is optimized if Python's own :c:type:`Py_UNICODE` type is identical to 373 the system's :c:type:`wchar_t`. 374 375 376 wchar_t Support 377 """"""""""""""" 378 379 :c:type:`wchar_t` support for platforms which support it: 380 381 .. c:function:: PyObject* PyUnicode_FromWideChar(const wchar_t *w, Py_ssize_t size) 382 383 Create a Unicode object from the :c:type:`wchar_t` buffer *w* of the given *size*. 267 384 Return *NULL* on failure. 268 385 269 386 .. versionchanged:: 2.5 270 This function used an :c type:`int` type for *size*. This might require271 changes in your code for properly supporting 64-bit systems. 272 273 274 .. c function:: Py_ssize_t PyUnicode_AsWideChar(PyUnicodeObject *unicode, wchar_t *w, Py_ssize_t size)275 276 Copy the Unicode object contents into the :c type:`wchar_t` buffer *w*. At most277 *size* :c type:`wchar_t` characters are copied (excluding a possibly trailing278 0-termination character). Return the number of :c type:`wchar_t` characters279 copied or -1 in case of an error. Note that the resulting :c type:`wchar_t`387 This function used an :c:type:`int` type for *size*. This might require 388 changes in your code for properly supporting 64-bit systems. 389 390 391 .. c:function:: Py_ssize_t PyUnicode_AsWideChar(PyUnicodeObject *unicode, wchar_t *w, Py_ssize_t size) 392 393 Copy the Unicode object contents into the :c:type:`wchar_t` buffer *w*. At most 394 *size* :c:type:`wchar_t` characters are copied (excluding a possibly trailing 395 0-termination character). Return the number of :c:type:`wchar_t` characters 396 copied or -1 in case of an error. Note that the resulting :c:type:`wchar_t` 280 397 string may or may not be 0-terminated. It is the responsibility of the caller 281 to make sure that the :ctype:`wchar_t` string is 0-terminated in case this is 282 required by the application. 283 284 .. versionchanged:: 2.5 285 This function returned an :ctype:`int` type and used an :ctype:`int` 398 to make sure that the :c:type:`wchar_t` string is 0-terminated in case this is 399 required by the application. Also, note that the :c:type:`wchar_t*` string 400 might contain null characters, which would cause the string to be truncated 401 when used with most C functions. 402 403 .. versionchanged:: 2.5 404 This function returned an :c:type:`int` type and used an :c:type:`int` 286 405 type for *size*. This might require changes in your code for properly 287 406 supporting 64-bit systems. … … 296 415 these codecs are directly usable via the following functions. 297 416 298 Many of the following APIs take two arguments encoding and errors . These299 parameters encoding and errors have the same semantics as the ones of the300 built-in :func:`unicode` Unicodeobject constructor.417 Many of the following APIs take two arguments encoding and errors, and they 418 have the same semantics as the ones of the built-in :func:`unicode` Unicode 419 object constructor. 301 420 302 421 Setting encoding to *NULL* causes the default encoding to be used which is 303 ASCII. The file system calls should use :c data:`Py_FileSystemDefaultEncoding`304 as the encoding for file names. This variable should be treated as read-only: On422 ASCII. The file system calls should use :c:data:`Py_FileSystemDefaultEncoding` 423 as the encoding for file names. This variable should be treated as read-only: on 305 424 some systems, it will be a pointer to a static string, on others, it will change 306 425 at run-time (such as when the application invokes setlocale). … … 313 432 generic ones are documented for simplicity. 314 433 434 435 Generic Codecs 436 """""""""""""" 437 315 438 These are the generic codec APIs: 316 439 317 .. % --- Generic Codecs ----------------------------------------------------- 318 319 320 .. cfunction:: PyObject* PyUnicode_Decode(const char *s, Py_ssize_t size, const char *encoding, const char *errors) 440 441 .. c:function:: PyObject* PyUnicode_Decode(const char *s, Py_ssize_t size, const char *encoding, const char *errors) 321 442 322 443 Create a Unicode object by decoding *size* bytes of the encoded string *s*. … … 327 448 328 449 .. versionchanged:: 2.5 329 This function used an :c type:`int` type for *size*. This might require330 changes in your code for properly supporting 64-bit systems. 331 332 333 .. c function:: PyObject* PyUnicode_Encode(const Py_UNICODE *s, Py_ssize_t size, const char *encoding, const char *errors)334 335 Encode the :c type:`Py_UNICODE` buffer of the given sizeand return a Python450 This function used an :c:type:`int` type for *size*. This might require 451 changes in your code for properly supporting 64-bit systems. 452 453 454 .. c:function:: PyObject* PyUnicode_Encode(const Py_UNICODE *s, Py_ssize_t size, const char *encoding, const char *errors) 455 456 Encode the :c:type:`Py_UNICODE` buffer *s* of the given *size* and return a Python 336 457 string object. *encoding* and *errors* have the same meaning as the parameters 337 of the same name in the Unicode :meth:` encode` method. The codec to be used is338 looked up using the Python codec registry. Return *NULL* if an exception was339 raised by the codec.340 341 .. versionchanged:: 2.5 342 This function used an :c type:`int` type for *size*. This might require343 changes in your code for properly supporting 64-bit systems. 344 345 346 .. c function:: PyObject* PyUnicode_AsEncodedString(PyObject *unicode, const char *encoding, const char *errors)458 of the same name in the Unicode :meth:`~unicode.encode` method. The codec 459 to be used is looked up using the Python codec registry. Return *NULL* if 460 an exception was raised by the codec. 461 462 .. versionchanged:: 2.5 463 This function used an :c:type:`int` type for *size*. This might require 464 changes in your code for properly supporting 64-bit systems. 465 466 467 .. c:function:: PyObject* PyUnicode_AsEncodedString(PyObject *unicode, const char *encoding, const char *errors) 347 468 348 469 Encode a Unicode object and return the result as Python string object. … … 352 473 codec. 353 474 475 476 UTF-8 Codecs 477 """""""""""" 478 354 479 These are the UTF-8 codec APIs: 355 480 356 .. % --- UTF-8 Codecs ------------------------------------------------------- 357 358 359 .. cfunction:: PyObject* PyUnicode_DecodeUTF8(const char *s, Py_ssize_t size, const char *errors) 481 482 .. c:function:: PyObject* PyUnicode_DecodeUTF8(const char *s, Py_ssize_t size, const char *errors) 360 483 361 484 Create a Unicode object by decoding *size* bytes of the UTF-8 encoded string … … 363 486 364 487 .. versionchanged:: 2.5 365 This function used an :c type:`int` type for *size*. This might require366 changes in your code for properly supporting 64-bit systems. 367 368 369 .. c function:: PyObject* PyUnicode_DecodeUTF8Stateful(const char *s, Py_ssize_t size, const char *errors, Py_ssize_t *consumed)370 371 If *consumed* is *NULL*, behave like :c func:`PyUnicode_DecodeUTF8`. If488 This function used an :c:type:`int` type for *size*. This might require 489 changes in your code for properly supporting 64-bit systems. 490 491 492 .. c:function:: PyObject* PyUnicode_DecodeUTF8Stateful(const char *s, Py_ssize_t size, const char *errors, Py_ssize_t *consumed) 493 494 If *consumed* is *NULL*, behave like :c:func:`PyUnicode_DecodeUTF8`. If 372 495 *consumed* is not *NULL*, trailing incomplete UTF-8 byte sequences will not be 373 496 treated as an error. Those bytes will not be decoded and the number of bytes … … 377 500 378 501 .. versionchanged:: 2.5 379 This function used an :c type:`int` type for *size*. This might require380 changes in your code for properly supporting 64-bit systems. 381 382 383 .. c function:: PyObject* PyUnicode_EncodeUTF8(const Py_UNICODE *s, Py_ssize_t size, const char *errors)384 385 Encode the :c type:`Py_UNICODE` buffer of the given sizeusing UTF-8 and return a502 This function used an :c:type:`int` type for *size*. This might require 503 changes in your code for properly supporting 64-bit systems. 504 505 506 .. c:function:: PyObject* PyUnicode_EncodeUTF8(const Py_UNICODE *s, Py_ssize_t size, const char *errors) 507 508 Encode the :c:type:`Py_UNICODE` buffer *s* of the given *size* using UTF-8 and return a 386 509 Python string object. Return *NULL* if an exception was raised by the codec. 387 510 388 511 .. versionchanged:: 2.5 389 This function used an :c type:`int` type for *size*. This might require390 changes in your code for properly supporting 64-bit systems. 391 392 393 .. c function:: PyObject* PyUnicode_AsUTF8String(PyObject *unicode)512 This function used an :c:type:`int` type for *size*. This might require 513 changes in your code for properly supporting 64-bit systems. 514 515 516 .. c:function:: PyObject* PyUnicode_AsUTF8String(PyObject *unicode) 394 517 395 518 Encode a Unicode object using UTF-8 and return the result as Python string … … 397 520 by the codec. 398 521 522 523 UTF-32 Codecs 524 """"""""""""" 525 399 526 These are the UTF-32 codec APIs: 400 527 401 .. % --- UTF-32 Codecs ------------------------------------------------------ */ 402 403 404 .. cfunction:: PyObject* PyUnicode_DecodeUTF32(const char *s, Py_ssize_t size, const char *errors, int *byteorder) 405 406 Decode *length* bytes from a UTF-32 encoded buffer string and return the 528 529 .. c:function:: PyObject* PyUnicode_DecodeUTF32(const char *s, Py_ssize_t size, const char *errors, int *byteorder) 530 531 Decode *size* bytes from a UTF-32 encoded buffer string and return the 407 532 corresponding Unicode object. *errors* (if non-*NULL*) defines the error 408 533 handling. It defaults to "strict". … … 432 557 433 558 434 .. c function:: PyObject* PyUnicode_DecodeUTF32Stateful(const char *s, Py_ssize_t size, const char *errors, int *byteorder, Py_ssize_t *consumed)435 436 If *consumed* is *NULL*, behave like :c func:`PyUnicode_DecodeUTF32`. If437 *consumed* is not *NULL*, :c func:`PyUnicode_DecodeUTF32Stateful` will not treat559 .. c:function:: PyObject* PyUnicode_DecodeUTF32Stateful(const char *s, Py_ssize_t size, const char *errors, int *byteorder, Py_ssize_t *consumed) 560 561 If *consumed* is *NULL*, behave like :c:func:`PyUnicode_DecodeUTF32`. If 562 *consumed* is not *NULL*, :c:func:`PyUnicode_DecodeUTF32Stateful` will not treat 438 563 trailing incomplete UTF-32 byte sequences (such as a number of bytes not divisible 439 564 by four) as an error. Those bytes will not be decoded and the number of bytes … … 443 568 444 569 445 .. c function:: PyObject* PyUnicode_EncodeUTF32(const Py_UNICODE *s, Py_ssize_t size, const char *errors, int byteorder)570 .. c:function:: PyObject* PyUnicode_EncodeUTF32(const Py_UNICODE *s, Py_ssize_t size, const char *errors, int byteorder) 446 571 447 572 Return a Python bytes object holding the UTF-32 encoded value of the Unicode … … 463 588 464 589 465 .. c function:: PyObject* PyUnicode_AsUTF32String(PyObject *unicode)590 .. c:function:: PyObject* PyUnicode_AsUTF32String(PyObject *unicode) 466 591 467 592 Return a Python string using the UTF-32 encoding in native byte order. The … … 472 597 473 598 599 UTF-16 Codecs 600 """"""""""""" 601 474 602 These are the UTF-16 codec APIs: 475 603 476 .. % --- UTF-16 Codecs ------------------------------------------------------ */ 477 478 479 .. cfunction:: PyObject* PyUnicode_DecodeUTF16(const char *s, Py_ssize_t size, const char *errors, int *byteorder) 480 481 Decode *length* bytes from a UTF-16 encoded buffer string and return the 604 605 .. c:function:: PyObject* PyUnicode_DecodeUTF16(const char *s, Py_ssize_t size, const char *errors, int *byteorder) 606 607 Decode *size* bytes from a UTF-16 encoded buffer string and return the 482 608 corresponding Unicode object. *errors* (if non-*NULL*) defines the error 483 609 handling. It defaults to "strict". … … 504 630 505 631 .. versionchanged:: 2.5 506 This function used an :c type:`int` type for *size*. This might require507 changes in your code for properly supporting 64-bit systems. 508 509 510 .. c function:: PyObject* PyUnicode_DecodeUTF16Stateful(const char *s, Py_ssize_t size, const char *errors, int *byteorder, Py_ssize_t *consumed)511 512 If *consumed* is *NULL*, behave like :c func:`PyUnicode_DecodeUTF16`. If513 *consumed* is not *NULL*, :c func:`PyUnicode_DecodeUTF16Stateful` will not treat632 This function used an :c:type:`int` type for *size*. This might require 633 changes in your code for properly supporting 64-bit systems. 634 635 636 .. c:function:: PyObject* PyUnicode_DecodeUTF16Stateful(const char *s, Py_ssize_t size, const char *errors, int *byteorder, Py_ssize_t *consumed) 637 638 If *consumed* is *NULL*, behave like :c:func:`PyUnicode_DecodeUTF16`. If 639 *consumed* is not *NULL*, :c:func:`PyUnicode_DecodeUTF16Stateful` will not treat 514 640 trailing incomplete UTF-16 byte sequences (such as an odd number of bytes or a 515 641 split surrogate pair) as an error. Those bytes will not be decoded and the … … 519 645 520 646 .. versionchanged:: 2.5 521 This function used an :c type:`int` type for *size* and an :ctype:`int *`647 This function used an :c:type:`int` type for *size* and an :c:type:`int *` 522 648 type for *consumed*. This might require changes in your code for 523 649 properly supporting 64-bit systems. 524 650 525 651 526 .. c function:: PyObject* PyUnicode_EncodeUTF16(const Py_UNICODE *s, Py_ssize_t size, const char *errors, int byteorder)652 .. c:function:: PyObject* PyUnicode_EncodeUTF16(const Py_UNICODE *s, Py_ssize_t size, const char *errors, int byteorder) 527 653 528 654 Return a Python string object holding the UTF-16 encoded value of the Unicode … … 536 662 mark (U+FEFF). In the other two modes, no BOM mark is prepended. 537 663 538 If *Py_UNICODE_WIDE* is defined, a single :c type:`Py_UNICODE` value may get539 represented as a surrogate pair. If it is not defined, each :c type:`Py_UNICODE`664 If *Py_UNICODE_WIDE* is defined, a single :c:type:`Py_UNICODE` value may get 665 represented as a surrogate pair. If it is not defined, each :c:type:`Py_UNICODE` 540 666 values is interpreted as an UCS-2 character. 541 667 … … 543 669 544 670 .. versionchanged:: 2.5 545 This function used an :c type:`int` type for *size*. This might require546 changes in your code for properly supporting 64-bit systems. 547 548 549 .. c function:: PyObject* PyUnicode_AsUTF16String(PyObject *unicode)671 This function used an :c:type:`int` type for *size*. This might require 672 changes in your code for properly supporting 64-bit systems. 673 674 675 .. c:function:: PyObject* PyUnicode_AsUTF16String(PyObject *unicode) 550 676 551 677 Return a Python string using the UTF-16 encoding in native byte order. The … … 553 679 *NULL* if an exception was raised by the codec. 554 680 681 682 UTF-7 Codecs 683 """""""""""" 684 685 These are the UTF-7 codec APIs: 686 687 688 .. c:function:: PyObject* PyUnicode_DecodeUTF7(const char *s, Py_ssize_t size, const char *errors) 689 690 Create a Unicode object by decoding *size* bytes of the UTF-7 encoded string 691 *s*. Return *NULL* if an exception was raised by the codec. 692 693 694 .. c:function:: PyObject* PyUnicode_DecodeUTF7Stateful(const char *s, Py_ssize_t size, const char *errors, Py_ssize_t *consumed) 695 696 If *consumed* is *NULL*, behave like :c:func:`PyUnicode_DecodeUTF7`. If 697 *consumed* is not *NULL*, trailing incomplete UTF-7 base-64 sections will not 698 be treated as an error. Those bytes will not be decoded and the number of 699 bytes that have been decoded will be stored in *consumed*. 700 701 702 .. c:function:: PyObject* PyUnicode_EncodeUTF7(const Py_UNICODE *s, Py_ssize_t size, int base64SetO, int base64WhiteSpace, const char *errors) 703 704 Encode the :c:type:`Py_UNICODE` buffer of the given size using UTF-7 and 705 return a Python bytes object. Return *NULL* if an exception was raised by 706 the codec. 707 708 If *base64SetO* is nonzero, "Set O" (punctuation that has no otherwise 709 special meaning) will be encoded in base-64. If *base64WhiteSpace* is 710 nonzero, whitespace will be encoded in base-64. Both are set to zero for the 711 Python "utf-7" codec. 712 713 714 Unicode-Escape Codecs 715 """"""""""""""""""""" 716 555 717 These are the "Unicode Escape" codec APIs: 556 718 557 .. % --- Unicode-Escape Codecs ---------------------------------------------- 558 559 560 .. cfunction:: PyObject* PyUnicode_DecodeUnicodeEscape(const char *s, Py_ssize_t size, const char *errors) 719 720 .. c:function:: PyObject* PyUnicode_DecodeUnicodeEscape(const char *s, Py_ssize_t size, const char *errors) 561 721 562 722 Create a Unicode object by decoding *size* bytes of the Unicode-Escape encoded … … 564 724 565 725 .. versionchanged:: 2.5 566 This function used an :c type:`int` type for *size*. This might require567 changes in your code for properly supporting 64-bit systems. 568 569 570 .. c function:: PyObject* PyUnicode_EncodeUnicodeEscape(const Py_UNICODE *s, Py_ssize_t size)571 572 Encode the :c type:`Py_UNICODE` buffer of the given sizeusing Unicode-Escape and726 This function used an :c:type:`int` type for *size*. This might require 727 changes in your code for properly supporting 64-bit systems. 728 729 730 .. c:function:: PyObject* PyUnicode_EncodeUnicodeEscape(const Py_UNICODE *s, Py_ssize_t size) 731 732 Encode the :c:type:`Py_UNICODE` buffer of the given *size* using Unicode-Escape and 573 733 return a Python string object. Return *NULL* if an exception was raised by the 574 734 codec. 575 735 576 736 .. versionchanged:: 2.5 577 This function used an :c type:`int` type for *size*. This might require578 changes in your code for properly supporting 64-bit systems. 579 580 581 .. c function:: PyObject* PyUnicode_AsUnicodeEscapeString(PyObject *unicode)737 This function used an :c:type:`int` type for *size*. This might require 738 changes in your code for properly supporting 64-bit systems. 739 740 741 .. c:function:: PyObject* PyUnicode_AsUnicodeEscapeString(PyObject *unicode) 582 742 583 743 Encode a Unicode object using Unicode-Escape and return the result as Python … … 585 745 raised by the codec. 586 746 747 748 Raw-Unicode-Escape Codecs 749 """"""""""""""""""""""""" 750 587 751 These are the "Raw Unicode Escape" codec APIs: 588 752 589 .. % --- Raw-Unicode-Escape Codecs ------------------------------------------ 590 591 592 .. cfunction:: PyObject* PyUnicode_DecodeRawUnicodeEscape(const char *s, Py_ssize_t size, const char *errors) 753 754 .. c:function:: PyObject* PyUnicode_DecodeRawUnicodeEscape(const char *s, Py_ssize_t size, const char *errors) 593 755 594 756 Create a Unicode object by decoding *size* bytes of the Raw-Unicode-Escape … … 596 758 597 759 .. versionchanged:: 2.5 598 This function used an :c type:`int` type for *size*. This might require599 changes in your code for properly supporting 64-bit systems. 600 601 602 .. c function:: PyObject* PyUnicode_EncodeRawUnicodeEscape(const Py_UNICODE *s, Py_ssize_t size, const char *errors)603 604 Encode the :c type:`Py_UNICODE` buffer of the given sizeusing Raw-Unicode-Escape760 This function used an :c:type:`int` type for *size*. This might require 761 changes in your code for properly supporting 64-bit systems. 762 763 764 .. c:function:: PyObject* PyUnicode_EncodeRawUnicodeEscape(const Py_UNICODE *s, Py_ssize_t size, const char *errors) 765 766 Encode the :c:type:`Py_UNICODE` buffer of the given *size* using Raw-Unicode-Escape 605 767 and return a Python string object. Return *NULL* if an exception was raised by 606 768 the codec. 607 769 608 770 .. versionchanged:: 2.5 609 This function used an :c type:`int` type for *size*. This might require610 changes in your code for properly supporting 64-bit systems. 611 612 613 .. c function:: PyObject* PyUnicode_AsRawUnicodeEscapeString(PyObject *unicode)771 This function used an :c:type:`int` type for *size*. This might require 772 changes in your code for properly supporting 64-bit systems. 773 774 775 .. c:function:: PyObject* PyUnicode_AsRawUnicodeEscapeString(PyObject *unicode) 614 776 615 777 Encode a Unicode object using Raw-Unicode-Escape and return the result as … … 617 779 was raised by the codec. 618 780 781 782 Latin-1 Codecs 783 """""""""""""" 784 619 785 These are the Latin-1 codec APIs: Latin-1 corresponds to the first 256 Unicode 620 786 ordinals and only these are accepted by the codecs during encoding. 621 787 622 .. % --- Latin-1 Codecs ----------------------------------------------------- 623 624 625 .. cfunction:: PyObject* PyUnicode_DecodeLatin1(const char *s, Py_ssize_t size, const char *errors) 788 789 .. c:function:: PyObject* PyUnicode_DecodeLatin1(const char *s, Py_ssize_t size, const char *errors) 626 790 627 791 Create a Unicode object by decoding *size* bytes of the Latin-1 encoded string … … 629 793 630 794 .. versionchanged:: 2.5 631 This function used an :c type:`int` type for *size*. This might require632 changes in your code for properly supporting 64-bit systems. 633 634 635 .. c function:: PyObject* PyUnicode_EncodeLatin1(const Py_UNICODE *s, Py_ssize_t size, const char *errors)636 637 Encode the :c type:`Py_UNICODE` buffer of the given sizeusing Latin-1 and return795 This function used an :c:type:`int` type for *size*. This might require 796 changes in your code for properly supporting 64-bit systems. 797 798 799 .. c:function:: PyObject* PyUnicode_EncodeLatin1(const Py_UNICODE *s, Py_ssize_t size, const char *errors) 800 801 Encode the :c:type:`Py_UNICODE` buffer of the given *size* using Latin-1 and return 638 802 a Python string object. Return *NULL* if an exception was raised by the codec. 639 803 640 804 .. versionchanged:: 2.5 641 This function used an :c type:`int` type for *size*. This might require642 changes in your code for properly supporting 64-bit systems. 643 644 645 .. c function:: PyObject* PyUnicode_AsLatin1String(PyObject *unicode)805 This function used an :c:type:`int` type for *size*. This might require 806 changes in your code for properly supporting 64-bit systems. 807 808 809 .. c:function:: PyObject* PyUnicode_AsLatin1String(PyObject *unicode) 646 810 647 811 Encode a Unicode object using Latin-1 and return the result as Python string … … 649 813 by the codec. 650 814 815 816 ASCII Codecs 817 """""""""""" 818 651 819 These are the ASCII codec APIs. Only 7-bit ASCII data is accepted. All other 652 820 codes generate errors. 653 821 654 .. % --- ASCII Codecs ------------------------------------------------------- 655 656 657 .. cfunction:: PyObject* PyUnicode_DecodeASCII(const char *s, Py_ssize_t size, const char *errors) 822 823 .. c:function:: PyObject* PyUnicode_DecodeASCII(const char *s, Py_ssize_t size, const char *errors) 658 824 659 825 Create a Unicode object by decoding *size* bytes of the ASCII encoded string … … 661 827 662 828 .. versionchanged:: 2.5 663 This function used an :c type:`int` type for *size*. This might require664 changes in your code for properly supporting 64-bit systems. 665 666 667 .. c function:: PyObject* PyUnicode_EncodeASCII(const Py_UNICODE *s, Py_ssize_t size, const char *errors)668 669 Encode the :c type:`Py_UNICODE` buffer of the given sizeusing ASCII and return a829 This function used an :c:type:`int` type for *size*. This might require 830 changes in your code for properly supporting 64-bit systems. 831 832 833 .. c:function:: PyObject* PyUnicode_EncodeASCII(const Py_UNICODE *s, Py_ssize_t size, const char *errors) 834 835 Encode the :c:type:`Py_UNICODE` buffer of the given *size* using ASCII and return a 670 836 Python string object. Return *NULL* if an exception was raised by the codec. 671 837 672 838 .. versionchanged:: 2.5 673 This function used an :c type:`int` type for *size*. This might require674 changes in your code for properly supporting 64-bit systems. 675 676 677 .. c function:: PyObject* PyUnicode_AsASCIIString(PyObject *unicode)839 This function used an :c:type:`int` type for *size*. This might require 840 changes in your code for properly supporting 64-bit systems. 841 842 843 .. c:function:: PyObject* PyUnicode_AsASCIIString(PyObject *unicode) 678 844 679 845 Encode a Unicode object using ASCII and return the result as Python string … … 681 847 by the codec. 682 848 683 These are the mapping codec APIs: 684 685 .. % --- Character Map Codecs ----------------------------------------------- 849 850 Character Map Codecs 851 """""""""""""""""""" 686 852 687 853 This codec is special in that it can be used to implement many different codecs … … 706 872 characters to different code points. 707 873 708 709 .. cfunction:: PyObject* PyUnicode_DecodeCharmap(const char *s, Py_ssize_t size, PyObject *mapping, const char *errors) 874 These are the mapping codec APIs: 875 876 .. c:function:: PyObject* PyUnicode_DecodeCharmap(const char *s, Py_ssize_t size, PyObject *mapping, const char *errors) 710 877 711 878 Create a Unicode object by decoding *size* bytes of the encoded string *s* using … … 720 887 721 888 .. versionchanged:: 2.5 722 This function used an :c type:`int` type for *size*. This might require723 changes in your code for properly supporting 64-bit systems. 724 725 726 .. c function:: PyObject* PyUnicode_EncodeCharmap(const Py_UNICODE *s, Py_ssize_t size, PyObject *mapping, const char *errors)727 728 Encode the :c type:`Py_UNICODE` buffer of the given sizeusing the given889 This function used an :c:type:`int` type for *size*. This might require 890 changes in your code for properly supporting 64-bit systems. 891 892 893 .. c:function:: PyObject* PyUnicode_EncodeCharmap(const Py_UNICODE *s, Py_ssize_t size, PyObject *mapping, const char *errors) 894 895 Encode the :c:type:`Py_UNICODE` buffer of the given *size* using the given 729 896 *mapping* object and return a Python string object. Return *NULL* if an 730 897 exception was raised by the codec. 731 898 732 899 .. versionchanged:: 2.5 733 This function used an :c type:`int` type for *size*. This might require734 changes in your code for properly supporting 64-bit systems. 735 736 737 .. c function:: PyObject* PyUnicode_AsCharmapString(PyObject *unicode, PyObject *mapping)900 This function used an :c:type:`int` type for *size*. This might require 901 changes in your code for properly supporting 64-bit systems. 902 903 904 .. c:function:: PyObject* PyUnicode_AsCharmapString(PyObject *unicode, PyObject *mapping) 738 905 739 906 Encode a Unicode object using the given *mapping* object and return the result … … 744 911 745 912 746 .. c function:: PyObject* PyUnicode_TranslateCharmap(const Py_UNICODE *s, Py_ssize_t size, PyObject *table, const char *errors)747 748 Translate a :c type:`Py_UNICODE` buffer of the given lengthby applying a913 .. c:function:: PyObject* PyUnicode_TranslateCharmap(const Py_UNICODE *s, Py_ssize_t size, PyObject *table, const char *errors) 914 915 Translate a :c:type:`Py_UNICODE` buffer of the given *size* by applying a 749 916 character mapping *table* to it and return the resulting Unicode object. Return 750 917 *NULL* when an exception was raised by the codec. … … 758 925 759 926 .. versionchanged:: 2.5 760 This function used an :ctype:`int` type for *size*. This might require 761 changes in your code for properly supporting 64-bit systems. 927 This function used an :c:type:`int` type for *size*. This might require 928 changes in your code for properly supporting 64-bit systems. 929 930 931 MBCS codecs for Windows 932 """"""""""""""""""""""" 762 933 763 934 These are the MBCS codec APIs. They are currently only available on Windows and … … 766 937 the user settings on the machine running the codec. 767 938 768 .. % --- MBCS codecs for Windows -------------------------------------------- 769 770 771 .. cfunction:: PyObject* PyUnicode_DecodeMBCS(const char *s, Py_ssize_t size, const char *errors) 939 940 .. c:function:: PyObject* PyUnicode_DecodeMBCS(const char *s, Py_ssize_t size, const char *errors) 772 941 773 942 Create a Unicode object by decoding *size* bytes of the MBCS encoded string *s*. … … 775 944 776 945 .. versionchanged:: 2.5 777 This function used an :c type:`int` type for *size*. This might require778 changes in your code for properly supporting 64-bit systems. 779 780 781 .. c function:: PyObject* PyUnicode_DecodeMBCSStateful(const char *s, int size, const char *errors, int *consumed)782 783 If *consumed* is *NULL*, behave like :c func:`PyUnicode_DecodeMBCS`. If784 *consumed* is not *NULL*, :c func:`PyUnicode_DecodeMBCSStateful` will not decode946 This function used an :c:type:`int` type for *size*. This might require 947 changes in your code for properly supporting 64-bit systems. 948 949 950 .. c:function:: PyObject* PyUnicode_DecodeMBCSStateful(const char *s, int size, const char *errors, int *consumed) 951 952 If *consumed* is *NULL*, behave like :c:func:`PyUnicode_DecodeMBCS`. If 953 *consumed* is not *NULL*, :c:func:`PyUnicode_DecodeMBCSStateful` will not decode 785 954 trailing lead byte and the number of bytes that have been decoded will be stored 786 955 in *consumed*. … … 789 958 790 959 791 .. c function:: PyObject* PyUnicode_EncodeMBCS(const Py_UNICODE *s, Py_ssize_t size, const char *errors)792 793 Encode the :c type:`Py_UNICODE` buffer of the given sizeusing MBCS and return a960 .. c:function:: PyObject* PyUnicode_EncodeMBCS(const Py_UNICODE *s, Py_ssize_t size, const char *errors) 961 962 Encode the :c:type:`Py_UNICODE` buffer of the given *size* using MBCS and return a 794 963 Python string object. Return *NULL* if an exception was raised by the codec. 795 964 796 965 .. versionchanged:: 2.5 797 This function used an :c type:`int` type for *size*. This might require798 changes in your code for properly supporting 64-bit systems. 799 800 801 .. c function:: PyObject* PyUnicode_AsMBCSString(PyObject *unicode)966 This function used an :c:type:`int` type for *size*. This might require 967 changes in your code for properly supporting 64-bit systems. 968 969 970 .. c:function:: PyObject* PyUnicode_AsMBCSString(PyObject *unicode) 802 971 803 972 Encode a Unicode object using MBCS and return the result as Python string … … 805 974 by the codec. 806 975 807 .. % --- Methods & Slots ---------------------------------------------------- 808 976 977 Methods & Slots 978 """"""""""""""" 809 979 810 980 .. _unicodemethodsandslots: … … 820 990 821 991 822 .. c function:: PyObject* PyUnicode_Concat(PyObject *left, PyObject *right)992 .. c:function:: PyObject* PyUnicode_Concat(PyObject *left, PyObject *right) 823 993 824 994 Concat two strings giving a new Unicode string. 825 995 826 996 827 .. c function:: PyObject* PyUnicode_Split(PyObject *s, PyObject *sep, Py_ssize_t maxsplit)828 829 Split a string giving a list of Unicode strings. If sepis *NULL*, splitting997 .. c:function:: PyObject* PyUnicode_Split(PyObject *s, PyObject *sep, Py_ssize_t maxsplit) 998 999 Split a string giving a list of Unicode strings. If *sep* is *NULL*, splitting 830 1000 will be done at all whitespace substrings. Otherwise, splits occur at the given 831 1001 separator. At most *maxsplit* splits will be done. If negative, no limit is … … 833 1003 834 1004 .. versionchanged:: 2.5 835 This function used an :c type:`int` type for *maxsplit*. This might require836 changes in your code for properly supporting 64-bit systems. 837 838 839 .. c function:: PyObject* PyUnicode_Splitlines(PyObject *s, int keepend)1005 This function used an :c:type:`int` type for *maxsplit*. This might require 1006 changes in your code for properly supporting 64-bit systems. 1007 1008 1009 .. c:function:: PyObject* PyUnicode_Splitlines(PyObject *s, int keepend) 840 1010 841 1011 Split a Unicode string at line breaks, returning a list of Unicode strings. … … 844 1014 845 1015 846 .. c function:: PyObject* PyUnicode_Translate(PyObject *str, PyObject *table, const char *errors)1016 .. c:function:: PyObject* PyUnicode_Translate(PyObject *str, PyObject *table, const char *errors) 847 1017 848 1018 Translate a string by applying a character mapping table to it and return the … … 860 1030 861 1031 862 .. c function:: PyObject* PyUnicode_Join(PyObject *separator, PyObject *seq)863 864 Join a sequence of strings using the given separatorand return the resulting1032 .. c:function:: PyObject* PyUnicode_Join(PyObject *separator, PyObject *seq) 1033 1034 Join a sequence of strings using the given *separator* and return the resulting 865 1035 Unicode string. 866 1036 867 1037 868 .. c function:: int PyUnicode_Tailmatch(PyObject *str, PyObject *substr, Py_ssize_t start, Py_ssize_t end, int direction)869 870 Return 1 if *substr* matches *str*[*start*:*end*]at the given tail end1038 .. c:function:: int PyUnicode_Tailmatch(PyObject *str, PyObject *substr, Py_ssize_t start, Py_ssize_t end, int direction) 1039 1040 Return 1 if *substr* matches ``str[start:end]`` at the given tail end 871 1041 (*direction* == -1 means to do a prefix match, *direction* == 1 a suffix match), 872 1042 0 otherwise. Return ``-1`` if an error occurred. 873 1043 874 1044 .. versionchanged:: 2.5 875 This function used an :c type:`int` type for *start* and *end*. This1045 This function used an :c:type:`int` type for *start* and *end*. This 876 1046 might require changes in your code for properly supporting 64-bit 877 1047 systems. 878 1048 879 1049 880 .. c function:: Py_ssize_t PyUnicode_Find(PyObject *str, PyObject *substr, Py_ssize_t start, Py_ssize_t end, int direction)881 882 Return the first position of *substr* in *str*[*start*:*end*]using the given1050 .. c:function:: Py_ssize_t PyUnicode_Find(PyObject *str, PyObject *substr, Py_ssize_t start, Py_ssize_t end, int direction) 1051 1052 Return the first position of *substr* in ``str[start:end]`` using the given 883 1053 *direction* (*direction* == 1 means to do a forward search, *direction* == -1 a 884 1054 backward search). The return value is the index of the first match; a value of … … 887 1057 888 1058 .. versionchanged:: 2.5 889 This function used an :c type:`int` type for *start* and *end*. This1059 This function used an :c:type:`int` type for *start* and *end*. This 890 1060 might require changes in your code for properly supporting 64-bit 891 1061 systems. 892 1062 893 1063 894 .. c function:: Py_ssize_t PyUnicode_Count(PyObject *str, PyObject *substr, Py_ssize_t start, Py_ssize_t end)1064 .. c:function:: Py_ssize_t PyUnicode_Count(PyObject *str, PyObject *substr, Py_ssize_t start, Py_ssize_t end) 895 1065 896 1066 Return the number of non-overlapping occurrences of *substr* in … … 898 1068 899 1069 .. versionchanged:: 2.5 900 This function returned an :c type:`int` type and used an :ctype:`int`1070 This function returned an :c:type:`int` type and used an :c:type:`int` 901 1071 type for *start* and *end*. This might require changes in your code for 902 1072 properly supporting 64-bit systems. 903 1073 904 1074 905 .. c function:: PyObject* PyUnicode_Replace(PyObject *str, PyObject *substr, PyObject *replstr, Py_ssize_t maxcount)1075 .. c:function:: PyObject* PyUnicode_Replace(PyObject *str, PyObject *substr, PyObject *replstr, Py_ssize_t maxcount) 906 1076 907 1077 Replace at most *maxcount* occurrences of *substr* in *str* with *replstr* and … … 910 1080 911 1081 .. versionchanged:: 2.5 912 This function used an :c type:`int` type for *maxcount*. This might1082 This function used an :c:type:`int` type for *maxcount*. This might 913 1083 require changes in your code for properly supporting 64-bit systems. 914 1084 915 1085 916 .. c function:: int PyUnicode_Compare(PyObject *left, PyObject *right)1086 .. c:function:: int PyUnicode_Compare(PyObject *left, PyObject *right) 917 1087 918 1088 Compare two strings and return -1, 0, 1 for less than, equal, and greater than, … … 920 1090 921 1091 922 .. c function:: int PyUnicode_RichCompare(PyObject *left, PyObject *right, int op)1092 .. c:function:: int PyUnicode_RichCompare(PyObject *left, PyObject *right, int op) 923 1093 924 1094 Rich compare two unicode strings and return one of the following: … … 936 1106 937 1107 938 .. c function:: PyObject* PyUnicode_Format(PyObject *format, PyObject *args)1108 .. c:function:: PyObject* PyUnicode_Format(PyObject *format, PyObject *args) 939 1109 940 1110 Return a new string object from *format* and *args*; this is analogous to … … 942 1112 943 1113 944 .. c function:: int PyUnicode_Contains(PyObject *container, PyObject *element)1114 .. c:function:: int PyUnicode_Contains(PyObject *container, PyObject *element) 945 1115 946 1116 Check whether *element* is contained in *container* and return true or false -
python/vendor/current/Doc/c-api/utilities.rst
r2 r388 20 20 conversion.rst 21 21 reflection.rst 22 codec.rst -
python/vendor/current/Doc/c-api/veryhigh.rst
r2 r388 17 17 following the functions which accept them as parameters. 18 18 19 Note also that several of these functions take :c type:`FILE\*` parameters. One20 particular issue which needs to be handled carefully is that the :c type:`FILE`19 Note also that several of these functions take :c:type:`FILE\*` parameters. One 20 particular issue which needs to be handled carefully is that the :c:type:`FILE` 21 21 structure for different C libraries can be different and incompatible. Under 22 22 Windows (at least), it is possible for dynamically linked extensions to actually 23 use different libraries, so care should be taken that :c type:`FILE\*` parameters23 use different libraries, so care should be taken that :c:type:`FILE\*` parameters 24 24 are only passed to these functions if it is certain that they were created by 25 25 the same library that the Python runtime is using. 26 26 27 27 28 .. c function:: int Py_Main(int argc, char **argv)28 .. c:function:: int Py_Main(int argc, char **argv) 29 29 30 30 The main program for the standard interpreter. This is made available for 31 31 programs which embed Python. The *argc* and *argv* parameters should be 32 prepared exactly as those which are passed to a C program's :c func:`main`32 prepared exactly as those which are passed to a C program's :c:func:`main` 33 33 function. It is important to note that the argument list may be modified (but 34 34 the contents of the strings pointed to by the argument list are not). The return 35 value will be the integer passed to the :func:`sys.exit` function, ``1`` if the36 interpreter exits due to an exception, or ``2`` if the parameter list does not37 represent a valid Python command line.38 39 Note that if an otherwise unhandled :exc:`SystemE rror` is raised, this35 value will be ``0`` if the interpreter exits normally (ie, without an 36 exception), ``1`` if the interpreter exits due to an exception, or ``2`` 37 if the parameter list does not represent a valid Python command line. 38 39 Note that if an otherwise unhandled :exc:`SystemExit` is raised, this 40 40 function will not return ``1``, but exit the process, as long as 41 41 ``Py_InspectFlag`` is not set. 42 42 43 43 44 .. c function:: int PyRun_AnyFile(FILE *fp, const char *filename)45 46 This is a simplified interface to :c func:`PyRun_AnyFileExFlags` below, leaving44 .. c:function:: int PyRun_AnyFile(FILE *fp, const char *filename) 45 46 This is a simplified interface to :c:func:`PyRun_AnyFileExFlags` below, leaving 47 47 *closeit* set to ``0`` and *flags* set to *NULL*. 48 48 49 49 50 .. c function:: int PyRun_AnyFileFlags(FILE *fp, const char *filename, PyCompilerFlags *flags)51 52 This is a simplified interface to :c func:`PyRun_AnyFileExFlags` below, leaving50 .. c:function:: int PyRun_AnyFileFlags(FILE *fp, const char *filename, PyCompilerFlags *flags) 51 52 This is a simplified interface to :c:func:`PyRun_AnyFileExFlags` below, leaving 53 53 the *closeit* argument set to ``0``. 54 54 55 55 56 .. c function:: int PyRun_AnyFileEx(FILE *fp, const char *filename, int closeit)57 58 This is a simplified interface to :c func:`PyRun_AnyFileExFlags` below, leaving56 .. c:function:: int PyRun_AnyFileEx(FILE *fp, const char *filename, int closeit) 57 58 This is a simplified interface to :c:func:`PyRun_AnyFileExFlags` below, leaving 59 59 the *flags* argument set to *NULL*. 60 60 61 61 62 .. c function:: int PyRun_AnyFileExFlags(FILE *fp, const char *filename, int closeit, PyCompilerFlags *flags)62 .. c:function:: int PyRun_AnyFileExFlags(FILE *fp, const char *filename, int closeit, PyCompilerFlags *flags) 63 63 64 64 If *fp* refers to a file associated with an interactive device (console or 65 65 terminal input or Unix pseudo-terminal), return the value of 66 :c func:`PyRun_InteractiveLoop`, otherwise return the result of67 :c func:`PyRun_SimpleFile`. If *filename* is *NULL*, this function uses66 :c:func:`PyRun_InteractiveLoop`, otherwise return the result of 67 :c:func:`PyRun_SimpleFile`. If *filename* is *NULL*, this function uses 68 68 ``"???"`` as the filename. 69 69 70 70 71 .. c function:: int PyRun_SimpleString(const char *command)72 73 This is a simplified interface to :c func:`PyRun_SimpleStringFlags` below,71 .. c:function:: int PyRun_SimpleString(const char *command) 72 73 This is a simplified interface to :c:func:`PyRun_SimpleStringFlags` below, 74 74 leaving the *PyCompilerFlags\** argument set to NULL. 75 75 76 76 77 .. c function:: int PyRun_SimpleStringFlags(const char *command, PyCompilerFlags *flags)77 .. c:function:: int PyRun_SimpleStringFlags(const char *command, PyCompilerFlags *flags) 78 78 79 79 Executes the Python source code from *command* in the :mod:`__main__` module … … 83 83 meaning of *flags*, see below. 84 84 85 Note that if an otherwise unhandled :exc:`SystemE rror` is raised, this85 Note that if an otherwise unhandled :exc:`SystemExit` is raised, this 86 86 function will not return ``-1``, but exit the process, as long as 87 87 ``Py_InspectFlag`` is not set. 88 88 89 89 90 .. c function:: int PyRun_SimpleFile(FILE *fp, const char *filename)91 92 This is a simplified interface to :c func:`PyRun_SimpleFileExFlags` below,90 .. c:function:: int PyRun_SimpleFile(FILE *fp, const char *filename) 91 92 This is a simplified interface to :c:func:`PyRun_SimpleFileExFlags` below, 93 93 leaving *closeit* set to ``0`` and *flags* set to *NULL*. 94 94 95 95 96 .. c function:: int PyRun_SimpleFileFlags(FILE *fp, const char *filename, PyCompilerFlags *flags)97 98 This is a simplified interface to :c func:`PyRun_SimpleFileExFlags` below,96 .. c:function:: int PyRun_SimpleFileFlags(FILE *fp, const char *filename, PyCompilerFlags *flags) 97 98 This is a simplified interface to :c:func:`PyRun_SimpleFileExFlags` below, 99 99 leaving *closeit* set to ``0``. 100 100 101 101 102 .. c function:: int PyRun_SimpleFileEx(FILE *fp, const char *filename, int closeit)103 104 This is a simplified interface to :c func:`PyRun_SimpleFileExFlags` below,102 .. c:function:: int PyRun_SimpleFileEx(FILE *fp, const char *filename, int closeit) 103 104 This is a simplified interface to :c:func:`PyRun_SimpleFileExFlags` below, 105 105 leaving *flags* set to *NULL*. 106 106 107 107 108 .. c function:: int PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit, PyCompilerFlags *flags)109 110 Similar to :c func:`PyRun_SimpleStringFlags`, but the Python source code is read108 .. c:function:: int PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit, PyCompilerFlags *flags) 109 110 Similar to :c:func:`PyRun_SimpleStringFlags`, but the Python source code is read 111 111 from *fp* instead of an in-memory string. *filename* should be the name of the 112 112 file. If *closeit* is true, the file is closed before PyRun_SimpleFileExFlags … … 114 114 115 115 116 .. c function:: int PyRun_InteractiveOne(FILE *fp, const char *filename)117 118 This is a simplified interface to :c func:`PyRun_InteractiveOneFlags` below,116 .. c:function:: int PyRun_InteractiveOne(FILE *fp, const char *filename) 117 118 This is a simplified interface to :c:func:`PyRun_InteractiveOneFlags` below, 119 119 leaving *flags* set to *NULL*. 120 120 121 121 122 .. c function:: int PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags)123 124 Read and execute a single statement from a file associated with an interactive125 device according to the *flags* argument. If *filename* is *NULL*, ``"???"`` is126 used instead. The user will be prompted using ``sys.ps1`` and ``sys.ps2``.127 Returns ``0`` when the input was executed successfully, ``-1`` if there was an128 exception, or an error code from the :file:`errcode.h` include file distributed129 as part of Python if there was a parse error. (Note that :file:`errcode.h` is130 not included by:file:`Python.h`, so must be included specifically if needed.)131 132 133 .. c function:: int PyRun_InteractiveLoop(FILE *fp, const char *filename)134 135 This is a simplified interface to :c func:`PyRun_InteractiveLoopFlags` below,122 .. c:function:: int PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags) 123 124 Read and execute a single statement from a file associated with an 125 interactive device according to the *flags* argument. The user will be 126 prompted using ``sys.ps1`` and ``sys.ps2``. Returns ``0`` when the input was 127 executed successfully, ``-1`` if there was an exception, or an error code 128 from the :file:`errcode.h` include file distributed as part of Python if 129 there was a parse error. (Note that :file:`errcode.h` is not included by 130 :file:`Python.h`, so must be included specifically if needed.) 131 132 133 .. c:function:: int PyRun_InteractiveLoop(FILE *fp, const char *filename) 134 135 This is a simplified interface to :c:func:`PyRun_InteractiveLoopFlags` below, 136 136 leaving *flags* set to *NULL*. 137 137 138 138 139 .. c function:: int PyRun_InteractiveLoopFlags(FILE *fp,const char *filename, PyCompilerFlags *flags)139 .. c:function:: int PyRun_InteractiveLoopFlags(FILE *fp, const char *filename, PyCompilerFlags *flags) 140 140 141 141 Read and execute statements from a file associated with an interactive device 142 until EOF is reached. If *filename* is *NULL*, ``"???"`` is used instead. The143 user will be prompted using ``sys.ps1`` and``sys.ps2``. Returns ``0`` at EOF.144 145 146 .. c function:: struct _node* PyParser_SimpleParseString(const char *str, int start)142 until EOF is reached. The user will be prompted using ``sys.ps1`` and 143 ``sys.ps2``. Returns ``0`` at EOF. 144 145 146 .. c:function:: struct _node* PyParser_SimpleParseString(const char *str, int start) 147 147 148 148 This is a simplified interface to 149 :c func:`PyParser_SimpleParseStringFlagsFilename` below, leaving *filename* set149 :c:func:`PyParser_SimpleParseStringFlagsFilename` below, leaving *filename* set 150 150 to *NULL* and *flags* set to ``0``. 151 151 152 152 153 .. c function:: struct _node* PyParser_SimpleParseStringFlags( const char *str, int start, int flags)153 .. c:function:: struct _node* PyParser_SimpleParseStringFlags( const char *str, int start, int flags) 154 154 155 155 This is a simplified interface to 156 :c func:`PyParser_SimpleParseStringFlagsFilename` below, leaving *filename* set156 :c:func:`PyParser_SimpleParseStringFlagsFilename` below, leaving *filename* set 157 157 to *NULL*. 158 158 159 159 160 .. c function:: struct _node* PyParser_SimpleParseStringFlagsFilename( const char *str, const char *filename, int start, int flags)160 .. c:function:: struct _node* PyParser_SimpleParseStringFlagsFilename( const char *str, const char *filename, int start, int flags) 161 161 162 162 Parse Python source code from *str* using the start token *start* according to … … 166 166 167 167 168 .. c function:: struct _node* PyParser_SimpleParseFile(FILE *fp, const char *filename, int start)169 170 This is a simplified interface to :c func:`PyParser_SimpleParseFileFlags` below,168 .. c:function:: struct _node* PyParser_SimpleParseFile(FILE *fp, const char *filename, int start) 169 170 This is a simplified interface to :c:func:`PyParser_SimpleParseFileFlags` below, 171 171 leaving *flags* set to ``0`` 172 172 173 173 174 .. c function:: struct _node* PyParser_SimpleParseFileFlags(FILE *fp, const char *filename, int start, int flags)175 176 Similar to :c func:`PyParser_SimpleParseStringFlagsFilename`, but the Python174 .. c:function:: struct _node* PyParser_SimpleParseFileFlags(FILE *fp, const char *filename, int start, int flags) 175 176 Similar to :c:func:`PyParser_SimpleParseStringFlagsFilename`, but the Python 177 177 source code is read from *fp* instead of an in-memory string. 178 178 179 179 180 .. c function:: PyObject* PyRun_String(const char *str, int start, PyObject *globals, PyObject *locals)181 182 This is a simplified interface to :c func:`PyRun_StringFlags` below, leaving180 .. c:function:: PyObject* PyRun_String(const char *str, int start, PyObject *globals, PyObject *locals) 181 182 This is a simplified interface to :c:func:`PyRun_StringFlags` below, leaving 183 183 *flags* set to *NULL*. 184 184 185 185 186 .. c function:: PyObject* PyRun_StringFlags(const char *str, int start, PyObject *globals, PyObject *locals, PyCompilerFlags *flags)186 .. c:function:: PyObject* PyRun_StringFlags(const char *str, int start, PyObject *globals, PyObject *locals, PyCompilerFlags *flags) 187 187 188 188 Execute Python source code from *str* in the context specified by the … … 195 195 196 196 197 .. c function:: PyObject* PyRun_File(FILE *fp, const char *filename, int start, PyObject *globals, PyObject *locals)198 199 This is a simplified interface to :c func:`PyRun_FileExFlags` below, leaving197 .. c:function:: PyObject* PyRun_File(FILE *fp, const char *filename, int start, PyObject *globals, PyObject *locals) 198 199 This is a simplified interface to :c:func:`PyRun_FileExFlags` below, leaving 200 200 *closeit* set to ``0`` and *flags* set to *NULL*. 201 201 202 202 203 .. c function:: PyObject* PyRun_FileEx(FILE *fp, const char *filename, int start, PyObject *globals, PyObject *locals, int closeit)204 205 This is a simplified interface to :c func:`PyRun_FileExFlags` below, leaving203 .. c:function:: PyObject* PyRun_FileEx(FILE *fp, const char *filename, int start, PyObject *globals, PyObject *locals, int closeit) 204 205 This is a simplified interface to :c:func:`PyRun_FileExFlags` below, leaving 206 206 *flags* set to *NULL*. 207 207 208 208 209 .. c function:: PyObject* PyRun_FileFlags(FILE *fp, const char *filename, int start, PyObject *globals, PyObject *locals, PyCompilerFlags *flags)210 211 This is a simplified interface to :c func:`PyRun_FileExFlags` below, leaving209 .. c:function:: PyObject* PyRun_FileFlags(FILE *fp, const char *filename, int start, PyObject *globals, PyObject *locals, PyCompilerFlags *flags) 210 211 This is a simplified interface to :c:func:`PyRun_FileExFlags` below, leaving 212 212 *closeit* set to ``0``. 213 213 214 214 215 .. c function:: PyObject* PyRun_FileExFlags(FILE *fp, const char *filename, int start, PyObject *globals, PyObject *locals, int closeit, PyCompilerFlags *flags)216 217 Similar to :c func:`PyRun_StringFlags`, but the Python source code is read from215 .. c:function:: PyObject* PyRun_FileExFlags(FILE *fp, const char *filename, int start, PyObject *globals, PyObject *locals, int closeit, PyCompilerFlags *flags) 216 217 Similar to :c:func:`PyRun_StringFlags`, but the Python source code is read from 218 218 *fp* instead of an in-memory string. *filename* should be the name of the file. 219 If *closeit* is true, the file is closed before :c func:`PyRun_FileExFlags`219 If *closeit* is true, the file is closed before :c:func:`PyRun_FileExFlags` 220 220 returns. 221 221 222 222 223 .. c function:: PyObject* Py_CompileString(const char *str, const char *filename, int start)224 225 This is a simplified interface to :c func:`Py_CompileStringFlags` below, leaving223 .. c:function:: PyObject* Py_CompileString(const char *str, const char *filename, int start) 224 225 This is a simplified interface to :c:func:`Py_CompileStringFlags` below, leaving 226 226 *flags* set to *NULL*. 227 227 228 228 229 .. c function:: PyObject* Py_CompileStringFlags(const char *str, const char *filename, int start, PyCompilerFlags *flags)229 .. c:function:: PyObject* Py_CompileStringFlags(const char *str, const char *filename, int start, PyCompilerFlags *flags) 230 230 231 231 Parse and compile the Python source code in *str*, returning the resulting code … … 238 238 239 239 240 .. c function:: PyObject* PyEval_EvalCode(PyCodeObject *co, PyObject *globals, PyObject *locals)241 242 This is a simplified interface to :c func:`PyEval_EvalCodeEx`, with just240 .. c:function:: PyObject* PyEval_EvalCode(PyCodeObject *co, PyObject *globals, PyObject *locals) 241 242 This is a simplified interface to :c:func:`PyEval_EvalCodeEx`, with just 243 243 the code object, and the dictionaries of global and local variables. 244 244 The other arguments are set to *NULL*. 245 245 246 246 247 .. c function:: PyObject* PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals, PyObject **args, int argcount, PyObject **kws, int kwcount, PyObject **defs, int defcount, PyObject *closure)247 .. c:function:: PyObject* PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals, PyObject **args, int argcount, PyObject **kws, int kwcount, PyObject **defs, int defcount, PyObject *closure) 248 248 249 249 Evaluate a precompiled code object, given a particular environment for its … … 253 253 254 254 255 .. c function:: PyObject* PyEval_EvalFrame(PyFrameObject *f)255 .. c:function:: PyObject* PyEval_EvalFrame(PyFrameObject *f) 256 256 257 257 Evaluate an execution frame. This is a simplified interface to … … 259 259 260 260 261 .. c function:: PyObject* PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)261 .. c:function:: PyObject* PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) 262 262 263 263 This is the main, unvarnished function of Python interpretation. It is … … 266 266 The additional *throwflag* parameter can mostly be ignored - if true, then 267 267 it causes an exception to immediately be thrown; this is used for the 268 :meth:` throw` methods of generator objects.269 270 271 .. c function:: int PyEval_MergeCompilerFlags(PyCompilerFlags *cf)268 :meth:`~generator.throw` methods of generator objects. 269 270 271 .. c:function:: int PyEval_MergeCompilerFlags(PyCompilerFlags *cf) 272 272 273 273 This function changes the flags of the current evaluation frame, and returns … … 275 275 276 276 277 .. c var:: int Py_eval_input277 .. c:var:: int Py_eval_input 278 278 279 279 .. index:: single: Py_CompileString() 280 280 281 281 The start symbol from the Python grammar for isolated expressions; for use with 282 :c func:`Py_CompileString`.283 284 285 .. c var:: int Py_file_input282 :c:func:`Py_CompileString`. 283 284 285 .. c:var:: int Py_file_input 286 286 287 287 .. index:: single: Py_CompileString() 288 288 289 289 The start symbol from the Python grammar for sequences of statements as read 290 from a file or other source; for use with :c func:`Py_CompileString`. This is290 from a file or other source; for use with :c:func:`Py_CompileString`. This is 291 291 the symbol to use when compiling arbitrarily long Python source code. 292 292 293 293 294 .. c var:: int Py_single_input294 .. c:var:: int Py_single_input 295 295 296 296 .. index:: single: Py_CompileString() 297 297 298 298 The start symbol from the Python grammar for a single statement; for use with 299 :c func:`Py_CompileString`. This is the symbol used for the interactive299 :c:func:`Py_CompileString`. This is the symbol used for the interactive 300 300 interpreter loop. 301 301 302 302 303 .. c type:: struct PyCompilerFlags303 .. c:type:: struct PyCompilerFlags 304 304 305 305 This is the structure used to hold compiler flags. In cases where code is only … … 317 317 318 318 319 .. c var:: int CO_FUTURE_DIVISION319 .. c:var:: int CO_FUTURE_DIVISION 320 320 321 321 This bit can be set in *flags* to cause division operator ``/`` to be -
python/vendor/current/Doc/c-api/weakref.rst
r2 r388 12 12 13 13 14 .. c function:: int PyWeakref_Check(ob)14 .. c:function:: int PyWeakref_Check(ob) 15 15 16 16 Return true if *ob* is either a reference or proxy object. … … 19 19 20 20 21 .. c function:: int PyWeakref_CheckRef(ob)21 .. c:function:: int PyWeakref_CheckRef(ob) 22 22 23 23 Return true if *ob* is a reference object. … … 26 26 27 27 28 .. c function:: int PyWeakref_CheckProxy(ob)28 .. c:function:: int PyWeakref_CheckProxy(ob) 29 29 30 30 Return true if *ob* is a proxy object. … … 33 33 34 34 35 .. c function:: PyObject* PyWeakref_NewRef(PyObject *ob, PyObject *callback)35 .. c:function:: PyObject* PyWeakref_NewRef(PyObject *ob, PyObject *callback) 36 36 37 37 Return a weak reference object for the object *ob*. This will always return … … 47 47 48 48 49 .. c function:: PyObject* PyWeakref_NewProxy(PyObject *ob, PyObject *callback)49 .. c:function:: PyObject* PyWeakref_NewProxy(PyObject *ob, PyObject *callback) 50 50 51 51 Return a weak reference proxy object for the object *ob*. This will always … … 61 61 62 62 63 .. c function:: PyObject* PyWeakref_GetObject(PyObject *ref)63 .. c:function:: PyObject* PyWeakref_GetObject(PyObject *ref) 64 64 65 65 Return the referenced object from a weak reference, *ref*. If the referent is 66 no longer live, returns ``None``.66 no longer live, returns :const:`Py_None`. 67 67 68 68 .. versionadded:: 2.2 69 69 70 .. warning:: 70 71 71 .. cfunction:: PyObject* PyWeakref_GET_OBJECT(PyObject *ref) 72 This function returns a **borrowed reference** to the referenced object. 73 This means that you should always call :c:func:`Py_INCREF` on the object 74 except if you know that it cannot be destroyed while you are still 75 using it. 72 76 73 Similar to :cfunc:`PyWeakref_GetObject`, but implemented as a macro that does no 77 78 .. c:function:: PyObject* PyWeakref_GET_OBJECT(PyObject *ref) 79 80 Similar to :c:func:`PyWeakref_GetObject`, but implemented as a macro that does no 74 81 error checking. 75 82
Note:
See TracChangeset
for help on using the changeset viewer.