~ubuntu-branches/ubuntu/maverick/python3.1/maverick

« back to all changes in this revision

Viewing changes to Modules/hashlib.h

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-03-23 00:01:27 UTC
  • Revision ID: james.westby@ubuntu.com-20090323000127-5fstfxju4ufrhthq
Tags: upstream-3.1~a1+20090322
ImportĀ upstreamĀ versionĀ 3.1~a1+20090322

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Common code for use by all hashlib related modules. */
 
2
 
 
3
/*
 
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
 
6
 * on any errors.
 
7
 */
 
8
#define GET_BUFFER_VIEW_OR_ERROUT(obj, viewp) do { \
 
9
        if (PyUnicode_Check((obj))) { \
 
10
            PyErr_SetString(PyExc_TypeError, \
 
11
                            "Unicode-objects must be encoded before hashing");\
 
12
            return NULL; \
 
13
        } \
 
14
        if (!PyObject_CheckBuffer((obj))) { \
 
15
            PyErr_SetString(PyExc_TypeError, \
 
16
                            "object supporting the buffer API required"); \
 
17
            return NULL; \
 
18
        } \
 
19
        if (PyObject_GetBuffer((obj), (viewp), PyBUF_SIMPLE) == -1) { \
 
20
            return NULL; \
 
21
        } \
 
22
        if ((viewp)->ndim > 1) { \
 
23
            PyErr_SetString(PyExc_BufferError, \
 
24
                            "Buffer must be single dimension"); \
 
25
            PyBuffer_Release((viewp)); \
 
26
            return NULL; \
 
27
        } \
 
28
    } while(0);