From 72324ab958912fb157a20a31f2dc51a072fea7ff Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Tue, 28 Aug 2018 17:24:31 -0600 Subject: [PATCH 1/5] bpo-33407: Implement Py_DEPRECATED() on Windows --- Include/abstract.h | 15 +- Include/ceval.h | 4 +- Include/intrcheck.h | 2 +- Include/longobject.h | 3 +- Include/moduleobject.h | 2 +- Include/pyerrors.h | 17 +- Include/pyport.h | 9 +- Include/pythread.h | 13 +- Include/sliceobject.h | 4 +- Include/unicodeobject.h | 147 +++++++++--------- .../2018-08-28-17-23-49.bpo-33407.ARG0W_.rst | 1 + 11 files changed, 114 insertions(+), 103 deletions(-) create mode 100644 Misc/NEWS.d/next/Windows/2018-08-28-17-23-49.bpo-33407.ARG0W_.rst diff --git a/Include/abstract.h b/Include/abstract.h index 85550a34ca2686..bfc1179467eb1c 100644 --- a/Include/abstract.h +++ b/Include/abstract.h @@ -468,17 +468,16 @@ 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 @@ -486,10 +485,10 @@ PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj) 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 @@ -497,10 +496,10 @@ PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj, 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 ============================================ */ diff --git a/Include/ceval.h b/Include/ceval.h index bce8a0beed85e1..49d823f8de37a8 100644 --- a/Include/ceval.h +++ b/Include/ceval.h @@ -193,8 +193,8 @@ PyAPI_FUNC(void) PyEval_InitThreads(void); #ifndef Py_LIMITED_API PyAPI_FUNC(void) _PyEval_FiniThreads(void); #endif /* !Py_LIMITED_API */ -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); PyAPI_FUNC(void) PyEval_ReInitThreads(void); diff --git a/Include/intrcheck.h b/Include/intrcheck.h index 2e17336ca659ed..e5bf5a834e44c8 100644 --- a/Include/intrcheck.h +++ b/Include/intrcheck.h @@ -15,7 +15,7 @@ PyAPI_FUNC(void) PyOS_AfterFork_Child(void); #endif #endif /* Deprecated, please use PyOS_AfterFork_Child() instead */ -PyAPI_FUNC(void) PyOS_AfterFork(void) Py_DEPRECATED(3.7); +Py_DEPRECATED(3.7) PyAPI_FUNC(void) PyOS_AfterFork(void); #ifndef Py_LIMITED_API PyAPI_FUNC(int) _PyOS_IsMainThread(void); diff --git a/Include/longobject.h b/Include/longobject.h index 82c06c92a63899..1dde9be517e08a 100644 --- a/Include/longobject.h +++ b/Include/longobject.h @@ -102,7 +102,8 @@ PyAPI_FUNC(long long) PyLong_AsLongLongAndOverflow(PyObject *, int *); PyAPI_FUNC(PyObject *) PyLong_FromString(const char *, char **, int); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) PyLong_FromUnicode(Py_UNICODE*, Py_ssize_t, int) Py_DEPRECATED(3.3); +Py_DEPRECATED(3.3) +PyAPI_FUNC(PyObject *) PyLong_FromUnicode(Py_UNICODE*, Py_ssize_t, int); PyAPI_FUNC(PyObject *) PyLong_FromUnicodeObject(PyObject *u, int base); PyAPI_FUNC(PyObject *) _PyLong_FromBytes(const char *, Py_ssize_t, int); #endif diff --git a/Include/moduleobject.h b/Include/moduleobject.h index 1d8fe46dea03a1..a88cca2e5480dc 100644 --- a/Include/moduleobject.h +++ b/Include/moduleobject.h @@ -25,7 +25,7 @@ PyAPI_FUNC(PyObject *) PyModule_GetDict(PyObject *); PyAPI_FUNC(PyObject *) PyModule_GetNameObject(PyObject *); #endif PyAPI_FUNC(const char *) PyModule_GetName(PyObject *); -PyAPI_FUNC(const char *) PyModule_GetFilename(PyObject *) Py_DEPRECATED(3.2); +Py_DEPRECATED(3.2) PyAPI_FUNC(const char *) PyModule_GetFilename(PyObject *); PyAPI_FUNC(PyObject *) PyModule_GetFilenameObject(PyObject *); #ifndef Py_LIMITED_API PyAPI_FUNC(void) _PyModule_Clear(PyObject *); diff --git a/Include/pyerrors.h b/Include/pyerrors.h index 4e2995469f3c2d..575e34be687ce2 100644 --- a/Include/pyerrors.h +++ b/Include/pyerrors.h @@ -254,8 +254,9 @@ PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilename( const char *filename /* decoded from the filesystem encoding */ ); #if defined(MS_WINDOWS) && !defined(Py_LIMITED_API) +Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithUnicodeFilename( - PyObject *, const Py_UNICODE *) Py_DEPRECATED(3.3); + PyObject *, const Py_UNICODE *); #endif /* MS_WINDOWS */ PyAPI_FUNC(PyObject *) PyErr_Format( @@ -288,8 +289,9 @@ PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename( ); #ifndef Py_LIMITED_API /* 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 *); #endif PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErr(int); PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObject( @@ -304,8 +306,9 @@ PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilename( const char *filename /* decoded from the filesystem encoding */ ); #ifndef Py_LIMITED_API +Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithUnicodeFilename( - PyObject *,int, const Py_UNICODE *) Py_DEPRECATED(3.3); + PyObject *,int, const Py_UNICODE *); #endif PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int); #endif /* MS_WINDOWS */ @@ -402,25 +405,25 @@ PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_Create( /* create a UnicodeEncodeError object */ #ifndef Py_LIMITED_API -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); + ); #endif /* create a UnicodeTranslateError object */ #ifndef Py_LIMITED_API -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, diff --git a/Include/pyport.h b/Include/pyport.h index f4b547a50b8580..91543a7ab29b36 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -484,13 +484,16 @@ extern "C" { /* Py_DEPRECATED(version) * Declare a variable, type, or function deprecated. * Usage: - * extern int old_var Py_DEPRECATED(2.3); - * typedef int T1 Py_DEPRECATED(2.4); - * extern int x() Py_DEPRECATED(2.5); + * Py_DEPRECATED(2.3) extern int old_var; + * Py_DEPRECATED(2.4) typedef int T1; + * Py_DEPRECATED(2.5) extern int x(); */ #if defined(__GNUC__) \ && ((__GNUC__ >= 4) || (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)) #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__)) +#elif defined(_MSC_VER) +#define Py_DEPRECATED(VERSION) __declspec(deprecated( \ + "deprecated in " #VERSION)) #else #define Py_DEPRECATED(VERSION_UNUSED) #endif diff --git a/Include/pythread.h b/Include/pythread.h index eb61033b2d9089..49ccb7519d4a88 100644 --- a/Include/pythread.h +++ b/Include/pythread.h @@ -92,14 +92,15 @@ PyAPI_FUNC(PyObject*) PyThread_GetInfo(void); platforms, but it is not POSIX-compliant. Therefore, the new TSS API uses opaque data type to represent TSS keys to be compatible (see PEP 539). */ -PyAPI_FUNC(int) PyThread_create_key(void) Py_DEPRECATED(3.7); -PyAPI_FUNC(void) PyThread_delete_key(int key) Py_DEPRECATED(3.7); -PyAPI_FUNC(int) PyThread_set_key_value(int key, void *value) Py_DEPRECATED(3.7); -PyAPI_FUNC(void *) PyThread_get_key_value(int key) Py_DEPRECATED(3.7); -PyAPI_FUNC(void) PyThread_delete_key_value(int key) Py_DEPRECATED(3.7); +Py_DEPRECATED(3.7) PyAPI_FUNC(int) PyThread_create_key(void); +Py_DEPRECATED(3.7) PyAPI_FUNC(void) PyThread_delete_key(int key); +Py_DEPRECATED(3.7) PyAPI_FUNC(int) PyThread_set_key_value(int key, + void *value); +Py_DEPRECATED(3.7) PyAPI_FUNC(void *) PyThread_get_key_value(int key); +Py_DEPRECATED(3.7) PyAPI_FUNC(void) PyThread_delete_key_value(int key); /* Cleanup after a fork */ -PyAPI_FUNC(void) PyThread_ReInitTLS(void) Py_DEPRECATED(3.7); +Py_DEPRECATED(3.7) PyAPI_FUNC(void) PyThread_ReInitTLS(void); #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03070000 diff --git a/Include/sliceobject.h b/Include/sliceobject.h index c238b099ea8151..aae6f3cc7945e1 100644 --- a/Include/sliceobject.h +++ b/Include/sliceobject.h @@ -40,9 +40,11 @@ PyAPI_FUNC(int) _PySlice_GetLongIndices(PySliceObject *self, PyObject *length, #endif PyAPI_FUNC(int) PySlice_GetIndices(PyObject *r, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step); +Py_DEPRECATED(3.7) PyAPI_FUNC(int) PySlice_GetIndicesEx(PyObject *r, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, - Py_ssize_t *step, Py_ssize_t *slicelength) Py_DEPRECATED(3.7); + Py_ssize_t *step, + Py_ssize_t *slicelength); #if !defined(Py_LIMITED_API) || (Py_LIMITED_API+0 >= 0x03050400 && Py_LIMITED_API+0 < 0x03060000) || Py_LIMITED_API+0 >= 0x03060100 #define PySlice_GetIndicesEx(slice, length, start, stop, step, slicelen) ( \ diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h index 0274de6733ab0e..de3e21729d362f 100644 --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -90,7 +90,7 @@ Copyright (c) Corporation for National Research Initiatives. #ifndef Py_LIMITED_API #define PY_UNICODE_TYPE wchar_t -typedef wchar_t Py_UNICODE /* Py_DEPRECATED(3.3) */; +/* Py_DEPRECATED(3.3) */ typedef wchar_t Py_UNICODE; #endif /* If the compiler provides a wchar_t type we try to support it @@ -376,6 +376,7 @@ PyAPI_DATA(PyTypeObject) PyUnicodeIter_Type; If the Py_UNICODE representation is not available, it will be computed on request. Use PyUnicode_GET_LENGTH() for the length in code points. */ +/* Py_DEPRECATED(3.3) */ #define PyUnicode_GET_SIZE(op) \ (assert(PyUnicode_Check(op)), \ (((PyASCIIObject *)(op))->wstr) ? \ @@ -383,26 +384,25 @@ PyAPI_DATA(PyTypeObject) PyUnicodeIter_Type; ((void)PyUnicode_AsUnicode((PyObject *)(op)), \ assert(((PyASCIIObject *)(op))->wstr), \ PyUnicode_WSTR_LENGTH(op))) - /* Py_DEPRECATED(3.3) */ +/* Py_DEPRECATED(3.3) */ #define PyUnicode_GET_DATA_SIZE(op) \ (PyUnicode_GET_SIZE(op) * Py_UNICODE_SIZE) - /* Py_DEPRECATED(3.3) */ /* Alias for PyUnicode_AsUnicode(). This will create a wchar_t/Py_UNICODE representation on demand. Using this macro is very inefficient now, try to port your code to use the new PyUnicode_*BYTE_DATA() macros or use PyUnicode_WRITE() and PyUnicode_READ(). */ +/* Py_DEPRECATED(3.3) */ #define PyUnicode_AS_UNICODE(op) \ (assert(PyUnicode_Check(op)), \ (((PyASCIIObject *)(op))->wstr) ? (((PyASCIIObject *)(op))->wstr) : \ PyUnicode_AsUnicode((PyObject *)(op))) - /* Py_DEPRECATED(3.3) */ +/* Py_DEPRECATED(3.3) */ #define PyUnicode_AS_DATA(op) \ ((const char *)(PyUnicode_AS_UNICODE(op))) - /* Py_DEPRECATED(3.3) */ /* --- Flexible String Representation Helper Macros (PEP 393) -------------- */ @@ -685,10 +685,10 @@ PyAPI_FUNC(void) _PyUnicode_FastFill( The buffer is copied into the new object. */ #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode( +/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode( const Py_UNICODE *u, /* Unicode buffer */ Py_ssize_t size /* size of buffer */ - ) /* Py_DEPRECATED(3.3) */; + ); #endif /* Similar to PyUnicode_FromUnicode(), but u points to UTF-8 encoded bytes */ @@ -758,9 +758,9 @@ PyAPI_FUNC(Py_UCS4*) PyUnicode_AsUCS4Copy(PyObject *unicode); If the wchar_t/Py_UNICODE representation is not yet available, this function will calculate it. */ -PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicode( +/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicode( PyObject *unicode /* Unicode object */ - ) /* Py_DEPRECATED(3.3) */; + ); /* Similar to PyUnicode_AsUnicode(), but raises a ValueError if the string contains null characters. */ @@ -773,10 +773,10 @@ PyAPI_FUNC(const Py_UNICODE *) _PyUnicode_AsUnicode( If the wchar_t/Py_UNICODE representation is not yet available, this function will calculate it. */ -PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicodeAndSize( +/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicodeAndSize( PyObject *unicode, /* Unicode object */ Py_ssize_t *size /* location where to save the length */ - ) /* Py_DEPRECATED(3.3) */; + ); #endif #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 @@ -790,9 +790,9 @@ PyAPI_FUNC(Py_ssize_t) PyUnicode_GetLength( /* Get the number of Py_UNICODE units in the string representation. */ -PyAPI_FUNC(Py_ssize_t) PyUnicode_GetSize( +Py_DEPRECATED(3.3) PyAPI_FUNC(Py_ssize_t) PyUnicode_GetSize( PyObject *unicode /* Unicode object */ - ) Py_DEPRECATED(3.3); + ); #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 /* Read a character from the string. */ @@ -816,7 +816,7 @@ PyAPI_FUNC(int) PyUnicode_WriteChar( #ifndef Py_LIMITED_API /* Get the maximum ordinal for a Unicode character. */ -PyAPI_FUNC(Py_UNICODE) PyUnicode_GetMax(void) Py_DEPRECATED(3.3); +Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE) PyUnicode_GetMax(void); #endif /* Resize a Unicode object. The length is the number of characters, except @@ -1189,11 +1189,11 @@ PyAPI_FUNC(PyObject*) PyUnicode_Decode( Use PyCodec_Decode() to decode with rot13 and non-standard codecs that decode from str. */ -PyAPI_FUNC(PyObject*) PyUnicode_AsDecodedObject( +Py_DEPRECATED(3.6) PyAPI_FUNC(PyObject*) PyUnicode_AsDecodedObject( PyObject *unicode, /* Unicode object */ const char *encoding, /* encoding */ const char *errors /* error handling */ - ) Py_DEPRECATED(3.6); + ); /* Decode a Unicode object unicode and return the result as Unicode object. @@ -1202,22 +1202,22 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsDecodedObject( Use PyCodec_Decode() to decode with rot13 and non-standard codecs that decode from str to str. */ -PyAPI_FUNC(PyObject*) PyUnicode_AsDecodedUnicode( +Py_DEPRECATED(3.6) PyAPI_FUNC(PyObject*) PyUnicode_AsDecodedUnicode( PyObject *unicode, /* Unicode object */ const char *encoding, /* encoding */ const char *errors /* error handling */ - ) Py_DEPRECATED(3.6); + ); /* Encodes a Py_UNICODE buffer of the given size and returns a Python string object. */ #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) PyUnicode_Encode( +Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_Encode( const Py_UNICODE *s, /* Unicode char buffer */ Py_ssize_t size, /* number of Py_UNICODE chars to encode */ const char *encoding, /* encoding */ const char *errors /* error handling */ - ) Py_DEPRECATED(3.3); + ); #endif /* Encodes a Unicode object and returns the result as Python @@ -1228,11 +1228,11 @@ PyAPI_FUNC(PyObject*) PyUnicode_Encode( Use PyCodec_Encode() for encoding with rot13 and non-standard codecs that encode form str to non-bytes. */ -PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedObject( +Py_DEPRECATED(3.6) PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedObject( PyObject *unicode, /* Unicode object */ const char *encoding, /* encoding */ const char *errors /* error handling */ - ) Py_DEPRECATED(3.6); + ); /* Encodes a Unicode object and returns the result as Python string object. */ @@ -1250,11 +1250,11 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedString( Use PyCodec_Encode() to encode with rot13 and non-standard codecs that encode from str to str. */ -PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedUnicode( +Py_DEPRECATED(3.6) PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedUnicode( PyObject *unicode, /* Unicode object */ const char *encoding, /* encoding */ const char *errors /* error handling */ - ) Py_DEPRECATED(3.6); + ); /* Build an encoding map. */ @@ -1278,13 +1278,13 @@ PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF7Stateful( ); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF7( +Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF7( const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length, /* number of Py_UNICODE chars to encode */ int base64SetO, /* Encode RFC2152 Set O characters in base64 */ int base64WhiteSpace, /* Encode whitespace (sp, ht, nl, cr) in base64 */ const char *errors /* error handling */ - ) Py_DEPRECATED(3.3); + ); PyAPI_FUNC(PyObject*) _PyUnicode_EncodeUTF7( PyObject *unicode, /* Unicode object */ int base64SetO, /* Encode RFC2152 Set O characters in base64 */ @@ -1317,11 +1317,11 @@ PyAPI_FUNC(PyObject*) _PyUnicode_AsUTF8String( PyObject *unicode, const char *errors); -PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF8( +Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF8( const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length, /* number of Py_UNICODE chars to encode */ const char *errors /* error handling */ - ) Py_DEPRECATED(3.3); + ); #endif /* --- UTF-32 Codecs ------------------------------------------------------ */ @@ -1392,12 +1392,12 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsUTF32String( */ #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF32( +Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF32( const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length, /* number of Py_UNICODE chars to encode */ const char *errors, /* error handling */ int byteorder /* byteorder to use 0=BOM+native;-1=LE,1=BE */ - ) Py_DEPRECATED(3.3); + ); PyAPI_FUNC(PyObject*) _PyUnicode_EncodeUTF32( PyObject *object, /* Unicode object */ const char *errors, /* error handling */ @@ -1477,12 +1477,12 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsUTF16String( */ #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF16( +Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF16( const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length, /* number of Py_UNICODE chars to encode */ const char *errors, /* error handling */ int byteorder /* byteorder to use 0=BOM+native;-1=LE,1=BE */ - ) Py_DEPRECATED(3.3); + ); PyAPI_FUNC(PyObject*) _PyUnicode_EncodeUTF16( PyObject* unicode, /* Unicode object */ const char *errors, /* error handling */ @@ -1516,10 +1516,10 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsUnicodeEscapeString( ); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) PyUnicode_EncodeUnicodeEscape( +Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_EncodeUnicodeEscape( const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length /* Number of Py_UNICODE chars to encode */ - ) Py_DEPRECATED(3.3); + ); #endif /* --- Raw-Unicode-Escape Codecs ------------------------------------------ */ @@ -1535,10 +1535,10 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsRawUnicodeEscapeString( ); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) PyUnicode_EncodeRawUnicodeEscape( +Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_EncodeRawUnicodeEscape( const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length /* Number of Py_UNICODE chars to encode */ - ) Py_DEPRECATED(3.3); + ); #endif /* --- Unicode Internal Codec --------------------------------------------- @@ -1574,11 +1574,11 @@ PyAPI_FUNC(PyObject*) _PyUnicode_AsLatin1String( PyObject* unicode, const char* errors); -PyAPI_FUNC(PyObject*) PyUnicode_EncodeLatin1( +Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_EncodeLatin1( const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */ const char *errors /* error handling */ - ) Py_DEPRECATED(3.3); + ); #endif /* --- ASCII Codecs ------------------------------------------------------- @@ -1602,11 +1602,11 @@ PyAPI_FUNC(PyObject*) _PyUnicode_AsASCIIString( PyObject* unicode, const char* errors); -PyAPI_FUNC(PyObject*) PyUnicode_EncodeASCII( +Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_EncodeASCII( const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */ const char *errors /* error handling */ - ) Py_DEPRECATED(3.3); + ); #endif /* --- Character Map Codecs ----------------------------------------------- @@ -1639,12 +1639,12 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsCharmapString( ); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) PyUnicode_EncodeCharmap( +Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_EncodeCharmap( const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */ PyObject *mapping, /* encoding mapping */ const char *errors /* error handling */ - ) Py_DEPRECATED(3.3); + ); PyAPI_FUNC(PyObject*) _PyUnicode_EncodeCharmap( PyObject *unicode, /* Unicode object */ PyObject *mapping, /* encoding mapping */ @@ -1666,12 +1666,12 @@ PyAPI_FUNC(PyObject*) _PyUnicode_EncodeCharmap( */ #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) PyUnicode_TranslateCharmap( +Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject *) PyUnicode_TranslateCharmap( const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */ PyObject *table, /* Translate table */ const char *errors /* error handling */ - ) Py_DEPRECATED(3.3); + ); #endif #ifdef MS_WINDOWS @@ -1706,11 +1706,11 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsMBCSString( ); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) PyUnicode_EncodeMBCS( +Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_EncodeMBCS( const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length, /* number of Py_UNICODE chars to encode */ const char *errors /* error handling */ - ) Py_DEPRECATED(3.3); + ); #endif #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 @@ -1748,12 +1748,12 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeCodePage( */ -PyAPI_FUNC(int) PyUnicode_EncodeDecimal( +/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(int) PyUnicode_EncodeDecimal( Py_UNICODE *s, /* Unicode buffer */ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */ char *output, /* Output buffer; must have size >= length */ const char *errors /* error handling */ - ) /* Py_DEPRECATED(3.3) */; + ); /* Transforms code points that have decimal digit property to the corresponding ASCII digit code points. @@ -1761,10 +1761,11 @@ PyAPI_FUNC(int) PyUnicode_EncodeDecimal( Returns a new Unicode string on success, NULL on failure. */ +/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(PyObject*) PyUnicode_TransformDecimalToASCII( Py_UNICODE *s, /* Unicode buffer */ Py_ssize_t length /* Number of Py_UNICODE chars to transform */ - ) /* Py_DEPRECATED(3.3) */; + ); /* Coverts a Unicode object holding a decimal value to an ASCII string for using in int, float and complex parsers. @@ -2187,17 +2188,17 @@ PyAPI_FUNC(int) _PyUnicode_IsLinebreak( const Py_UCS4 ch /* Unicode character */ ); -PyAPI_FUNC(Py_UCS4) _PyUnicode_ToLowercase( +/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(Py_UCS4) _PyUnicode_ToLowercase( Py_UCS4 ch /* Unicode character */ - ) /* Py_DEPRECATED(3.3) */; + ); -PyAPI_FUNC(Py_UCS4) _PyUnicode_ToUppercase( +/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(Py_UCS4) _PyUnicode_ToUppercase( Py_UCS4 ch /* Unicode character */ - ) /* Py_DEPRECATED(3.3) */; + ); -PyAPI_FUNC(Py_UCS4) _PyUnicode_ToTitlecase( +Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UCS4) _PyUnicode_ToTitlecase( Py_UCS4 ch /* Unicode character */ - ) Py_DEPRECATED(3.3); + ); PyAPI_FUNC(int) _PyUnicode_ToLowerFull( Py_UCS4 ch, /* Unicode character */ @@ -2259,42 +2260,42 @@ PyAPI_FUNC(int) _PyUnicode_IsAlpha( Py_UCS4 ch /* Unicode character */ ); -PyAPI_FUNC(size_t) Py_UNICODE_strlen( +Py_DEPRECATED(3.3) PyAPI_FUNC(size_t) Py_UNICODE_strlen( const Py_UNICODE *u - ) Py_DEPRECATED(3.3); + ); -PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strcpy( +Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strcpy( Py_UNICODE *s1, - const Py_UNICODE *s2) Py_DEPRECATED(3.3); + const Py_UNICODE *s2); -PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strcat( - Py_UNICODE *s1, const Py_UNICODE *s2) Py_DEPRECATED(3.3); +Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strcat( + Py_UNICODE *s1, const Py_UNICODE *s2); -PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strncpy( +Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strncpy( Py_UNICODE *s1, const Py_UNICODE *s2, - size_t n) Py_DEPRECATED(3.3); + size_t n); -PyAPI_FUNC(int) Py_UNICODE_strcmp( +Py_DEPRECATED(3.3) PyAPI_FUNC(int) Py_UNICODE_strcmp( const Py_UNICODE *s1, const Py_UNICODE *s2 - ) Py_DEPRECATED(3.3); + ); -PyAPI_FUNC(int) Py_UNICODE_strncmp( +Py_DEPRECATED(3.3) PyAPI_FUNC(int) Py_UNICODE_strncmp( const Py_UNICODE *s1, const Py_UNICODE *s2, size_t n - ) Py_DEPRECATED(3.3); + ); -PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strchr( +Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strchr( const Py_UNICODE *s, Py_UNICODE c - ) Py_DEPRECATED(3.3); + ); -PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strrchr( +Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strrchr( const Py_UNICODE *s, Py_UNICODE c - ) Py_DEPRECATED(3.3); + ); PyAPI_FUNC(PyObject*) _PyUnicode_FormatLong(PyObject *, int, int, int); @@ -2302,9 +2303,9 @@ PyAPI_FUNC(PyObject*) _PyUnicode_FormatLong(PyObject *, int, int, int); and raise a MemoryError exception on memory allocation failure, otherwise return a new allocated buffer (use PyMem_Free() to free the buffer). */ -PyAPI_FUNC(Py_UNICODE*) PyUnicode_AsUnicodeCopy( +Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE*) PyUnicode_AsUnicodeCopy( PyObject *unicode - ) Py_DEPRECATED(3.3); + ); #endif /* Py_LIMITED_API */ #if defined(Py_DEBUG) && !defined(Py_LIMITED_API) diff --git a/Misc/NEWS.d/next/Windows/2018-08-28-17-23-49.bpo-33407.ARG0W_.rst b/Misc/NEWS.d/next/Windows/2018-08-28-17-23-49.bpo-33407.ARG0W_.rst new file mode 100644 index 00000000000000..836d59c471aa03 --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2018-08-28-17-23-49.bpo-33407.ARG0W_.rst @@ -0,0 +1 @@ +Implement ``Py_DEPRECATED()`` on Windows. From f5a331a6d1a59a5e8bb0b79285a7a2cb43fc59d2 Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Wed, 15 May 2019 21:10:39 -0600 Subject: [PATCH 2/5] Add a What's New entry. --- Doc/whatsnew/3.8.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst index c135183095cae6..b82fb4b8c2e65c 100644 --- a/Doc/whatsnew/3.8.rst +++ b/Doc/whatsnew/3.8.rst @@ -1077,6 +1077,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) int Py_OldFunction(void); + + (Contributed by Zackery Spytz in :issue:`33407`.) + CPython bytecode changes ------------------------ From 2d799b15b5a0da2ca7baa0fc5e91275cf9c20e7b Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Wed, 15 May 2019 21:30:10 -0600 Subject: [PATCH 3/5] Add a missing change in the new Include/cpython/unicodeobject.h file. --- Include/cpython/unicodeobject.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h index 6be4dee1d1041d..c11503d3399921 100644 --- a/Include/cpython/unicodeobject.h +++ b/Include/cpython/unicodeobject.h @@ -822,12 +822,12 @@ Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF8( /* --- UTF-32 Codecs ------------------------------------------------------ */ -PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF32( +Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF32( const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length, /* number of Py_UNICODE chars to encode */ const char *errors, /* error handling */ int byteorder /* byteorder to use 0=BOM+native;-1=LE,1=BE */ - ) Py_DEPRECATED(3.3); + ); PyAPI_FUNC(PyObject*) _PyUnicode_EncodeUTF32( PyObject *object, /* Unicode object */ From 68d60fc5fb7fcaa6235a72e1121e753f31a7ed77 Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Fri, 24 May 2019 07:41:43 -0600 Subject: [PATCH 4/5] Use PyAPI_FUNC() in the example. --- Doc/whatsnew/3.8.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst index b82fb4b8c2e65c..ac61d1d63e1632 100644 --- a/Doc/whatsnew/3.8.rst +++ b/Doc/whatsnew/3.8.rst @@ -1082,7 +1082,7 @@ Changes in the C API Example:: - Py_DEPRECATED(3.8) int Py_OldFunction(void); + Py_DEPRECATED(3.8) PyAPI_FUNC(int) Py_OldFunction(void); (Contributed by Zackery Spytz in :issue:`33407`.) From ddec4b9b089cb4e3fb59f4bcab2d257e24173bae Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Tue, 28 May 2019 07:32:02 -0600 Subject: [PATCH 5/5] Implement the requested changes. --- Doc/c-api/intro.rst | 12 ++++++++++++ Include/pyport.h | 7 ++++--- .../Windows/2018-08-28-17-23-49.bpo-33407.ARG0W_.rst | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index 69aef0da04f3ba..e091261b061ab9 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -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: diff --git a/Include/pyport.h b/Include/pyport.h index a6b2af033ef120..32d98c59a7c134 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -504,10 +504,11 @@ extern "C" { /* Py_DEPRECATED(version) * Declare a variable, type, or function deprecated. + * The macro must be placed before the declaration. * Usage: - * Py_DEPRECATED(2.3) extern int old_var; - * Py_DEPRECATED(2.4) typedef int T1; - * Py_DEPRECATED(2.5) extern int x(); + * Py_DEPRECATED(3.3) extern int old_var; + * Py_DEPRECATED(3.4) typedef int T1; + * Py_DEPRECATED(3.8) PyAPI_FUNC(int) Py_OldFunction(void); */ #if defined(__GNUC__) \ && ((__GNUC__ >= 4) || (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)) diff --git a/Misc/NEWS.d/next/Windows/2018-08-28-17-23-49.bpo-33407.ARG0W_.rst b/Misc/NEWS.d/next/Windows/2018-08-28-17-23-49.bpo-33407.ARG0W_.rst index 836d59c471aa03..47b1e0668b18b8 100644 --- a/Misc/NEWS.d/next/Windows/2018-08-28-17-23-49.bpo-33407.ARG0W_.rst +++ b/Misc/NEWS.d/next/Windows/2018-08-28-17-23-49.bpo-33407.ARG0W_.rst @@ -1 +1 @@ -Implement ``Py_DEPRECATED()`` on Windows. +The :c:macro:`Py_DEPRECATED()` macro has been implemented for MSVC.