bpo-39573: Add Py_SET_SIZE() function (GH-18400)
Add Py_SET_SIZE() function to set the size of an object.
This commit is contained in:
parent
877ea88934
commit
b10dc3e7a1
|
@ -101,6 +101,13 @@ the definition of all other Python objects.
|
|||
(((PyVarObject*)(o))->ob_size)
|
||||
|
||||
|
||||
.. c:function:: void Py_SET_SIZE(PyVarObject *o, Py_ssize_t size)
|
||||
|
||||
Set the object *o* size of *size*.
|
||||
|
||||
.. versionadded:: 3.9
|
||||
|
||||
|
||||
.. c:macro:: PyObject_HEAD_INIT(type)
|
||||
|
||||
This is a macro which expands to initialization values for a new
|
||||
|
|
|
@ -30,7 +30,7 @@ static inline PyVarObject*
|
|||
_PyObject_INIT_VAR(PyVarObject *op, PyTypeObject *typeobj, Py_ssize_t size)
|
||||
{
|
||||
assert(op != NULL);
|
||||
Py_SIZE(op) = size;
|
||||
Py_SET_SIZE(op, size);
|
||||
PyObject_INIT((PyObject *)op, typeobj);
|
||||
return op;
|
||||
}
|
||||
|
|
|
@ -133,6 +133,11 @@ static inline void _Py_SET_TYPE(PyObject *ob, PyTypeObject *type) {
|
|||
}
|
||||
#define Py_SET_TYPE(ob, type) _Py_SET_TYPE(_PyObject_CAST(ob), type)
|
||||
|
||||
static inline void _Py_SET_SIZE(PyVarObject *ob, Py_ssize_t refcnt) {
|
||||
ob->ob_size = refcnt;
|
||||
}
|
||||
#define Py_SET_SIZE(ob, refcnt) _Py_SET_SIZE(_PyVarObject_CAST(ob), refcnt)
|
||||
|
||||
|
||||
/*
|
||||
Type objects contain a string containing the type name (to help somewhat
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Add :c:func:`Py_SET_SIZE` function to set the size of an object.
|
|
@ -160,7 +160,7 @@ PyObject_InitVar(PyVarObject *op, PyTypeObject *tp, Py_ssize_t size)
|
|||
return (PyVarObject *) PyErr_NoMemory();
|
||||
}
|
||||
|
||||
Py_SIZE(op) = size;
|
||||
Py_SET_SIZE(op, size);
|
||||
PyObject_Init((PyObject *)op, tp);
|
||||
return op;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue