diff options
author | Gregory P. Smith <greg@mad-scientist.com> | 2010-01-02 22:28:48 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@mad-scientist.com> | 2010-01-02 22:28:48 (GMT) |
commit | 443ec6875f04c8111832307c047409792cd445d1 (patch) | |
tree | 7e2f3a41bbbb494feda2b6831ce180410d5e952d /Modules/md5module.c | |
parent | c2fa18ca20e9ad1b8931eec61ece2a93e24766db (diff) | |
download | cpython-443ec6875f04c8111832307c047409792cd445d1.zip cpython-443ec6875f04c8111832307c047409792cd445d1.tar.gz cpython-443ec6875f04c8111832307c047409792cd445d1.tar.bz2 |
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.
Diffstat (limited to 'Modules/md5module.c')
-rw-r--r-- | Modules/md5module.c | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/Modules/md5module.c b/Modules/md5module.c index 7081706..9d7e3fd 100644 --- a/Modules/md5module.c +++ b/Modules/md5module.c @@ -12,7 +12,6 @@ #include "Python.h" #include "structmember.h" #include "md5.h" -#include "hashlib.h" typedef struct { PyObject_HEAD @@ -51,20 +50,16 @@ md5_dealloc(md5object *md5p) 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 @@ static PyObject * 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; } |