Victor Stinner | b6522d0 | 2016-12-19 13:12:08 +0100 | [diff] [blame] | 1 | /* Abstract Object Interface (many thanks to Jim Fulton) */ |
| 2 | |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 3 | #ifndef Py_ABSTRACTOBJECT_H |
| 4 | #define Py_ABSTRACTOBJECT_H |
| 5 | #ifdef __cplusplus |
| 6 | extern "C" { |
| 7 | #endif |
| 8 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 9 | /* === Object Protocol ================================================== */ |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 10 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 11 | /* Implemented elsewhere: |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 12 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 13 | int PyObject_Print(PyObject *o, FILE *fp, int flags); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 14 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 15 | Print an object 'o' on file 'fp'. Returns -1 on error. The flags argument |
| 16 | is used to enable certain printing options. The only option currently |
| 17 | supported is Py_Print_RAW. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 18 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 19 | (What should be said about Py_Print_RAW?). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 20 | |
| 21 | |
| 22 | /* Implemented elsewhere: |
| 23 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 24 | int PyObject_HasAttrString(PyObject *o, const char *attr_name); |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 25 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 26 | Returns 1 if object 'o' has the attribute attr_name, and 0 otherwise. |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 27 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 28 | This is equivalent to the Python expression: hasattr(o,attr_name). |
| 29 | |
| 30 | This function always succeeds. */ |
| 31 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 32 | |
| 33 | /* Implemented elsewhere: |
| 34 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 35 | PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name); |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 36 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 37 | Retrieve an attributed named attr_name form object o. |
| 38 | Returns the attribute value on success, or NULL on failure. |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 39 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 40 | This is the equivalent of the Python expression: o.attr_name. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 41 | |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 42 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 43 | /* Implemented elsewhere: |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 44 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 45 | int PyObject_HasAttr(PyObject *o, PyObject *attr_name); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 46 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 47 | Returns 1 if o has the attribute attr_name, and 0 otherwise. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 48 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 49 | This is equivalent to the Python expression: hasattr(o,attr_name). |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 50 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 51 | This function always succeeds. */ |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 52 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 53 | /* Implemented elsewhere: |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 54 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 55 | PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 56 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 57 | Retrieve an attributed named 'attr_name' form object 'o'. |
| 58 | Returns the attribute value on success, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 59 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 60 | This is the equivalent of the Python expression: o.attr_name. */ |
Marc-André Lemburg | ad7c98e | 2001-01-17 17:09:53 +0000 | [diff] [blame] | 61 | |
Marc-André Lemburg | ad7c98e | 2001-01-17 17:09:53 +0000 | [diff] [blame] | 62 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 63 | /* Implemented elsewhere: |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 64 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 65 | int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 66 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 67 | Set the value of the attribute named attr_name, for object 'o', |
| 68 | to the value 'v'. Raise an exception and return -1 on failure; return 0 on |
| 69 | success. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 70 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 71 | This is the equivalent of the Python statement o.attr_name=v. */ |
| 72 | |
| 73 | |
| 74 | /* Implemented elsewhere: |
| 75 | |
| 76 | int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v); |
| 77 | |
| 78 | Set the value of the attribute named attr_name, for object 'o', to the value |
| 79 | 'v'. an exception and return -1 on failure; return 0 on success. |
| 80 | |
| 81 | This is the equivalent of the Python statement o.attr_name=v. */ |
| 82 | |
| 83 | /* Implemented as a macro: |
| 84 | |
| 85 | int PyObject_DelAttrString(PyObject *o, const char *attr_name); |
| 86 | |
| 87 | Delete attribute named attr_name, for object o. Returns |
| 88 | -1 on failure. |
| 89 | |
| 90 | This is the equivalent of the Python statement: del o.attr_name. */ |
| 91 | #define PyObject_DelAttrString(O,A) PyObject_SetAttrString((O),(A), NULL) |
| 92 | |
| 93 | |
| 94 | /* Implemented as a macro: |
| 95 | |
| 96 | int PyObject_DelAttr(PyObject *o, PyObject *attr_name); |
| 97 | |
| 98 | Delete attribute named attr_name, for object o. Returns -1 |
| 99 | on failure. This is the equivalent of the Python |
| 100 | statement: del o.attr_name. */ |
| 101 | #define PyObject_DelAttr(O,A) PyObject_SetAttr((O),(A), NULL) |
| 102 | |
| 103 | |
| 104 | /* Implemented elsewhere: |
| 105 | |
| 106 | PyObject *PyObject_Repr(PyObject *o); |
| 107 | |
| 108 | Compute the string representation of object 'o'. Returns the |
| 109 | string representation on success, NULL on failure. |
| 110 | |
| 111 | This is the equivalent of the Python expression: repr(o). |
| 112 | |
| 113 | Called by the repr() built-in function. */ |
| 114 | |
| 115 | |
| 116 | /* Implemented elsewhere: |
| 117 | |
| 118 | PyObject *PyObject_Str(PyObject *o); |
| 119 | |
| 120 | Compute the string representation of object, o. Returns the |
| 121 | string representation on success, NULL on failure. |
| 122 | |
| 123 | This is the equivalent of the Python expression: str(o). |
| 124 | |
| 125 | Called by the str() and print() built-in functions. */ |
| 126 | |
| 127 | |
| 128 | /* Declared elsewhere |
| 129 | |
| 130 | PyAPI_FUNC(int) PyCallable_Check(PyObject *o); |
| 131 | |
| 132 | Determine if the object, o, is callable. Return 1 if the object is callable |
| 133 | and 0 otherwise. |
| 134 | |
| 135 | This function always succeeds. */ |
| 136 | |
| 137 | |
| 138 | #ifdef PY_SSIZE_T_CLEAN |
| 139 | # define PyObject_CallFunction _PyObject_CallFunction_SizeT |
| 140 | # define PyObject_CallMethod _PyObject_CallMethod_SizeT |
| 141 | # ifndef Py_LIMITED_API |
| 142 | # define _PyObject_CallMethodId _PyObject_CallMethodId_SizeT |
| 143 | # endif /* !Py_LIMITED_API */ |
| 144 | #endif |
| 145 | |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 146 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 147 | /* Call a callable Python object 'callable' with arguments given by the |
| 148 | tuple 'args' and keywords arguments given by the dictionary 'kwargs'. |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 149 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 150 | 'args' must not be *NULL*, use an empty tuple if no arguments are |
| 151 | needed. If no named arguments are needed, 'kwargs' can be NULL. |
Victor Stinner | 2d0eb65 | 2016-12-06 16:27:24 +0100 | [diff] [blame] | 152 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 153 | This is the equivalent of the Python expression: |
| 154 | callable(*args, **kwargs). */ |
| 155 | PyAPI_FUNC(PyObject *) PyObject_Call(PyObject *callable, |
| 156 | PyObject *args, PyObject *kwargs); |
| 157 | |
Victor Stinner | 4a7cc88 | 2015-03-06 23:35:27 +0100 | [diff] [blame] | 158 | #ifndef Py_LIMITED_API |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 159 | PyAPI_FUNC(PyObject*) _PyStack_AsTuple( |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 160 | PyObject *const *stack, |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 161 | Py_ssize_t nargs); |
Victor Stinner | 9be7e7b | 2016-08-19 16:11:43 +0200 | [diff] [blame] | 162 | |
Victor Stinner | 69de71b | 2017-01-16 23:50:53 +0100 | [diff] [blame] | 163 | PyAPI_FUNC(PyObject*) _PyStack_AsTupleSlice( |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 164 | PyObject *const *stack, |
Victor Stinner | 69de71b | 2017-01-16 23:50:53 +0100 | [diff] [blame] | 165 | Py_ssize_t nargs, |
| 166 | Py_ssize_t start, |
| 167 | Py_ssize_t end); |
| 168 | |
Victor Stinner | c3858bd | 2017-01-24 15:05:30 +0100 | [diff] [blame] | 169 | /* Convert keyword arguments from the FASTCALL (stack: C array, kwnames: tuple) |
| 170 | format to a Python dictionary ("kwargs" dict). |
Victor Stinner | 57f91ac | 2016-09-12 13:37:07 +0200 | [diff] [blame] | 171 | |
Victor Stinner | c3858bd | 2017-01-24 15:05:30 +0100 | [diff] [blame] | 172 | The type of kwnames keys is not checked. The final function getting |
Ville Skyttä | 49b2734 | 2017-08-03 09:00:59 +0300 | [diff] [blame] | 173 | arguments is responsible to check if all keys are strings, for example using |
Victor Stinner | c3858bd | 2017-01-24 15:05:30 +0100 | [diff] [blame] | 174 | PyArg_ParseTupleAndKeywords() or PyArg_ValidateKeywordArguments(). |
| 175 | |
| 176 | Duplicate keys are merged using the last value. If duplicate keys must raise |
| 177 | an exception, the caller is responsible to implement an explicit keys on |
| 178 | kwnames. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 179 | PyAPI_FUNC(PyObject *) _PyStack_AsDict( |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 180 | PyObject *const *values, |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 181 | PyObject *kwnames); |
Victor Stinner | ae8b69c | 2016-09-09 14:07:44 -0700 | [diff] [blame] | 182 | |
Victor Stinner | 998c209 | 2017-01-17 01:57:29 +0100 | [diff] [blame] | 183 | /* Convert (args, nargs, kwargs: dict) into a (stack, nargs, kwnames: tuple). |
Victor Stinner | a9efb2f | 2016-09-09 17:40:22 -0700 | [diff] [blame] | 184 | |
Victor Stinner | 998c209 | 2017-01-17 01:57:29 +0100 | [diff] [blame] | 185 | Return 0 on success, raise an exception and return -1 on error. |
| 186 | |
| 187 | Write the new stack into *p_stack. If *p_stack is differen than args, it |
| 188 | must be released by PyMem_Free(). |
Victor Stinner | a9efb2f | 2016-09-09 17:40:22 -0700 | [diff] [blame] | 189 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 190 | The stack uses borrowed references. |
Victor Stinner | a9efb2f | 2016-09-09 17:40:22 -0700 | [diff] [blame] | 191 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 192 | The type of keyword keys is not checked, these checks should be done |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 193 | later (ex: _PyArg_ParseStackAndKeywords). */ |
Victor Stinner | 998c209 | 2017-01-17 01:57:29 +0100 | [diff] [blame] | 194 | PyAPI_FUNC(int) _PyStack_UnpackDict( |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 195 | PyObject *const *args, |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 196 | Py_ssize_t nargs, |
| 197 | PyObject *kwargs, |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 198 | PyObject *const **p_stack, |
Victor Stinner | 35ecebe | 2017-01-18 10:31:46 +0100 | [diff] [blame] | 199 | PyObject **p_kwnames); |
Victor Stinner | a9efb2f | 2016-09-09 17:40:22 -0700 | [diff] [blame] | 200 | |
Victor Stinner | bc08ab4 | 2016-12-15 12:40:53 +0100 | [diff] [blame] | 201 | /* Suggested size (number of positional arguments) for arrays of PyObject* |
| 202 | allocated on a C stack to avoid allocating memory on the heap memory. Such |
| 203 | array is used to pass positional arguments to call functions of the |
| 204 | _PyObject_FastCall() family. |
| 205 | |
| 206 | The size is chosen to not abuse the C stack and so limit the risk of stack |
| 207 | overflow. The size is also chosen to allow using the small stack for most |
| 208 | function calls of the Python standard library. On 64-bit CPU, it allocates |
| 209 | 40 bytes on the stack. */ |
| 210 | #define _PY_FASTCALL_SMALL_STACK 5 |
| 211 | |
Victor Stinner | 0f7b0b3 | 2017-03-14 21:37:20 +0100 | [diff] [blame] | 212 | /* Return 1 if callable supports FASTCALL calling convention for positional |
| 213 | arguments: see _PyObject_FastCallDict() and _PyObject_FastCallKeywords() */ |
| 214 | PyAPI_FUNC(int) _PyObject_HasFastCall(PyObject *callable); |
| 215 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 216 | /* Call the callable object 'callable' with the "fast call" calling convention: |
| 217 | args is a C array for positional arguments (nargs is the number of |
| 218 | positional arguments), kwargs is a dictionary for keyword arguments. |
Victor Stinner | 9be7e7b | 2016-08-19 16:11:43 +0200 | [diff] [blame] | 219 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 220 | If nargs is equal to zero, args can be NULL. kwargs can be NULL. |
| 221 | nargs must be greater or equal to zero. |
Victor Stinner | 9be7e7b | 2016-08-19 16:11:43 +0200 | [diff] [blame] | 222 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 223 | Return the result on success. Raise an exception on return NULL on |
| 224 | error. */ |
| 225 | PyAPI_FUNC(PyObject *) _PyObject_FastCallDict( |
| 226 | PyObject *callable, |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 227 | PyObject *const *args, |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 228 | Py_ssize_t nargs, |
| 229 | PyObject *kwargs); |
Victor Stinner | 559bb6a | 2016-08-22 22:48:54 +0200 | [diff] [blame] | 230 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 231 | /* Call the callable object 'callable' with the "fast call" calling convention: |
| 232 | args is a C array for positional arguments followed by values of |
| 233 | keyword arguments. Keys of keyword arguments are stored as a tuple |
| 234 | of strings in kwnames. nargs is the number of positional parameters at |
| 235 | the beginning of stack. The size of kwnames gives the number of keyword |
| 236 | values in the stack after positional arguments. |
Victor Stinner | d873572 | 2016-09-09 12:36:44 -0700 | [diff] [blame] | 237 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 238 | kwnames must only contains str strings, no subclass, and all keys must |
| 239 | be unique. |
Victor Stinner | d873572 | 2016-09-09 12:36:44 -0700 | [diff] [blame] | 240 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 241 | If nargs is equal to zero and there is no keyword argument (kwnames is |
| 242 | NULL or its size is zero), args can be NULL. |
Victor Stinner | 57f91ac | 2016-09-12 13:37:07 +0200 | [diff] [blame] | 243 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 244 | Return the result on success. Raise an exception and return NULL on |
| 245 | error. */ |
| 246 | PyAPI_FUNC(PyObject *) _PyObject_FastCallKeywords( |
| 247 | PyObject *callable, |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 248 | PyObject *const *args, |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 249 | Py_ssize_t nargs, |
| 250 | PyObject *kwnames); |
Victor Stinner | d873572 | 2016-09-09 12:36:44 -0700 | [diff] [blame] | 251 | |
Victor Stinner | 559bb6a | 2016-08-22 22:48:54 +0200 | [diff] [blame] | 252 | #define _PyObject_FastCall(func, args, nargs) \ |
| 253 | _PyObject_FastCallDict((func), (args), (nargs), NULL) |
| 254 | |
| 255 | #define _PyObject_CallNoArg(func) \ |
Victor Stinner | 7bfb42d | 2016-12-05 17:04:32 +0100 | [diff] [blame] | 256 | _PyObject_FastCallDict((func), NULL, 0, NULL) |
Victor Stinner | 9be7e7b | 2016-08-19 16:11:43 +0200 | [diff] [blame] | 257 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 258 | PyAPI_FUNC(PyObject *) _PyObject_Call_Prepend( |
| 259 | PyObject *callable, |
| 260 | PyObject *obj, |
| 261 | PyObject *args, |
| 262 | PyObject *kwargs); |
Victor Stinner | 3f1057a | 2016-08-25 01:04:14 +0200 | [diff] [blame] | 263 | |
Victor Stinner | 516b981 | 2017-02-09 22:53:47 +0100 | [diff] [blame] | 264 | PyAPI_FUNC(PyObject *) _PyObject_FastCall_Prepend( |
| 265 | PyObject *callable, |
| 266 | PyObject *obj, |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 267 | PyObject *const *args, |
Victor Stinner | 516b981 | 2017-02-09 22:53:47 +0100 | [diff] [blame] | 268 | Py_ssize_t nargs); |
| 269 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 270 | PyAPI_FUNC(PyObject *) _Py_CheckFunctionResult(PyObject *callable, |
| 271 | PyObject *result, |
| 272 | const char *where); |
Victor Stinner | 9be7e7b | 2016-08-19 16:11:43 +0200 | [diff] [blame] | 273 | #endif /* Py_LIMITED_API */ |
Victor Stinner | 4a7cc88 | 2015-03-06 23:35:27 +0100 | [diff] [blame] | 274 | |
Victor Stinner | 2d0eb65 | 2016-12-06 16:27:24 +0100 | [diff] [blame] | 275 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 276 | /* Call a callable Python object 'callable', with arguments given by the |
| 277 | tuple 'args'. If no arguments are needed, then 'args' can be *NULL*. |
Victor Stinner | 2d0eb65 | 2016-12-06 16:27:24 +0100 | [diff] [blame] | 278 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 279 | Returns the result of the call on success, or *NULL* on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 280 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 281 | This is the equivalent of the Python expression: |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 282 | callable(*args). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 283 | PyAPI_FUNC(PyObject *) PyObject_CallObject(PyObject *callable, |
| 284 | PyObject *args); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 285 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 286 | /* Call a callable Python object, callable, with a variable number of C |
| 287 | arguments. The C arguments are described using a mkvalue-style format |
| 288 | string. |
Victor Stinner | 2d0eb65 | 2016-12-06 16:27:24 +0100 | [diff] [blame] | 289 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 290 | The format may be NULL, indicating that no arguments are provided. |
Victor Stinner | 2d0eb65 | 2016-12-06 16:27:24 +0100 | [diff] [blame] | 291 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 292 | Returns the result of the call on success, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 293 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 294 | This is the equivalent of the Python expression: |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 295 | callable(arg1, arg2, ...). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 296 | PyAPI_FUNC(PyObject *) PyObject_CallFunction(PyObject *callable, |
| 297 | const char *format, ...); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 298 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 299 | /* Call the method named 'name' of object 'obj' with a variable number of |
| 300 | C arguments. The C arguments are described by a mkvalue format string. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 301 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 302 | The format can be NULL, indicating that no arguments are provided. |
Victor Stinner | 2d0eb65 | 2016-12-06 16:27:24 +0100 | [diff] [blame] | 303 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 304 | Returns the result of the call on success, or NULL on failure. |
| 305 | |
| 306 | This is the equivalent of the Python expression: |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 307 | obj.name(arg1, arg2, ...). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 308 | PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *obj, |
| 309 | const char *name, |
| 310 | const char *format, ...); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 311 | |
Serhiy Storchaka | 9fab79b | 2016-09-11 11:03:14 +0300 | [diff] [blame] | 312 | #ifndef Py_LIMITED_API |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 313 | /* Like PyObject_CallMethod(), but expect a _Py_Identifier* |
| 314 | as the method name. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 315 | PyAPI_FUNC(PyObject *) _PyObject_CallMethodId(PyObject *obj, |
| 316 | _Py_Identifier *name, |
| 317 | const char *format, ...); |
Serhiy Storchaka | 9fab79b | 2016-09-11 11:03:14 +0300 | [diff] [blame] | 318 | #endif /* !Py_LIMITED_API */ |
Martin v. Löwis | afe55bb | 2011-10-09 10:38:36 +0200 | [diff] [blame] | 319 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 320 | PyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable, |
| 321 | const char *format, |
| 322 | ...); |
| 323 | |
| 324 | PyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *obj, |
| 325 | const char *name, |
| 326 | const char *format, |
| 327 | ...); |
| 328 | |
Serhiy Storchaka | 9fab79b | 2016-09-11 11:03:14 +0300 | [diff] [blame] | 329 | #ifndef Py_LIMITED_API |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 330 | PyAPI_FUNC(PyObject *) _PyObject_CallMethodId_SizeT(PyObject *obj, |
| 331 | _Py_Identifier *name, |
| 332 | const char *format, |
| 333 | ...); |
Serhiy Storchaka | 9fab79b | 2016-09-11 11:03:14 +0300 | [diff] [blame] | 334 | #endif /* !Py_LIMITED_API */ |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 335 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 336 | /* Call a callable Python object 'callable' with a variable number of C |
| 337 | arguments. The C arguments are provided as PyObject* values, terminated |
| 338 | by a NULL. |
Victor Stinner | 2d0eb65 | 2016-12-06 16:27:24 +0100 | [diff] [blame] | 339 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 340 | Returns the result of the call on success, or NULL on failure. |
Victor Stinner | 2d0eb65 | 2016-12-06 16:27:24 +0100 | [diff] [blame] | 341 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 342 | This is the equivalent of the Python expression: |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 343 | callable(arg1, arg2, ...). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 344 | PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable, |
| 345 | ...); |
Fred Drake | b421b8c | 2001-10-26 16:21:32 +0000 | [diff] [blame] | 346 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 347 | /* Call the method named 'name' of object 'obj' with a variable number of |
| 348 | C arguments. The C arguments are provided as PyObject* values, terminated |
| 349 | by NULL. |
| 350 | |
| 351 | Returns the result of the call on success, or NULL on failure. |
| 352 | |
| 353 | This is the equivalent of the Python expression: obj.name(*args). */ |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 354 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 355 | PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs( |
| 356 | PyObject *obj, |
| 357 | PyObject *name, |
| 358 | ...); |
| 359 | |
Victor Stinner | 2d0eb65 | 2016-12-06 16:27:24 +0100 | [diff] [blame] | 360 | #ifndef Py_LIMITED_API |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 361 | PyAPI_FUNC(PyObject *) _PyObject_CallMethodIdObjArgs( |
| 362 | PyObject *obj, |
| 363 | struct _Py_Identifier *name, |
| 364 | ...); |
Victor Stinner | 2d0eb65 | 2016-12-06 16:27:24 +0100 | [diff] [blame] | 365 | #endif /* !Py_LIMITED_API */ |
| 366 | |
| 367 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 368 | /* Implemented elsewhere: |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 369 | |
Andrew Svetlov | 9508402 | 2017-12-16 21:08:05 +0200 | [diff] [blame^] | 370 | Py_hash_t PyObject_Hash(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 371 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 372 | Compute and return the hash, hash_value, of an object, o. On |
| 373 | failure, return -1. |
| 374 | |
| 375 | This is the equivalent of the Python expression: hash(o). */ |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 376 | |
| 377 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 378 | /* Implemented elsewhere: |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 379 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 380 | int PyObject_IsTrue(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 381 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 382 | Returns 1 if the object, o, is considered to be true, 0 if o is |
| 383 | considered to be false and -1 on failure. |
| 384 | |
| 385 | This is equivalent to the Python expression: not not o. */ |
| 386 | |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 387 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 388 | /* Implemented elsewhere: |
Guido van Rossum | c3d3f96 | 1998-04-09 17:53:59 +0000 | [diff] [blame] | 389 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 390 | int PyObject_Not(PyObject *o); |
Guido van Rossum | c3d3f96 | 1998-04-09 17:53:59 +0000 | [diff] [blame] | 391 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 392 | Returns 0 if the object, o, is considered to be true, 1 if o is |
| 393 | considered to be false and -1 on failure. |
Guido van Rossum | c3d3f96 | 1998-04-09 17:53:59 +0000 | [diff] [blame] | 394 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 395 | This is equivalent to the Python expression: not o. */ |
| 396 | |
| 397 | |
| 398 | /* Get the type of an object. |
| 399 | |
| 400 | On success, returns a type object corresponding to the object type of object |
| 401 | 'o'. On failure, returns NULL. |
| 402 | |
| 403 | This is equivalent to the Python expression: type(o) */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 404 | PyAPI_FUNC(PyObject *) PyObject_Type(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 405 | |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 406 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 407 | /* Return the size of object 'o'. If the object 'o' provides both sequence and |
| 408 | mapping protocols, the sequence size is returned. |
| 409 | |
| 410 | On error, -1 is returned. |
| 411 | |
| 412 | This is the equivalent to the Python expression: len(o) */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 413 | PyAPI_FUNC(Py_ssize_t) PyObject_Size(PyObject *o); |
Jeremy Hylton | 6253f83 | 2000-07-12 12:56:19 +0000 | [diff] [blame] | 414 | |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 415 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 416 | /* For DLL compatibility */ |
Marc-André Lemburg | cf5f358 | 2000-07-17 09:22:55 +0000 | [diff] [blame] | 417 | #undef PyObject_Length |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 418 | PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o); |
Marc-André Lemburg | cf5f358 | 2000-07-17 09:22:55 +0000 | [diff] [blame] | 419 | #define PyObject_Length PyObject_Size |
| 420 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 421 | |
Armin Ronacher | 74b38b1 | 2012-10-07 10:29:32 +0200 | [diff] [blame] | 422 | #ifndef Py_LIMITED_API |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 423 | PyAPI_FUNC(int) _PyObject_HasLen(PyObject *o); |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 424 | |
| 425 | /* Guess the size of object 'o' using len(o) or o.__length_hint__(). |
| 426 | If neither of those return a non-negative value, then return the default |
| 427 | value. If one of the calls fails, this function returns -1. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 428 | PyAPI_FUNC(Py_ssize_t) PyObject_LengthHint(PyObject *o, Py_ssize_t); |
Armin Ronacher | 74b38b1 | 2012-10-07 10:29:32 +0200 | [diff] [blame] | 429 | #endif |
Raymond Hettinger | 6b27cda | 2005-09-24 21:23:05 +0000 | [diff] [blame] | 430 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 431 | /* Return element of 'o' corresponding to the object 'key'. Return NULL |
| 432 | on failure. |
Marc-André Lemburg | cf5f358 | 2000-07-17 09:22:55 +0000 | [diff] [blame] | 433 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 434 | This is the equivalent of the Python expression: o[key] */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 435 | PyAPI_FUNC(PyObject *) PyObject_GetItem(PyObject *o, PyObject *key); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 436 | |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 437 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 438 | /* Map the object 'key' to the value 'v' into 'o'. |
| 439 | |
| 440 | Raise an exception and return -1 on failure; return 0 on success. |
| 441 | |
| 442 | This is the equivalent of the Python statement: o[key]=v. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 443 | PyAPI_FUNC(int) PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 444 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 445 | /* Remove the mapping for object, key, from the object 'o'. |
| 446 | Returns -1 on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 447 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 448 | This is equivalent to the Python statement: del o[key]. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 449 | PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, const char *key); |
Martin v. Löwis | b0d71d0 | 2002-01-05 10:50:30 +0000 | [diff] [blame] | 450 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 451 | /* Delete the mapping for key from object 'o'. Returns -1 on failure. |
Martin v. Löwis | b0d71d0 | 2002-01-05 10:50:30 +0000 | [diff] [blame] | 452 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 453 | This is the equivalent of the Python statement: del o[key]. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 454 | PyAPI_FUNC(int) PyObject_DelItem(PyObject *o, PyObject *key); |
Guido van Rossum | 6cdc6f4 | 1996-08-21 17:41:54 +0000 | [diff] [blame] | 455 | |
Guido van Rossum | 6cdc6f4 | 1996-08-21 17:41:54 +0000 | [diff] [blame] | 456 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 457 | /* === Old Buffer API ============================================ */ |
| 458 | |
| 459 | /* FIXME: usage of these should all be replaced in Python itself |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 460 | but for backwards compatibility we will implement them. |
| 461 | Their usage without a corresponding "unlock" mechanism |
| 462 | may create issues (but they would already be there). */ |
Travis E. Oliphant | b99f762 | 2007-08-18 11:21:56 +0000 | [diff] [blame] | 463 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 464 | /* Takes an arbitrary object which must support the (character, single segment) |
| 465 | buffer interface and returns a pointer to a read-only memory location |
| 466 | useable as character based input for subsequent processing. |
| 467 | |
| 468 | Return 0 on success. buffer and buffer_len are only set in case no error |
| 469 | occurs. Otherwise, -1 is returned and an exception set. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 470 | PyAPI_FUNC(int) PyObject_AsCharBuffer(PyObject *obj, |
| 471 | const char **buffer, |
| 472 | Py_ssize_t *buffer_len) |
| 473 | Py_DEPRECATED(3.0); |
Guido van Rossum | fd9eed3 | 2000-03-10 22:35:06 +0000 | [diff] [blame] | 474 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 475 | /* Checks whether an arbitrary object supports the (character, single segment) |
| 476 | buffer interface. |
Guido van Rossum | fd9eed3 | 2000-03-10 22:35:06 +0000 | [diff] [blame] | 477 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 478 | Returns 1 on success, 0 on failure. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 479 | PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj) |
| 480 | Py_DEPRECATED(3.0); |
Jeremy Hylton | 89c3a22 | 2001-11-09 21:59:42 +0000 | [diff] [blame] | 481 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 482 | /* Same as PyObject_AsCharBuffer() except that this API expects (readable, |
| 483 | single segment) buffer interface and returns a pointer to a read-only memory |
| 484 | location which can contain arbitrary data. |
Jeremy Hylton | 89c3a22 | 2001-11-09 21:59:42 +0000 | [diff] [blame] | 485 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 486 | 0 is returned on success. buffer and buffer_len are only set in case no |
| 487 | error occurs. Otherwise, -1 is returned and an exception set. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 488 | PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj, |
| 489 | const void **buffer, |
| 490 | Py_ssize_t *buffer_len) |
| 491 | Py_DEPRECATED(3.0); |
Guido van Rossum | fd9eed3 | 2000-03-10 22:35:06 +0000 | [diff] [blame] | 492 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 493 | /* Takes an arbitrary object which must support the (writable, single segment) |
| 494 | buffer interface and returns a pointer to a writable memory location in |
| 495 | buffer of size 'buffer_len'. |
Guido van Rossum | fd9eed3 | 2000-03-10 22:35:06 +0000 | [diff] [blame] | 496 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 497 | Return 0 on success. buffer and buffer_len are only set in case no error |
| 498 | occurs. Otherwise, -1 is returned and an exception set. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 499 | PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *obj, |
| 500 | void **buffer, |
| 501 | Py_ssize_t *buffer_len) |
| 502 | Py_DEPRECATED(3.0); |
Guido van Rossum | fd9eed3 | 2000-03-10 22:35:06 +0000 | [diff] [blame] | 503 | |
Guido van Rossum | fd9eed3 | 2000-03-10 22:35:06 +0000 | [diff] [blame] | 504 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 505 | /* === New Buffer API ============================================ */ |
Travis E. Oliphant | b99f762 | 2007-08-18 11:21:56 +0000 | [diff] [blame] | 506 | |
Martin v. Löwis | c83bc3c | 2011-01-06 19:15:47 +0000 | [diff] [blame] | 507 | #ifndef Py_LIMITED_API |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 508 | |
| 509 | /* Return 1 if the getbuffer function is available, otherwise return 0. */ |
Travis E. Oliphant | b99f762 | 2007-08-18 11:21:56 +0000 | [diff] [blame] | 510 | #define PyObject_CheckBuffer(obj) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 511 | (((obj)->ob_type->tp_as_buffer != NULL) && \ |
| 512 | ((obj)->ob_type->tp_as_buffer->bf_getbuffer != NULL)) |
Travis E. Oliphant | b99f762 | 2007-08-18 11:21:56 +0000 | [diff] [blame] | 513 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 514 | /* This is a C-API version of the getbuffer function call. It checks |
| 515 | to make sure object has the required function pointer and issues the |
| 516 | call. |
Travis E. Oliphant | b99f762 | 2007-08-18 11:21:56 +0000 | [diff] [blame] | 517 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 518 | Returns -1 and raises an error on failure and returns 0 on success. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 519 | PyAPI_FUNC(int) PyObject_GetBuffer(PyObject *obj, Py_buffer *view, |
| 520 | int flags); |
Travis E. Oliphant | b99f762 | 2007-08-18 11:21:56 +0000 | [diff] [blame] | 521 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 522 | /* Get the memory area pointed to by the indices for the buffer given. |
| 523 | Note that view->ndim is the assumed size of indices. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 524 | PyAPI_FUNC(void *) PyBuffer_GetPointer(Py_buffer *view, Py_ssize_t *indices); |
Travis E. Oliphant | b99f762 | 2007-08-18 11:21:56 +0000 | [diff] [blame] | 525 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 526 | /* Return the implied itemsize of the data-format area from a |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 527 | struct-style description. */ |
| 528 | PyAPI_FUNC(int) PyBuffer_SizeFromFormat(const char *); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 529 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 530 | /* Implementation in memoryobject.c */ |
| 531 | PyAPI_FUNC(int) PyBuffer_ToContiguous(void *buf, Py_buffer *view, |
| 532 | Py_ssize_t len, char order); |
Travis E. Oliphant | b99f762 | 2007-08-18 11:21:56 +0000 | [diff] [blame] | 533 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 534 | PyAPI_FUNC(int) PyBuffer_FromContiguous(Py_buffer *view, void *buf, |
| 535 | Py_ssize_t len, char order); |
Travis E. Oliphant | b99f762 | 2007-08-18 11:21:56 +0000 | [diff] [blame] | 536 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 537 | /* Copy len bytes of data from the contiguous chunk of memory |
| 538 | pointed to by buf into the buffer exported by obj. Return |
| 539 | 0 on success and return -1 and raise a PyBuffer_Error on |
| 540 | error (i.e. the object does not have a buffer interface or |
| 541 | it is not working). |
Travis E. Oliphant | b99f762 | 2007-08-18 11:21:56 +0000 | [diff] [blame] | 542 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 543 | If fort is 'F', then if the object is multi-dimensional, |
| 544 | then the data will be copied into the array in |
| 545 | Fortran-style (first dimension varies the fastest). If |
| 546 | fort is 'C', then the data will be copied into the array |
| 547 | in C-style (last dimension varies the fastest). If fort |
| 548 | is 'A', then it does not matter and the copy will be made |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 549 | in whatever way is more efficient. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 550 | PyAPI_FUNC(int) PyObject_CopyData(PyObject *dest, PyObject *src); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 551 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 552 | /* Copy the data from the src buffer to the buffer of destination. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 553 | PyAPI_FUNC(int) PyBuffer_IsContiguous(const Py_buffer *view, char fort); |
Travis E. Oliphant | b99f762 | 2007-08-18 11:21:56 +0000 | [diff] [blame] | 554 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 555 | /*Fill the strides array with byte-strides of a contiguous |
| 556 | (Fortran-style if fort is 'F' or C-style otherwise) |
| 557 | array of the given shape with the given number of bytes |
| 558 | per element. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 559 | PyAPI_FUNC(void) PyBuffer_FillContiguousStrides(int ndims, |
| 560 | Py_ssize_t *shape, |
| 561 | Py_ssize_t *strides, |
| 562 | int itemsize, |
| 563 | char fort); |
Travis E. Oliphant | b99f762 | 2007-08-18 11:21:56 +0000 | [diff] [blame] | 564 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 565 | /* Fills in a buffer-info structure correctly for an exporter |
| 566 | that can only share a contiguous chunk of memory of |
| 567 | "unsigned bytes" of the given length. |
Travis E. Oliphant | b99f762 | 2007-08-18 11:21:56 +0000 | [diff] [blame] | 568 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 569 | Returns 0 on success and -1 (with raising an error) on error. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 570 | PyAPI_FUNC(int) PyBuffer_FillInfo(Py_buffer *view, PyObject *o, void *buf, |
| 571 | Py_ssize_t len, int readonly, |
| 572 | int flags); |
Travis E. Oliphant | b99f762 | 2007-08-18 11:21:56 +0000 | [diff] [blame] | 573 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 574 | /* Releases a Py_buffer obtained from getbuffer ParseTuple's "s*". */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 575 | PyAPI_FUNC(void) PyBuffer_Release(Py_buffer *view); |
Martin v. Löwis | 423be95 | 2008-08-13 15:53:07 +0000 | [diff] [blame] | 576 | |
Martin v. Löwis | c83bc3c | 2011-01-06 19:15:47 +0000 | [diff] [blame] | 577 | #endif /* Py_LIMITED_API */ |
Travis E. Oliphant | b99f762 | 2007-08-18 11:21:56 +0000 | [diff] [blame] | 578 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 579 | /* Takes an arbitrary object and returns the result of calling |
| 580 | obj.__format__(format_spec). */ |
| 581 | PyAPI_FUNC(PyObject *) PyObject_Format(PyObject *obj, |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 582 | PyObject *format_spec); |
Eric Smith | 8fd3eba | 2008-02-17 19:48:00 +0000 | [diff] [blame] | 583 | |
Guido van Rossum | 213c7a6 | 2001-04-23 14:08:49 +0000 | [diff] [blame] | 584 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 585 | /* ==== Iterators ================================================ */ |
| 586 | |
| 587 | /* Takes an object and returns an iterator for it. |
| 588 | This is typically a new iterator but if the argument is an iterator, this |
| 589 | returns itself. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 590 | PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *); |
Guido van Rossum | 59d1d2b | 2001-04-20 19:13:02 +0000 | [diff] [blame] | 591 | |
Guido van Rossum | 213c7a6 | 2001-04-23 14:08:49 +0000 | [diff] [blame] | 592 | #define PyIter_Check(obj) \ |
Amaury Forgeot d'Arc | f343e01 | 2009-01-12 23:58:21 +0000 | [diff] [blame] | 593 | ((obj)->ob_type->tp_iternext != NULL && \ |
| 594 | (obj)->ob_type->tp_iternext != &_PyObject_NextNotImplemented) |
Guido van Rossum | 213c7a6 | 2001-04-23 14:08:49 +0000 | [diff] [blame] | 595 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 596 | /* Takes an iterator object and calls its tp_iternext slot, |
| 597 | returning the next value. |
| 598 | |
| 599 | If the iterator is exhausted, this returns NULL without setting an |
| 600 | exception. |
| 601 | |
| 602 | NULL with an exception means an error occurred. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 603 | PyAPI_FUNC(PyObject *) PyIter_Next(PyObject *); |
Guido van Rossum | 213c7a6 | 2001-04-23 14:08:49 +0000 | [diff] [blame] | 604 | |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 605 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 606 | /* === Number Protocol ================================================== */ |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 607 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 608 | /* Returns 1 if the object 'o' provides numeric protocols, and 0 otherwise. |
| 609 | |
| 610 | This function always succeeds. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 611 | PyAPI_FUNC(int) PyNumber_Check(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 612 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 613 | /* Returns the result of adding o1 and o2, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 614 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 615 | This is the equivalent of the Python expression: o1 + o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 616 | PyAPI_FUNC(PyObject *) PyNumber_Add(PyObject *o1, PyObject *o2); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 617 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 618 | /* Returns the result of subtracting o2 from o1, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 619 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 620 | This is the equivalent of the Python expression: o1 - o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 621 | PyAPI_FUNC(PyObject *) PyNumber_Subtract(PyObject *o1, PyObject *o2); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 622 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 623 | /* Returns the result of multiplying o1 and o2, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 624 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 625 | This is the equivalent of the Python expression: o1 * o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 626 | PyAPI_FUNC(PyObject *) PyNumber_Multiply(PyObject *o1, PyObject *o2); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 627 | |
Serhiy Storchaka | 34d0ac8 | 2016-12-27 14:57:39 +0200 | [diff] [blame] | 628 | #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 629 | /* This is the equivalent of the Python expression: o1 @ o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 630 | PyAPI_FUNC(PyObject *) PyNumber_MatrixMultiply(PyObject *o1, PyObject *o2); |
Serhiy Storchaka | 34d0ac8 | 2016-12-27 14:57:39 +0200 | [diff] [blame] | 631 | #endif |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 632 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 633 | /* Returns the result of dividing o1 by o2 giving an integral result, |
| 634 | or NULL on failure. |
Guido van Rossum | 4668b00 | 2001-08-08 05:00:18 +0000 | [diff] [blame] | 635 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 636 | This is the equivalent of the Python expression: o1 // o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 637 | PyAPI_FUNC(PyObject *) PyNumber_FloorDivide(PyObject *o1, PyObject *o2); |
Guido van Rossum | 4668b00 | 2001-08-08 05:00:18 +0000 | [diff] [blame] | 638 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 639 | /* Returns the result of dividing o1 by o2 giving a float result, or NULL on |
| 640 | failure. |
Guido van Rossum | 4668b00 | 2001-08-08 05:00:18 +0000 | [diff] [blame] | 641 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 642 | This is the equivalent of the Python expression: o1 / o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 643 | PyAPI_FUNC(PyObject *) PyNumber_TrueDivide(PyObject *o1, PyObject *o2); |
Guido van Rossum | 4668b00 | 2001-08-08 05:00:18 +0000 | [diff] [blame] | 644 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 645 | /* Returns the remainder of dividing o1 by o2, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 646 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 647 | This is the equivalent of the Python expression: o1 % o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 648 | PyAPI_FUNC(PyObject *) PyNumber_Remainder(PyObject *o1, PyObject *o2); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 649 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 650 | /* See the built-in function divmod. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 651 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 652 | Returns NULL on failure. |
| 653 | |
| 654 | This is the equivalent of the Python expression: divmod(o1, o2). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 655 | PyAPI_FUNC(PyObject *) PyNumber_Divmod(PyObject *o1, PyObject *o2); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 656 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 657 | /* See the built-in function pow. Returns NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 658 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 659 | This is the equivalent of the Python expression: pow(o1, o2, o3), |
| 660 | where o3 is optional. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 661 | PyAPI_FUNC(PyObject *) PyNumber_Power(PyObject *o1, PyObject *o2, |
| 662 | PyObject *o3); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 663 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 664 | /* Returns the negation of o on success, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 665 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 666 | This is the equivalent of the Python expression: -o. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 667 | PyAPI_FUNC(PyObject *) PyNumber_Negative(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 668 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 669 | /* Returns the positive of o on success, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 670 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 671 | This is the equivalent of the Python expression: +o. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 672 | PyAPI_FUNC(PyObject *) PyNumber_Positive(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 673 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 674 | /* Returns the absolute value of 'o', or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 675 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 676 | This is the equivalent of the Python expression: abs(o). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 677 | PyAPI_FUNC(PyObject *) PyNumber_Absolute(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 678 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 679 | /* Returns the bitwise negation of 'o' on success, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 680 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 681 | This is the equivalent of the Python expression: ~o. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 682 | PyAPI_FUNC(PyObject *) PyNumber_Invert(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 683 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 684 | /* Returns the result of left shifting o1 by o2 on success, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 685 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 686 | This is the equivalent of the Python expression: o1 << o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 687 | PyAPI_FUNC(PyObject *) PyNumber_Lshift(PyObject *o1, PyObject *o2); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 688 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 689 | /* Returns the result of right shifting o1 by o2 on success, or NULL on |
| 690 | failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 691 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 692 | This is the equivalent of the Python expression: o1 >> o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 693 | PyAPI_FUNC(PyObject *) PyNumber_Rshift(PyObject *o1, PyObject *o2); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 694 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 695 | /* Returns the result of bitwise and of o1 and o2 on success, or NULL on |
| 696 | failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 697 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 698 | This is the equivalent of the Python expression: o1 & o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 699 | PyAPI_FUNC(PyObject *) PyNumber_And(PyObject *o1, PyObject *o2); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 700 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 701 | /* Returns the bitwise exclusive or of o1 by o2 on success, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 702 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 703 | This is the equivalent of the Python expression: o1 ^ o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 704 | PyAPI_FUNC(PyObject *) PyNumber_Xor(PyObject *o1, PyObject *o2); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 705 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 706 | /* Returns the result of bitwise or on o1 and o2 on success, or NULL on |
| 707 | failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 708 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 709 | This is the equivalent of the Python expression: o1 | o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 710 | PyAPI_FUNC(PyObject *) PyNumber_Or(PyObject *o1, PyObject *o2); |
| 711 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 712 | #define PyIndex_Check(obj) \ |
| 713 | ((obj)->ob_type->tp_as_number != NULL && \ |
| 714 | (obj)->ob_type->tp_as_number->nb_index != NULL) |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 715 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 716 | /* Returns the object 'o' converted to a Python int, or NULL with an exception |
| 717 | raised on failure. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 718 | PyAPI_FUNC(PyObject *) PyNumber_Index(PyObject *o); |
Guido van Rossum | 38fff8c | 2006-03-07 18:50:55 +0000 | [diff] [blame] | 719 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 720 | /* Returns the object 'o' converted to Py_ssize_t by going through |
| 721 | PyNumber_Index() first. |
Guido van Rossum | 38fff8c | 2006-03-07 18:50:55 +0000 | [diff] [blame] | 722 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 723 | If an overflow error occurs while converting the int to Py_ssize_t, then the |
| 724 | second argument 'exc' is the error-type to return. If it is NULL, then the |
| 725 | overflow error is cleared and the value is clipped. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 726 | PyAPI_FUNC(Py_ssize_t) PyNumber_AsSsize_t(PyObject *o, PyObject *exc); |
Thomas Wouters | 00ee7ba | 2006-08-21 19:07:27 +0000 | [diff] [blame] | 727 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 728 | /* Returns the object 'o' converted to an integer object on success, or NULL |
| 729 | on failure. |
Guido van Rossum | 38fff8c | 2006-03-07 18:50:55 +0000 | [diff] [blame] | 730 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 731 | This is the equivalent of the Python expression: int(o). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 732 | PyAPI_FUNC(PyObject *) PyNumber_Long(PyObject *o); |
Mark Dickinson | d746768 | 2009-01-10 22:14:33 +0000 | [diff] [blame] | 733 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 734 | /* Returns the object 'o' converted to a float object on success, or NULL |
| 735 | on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 736 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 737 | This is the equivalent of the Python expression: float(o). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 738 | PyAPI_FUNC(PyObject *) PyNumber_Float(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 739 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 740 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 741 | /* --- In-place variants of (some of) the above number protocol functions -- */ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 742 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 743 | /* Returns the result of adding o2 to o1, possibly in-place, or NULL |
| 744 | on failure. |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 745 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 746 | This is the equivalent of the Python expression: o1 += o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 747 | PyAPI_FUNC(PyObject *) PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2); |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 748 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 749 | /* Returns the result of subtracting o2 from o1, possibly in-place or |
| 750 | NULL on failure. |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 751 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 752 | This is the equivalent of the Python expression: o1 -= o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 753 | PyAPI_FUNC(PyObject *) PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2); |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 754 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 755 | /* Returns the result of multiplying o1 by o2, possibly in-place, or NULL on |
| 756 | failure. |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 757 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 758 | This is the equivalent of the Python expression: o1 *= o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 759 | PyAPI_FUNC(PyObject *) PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2); |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 760 | |
Serhiy Storchaka | 34d0ac8 | 2016-12-27 14:57:39 +0200 | [diff] [blame] | 761 | #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 762 | /* This is the equivalent of the Python expression: o1 @= o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 763 | PyAPI_FUNC(PyObject *) PyNumber_InPlaceMatrixMultiply(PyObject *o1, PyObject *o2); |
Serhiy Storchaka | 34d0ac8 | 2016-12-27 14:57:39 +0200 | [diff] [blame] | 764 | #endif |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 765 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 766 | /* Returns the result of dividing o1 by o2 giving an integral result, possibly |
| 767 | in-place, or NULL on failure. |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 768 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 769 | This is the equivalent of the Python expression: o1 /= o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 770 | PyAPI_FUNC(PyObject *) PyNumber_InPlaceFloorDivide(PyObject *o1, |
| 771 | PyObject *o2); |
Guido van Rossum | 4668b00 | 2001-08-08 05:00:18 +0000 | [diff] [blame] | 772 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 773 | /* Returns the result of dividing o1 by o2 giving a float result, possibly |
| 774 | in-place, or null on failure. |
Guido van Rossum | 4668b00 | 2001-08-08 05:00:18 +0000 | [diff] [blame] | 775 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 776 | This is the equivalent of the Python expression: o1 /= o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 777 | PyAPI_FUNC(PyObject *) PyNumber_InPlaceTrueDivide(PyObject *o1, |
| 778 | PyObject *o2); |
Guido van Rossum | 4668b00 | 2001-08-08 05:00:18 +0000 | [diff] [blame] | 779 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 780 | /* Returns the remainder of dividing o1 by o2, possibly in-place, or NULL on |
| 781 | failure. |
Guido van Rossum | 4668b00 | 2001-08-08 05:00:18 +0000 | [diff] [blame] | 782 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 783 | This is the equivalent of the Python expression: o1 %= o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 784 | PyAPI_FUNC(PyObject *) PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2); |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 785 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 786 | /* Returns the result of raising o1 to the power of o2, possibly in-place, |
| 787 | or NULL on failure. |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 788 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 789 | This is the equivalent of the Python expression: o1 **= o2, |
| 790 | or o1 = pow(o1, o2, o3) if o3 is present. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 791 | PyAPI_FUNC(PyObject *) PyNumber_InPlacePower(PyObject *o1, PyObject *o2, |
| 792 | PyObject *o3); |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 793 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 794 | /* Returns the result of left shifting o1 by o2, possibly in-place, or NULL |
| 795 | on failure. |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 796 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 797 | This is the equivalent of the Python expression: o1 <<= o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 798 | PyAPI_FUNC(PyObject *) PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2); |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 799 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 800 | /* Returns the result of right shifting o1 by o2, possibly in-place or NULL |
| 801 | on failure. |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 802 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 803 | This is the equivalent of the Python expression: o1 >>= o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 804 | PyAPI_FUNC(PyObject *) PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2); |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 805 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 806 | /* Returns the result of bitwise and of o1 and o2, possibly in-place, or NULL |
| 807 | on failure. |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 808 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 809 | This is the equivalent of the Python expression: o1 &= o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 810 | PyAPI_FUNC(PyObject *) PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2); |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 811 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 812 | /* Returns the bitwise exclusive or of o1 by o2, possibly in-place, or NULL |
| 813 | on failure. |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 814 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 815 | This is the equivalent of the Python expression: o1 ^= o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 816 | PyAPI_FUNC(PyObject *) PyNumber_InPlaceXor(PyObject *o1, PyObject *o2); |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 817 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 818 | /* Returns the result of bitwise or of o1 and o2, possibly in-place, |
| 819 | or NULL on failure. |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 820 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 821 | This is the equivalent of the Python expression: o1 |= o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 822 | PyAPI_FUNC(PyObject *) PyNumber_InPlaceOr(PyObject *o1, PyObject *o2); |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 823 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 824 | /* Returns the integer n converted to a string with a base, with a base |
| 825 | marker of 0b, 0o or 0x prefixed if applicable. |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 826 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 827 | If n is not an int object, it is converted with PyNumber_Index first. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 828 | PyAPI_FUNC(PyObject *) PyNumber_ToBase(PyObject *n, int base); |
Guido van Rossum | cd16bf6 | 2007-06-13 18:07:49 +0000 | [diff] [blame] | 829 | |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 830 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 831 | /* === Sequence protocol ================================================ */ |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 832 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 833 | /* Return 1 if the object provides sequence protocol, and zero |
| 834 | otherwise. |
| 835 | |
| 836 | This function always succeeds. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 837 | PyAPI_FUNC(int) PySequence_Check(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 838 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 839 | /* Return the size of sequence object o, or -1 on failure. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 840 | PyAPI_FUNC(Py_ssize_t) PySequence_Size(PyObject *o); |
Jeremy Hylton | 6253f83 | 2000-07-12 12:56:19 +0000 | [diff] [blame] | 841 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 842 | /* For DLL compatibility */ |
Marc-André Lemburg | cf5f358 | 2000-07-17 09:22:55 +0000 | [diff] [blame] | 843 | #undef PySequence_Length |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 844 | PyAPI_FUNC(Py_ssize_t) PySequence_Length(PyObject *o); |
Marc-André Lemburg | cf5f358 | 2000-07-17 09:22:55 +0000 | [diff] [blame] | 845 | #define PySequence_Length PySequence_Size |
| 846 | |
| 847 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 848 | /* Return the concatenation of o1 and o2 on success, and NULL on failure. |
| 849 | |
| 850 | This is the equivalent of the Python expression: o1 + o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 851 | PyAPI_FUNC(PyObject *) PySequence_Concat(PyObject *o1, PyObject *o2); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 852 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 853 | /* Return the result of repeating sequence object 'o' 'count' times, |
| 854 | or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 855 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 856 | This is the equivalent of the Python expression: o * count. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 857 | PyAPI_FUNC(PyObject *) PySequence_Repeat(PyObject *o, Py_ssize_t count); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 858 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 859 | /* Return the ith element of o, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 860 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 861 | This is the equivalent of the Python expression: o[i]. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 862 | PyAPI_FUNC(PyObject *) PySequence_GetItem(PyObject *o, Py_ssize_t i); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 863 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 864 | /* Return the slice of sequence object o between i1 and i2, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 865 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 866 | This is the equivalent of the Python expression: o[i1:i2]. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 867 | PyAPI_FUNC(PyObject *) PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 868 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 869 | /* Assign object 'v' to the ith element of the sequence 'o'. Raise an exception |
| 870 | and return -1 on failure; return 0 on success. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 871 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 872 | This is the equivalent of the Python statement o[i] = v. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 873 | PyAPI_FUNC(int) PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 874 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 875 | /* Delete the 'i'-th element of the sequence 'v'. Returns -1 on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 876 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 877 | This is the equivalent of the Python statement: del o[i]. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 878 | PyAPI_FUNC(int) PySequence_DelItem(PyObject *o, Py_ssize_t i); |
Guido van Rossum | 6cdc6f4 | 1996-08-21 17:41:54 +0000 | [diff] [blame] | 879 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 880 | /* Assign the sequence object 'v' to the slice in sequence object 'o', |
| 881 | from 'i1' to 'i2'. Returns -1 on failure. |
Guido van Rossum | 6cdc6f4 | 1996-08-21 17:41:54 +0000 | [diff] [blame] | 882 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 883 | This is the equivalent of the Python statement: o[i1:i2] = v. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 884 | PyAPI_FUNC(int) PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2, |
| 885 | PyObject *v); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 886 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 887 | /* Delete the slice in sequence object 'o' from 'i1' to 'i2'. |
| 888 | Returns -1 on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 889 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 890 | This is the equivalent of the Python statement: del o[i1:i2]. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 891 | PyAPI_FUNC(int) PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2); |
Guido van Rossum | 6cdc6f4 | 1996-08-21 17:41:54 +0000 | [diff] [blame] | 892 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 893 | /* Returns the sequence 'o' as a tuple on success, and NULL on failure. |
Guido van Rossum | 6cdc6f4 | 1996-08-21 17:41:54 +0000 | [diff] [blame] | 894 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 895 | This is equivalent to the Python expression: tuple(o). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 896 | PyAPI_FUNC(PyObject *) PySequence_Tuple(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 897 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 898 | /* Returns the sequence 'o' as a list on success, and NULL on failure. |
| 899 | This is equivalent to the Python expression: list(o) */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 900 | PyAPI_FUNC(PyObject *) PySequence_List(PyObject *o); |
Guido van Rossum | f39fc43 | 1997-03-04 18:31:47 +0000 | [diff] [blame] | 901 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 902 | /* Return the sequence 'o' as a list, unless it's already a tuple or list. |
| 903 | |
| 904 | Use PySequence_Fast_GET_ITEM to access the members of this list, and |
| 905 | PySequence_Fast_GET_SIZE to get its length. |
| 906 | |
| 907 | Returns NULL on failure. If the object does not support iteration, raises a |
| 908 | TypeError exception with 'm' as the message text. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 909 | PyAPI_FUNC(PyObject *) PySequence_Fast(PyObject *o, const char* m); |
Andrew M. Kuchling | 74042d6 | 2000-06-18 18:43:14 +0000 | [diff] [blame] | 910 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 911 | /* Return the size of the sequence 'o', assuming that 'o' was returned by |
| 912 | PySequence_Fast and is not NULL. */ |
Tim Peters | 1fc240e | 2001-10-26 05:06:50 +0000 | [diff] [blame] | 913 | #define PySequence_Fast_GET_SIZE(o) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 914 | (PyList_Check(o) ? PyList_GET_SIZE(o) : PyTuple_GET_SIZE(o)) |
Tim Peters | 1fc240e | 2001-10-26 05:06:50 +0000 | [diff] [blame] | 915 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 916 | /* Return the 'i'-th element of the sequence 'o', assuming that o was returned |
| 917 | by PySequence_Fast, and that i is within bounds. */ |
Andrew M. Kuchling | 74042d6 | 2000-06-18 18:43:14 +0000 | [diff] [blame] | 918 | #define PySequence_Fast_GET_ITEM(o, i)\ |
| 919 | (PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i)) |
Andrew M. Kuchling | 74042d6 | 2000-06-18 18:43:14 +0000 | [diff] [blame] | 920 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 921 | /* Assume tp_as_sequence and sq_item exist and that 'i' does not |
| 922 | need to be corrected for a negative index. */ |
Martin v. Löwis | 01f94bd | 2002-05-08 08:44:21 +0000 | [diff] [blame] | 923 | #define PySequence_ITEM(o, i)\ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 924 | ( Py_TYPE(o)->tp_as_sequence->sq_item(o, i) ) |
Martin v. Löwis | 01f94bd | 2002-05-08 08:44:21 +0000 | [diff] [blame] | 925 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 926 | /* Return a pointer to the underlying item array for |
| 927 | an object retured by PySequence_Fast */ |
Raymond Hettinger | 42bec93 | 2004-03-12 16:38:17 +0000 | [diff] [blame] | 928 | #define PySequence_Fast_ITEMS(sf) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 929 | (PyList_Check(sf) ? ((PyListObject *)(sf))->ob_item \ |
| 930 | : ((PyTupleObject *)(sf))->ob_item) |
Raymond Hettinger | c1e4f9d | 2004-03-12 08:04:00 +0000 | [diff] [blame] | 931 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 932 | /* Return the number of occurrences on value on 'o', that is, return |
| 933 | the number of keys for which o[key] == value. |
| 934 | |
| 935 | On failure, return -1. This is equivalent to the Python expression: |
| 936 | o.count(value). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 937 | PyAPI_FUNC(Py_ssize_t) PySequence_Count(PyObject *o, PyObject *value); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 938 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 939 | /* Return 1 if 'ob' is in the sequence 'seq'; 0 if 'ob' is not in the sequence |
| 940 | 'seq'; -1 on error. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 941 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 942 | Use __contains__ if possible, else _PySequence_IterSearch(). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 943 | PyAPI_FUNC(int) PySequence_Contains(PyObject *seq, PyObject *ob); |
Tim Peters | cb8d368 | 2001-05-05 21:05:01 +0000 | [diff] [blame] | 944 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 945 | #ifndef Py_LIMITED_API |
Tim Peters | 16a77ad | 2001-09-08 04:00:12 +0000 | [diff] [blame] | 946 | #define PY_ITERSEARCH_COUNT 1 |
| 947 | #define PY_ITERSEARCH_INDEX 2 |
| 948 | #define PY_ITERSEARCH_CONTAINS 3 |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 949 | |
| 950 | /* Iterate over seq. |
| 951 | |
| 952 | Result depends on the operation: |
| 953 | |
| 954 | PY_ITERSEARCH_COUNT: return # of times obj appears in seq; -1 if |
| 955 | error. |
| 956 | PY_ITERSEARCH_INDEX: return 0-based index of first occurrence of |
| 957 | obj in seq; set ValueError and return -1 if none found; |
| 958 | also return -1 on error. |
| 959 | PY_ITERSEARCH_CONTAINS: return 1 if obj in seq, else 0; -1 on |
| 960 | error. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 961 | PyAPI_FUNC(Py_ssize_t) _PySequence_IterSearch(PyObject *seq, |
| 962 | PyObject *obj, int operation); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 963 | #endif |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 964 | |
Guido van Rossum | 8368453 | 1999-03-17 18:44:39 +0000 | [diff] [blame] | 965 | |
| 966 | /* For DLL-level backwards compatibility */ |
| 967 | #undef PySequence_In |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 968 | /* Determine if the sequence 'o' contains 'value'. If an item in 'o' is equal |
| 969 | to 'value', return 1, otherwise return 0. On error, return -1. |
| 970 | |
| 971 | This is equivalent to the Python expression: value in o. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 972 | PyAPI_FUNC(int) PySequence_In(PyObject *o, PyObject *value); |
Guido van Rossum | 8368453 | 1999-03-17 18:44:39 +0000 | [diff] [blame] | 973 | |
| 974 | /* For source-level backwards compatibility */ |
Guido van Rossum | f1536db | 1998-08-23 22:06:59 +0000 | [diff] [blame] | 975 | #define PySequence_In PySequence_Contains |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 976 | |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 977 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 978 | /* Return the first index for which o[i] == value. |
| 979 | On error, return -1. |
| 980 | |
| 981 | This is equivalent to the Python expression: o.index(value). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 982 | PyAPI_FUNC(Py_ssize_t) PySequence_Index(PyObject *o, PyObject *value); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 983 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 984 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 985 | /* --- In-place versions of some of the above Sequence functions --- */ |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 986 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 987 | /* Append sequence 'o2' to sequence 'o1', in-place when possible. Return the |
| 988 | resulting object, which could be 'o1', or NULL on failure. |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 989 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 990 | This is the equivalent of the Python expression: o1 += o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 991 | PyAPI_FUNC(PyObject *) PySequence_InPlaceConcat(PyObject *o1, PyObject *o2); |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 992 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 993 | /* Repeat sequence 'o' by 'count', in-place when possible. Return the resulting |
| 994 | object, which could be 'o', or NULL on failure. |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 995 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 996 | This is the equivalent of the Python expression: o1 *= count. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 997 | PyAPI_FUNC(PyObject *) PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count); |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 998 | |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 999 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 1000 | /* === Mapping protocol ================================================= */ |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 1001 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 1002 | /* Return 1 if the object provides mapping protocol, and 0 otherwise. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 1003 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 1004 | This function always succeeds. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 1005 | PyAPI_FUNC(int) PyMapping_Check(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 1006 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 1007 | /* Returns the number of keys in mapping object 'o' on success, and -1 on |
| 1008 | failure. For objects that do not provide sequence protocol, this is |
| 1009 | equivalent to the Python expression: len(o). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 1010 | PyAPI_FUNC(Py_ssize_t) PyMapping_Size(PyObject *o); |
Jeremy Hylton | 6253f83 | 2000-07-12 12:56:19 +0000 | [diff] [blame] | 1011 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 1012 | /* For DLL compatibility */ |
Marc-André Lemburg | cf5f358 | 2000-07-17 09:22:55 +0000 | [diff] [blame] | 1013 | #undef PyMapping_Length |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 1014 | PyAPI_FUNC(Py_ssize_t) PyMapping_Length(PyObject *o); |
Marc-André Lemburg | cf5f358 | 2000-07-17 09:22:55 +0000 | [diff] [blame] | 1015 | #define PyMapping_Length PyMapping_Size |
| 1016 | |
| 1017 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 1018 | /* Implemented as a macro: |
Guido van Rossum | a25e5e9 | 1996-09-06 13:48:38 +0000 | [diff] [blame] | 1019 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 1020 | int PyMapping_DelItemString(PyObject *o, const char *key); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 1021 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 1022 | Remove the mapping for object 'key' from the mapping 'o'. Returns -1 on |
| 1023 | failure. |
| 1024 | |
| 1025 | This is equivalent to the Python statement: del o[key]. */ |
Jeremy Hylton | 7c7ee5f | 2001-11-28 16:20:07 +0000 | [diff] [blame] | 1026 | #define PyMapping_DelItemString(O,K) PyObject_DelItemString((O),(K)) |
Guido van Rossum | a25e5e9 | 1996-09-06 13:48:38 +0000 | [diff] [blame] | 1027 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 1028 | /* Implemented as a macro: |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 1029 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 1030 | int PyMapping_DelItem(PyObject *o, PyObject *key); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 1031 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 1032 | Remove the mapping for object 'key' from the mapping object 'o'. |
| 1033 | Returns -1 on failure. |
| 1034 | |
| 1035 | This is equivalent to the Python statement: del o[key]. */ |
Jeremy Hylton | 7c7ee5f | 2001-11-28 16:20:07 +0000 | [diff] [blame] | 1036 | #define PyMapping_DelItem(O,K) PyObject_DelItem((O),(K)) |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 1037 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 1038 | /* On success, return 1 if the mapping object 'o' has the key 'key', |
| 1039 | and 0 otherwise. |
| 1040 | |
| 1041 | This is equivalent to the Python expression: key in o. |
| 1042 | |
| 1043 | This function always succeeds. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 1044 | PyAPI_FUNC(int) PyMapping_HasKeyString(PyObject *o, const char *key); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 1045 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 1046 | /* Return 1 if the mapping object has the key 'key', and 0 otherwise. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 1047 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 1048 | This is equivalent to the Python expression: key in o. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 1049 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 1050 | This function always succeeds. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 1051 | PyAPI_FUNC(int) PyMapping_HasKey(PyObject *o, PyObject *key); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 1052 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 1053 | /* On success, return a list or tuple of the keys in mapping object 'o'. |
| 1054 | On failure, return NULL. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 1055 | PyAPI_FUNC(PyObject *) PyMapping_Keys(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 1056 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 1057 | /* On success, return a list or tuple of the values in mapping object 'o'. |
| 1058 | On failure, return NULL. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 1059 | PyAPI_FUNC(PyObject *) PyMapping_Values(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 1060 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 1061 | /* On success, return a list or tuple of the items in mapping object 'o', |
| 1062 | where each item is a tuple containing a key-value pair. On failure, return |
| 1063 | NULL. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 1064 | PyAPI_FUNC(PyObject *) PyMapping_Items(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 1065 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 1066 | /* Return element of o corresponding to the object, key, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 1067 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 1068 | This is the equivalent of the Python expression: o[key]. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 1069 | PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o, |
| 1070 | const char *key); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 1071 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 1072 | /* Map the object 'key' to the value 'v' in the mapping 'o'. |
| 1073 | Returns -1 on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 1074 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 1075 | This is the equivalent of the Python statement: o[key]=v. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 1076 | PyAPI_FUNC(int) PyMapping_SetItemString(PyObject *o, const char *key, |
| 1077 | PyObject *value); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 1078 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 1079 | /* isinstance(object, typeorclass) */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1080 | PyAPI_FUNC(int) PyObject_IsInstance(PyObject *object, PyObject *typeorclass); |
Guido van Rossum | 823649d | 2001-03-21 18:40:58 +0000 | [diff] [blame] | 1081 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 1082 | /* issubclass(object, typeorclass) */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1083 | PyAPI_FUNC(int) PyObject_IsSubclass(PyObject *object, PyObject *typeorclass); |
Guido van Rossum | 823649d | 2001-03-21 18:40:58 +0000 | [diff] [blame] | 1084 | |
| 1085 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 1086 | #ifndef Py_LIMITED_API |
Antoine Pitrou | ec569b7 | 2008-08-26 22:40:48 +0000 | [diff] [blame] | 1087 | PyAPI_FUNC(int) _PyObject_RealIsInstance(PyObject *inst, PyObject *cls); |
| 1088 | |
| 1089 | PyAPI_FUNC(int) _PyObject_RealIsSubclass(PyObject *derived, PyObject *cls); |
| 1090 | |
Gregory P. Smith | fb94c5f | 2010-03-14 06:49:55 +0000 | [diff] [blame] | 1091 | PyAPI_FUNC(char *const *) _PySequence_BytesToCharpArray(PyObject* self); |
| 1092 | |
| 1093 | PyAPI_FUNC(void) _Py_FreeCharPArray(char *const array[]); |
Antoine Pitrou | ec569b7 | 2008-08-26 22:40:48 +0000 | [diff] [blame] | 1094 | |
Antoine Pitrou | f68c2a7 | 2010-09-01 12:58:21 +0000 | [diff] [blame] | 1095 | /* For internal use by buffer API functions */ |
| 1096 | PyAPI_FUNC(void) _Py_add_one_to_index_F(int nd, Py_ssize_t *index, |
| 1097 | const Py_ssize_t *shape); |
| 1098 | PyAPI_FUNC(void) _Py_add_one_to_index_C(int nd, Py_ssize_t *index, |
| 1099 | const Py_ssize_t *shape); |
Serhiy Storchaka | 762bf40 | 2017-03-30 09:15:31 +0300 | [diff] [blame] | 1100 | |
| 1101 | /* Convert Python int to Py_ssize_t. Do nothing if the argument is None. */ |
| 1102 | PyAPI_FUNC(int) _Py_convert_optional_to_ssize_t(PyObject *, void *); |
Serhiy Storchaka | 9fab79b | 2016-09-11 11:03:14 +0300 | [diff] [blame] | 1103 | #endif /* !Py_LIMITED_API */ |
Antoine Pitrou | f68c2a7 | 2010-09-01 12:58:21 +0000 | [diff] [blame] | 1104 | |
| 1105 | |
Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 1106 | #ifdef __cplusplus |
| 1107 | } |
| 1108 | #endif |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 1109 | #endif /* Py_ABSTRACTOBJECT_H */ |