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.
diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c
index df4580a..004d5a3 100644
--- a/Modules/_hashopenssl.c
+++ b/Modules/_hashopenssl.c
@@ -15,7 +15,6 @@
 
 #include "Python.h"
 #include "structmember.h"
-#include "hashlib.h"
 
 #ifdef WITH_THREAD
 #include "pythread.h"
@@ -218,14 +217,11 @@
 static PyObject *
 EVP_update(EVPobject *self, PyObject *args)
 {
-    PyObject *obj;
     Py_buffer view;
 
-    if (!PyArg_ParseTuple(args, "O:update", &obj))
+    if (!PyArg_ParseTuple(args, "s*:update", &view))
         return NULL;
 
-    GET_BUFFER_VIEW_OR_ERROUT(obj, &view, NULL);
-
 #ifdef WITH_THREAD
     if (self->lock == NULL && view.len >= HASHLIB_GIL_MINSIZE) {
         self->lock = PyThread_allocate_lock();
@@ -238,17 +234,16 @@
         EVP_hash(self, view.buf, view.len);
         PyThread_release_lock(self->lock);
         Py_END_ALLOW_THREADS
-    } else {
+    }
+    else
+#endif
+    {
         EVP_hash(self, view.buf, view.len);
     }
-#else
-    EVP_hash(self, view.buf, view.len);
-#endif
 
     PyBuffer_Release(&view);
 
-    Py_INCREF(Py_None);
-    return Py_None;
+    Py_RETURN_NONE;
 }
 
 static PyMethodDef EVP_methods[] = {
@@ -314,31 +309,25 @@
 {
     static char *kwlist[] = {"name", "string", NULL};
     PyObject *name_obj = NULL;
-    PyObject *data_obj = NULL;
-    Py_buffer view;
+    Py_buffer view = { 0 };
     char *nameStr;
     const EVP_MD *digest;
 
-    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:HASH", kwlist,
-                                     &name_obj, &data_obj)) {
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|s*:HASH", kwlist,
+                                     &name_obj, &view)) {
         return -1;
     }
 
-    if (data_obj)
-        GET_BUFFER_VIEW_OR_ERROUT(data_obj, &view, -1);
-
     if (!PyArg_Parse(name_obj, "s", &nameStr)) {
         PyErr_SetString(PyExc_TypeError, "name must be a string");
-        if (data_obj)
-            PyBuffer_Release(&view);
+	PyBuffer_Release(&view);
         return -1;
     }
 
     digest = EVP_get_digestbyname(nameStr);
     if (!digest) {
         PyErr_SetString(PyExc_ValueError, "unknown hash function");
-        if (data_obj)
-            PyBuffer_Release(&view);
+	PyBuffer_Release(&view);
         return -1;
     }
     EVP_DigestInit(&self->ctx, digest);
@@ -346,7 +335,7 @@
     self->name = name_obj;
     Py_INCREF(self->name);
 
-    if (data_obj) {
+    if (view.obj) {
         if (view.len >= HASHLIB_GIL_MINSIZE) {
             Py_BEGIN_ALLOW_THREADS
             EVP_hash(self, view.buf, view.len);
@@ -471,14 +460,13 @@
 {
     static char *kwlist[] = {"name", "string", NULL};
     PyObject *name_obj = NULL;
-    PyObject *data_obj = NULL;
     Py_buffer view = { 0 };
     PyObject *ret_obj;
     char *name;
     const EVP_MD *digest;
 
-    if (!PyArg_ParseTupleAndKeywords(args, kwdict, "O|O:new", kwlist,
-                                     &name_obj, &data_obj)) {
+    if (!PyArg_ParseTupleAndKeywords(args, kwdict, "O|s*:new", kwlist,
+                                     &name_obj, &view)) {
         return NULL;
     }
 
@@ -487,16 +475,12 @@
         return NULL;
     }
 
-    if (data_obj)
-        GET_BUFFER_VIEW_OR_ERROUT(data_obj, &view, NULL);
-
     digest = EVP_get_digestbyname(name);
 
     ret_obj = EVPnew(name_obj, digest, NULL, (unsigned char*)view.buf,
-                        Py_SAFE_DOWNCAST(view.len, Py_ssize_t, unsigned int));
+		     view.len);
+    PyBuffer_Release(&view);
 
-    if (data_obj)
-        PyBuffer_Release(&view);
     return ret_obj;
 }
 
@@ -511,26 +495,19 @@
     static PyObject * \
     EVP_new_ ## NAME (PyObject *self, PyObject *args) \
     { \
-        PyObject *data_obj = NULL; \
         Py_buffer view = { 0 }; \
         PyObject *ret_obj; \
      \
-        if (!PyArg_ParseTuple(args, "|O:" #NAME , &data_obj)) { \
+        if (!PyArg_ParseTuple(args, "|s*:" #NAME , &view)) { \
             return NULL; \
         } \
      \
-        if (data_obj) \
-            GET_BUFFER_VIEW_OR_ERROUT(data_obj, &view, NULL); \
-     \
-        ret_obj = EVPnew( \
-                    CONST_ ## NAME ## _name_obj, \
-                    NULL, \
-                    CONST_new_ ## NAME ## _ctx_p, \
-                    (unsigned char*)view.buf, \
-                    Py_SAFE_DOWNCAST(view.len, Py_ssize_t, unsigned int)); \
-     \
-        if (data_obj) \
-            PyBuffer_Release(&view); \
+	ret_obj = EVPnew( \
+		    CONST_ ## NAME ## _name_obj, \
+		    NULL, \
+		    CONST_new_ ## NAME ## _ctx_p, \
+		    (unsigned char*)view.buf, view.len); \
+	PyBuffer_Release(&view); \
         return ret_obj; \
     }
 
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 @@
 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;
 }
diff --git a/Modules/sha256module.c b/Modules/sha256module.c
index f489f48..b53d2ff 100644
--- a/Modules/sha256module.c
+++ b/Modules/sha256module.c
@@ -18,7 +18,6 @@
 
 #include "Python.h"
 #include "structmember.h"
-#include "hashlib.h"
 
 
 /* Endianness testing and definitions */
@@ -481,19 +480,15 @@
 static PyObject *
 SHA256_update(SHAobject *self, PyObject *args)
 {
-    PyObject *obj;
     Py_buffer buf;
 
-    if (!PyArg_ParseTuple(args, "O:update", &obj))
+    if (!PyArg_ParseTuple(args, "s*:update", &buf))
         return NULL;
 
-    GET_BUFFER_VIEW_OR_ERROUT(obj, &buf, NULL);
-
     sha_update(self, buf.buf, buf.len);
 
     PyBuffer_Release(&buf);
-    Py_INCREF(Py_None);
-    return Py_None;
+    Py_RETURN_NONE;
 }
 
 static PyMethodDef SHA_methods[] = {
@@ -618,20 +613,15 @@
 {
     static char *kwlist[] = {"string", NULL};
     SHAobject *new;
-    PyObject *data_obj = NULL;
-    Py_buffer buf;
+    Py_buffer buf = { 0 };
 
-    if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|O:new", kwlist,
-                                     &data_obj)) {
+    if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|s*:new", kwlist,
+                                     &buf)) {
         return NULL;
     }
 
-    if (data_obj)
-        GET_BUFFER_VIEW_OR_ERROUT(data_obj, &buf, NULL);
-
     if ((new = newSHA256object()) == NULL) {
-        if (data_obj)
-            PyBuffer_Release(&buf);
+	PyBuffer_Release(&buf);
         return NULL;
     }
 
@@ -639,14 +629,13 @@
 
     if (PyErr_Occurred()) {
         Py_DECREF(new);
-        if (data_obj)
-            PyBuffer_Release(&buf);
+	PyBuffer_Release(&buf);
         return NULL;
     }
-    if (data_obj) {
+    if (buf.len > 0) {
         sha_update(new, buf.buf, buf.len);
-        PyBuffer_Release(&buf);
     }
+    PyBuffer_Release(&buf);
 
     return (PyObject *)new;
 }
@@ -659,20 +648,15 @@
 {
     static char *kwlist[] = {"string", NULL};
     SHAobject *new;
-    PyObject *data_obj = NULL;
-    Py_buffer buf;
+    Py_buffer buf = { 0 };
 
-    if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|O:new", kwlist,
-                                     &data_obj)) {
+    if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|s*:new", kwlist,
+                                     &buf)) {
         return NULL;
     }
 
-    if (data_obj)
-        GET_BUFFER_VIEW_OR_ERROUT(data_obj, &buf, NULL);
-
     if ((new = newSHA224object()) == NULL) {
-        if (data_obj)
-            PyBuffer_Release(&buf);
+	PyBuffer_Release(&buf);
         return NULL;
     }
 
@@ -680,14 +664,13 @@
 
     if (PyErr_Occurred()) {
         Py_DECREF(new);
-        if (data_obj)
-            PyBuffer_Release(&buf);
+	PyBuffer_Release(&buf);
         return NULL;
     }
-    if (data_obj) {
+    if (buf.len > 0) {
         sha_update(new, buf.buf, buf.len);
-        PyBuffer_Release(&buf);
     }
+    PyBuffer_Release(&buf);
 
     return (PyObject *)new;
 }
diff --git a/Modules/sha512module.c b/Modules/sha512module.c
index 2481275..4e8368b 100644
--- a/Modules/sha512module.c
+++ b/Modules/sha512module.c
@@ -18,7 +18,6 @@
 
 #include "Python.h"
 #include "structmember.h"
-#include "hashlib.h"
 
 #ifdef PY_LONG_LONG /* If no PY_LONG_LONG, don't compile anything! */
 
@@ -547,19 +546,15 @@
 static PyObject *
 SHA512_update(SHAobject *self, PyObject *args)
 {
-    PyObject *obj;
     Py_buffer buf;
 
-    if (!PyArg_ParseTuple(args, "O:update", &obj))
+    if (!PyArg_ParseTuple(args, "s*:update", &buf))
         return NULL;
 
-    GET_BUFFER_VIEW_OR_ERROUT(obj, &buf, NULL);
-
     sha512_update(self, buf.buf, buf.len);
 
     PyBuffer_Release(&buf);
-    Py_INCREF(Py_None);
-    return Py_None;
+    Py_RETURN_NONE;
 }
 
 static PyMethodDef SHA_methods[] = {
@@ -684,20 +679,15 @@
 {
     static char *kwlist[] = {"string", NULL};
     SHAobject *new;
-    PyObject *data_obj = NULL;
-    Py_buffer buf;
+    Py_buffer buf = { 0 };
 
-    if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|O:new", kwlist,
-                                     &data_obj)) {
+    if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|s*:new", kwlist,
+                                     &buf)) {
         return NULL;
     }
 
-    if (data_obj)
-        GET_BUFFER_VIEW_OR_ERROUT(data_obj, &buf, NULL);
-
     if ((new = newSHA512object()) == NULL) {
-        if (data_obj)
-            PyBuffer_Release(&buf);
+	PyBuffer_Release(&buf);
         return NULL;
     }
 
@@ -705,14 +695,13 @@
 
     if (PyErr_Occurred()) {
         Py_DECREF(new);
-        if (data_obj)
-            PyBuffer_Release(&buf);
+	PyBuffer_Release(&buf);
         return NULL;
     }
-    if (data_obj) {
+    if (buf.len > 0) {
         sha512_update(new, buf.buf, buf.len);
-        PyBuffer_Release(&buf);
     }
+    PyBuffer_Release(&buf);
 
     return (PyObject *)new;
 }
@@ -725,20 +714,15 @@
 {
     static char *kwlist[] = {"string", NULL};
     SHAobject *new;
-    PyObject *data_obj = NULL;
-    Py_buffer buf;
+    Py_buffer buf = { 0 };
 
-    if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|O:new", kwlist,
-                                     &data_obj)) {
+    if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|s*:new", kwlist,
+                                     &buf)) {
         return NULL;
     }
 
-    if (data_obj)
-        GET_BUFFER_VIEW_OR_ERROUT(data_obj, &buf, NULL);
-
     if ((new = newSHA384object()) == NULL) {
-        if (data_obj)
-            PyBuffer_Release(&buf);
+	PyBuffer_Release(&buf);
         return NULL;
     }
 
@@ -746,14 +730,13 @@
 
     if (PyErr_Occurred()) {
         Py_DECREF(new);
-        if (data_obj)
-            PyBuffer_Release(&buf);
+	PyBuffer_Release(&buf);
         return NULL;
     }
-    if (data_obj) {
+    if (buf.len > 0) {
         sha512_update(new, buf.buf, buf.len);
-        PyBuffer_Release(&buf);
     }
+    PyBuffer_Release(&buf);
 
     return (PyObject *)new;
 }
diff --git a/Modules/shamodule.c b/Modules/shamodule.c
index 6399b75..6e7b69e 100644
--- a/Modules/shamodule.c
+++ b/Modules/shamodule.c
@@ -17,7 +17,6 @@
 
 #include "Python.h"
 #include "structmember.h"
-#include "hashlib.h"
 
 
 /* Endianness testing and definitions */
@@ -429,20 +428,16 @@
 static PyObject *
 SHA_update(SHAobject *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);
-
     sha_update(self, (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;
 }
 
 static PyMethodDef SHA_methods[] = {
@@ -540,20 +535,15 @@
 {
     static char *kwlist[] = {"string", NULL};
     SHAobject *new;
-    PyObject *data_obj = NULL;
-    Py_buffer view;
+    Py_buffer view = { 0 };
 
-    if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|O:new", kwlist,
-                                     &data_obj)) {
+    if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|s*:new", kwlist,
+                                     &view)) {
         return NULL;
     }
 
-    if (data_obj)
-        GET_BUFFER_VIEW_OR_ERROUT(data_obj, &view, NULL);
-
     if ((new = newSHAobject()) == NULL) {
-        if (data_obj)
-            PyBuffer_Release(&view);
+	PyBuffer_Release(&view);
         return NULL;
     }
 
@@ -561,15 +551,14 @@
 
     if (PyErr_Occurred()) {
         Py_DECREF(new);
-        if (data_obj)
-            PyBuffer_Release(&view);
+	PyBuffer_Release(&view);
         return NULL;
     }
-    if (data_obj) {
+    if (view.len > 0) {
         sha_update(new, (unsigned char*)view.buf,
                    Py_SAFE_DOWNCAST(view.len, Py_ssize_t, unsigned int));
-        PyBuffer_Release(&view);
     }
+    PyBuffer_Release(&view);
 
     return (PyObject *)new;
 }