Skip to content

Commit 89c0e3c

Browse files
committed
reduce exported scope
1 parent a1a2f1b commit 89c0e3c

File tree

2 files changed

+39
-38
lines changed

2 files changed

+39
-38
lines changed

Modules/_hashlib/hashlib_buffer.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,28 @@ _Py_hashlib_data_argument(PyObject **res, PyObject *data, PyObject *string)
3838
return -1;
3939
}
4040
}
41+
42+
int
43+
_Py_hashlib_get_buffer_view(PyObject *obj, Py_buffer *view)
44+
{
45+
if (PyUnicode_Check(obj)) {
46+
PyErr_SetString(PyExc_TypeError,
47+
"Strings must be encoded before hashing");
48+
return -1;
49+
}
50+
if (!PyObject_CheckBuffer(obj)) {
51+
PyErr_SetString(PyExc_TypeError,
52+
"object supporting the buffer API required");
53+
return -1;
54+
}
55+
if (PyObject_GetBuffer(obj, view, PyBUF_SIMPLE) == -1) {
56+
return -1;
57+
}
58+
if (view->ndim > 1) {
59+
PyErr_SetString(PyExc_BufferError,
60+
"Buffer must be single dimension");
61+
PyBuffer_Release(view);
62+
return -1;
63+
}
64+
return 0;
65+
}

Modules/_hashlib/hashlib_buffer.h

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,26 @@
33

44
#include "Python.h"
55

6+
/*
7+
* Allow to use the 'data' or 'string' keyword in hashlib.new()
8+
* and other hash functions named constructors.
9+
*
10+
* - If 'data' and 'string' are both non-NULL, set an exception and return -1.
11+
* - If 'data' and 'string' are both NULL, set '*res' to NULL and return 0.
12+
* - Otherwise, set '*res' to 'data' or 'string' and return 1. A deprecation
13+
* warning is set when 'string' is specified.
14+
*/
15+
extern int
16+
_Py_hashlib_data_argument(PyObject **res, PyObject *data, PyObject *string);
17+
618
/*
719
* Obtain a buffer view from a buffer-like object 'obj'.
820
*
921
* On success, store the result in 'view' and return 0.
1022
* On error, set an exception and return -1.
1123
*/
12-
static inline int
13-
_Py_hashlib_get_buffer_view(PyObject *obj, Py_buffer *view)
14-
{
15-
if (PyUnicode_Check(obj)) {
16-
PyErr_SetString(PyExc_TypeError,
17-
"Strings must be encoded before hashing");
18-
return -1;
19-
}
20-
if (!PyObject_CheckBuffer(obj)) {
21-
PyErr_SetString(PyExc_TypeError,
22-
"object supporting the buffer API required");
23-
return -1;
24-
}
25-
if (PyObject_GetBuffer(obj, view, PyBUF_SIMPLE) == -1) {
26-
return -1;
27-
}
28-
if (view->ndim > 1) {
29-
PyErr_SetString(PyExc_BufferError,
30-
"Buffer must be single dimension");
31-
PyBuffer_Release(view);
32-
return -1;
33-
}
34-
return 0;
35-
}
24+
extern int
25+
_Py_hashlib_get_buffer_view(PyObject *obj, Py_buffer *view);
3626

3727
/*
3828
* Call _Py_hashlib_get_buffer_view() and check if it succeeded.
@@ -51,18 +41,4 @@ _Py_hashlib_get_buffer_view(PyObject *obj, Py_buffer *view)
5141
#define GET_BUFFER_VIEW_OR_ERROUT(OBJ, VIEW) \
5242
GET_BUFFER_VIEW_OR_ERROR(OBJ, VIEW, return NULL)
5343

54-
/*
55-
* Allow to use the 'data' or 'string' keyword in hashlib.new()
56-
* and other hash functions named constructors.
57-
*
58-
* - If 'data' and 'string' are both non-NULL, set an exception and return -1.
59-
* - If 'data' and 'string' are both NULL, set '*res' to NULL and return 0.
60-
* - Otherwise, set '*res' to 'data' or 'string' and return 1. A deprecation
61-
* warning is set when 'string' is specified.
62-
*
63-
* The symbol is exported for '_hashlib' and HACL*-based extension modules.
64-
*/
65-
PyAPI_FUNC(int)
66-
_Py_hashlib_data_argument(PyObject **res, PyObject *data, PyObject *string);
67-
6844
#endif // !_HASHLIB_HASHLIB_BUFFER_H

0 commit comments

Comments
 (0)