Changeset 404 for python


Ignore:
Timestamp:
Mar 22, 2014, 2:49:57 PM (11 years ago)
Author:
dmik
Message:

python: Reuse VMS random routine on OS/2 as well.

OS/2 has always been using openssl random routine just as VMS
does but it was defined in a separate file which is superfluous.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk/Modules/posixmodule.c

    r402 r404  
    87068706#endif
    87078707
    8708 #ifndef __EMX__
    87098708PyDoc_STRVAR(posix_urandom__doc__,
    87108709"urandom(n) -> str\n\n\
     
    87368735    return result;
    87378736}
    8738 #else
    8739 /* Use openssl random routine */
    8740 #include <openssl/rand.h>
    8741 PyDoc_STRVAR(os2_urandom__doc__,
    8742 "urandom(n) -> str\n\n\
    8743 Return a string of n random bytes suitable for cryptographic use.");
    8744 
    8745 static PyObject*
    8746 os2_urandom(PyObject *self, PyObject *args)
    8747 {
    8748         int howMany;
    8749         PyObject* result;
    8750 
    8751         /* Read arguments */
    8752         if (! PyArg_ParseTuple(args, "i:urandom", &howMany))
    8753                 return NULL;
    8754         if (howMany < 0)
    8755                 return PyErr_Format(PyExc_ValueError,
    8756                                     "negative argument not allowed");
    8757 
    8758         /* Allocate bytes */
    8759         result = PyString_FromStringAndSize(NULL, howMany);
    8760         if (result != NULL) {
    8761                 /* Get random data */
    8762                 if (RAND_pseudo_bytes((unsigned char*)
    8763                                       PyString_AS_STRING(result),
    8764                                       howMany) < 0) {
    8765                         Py_DECREF(result);
    8766                         return PyErr_Format(PyExc_ValueError,
    8767                                             "RAND_pseudo_bytes");
    8768                 }
    8769         }
    8770         return result;
    8771 }
    8772 #endif
    87738737
    87748738#ifdef HAVE_SETRESUID
     
    91679131    {"getresgid",       posix_getresgid, METH_NOARGS, posix_getresgid__doc__},
    91689132#endif
    9169 #ifndef __EMX__
    91709133    {"urandom",         posix_urandom,   METH_VARARGS, posix_urandom__doc__},
    9171 #else
    9172     {"urandom",         os2_urandom,     METH_VARARGS, os2_urandom__doc__},
    9173 #endif
    91749134    {NULL,              NULL}            /* Sentinel */
    91759135};
  • python/trunk/Python/random.c

    r391 r404  
    9696
    9797
    98 #ifdef __VMS
     98#if defined(__VMS) || defined(__OS2__)
    9999/* Use openssl random routine */
    100100#include <openssl/rand.h>
     
    117117
    118118
    119 #if !defined(MS_WINDOWS) && !defined(__VMS)
     119#if !defined(MS_WINDOWS) && !defined(__VMS) && !defined(__OS2__)
    120120
    121121/* Read size bytes from /dev/urandom into buffer.
     
    244244    return win32_urandom((unsigned char *)buffer, size, 1);
    245245#else
    246 # ifdef __VMS
     246# if defined(__VMS) || defined(__OS2__)
    247247    return vms_urandom((unsigned char *)buffer, size, 1);
    248248# else
     
    303303        (void)win32_urandom((unsigned char *)secret, secret_size, 0);
    304304#else /* #ifdef MS_WINDOWS */
    305 # ifdef __VMS
     305# if defined(__VMS) || defined(__OS2__)
    306306        vms_urandom((unsigned char *)secret, secret_size, 0);
    307307# else
Note: See TracChangeset for help on using the changeset viewer.