Skip to content

Commit bbe7497

Browse files
authored
bpo-45434: Remove pystrhex.h header file (GH-28923)
Move Include/pystrhex.h to Include/internal/pycore_strhex.h. The header file only contains private functions. The following C extensions are now built with Py_BUILD_CORE_MODULE macro defined to get access to the internal C API: * _blake2 * _hashopenssl * _md5 * _sha1 * _sha3 * _ssl * binascii
1 parent a8b9350 commit bbe7497

22 files changed

+93
-63
lines changed

Doc/whatsnew/3.11.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,3 +598,7 @@ Removed
598598
since Python 3.3. Use ``PyUnicode_CopyCharacters()`` or ``memcpy()``
599599
(``wchar_t*`` string), and ``PyUnicode_Fill()`` functions instead.
600600
(Contributed by Victor Stinner in :issue:`41123`.)
601+
602+
* Remove the ``pystrhex.h`` header file. It only contains private functions.
603+
C extensions should only include the main ``<Python.h>`` header file.
604+
(Contributed by Victor Stinner in :issue:`45434`.)

Include/internal/pycore_strhex.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#ifndef Py_INTERNAL_STRHEX_H
2+
#define Py_INTERNAL_STRHEX_H
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
#ifndef Py_BUILD_CORE
8+
# error "this header requires Py_BUILD_CORE define"
9+
#endif
10+
11+
// Returns a str() containing the hex representation of argbuf.
12+
PyAPI_FUNC(PyObject*) _Py_strhex(const
13+
char* argbuf,
14+
const Py_ssize_t arglen);
15+
16+
// Returns a bytes() containing the ASCII hex representation of argbuf.
17+
PyAPI_FUNC(PyObject*) _Py_strhex_bytes(
18+
const char* argbuf,
19+
const Py_ssize_t arglen);
20+
21+
// These variants include support for a separator between every N bytes:
22+
PyAPI_FUNC(PyObject*) _Py_strhex_with_sep(
23+
const char* argbuf,
24+
const Py_ssize_t arglen,
25+
const PyObject* sep,
26+
const int bytes_per_group);
27+
PyAPI_FUNC(PyObject*) _Py_strhex_bytes_with_sep(
28+
const char* argbuf,
29+
const Py_ssize_t arglen,
30+
const PyObject* sep,
31+
const int bytes_per_group);
32+
33+
#ifdef __cplusplus
34+
}
35+
#endif
36+
#endif /* !Py_INTERNAL_STRHEX_H */

Include/pystrhex.h

Lines changed: 0 additions & 22 deletions
This file was deleted.

Makefile.pre.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,6 @@ PYTHON_HEADERS= \
11791179
$(srcdir)/Include/pyport.h \
11801180
$(srcdir)/Include/pystate.h \
11811181
$(srcdir)/Include/pystrcmp.h \
1182-
$(srcdir)/Include/pystrhex.h \
11831182
$(srcdir)/Include/pystrtod.h \
11841183
$(srcdir)/Include/pythonrun.h \
11851184
$(srcdir)/Include/pythread.h \
@@ -1271,6 +1270,7 @@ PYTHON_HEADERS= \
12711270
$(srcdir)/Include/internal/pycore_pymem.h \
12721271
$(srcdir)/Include/internal/pycore_pystate.h \
12731272
$(srcdir)/Include/internal/pycore_runtime.h \
1273+
$(srcdir)/Include/internal/pycore_strhex.h \
12741274
$(srcdir)/Include/internal/pycore_structseq.h \
12751275
$(srcdir)/Include/internal/pycore_symtable.h \
12761276
$(srcdir)/Include/internal/pycore_sysmodule.h \
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Remove the ``pystrhex.h`` header file. It only contains private functions. C
2+
extensions should only include the main ``<Python.h>`` header file. Patch by
3+
Victor Stinner.

Modules/Setup

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,19 +212,23 @@ _symtable symtablemodule.c
212212
# OPENSSL=/path/to/openssl/directory
213213
# _ssl _ssl.c \
214214
# -I$(OPENSSL)/include -L$(OPENSSL)/lib \
215-
# -lssl -lcrypto
215+
# -lssl -lcrypto \
216+
# -DPy_BUILD_CORE_BUILTIN
216217
#_hashlib _hashopenssl.c \
217218
# -I$(OPENSSL)/include -L$(OPENSSL)/lib \
218-
# -lcrypto
219+
# -lcrypto \
220+
# -DPy_BUILD_CORE_BUILTIN
219221

220222
# To statically link OpenSSL:
221223
# _ssl _ssl.c \
222224
# -I$(OPENSSL)/include -L$(OPENSSL)/lib \
223225
# -l:libssl.a -Wl,--exclude-libs,libssl.a \
224-
# -l:libcrypto.a -Wl,--exclude-libs,libcrypto.a
226+
# -l:libcrypto.a -Wl,--exclude-libs,libcrypto.a \
227+
# -DPy_BUILD_CORE_BUILTIN
225228
#_hashlib _hashopenssl.c \
226229
# -I$(OPENSSL)/include -L$(OPENSSL)/lib \
227-
# -l:libcrypto.a -Wl,--exclude-libs,libcrypto.a
230+
# -l:libcrypto.a -Wl,--exclude-libs,libcrypto.a \
231+
# -DPy_BUILD_CORE_BUILTIN
228232

229233
# The crypt module is now disabled by default because it breaks builds
230234
# on many systems (where -lcrypt is needed), e.g. Linux (I believe).
@@ -255,18 +259,18 @@ _symtable symtablemodule.c
255259
# The _md5 module implements the RSA Data Security, Inc. MD5
256260
# Message-Digest Algorithm, described in RFC 1321.
257261

258-
#_md5 md5module.c
262+
#_md5 md5module.c -DPy_BUILD_CORE_BUILTIN
259263

260264

261265
# The _sha module implements the SHA checksum algorithms.
262266
# (NIST's Secure Hash Algorithms.)
263-
#_sha1 sha1module.c
267+
#_sha1 sha1module.c -DPy_BUILD_CORE_BUILTIN
264268
#_sha256 sha256module.c -DPy_BUILD_CORE_BUILTIN
265269
#_sha512 sha512module.c -DPy_BUILD_CORE_BUILTIN
266-
#_sha3 _sha3/sha3module.c
270+
#_sha3 _sha3/sha3module.c -DPy_BUILD_CORE_BUILTIN
267271

268272
# _blake module
269-
#_blake2 _blake2/blake2module.c _blake2/blake2b_impl.c _blake2/blake2s_impl.c
273+
#_blake2 _blake2/blake2module.c _blake2/blake2b_impl.c _blake2/blake2s_impl.c -DPy_BUILD_CORE_BUILTIN
270274

271275
# The _tkinter module.
272276
#
@@ -339,7 +343,7 @@ _symtable symtablemodule.c
339343

340344

341345
# Helper module for various ascii-encoders
342-
#binascii binascii.c
346+
#binascii binascii.c -DPy_BUILD_CORE_MODULE
343347

344348
# Andrew Kuchling's zlib module.
345349
# This require zlib 1.1.3 (or later).

Modules/_blake2/blake2b_impl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
#include "Python.h"
17-
#include "pystrhex.h"
17+
#include "pycore_strhex.h" // _Py_strhex()
1818

1919
#include "../hashlib.h"
2020
#include "blake2ns.h"

Modules/_blake2/blake2s_impl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
#include "Python.h"
17-
#include "pystrhex.h"
17+
#include "pycore_strhex.h" // _Py_strhex()
1818

1919
#include "../hashlib.h"
2020
#include "blake2ns.h"

Modules/_hashopenssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include "Python.h"
2424
#include "hashlib.h"
25-
#include "pystrhex.h"
25+
#include "pycore_strhex.h" // _Py_strhex()
2626

2727
/* EVP is the preferred interface to hashing in OpenSSL */
2828
#include <openssl/evp.h>

Modules/_sha3/sha3module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
#include "Python.h"
19-
#include "pystrhex.h"
19+
#include "pycore_strhex.h" // _Py_strhex()
2020
#include "../hashlib.h"
2121

2222
/* **************************************************************************

0 commit comments

Comments
 (0)