From db837c19b606de4e1e18689b9a89fd5777ab836b Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Fri, 16 Apr 2021 17:08:43 +0200 Subject: [PATCH 1/5] Move _Py_EncodeLocaleRaw to the private header This symbol is not part of the limited API, and was even missing in Python's stable ABI DLL. --- Include/cpython/fileutils.h | 3 +++ Include/fileutils.h | 4 ---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Include/cpython/fileutils.h b/Include/cpython/fileutils.h index 312fd958284788..954f078d25a77d 100644 --- a/Include/cpython/fileutils.h +++ b/Include/cpython/fileutils.h @@ -32,6 +32,9 @@ PyAPI_FUNC(int) _Py_EncodeLocaleEx( int current_locale, _Py_error_handler errors); +PyAPI_FUNC(char*) _Py_EncodeLocaleRaw( + const wchar_t *text, + size_t *error_pos); PyAPI_FUNC(PyObject *) _Py_device_encoding(int); diff --git a/Include/fileutils.h b/Include/fileutils.h index 12bd071c49c04a..16f3b635deed89 100644 --- a/Include/fileutils.h +++ b/Include/fileutils.h @@ -12,10 +12,6 @@ PyAPI_FUNC(wchar_t *) Py_DecodeLocale( PyAPI_FUNC(char*) Py_EncodeLocale( const wchar_t *text, size_t *error_pos); - -PyAPI_FUNC(char*) _Py_EncodeLocaleRaw( - const wchar_t *text, - size_t *error_pos); #endif #ifndef Py_LIMITED_API From 2f05fde3887b753a57f3fb3123744bdd6aff6ea1 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Fri, 16 Apr 2021 17:11:05 +0200 Subject: [PATCH 2/5] Don't define _Py_HashSecret_Initialized in limited API The underscore means it's not public API. It was also not exported in the Windows stable ABI library. --- Include/pyhash.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/Include/pyhash.h b/Include/pyhash.h index 4437b870332bde..9351284a0d0f97 100644 --- a/Include/pyhash.h +++ b/Include/pyhash.h @@ -77,7 +77,6 @@ typedef union { } expat; } _Py_HashSecret_t; PyAPI_DATA(_Py_HashSecret_t) _Py_HashSecret; -#endif #ifdef Py_DEBUG PyAPI_DATA(int) _Py_HashSecret_Initialized; @@ -85,7 +84,6 @@ PyAPI_DATA(int) _Py_HashSecret_Initialized; /* hash function definition */ -#ifndef Py_LIMITED_API typedef struct { Py_hash_t (*const hash)(const void *, Py_ssize_t); const char *name; From 1d11e55ad46a6715698b2b9f08313b4801e9f1e7 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Tue, 20 Apr 2021 14:30:49 +0200 Subject: [PATCH 3/5] Remove PyMarshal_* and PyMember_{Get,Set}One functions from the limited API These functions are not declared with Py_LIMITED_API. Except for functions that take FILE*, they remain in the stable ABI. --- Doc/data/stable_abi.dat | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Doc/data/stable_abi.dat b/Doc/data/stable_abi.dat index b7e3ef4a676a8e..90637cc2ebce3b 100644 --- a/Doc/data/stable_abi.dat +++ b/Doc/data/stable_abi.dat @@ -351,16 +351,10 @@ PyMapping_Length PyMapping_SetItemString PyMapping_Size PyMapping_Values -PyMarshal_ReadObjectFromString -PyMarshal_WriteLongToFile -PyMarshal_WriteObjectToFile -PyMarshal_WriteObjectToString PyMem_Free PyMem_Malloc PyMem_Realloc PyMemberDescr_Type -PyMember_GetOne -PyMember_SetOne PyMemoryView_FromMemory PyMemoryView_FromObject PyMemoryView_GetContiguous From 75094f4dac2c226cabb2596bc66cfed8c8a1d4ed Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Fri, 16 Apr 2021 18:00:52 +0200 Subject: [PATCH 4/5] Include PyMem_Calloc in the limited API --- Doc/data/stable_abi.dat | 1 + Include/cpython/pymem.h | 2 -- Include/pymem.h | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/data/stable_abi.dat b/Doc/data/stable_abi.dat index 90637cc2ebce3b..cdc7160250243b 100644 --- a/Doc/data/stable_abi.dat +++ b/Doc/data/stable_abi.dat @@ -351,6 +351,7 @@ PyMapping_Length PyMapping_SetItemString PyMapping_Size PyMapping_Values +PyMem_Calloc PyMem_Free PyMem_Malloc PyMem_Realloc diff --git a/Include/cpython/pymem.h b/Include/cpython/pymem.h index 61d719584584e8..d1054d76520b9a 100644 --- a/Include/cpython/pymem.h +++ b/Include/cpython/pymem.h @@ -10,8 +10,6 @@ PyAPI_FUNC(void) PyMem_RawFree(void *ptr); /* Try to get the allocators name set by _PyMem_SetupAllocators(). */ PyAPI_FUNC(const char*) _PyMem_GetCurrentAllocatorName(void); -PyAPI_FUNC(void *) PyMem_Calloc(size_t nelem, size_t elsize); - /* strdup() using PyMem_RawMalloc() */ PyAPI_FUNC(char *) _PyMem_RawStrdup(const char *str); diff --git a/Include/pymem.h b/Include/pymem.h index 92cd5369589edb..2f770b1fbf183d 100644 --- a/Include/pymem.h +++ b/Include/pymem.h @@ -50,6 +50,7 @@ extern "C" { */ PyAPI_FUNC(void *) PyMem_Malloc(size_t size); +PyAPI_FUNC(void *) PyMem_Calloc(size_t nelem, size_t elsize); PyAPI_FUNC(void *) PyMem_Realloc(void *ptr, size_t new_size); PyAPI_FUNC(void) PyMem_Free(void *ptr); From 2ec383f086cece1642588ae47e971871c8eb604f Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Tue, 20 Apr 2021 15:06:35 +0200 Subject: [PATCH 5/5] Add blurb --- Misc/NEWS.d/next/C API/2021-04-20-15-06-29.bpo-43795.y0IP4c.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/C API/2021-04-20-15-06-29.bpo-43795.y0IP4c.rst diff --git a/Misc/NEWS.d/next/C API/2021-04-20-15-06-29.bpo-43795.y0IP4c.rst b/Misc/NEWS.d/next/C API/2021-04-20-15-06-29.bpo-43795.y0IP4c.rst new file mode 100644 index 00000000000000..1dee6e2d69a1b4 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2021-04-20-15-06-29.bpo-43795.y0IP4c.rst @@ -0,0 +1,2 @@ +:c:func:`PyMem_Calloc` is now available in the limited C API +(``Py_LIMITED_API``).