| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 20941de commit fe2978b
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -88,13 +88,13 @@ the definition of all other Python objects. | |||
| 88 | 88 | .. versionadded:: 3.9 | |
| 89 | 89 | ||
| 90 | 90 | ||
| 91 | - .. c:macro:: Py_REFCNT(o) | ||
| 91 | + .. c:function:: Py_ssize_t Py_REFCNT(const PyObject *o) | ||
| 92 | 92 | ||
| 93 | - This macro is used to access the :attr:`ob_refcnt` member of a Python | ||
| 94 | - object. | ||
| 95 | - It expands to:: | ||
| 93 | + Get the reference count of the Python object *o*. | ||
| 96 | 94 | ||
| 97 | - (((PyObject*)(o))->ob_refcnt) | ||
| 95 | + .. versionchanged:: 3.10 | ||
| 96 | + :c:func:`Py_REFCNT()` is changed to the inline static function. | ||
| 97 | + Use :c:func:`Py_SET_REFCNT()` to set an object reference count. | ||
| 98 | 98 | ||
| 99 | 99 | ||
| 100 | 100 | .. c:function:: void Py_SET_REFCNT(PyObject *o, Py_ssize_t refcnt) | |
@@ -104,12 +104,13 @@ the definition of all other Python objects. | |||
| 104 | 104 | .. versionadded:: 3.9 | |
| 105 | 105 | ||
| 106 | 106 | ||
| 107 | - .. c:macro:: Py_SIZE(o) | ||
| 107 | + .. c:function:: Py_ssize_t Py_SIZE(const PyVarObject *o) | ||
| 108 | 108 | ||
| 109 | - This macro is used to access the :attr:`ob_size` member of a Python object. | ||
| 110 | - It expands to:: | ||
| 109 | + Get the size of the Python object *o*. | ||
| 111 | 110 | ||
| 112 | - (((PyVarObject*)(o))->ob_size) | ||
| 111 | + .. versionchanged:: 3.10 | ||
| 112 | + :c:func:`Py_SIZE()` is changed to the inline static function. | ||
| 113 | + Use :c:func:`Py_SET_SIZE()` to set an object size. | ||
| 113 | 114 | ||
| 114 | 115 | ||
| 115 | 116 | .. c:function:: void Py_SET_SIZE(PyVarObject *o, Py_ssize_t size) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -138,6 +138,15 @@ Porting to Python 3.10 | |||
| 138 | 138 | see :c:func:`Py_SET_TYPE()` (available since Python 3.9). | |
| 139 | 139 | (Contributed by Dong-hee Na in :issue:`39573`.) | |
| 140 | 140 | ||
| 141 | + * Since :c:func:`Py_REFCNT()` is changed to the inline static function, | ||
| 142 | + ``Py_REFCNT(obj) = new_refcnt`` must be replaced with ``Py_SET_REFCNT(obj, new_refcnt)``: | ||
| 143 | + see :c:func:`Py_SET_REFCNT()` (available since Python 3.9). | ||
| 144 | + (Contributed by Victor Stinner in :issue:`39573`.) | ||
| 145 | + | ||
| 146 | + * Since :c:func:`Py_SIZE()` is changed to the inline static function, | ||
| 147 | + ``Py_SIZE(obj) = new_size`` must be replaced with ``Py_SET_SIZE(obj, new_size)``: | ||
| 148 | + see :c:func:`Py_SET_SIZE()` (available since Python 3.9). | ||
| 149 | + (Contributed by Victor Stinner in :issue:`39573`.) | ||
| 141 | 150 | ||
| 142 | 151 | Removed | |
| 143 | 152 | ------- | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -119,30 +119,45 @@ typedef struct { | |||
| 119 | 119 | ||
| 120 | 120 | /* Cast argument to PyVarObject* type. */ | |
| 121 | 121 | #define _PyVarObject_CAST(op) ((PyVarObject*)(op)) | |
| 122 | + #define _PyVarObject_CAST_CONST(op) ((const PyVarObject*)(op)) | ||
| 123 | + | ||
| 124 | + | ||
| 125 | + static inline Py_ssize_t _Py_REFCNT(const PyObject *ob) { | ||
| 126 | + return ob->ob_refcnt; | ||
| 127 | + } | ||
| 128 | + #define Py_REFCNT(ob) _Py_REFCNT(_PyObject_CAST_CONST(ob)) | ||
| 129 | + | ||
| 130 | + | ||
| 131 | + static inline Py_ssize_t _Py_SIZE(const PyVarObject *ob) { | ||
| 132 | + return ob->ob_size; | ||
| 133 | + } | ||
| 134 | + #define Py_SIZE(ob) _Py_SIZE(_PyVarObject_CAST_CONST(ob)) | ||
| 122 | 135 | ||
| 123 | - #define Py_REFCNT(ob) (_PyObject_CAST(ob)->ob_refcnt) | ||
| 124 | - #define Py_SIZE(ob) (_PyVarObject_CAST(ob)->ob_size) | ||
| 125 | 136 | ||
| 126 | 137 | static inline PyTypeObject* _Py_TYPE(const PyObject *ob) { | |
| 127 | 138 | return ob->ob_type; | |
| 128 | 139 | } | |
| 129 | 140 | #define Py_TYPE(ob) _Py_TYPE(_PyObject_CAST_CONST(ob)) | |
| 130 | 141 | ||
| 142 | + | ||
| 131 | 143 | static inline int _Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) { | |
| 132 | 144 | return ob->ob_type == type; | |
| 133 | 145 | } | |
| 134 | 146 | #define Py_IS_TYPE(ob, type) _Py_IS_TYPE(_PyObject_CAST_CONST(ob), type) | |
| 135 | 147 | ||
| 148 | + | ||
| 136 | 149 | static inline void _Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) { | |
| 137 | 150 | ob->ob_refcnt = refcnt; | |
| 138 | 151 | } | |
| 139 | 152 | #define Py_SET_REFCNT(ob, refcnt) _Py_SET_REFCNT(_PyObject_CAST(ob), refcnt) | |
| 140 | 153 | ||
| 154 | + | ||
| 141 | 155 | static inline void _Py_SET_TYPE(PyObject *ob, PyTypeObject *type) { | |
| 142 | 156 | ob->ob_type = type; | |
| 143 | 157 | } | |
| 144 | 158 | #define Py_SET_TYPE(ob, type) _Py_SET_TYPE(_PyObject_CAST(ob), type) | |
| 145 | 159 | ||
| 160 | + | ||
| 146 | 161 | static inline void _Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size) { | |
| 147 | 162 | ob->ob_size = size; | |
| 148 | 163 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,5 @@ | |||
| 1 | + Convert :c:func:`Py_REFCNT` and :c:func:`Py_SIZE` macros to static inline | ||
| 2 | + functions. They cannot be used as l-value anymore: use | ||
| 3 | + :c:func:`Py_SET_REFCNT` and :c:func:`Py_SET_SIZE` to set an object reference | ||
| 4 | + count and size. This change is backward incompatible on purpose, to prepare | ||
| 5 | + the C API for an opaque :c:type:`PyObject` structure. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2525,14 +2525,14 @@ array_buffer_getbuf(arrayobject *self, Py_buffer *view, int flags) | |||
| 2525 | 2525 | Py_INCREF(self); | |
| 2526 | 2526 | if (view->buf == NULL) | |
| 2527 | 2527 | view->buf = (void *)emptybuf; | |
| 2528 | - view->len = (Py_SIZE(self)) * self->ob_descr->itemsize; | ||
| 2528 | + view->len = Py_SIZE(self) * self->ob_descr->itemsize; | ||
| 2529 | 2529 | view->readonly = 0; | |
| 2530 | 2530 | view->ndim = 1; | |
| 2531 | 2531 | view->itemsize = self->ob_descr->itemsize; | |
| 2532 | 2532 | view->suboffsets = NULL; | |
| 2533 | 2533 | view->shape = NULL; | |
| 2534 | 2534 | if ((flags & PyBUF_ND)==PyBUF_ND) { | |
| 2535 | - view->shape = &((Py_SIZE(self))); | ||
| 2535 | + view->shape = &((PyVarObject*)self)->ob_size; | ||
| 2536 | 2536 | } | |
| 2537 | 2537 | view->strides = NULL; | |
| 2538 | 2538 | if ((flags & PyBUF_STRIDES)==PyBUF_STRIDES) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -82,7 +82,7 @@ tuple_alloc(Py_ssize_t size) | |||
| 82 | 82 | numfree[size]--; | |
| 83 | 83 | /* Inline PyObject_InitVar */ | |
| 84 | 84 | #ifdef Py_TRACE_REFS | |
| 85 | - Py_SIZE(op) = size; | ||
| 85 | + Py_SET_SIZE(op, size); | ||
| 86 | 86 | Py_SET_TYPE(op, &PyTuple_Type); | |
| 87 | 87 | #endif | |
| 88 | 88 | _Py_NewReference((PyObject *)op); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments