Author: guido.van.rossum
Date: Tue Jul 10 15:20:29 2007
New Revision: 56238

Modified:
   python/branches/py3k-struni/Modules/_hashopenssl.c
Log:
Make sure hexdigest() returns str, not str8.


Modified: python/branches/py3k-struni/Modules/_hashopenssl.c
==============================================================================
--- python/branches/py3k-struni/Modules/_hashopenssl.c  (original)
+++ python/branches/py3k-struni/Modules/_hashopenssl.c  Tue Jul 10 15:20:29 2007
@@ -127,17 +127,10 @@
 
     EVP_MD_CTX_cleanup(&temp_ctx);
 
-    /* Create a new string */
-    /* NOTE: not thread safe! modifying an already created string object */
-    /* (not a problem because we hold the GIL by default) */
-    retval = PyString_FromStringAndSize(NULL, digest_size * 2);
-    if (!retval)
-           return NULL;
-    hex_digest = PyString_AS_STRING(retval);
-    if (!hex_digest) {
-           Py_DECREF(retval);
-           return NULL;
-    }
+    /* Allocate a new buffer */
+    hex_digest = PyMem_Malloc(digest_size * 2 + 1);
+    if (!hex_digest)
+       return PyErr_NoMemory();
 
     /* Make hex version of the digest */
     for(i=j=0; i<digest_size; i++) {
@@ -149,6 +142,8 @@
        c = (c>9) ? c+'a'-10 : c + '0';
         hex_digest[j++] = c;
     }
+    retval = PyUnicode_FromStringAndSize(hex_digest, digest_size * 2);
+    PyMem_Free(hex_digest);
     return retval;
 }
 
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins

Reply via email to