Mercurial > cpython-lru_cache-weakref
diff Modules/md5module.c @ 58101:ff5bc2fa38d6 legacy-trunk
Issue #3745: Undo the requirement for new buffer API only objects to be passed
to hashlib functions in python 2.x. The module now uses the 's*' for argument
parsing which auto encodes unicode objects to the system default encoding for
us.
| author | Gregory P. Smith <greg@mad-scientist.com> |
|---|---|
| date | Sat, 02 Jan 2010 22:28:48 +0000 |
| parents | 6c08bfe78fff |
| children | fd25030223b0 |
line wrap: on
line diff
--- a/Modules/md5module.c Sat Jan 02 22:25:29 2010 +0000 +++ b/Modules/md5module.c Sat Jan 02 22:28:48 2010 +0000 @@ -12,7 +12,6 @@ #include "Python.h" #include "structmember.h" #include "md5.h" -#include "hashlib.h" typedef struct { PyObject_HEAD @@ -51,20 +50,16 @@ static PyObject * md5_update(md5object *self, PyObject *args) { - PyObject *data_obj; Py_buffer view; - if (!PyArg_ParseTuple(args, "O:update", &data_obj)) + if (!PyArg_ParseTuple(args, "s*:update", &view)) return NULL; - GET_BUFFER_VIEW_OR_ERROUT(data_obj, &view, NULL); - md5_append(&self->md5, (unsigned char*)view.buf, Py_SAFE_DOWNCAST(view.len, Py_ssize_t, unsigned int)); PyBuffer_Release(&view); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } PyDoc_STRVAR(update_doc, @@ -266,26 +261,21 @@ MD5_new(PyObject *self, PyObject *args) { md5object *md5p; - PyObject *data_obj = NULL; - Py_buffer view; + Py_buffer view = { 0 }; - if (!PyArg_ParseTuple(args, "|O:new", &data_obj)) + if (!PyArg_ParseTuple(args, "|s*:new", &view)) return NULL; - if (data_obj) - GET_BUFFER_VIEW_OR_ERROUT(data_obj, &view, NULL); - if ((md5p = newmd5object()) == NULL) { - if (data_obj) - PyBuffer_Release(&view); + PyBuffer_Release(&view); return NULL; } - if (data_obj) { + if (view.len > 0) { md5_append(&md5p->md5, (unsigned char*)view.buf, Py_SAFE_DOWNCAST(view.len, Py_ssize_t, unsigned int)); - PyBuffer_Release(&view); } + PyBuffer_Release(&view); return (PyObject *)md5p; }
