From 45876a90e2663f12b90c2090ec3e48bd97841aae Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 12 Feb 2020 22:32:34 +0100 Subject: bpo-35081: Move bytes_methods.h to the internal C API (GH-18492) Move the bytes_methods.h header file to the internal C API as pycore_bytes_methods.h: it only contains private symbols (prefixed by "_Py"), except of the PyDoc_STRVAR_shared() macro. --- Include/bytes_methods.h | 69 -------------------- Include/internal/pycore_bytes_methods.h | 73 ++++++++++++++++++++++ Makefile.pre.in | 2 +- .../C API/2020-02-12-21-38-49.bpo-35081.5tj1yC.rst | 3 + Objects/bytearrayobject.c | 2 +- Objects/bytes_methods.c | 2 +- Objects/bytesobject.c | 2 +- Objects/stringlib/ctype.h | 2 +- Objects/unicodeobject.c | 2 +- PCbuild/pythoncore.vcxproj | 2 +- PCbuild/pythoncore.vcxproj.filters | 6 +- 11 files changed, 86 insertions(+), 79 deletions(-) delete mode 100644 Include/bytes_methods.h create mode 100644 Include/internal/pycore_bytes_methods.h create mode 100644 Misc/NEWS.d/next/C API/2020-02-12-21-38-49.bpo-35081.5tj1yC.rst diff --git a/Include/bytes_methods.h b/Include/bytes_methods.h deleted file mode 100644 index 8434a50..0000000 --- a/Include/bytes_methods.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef Py_LIMITED_API -#ifndef Py_BYTES_CTYPE_H -#define Py_BYTES_CTYPE_H - -/* - * The internal implementation behind PyBytes (bytes) and PyByteArray (bytearray) - * methods of the given names, they operate on ASCII byte strings. - */ -extern PyObject* _Py_bytes_isspace(const char *cptr, Py_ssize_t len); -extern PyObject* _Py_bytes_isalpha(const char *cptr, Py_ssize_t len); -extern PyObject* _Py_bytes_isalnum(const char *cptr, Py_ssize_t len); -extern PyObject* _Py_bytes_isascii(const char *cptr, Py_ssize_t len); -extern PyObject* _Py_bytes_isdigit(const char *cptr, Py_ssize_t len); -extern PyObject* _Py_bytes_islower(const char *cptr, Py_ssize_t len); -extern PyObject* _Py_bytes_isupper(const char *cptr, Py_ssize_t len); -extern PyObject* _Py_bytes_istitle(const char *cptr, Py_ssize_t len); - -/* These store their len sized answer in the given preallocated *result arg. */ -extern void _Py_bytes_lower(char *result, const char *cptr, Py_ssize_t len); -extern void _Py_bytes_upper(char *result, const char *cptr, Py_ssize_t len); -extern void _Py_bytes_title(char *result, const char *s, Py_ssize_t len); -extern void _Py_bytes_capitalize(char *result, const char *s, Py_ssize_t len); -extern void _Py_bytes_swapcase(char *result, const char *s, Py_ssize_t len); - -extern PyObject *_Py_bytes_find(const char *str, Py_ssize_t len, PyObject *args); -extern PyObject *_Py_bytes_index(const char *str, Py_ssize_t len, PyObject *args); -extern PyObject *_Py_bytes_rfind(const char *str, Py_ssize_t len, PyObject *args); -extern PyObject *_Py_bytes_rindex(const char *str, Py_ssize_t len, PyObject *args); -extern PyObject *_Py_bytes_count(const char *str, Py_ssize_t len, PyObject *args); -extern int _Py_bytes_contains(const char *str, Py_ssize_t len, PyObject *arg); -extern PyObject *_Py_bytes_startswith(const char *str, Py_ssize_t len, PyObject *args); -extern PyObject *_Py_bytes_endswith(const char *str, Py_ssize_t len, PyObject *args); - -/* The maketrans() static method. */ -extern PyObject* _Py_bytes_maketrans(Py_buffer *frm, Py_buffer *to); - -/* Shared __doc__ strings. */ -extern const char _Py_isspace__doc__[]; -extern const char _Py_isalpha__doc__[]; -extern const char _Py_isalnum__doc__[]; -extern const char _Py_isascii__doc__[]; -extern const char _Py_isdigit__doc__[]; -extern const char _Py_islower__doc__[]; -extern const char _Py_isupper__doc__[]; -extern const char _Py_istitle__doc__[]; -extern const char _Py_lower__doc__[]; -extern const char _Py_upper__doc__[]; -extern const char _Py_title__doc__[]; -extern const char _Py_capitalize__doc__[]; -extern const char _Py_swapcase__doc__[]; -extern const char _Py_count__doc__[]; -extern const char _Py_find__doc__[]; -extern const char _Py_index__doc__[]; -extern const char _Py_rfind__doc__[]; -extern const char _Py_rindex__doc__[]; -extern const char _Py_startswith__doc__[]; -extern const char _Py_endswith__doc__[]; -extern const char _Py_maketrans__doc__[]; -extern const char _Py_expandtabs__doc__[]; -extern const char _Py_ljust__doc__[]; -extern const char _Py_rjust__doc__[]; -extern const char _Py_center__doc__[]; -extern const char _Py_zfill__doc__[]; - -/* this is needed because some docs are shared from the .o, not static */ -#define PyDoc_STRVAR_shared(name,str) const char name[] = PyDoc_STR(str) - -#endif /* !Py_BYTES_CTYPE_H */ -#endif /* !Py_LIMITED_API */ diff --git a/Include/internal/pycore_bytes_methods.h b/Include/internal/pycore_bytes_methods.h new file mode 100644 index 0000000..11e8ab2 --- /dev/null +++ b/Include/internal/pycore_bytes_methods.h @@ -0,0 +1,73 @@ +#ifndef Py_LIMITED_API +#ifndef Py_BYTES_CTYPE_H +#define Py_BYTES_CTYPE_H + +#ifndef Py_BUILD_CORE +# error "this header requires Py_BUILD_CORE define" +#endif + +/* + * The internal implementation behind PyBytes (bytes) and PyByteArray (bytearray) + * methods of the given names, they operate on ASCII byte strings. + */ +extern PyObject* _Py_bytes_isspace(const char *cptr, Py_ssize_t len); +extern PyObject* _Py_bytes_isalpha(const char *cptr, Py_ssize_t len); +extern PyObject* _Py_bytes_isalnum(const char *cptr, Py_ssize_t len); +extern PyObject* _Py_bytes_isascii(const char *cptr, Py_ssize_t len); +extern PyObject* _Py_bytes_isdigit(const char *cptr, Py_ssize_t len); +extern PyObject* _Py_bytes_islower(const char *cptr, Py_ssize_t len); +extern PyObject* _Py_bytes_isupper(const char *cptr, Py_ssize_t len); +extern PyObject* _Py_bytes_istitle(const char *cptr, Py_ssize_t len); + +/* These store their len sized answer in the given preallocated *result arg. */ +extern void _Py_bytes_lower(char *result, const char *cptr, Py_ssize_t len); +extern void _Py_bytes_upper(char *result, const char *cptr, Py_ssize_t len); +extern void _Py_bytes_title(char *result, const char *s, Py_ssize_t len); +extern void _Py_bytes_capitalize(char *result, const char *s, Py_ssize_t len); +extern void _Py_bytes_swapcase(char *result, const char *s, Py_ssize_t len); + +extern PyObject *_Py_bytes_find(const char *str, Py_ssize_t len, PyObject *args); +extern PyObject *_Py_bytes_index(const char *str, Py_ssize_t len, PyObject *args); +extern PyObject *_Py_bytes_rfind(const char *str, Py_ssize_t len, PyObject *args); +extern PyObject *_Py_bytes_rindex(const char *str, Py_ssize_t len, PyObject *args); +extern PyObject *_Py_bytes_count(const char *str, Py_ssize_t len, PyObject *args); +extern int _Py_bytes_contains(const char *str, Py_ssize_t len, PyObject *arg); +extern PyObject *_Py_bytes_startswith(const char *str, Py_ssize_t len, PyObject *args); +extern PyObject *_Py_bytes_endswith(const char *str, Py_ssize_t len, PyObject *args); + +/* The maketrans() static method. */ +extern PyObject* _Py_bytes_maketrans(Py_buffer *frm, Py_buffer *to); + +/* Shared __doc__ strings. */ +extern const char _Py_isspace__doc__[]; +extern const char _Py_isalpha__doc__[]; +extern const char _Py_isalnum__doc__[]; +extern const char _Py_isascii__doc__[]; +extern const char _Py_isdigit__doc__[]; +extern const char _Py_islower__doc__[]; +extern const char _Py_isupper__doc__[]; +extern const char _Py_istitle__doc__[]; +extern const char _Py_lower__doc__[]; +extern const char _Py_upper__doc__[]; +extern const char _Py_title__doc__[]; +extern const char _Py_capitalize__doc__[]; +extern const char _Py_swapcase__doc__[]; +extern const char _Py_count__doc__[]; +extern const char _Py_find__doc__[]; +extern const char _Py_index__doc__[]; +extern const char _Py_rfind__doc__[]; +extern const char _Py_rindex__doc__[]; +extern const char _Py_startswith__doc__[]; +extern const char _Py_endswith__doc__[]; +extern const char _Py_maketrans__doc__[]; +extern const char _Py_expandtabs__doc__[]; +extern const char _Py_ljust__doc__[]; +extern const char _Py_rjust__doc__[]; +extern const char _Py_center__doc__[]; +extern const char _Py_zfill__doc__[]; + +/* this is needed because some docs are shared from the .o, not static */ +#define PyDoc_STRVAR_shared(name,str) const char name[] = PyDoc_STR(str) + +#endif /* !Py_BYTES_CTYPE_H */ +#endif /* !Py_LIMITED_API */ diff --git a/Makefile.pre.in b/Makefile.pre.in index 3da104b..aae93ff 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -970,7 +970,6 @@ PYTHON_HEADERS= \ $(srcdir)/Include/bltinmodule.h \ $(srcdir)/Include/boolobject.h \ $(srcdir)/Include/bytearrayobject.h \ - $(srcdir)/Include/bytes_methods.h \ $(srcdir)/Include/bytesobject.h \ $(srcdir)/Include/cellobject.h \ $(srcdir)/Include/ceval.h \ @@ -1077,6 +1076,7 @@ PYTHON_HEADERS= \ \ $(srcdir)/Include/internal/pycore_accu.h \ $(srcdir)/Include/internal/pycore_atomic.h \ + $(srcdir)/Include/internal/pycore_bytes_methods.h \ $(srcdir)/Include/internal/pycore_call.h \ $(srcdir)/Include/internal/pycore_ceval.h \ $(srcdir)/Include/internal/pycore_code.h \ diff --git a/Misc/NEWS.d/next/C API/2020-02-12-21-38-49.bpo-35081.5tj1yC.rst b/Misc/NEWS.d/next/C API/2020-02-12-21-38-49.bpo-35081.5tj1yC.rst new file mode 100644 index 0000000..6be3320 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2020-02-12-21-38-49.bpo-35081.5tj1yC.rst @@ -0,0 +1,3 @@ +Move the ``bytes_methods.h`` header file to the internal C API as +``pycore_bytes_methods.h``: it only contains private symbols (prefixed by +``_Py``), except of the ``PyDoc_STRVAR_shared()`` macro. diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index a3fc35c..d396435 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -2,11 +2,11 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" +#include "pycore_bytes_methods.h" #include "pycore_object.h" #include "pycore_pymem.h" #include "pycore_pystate.h" #include "structmember.h" -#include "bytes_methods.h" #include "bytesobject.h" #include "pystrhex.h" diff --git a/Objects/bytes_methods.c b/Objects/bytes_methods.c index db030be..a4b3868 100644 --- a/Objects/bytes_methods.c +++ b/Objects/bytes_methods.c @@ -1,6 +1,6 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" -#include "bytes_methods.h" +#include "pycore_bytes_methods.h" PyDoc_STRVAR_shared(_Py_isspace__doc__, "B.isspace() -> bool\n\ diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index df3edda..bd8af72 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -3,11 +3,11 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" +#include "pycore_bytes_methods.h" #include "pycore_object.h" #include "pycore_pymem.h" #include "pycore_pystate.h" -#include "bytes_methods.h" #include "pystrhex.h" #include diff --git a/Objects/stringlib/ctype.h b/Objects/stringlib/ctype.h index 843cfa2..9b319b0 100644 --- a/Objects/stringlib/ctype.h +++ b/Objects/stringlib/ctype.h @@ -2,7 +2,7 @@ # error "ctype.h only compatible with byte-wise strings" #endif -#include "bytes_methods.h" +#include "pycore_bytes_methods.h" static PyObject* stringlib_isspace(PyObject *self, PyObject *Py_UNUSED(ignored)) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 8470e41..11fa1fb5 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -40,6 +40,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define PY_SSIZE_T_CLEAN #include "Python.h" +#include "pycore_bytes_methods.h" #include "pycore_fileutils.h" #include "pycore_initconfig.h" #include "pycore_object.h" @@ -47,7 +48,6 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "pycore_pylifecycle.h" #include "pycore_pystate.h" #include "ucnhash.h" -#include "bytes_methods.h" #include "stringlib/eq.h" #ifdef MS_WINDOWS diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index 36a27f4..a3719d8 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -115,7 +115,6 @@ - @@ -161,6 +160,7 @@ + diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters index 0301557..67e223d 100644 --- a/PCbuild/pythoncore.vcxproj.filters +++ b/PCbuild/pythoncore.vcxproj.filters @@ -48,9 +48,6 @@ Include - - Include - Include @@ -186,6 +183,9 @@ Include + + Include + Include -- cgit v0.12