You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
1.0 KiB

  1. /* Common code for use by all hashlib related modules. */
  2. /*
  3. * Given a PyObject* obj, fill in the Py_buffer* viewp with the result
  4. * of PyObject_GetBuffer. Sets and exception and issues a return NULL
  5. * on any errors.
  6. */
  7. #define GET_BUFFER_VIEW_OR_ERROUT(obj, viewp) do { \
  8. if (PyUnicode_Check((obj))) { \
  9. PyErr_SetString(PyExc_TypeError, \
  10. "Unicode-objects must be encoded before hashing");\
  11. return NULL; \
  12. } \
  13. if (!PyObject_CheckBuffer((obj))) { \
  14. PyErr_SetString(PyExc_TypeError, \
  15. "object supporting the buffer API required"); \
  16. return NULL; \
  17. } \
  18. if (PyObject_GetBuffer((obj), (viewp), PyBUF_SIMPLE) == -1) { \
  19. return NULL; \
  20. } \
  21. if ((viewp)->ndim > 1) { \
  22. PyErr_SetString(PyExc_BufferError, \
  23. "Buffer must be single dimension"); \
  24. PyBuffer_Release((viewp)); \
  25. return NULL; \
  26. } \
  27. } while(0);