Skip to content

Commit 3c8724f

Browse files
ZackerySpytzvstinner
authored andcommitted
bpo-33407: Implement Py_DEPRECATED() on MSVC (GH-8980)
1 parent 17a5588 commit 3c8724f

File tree

14 files changed

+136
-104
lines changed

14 files changed

+136
-104
lines changed

Doc/c-api/intro.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,18 @@ complete listing.
160160

161161
.. versionadded:: 3.4
162162

163+
.. c:macro:: Py_DEPRECATED(version)
164+
165+
Use this for deprecated declarations. The macro must be placed before the
166+
symbol name.
167+
168+
Example::
169+
170+
Py_DEPRECATED(3.8) PyAPI_FUNC(int) Py_OldFunction(void);
171+
172+
.. versionchanged:: 3.8
173+
MSVC support was added.
174+
163175

164176
.. _api-objects:
165177

Doc/whatsnew/3.8.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,15 @@ Changes in the C API
12401240

12411241
(Contributed by Eddie Elizondo in :issue:`35810`.)
12421242

1243+
* The :c:macro:`Py_DEPRECATED()` macro has been implemented for MSVC.
1244+
The macro now must be placed before the symbol name.
1245+
1246+
Example::
1247+
1248+
Py_DEPRECATED(3.8) PyAPI_FUNC(int) Py_OldFunction(void);
1249+
1250+
(Contributed by Zackery Spytz in :issue:`33407`.)
1251+
12431252

12441253
CPython bytecode changes
12451254
------------------------

Include/abstract.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,39 +316,38 @@ PyAPI_FUNC(int) PyObject_DelItem(PyObject *o, PyObject *key);
316316
317317
Return 0 on success. buffer and buffer_len are only set in case no error
318318
occurs. Otherwise, -1 is returned and an exception set. */
319+
Py_DEPRECATED(3.0)
319320
PyAPI_FUNC(int) PyObject_AsCharBuffer(PyObject *obj,
320321
const char **buffer,
321-
Py_ssize_t *buffer_len)
322-
Py_DEPRECATED(3.0);
322+
Py_ssize_t *buffer_len);
323323

324324
/* Checks whether an arbitrary object supports the (character, single segment)
325325
buffer interface.
326326
327327
Returns 1 on success, 0 on failure. */
328-
PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj)
329-
Py_DEPRECATED(3.0);
328+
Py_DEPRECATED(3.0) PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj);
330329

331330
/* Same as PyObject_AsCharBuffer() except that this API expects (readable,
332331
single segment) buffer interface and returns a pointer to a read-only memory
333332
location which can contain arbitrary data.
334333
335334
0 is returned on success. buffer and buffer_len are only set in case no
336335
error occurs. Otherwise, -1 is returned and an exception set. */
336+
Py_DEPRECATED(3.0)
337337
PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj,
338338
const void **buffer,
339-
Py_ssize_t *buffer_len)
340-
Py_DEPRECATED(3.0);
339+
Py_ssize_t *buffer_len);
341340

342341
/* Takes an arbitrary object which must support the (writable, single segment)
343342
buffer interface and returns a pointer to a writable memory location in
344343
buffer of size 'buffer_len'.
345344
346345
Return 0 on success. buffer and buffer_len are only set in case no error
347346
occurs. Otherwise, -1 is returned and an exception set. */
347+
Py_DEPRECATED(3.0)
348348
PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *obj,
349349
void **buffer,
350-
Py_ssize_t *buffer_len)
351-
Py_DEPRECATED(3.0);
350+
Py_ssize_t *buffer_len);
352351

353352

354353
/* === New Buffer API ============================================ */

Include/ceval.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *);
189189

190190
PyAPI_FUNC(int) PyEval_ThreadsInitialized(void);
191191
PyAPI_FUNC(void) PyEval_InitThreads(void);
192-
PyAPI_FUNC(void) PyEval_AcquireLock(void) Py_DEPRECATED(3.2);
193-
PyAPI_FUNC(void) PyEval_ReleaseLock(void) /* Py_DEPRECATED(3.2) */;
192+
Py_DEPRECATED(3.2) PyAPI_FUNC(void) PyEval_AcquireLock(void);
193+
/* Py_DEPRECATED(3.2) */ PyAPI_FUNC(void) PyEval_ReleaseLock(void);
194194
PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate);
195195
PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate);
196196

Include/cpython/pyerrors.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ PyAPI_FUNC(void) _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *);
8888
/* Convenience functions */
8989

9090
#ifdef MS_WINDOWS
91+
Py_DEPRECATED(3.3)
9192
PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithUnicodeFilename(
92-
PyObject *, const Py_UNICODE *) Py_DEPRECATED(3.3);
93+
PyObject *, const Py_UNICODE *);
9394
#endif /* MS_WINDOWS */
9495

9596
/* Like PyErr_Format(), but saves current exception as __context__ and
@@ -103,11 +104,12 @@ PyAPI_FUNC(PyObject *) _PyErr_FormatFromCause(
103104

104105
#ifdef MS_WINDOWS
105106
/* XXX redeclare to use WSTRING */
107+
Py_DEPRECATED(3.3)
106108
PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithUnicodeFilename(
107-
int, const Py_UNICODE *) Py_DEPRECATED(3.3);
108-
109+
int, const Py_UNICODE *);
110+
Py_DEPRECATED(3.3)
109111
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithUnicodeFilename(
110-
PyObject *,int, const Py_UNICODE *) Py_DEPRECATED(3.3);
112+
PyObject *,int, const Py_UNICODE *);
111113
#endif
112114

113115
/* In exceptions.c */
@@ -147,23 +149,23 @@ PyAPI_FUNC(PyObject *) PyErr_ProgramTextObject(
147149
int lineno);
148150

149151
/* Create a UnicodeEncodeError object */
150-
PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_Create(
152+
Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_Create(
151153
const char *encoding, /* UTF-8 encoded string */
152154
const Py_UNICODE *object,
153155
Py_ssize_t length,
154156
Py_ssize_t start,
155157
Py_ssize_t end,
156158
const char *reason /* UTF-8 encoded string */
157-
) Py_DEPRECATED(3.3);
159+
);
158160

159161
/* Create a UnicodeTranslateError object */
160-
PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_Create(
162+
Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_Create(
161163
const Py_UNICODE *object,
162164
Py_ssize_t length,
163165
Py_ssize_t start,
164166
Py_ssize_t end,
165167
const char *reason /* UTF-8 encoded string */
166-
) Py_DEPRECATED(3.3);
168+
);
167169
PyAPI_FUNC(PyObject *) _PyUnicodeTranslateError_Create(
168170
PyObject *object,
169171
Py_ssize_t start,

0 commit comments

Comments
 (0)