File indexing completed on 2025-01-30 10:18:04
0001 #ifndef Py_CPYTHON_OBJECT_H
0002 # error "this header file must not be included directly"
0003 #endif
0004
0005 PyAPI_FUNC(void) _Py_NewReference(PyObject *op);
0006 PyAPI_FUNC(void) _Py_NewReferenceNoTotal(PyObject *op);
0007
0008 #ifdef Py_TRACE_REFS
0009
0010 PyAPI_FUNC(void) _Py_ForgetReference(PyObject *);
0011 #endif
0012
0013 #ifdef Py_REF_DEBUG
0014
0015 PyAPI_FUNC(Py_ssize_t) _Py_GetGlobalRefTotal(void);
0016 # define _Py_GetRefTotal() _Py_GetGlobalRefTotal()
0017 PyAPI_FUNC(Py_ssize_t) _Py_GetLegacyRefTotal(void);
0018 PyAPI_FUNC(Py_ssize_t) _PyInterpreterState_GetRefTotal(PyInterpreterState *);
0019 #endif
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 typedef struct _Py_Identifier {
0043 const char* string;
0044
0045
0046 Py_ssize_t index;
0047 } _Py_Identifier;
0048
0049 #ifndef Py_BUILD_CORE
0050
0051
0052
0053 #define _Py_static_string_init(value) { .string = (value), .index = -1 }
0054 #define _Py_static_string(varname, value) static _Py_Identifier varname = _Py_static_string_init(value)
0055 #define _Py_IDENTIFIER(varname) _Py_static_string(PyId_##varname, #varname)
0056
0057 #endif
0058
0059 typedef struct {
0060
0061
0062
0063
0064 binaryfunc nb_add;
0065 binaryfunc nb_subtract;
0066 binaryfunc nb_multiply;
0067 binaryfunc nb_remainder;
0068 binaryfunc nb_divmod;
0069 ternaryfunc nb_power;
0070 unaryfunc nb_negative;
0071 unaryfunc nb_positive;
0072 unaryfunc nb_absolute;
0073 inquiry nb_bool;
0074 unaryfunc nb_invert;
0075 binaryfunc nb_lshift;
0076 binaryfunc nb_rshift;
0077 binaryfunc nb_and;
0078 binaryfunc nb_xor;
0079 binaryfunc nb_or;
0080 unaryfunc nb_int;
0081 void *nb_reserved;
0082 unaryfunc nb_float;
0083
0084 binaryfunc nb_inplace_add;
0085 binaryfunc nb_inplace_subtract;
0086 binaryfunc nb_inplace_multiply;
0087 binaryfunc nb_inplace_remainder;
0088 ternaryfunc nb_inplace_power;
0089 binaryfunc nb_inplace_lshift;
0090 binaryfunc nb_inplace_rshift;
0091 binaryfunc nb_inplace_and;
0092 binaryfunc nb_inplace_xor;
0093 binaryfunc nb_inplace_or;
0094
0095 binaryfunc nb_floor_divide;
0096 binaryfunc nb_true_divide;
0097 binaryfunc nb_inplace_floor_divide;
0098 binaryfunc nb_inplace_true_divide;
0099
0100 unaryfunc nb_index;
0101
0102 binaryfunc nb_matrix_multiply;
0103 binaryfunc nb_inplace_matrix_multiply;
0104 } PyNumberMethods;
0105
0106 typedef struct {
0107 lenfunc sq_length;
0108 binaryfunc sq_concat;
0109 ssizeargfunc sq_repeat;
0110 ssizeargfunc sq_item;
0111 void *was_sq_slice;
0112 ssizeobjargproc sq_ass_item;
0113 void *was_sq_ass_slice;
0114 objobjproc sq_contains;
0115
0116 binaryfunc sq_inplace_concat;
0117 ssizeargfunc sq_inplace_repeat;
0118 } PySequenceMethods;
0119
0120 typedef struct {
0121 lenfunc mp_length;
0122 binaryfunc mp_subscript;
0123 objobjargproc mp_ass_subscript;
0124 } PyMappingMethods;
0125
0126 typedef PySendResult (*sendfunc)(PyObject *iter, PyObject *value, PyObject **result);
0127
0128 typedef struct {
0129 unaryfunc am_await;
0130 unaryfunc am_aiter;
0131 unaryfunc am_anext;
0132 sendfunc am_send;
0133 } PyAsyncMethods;
0134
0135 typedef struct {
0136 getbufferproc bf_getbuffer;
0137 releasebufferproc bf_releasebuffer;
0138 } PyBufferProcs;
0139
0140
0141
0142 typedef Py_ssize_t printfunc;
0143
0144
0145
0146 struct _typeobject {
0147 PyObject_VAR_HEAD
0148 const char *tp_name;
0149 Py_ssize_t tp_basicsize, tp_itemsize;
0150
0151
0152
0153 destructor tp_dealloc;
0154 Py_ssize_t tp_vectorcall_offset;
0155 getattrfunc tp_getattr;
0156 setattrfunc tp_setattr;
0157 PyAsyncMethods *tp_as_async;
0158
0159 reprfunc tp_repr;
0160
0161
0162
0163 PyNumberMethods *tp_as_number;
0164 PySequenceMethods *tp_as_sequence;
0165 PyMappingMethods *tp_as_mapping;
0166
0167
0168
0169 hashfunc tp_hash;
0170 ternaryfunc tp_call;
0171 reprfunc tp_str;
0172 getattrofunc tp_getattro;
0173 setattrofunc tp_setattro;
0174
0175
0176 PyBufferProcs *tp_as_buffer;
0177
0178
0179 unsigned long tp_flags;
0180
0181 const char *tp_doc;
0182
0183
0184
0185 traverseproc tp_traverse;
0186
0187
0188 inquiry tp_clear;
0189
0190
0191
0192 richcmpfunc tp_richcompare;
0193
0194
0195 Py_ssize_t tp_weaklistoffset;
0196
0197
0198 getiterfunc tp_iter;
0199 iternextfunc tp_iternext;
0200
0201
0202 PyMethodDef *tp_methods;
0203 PyMemberDef *tp_members;
0204 PyGetSetDef *tp_getset;
0205
0206 PyTypeObject *tp_base;
0207 PyObject *tp_dict;
0208 descrgetfunc tp_descr_get;
0209 descrsetfunc tp_descr_set;
0210 Py_ssize_t tp_dictoffset;
0211 initproc tp_init;
0212 allocfunc tp_alloc;
0213 newfunc tp_new;
0214 freefunc tp_free;
0215 inquiry tp_is_gc;
0216 PyObject *tp_bases;
0217 PyObject *tp_mro;
0218 PyObject *tp_cache;
0219 void *tp_subclasses;
0220 PyObject *tp_weaklist;
0221 destructor tp_del;
0222
0223
0224 unsigned int tp_version_tag;
0225
0226 destructor tp_finalize;
0227 vectorcallfunc tp_vectorcall;
0228
0229
0230 unsigned char tp_watched;
0231 };
0232
0233
0234
0235
0236 struct _specialization_cache {
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247 PyObject *getitem;
0248 uint32_t getitem_version;
0249 };
0250
0251
0252 typedef struct _heaptypeobject {
0253
0254
0255 PyTypeObject ht_type;
0256 PyAsyncMethods as_async;
0257 PyNumberMethods as_number;
0258 PyMappingMethods as_mapping;
0259 PySequenceMethods as_sequence;
0260
0261
0262
0263
0264 PyBufferProcs as_buffer;
0265 PyObject *ht_name, *ht_slots, *ht_qualname;
0266 struct _dictkeysobject *ht_cached_keys;
0267 PyObject *ht_module;
0268 char *_ht_tpname;
0269 struct _specialization_cache _spec_cache;
0270
0271 } PyHeapTypeObject;
0272
0273 PyAPI_FUNC(const char *) _PyType_Name(PyTypeObject *);
0274 PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *);
0275 PyAPI_FUNC(PyObject *) _PyType_LookupId(PyTypeObject *, _Py_Identifier *);
0276 PyAPI_FUNC(PyObject *) _PyObject_LookupSpecialId(PyObject *, _Py_Identifier *);
0277 #ifndef Py_BUILD_CORE
0278
0279
0280 #define _PyObject_LookupSpecial _PyObject_LookupSpecialId
0281 #endif
0282 PyAPI_FUNC(PyTypeObject *) _PyType_CalculateMetaclass(PyTypeObject *, PyObject *);
0283 PyAPI_FUNC(PyObject *) _PyType_GetDocFromInternalDoc(const char *, const char *);
0284 PyAPI_FUNC(PyObject *) _PyType_GetTextSignatureFromInternalDoc(const char *, const char *);
0285 PyAPI_FUNC(PyObject *) PyType_GetModuleByDef(PyTypeObject *, PyModuleDef *);
0286 PyAPI_FUNC(PyObject *) PyType_GetDict(PyTypeObject *);
0287
0288 PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int);
0289 PyAPI_FUNC(void) _Py_BreakPoint(void);
0290 PyAPI_FUNC(void) _PyObject_Dump(PyObject *);
0291 PyAPI_FUNC(int) _PyObject_IsFreed(PyObject *);
0292
0293 PyAPI_FUNC(int) _PyObject_IsAbstract(PyObject *);
0294 PyAPI_FUNC(PyObject *) _PyObject_GetAttrId(PyObject *, _Py_Identifier *);
0295 PyAPI_FUNC(int) _PyObject_SetAttrId(PyObject *, _Py_Identifier *, PyObject *);
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305 PyAPI_FUNC(int) _PyObject_LookupAttr(PyObject *, PyObject *, PyObject **);
0306 PyAPI_FUNC(int) _PyObject_LookupAttrId(PyObject *, _Py_Identifier *, PyObject **);
0307
0308 PyAPI_FUNC(int) _PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method);
0309
0310 PyAPI_FUNC(PyObject **) _PyObject_GetDictPtr(PyObject *);
0311 PyAPI_FUNC(PyObject *) _PyObject_NextNotImplemented(PyObject *);
0312 PyAPI_FUNC(void) PyObject_CallFinalizer(PyObject *);
0313 PyAPI_FUNC(int) PyObject_CallFinalizerFromDealloc(PyObject *);
0314
0315
0316
0317 PyAPI_FUNC(PyObject *)
0318 _PyObject_GenericGetAttrWithDict(PyObject *, PyObject *, PyObject *, int);
0319 PyAPI_FUNC(int)
0320 _PyObject_GenericSetAttrWithDict(PyObject *, PyObject *,
0321 PyObject *, PyObject *);
0322
0323 PyAPI_FUNC(PyObject *) _PyObject_FunctionStr(PyObject *);
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348 #ifdef _Py_TYPEOF
0349 #define Py_SETREF(dst, src) \
0350 do { \
0351 _Py_TYPEOF(dst)* _tmp_dst_ptr = &(dst); \
0352 _Py_TYPEOF(dst) _tmp_old_dst = (*_tmp_dst_ptr); \
0353 *_tmp_dst_ptr = (src); \
0354 Py_DECREF(_tmp_old_dst); \
0355 } while (0)
0356 #else
0357 #define Py_SETREF(dst, src) \
0358 do { \
0359 PyObject **_tmp_dst_ptr = _Py_CAST(PyObject**, &(dst)); \
0360 PyObject *_tmp_old_dst = (*_tmp_dst_ptr); \
0361 PyObject *_tmp_src = _PyObject_CAST(src); \
0362 memcpy(_tmp_dst_ptr, &_tmp_src, sizeof(PyObject*)); \
0363 Py_DECREF(_tmp_old_dst); \
0364 } while (0)
0365 #endif
0366
0367
0368
0369
0370 #ifdef _Py_TYPEOF
0371 #define Py_XSETREF(dst, src) \
0372 do { \
0373 _Py_TYPEOF(dst)* _tmp_dst_ptr = &(dst); \
0374 _Py_TYPEOF(dst) _tmp_old_dst = (*_tmp_dst_ptr); \
0375 *_tmp_dst_ptr = (src); \
0376 Py_XDECREF(_tmp_old_dst); \
0377 } while (0)
0378 #else
0379 #define Py_XSETREF(dst, src) \
0380 do { \
0381 PyObject **_tmp_dst_ptr = _Py_CAST(PyObject**, &(dst)); \
0382 PyObject *_tmp_old_dst = (*_tmp_dst_ptr); \
0383 PyObject *_tmp_src = _PyObject_CAST(src); \
0384 memcpy(_tmp_dst_ptr, &_tmp_src, sizeof(PyObject*)); \
0385 Py_XDECREF(_tmp_old_dst); \
0386 } while (0)
0387 #endif
0388
0389
0390 PyAPI_DATA(PyTypeObject) _PyNone_Type;
0391 PyAPI_DATA(PyTypeObject) _PyNotImplemented_Type;
0392
0393
0394
0395
0396 PyAPI_DATA(int) _Py_SwappedOp[];
0397
0398 PyAPI_FUNC(void)
0399 _PyDebugAllocatorStats(FILE *out, const char *block_name, int num_blocks,
0400 size_t sizeof_block);
0401 PyAPI_FUNC(void)
0402 _PyObject_DebugTypeStats(FILE *out);
0403
0404
0405
0406
0407
0408
0409
0410
0411
0412
0413
0414
0415
0416
0417
0418 #ifdef NDEBUG
0419
0420 # define _PyObject_ASSERT_FROM(obj, expr, msg, filename, lineno, func) \
0421 ((void)0)
0422 #else
0423
0424 # define _PyObject_ASSERT_FROM(obj, expr, msg, filename, lineno, func) \
0425 ((expr) \
0426 ? (void)(0) \
0427 : _PyObject_AssertFailed((obj), Py_STRINGIFY(expr), \
0428 (msg), (filename), (lineno), (func)))
0429 #endif
0430
0431 #define _PyObject_ASSERT_WITH_MSG(obj, expr, msg) \
0432 _PyObject_ASSERT_FROM((obj), expr, (msg), __FILE__, __LINE__, __func__)
0433 #define _PyObject_ASSERT(obj, expr) \
0434 _PyObject_ASSERT_WITH_MSG((obj), expr, NULL)
0435
0436 #define _PyObject_ASSERT_FAILED_MSG(obj, msg) \
0437 _PyObject_AssertFailed((obj), NULL, (msg), __FILE__, __LINE__, __func__)
0438
0439
0440
0441
0442
0443
0444 PyAPI_FUNC(void) _Py_NO_RETURN _PyObject_AssertFailed(
0445 PyObject *obj,
0446 const char *expr,
0447 const char *msg,
0448 const char *file,
0449 int line,
0450 const char *function);
0451
0452
0453
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463 PyAPI_FUNC(int) _PyObject_CheckConsistency(
0464 PyObject *op,
0465 int check_content);
0466
0467
0468
0469
0470
0471
0472
0473
0474
0475
0476
0477
0478
0479
0480
0481
0482
0483
0484
0485
0486
0487
0488
0489
0490
0491
0492
0493
0494
0495
0496
0497
0498
0499
0500
0501
0502
0503
0504
0505
0506
0507
0508
0509
0510
0511
0512
0513
0514
0515
0516 PyAPI_FUNC(int) _PyTrash_begin(PyThreadState *tstate, PyObject *op);
0517 PyAPI_FUNC(void) _PyTrash_end(PyThreadState *tstate);
0518
0519 PyAPI_FUNC(int) _PyTrash_cond(PyObject *op, destructor dealloc);
0520
0521 #define Py_TRASHCAN_BEGIN_CONDITION(op, cond) \
0522 do { \
0523 PyThreadState *_tstate = NULL; \
0524
0525 \
0526 if (cond) { \
0527 _tstate = _PyThreadState_UncheckedGet(); \
0528 if (_PyTrash_begin(_tstate, _PyObject_CAST(op))) { \
0529 break; \
0530 } \
0531 }
0532
0533 #define Py_TRASHCAN_END \
0534 if (_tstate) { \
0535 _PyTrash_end(_tstate); \
0536 } \
0537 } while (0);
0538
0539 #define Py_TRASHCAN_BEGIN(op, dealloc) \
0540 Py_TRASHCAN_BEGIN_CONDITION((op), \
0541 _PyTrash_cond(_PyObject_CAST(op), (destructor)(dealloc)))
0542
0543
0544
0545
0546
0547
0548 Py_DEPRECATED(3.11) typedef int UsingDeprecatedTrashcanMacro;
0549 #define Py_TRASHCAN_SAFE_BEGIN(op) \
0550 do { \
0551 UsingDeprecatedTrashcanMacro cond=1; \
0552 Py_TRASHCAN_BEGIN_CONDITION((op), cond);
0553 #define Py_TRASHCAN_SAFE_END(op) \
0554 Py_TRASHCAN_END; \
0555 } while(0);
0556
0557 PyAPI_FUNC(void *) PyObject_GetItemData(PyObject *obj);
0558
0559 PyAPI_FUNC(int) _PyObject_VisitManagedDict(PyObject *obj, visitproc visit, void *arg);
0560 PyAPI_FUNC(void) _PyObject_ClearManagedDict(PyObject *obj);
0561
0562 #define TYPE_MAX_WATCHERS 8
0563
0564 typedef int(*PyType_WatchCallback)(PyTypeObject *);
0565 PyAPI_FUNC(int) PyType_AddWatcher(PyType_WatchCallback callback);
0566 PyAPI_FUNC(int) PyType_ClearWatcher(int watcher_id);
0567 PyAPI_FUNC(int) PyType_Watch(int watcher_id, PyObject *type);
0568 PyAPI_FUNC(int) PyType_Unwatch(int watcher_id, PyObject *type);
0569
0570
0571
0572
0573
0574
0575 PyAPI_FUNC(int) PyUnstable_Type_AssignVersionTag(PyTypeObject *type);