Skip to content

Commit

Permalink
bpo-33407: Implement Py_DEPRECATED() on MSVC (pythonGH-8980)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZackerySpytz authored and DinoV committed Jan 14, 2020
1 parent c5b8a89 commit 53312cc
Show file tree
Hide file tree
Showing 14 changed files with 136 additions and 104 deletions.
12 changes: 12 additions & 0 deletions Doc/c-api/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ complete listing.

.. versionadded:: 3.4

.. c:macro:: Py_DEPRECATED(version)
Use this for deprecated declarations. The macro must be placed before the
symbol name.

Example::

Py_DEPRECATED(3.8) PyAPI_FUNC(int) Py_OldFunction(void);

.. versionchanged:: 3.8
MSVC support was added.


.. _api-objects:

Expand Down
9 changes: 9 additions & 0 deletions Doc/whatsnew/3.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,15 @@ Changes in the C API

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

* The :c:macro:`Py_DEPRECATED()` macro has been implemented for MSVC.
The macro now must be placed before the symbol name.

Example::

Py_DEPRECATED(3.8) PyAPI_FUNC(int) Py_OldFunction(void);

(Contributed by Zackery Spytz in :issue:`33407`.)


CPython bytecode changes
------------------------
Expand Down
15 changes: 7 additions & 8 deletions Include/abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,39 +316,38 @@ PyAPI_FUNC(int) PyObject_DelItem(PyObject *o, PyObject *key);
Return 0 on success. buffer and buffer_len are only set in case no error
occurs. Otherwise, -1 is returned and an exception set. */
Py_DEPRECATED(3.0)
PyAPI_FUNC(int) PyObject_AsCharBuffer(PyObject *obj,
const char **buffer,
Py_ssize_t *buffer_len)
Py_DEPRECATED(3.0);
Py_ssize_t *buffer_len);

/* Checks whether an arbitrary object supports the (character, single segment)
buffer interface.
Returns 1 on success, 0 on failure. */
PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj)
Py_DEPRECATED(3.0);
Py_DEPRECATED(3.0) PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj);

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

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


/* === New Buffer API ============================================ */
Expand Down
4 changes: 2 additions & 2 deletions Include/ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *);

PyAPI_FUNC(int) PyEval_ThreadsInitialized(void);
PyAPI_FUNC(void) PyEval_InitThreads(void);
PyAPI_FUNC(void) PyEval_AcquireLock(void) Py_DEPRECATED(3.2);
PyAPI_FUNC(void) PyEval_ReleaseLock(void) /* Py_DEPRECATED(3.2) */;
Py_DEPRECATED(3.2) PyAPI_FUNC(void) PyEval_AcquireLock(void);
/* Py_DEPRECATED(3.2) */ PyAPI_FUNC(void) PyEval_ReleaseLock(void);
PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate);
PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate);

Expand Down
18 changes: 10 additions & 8 deletions Include/cpython/pyerrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ PyAPI_FUNC(void) _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *);
/* Convenience functions */

#ifdef MS_WINDOWS
Py_DEPRECATED(3.3)
PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithUnicodeFilename(
PyObject *, const Py_UNICODE *) Py_DEPRECATED(3.3);
PyObject *, const Py_UNICODE *);
#endif /* MS_WINDOWS */

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

#ifdef MS_WINDOWS
/* XXX redeclare to use WSTRING */
Py_DEPRECATED(3.3)
PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithUnicodeFilename(
int, const Py_UNICODE *) Py_DEPRECATED(3.3);

int, const Py_UNICODE *);
Py_DEPRECATED(3.3)
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithUnicodeFilename(
PyObject *,int, const Py_UNICODE *) Py_DEPRECATED(3.3);
PyObject *,int, const Py_UNICODE *);
#endif

/* In exceptions.c */
Expand Down Expand Up @@ -147,23 +149,23 @@ PyAPI_FUNC(PyObject *) PyErr_ProgramTextObject(
int lineno);

/* Create a UnicodeEncodeError object */
PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_Create(
Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_Create(
const char *encoding, /* UTF-8 encoded string */
const Py_UNICODE *object,
Py_ssize_t length,
Py_ssize_t start,
Py_ssize_t end,
const char *reason /* UTF-8 encoded string */
) Py_DEPRECATED(3.3);
);

/* Create a UnicodeTranslateError object */
PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_Create(
Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_Create(
const Py_UNICODE *object,
Py_ssize_t length,
Py_ssize_t start,
Py_ssize_t end,
const char *reason /* UTF-8 encoded string */
) Py_DEPRECATED(3.3);
);
PyAPI_FUNC(PyObject *) _PyUnicodeTranslateError_Create(
PyObject *object,
Py_ssize_t start,
Expand Down
Loading

0 comments on commit 53312cc

Please sign in to comment.