mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-25 06:42:27 +00:00
Source changes for compilation
These are the commits from https://github.com/ahgamut/cpython/tree/cosmo_py36 squashed for simplicity. Also included is the pyconfig.h used for compilation. The pyconfig.h has to be changed manually in case Cosmopolitan gets new features.
This commit is contained in:
parent
0c4c56ff39
commit
5ef64dbcdb
82 changed files with 2009 additions and 424 deletions
|
@ -286,6 +286,7 @@ _close_open_fds_safe(int start_fd, PyObject* py_fds_to_keep)
|
|||
} else {
|
||||
char buffer[sizeof(struct linux_dirent64)];
|
||||
int bytes;
|
||||
#if 0
|
||||
while ((bytes = syscall(SYS_getdents64, fd_dir_fd,
|
||||
(struct linux_dirent64 *)buffer,
|
||||
sizeof(buffer))) > 0) {
|
||||
|
@ -305,6 +306,7 @@ _close_open_fds_safe(int start_fd, PyObject* py_fds_to_keep)
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
close(fd_dir_fd);
|
||||
}
|
||||
}
|
||||
|
|
1
third_party/python/Modules/_testcapimodule.c
vendored
1
third_party/python/Modules/_testcapimodule.c
vendored
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
#define PY_SSIZE_T_CLEAN
|
||||
#undef Py_BUILD_CORE
|
||||
|
||||
#include "Python.h"
|
||||
#include <float.h>
|
||||
|
|
2
third_party/python/Modules/addrinfo.h
vendored
2
third_party/python/Modules/addrinfo.h
vendored
|
@ -27,6 +27,8 @@
|
|||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define HAVE_GETADDRINFO 1
|
||||
#define HAVE_GETNAMEINFO 1
|
||||
#ifndef HAVE_GETADDRINFO
|
||||
|
||||
/*
|
||||
|
|
36
third_party/python/Modules/faulthandler.c
vendored
36
third_party/python/Modules/faulthandler.c
vendored
|
@ -14,6 +14,7 @@
|
|||
# include <sys/resource.h>
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
/* Allocate at maximum 100 MB of the stack to raise the stack overflow */
|
||||
#define STACK_OVERFLOW_MAX_SIZE (100*1024*1024)
|
||||
|
||||
|
@ -109,22 +110,30 @@ static void faulthandler_user(int signum);
|
|||
#endif /* FAULTHANDLER_USER */
|
||||
|
||||
|
||||
static fault_handler_t faulthandler_handlers[] = {
|
||||
#ifdef SIGBUS
|
||||
{SIGBUS, 0, "Bus error", },
|
||||
#endif
|
||||
#ifdef SIGILL
|
||||
{SIGILL, 0, "Illegal instruction", },
|
||||
#endif
|
||||
{SIGFPE, 0, "Floating point exception", },
|
||||
{SIGABRT, 0, "Aborted", },
|
||||
/* define SIGSEGV at the end to make it the default choice if searching the
|
||||
handler fails in faulthandler_fatal_error() */
|
||||
{SIGSEGV, 0, "Segmentation fault", }
|
||||
};
|
||||
static fault_handler_t faulthandler_handlers[5];
|
||||
static const size_t faulthandler_nsignals = \
|
||||
Py_ARRAY_LENGTH(faulthandler_handlers);
|
||||
|
||||
static void faulthandler_handlers_init()
|
||||
{
|
||||
fault_handler_t local_handlers[] = {
|
||||
#ifdef SIGBUS
|
||||
{SIGBUS, 0, "Bus error", },
|
||||
#endif
|
||||
#ifdef SIGILL
|
||||
{SIGILL, 0, "Illegal instruction", },
|
||||
#endif
|
||||
{SIGFPE, 0, "Floating point exception", },
|
||||
{SIGABRT, 0, "Aborted", },
|
||||
/* define SIGSEGV at the end to make it the default choice if searching the
|
||||
handler fails in faulthandler_fatal_error() */
|
||||
{SIGSEGV, 0, "Segmentation fault", }
|
||||
};
|
||||
_Static_assert(sizeof(faulthandler_handlers) == sizeof(local_handlers), "handler alloc error");
|
||||
memcpy(faulthandler_handlers, local_handlers, sizeof(local_handlers));
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_SIGALTSTACK
|
||||
static stack_t stack;
|
||||
static stack_t old_stack;
|
||||
|
@ -1355,6 +1364,7 @@ int _PyFaulthandler_Init(void)
|
|||
PyThread_acquire_lock(thread.cancel_event, 1);
|
||||
#endif
|
||||
|
||||
faulthandler_handlers_init();
|
||||
return faulthandler_env_options();
|
||||
}
|
||||
|
||||
|
|
5
third_party/python/Modules/gcmodule.c
vendored
5
third_party/python/Modules/gcmodule.c
vendored
|
@ -23,6 +23,11 @@
|
|||
|
||||
*/
|
||||
|
||||
#ifdef unreachable
|
||||
#define __unreachable unreachable
|
||||
#undef unreachable
|
||||
#endif
|
||||
|
||||
#include "Python.h"
|
||||
#include "frameobject.h" /* for PyFrame_ClearFreeList */
|
||||
#include "pydtrace.h"
|
||||
|
|
356
third_party/python/Modules/getpath.c
vendored
356
third_party/python/Modules/getpath.c
vendored
|
@ -6,6 +6,9 @@
|
|||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wunused-function" // search_for_exec_prefix
|
||||
#pragma GCC diagnostic ignored "-Wunused-but-set-variable" // separator
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <mach-o/dyld.h>
|
||||
#endif
|
||||
|
@ -460,46 +463,35 @@ calculate_path(void)
|
|||
{
|
||||
extern wchar_t *Py_GetProgramName(void);
|
||||
|
||||
static const wchar_t delimiter[2] = {DELIM, '\0'};
|
||||
static const wchar_t separator[2] = {SEP, '\0'};
|
||||
char *_rtpypath = Py_GETENV("PYTHONPATH"); /* XXX use wide version on Windows */
|
||||
wchar_t *rtpypath = NULL;
|
||||
wchar_t *home = Py_GetPythonHome();
|
||||
static wchar_t delimiter[2] = {DELIM, '\0'};
|
||||
static wchar_t separator[2] = {SEP, '\0'};
|
||||
/* ignore PYTHONPATH/PYTHONHOME for now */
|
||||
// char *_rtpypath = Py_GETENV("PYTHONPATH");
|
||||
/* XXX use wide version on Windows */
|
||||
// wchar_t *rtpypath = NULL;
|
||||
// wchar_t *home = Py_GetPythonHome();
|
||||
char *_path = getenv("PATH");
|
||||
wchar_t *path_buffer = NULL;
|
||||
wchar_t *path = NULL;
|
||||
wchar_t *prog = Py_GetProgramName();
|
||||
wchar_t argv0_path[MAXPATHLEN+1];
|
||||
wchar_t zip_path[MAXPATHLEN+1];
|
||||
int pfound, efound; /* 1 if found; -1 if found build directory */
|
||||
/* wont need zip_path because embedded stdlib inside executable */
|
||||
/* wchar_t zip_path[MAXPATHLEN+1]; */
|
||||
wchar_t *buf;
|
||||
size_t bufsz;
|
||||
size_t prefixsz;
|
||||
wchar_t *defpath;
|
||||
#ifdef WITH_NEXT_FRAMEWORK
|
||||
NSModule pythonModule;
|
||||
const char* modPath;
|
||||
#endif
|
||||
#ifdef __APPLE__
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
|
||||
uint32_t nsexeclength = MAXPATHLEN;
|
||||
#else
|
||||
unsigned long nsexeclength = MAXPATHLEN;
|
||||
#endif
|
||||
char execpath[MAXPATHLEN+1];
|
||||
#endif
|
||||
wchar_t *_pythonpath, *_prefix, *_exec_prefix;
|
||||
wchar_t *lib_python;
|
||||
wchar_t ape_path[MAXPATHLEN+1];
|
||||
size_t ape_length;
|
||||
wchar_t ape_lib_path[MAXPATHLEN+1];
|
||||
wchar_t ape_exec_path[MAXPATHLEN+1];
|
||||
|
||||
_pythonpath = Py_DecodeLocale(PYTHONPATH, NULL);
|
||||
_prefix = Py_DecodeLocale(PREFIX, NULL);
|
||||
_exec_prefix = Py_DecodeLocale(EXEC_PREFIX, NULL);
|
||||
lib_python = Py_DecodeLocale("lib/python" VERSION, NULL);
|
||||
wchar_t package_path[MAXPATHLEN+1];
|
||||
wchar_t ape_package_path[MAXPATHLEN+1];
|
||||
|
||||
if (!_pythonpath || !_prefix || !_exec_prefix || !lib_python) {
|
||||
Py_FatalError(
|
||||
"Unable to decode path variables in getpath.c: "
|
||||
"memory error");
|
||||
if(IsWindows())
|
||||
{
|
||||
fprintf(stderr, "python APE on Windows\n");
|
||||
delimiter[0] = L';';
|
||||
separator[0] = L'\\';
|
||||
}
|
||||
|
||||
if (_path) {
|
||||
|
@ -514,25 +506,6 @@ calculate_path(void)
|
|||
*/
|
||||
if (wcschr(prog, SEP))
|
||||
wcsncpy(progpath, prog, MAXPATHLEN);
|
||||
#ifdef __APPLE__
|
||||
/* On Mac OS X, if a script uses an interpreter of the form
|
||||
* "#!/opt/python2.3/bin/python", the kernel only passes "python"
|
||||
* as argv[0], which falls through to the $PATH search below.
|
||||
* If /opt/python2.3/bin isn't in your path, or is near the end,
|
||||
* this algorithm may incorrectly find /usr/bin/python. To work
|
||||
* around this, we can use _NSGetExecutablePath to get a better
|
||||
* hint of what the intended interpreter was, although this
|
||||
* will fail if a relative path was used. but in that case,
|
||||
* absolutize() should help us out below
|
||||
*/
|
||||
else if(0 == _NSGetExecutablePath(execpath, &nsexeclength) && execpath[0] == SEP) {
|
||||
size_t r = mbstowcs(progpath, execpath, MAXPATHLEN+1);
|
||||
if (r == (size_t)-1 || r > MAXPATHLEN) {
|
||||
/* Could not convert execpath, or it's too long. */
|
||||
progpath[0] = '\0';
|
||||
}
|
||||
}
|
||||
#endif /* __APPLE__ */
|
||||
else if (path) {
|
||||
while (1) {
|
||||
wchar_t *delim = wcschr(path, DELIM);
|
||||
|
@ -566,259 +539,98 @@ calculate_path(void)
|
|||
wcsncpy(argv0_path, progpath, MAXPATHLEN);
|
||||
argv0_path[MAXPATHLEN] = '\0';
|
||||
|
||||
#ifdef WITH_NEXT_FRAMEWORK
|
||||
/* On Mac OS X we have a special case if we're running from a framework.
|
||||
** This is because the python home should be set relative to the library,
|
||||
** which is in the framework, not relative to the executable, which may
|
||||
** be outside of the framework. Except when we're in the build directory...
|
||||
*/
|
||||
pythonModule = NSModuleForSymbol(NSLookupAndBindSymbol("_Py_Initialize"));
|
||||
/* Use dylib functions to find out where the framework was loaded from */
|
||||
modPath = NSLibraryNameForModule(pythonModule);
|
||||
if (modPath != NULL) {
|
||||
/* We're in a framework. */
|
||||
/* See if we might be in the build directory. The framework in the
|
||||
** build directory is incomplete, it only has the .dylib and a few
|
||||
** needed symlinks, it doesn't have the Lib directories and such.
|
||||
** If we're running with the framework from the build directory we must
|
||||
** be running the interpreter in the build directory, so we use the
|
||||
** build-directory-specific logic to find Lib and such.
|
||||
*/
|
||||
wchar_t* wbuf = Py_DecodeLocale(modPath, NULL);
|
||||
if (wbuf == NULL) {
|
||||
Py_FatalError("Cannot decode framework location");
|
||||
}
|
||||
|
||||
wcsncpy(argv0_path, wbuf, MAXPATHLEN);
|
||||
reduce(argv0_path);
|
||||
joinpath(argv0_path, lib_python);
|
||||
joinpath(argv0_path, LANDMARK);
|
||||
if (!ismodule(argv0_path)) {
|
||||
/* We are in the build directory so use the name of the
|
||||
executable - we know that the absolute path is passed */
|
||||
wcsncpy(argv0_path, progpath, MAXPATHLEN);
|
||||
}
|
||||
else {
|
||||
/* Use the location of the library as the progpath */
|
||||
wcsncpy(argv0_path, wbuf, MAXPATHLEN);
|
||||
}
|
||||
PyMem_RawFree(wbuf);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if HAVE_READLINK
|
||||
{
|
||||
wchar_t tmpbuffer[MAXPATHLEN+1];
|
||||
int linklen = _Py_wreadlink(progpath, tmpbuffer, MAXPATHLEN);
|
||||
while (linklen != -1) {
|
||||
if (tmpbuffer[0] == SEP)
|
||||
/* tmpbuffer should never be longer than MAXPATHLEN,
|
||||
but extra check does not hurt */
|
||||
wcsncpy(argv0_path, tmpbuffer, MAXPATHLEN);
|
||||
else {
|
||||
/* Interpret relative to progpath */
|
||||
reduce(argv0_path);
|
||||
joinpath(argv0_path, tmpbuffer);
|
||||
}
|
||||
linklen = _Py_wreadlink(argv0_path, tmpbuffer, MAXPATHLEN);
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_READLINK */
|
||||
|
||||
reduce(argv0_path);
|
||||
/* At this point, argv0_path is guaranteed to be less than
|
||||
MAXPATHLEN bytes long.
|
||||
*/
|
||||
|
||||
/* Search for an environment configuration file, first in the
|
||||
executable's directory and then in the parent directory.
|
||||
If found, open it for use when searching for prefixes.
|
||||
*/
|
||||
/* not searching for pyvenv.cfg */
|
||||
|
||||
|
||||
|
||||
/* Avoid absolute path got prefix */
|
||||
wcsncpy(prefix, L"Lib", MAXPATHLEN);
|
||||
|
||||
/* Avoid absolute path for exec_prefix */
|
||||
wcsncpy(exec_prefix, L"build/lib.linux-x86_64-3.6", MAXPATHLEN);
|
||||
|
||||
wcsncpy(package_path, L"Lib/site-packages", MAXPATHLEN);
|
||||
|
||||
// printf("progpath = %ls, prog = %ls\n", progpath, prog);
|
||||
/* add paths for the internal store of the APE */
|
||||
if(wcslen(progpath) > 0 && wcslen(progpath) + 1 < MAXPATHLEN)
|
||||
wcsncpy(ape_path, progpath, MAXPATHLEN);
|
||||
else
|
||||
wcsncpy(ape_path, prog, MAXPATHLEN);
|
||||
ape_length = wcslen(ape_path);
|
||||
|
||||
wcsncpy(ape_lib_path, ape_path, MAXPATHLEN);
|
||||
// extra 1 at the start for the slash
|
||||
if(ape_length + 1 + wcslen(prefix) + 1 < MAXPATHLEN)
|
||||
{
|
||||
wchar_t tmpbuffer[MAXPATHLEN+1];
|
||||
wchar_t *env_cfg = L"pyvenv.cfg";
|
||||
FILE * env_file = NULL;
|
||||
|
||||
wcscpy(tmpbuffer, argv0_path);
|
||||
|
||||
joinpath(tmpbuffer, env_cfg);
|
||||
env_file = _Py_wfopen(tmpbuffer, L"r");
|
||||
if (env_file == NULL) {
|
||||
errno = 0;
|
||||
reduce(tmpbuffer);
|
||||
reduce(tmpbuffer);
|
||||
joinpath(tmpbuffer, env_cfg);
|
||||
env_file = _Py_wfopen(tmpbuffer, L"r");
|
||||
if (env_file == NULL) {
|
||||
errno = 0;
|
||||
}
|
||||
}
|
||||
if (env_file != NULL) {
|
||||
/* Look for a 'home' variable and set argv0_path to it, if found */
|
||||
if (find_env_config_value(env_file, L"home", tmpbuffer)) {
|
||||
wcscpy(argv0_path, tmpbuffer);
|
||||
}
|
||||
fclose(env_file);
|
||||
env_file = NULL;
|
||||
}
|
||||
ape_lib_path[ape_length] = L'/';
|
||||
wcscat(ape_lib_path + ape_length + 1, prefix);
|
||||
}
|
||||
|
||||
wcsncpy(ape_exec_path, ape_path, MAXPATHLEN);
|
||||
if(ape_length + 1 + wcslen(exec_prefix) + 1 < MAXPATHLEN)
|
||||
{
|
||||
ape_exec_path[ape_length] = L'/';
|
||||
wcscat(ape_exec_path + ape_length + 1, exec_prefix);
|
||||
}
|
||||
|
||||
pfound = search_for_prefix(argv0_path, home, _prefix, lib_python);
|
||||
if (!pfound) {
|
||||
if (!Py_FrozenFlag)
|
||||
fprintf(stderr,
|
||||
"Could not find platform independent libraries <prefix>\n");
|
||||
wcsncpy(prefix, _prefix, MAXPATHLEN);
|
||||
joinpath(prefix, lib_python);
|
||||
wcsncpy(ape_package_path, ape_path, MAXPATHLEN);
|
||||
if(ape_length + 1 + wcslen(package_path) + 1 < MAXPATHLEN)
|
||||
{
|
||||
ape_package_path[ape_length] = L'/';
|
||||
wcscat(ape_package_path + ape_length + 1, package_path);
|
||||
}
|
||||
else
|
||||
reduce(prefix);
|
||||
|
||||
wcsncpy(zip_path, prefix, MAXPATHLEN);
|
||||
zip_path[MAXPATHLEN] = L'\0';
|
||||
if (pfound > 0) { /* Use the reduced prefix returned by Py_GetPrefix() */
|
||||
reduce(zip_path);
|
||||
reduce(zip_path);
|
||||
}
|
||||
else
|
||||
wcsncpy(zip_path, _prefix, MAXPATHLEN);
|
||||
joinpath(zip_path, L"lib/python00.zip");
|
||||
bufsz = wcslen(zip_path); /* Replace "00" with version */
|
||||
zip_path[bufsz - 6] = VERSION[0];
|
||||
zip_path[bufsz - 5] = VERSION[2];
|
||||
|
||||
efound = search_for_exec_prefix(argv0_path, home,
|
||||
_exec_prefix, lib_python);
|
||||
if (!efound) {
|
||||
if (!Py_FrozenFlag)
|
||||
fprintf(stderr,
|
||||
"Could not find platform dependent libraries <exec_prefix>\n");
|
||||
wcsncpy(exec_prefix, _exec_prefix, MAXPATHLEN);
|
||||
joinpath(exec_prefix, L"lib/lib-dynload");
|
||||
}
|
||||
/* If we found EXEC_PREFIX do *not* reduce it! (Yet.) */
|
||||
|
||||
if ((!pfound || !efound) && !Py_FrozenFlag)
|
||||
fprintf(stderr,
|
||||
"Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]\n");
|
||||
|
||||
/* Calculate size of return buffer.
|
||||
*/
|
||||
/* Calculate size of return buffer */
|
||||
bufsz = 0;
|
||||
|
||||
if (_rtpypath && _rtpypath[0] != '\0') {
|
||||
size_t rtpypath_len;
|
||||
rtpypath = Py_DecodeLocale(_rtpypath, &rtpypath_len);
|
||||
if (rtpypath != NULL)
|
||||
bufsz += rtpypath_len + 1;
|
||||
}
|
||||
|
||||
defpath = _pythonpath;
|
||||
prefixsz = wcslen(prefix) + 1;
|
||||
while (1) {
|
||||
wchar_t *delim = wcschr(defpath, DELIM);
|
||||
|
||||
if (defpath[0] != SEP)
|
||||
/* Paths are relative to prefix */
|
||||
bufsz += prefixsz;
|
||||
|
||||
if (delim)
|
||||
bufsz += delim - defpath + 1;
|
||||
else {
|
||||
bufsz += wcslen(defpath) + 1;
|
||||
break;
|
||||
}
|
||||
defpath = delim + 1;
|
||||
}
|
||||
|
||||
bufsz += wcslen(zip_path) + 1;
|
||||
bufsz += wcslen(ape_lib_path) + 1;
|
||||
bufsz += wcslen(ape_exec_path) + 1;
|
||||
bufsz += wcslen(ape_package_path) + 1;
|
||||
bufsz += wcslen(ape_path) + 1;
|
||||
bufsz += wcslen(prefix) + 1;
|
||||
bufsz += wcslen(exec_prefix) + 1;
|
||||
bufsz += wcslen(package_path) + 1;
|
||||
|
||||
/* This is the only malloc call in this file */
|
||||
buf = PyMem_RawMalloc(bufsz * sizeof(wchar_t));
|
||||
if (buf == NULL) {
|
||||
Py_FatalError(
|
||||
"Not enough memory for dynamic PYTHONPATH");
|
||||
}
|
||||
|
||||
/* Run-time value of $PYTHONPATH goes first */
|
||||
if (rtpypath) {
|
||||
wcscpy(buf, rtpypath);
|
||||
wcscat(buf, delimiter);
|
||||
}
|
||||
else
|
||||
buf[0] = '\0';
|
||||
buf[0] = L'\0';
|
||||
|
||||
/* Next is the default zip path */
|
||||
wcscat(buf, zip_path);
|
||||
wcscat(buf, prefix);
|
||||
wcscat(buf, delimiter);
|
||||
|
||||
/* Next goes merge of compile-time $PYTHONPATH with
|
||||
* dynamically located prefix.
|
||||
*/
|
||||
defpath = _pythonpath;
|
||||
while (1) {
|
||||
wchar_t *delim = wcschr(defpath, DELIM);
|
||||
|
||||
if (defpath[0] != SEP) {
|
||||
wcscat(buf, prefix);
|
||||
if (prefixsz >= 2 && prefix[prefixsz - 2] != SEP &&
|
||||
defpath[0] != (delim ? DELIM : L'\0')) { /* not empty */
|
||||
wcscat(buf, separator);
|
||||
}
|
||||
}
|
||||
|
||||
if (delim) {
|
||||
size_t len = delim - defpath + 1;
|
||||
size_t end = wcslen(buf) + len;
|
||||
wcsncat(buf, defpath, len);
|
||||
*(buf + end) = '\0';
|
||||
}
|
||||
else {
|
||||
wcscat(buf, defpath);
|
||||
break;
|
||||
}
|
||||
defpath = delim + 1;
|
||||
}
|
||||
wcscat(buf, package_path);
|
||||
wcscat(buf, delimiter);
|
||||
|
||||
wcscat(buf, ape_lib_path);
|
||||
wcscat(buf, delimiter);
|
||||
|
||||
wcscat(buf, ape_package_path);
|
||||
wcscat(buf, delimiter);
|
||||
|
||||
wcscat(buf, ape_exec_path);
|
||||
wcscat(buf, delimiter);
|
||||
|
||||
wcscat(buf, ape_path);
|
||||
wcscat(buf, delimiter);
|
||||
|
||||
|
||||
/* Finally, on goes the directory for dynamic-load modules */
|
||||
wcscat(buf, exec_prefix);
|
||||
|
||||
/* And publish the results */
|
||||
module_search_path = buf;
|
||||
|
||||
/* Reduce prefix and exec_prefix to their essence,
|
||||
* e.g. /usr/local/lib/python1.5 is reduced to /usr/local.
|
||||
* If we're loading relative to the build directory,
|
||||
* return the compiled-in defaults instead.
|
||||
*/
|
||||
if (pfound > 0) {
|
||||
reduce(prefix);
|
||||
reduce(prefix);
|
||||
/* The prefix is the root directory, but reduce() chopped
|
||||
* off the "/". */
|
||||
if (!prefix[0])
|
||||
wcscpy(prefix, separator);
|
||||
}
|
||||
else
|
||||
wcsncpy(prefix, _prefix, MAXPATHLEN);
|
||||
|
||||
if (efound > 0) {
|
||||
reduce(exec_prefix);
|
||||
reduce(exec_prefix);
|
||||
reduce(exec_prefix);
|
||||
if (!exec_prefix[0])
|
||||
wcscpy(exec_prefix, separator);
|
||||
}
|
||||
else
|
||||
wcsncpy(exec_prefix, _exec_prefix, MAXPATHLEN);
|
||||
|
||||
PyMem_RawFree(_pythonpath);
|
||||
PyMem_RawFree(_prefix);
|
||||
PyMem_RawFree(_exec_prefix);
|
||||
PyMem_RawFree(lib_python);
|
||||
PyMem_RawFree(rtpypath);
|
||||
// printf("%ls\n", buf);
|
||||
}
|
||||
|
||||
|
||||
|
|
2
third_party/python/Modules/main.c
vendored
2
third_party/python/Modules/main.c
vendored
|
@ -621,7 +621,7 @@ Py_Main(int argc, wchar_t **argv)
|
|||
_setmode(fileno(stderr), O_BINARY);
|
||||
#endif
|
||||
|
||||
if (Py_UnbufferedStdioFlag) {
|
||||
if (1 || Py_UnbufferedStdioFlag) {
|
||||
#ifdef HAVE_SETVBUF
|
||||
setvbuf(stdin, (char *)NULL, _IONBF, BUFSIZ);
|
||||
setvbuf(stdout, (char *)NULL, _IONBF, BUFSIZ);
|
||||
|
|
16
third_party/python/Modules/posixmodule.c
vendored
16
third_party/python/Modules/posixmodule.c
vendored
|
@ -3579,7 +3579,7 @@ _posix_listdir(path_t *path, PyObject *list)
|
|||
exit:
|
||||
if (dirp != NULL) {
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
#ifdef HAVE_FDOPENDIR
|
||||
#if 0 && HAVE_FDOPENDIR
|
||||
if (fd > -1)
|
||||
rewinddir(dirp);
|
||||
#endif
|
||||
|
@ -4336,7 +4336,15 @@ os_uname_impl(PyObject *module)
|
|||
PyObject *value;
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
res = uname(&u);
|
||||
if(!IsWindows()) res = uname(&u);
|
||||
else {
|
||||
strcpy(u.sysname, "Linux");
|
||||
strcpy(u.machine, "x86_64");
|
||||
strcpy(u.nodename, "");
|
||||
strcpy(u.release, "");
|
||||
strcpy(u.version, "");
|
||||
res = 0;
|
||||
}
|
||||
Py_END_ALLOW_THREADS
|
||||
if (res < 0)
|
||||
return posix_error();
|
||||
|
@ -5898,7 +5906,7 @@ error:
|
|||
#endif /* defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX) */
|
||||
|
||||
|
||||
#ifdef HAVE_FORKPTY
|
||||
#if HAVE_FORKPTY
|
||||
/*[clinic input]
|
||||
os.forkpty
|
||||
|
||||
|
@ -6665,7 +6673,7 @@ os_setgid_impl(PyObject *module, gid_t gid)
|
|||
#endif /* HAVE_SETGID */
|
||||
|
||||
|
||||
#ifdef HAVE_SETGROUPS
|
||||
#if HAVE_SETGROUPS
|
||||
/*[clinic input]
|
||||
os.setgroups
|
||||
|
||||
|
|
8
third_party/python/Modules/posixmodule.h
vendored
8
third_party/python/Modules/posixmodule.h
vendored
|
@ -19,6 +19,14 @@ PyAPI_FUNC(int) _Py_Gid_Converter(PyObject *, void *);
|
|||
#endif /* MS_WINDOWS */
|
||||
#endif
|
||||
|
||||
#undef HAVE_SETGROUPS
|
||||
#undef HAVE_FORKPTY
|
||||
#undef HAVE_SCHED_SETPARAM
|
||||
#undef HAVE_SCHED_SETSCHEDULER
|
||||
#undef HAVE_FCHMODAT
|
||||
#undef HAVE_LINKAT
|
||||
#undef HAVE_READLINKAT
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
81
third_party/python/Modules/socketmodule.c
vendored
81
third_party/python/Modules/socketmodule.c
vendored
|
@ -512,6 +512,15 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
|
|||
#define INADDR_NONE (-1)
|
||||
#endif
|
||||
|
||||
#ifndef SOMAXCONN
|
||||
#define SOMAXCONN 0x80
|
||||
#endif
|
||||
|
||||
#ifdef IPPROTO_MAX
|
||||
#undef IPPROTO_MAX
|
||||
#define IPPROTO_MAX 255
|
||||
#endif
|
||||
|
||||
/* XXX There's a problem here: *static* functions are not supposed to have
|
||||
a Py prefix (or use CapitalizedWords). Later... */
|
||||
|
||||
|
@ -1568,10 +1577,9 @@ static int
|
|||
getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
||||
struct sockaddr *addr_ret, int *len_ret)
|
||||
{
|
||||
switch (s->sock_family) {
|
||||
|
||||
if(0) {}
|
||||
#if defined(AF_UNIX)
|
||||
case AF_UNIX:
|
||||
else if (s->sock_family == AF_UNIX)
|
||||
{
|
||||
struct sockaddr_un* addr;
|
||||
Py_buffer path;
|
||||
|
@ -1624,7 +1632,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
|||
#endif /* AF_UNIX */
|
||||
|
||||
#if defined(AF_NETLINK)
|
||||
case AF_NETLINK:
|
||||
else if(s->sock_family == AF_NETLINK)
|
||||
{
|
||||
struct sockaddr_nl* addr;
|
||||
int pid, groups;
|
||||
|
@ -1647,12 +1655,13 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
|||
}
|
||||
#endif /* AF_NETLINK */
|
||||
|
||||
else if(
|
||||
#ifdef AF_RDS
|
||||
case AF_RDS:
|
||||
s->sock_family == AF_RDS ||
|
||||
/* RDS sockets use sockaddr_in: fall-through */
|
||||
#endif /* AF_RDS */
|
||||
|
||||
case AF_INET:
|
||||
s->sock_family == AF_INET)
|
||||
{
|
||||
struct sockaddr_in* addr;
|
||||
struct maybe_idna host = {NULL, NULL};
|
||||
|
@ -1687,7 +1696,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
|||
}
|
||||
|
||||
#ifdef ENABLE_IPV6
|
||||
case AF_INET6:
|
||||
else if(s->sock_family == AF_INET6)
|
||||
{
|
||||
struct sockaddr_in6* addr;
|
||||
struct maybe_idna host = {NULL, NULL};
|
||||
|
@ -1735,7 +1744,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
|||
#endif /* ENABLE_IPV6 */
|
||||
|
||||
#ifdef USE_BLUETOOTH
|
||||
case AF_BLUETOOTH:
|
||||
else if(s->sock_family == AF_BLUETOOTH)
|
||||
{
|
||||
switch (s->sock_proto) {
|
||||
case BTPROTO_L2CAP:
|
||||
|
@ -1831,7 +1840,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
|||
#endif /* USE_BLUETOOTH */
|
||||
|
||||
#if defined(HAVE_NETPACKET_PACKET_H) && defined(SIOCGIFINDEX)
|
||||
case AF_PACKET:
|
||||
else (s->sock_family == AF_PACKET)
|
||||
{
|
||||
struct sockaddr_ll* addr;
|
||||
struct ifreq ifr;
|
||||
|
@ -1892,7 +1901,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
|||
#endif /* HAVE_NETPACKET_PACKET_H && SIOCGIFINDEX */
|
||||
|
||||
#ifdef HAVE_LINUX_TIPC_H
|
||||
case AF_TIPC:
|
||||
else if(s->sock_family == AF_TIPC)
|
||||
{
|
||||
unsigned int atype, v1, v2, v3;
|
||||
unsigned int scope = TIPC_CLUSTER_SCOPE;
|
||||
|
@ -1942,7 +1951,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
|||
#endif /* HAVE_LINUX_TIPC_H */
|
||||
|
||||
#if defined(AF_CAN) && defined(CAN_RAW) && defined(CAN_BCM) && defined(SIOCGIFINDEX)
|
||||
case AF_CAN:
|
||||
else if(s->sock_family == AF_CAN){
|
||||
switch (s->sock_proto) {
|
||||
case CAN_RAW:
|
||||
/* fall-through */
|
||||
|
@ -1990,10 +1999,12 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
|||
"getsockaddrarg: unsupported CAN protocol");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif /* AF_CAN && CAN_RAW && CAN_BCM && SIOCGIFINDEX */
|
||||
|
||||
#ifdef PF_SYSTEM
|
||||
case PF_SYSTEM:
|
||||
else if(s->sock_family == PF_SYSTEM)
|
||||
{
|
||||
switch (s->sock_proto) {
|
||||
#ifdef SYSPROTO_CONTROL
|
||||
case SYSPROTO_CONTROL:
|
||||
|
@ -2048,9 +2059,10 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
|||
"getsockaddrarg: unsupported PF_SYSTEM protocol");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif /* PF_SYSTEM */
|
||||
#ifdef HAVE_SOCKADDR_ALG
|
||||
case AF_ALG:
|
||||
else if(s->sock_family == AF_ALG)
|
||||
{
|
||||
struct sockaddr_alg *sa;
|
||||
const char *type;
|
||||
|
@ -2086,10 +2098,10 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
|||
|
||||
/* More cases here... */
|
||||
|
||||
default:
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_OSError, "getsockaddrarg: bad family");
|
||||
return 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2101,10 +2113,9 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
|||
static int
|
||||
getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret)
|
||||
{
|
||||
switch (s->sock_family) {
|
||||
|
||||
if(0) {}
|
||||
#if defined(AF_UNIX)
|
||||
case AF_UNIX:
|
||||
else if(s->sock_family == AF_UNIX)
|
||||
{
|
||||
*len_ret = sizeof (struct sockaddr_un);
|
||||
return 1;
|
||||
|
@ -2112,26 +2123,27 @@ getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret)
|
|||
#endif /* AF_UNIX */
|
||||
|
||||
#if defined(AF_NETLINK)
|
||||
case AF_NETLINK:
|
||||
else if(s->sock_family == AF_NETLINK)
|
||||
{
|
||||
*len_ret = sizeof (struct sockaddr_nl);
|
||||
return 1;
|
||||
}
|
||||
#endif /* AF_NETLINK */
|
||||
|
||||
else if(
|
||||
#ifdef AF_RDS
|
||||
case AF_RDS:
|
||||
s->sock_family == AF_RDS ||
|
||||
/* RDS sockets use sockaddr_in: fall-through */
|
||||
#endif /* AF_RDS */
|
||||
|
||||
case AF_INET:
|
||||
s->sock_family == AF_INET)
|
||||
{
|
||||
*len_ret = sizeof (struct sockaddr_in);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_IPV6
|
||||
case AF_INET6:
|
||||
else if(s->sock_family == AF_INET6)
|
||||
{
|
||||
*len_ret = sizeof (struct sockaddr_in6);
|
||||
return 1;
|
||||
|
@ -2139,7 +2151,7 @@ getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret)
|
|||
#endif /* ENABLE_IPV6 */
|
||||
|
||||
#ifdef USE_BLUETOOTH
|
||||
case AF_BLUETOOTH:
|
||||
else if(s->sock_family == AF_BLUETOOTH)
|
||||
{
|
||||
switch(s->sock_proto)
|
||||
{
|
||||
|
@ -2168,7 +2180,7 @@ getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret)
|
|||
#endif /* USE_BLUETOOTH */
|
||||
|
||||
#ifdef HAVE_NETPACKET_PACKET_H
|
||||
case AF_PACKET:
|
||||
else(s->sock_family == AF_PACKET)
|
||||
{
|
||||
*len_ret = sizeof (struct sockaddr_ll);
|
||||
return 1;
|
||||
|
@ -2176,7 +2188,7 @@ getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret)
|
|||
#endif /* HAVE_NETPACKET_PACKET_H */
|
||||
|
||||
#ifdef HAVE_LINUX_TIPC_H
|
||||
case AF_TIPC:
|
||||
else if (s->sock_family == AF_TIPC)
|
||||
{
|
||||
*len_ret = sizeof (struct sockaddr_tipc);
|
||||
return 1;
|
||||
|
@ -2184,7 +2196,7 @@ getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret)
|
|||
#endif /* HAVE_LINUX_TIPC_H */
|
||||
|
||||
#ifdef AF_CAN
|
||||
case AF_CAN:
|
||||
else if (s->sock_family == AF_CAN)
|
||||
{
|
||||
*len_ret = sizeof (struct sockaddr_can);
|
||||
return 1;
|
||||
|
@ -2192,7 +2204,8 @@ getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret)
|
|||
#endif /* AF_CAN */
|
||||
|
||||
#ifdef PF_SYSTEM
|
||||
case PF_SYSTEM:
|
||||
else if(s->sock_family == PF_SYSTEM)
|
||||
{
|
||||
switch(s->sock_proto) {
|
||||
#ifdef SYSPROTO_CONTROL
|
||||
case SYSPROTO_CONTROL:
|
||||
|
@ -2204,9 +2217,10 @@ getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret)
|
|||
"unknown PF_SYSTEM protocol");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif /* PF_SYSTEM */
|
||||
#ifdef HAVE_SOCKADDR_ALG
|
||||
case AF_ALG:
|
||||
else if(s->sock_family == AF_ALG)
|
||||
{
|
||||
*len_ret = sizeof (struct sockaddr_alg);
|
||||
return 1;
|
||||
|
@ -2215,7 +2229,8 @@ getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret)
|
|||
|
||||
/* More cases here... */
|
||||
|
||||
default:
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_OSError, "getsockaddrlen: bad family");
|
||||
return 0;
|
||||
|
||||
|
@ -2613,12 +2628,18 @@ sock_setsockopt(PySocketSockObject *s, PyObject *args)
|
|||
Py_buffer optval;
|
||||
int flag;
|
||||
unsigned int optlen;
|
||||
int backup_optname;
|
||||
|
||||
PyObject *none;
|
||||
|
||||
backup_optname = SO_REUSEADDR;
|
||||
if(IsWindows() && SO_REUSEADDR != 1)
|
||||
backup_optname = 1;
|
||||
|
||||
/* setsockopt(level, opt, flag) */
|
||||
if (PyArg_ParseTuple(args, "iii:setsockopt",
|
||||
&level, &optname, &flag)) {
|
||||
res = setsockopt(s->sock_fd, level, optname,
|
||||
res = setsockopt(s->sock_fd, level, IsWindows() ? backup_optname : optname,
|
||||
(char*)&flag, sizeof flag);
|
||||
goto done;
|
||||
}
|
||||
|
|
1
third_party/python/Modules/socketmodule.h
vendored
1
third_party/python/Modules/socketmodule.h
vendored
|
@ -276,5 +276,6 @@ typedef struct {
|
|||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* !Py__SOCKET_H */
|
||||
|
|
5
third_party/python/Modules/timemodule.c
vendored
5
third_party/python/Modules/timemodule.c
vendored
|
@ -30,6 +30,9 @@
|
|||
#endif /* MS_WINDOWS */
|
||||
#endif /* !__WATCOMC__ || __QNX__ */
|
||||
|
||||
typedef int clockid_t;
|
||||
#undef HAVE_CLOCK_SETTIME
|
||||
|
||||
/* Forward declarations */
|
||||
static int pysleep(_PyTime_t);
|
||||
static PyObject* floattime(_Py_clock_info_t *info);
|
||||
|
@ -162,7 +165,7 @@ PyDoc_STRVAR(clock_gettime_doc,
|
|||
Return the time of the specified clock clk_id.");
|
||||
#endif /* HAVE_CLOCK_GETTIME */
|
||||
|
||||
#ifdef HAVE_CLOCK_SETTIME
|
||||
#if HAVE_CLOCK_SETTIME
|
||||
static PyObject *
|
||||
time_clock_settime(PyObject *self, PyObject *args)
|
||||
{
|
||||
|
|
4
third_party/python/Modules/zipimport.c
vendored
4
third_party/python/Modules/zipimport.c
vendored
|
@ -1259,7 +1259,9 @@ eq_mtime(time_t t1, time_t t2)
|
|||
if (d < 0)
|
||||
d = -d;
|
||||
/* dostime only stores even seconds, so be lenient */
|
||||
return d <= 1;
|
||||
if(Py_VerboseFlag)
|
||||
PySys_WriteStderr("# mtime diff = %ld (should be <=1)\n", d);
|
||||
return 1 || d <= 1;
|
||||
}
|
||||
|
||||
/* Given the contents of a .pyc file in a buffer, unmarshal the data
|
||||
|
|
2
third_party/python/Modules/zlibmodule.c
vendored
2
third_party/python/Modules/zlibmodule.c
vendored
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include "Python.h"
|
||||
#include "structmember.h"
|
||||
#include "zlib.h"
|
||||
// #include "zlib.h"
|
||||
|
||||
|
||||
#ifdef WITH_THREAD
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue