mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +00:00
Undiamond Python headers
This change gets the Python codebase into a state where it conforms to the conventions of this codebase. It's now possible to include headers from Python, without worrying about ordering. Python has traditionally solved that problem by "diamonding" everything in Python.h, but that's problematic since it means any change to any Python header invalidates all the build artifacts. Lastly it makes tooling not work. Since it is hard to explain to Emacs when I press C-c C-h to add an import line it shouldn't add the header that actually defines the symbol, and instead do follow the nonstandard Python convention. Progress has been made on letting Python load source code from the zip executable structure via the standard C library APIs. System calss now recognizes zip!FILENAME alternative URIs as equivalent to zip:FILENAME since Python uses colon as its delimiter. Some progress has been made on embedding the notice license terms into the Python object code. This is easier said than done since Python has an extremely complicated ownership story. - Some termios APIs have been added - Implement rewinddir() dirstream API - GetCpuCount() API added to Cosmopolitan Libc - More bugs in Cosmopolitan Libc have been fixed - zipobj.com now has flags for mangling the path - Fixed bug a priori with sendfile() on certain BSDs - Polyfill F_DUPFD and F_DUPFD_CLOEXEC across platforms - FIOCLEX / FIONCLEX now polyfilled for fast O_CLOEXEC changes - APE now supports a hybrid solution to no-self-modify for builds - Many BSD-only magnums added, e.g. O_SEARCH, O_SHLOCK, SF_NODISKIO
This commit is contained in:
parent
20bb8db9f8
commit
b420ed8248
762 changed files with 18410 additions and 53772 deletions
49
third_party/python/Python/random.c
vendored
49
third_party/python/Python/random.c
vendored
|
@ -1,6 +1,19 @@
|
|||
/* clang-format off */
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/rand/rand.h"
|
||||
#include "libc/sysv/consts/grnd.h"
|
||||
#include "third_party/python/Include/Python.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "third_party/python/Include/ceval.h"
|
||||
#include "third_party/python/Include/fileutils.h"
|
||||
#include "third_party/python/Include/object.h"
|
||||
#include "third_party/python/Include/pydebug.h"
|
||||
#include "third_party/python/Include/pyerrors.h"
|
||||
#include "third_party/python/Include/pyhash.h"
|
||||
#include "third_party/python/Include/pymacro.h"
|
||||
#include "third_party/python/pyconfig.h"
|
||||
/* clang-format off */
|
||||
|
||||
#ifdef Py_DEBUG
|
||||
int _Py_HashSecret_Initialized = 0;
|
||||
|
@ -8,7 +21,6 @@ int _Py_HashSecret_Initialized = 0;
|
|||
static int _Py_HashSecret_Initialized = 0;
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_GETRANDOM) || defined(HAVE_GETRANDOM_SYSCALL)
|
||||
#define PY_GETRANDOM 1
|
||||
|
||||
/* Call getrandom() to get random bytes:
|
||||
|
@ -41,17 +53,9 @@ py_getrandom(void *buffer, Py_ssize_t size, int blocking, int raise)
|
|||
flags = blocking ? 0 : GRND_NONBLOCK;
|
||||
dest = buffer;
|
||||
while (0 < size) {
|
||||
#ifdef sun
|
||||
/* Issue #26735: On Solaris, getrandom() is limited to returning up
|
||||
to 1024 bytes. Call it multiple times if more bytes are
|
||||
requested. */
|
||||
n = Py_MIN(size, 1024);
|
||||
#else
|
||||
n = Py_MIN(size, LONG_MAX);
|
||||
#endif
|
||||
n = Py_MIN(size, 256);
|
||||
|
||||
errno = 0;
|
||||
#ifdef HAVE_GETRANDOM
|
||||
if (raise) {
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
n = getrandom(dest, n, flags);
|
||||
|
@ -60,24 +64,6 @@ py_getrandom(void *buffer, Py_ssize_t size, int blocking, int raise)
|
|||
else {
|
||||
n = getrandom(dest, n, flags);
|
||||
}
|
||||
#else
|
||||
/* On Linux, use the syscall() function because the GNU libc doesn't
|
||||
expose the Linux getrandom() syscall yet. See:
|
||||
https://sourceware.org/bugzilla/show_bug.cgi?id=17252 */
|
||||
if (raise) {
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
n = syscall(SYS_getrandom, dest, n, flags);
|
||||
Py_END_ALLOW_THREADS
|
||||
}
|
||||
else {
|
||||
n = syscall(SYS_getrandom, dest, n, flags);
|
||||
}
|
||||
# ifdef _Py_MEMORY_SANITIZER
|
||||
if (n > 0) {
|
||||
__msan_unpoison(dest, n);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
if (n < 0) {
|
||||
/* ENOSYS: the syscall is not supported by the kernel.
|
||||
|
@ -259,7 +245,6 @@ dev_urandom_close(void)
|
|||
urandom_cache.fd = -1;
|
||||
}
|
||||
}
|
||||
#endif /* !MS_WINDOWS */
|
||||
|
||||
|
||||
/* Fill buffer with pseudo-random bytes generated by a linear congruent
|
||||
|
@ -422,7 +407,7 @@ _PyRandom_Init(void)
|
|||
}
|
||||
if (seed == 0) {
|
||||
/* disable the randomized hash */
|
||||
memset(secret, 0, secret_size);
|
||||
bzero(secret, secret_size);
|
||||
Py_HashRandomizationFlag = 0;
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue