annotate Modules/hashlib.h @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents 1e7ac14e4938
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
51580
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
1 /* Common code for use by all hashlib related modules. */
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
2
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
3 /*
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
4 * Given a PyObject* obj, fill in the Py_buffer* viewp with the result
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
5 * of PyObject_GetBuffer. Sets and exception and issues a returns
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
6 * on any errors.
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
7 */
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
8 #define GET_BUFFER_VIEW_OR_ERROUT(obj, viewp, error_return) do { \
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
9 if (PyUnicode_Check((obj))) { \
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
10 PyErr_SetString(PyExc_TypeError, \
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
11 "Unicode-objects must be encoded before hashing");\
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
12 return error_return; \
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
13 } \
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
14 if (!PyObject_CheckBuffer((obj))) { \
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
15 PyErr_SetString(PyExc_TypeError, \
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
16 "object supporting the buffer API required"); \
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
17 return error_return; \
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
18 } \
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
19 if (PyObject_GetBuffer((obj), (viewp), PyBUF_SIMPLE) == -1) { \
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
20 return error_return; \
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
21 } \
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
22 if ((viewp)->ndim > 1) { \
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
23 PyErr_SetString(PyExc_BufferError, \
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
24 "Buffer must be single dimension"); \
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
25 PyBuffer_Release((viewp)); \
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
26 return error_return; \
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
27 } \
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
28 } while(0);