Skip to content

Commit 437ba52

Browse files
committed
Extract common code into defs
1 parent 4503529 commit 437ba52

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

Python/sysmodule.c

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ module sys
7575
#include "clinic/sysmodule.c.h"
7676

7777

78+
#define WarnIncomingSysAbiflagsChange() \
79+
PyErr_WarnEx(PyExc_DeprecationWarning, \
80+
"sys.abiflags will be set to a meaningful value " \
81+
"on all platforms in Python 3.16 instead of absent", \
82+
/*stack_level=*/1)
83+
84+
7885
PyObject *
7986
_PySys_GetRequiredAttr(PyObject *name)
8087
{
@@ -94,10 +101,7 @@ _PySys_GetRequiredAttr(PyObject *name)
94101
if (PyDict_GetItemRef(sysdict, name, &value) == 0) {
95102
#ifndef ABIFLAGS
96103
if (_PyUnicode_EqualToASCIIString(name, "abiflags")) {
97-
if (PyErr_WarnEx(PyExc_DeprecationWarning,
98-
"sys.abiflags will be set to a meaningful value "
99-
"on all platforms in Python 3.16 instead of absent",
100-
/*stack_level=*/1) < 0) {
104+
if (WarnIncomingSysAbiflagsChange() < 0) {
101105
return NULL;
102106
}
103107
}
@@ -120,10 +124,7 @@ _PySys_GetRequiredAttrString(const char *name)
120124
if (PyDict_GetItemStringRef(sysdict, name, &value) == 0) {
121125
#ifndef ABIFLAGS
122126
if (strcmp(name, "abiflags") == 0) {
123-
if (PyErr_WarnEx(PyExc_DeprecationWarning,
124-
"sys.abiflags will be set to a meaningful value "
125-
"on all platforms in Python 3.16 instead of absent",
126-
/*stack_level=*/1) < 0) {
127+
if (WarnIncomingSysAbiflagsChange() < 0) {
127128
return NULL;
128129
}
129130
}
@@ -152,10 +153,7 @@ _PySys_GetOptionalAttr(PyObject *name, PyObject **value)
152153
int ret = PyDict_GetItemRef(sysdict, name, value);
153154
#ifndef ABIFLAGS
154155
if (ret == 0 && _PyUnicode_EqualToASCIIString(name, "abiflags")) {
155-
if (PyErr_WarnEx(PyExc_DeprecationWarning,
156-
"sys.abiflags will be set to a meaningful value "
157-
"on all platforms in Python 3.16 instead of absent",
158-
/*stack_level=*/1) < 0) {
156+
if (WarnIncomingSysAbiflagsChange() < 0) {
159157
return -1;
160158
}
161159
}
@@ -175,10 +173,7 @@ _PySys_GetOptionalAttrString(const char *name, PyObject **value)
175173
int ret = PyDict_GetItemStringRef(sysdict, name, value);
176174
#ifndef ABIFLAGS
177175
if (ret == 0 && strcmp(name, "abiflags") == 0) {
178-
if (PyErr_WarnEx(PyExc_DeprecationWarning,
179-
"sys.abiflags will be set to a meaningful value "
180-
"on all platforms in Python 3.16 instead of absent",
181-
/*stack_level=*/1) < 0) {
176+
if (WarnIncomingSysAbiflagsChange() < 0) {
182177
return -1;
183178
}
184179
}
@@ -206,10 +201,7 @@ PySys_GetObject(const char *name)
206201
Py_XDECREF(value); // return a borrowed reference
207202
#ifndef ABIFLAGS
208203
if (ret == 0 && strcmp(name, "abiflags") == 0) {
209-
if (PyErr_WarnEx(PyExc_DeprecationWarning,
210-
"sys.abiflags will be set to a meaningful value "
211-
"on all platforms in Python 3.16 instead of absent",
212-
/*stack_level=*/1) < 0) {
204+
if (WarnIncomingSysAbiflagsChange() < 0) {
213205
return NULL;
214206
}
215207
}

0 commit comments

Comments
 (0)