Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(37618)

Delta Between Two Patch Sets: Modules/hashlib.h

Issue 16113: Add SHA-3 (Keccak) support
Left Patch Set: Created 6 years, 11 months ago
Right Patch Set: Created 3 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_hashlib.py ('k') | Modules/_sha3/cleanup.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* Common code for use by all hashlib related modules. */ 1 /* Common code for use by all hashlib related modules. */
2 2
3 /* 3 /*
4 * Given a PyObject* obj, fill in the Py_buffer* viewp with the result 4 * Given a PyObject* obj, fill in the Py_buffer* viewp with the result
5 * of PyObject_GetBuffer. Sets and exception and issues a return NULL 5 * of PyObject_GetBuffer. Sets an exception and issues the erraction
6 * on any errors. 6 * on any errors, e.g. 'return NULL' or 'goto error'.
7 */ 7 */
8 #define GET_BUFFER_VIEW_OR_ERROUT(obj, viewp) do { \ 8 #define GET_BUFFER_VIEW_OR_ERROR(obj, viewp, erraction) do { \
9 if (PyUnicode_Check((obj))) { \ 9 if (PyUnicode_Check((obj))) { \
10 PyErr_SetString(PyExc_TypeError, \ 10 PyErr_SetString(PyExc_TypeError, \
11 "Unicode-objects must be encoded before hashing");\ 11 "Unicode-objects must be encoded before hashing");\
12 return NULL; \ 12 erraction; \
13 } \ 13 } \
14 if (!PyObject_CheckBuffer((obj))) { \ 14 if (!PyObject_CheckBuffer((obj))) { \
15 PyErr_SetString(PyExc_TypeError, \ 15 PyErr_SetString(PyExc_TypeError, \
16 "object supporting the buffer API required"); \ 16 "object supporting the buffer API required"); \
17 return NULL; \ 17 erraction; \
18 } \ 18 } \
19 if (PyObject_GetBuffer((obj), (viewp), PyBUF_SIMPLE) == -1) { \ 19 if (PyObject_GetBuffer((obj), (viewp), PyBUF_SIMPLE) == -1) { \
20 return NULL; \ 20 erraction; \
21 } \ 21 } \
22 if ((viewp)->ndim > 1) { \ 22 if ((viewp)->ndim > 1) { \
23 PyErr_SetString(PyExc_BufferError, \ 23 PyErr_SetString(PyExc_BufferError, \
24 "Buffer must be single dimension"); \ 24 "Buffer must be single dimension"); \
25 PyBuffer_Release((viewp)); \ 25 PyBuffer_Release((viewp)); \
26 return NULL; \ 26 erraction; \
27 } \ 27 } \
28 } while(0); 28 } while(0)
29
30 #define GET_BUFFER_VIEW_OR_ERROUT(obj, viewp) \
31 GET_BUFFER_VIEW_OR_ERROR(obj, viewp, return NULL)
29 32
30 /* 33 /*
31 * Helper code to synchronize access to the hash object when the GIL is 34 * Helper code to synchronize access to the hash object when the GIL is
32 * released around a CPU consuming hashlib operation. All code paths that 35 * released around a CPU consuming hashlib operation. All code paths that
33 * access a mutable part of obj must be enclosed in a ENTER_HASHLIB / 36 * access a mutable part of obj must be enclosed in an ENTER_HASHLIB /
34 * LEAVE_HASHLIB block or explicitly acquire and release the lock inside 37 * LEAVE_HASHLIB block or explicitly acquire and release the lock inside
35 * a PY_BEGIN / END_ALLOW_THREADS block if they wish to release the GIL for 38 * a PY_BEGIN / END_ALLOW_THREADS block if they wish to release the GIL for
36 * an operation. 39 * an operation.
37 */ 40 */
38 41
39 #ifdef WITH_THREAD 42 #ifdef WITH_THREAD
40 #include "pythread.h" 43 #include "pythread.h"
41 #define ENTER_HASHLIB(obj) \ 44 #define ENTER_HASHLIB(obj) \
42 if ((obj)->lock) { \ 45 if ((obj)->lock) { \
43 if (!PyThread_acquire_lock((obj)->lock, 0)) { \ 46 if (!PyThread_acquire_lock((obj)->lock, 0)) { \
44 Py_BEGIN_ALLOW_THREADS \ 47 Py_BEGIN_ALLOW_THREADS \
45 PyThread_acquire_lock((obj)->lock, 1); \ 48 PyThread_acquire_lock((obj)->lock, 1); \
46 Py_END_ALLOW_THREADS \ 49 Py_END_ALLOW_THREADS \
47 } \ 50 } \
48 } 51 }
49 #define LEAVE_HASHLIB(obj) \ 52 #define LEAVE_HASHLIB(obj) \
50 if ((obj)->lock) { \ 53 if ((obj)->lock) { \
51 PyThread_release_lock((obj)->lock); \ 54 PyThread_release_lock((obj)->lock); \
52 } 55 }
53 #else 56 #else
54 #define ENTER_HASHLIB(obj) 57 #define ENTER_HASHLIB(obj)
55 #define LEAVE_HASHLIB(obj) 58 #define LEAVE_HASHLIB(obj)
56 #endif 59 #endif
57 60
58 /* Threshold size for initial GIL release. */ 61 /* TODO(gps): We should probably make this a module or EVPobject attribute
59 #define GIL_RELEASE_MINSIZE 2048 62 * to allow the user to optimize based on the platform they're using. */
AntoinePitrou 2012/10/05 23:27:10 You probably want a larger value, say 8192 or 1638
gregory.p.smith 2012/10/05 23:32:14 processor speeds that software runs on varies all
christian.heimes 2012/10/05 23:37:05 There is the constant, great! I'll move HASHLIB_GI
63 #define HASHLIB_GIL_MINSIZE 2048
64
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+