cython

Форк
0
433 строки · 19.2 Кб
1
from libc.stdio cimport FILE
2
cimport cpython.type
3

4
cdef extern from "Python.h":
5

6
    ctypedef struct PyObject  # forward declaration
7

8
    ctypedef object (*newfunc)(cpython.type.type, PyObject*, PyObject*)  # (type, args|NULL, kwargs|NULL)
9

10
    ctypedef object (*unaryfunc)(object)
11
    ctypedef object (*binaryfunc)(object, object)
12
    ctypedef object (*ternaryfunc)(object, object, object)
13
    ctypedef int (*inquiry)(object) except -1
14
    ctypedef Py_ssize_t (*lenfunc)(object) except -1
15
    ctypedef object (*ssizeargfunc)(object, Py_ssize_t)
16
    ctypedef object (*ssizessizeargfunc)(object, Py_ssize_t, Py_ssize_t)
17
    ctypedef int (*ssizeobjargproc)(object, Py_ssize_t, object) except -1
18
    ctypedef int (*ssizessizeobjargproc)(object, Py_ssize_t, Py_ssize_t, object) except -1
19
    ctypedef int (*objobjargproc)(object, object, object) except -1
20
    ctypedef int (*objobjproc)(object, object) except -1
21

22
    ctypedef Py_hash_t (*hashfunc)(object) except -1
23
    ctypedef object (*reprfunc)(object)
24

25
    ctypedef int (*cmpfunc)(object, object) except -2
26
    ctypedef object (*richcmpfunc)(object, object, int)
27

28
    # The following functions use 'PyObject*' as first argument instead of 'object' to prevent
29
    # accidental reference counting when calling them during a garbage collection run.
30
    ctypedef void (*destructor)(PyObject*)
31
    ctypedef int (*visitproc)(PyObject*, void *) except -1
32
    ctypedef int (*traverseproc)(PyObject*, visitproc, void*) except -1
33
    ctypedef void (*freefunc)(void*)
34

35
    ctypedef object (*descrgetfunc)(object, object, object)
36
    ctypedef int (*descrsetfunc)(object, object, object) except -1
37

38
    ctypedef object (*PyCFunction)(object, object)
39

40
    ctypedef struct PyMethodDef:
41
        const char* ml_name
42
        PyCFunction ml_meth
43
        int ml_flags
44
        const char* ml_doc
45

46
    ctypedef struct PyTypeObject:
47
        const char* tp_name
48
        const char* tp_doc
49
        Py_ssize_t tp_basicsize
50
        Py_ssize_t tp_itemsize
51
        Py_ssize_t tp_dictoffset
52
        unsigned long tp_flags
53

54
        newfunc tp_new
55
        destructor tp_dealloc
56
        destructor tp_del
57
        destructor tp_finalize
58
        traverseproc tp_traverse
59
        inquiry tp_clear
60
        freefunc tp_free
61

62
        ternaryfunc tp_call
63
        hashfunc tp_hash
64
        reprfunc tp_str
65
        reprfunc tp_repr
66

67
        cmpfunc tp_compare
68
        richcmpfunc tp_richcompare
69

70
        PyMethodDef* tp_methods
71

72
        PyTypeObject* tp_base
73
        PyObject* tp_dict
74

75
        descrgetfunc tp_descr_get
76
        descrsetfunc tp_descr_set
77

78
        unsigned int tp_version_tag
79

80
    ctypedef struct PyObject:
81
        Py_ssize_t ob_refcnt
82
        PyTypeObject *ob_type
83

84
    cdef PyTypeObject *Py_TYPE(object)
85

86
    void* PyObject_Malloc(size_t)
87
    void* PyObject_Realloc(void *, size_t)
88
    void PyObject_Free(void *)
89

90
    #####################################################################
91
    # 6.1 Object Protocol
92
    #####################################################################
93
    int PyObject_Print(object o, FILE *fp, int flags) except -1
94
    # Print an object o, on file fp. Returns -1 on error. The flags
95
    # argument is used to enable certain printing options. The only
96
    # option currently supported is Py_PRINT_RAW; if given, the str()
97
    # of the object is written instead of the repr().
98

99
    bint PyObject_HasAttrString(object o, const char *attr_name)
100
    # Returns 1 if o has the attribute attr_name, and 0
101
    # otherwise. This is equivalent to the Python expression
102
    # "hasattr(o, attr_name)". This function always succeeds.
103

104
    object PyObject_GetAttrString(object o, const char *attr_name)
105
    # Return value: New reference.  Retrieve an attribute named
106
    # attr_name from object o. Returns the attribute value on success,
107
    # or NULL on failure. This is the equivalent of the Python
108
    # expression "o.attr_name".
109

110
    bint PyObject_HasAttr(object o, object attr_name)
111
    # Returns 1 if o has the attribute attr_name, and 0
112
    # otherwise. This is equivalent to the Python expression
113
    # "hasattr(o, attr_name)". This function always succeeds.
114

115
    object PyObject_GetAttr(object o, object attr_name)
116
    # Return value: New reference.  Retrieve an attribute named
117
    # attr_name from object o. Returns the attribute value on success,
118
    # or NULL on failure. This is the equivalent of the Python
119
    # expression "o.attr_name".
120

121
    object PyObject_GenericGetAttr(object o, object attr_name)
122

123
    int PyObject_SetAttrString(object o, const char *attr_name, object v) except -1
124
    # Set the value of the attribute named attr_name, for object o, to
125
    # the value v. Returns -1 on failure. This is the equivalent of
126
    # the Python statement "o.attr_name = v".
127

128
    int PyObject_SetAttr(object o, object attr_name, object v) except -1
129
    # Set the value of the attribute named attr_name, for object o, to
130
    # the value v. Returns -1 on failure. This is the equivalent of
131
    # the Python statement "o.attr_name = v".
132

133
    int PyObject_GenericSetAttr(object o, object attr_name, object v) except -1
134

135
    int PyObject_DelAttrString(object o, const char *attr_name) except -1
136
    # Delete attribute named attr_name, for object o. Returns -1 on
137
    # failure. This is the equivalent of the Python statement: "del
138
    # o.attr_name".
139

140
    int PyObject_DelAttr(object o, object attr_name) except -1
141
    # Delete attribute named attr_name, for object o. Returns -1 on
142
    # failure. This is the equivalent of the Python statement "del
143
    # o.attr_name".
144

145
    object PyObject_GenericGetDict(object o, void *context)
146
    # Return value: New reference.
147
    # A generic implementation for the getter of a __dict__ descriptor. It
148
    # creates the dictionary if necessary.
149
    # New in version 3.3.
150

151
    int PyObject_GenericSetDict(object o, object value, void *context) except -1
152
    # A generic implementation for the setter of a __dict__ descriptor. This
153
    # implementation does not allow the dictionary to be deleted.
154
    # New in version 3.3.
155

156
    int Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, Py_GE
157

158
    object PyObject_RichCompare(object o1, object o2, int opid)
159
    # Return value: New reference.
160
    # Compare the values of o1 and o2 using the operation specified by
161
    # opid, which must be one of Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, or
162
    # Py_GE, corresponding to <, <=, ==, !=, >, or >=
163
    # respectively. This is the equivalent of the Python expression
164
    # "o1 op o2", where op is the operator corresponding to
165
    # opid. Returns the value of the comparison on success, or NULL on
166
    # failure.
167

168
    bint PyObject_RichCompareBool(object o1, object o2, int opid) except -1
169
    # Compare the values of o1 and o2 using the operation specified by
170
    # opid, which must be one of Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, or
171
    # Py_GE, corresponding to <, <=, ==, !=, >, or >=
172
    # respectively. Returns -1 on error, 0 if the result is false, 1
173
    # otherwise. This is the equivalent of the Python expression "o1
174
    # op o2", where op is the operator corresponding to opid.
175

176
    int PyObject_Cmp(object o1, object o2, int *result) except -1
177
    # Compare the values of o1 and o2 using a routine provided by o1,
178
    # if one exists, otherwise with a routine provided by o2. The
179
    # result of the comparison is returned in result. Returns -1 on
180
    # failure. This is the equivalent of the Python statement "result
181
    # = cmp(o1, o2)".
182

183
    int PyObject_Compare(object o1, object o2) except *
184
    # Compare the values of o1 and o2 using a routine provided by o1,
185
    # if one exists, otherwise with a routine provided by o2. Returns
186
    # the result of the comparison on success. On error, the value
187
    # returned is undefined; use PyErr_Occurred() to detect an
188
    # error. This is equivalent to the Python expression "cmp(o1,
189
    # o2)".
190

191
    object PyObject_Repr(object o)
192
    # Return value: New reference.
193
    # Compute a string representation of object o. Returns the string
194
    # representation on success, NULL on failure. This is the
195
    # equivalent of the Python expression "repr(o)". Called by the
196
    # repr() built-in function and by reverse quotes.
197

198
    object PyObject_Str(object o)
199
    # Return value: New reference.
200
    # Compute a string representation of object o. Returns the string
201
    # representation on success, NULL on failure. This is the
202
    # equivalent of the Python expression "str(o)". Called by the
203
    # str() built-in function and by the print statement.
204

205
    object PyObject_Bytes(object o)
206
    # Return value: New reference.
207
    # Compute a bytes representation of object o. Return NULL on
208
    # failure and a bytes object on success. This is equivalent to
209
    # the Python expression bytes(o), when o is not an integer.
210
    # Unlike bytes(o), a TypeError is raised when o is an integer
211
    # instead of a zero-initialized bytes object.
212

213
    bint PyObject_IsInstance(object inst, object cls) except -1
214
    # Returns 1 if inst is an instance of the class cls or a subclass
215
    # of cls, or 0 if not. On error, returns -1 and sets an
216
    # exception. If cls is a type object rather than a class object,
217
    # PyObject_IsInstance() returns 1 if inst is of type cls. If cls
218
    # is a tuple, the check will be done against every entry in
219
    # cls. The result will be 1 when at least one of the checks
220
    # returns 1, otherwise it will be 0. If inst is not a class
221
    # instance and cls is neither a type object, nor a class object,
222
    # nor a tuple, inst must have a __class__ attribute -- the class
223
    # relationship of the value of that attribute with cls will be
224
    # used to determine the result of this function.
225

226
    # Subclass determination is done in a fairly straightforward way,
227
    # but includes a wrinkle that implementors of extensions to the
228
    # class system may want to be aware of. If A and B are class
229
    # objects, B is a subclass of A if it inherits from A either
230
    # directly or indirectly. If either is not a class object, a more
231
    # general mechanism is used to determine the class relationship of
232
    # the two objects. When testing if B is a subclass of A, if A is
233
    # B, PyObject_IsSubclass() returns true. If A and B are different
234
    # objects, B's __bases__ attribute is searched in a depth-first
235
    # fashion for A -- the presence of the __bases__ attribute is
236
    # considered sufficient for this determination.
237

238
    bint PyObject_IsSubclass(object derived, object cls) except -1
239
    # Returns 1 if the class derived is identical to or derived from
240
    # the class cls, otherwise returns 0. In case of an error, returns
241
    # -1. If cls is a tuple, the check will be done against every
242
    # entry in cls. The result will be 1 when at least one of the
243
    # checks returns 1, otherwise it will be 0. If either derived or
244
    # cls is not an actual class object (or tuple), this function uses
245
    # the generic algorithm described above. New in version
246
    # 2.1. Changed in version 2.3: Older versions of Python did not
247
    # support a tuple as the second argument.
248

249
    bint PyCallable_Check(object o)
250
    # Determine if the object o is callable. Return 1 if the object is
251
    # callable and 0 otherwise. This function always succeeds.
252

253
    object PyObject_Call(object callable_object, object args, object kw)
254
    # Return value: New reference.
255
    # Call a callable Python object callable_object, with arguments
256
    # given by the tuple args, and named arguments given by the
257
    # dictionary kw. If no named arguments are needed, kw may be
258
    # NULL. args must not be NULL, use an empty tuple if no arguments
259
    # are needed. Returns the result of the call on success, or NULL
260
    # on failure. This is the equivalent of the Python expression
261
    # "apply(callable_object, args, kw)" or "callable_object(*args,
262
    # **kw)".
263

264
    object PyObject_CallObject(object callable_object, object args)
265
    # Return value: New reference.
266
    # Call a callable Python object callable_object, with arguments
267
    # given by the tuple args. If no arguments are needed, then args
268
    # may be NULL. Returns the result of the call on success, or NULL
269
    # on failure. This is the equivalent of the Python expression
270
    # "apply(callable_object, args)" or "callable_object(*args)".
271

272
    object PyObject_CallFunction(object callable, char *format, ...)
273
    # Return value: New reference.
274
    # Call a callable Python object callable, with a variable number
275
    # of C arguments. The C arguments are described using a
276
    # Py_BuildValue() style format string. The format may be NULL,
277
    # indicating that no arguments are provided. Returns the result of
278
    # the call on success, or NULL on failure. This is the equivalent
279
    # of the Python expression "apply(callable, args)" or
280
    # "callable(*args)". Note that if you only pass object  args,
281
    # PyObject_CallFunctionObjArgs is a faster alternative.
282

283
    object PyObject_CallMethod(object o, char *method, char *format, ...)
284
    # Return value: New reference.
285
    # Call the method named method of object o with a variable number
286
    # of C arguments. The C arguments are described by a
287
    # Py_BuildValue() format string that should produce a tuple. The
288
    # format may be NULL, indicating that no arguments are
289
    # provided. Returns the result of the call on success, or NULL on
290
    # failure. This is the equivalent of the Python expression
291
    # "o.method(args)". Note that if you only pass object  args,
292
    # PyObject_CallMethodObjArgs is a faster alternative.
293

294
    #object PyObject_CallFunctionObjArgs(object callable, ..., NULL)
295
    object PyObject_CallFunctionObjArgs(object callable, ...)
296
    # Return value: New reference.
297
    # Call a callable Python object callable, with a variable number
298
    # of PyObject* arguments. The arguments are provided as a variable
299
    # number of parameters followed by NULL. Returns the result of the
300
    # call on success, or NULL on failure.
301

302
    #PyObject* PyObject_CallMethodObjArgs(object o, object name, ..., NULL)
303
    object PyObject_CallMethodObjArgs(object o, object name, ...)
304
    # Return value: New reference.
305
    # Calls a method of the object o, where the name of the method is
306
    # given as a Python string object in name. It is called with a
307
    # variable number of PyObject* arguments. The arguments are
308
    # provided as a variable number of parameters followed by
309
    # NULL. Returns the result of the call on success, or NULL on
310
    # failure.
311

312
    long PyObject_Hash(object o) except? -1
313
    # Compute and return the hash value of an object o. On failure,
314
    # return -1. This is the equivalent of the Python expression
315
    # "hash(o)".
316

317
    bint PyObject_IsTrue(object o) except -1
318
    # Returns 1 if the object o is considered to be true, and 0
319
    # otherwise. This is equivalent to the Python expression "not not
320
    # o". On failure, return -1.
321

322
    bint PyObject_Not(object o) except -1
323
    # Returns 0 if the object o is considered to be true, and 1
324
    # otherwise. This is equivalent to the Python expression "not
325
    # o". On failure, return -1.
326

327
    object PyObject_Type(object o)
328
    # Return value: New reference.
329
    # When o is non-NULL, returns a type object corresponding to the
330
    # object type of object o. On failure, raises SystemError and
331
    # returns NULL. This is equivalent to the Python expression
332
    # type(o). This function increments the reference count of the
333
    # return value. There's really no reason to use this function
334
    # instead of the common expression o->ob_type, which returns a
335
    # pointer of type PyTypeObject*, except when the incremented
336
    # reference count is needed.
337

338
    bint PyObject_TypeCheck(object o, PyTypeObject *type)
339
    # Return true if the object o is of type type or a subtype of
340
    # type. Both parameters must be non-NULL.
341

342
    Py_ssize_t PyObject_Length(object o) except -1
343
    Py_ssize_t PyObject_Size(object o) except -1
344
    # Return the length of object o. If the object o provides either
345
    # the sequence and mapping protocols, the sequence length is
346
    # returned. On error, -1 is returned. This is the equivalent to
347
    # the Python expression "len(o)".
348

349
    Py_ssize_t PyObject_LengthHint(object o, Py_ssize_t default) except -1
350
    # Return an estimated length for the object o. First try to return its
351
    # actual length, then an estimate using __length_hint__(), and finally
352
    # return the default value. On error, return -1. This is the equivalent to
353
    # the Python expression "operator.length_hint(o, default)".
354
    # New in version 3.4.
355

356
    object PyObject_GetItem(object o, object key)
357
    # Return value: New reference.
358
    # Return element of o corresponding to the object key or NULL on
359
    # failure. This is the equivalent of the Python expression
360
    # "o[key]".
361

362
    int PyObject_SetItem(object o, object key, object v) except -1
363
    # Map the object key to the value v. Returns -1 on failure. This
364
    # is the equivalent of the Python statement "o[key] = v".
365

366
    int PyObject_DelItem(object o, object key) except -1
367
    # Delete the mapping for key from o. Returns -1 on failure. This
368
    # is the equivalent of the Python statement "del o[key]".
369

370
    int PyObject_AsFileDescriptor(object o) except -1
371
    # Derives a file-descriptor from a Python object. If the object is
372
    # an integer or long integer, its value is returned. If not, the
373
    # object's fileno() method is called if it exists; the method must
374
    # return an integer or long integer, which is returned as the file
375
    # descriptor value. Returns -1 on failure.
376

377
    object PyObject_Dir(object o)
378
    # Return value: New reference.
379
    # This is equivalent to the Python expression "dir(o)", returning
380
    # a (possibly empty) list of strings appropriate for the object
381
    # argument, or NULL if there was an error. If the argument is
382
    # NULL, this is like the Python "dir()", returning the names of
383
    # the current locals; in this case, if no execution frame is
384
    # active then NULL is returned but PyErr_Occurred() will return
385
    # false.
386

387
    object PyObject_GetIter(object o)
388
    # Return value: New reference.
389
    # This is equivalent to the Python expression "iter(o)". It
390
    # returns a new iterator for the object argument, or the object
391
    # itself if the object is already an iterator. Raises TypeError
392
    # and returns NULL if the object cannot be iterated.
393

394
    Py_ssize_t Py_SIZE(object o)
395

396
    object PyObject_Format(object obj, object format_spec)
397
    # Takes an arbitrary object and returns the result of calling
398
    # obj.__format__(format_spec).
399
    # Added in Py2.6
400

401
    # Type flags (tp_flags of PyTypeObject)
402
    long Py_TPFLAGS_HAVE_GETCHARBUFFER
403
    long Py_TPFLAGS_HAVE_SEQUENCE_IN
404
    long Py_TPFLAGS_HAVE_INPLACEOPS
405
    long Py_TPFLAGS_CHECKTYPES
406
    long Py_TPFLAGS_HAVE_RICHCOMPARE
407
    long Py_TPFLAGS_HAVE_WEAKREFS
408
    long Py_TPFLAGS_HAVE_ITER
409
    long Py_TPFLAGS_HAVE_CLASS
410
    long Py_TPFLAGS_HEAPTYPE
411
    long Py_TPFLAGS_BASETYPE
412
    long Py_TPFLAGS_READY
413
    long Py_TPFLAGS_READYING
414
    long Py_TPFLAGS_HAVE_GC
415
    long Py_TPFLAGS_HAVE_STACKLESS_EXTENSION
416
    long Py_TPFLAGS_HAVE_INDEX
417
    long Py_TPFLAGS_HAVE_VERSION_TAG
418
    long Py_TPFLAGS_VALID_VERSION_TAG
419
    long Py_TPFLAGS_IS_ABSTRACT
420
    long Py_TPFLAGS_HAVE_NEWBUFFER
421
    long Py_TPFLAGS_INT_SUBCLASS
422
    long Py_TPFLAGS_LONG_SUBCLASS
423
    long Py_TPFLAGS_LIST_SUBCLASS
424
    long Py_TPFLAGS_TUPLE_SUBCLASS
425
    long Py_TPFLAGS_STRING_SUBCLASS
426
    long Py_TPFLAGS_UNICODE_SUBCLASS
427
    long Py_TPFLAGS_DICT_SUBCLASS
428
    long Py_TPFLAGS_BASE_EXC_SUBCLASS
429
    long Py_TPFLAGS_TYPE_SUBCLASS
430
    long Py_TPFLAGS_DEFAULT_EXTERNAL
431
    long Py_TPFLAGS_DEFAULT_CORE
432
    long Py_TPFLAGS_DEFAULT
433
    long Py_TPFLAGS_HAVE_FINALIZE
434

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.