annotate Modules/hashlib.h @ 70817:dd775b1561ba

Fix markup.
author Georg Brandl <georg@python.org>
date Tue, 14 Jun 2011 21:09:55 +0200
parents ce29faed7f69
children 3716d64f846b 11c9a894680e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
51574
ce29faed7f69 - 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. */
ce29faed7f69 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
2
ce29faed7f69 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
3 /*
ce29faed7f69 - 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
ce29faed7f69 - 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 return NULL
ce29faed7f69 - 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.
ce29faed7f69 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
7 */
ce29faed7f69 - 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) do { \
ce29faed7f69 - 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))) { \
ce29faed7f69 - 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, \
ce29faed7f69 - 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");\
ce29faed7f69 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
12 return NULL; \
ce29faed7f69 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
13 } \
ce29faed7f69 - 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))) { \
ce29faed7f69 - 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, \
ce29faed7f69 - 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"); \
ce29faed7f69 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
17 return NULL; \
ce29faed7f69 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
18 } \
ce29faed7f69 - 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) { \
ce29faed7f69 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
20 return NULL; \
ce29faed7f69 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
21 } \
ce29faed7f69 - 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) { \
ce29faed7f69 - 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, \
ce29faed7f69 - 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"); \
ce29faed7f69 - 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)); \
ce29faed7f69 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
26 return NULL; \
ce29faed7f69 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
27 } \
ce29faed7f69 - 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);