GitHub

Original file line numberDiff line numberDiff line change

@@ -119,30 +119,45 @@ typedef struct {

119119
120120

/* Cast argument to PyVarObject* type. */

121121

#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))

122135
123-

#define Py_REFCNT(ob) (_PyObject_CAST(ob)->ob_refcnt)

124-

#define Py_SIZE(ob) (_PyVarObject_CAST(ob)->ob_size)

125136
126137

static inline PyTypeObject* _Py_TYPE(const PyObject *ob) {

127138

return ob->ob_type;

128139

}

129140

#define Py_TYPE(ob) _Py_TYPE(_PyObject_CAST_CONST(ob))

130141
142+
131143

static inline int _Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) {

132144

return ob->ob_type == type;

133145

}

134146

#define Py_IS_TYPE(ob, type) _Py_IS_TYPE(_PyObject_CAST_CONST(ob), type)

135147
148+
136149

static inline void _Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) {

137150

ob->ob_refcnt = refcnt;

138151

}

139152

#define Py_SET_REFCNT(ob, refcnt) _Py_SET_REFCNT(_PyObject_CAST(ob), refcnt)

140153
154+
141155

static inline void _Py_SET_TYPE(PyObject *ob, PyTypeObject *type) {

142156

ob->ob_type = type;

143157

}

144158

#define Py_SET_TYPE(ob, type) _Py_SET_TYPE(_PyObject_CAST(ob), type)

145159
160+
146161

static inline void _Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size) {

147162

ob->ob_size = size;

148163

}

Read the original on github.com ↗