[Python-checkins] python/dist/src/Modules posixmodule.c, 2.325,
2.326
tim_one at users.sourceforge.net
tim_one at users.sourceforge.net
Mon Aug 30 19:36:49 CEST 2004
Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13542/Modules
Modified Files:
posixmodule.c
Log Message:
win32_urandom(): There's no need to copy the generated byte string, so
don't.
Index: posixmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/posixmodule.c,v
retrieving revision 2.325
retrieving revision 2.326
diff -u -d -r2.325 -r2.326
--- posixmodule.c 30 Aug 2004 17:10:53 -0000 2.325
+++ posixmodule.c 30 Aug 2004 17:36:46 -0000 2.326
@@ -7239,9 +7239,8 @@
static PyObject*
win32_urandom(PyObject *self, PyObject *args)
{
- int howMany = 0;
- unsigned char* bytes = NULL;
- PyObject* returnVal = NULL;
+ int howMany;
+ PyObject* result;
/* Read arguments */
if (! PyArg_ParseTuple(args, "i:urandom", &howMany))
@@ -7282,21 +7281,16 @@
}
/* Allocate bytes */
- bytes = (unsigned char*)PyMem_Malloc(howMany);
- if (bytes == NULL)
- return PyErr_NoMemory();
-
- /* Get random data */
- if (! pCryptGenRandom(hCryptProv, howMany, bytes)) {
- PyMem_Free(bytes);
- return win32_error("CryptGenRandom", NULL);
+ result = PyString_FromStringAndSize(NULL, howMany);
+ if (result != NULL) {
+ /* Get random data */
+ if (! pCryptGenRandom(hCryptProv, howMany, (unsigned char*)
+ PyString_AS_STRING(result))) {
+ Py_DECREF(result);
+ return win32_error("CryptGenRandom", NULL);
+ }
}
-
- /* Build return value */
- returnVal = PyString_FromStringAndSize(bytes, howMany);
- PyMem_Free(bytes);
-
- return returnVal;
+ return result;
}
#endif
More information about the Python-checkins
mailing list