Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 131801d

Browse filesBrowse files
authored
gh-99845: PEP 670: Convert PyObject macros to functions (#99850)
Convert macros to static inline functions to avoid macro pitfalls, like duplication of side effects: * _PyObject_SIZE() * _PyObject_VAR_SIZE() The result type is size_t (unsigned).
1 parent 85dd6cb commit 131801d
Copy full SHA for 131801d

File tree

Expand file treeCollapse file tree

1 file changed

+8
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-5
lines changed

‎Include/cpython/objimpl.h

Copy file name to clipboardExpand all lines: Include/cpython/objimpl.h
+8-5Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
# error "this header file must not be included directly"
33
#endif
44

5-
#define _PyObject_SIZE(typeobj) ( (typeobj)->tp_basicsize )
5+
static inline size_t _PyObject_SIZE(PyTypeObject *type) {
6+
return _Py_STATIC_CAST(size_t, type->tp_basicsize);
7+
}
68

79
/* _PyObject_VAR_SIZE returns the number of bytes (as size_t) allocated for a
810
vrbl-size object with nitems items, exclusive of gc overhead (if any). The
@@ -18,10 +20,11 @@
1820
# error "_PyObject_VAR_SIZE requires SIZEOF_VOID_P be a power of 2"
1921
#endif
2022

21-
#define _PyObject_VAR_SIZE(typeobj, nitems) \
22-
_Py_SIZE_ROUND_UP((typeobj)->tp_basicsize + \
23-
(nitems)*(typeobj)->tp_itemsize, \
24-
SIZEOF_VOID_P)
23+
static inline size_t _PyObject_VAR_SIZE(PyTypeObject *type, Py_ssize_t nitems) {
24+
size_t size = _Py_STATIC_CAST(size_t, type->tp_basicsize);
25+
size += _Py_STATIC_CAST(size_t, nitems) * _Py_STATIC_CAST(size_t, type->tp_itemsize);
26+
return _Py_SIZE_ROUND_UP(size, SIZEOF_VOID_P);
27+
}
2528

2629

2730
/* This example code implements an object constructor with a custom

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.