同步操作将从 OpenHarmony-SIG/python 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/* The PyObject_ memory family: high-level object memory interfaces.See pymem.h for the low-level PyMem_ family.*/#ifndef Py_OBJIMPL_H#define Py_OBJIMPL_H#include "pymem.h"#ifdef __cplusplusextern "C" {#endif/* BEWARE:Each interface exports both functions and macros. Extension modules shoulduse the functions, to ensure binary compatibility across Python versions.Because the Python implementation is free to change internal details, andthe macros may (or may not) expose details for speed, if you do use themacros you must recompile your extensions with each Python release.Never mix calls to PyObject_ memory functions with calls to the platformmalloc/realloc/ calloc/free, or with calls to PyMem_.*//*Functions and macros for modules that implement new object types.- PyObject_New(type, typeobj) allocates memory for a new object of the giventype, and initializes part of it. 'type' must be the C structure type usedto represent the object, and 'typeobj' the address of the correspondingtype object. Reference count and type pointer are filled in; the rest ofthe bytes of the object are *undefined*! The resulting expression type is'type *'. The size of the object is determined by the tp_basicsize fieldof the type object.- PyObject_NewVar(type, typeobj, n) is similar but allocates a variable-sizeobject with room for n items. In addition to the refcount and type pointerfields, this also fills in the ob_size field.- PyObject_Del(op) releases the memory allocated for an object. It does notrun a destructor -- it only frees the memory. PyObject_Free is identical.- PyObject_Init(op, typeobj) and PyObject_InitVar(op, typeobj, n) don'tallocate memory. Instead of a 'type' parameter, they take a pointer to anew object (allocated by an arbitrary allocator), and initialize its objectheader fields.Note that objects created with PyObject_{New, NewVar} are allocated using thespecialized Python allocator (implemented in obmalloc.c), if WITH_PYMALLOC isenabled. In addition, a special debugging allocator is used if PYMALLOC_DEBUGis also #defined.In case a specific form of memory management is needed (for example, if youmust use the platform malloc heap(s), or shared memory, or C++ local storage oroperator new), you must first allocate the object with your custom allocator,then pass its pointer to PyObject_{Init, InitVar} for filling in its Python-specific fields: reference count, type pointer, possibly others. You shouldbe aware that Python has no control over these objects because they don'tcooperate with the Python memory manager. Such objects may not be eligiblefor automatic garbage collection and you have to make sure that they arereleased accordingly whenever their destructor gets called (cf. the specificform of memory management you're using).Unless you have specific memory management requirements, usePyObject_{New, NewVar, Del}.*//** Raw object memory interface* ===========================*//* Functions to call the same malloc/realloc/free as used by Python'sobject allocator. If WITH_PYMALLOC is enabled, these may differ fromthe platform malloc/realloc/free. The Python object allocator isdesigned for fast, cache-conscious allocation of many "small" objects,and with low hidden memory overhead.PyObject_Malloc(0) returns a unique non-NULL pointer if possible.PyObject_Realloc(NULL, n) acts like PyObject_Malloc(n).PyObject_Realloc(p != NULL, 0) does not return NULL, or free the memoryat p.Returned pointers must be checked for NULL explicitly; no action isperformed on failure other than to return NULL (no warning it printed, noexception is set, etc).For allocating objects, use PyObject_{New, NewVar} instead wheneverpossible. The PyObject_{Malloc, Realloc, Free} family is exposedso that you can exploit Python's small-block allocator for non-objectuses. If you must use these routines to allocate object memory, make surethe object gets initialized via PyObject_{Init, InitVar} after obtainingthe raw memory.*/PyAPI_FUNC(void *) PyObject_Malloc(size_t size);#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000PyAPI_FUNC(void *) PyObject_Calloc(size_t nelem, size_t elsize);#endifPyAPI_FUNC(void *) PyObject_Realloc(void *ptr, size_t new_size);PyAPI_FUNC(void) PyObject_Free(void *ptr);/* Macros */#define PyObject_MALLOC PyObject_Malloc#define PyObject_REALLOC PyObject_Realloc#define PyObject_FREE PyObject_Free#define PyObject_Del PyObject_Free#define PyObject_DEL PyObject_Free/** Generic object allocator interface* ==================================*//* Functions */PyAPI_FUNC(PyObject *) PyObject_Init(PyObject *, PyTypeObject *);PyAPI_FUNC(PyVarObject *) PyObject_InitVar(PyVarObject *,PyTypeObject *, Py_ssize_t);PyAPI_FUNC(PyObject *) _PyObject_New(PyTypeObject *);PyAPI_FUNC(PyVarObject *) _PyObject_NewVar(PyTypeObject *, Py_ssize_t);#define PyObject_New(type, typeobj) \( (type *) _PyObject_New(typeobj) )#define PyObject_NewVar(type, typeobj, n) \( (type *) _PyObject_NewVar((typeobj), (n)) )/* Inline functions trading binary compatibility for speed:PyObject_INIT() is the fast version of PyObject_Init(), andPyObject_INIT_VAR() is the fast version of PyObject_InitVar.See also pymem.h.These inline functions expect non-NULL object pointers. */static inline PyObject*_PyObject_INIT(PyObject *op, PyTypeObject *typeobj){assert(op != NULL);Py_TYPE(op) = typeobj;if (PyType_GetFlags(typeobj) & Py_TPFLAGS_HEAPTYPE) {Py_INCREF(typeobj);}_Py_NewReference(op);return op;}#define PyObject_INIT(op, typeobj) \_PyObject_INIT(_PyObject_CAST(op), (typeobj))static inline PyVarObject*_PyObject_INIT_VAR(PyVarObject *op, PyTypeObject *typeobj, Py_ssize_t size){assert(op != NULL);Py_SIZE(op) = size;PyObject_INIT((PyObject *)op, typeobj);return op;}#define PyObject_INIT_VAR(op, typeobj, size) \_PyObject_INIT_VAR(_PyVarObject_CAST(op), (typeobj), (size))#define _PyObject_SIZE(typeobj) ( (typeobj)->tp_basicsize )/* _PyObject_VAR_SIZE returns the number of bytes (as size_t) allocated for avrbl-size object with nitems items, exclusive of gc overhead (if any). Thevalue is rounded up to the closest multiple of sizeof(void *), in order toensure that pointer fields at the end of the object are correctly alignedfor the platform (this is of special importance for subclasses of, e.g.,str or int, so that pointers can be stored after the embedded data).Note that there's no memory wastage in doing this, as malloc has toreturn (at worst) pointer-aligned memory anyway.*/#if ((SIZEOF_VOID_P - 1) & SIZEOF_VOID_P) != 0# error "_PyObject_VAR_SIZE requires SIZEOF_VOID_P be a power of 2"#endif#define _PyObject_VAR_SIZE(typeobj, nitems) \_Py_SIZE_ROUND_UP((typeobj)->tp_basicsize + \(nitems)*(typeobj)->tp_itemsize, \SIZEOF_VOID_P)#define PyObject_NEW(type, typeobj) \( (type *) PyObject_Init( \(PyObject *) PyObject_MALLOC( _PyObject_SIZE(typeobj) ), (typeobj)) )#define PyObject_NEW_VAR(type, typeobj, n) \( (type *) PyObject_InitVar( \(PyVarObject *) PyObject_MALLOC(_PyObject_VAR_SIZE((typeobj),(n)) ),\(typeobj), (n)) )/* This example code implements an object constructor with a customallocator, where PyObject_New is inlined, and shows the importantdistinction between two steps (at least):1) the actual allocation of the object storage;2) the initialization of the Python specific fieldsin this storage with PyObject_{Init, InitVar}.PyObject *YourObject_New(...){PyObject *op;op = (PyObject *) Your_Allocator(_PyObject_SIZE(YourTypeStruct));if (op == NULL)return PyErr_NoMemory();PyObject_Init(op, &YourTypeStruct);op->ob_field = value;...return op;}Note that in C++, the use of the new operator usually implies thatthe 1st step is performed automatically for you, so in a C++ classconstructor you would start directly with PyObject_Init/InitVar*//** Garbage Collection Support* ==========================*//* C equivalent of gc.collect() which ignores the state of gc.enabled. */PyAPI_FUNC(Py_ssize_t) PyGC_Collect(void);/* Test if a type has a GC head */#define PyType_IS_GC(t) PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC)PyAPI_FUNC(PyVarObject *) _PyObject_GC_Resize(PyVarObject *, Py_ssize_t);#define PyObject_GC_Resize(type, op, n) \( (type *) _PyObject_GC_Resize(_PyVarObject_CAST(op), (n)) )PyAPI_FUNC(PyObject *) _PyObject_GC_New(PyTypeObject *);PyAPI_FUNC(PyVarObject *) _PyObject_GC_NewVar(PyTypeObject *, Py_ssize_t);/* Tell the GC to track this object.** See also private _PyObject_GC_TRACK() macro. */PyAPI_FUNC(void) PyObject_GC_Track(void *);/* Tell the GC to stop tracking this object.** See also private _PyObject_GC_UNTRACK() macro. */PyAPI_FUNC(void) PyObject_GC_UnTrack(void *);PyAPI_FUNC(void) PyObject_GC_Del(void *);#define PyObject_GC_New(type, typeobj) \( (type *) _PyObject_GC_New(typeobj) )#define PyObject_GC_NewVar(type, typeobj, n) \( (type *) _PyObject_GC_NewVar((typeobj), (n)) )/* Utility macro to help write tp_traverse functions.* To use this macro, the tp_traverse function must name its arguments* "visit" and "arg". This is intended to keep tp_traverse functions* looking as much alike as possible.*/#define Py_VISIT(op) \do { \if (op) { \int vret = visit(_PyObject_CAST(op), arg); \if (vret) \return vret; \} \} while (0)#ifndef Py_LIMITED_API# define Py_CPYTHON_OBJIMPL_H# include "cpython/objimpl.h"# undef Py_CPYTHON_OBJIMPL_H#endif#ifdef __cplusplus}#endif#endif /* !Py_OBJIMPL_H */
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。