mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-25 06:42:27 +00:00
Improve Libc by making Python work even better
Actually Portable Python is now outperforming the Python binaries that come bundled with Linux distros, at things like HTTP serving. You can now have a fully featured Python install in just one .com file that runs on six operating systems and is about 10mb in size. With tuning, the tiniest is ~1mb. We've got most of the libraries working, including pysqlite, and the repl now feels very pleasant. The things you can't do quite yet are: threads and shared objects but that can happen in the future, if the community falls in love with this project and wants to see it developed further. Changes: - Add siginterrupt() - Add sqlite3 to Python - Add issymlink() helper - Make GetZipCdir() faster - Add tgamma() and finite() - Add legacy function lutimes() - Add readlink() and realpath() - Use heap allocations when appropriate - Reorganize Python into two-stage build - Save Lua / Python shell history to dotfile - Integrate Python Lib embedding into linkage - Make isregularfile() and isdirectory() go faster - Make Python shell auto-completion work perfectly - Make crash reports work better if changed directory - Fix Python+NT open() / access() flag overflow error - Disable Python tests relating to \N{LONG NAME} syntax - Have Python REPL copyright() show all notice embeddings The biggest technical challenge at the moment is working around when Python tries to be too clever about filenames.
This commit is contained in:
parent
98ccbf44b1
commit
8af197560e
179 changed files with 6728 additions and 10430 deletions
9
third_party/python/Modules/_cursesmodule.c
vendored
9
third_party/python/Modules/_cursesmodule.c
vendored
|
@ -113,15 +113,6 @@ char *PyCursesVersion = "2.2";
|
|||
#define CURSES_MODULE
|
||||
#include "third_party/python/Include/py_curses.h"
|
||||
|
||||
#if defined(HAVE_TERM_H) || defined(__sgi)
|
||||
/* For termname, longname, putp, tigetflag, tigetnum, tigetstr, tparm
|
||||
which are not declared in SysV curses and for setupterm. */
|
||||
#include <term.h>
|
||||
/* Including <term.h> #defines many common symbols. */
|
||||
#undef lines
|
||||
#undef columns
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_NCURSES_H) && (defined(sgi) || defined(__sun) || defined(SCO5))
|
||||
#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
|
||||
typedef chtype attr_t; /* No attr_t type is available */
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h"
|
||||
/* clang-format off */
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
asm(".ident\t\"\\n\
|
||||
libmpdec (BSD-2)\\n\
|
||||
Copyright 2008-2016 Stefan Krah\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
|
|
21
third_party/python/Modules/_posixsubprocess.c
vendored
21
third_party/python/Modules/_posixsubprocess.c
vendored
|
@ -8,6 +8,7 @@
|
|||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/runtime/sysconf.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "third_party/python/Include/abstract.h"
|
||||
#include "third_party/python/Include/codecs.h"
|
||||
|
@ -167,22 +168,8 @@ static long
|
|||
safe_get_max_fd(void)
|
||||
{
|
||||
long local_max_fd;
|
||||
#if defined(__NetBSD__)
|
||||
local_max_fd = fcntl(0, F_MAXFD);
|
||||
if (local_max_fd >= 0)
|
||||
return local_max_fd;
|
||||
#endif
|
||||
#if defined(HAVE_SYS_RESOURCE_H) && defined(__OpenBSD__)
|
||||
struct rlimit rl;
|
||||
/* Not on the POSIX async signal safe functions list but likely
|
||||
* safe. TODO - Someone should audit OpenBSD to make sure. */
|
||||
if (getrlimit(RLIMIT_NOFILE, &rl) >= 0)
|
||||
return (long) rl.rlim_max;
|
||||
#endif
|
||||
#ifdef _SC_OPEN_MAX
|
||||
local_max_fd = sysconf(_SC_OPEN_MAX);
|
||||
if (local_max_fd == -1)
|
||||
#endif
|
||||
local_max_fd = 256; /* Matches legacy Lib/subprocess.py behavior. */
|
||||
return local_max_fd;
|
||||
}
|
||||
|
@ -223,7 +210,7 @@ _close_fds_by_brute_force(long start_fd, PyObject *py_fds_to_keep)
|
|||
}
|
||||
|
||||
|
||||
#if defined(__linux__) && defined(HAVE_SYS_SYSCALL_H)
|
||||
#if 0 && defined(__linux__)
|
||||
/* It doesn't matter if d_name has room for NAME_MAX chars; we're using this
|
||||
* only to read a directory of short file descriptor number names. The kernel
|
||||
* will return an error if we didn't give it enough space. Highly Unlikely.
|
||||
|
@ -293,7 +280,7 @@ _close_open_fds_safe(int start_fd, PyObject* py_fds_to_keep)
|
|||
|
||||
#define _close_open_fds _close_open_fds_safe
|
||||
|
||||
#else /* NOT (defined(__linux__) && defined(HAVE_SYS_SYSCALL_H)) */
|
||||
#else /* NOT defined(__linux__) */
|
||||
|
||||
|
||||
/* Close all open file descriptors from start_fd and higher.
|
||||
|
@ -362,7 +349,7 @@ _close_open_fds_maybe_unsafe(long start_fd, PyObject* py_fds_to_keep)
|
|||
|
||||
#define _close_open_fds _close_open_fds_maybe_unsafe
|
||||
|
||||
#endif /* else NOT (defined(__linux__) && defined(HAVE_SYS_SYSCALL_H)) */
|
||||
#endif /* else NOT defined(__linux__) */
|
||||
|
||||
|
||||
/*
|
||||
|
|
60
third_party/python/Modules/_sqlite/cache.c
vendored
60
third_party/python/Modules/_sqlite/cache.c
vendored
|
@ -1,29 +1,35 @@
|
|||
/* clang-format off */
|
||||
/* cache .c - a LRU cache
|
||||
*
|
||||
* Copyright (C) 2004-2010 Gerhard Häring <gh@ghaering.de>
|
||||
*
|
||||
* This file is part of pysqlite.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ │
|
||||
│ Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de> │
|
||||
│ │
|
||||
│ This file is part of pysqlite. │
|
||||
│ │
|
||||
│ This software is provided 'as-is', without any express or implied │
|
||||
│ warranty. In no event will the authors be held liable for any damages │
|
||||
│ arising from the use of this software. │
|
||||
│ │
|
||||
│ Permission is granted to anyone to use this software for any purpose, │
|
||||
│ including commercial applications, and to alter it and redistribute it │
|
||||
│ freely, subject to the following restrictions: │
|
||||
│ │
|
||||
│ 1. The origin of this software must not be misrepresented; you must not │
|
||||
│ claim that you wrote the original software. If you use this software │
|
||||
│ in a product, an acknowledgment in the product documentation would be │
|
||||
│ appreciated but is not required. │
|
||||
│ 2. Altered source versions must be plainly marked as such, and must not be │
|
||||
│ misrepresented as being the original software. │
|
||||
│ 3. This notice may not be removed or altered from any source distribution. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/python/Modules/_sqlite/cache.h"
|
||||
|
||||
#include "cache.h"
|
||||
#include <limits.h>
|
||||
asm(".ident\t\"\\n\\n\
|
||||
pysqlite (zlib license)\\n\
|
||||
Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de>\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
|
||||
/* only used internally */
|
||||
pysqlite_Node* pysqlite_new_node(PyObject* key, PyObject* data)
|
||||
|
@ -258,7 +264,7 @@ static PyMethodDef cache_methods[] = {
|
|||
|
||||
PyTypeObject pysqlite_NodeType = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
MODULE_NAME "Node", /* tp_name */
|
||||
"sqlite3Node", /* tp_name */
|
||||
sizeof(pysqlite_Node), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
(destructor)pysqlite_node_dealloc, /* tp_dealloc */
|
||||
|
@ -300,7 +306,7 @@ PyTypeObject pysqlite_NodeType = {
|
|||
|
||||
PyTypeObject pysqlite_CacheType = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
MODULE_NAME ".Cache", /* tp_name */
|
||||
"sqlite3.Cache", /* tp_name */
|
||||
sizeof(pysqlite_Cache), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
(destructor)pysqlite_cache_dealloc, /* tp_dealloc */
|
||||
|
|
83
third_party/python/Modules/_sqlite/connection.c
vendored
83
third_party/python/Modules/_sqlite/connection.c
vendored
|
@ -1,46 +1,47 @@
|
|||
/* clang-format off */
|
||||
/* connection.c - the connection type
|
||||
*
|
||||
* Copyright (C) 2004-2010 Gerhard Häring <gh@ghaering.de>
|
||||
*
|
||||
* This file is part of pysqlite.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "third_party/python/Modules/_sqlite/cache.h"
|
||||
#include "third_party/python/Modules/_sqlite/module.h"
|
||||
#include "third_party/python/Include/structmember.h"
|
||||
#include "third_party/python/Modules/_sqlite/connection.h"
|
||||
#include "third_party/python/Modules/_sqlite/statement.h"
|
||||
#include "third_party/python/Modules/_sqlite/cursor.h"
|
||||
#include "third_party/python/Modules/_sqlite/prepare_protocol.h"
|
||||
#include "third_party/python/Modules/_sqlite/util.h"
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ │
|
||||
│ Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de> │
|
||||
│ │
|
||||
│ This file is part of pysqlite. │
|
||||
│ │
|
||||
│ This software is provided 'as-is', without any express or implied │
|
||||
│ warranty. In no event will the authors be held liable for any damages │
|
||||
│ arising from the use of this software. │
|
||||
│ │
|
||||
│ Permission is granted to anyone to use this software for any purpose, │
|
||||
│ including commercial applications, and to alter it and redistribute it │
|
||||
│ freely, subject to the following restrictions: │
|
||||
│ │
|
||||
│ 1. The origin of this software must not be misrepresented; you must not │
|
||||
│ claim that you wrote the original software. If you use this software │
|
||||
│ in a product, an acknowledgment in the product documentation would be │
|
||||
│ appreciated but is not required. │
|
||||
│ 2. Altered source versions must be plainly marked as such, and must not be │
|
||||
│ misrepresented as being the original software. │
|
||||
│ 3. This notice may not be removed or altered from any source distribution. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/python/Include/pythread.h"
|
||||
#include "third_party/python/Include/structmember.h"
|
||||
#include "third_party/python/Modules/_sqlite/cache.h"
|
||||
#include "third_party/python/Modules/_sqlite/connection.h"
|
||||
#include "third_party/python/Modules/_sqlite/cursor.h"
|
||||
#include "third_party/python/Modules/_sqlite/module.h"
|
||||
#include "third_party/python/Modules/_sqlite/prepare_protocol.h"
|
||||
#include "third_party/python/Modules/_sqlite/statement.h"
|
||||
#include "third_party/python/Modules/_sqlite/util.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
pysqlite (zlib license)\\n\
|
||||
Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de>\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
|
||||
#define ACTION_FINALIZE 1
|
||||
#define ACTION_RESET 2
|
||||
|
||||
#if SQLITE_VERSION_NUMBER >= 3003008
|
||||
#ifndef SQLITE_OMIT_LOAD_EXTENSION
|
||||
#define HAVE_LOAD_EXTENSION
|
||||
#endif
|
||||
#endif
|
||||
|
||||
_Py_IDENTIFIER(cursor);
|
||||
|
||||
static const char * const begin_statements[] = {
|
||||
|
@ -1216,7 +1217,7 @@ PyObject* pysqlite_connection_call(pysqlite_Connection* self, PyObject* args, Py
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (!_PyArg_NoKeywords(MODULE_NAME ".Connection()", kwargs))
|
||||
if (!_PyArg_NoKeywords("sqlite3.Connection()", kwargs))
|
||||
return NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O", &sql))
|
||||
|
@ -1447,7 +1448,7 @@ pysqlite_connection_iterdump(pysqlite_Connection* self, PyObject* args)
|
|||
goto finally;
|
||||
}
|
||||
|
||||
module = PyImport_ImportModule(MODULE_NAME ".dump");
|
||||
module = PyImport_ImportModule("sqlite3.dump");
|
||||
if (!module) {
|
||||
goto finally;
|
||||
}
|
||||
|
@ -1675,7 +1676,7 @@ static struct PyMemberDef connection_members[] =
|
|||
|
||||
PyTypeObject pysqlite_ConnectionType = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
MODULE_NAME ".Connection", /* tp_name */
|
||||
"sqlite3.Connection", /* tp_name */
|
||||
sizeof(pysqlite_Connection), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
(destructor)pysqlite_connection_dealloc, /* tp_dealloc */
|
||||
|
|
61
third_party/python/Modules/_sqlite/cursor.c
vendored
61
third_party/python/Modules/_sqlite/cursor.c
vendored
|
@ -1,30 +1,37 @@
|
|||
/* clang-format off */
|
||||
/* cursor.c - the cursor type
|
||||
*
|
||||
* Copyright (C) 2004-2010 Gerhard Häring <gh@ghaering.de>
|
||||
*
|
||||
* This file is part of pysqlite.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ │
|
||||
│ Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de> │
|
||||
│ │
|
||||
│ This file is part of pysqlite. │
|
||||
│ │
|
||||
│ This software is provided 'as-is', without any express or implied │
|
||||
│ warranty. In no event will the authors be held liable for any damages │
|
||||
│ arising from the use of this software. │
|
||||
│ │
|
||||
│ Permission is granted to anyone to use this software for any purpose, │
|
||||
│ including commercial applications, and to alter it and redistribute it │
|
||||
│ freely, subject to the following restrictions: │
|
||||
│ │
|
||||
│ 1. The origin of this software must not be misrepresented; you must not │
|
||||
│ claim that you wrote the original software. If you use this software │
|
||||
│ in a product, an acknowledgment in the product documentation would be │
|
||||
│ appreciated but is not required. │
|
||||
│ 2. Altered source versions must be plainly marked as such, and must not be │
|
||||
│ misrepresented as being the original software. │
|
||||
│ 3. This notice may not be removed or altered from any source distribution. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/python/Modules/_sqlite/cursor.h"
|
||||
#include "third_party/python/Modules/_sqlite/module.h"
|
||||
#include "third_party/python/Modules/_sqlite/util.h"
|
||||
|
||||
#include "cursor.h"
|
||||
#include "module.h"
|
||||
#include "util.h"
|
||||
asm(".ident\t\"\\n\\n\
|
||||
pysqlite (zlib license)\\n\
|
||||
Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de>\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
|
||||
PyObject* pysqlite_cursor_iternext(pysqlite_Cursor* self);
|
||||
|
||||
|
@ -974,7 +981,7 @@ PyDoc_STR("SQLite database cursor class.");
|
|||
|
||||
PyTypeObject pysqlite_CursorType = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
MODULE_NAME ".Cursor", /* tp_name */
|
||||
"sqlite3.Cursor", /* tp_name */
|
||||
sizeof(pysqlite_Cursor), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
(destructor)pysqlite_cursor_dealloc, /* tp_dealloc */
|
||||
|
|
|
@ -1,36 +1,37 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ │
|
||||
│ Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de> │
|
||||
│ │
|
||||
│ This file is part of pysqlite. │
|
||||
│ │
|
||||
│ This software is provided 'as-is', without any express or implied │
|
||||
│ warranty. In no event will the authors be held liable for any damages │
|
||||
│ arising from the use of this software. │
|
||||
│ │
|
||||
│ Permission is granted to anyone to use this software for any purpose, │
|
||||
│ including commercial applications, and to alter it and redistribute it │
|
||||
│ freely, subject to the following restrictions: │
|
||||
│ │
|
||||
│ 1. The origin of this software must not be misrepresented; you must not │
|
||||
│ claim that you wrote the original software. If you use this software │
|
||||
│ in a product, an acknowledgment in the product documentation would be │
|
||||
│ appreciated but is not required. │
|
||||
│ 2. Altered source versions must be plainly marked as such, and must not be │
|
||||
│ misrepresented as being the original software. │
|
||||
│ 3. This notice may not be removed or altered from any source distribution. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/python/Modules/_sqlite/cursor.h"
|
||||
#include "third_party/python/Modules/_sqlite/microprotocols.h"
|
||||
#include "third_party/python/Modules/_sqlite/prepare_protocol.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
pysqlite (zlib license)\\n\
|
||||
Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de>\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
/* microprotocols.c - minimalist and non-validating protocols implementation
|
||||
*
|
||||
* Copyright (C) 2003-2004 Federico Di Gregorio <fog@debian.org>
|
||||
*
|
||||
* This file is part of psycopg and was adapted for pysqlite. Federico Di
|
||||
* Gregorio gave the permission to use it within pysqlite under the following
|
||||
* license:
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#include "cursor.h"
|
||||
#include "microprotocols.h"
|
||||
#include "prepare_protocol.h"
|
||||
|
||||
|
||||
/** the adapters registry **/
|
||||
|
||||
|
|
95
third_party/python/Modules/_sqlite/module.c
vendored
95
third_party/python/Modules/_sqlite/module.c
vendored
|
@ -1,38 +1,45 @@
|
|||
/* clang-format off */
|
||||
/* module.c - the module itself
|
||||
*
|
||||
* Copyright (C) 2004-2010 Gerhard Häring <gh@ghaering.de>
|
||||
*
|
||||
* This file is part of pysqlite.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ │
|
||||
│ Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de> │
|
||||
│ │
|
||||
│ This file is part of pysqlite. │
|
||||
│ │
|
||||
│ This software is provided 'as-is', without any express or implied │
|
||||
│ warranty. In no event will the authors be held liable for any damages │
|
||||
│ arising from the use of this software. │
|
||||
│ │
|
||||
│ Permission is granted to anyone to use this software for any purpose, │
|
||||
│ including commercial applications, and to alter it and redistribute it │
|
||||
│ freely, subject to the following restrictions: │
|
||||
│ │
|
||||
│ 1. The origin of this software must not be misrepresented; you must not │
|
||||
│ claim that you wrote the original software. If you use this software │
|
||||
│ in a product, an acknowledgment in the product documentation would be │
|
||||
│ appreciated but is not required. │
|
||||
│ 2. Altered source versions must be plainly marked as such, and must not be │
|
||||
│ misrepresented as being the original software. │
|
||||
│ 3. This notice may not be removed or altered from any source distribution. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/python/Modules/_sqlite/cache.h"
|
||||
#include "third_party/python/Modules/_sqlite/connection.h"
|
||||
#include "statement.h"
|
||||
#include "cursor.h"
|
||||
#include "cache.h"
|
||||
#include "prepare_protocol.h"
|
||||
#include "microprotocols.h"
|
||||
#include "row.h"
|
||||
#include "third_party/python/Modules/_sqlite/cursor.h"
|
||||
#include "third_party/python/Modules/_sqlite/microprotocols.h"
|
||||
#include "third_party/python/Modules/_sqlite/prepare_protocol.h"
|
||||
#include "third_party/python/Modules/_sqlite/row.h"
|
||||
#include "third_party/python/Modules/_sqlite/statement.h"
|
||||
|
||||
#if SQLITE_VERSION_NUMBER >= 3003003
|
||||
#define HAVE_SHARED_CACHE
|
||||
#endif
|
||||
asm(".ident\t\"\\n\\n\
|
||||
pysqlite (zlib license)\\n\
|
||||
Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de>\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
|
||||
/* #if SQLITE_VERSION_NUMBER >= 3003003 */
|
||||
/* #define HAVE_SHARED_CACHE */
|
||||
/* #endif */
|
||||
|
||||
/* static objects at module-level */
|
||||
|
||||
|
@ -359,56 +366,56 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
|
|||
|
||||
/*** Create DB-API Exception hierarchy */
|
||||
|
||||
if (!(pysqlite_Error = PyErr_NewException(MODULE_NAME ".Error", PyExc_Exception, NULL))) {
|
||||
if (!(pysqlite_Error = PyErr_NewException("sqlite3.Error", PyExc_Exception, NULL))) {
|
||||
goto error;
|
||||
}
|
||||
PyDict_SetItemString(dict, "Error", pysqlite_Error);
|
||||
|
||||
if (!(pysqlite_Warning = PyErr_NewException(MODULE_NAME ".Warning", PyExc_Exception, NULL))) {
|
||||
if (!(pysqlite_Warning = PyErr_NewException("sqlite3.Warning", PyExc_Exception, NULL))) {
|
||||
goto error;
|
||||
}
|
||||
PyDict_SetItemString(dict, "Warning", pysqlite_Warning);
|
||||
|
||||
/* Error subclasses */
|
||||
|
||||
if (!(pysqlite_InterfaceError = PyErr_NewException(MODULE_NAME ".InterfaceError", pysqlite_Error, NULL))) {
|
||||
if (!(pysqlite_InterfaceError = PyErr_NewException("sqlite3.InterfaceError", pysqlite_Error, NULL))) {
|
||||
goto error;
|
||||
}
|
||||
PyDict_SetItemString(dict, "InterfaceError", pysqlite_InterfaceError);
|
||||
|
||||
if (!(pysqlite_DatabaseError = PyErr_NewException(MODULE_NAME ".DatabaseError", pysqlite_Error, NULL))) {
|
||||
if (!(pysqlite_DatabaseError = PyErr_NewException("sqlite3.DatabaseError", pysqlite_Error, NULL))) {
|
||||
goto error;
|
||||
}
|
||||
PyDict_SetItemString(dict, "DatabaseError", pysqlite_DatabaseError);
|
||||
|
||||
/* pysqlite_DatabaseError subclasses */
|
||||
|
||||
if (!(pysqlite_InternalError = PyErr_NewException(MODULE_NAME ".InternalError", pysqlite_DatabaseError, NULL))) {
|
||||
if (!(pysqlite_InternalError = PyErr_NewException("sqlite3.InternalError", pysqlite_DatabaseError, NULL))) {
|
||||
goto error;
|
||||
}
|
||||
PyDict_SetItemString(dict, "InternalError", pysqlite_InternalError);
|
||||
|
||||
if (!(pysqlite_OperationalError = PyErr_NewException(MODULE_NAME ".OperationalError", pysqlite_DatabaseError, NULL))) {
|
||||
if (!(pysqlite_OperationalError = PyErr_NewException("sqlite3.OperationalError", pysqlite_DatabaseError, NULL))) {
|
||||
goto error;
|
||||
}
|
||||
PyDict_SetItemString(dict, "OperationalError", pysqlite_OperationalError);
|
||||
|
||||
if (!(pysqlite_ProgrammingError = PyErr_NewException(MODULE_NAME ".ProgrammingError", pysqlite_DatabaseError, NULL))) {
|
||||
if (!(pysqlite_ProgrammingError = PyErr_NewException("sqlite3.ProgrammingError", pysqlite_DatabaseError, NULL))) {
|
||||
goto error;
|
||||
}
|
||||
PyDict_SetItemString(dict, "ProgrammingError", pysqlite_ProgrammingError);
|
||||
|
||||
if (!(pysqlite_IntegrityError = PyErr_NewException(MODULE_NAME ".IntegrityError", pysqlite_DatabaseError,NULL))) {
|
||||
if (!(pysqlite_IntegrityError = PyErr_NewException("sqlite3.IntegrityError", pysqlite_DatabaseError,NULL))) {
|
||||
goto error;
|
||||
}
|
||||
PyDict_SetItemString(dict, "IntegrityError", pysqlite_IntegrityError);
|
||||
|
||||
if (!(pysqlite_DataError = PyErr_NewException(MODULE_NAME ".DataError", pysqlite_DatabaseError, NULL))) {
|
||||
if (!(pysqlite_DataError = PyErr_NewException("sqlite3.DataError", pysqlite_DatabaseError, NULL))) {
|
||||
goto error;
|
||||
}
|
||||
PyDict_SetItemString(dict, "DataError", pysqlite_DataError);
|
||||
|
||||
if (!(pysqlite_NotSupportedError = PyErr_NewException(MODULE_NAME ".NotSupportedError", pysqlite_DatabaseError, NULL))) {
|
||||
if (!(pysqlite_NotSupportedError = PyErr_NewException("sqlite3.NotSupportedError", pysqlite_DatabaseError, NULL))) {
|
||||
goto error;
|
||||
}
|
||||
PyDict_SetItemString(dict, "NotSupportedError", pysqlite_NotSupportedError);
|
||||
|
@ -473,7 +480,7 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
|
|||
error:
|
||||
if (PyErr_Occurred())
|
||||
{
|
||||
PyErr_SetString(PyExc_ImportError, MODULE_NAME ": init failed");
|
||||
PyErr_SetString(PyExc_ImportError, "sqlite3: init failed");
|
||||
Py_DECREF(module);
|
||||
module = NULL;
|
||||
}
|
||||
|
|
|
@ -1,28 +1,35 @@
|
|||
/* clang-format off */
|
||||
/* prepare_protocol.c - the protocol for preparing values for SQLite
|
||||
*
|
||||
* Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de>
|
||||
*
|
||||
* This file is part of pysqlite.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ │
|
||||
│ Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de> │
|
||||
│ │
|
||||
│ This file is part of pysqlite. │
|
||||
│ │
|
||||
│ This software is provided 'as-is', without any express or implied │
|
||||
│ warranty. In no event will the authors be held liable for any damages │
|
||||
│ arising from the use of this software. │
|
||||
│ │
|
||||
│ Permission is granted to anyone to use this software for any purpose, │
|
||||
│ including commercial applications, and to alter it and redistribute it │
|
||||
│ freely, subject to the following restrictions: │
|
||||
│ │
|
||||
│ 1. The origin of this software must not be misrepresented; you must not │
|
||||
│ claim that you wrote the original software. If you use this software │
|
||||
│ in a product, an acknowledgment in the product documentation would be │
|
||||
│ appreciated but is not required. │
|
||||
│ 2. Altered source versions must be plainly marked as such, and must not be │
|
||||
│ misrepresented as being the original software. │
|
||||
│ 3. This notice may not be removed or altered from any source distribution. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/python/Modules/_sqlite/prepare_protocol.h"
|
||||
|
||||
#include "prepare_protocol.h"
|
||||
asm(".ident\t\"\\n\\n\
|
||||
pysqlite (zlib license)\\n\
|
||||
Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de>\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
|
||||
int pysqlite_prepare_protocol_init(pysqlite_PrepareProtocol* self, PyObject* args, PyObject* kwargs)
|
||||
{
|
||||
|
@ -36,7 +43,7 @@ void pysqlite_prepare_protocol_dealloc(pysqlite_PrepareProtocol* self)
|
|||
|
||||
PyTypeObject pysqlite_PrepareProtocolType= {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
MODULE_NAME ".PrepareProtocol", /* tp_name */
|
||||
"sqlite3.PrepareProtocol", /* tp_name */
|
||||
sizeof(pysqlite_PrepareProtocol), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
(destructor)pysqlite_prepare_protocol_dealloc, /* tp_dealloc */
|
||||
|
|
59
third_party/python/Modules/_sqlite/row.c
vendored
59
third_party/python/Modules/_sqlite/row.c
vendored
|
@ -1,29 +1,36 @@
|
|||
/* clang-format off */
|
||||
/* row.c - an enhanced tuple for database rows
|
||||
*
|
||||
* Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de>
|
||||
*
|
||||
* This file is part of pysqlite.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "third_party/python/Modules/_sqlite/row.h"
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ │
|
||||
│ Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de> │
|
||||
│ │
|
||||
│ This file is part of pysqlite. │
|
||||
│ │
|
||||
│ This software is provided 'as-is', without any express or implied │
|
||||
│ warranty. In no event will the authors be held liable for any damages │
|
||||
│ arising from the use of this software. │
|
||||
│ │
|
||||
│ Permission is granted to anyone to use this software for any purpose, │
|
||||
│ including commercial applications, and to alter it and redistribute it │
|
||||
│ freely, subject to the following restrictions: │
|
||||
│ │
|
||||
│ 1. The origin of this software must not be misrepresented; you must not │
|
||||
│ claim that you wrote the original software. If you use this software │
|
||||
│ in a product, an acknowledgment in the product documentation would be │
|
||||
│ appreciated but is not required. │
|
||||
│ 2. Altered source versions must be plainly marked as such, and must not be │
|
||||
│ misrepresented as being the original software. │
|
||||
│ 3. This notice may not be removed or altered from any source distribution. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/python/Modules/_sqlite/cursor.h"
|
||||
#include "third_party/python/Modules/_sqlite/row.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
pysqlite (zlib license)\\n\
|
||||
Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de>\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
|
||||
void pysqlite_row_dealloc(pysqlite_Row* self)
|
||||
{
|
||||
|
@ -233,7 +240,7 @@ static PyMethodDef pysqlite_row_methods[] = {
|
|||
|
||||
PyTypeObject pysqlite_RowType = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
MODULE_NAME ".Row", /* tp_name */
|
||||
"sqlite3.Row", /* tp_name */
|
||||
sizeof(pysqlite_Row), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
(destructor)pysqlite_row_dealloc, /* tp_dealloc */
|
||||
|
|
61
third_party/python/Modules/_sqlite/statement.c
vendored
61
third_party/python/Modules/_sqlite/statement.c
vendored
|
@ -1,34 +1,41 @@
|
|||
/* clang-format off */
|
||||
/* statement.c - the statement type
|
||||
*
|
||||
* Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de>
|
||||
*
|
||||
* This file is part of pysqlite.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "third_party/python/Modules/_sqlite/statement.h"
|
||||
#include "third_party/python/Modules/_sqlite/cursor.h"
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ │
|
||||
│ Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de> │
|
||||
│ │
|
||||
│ This file is part of pysqlite. │
|
||||
│ │
|
||||
│ This software is provided 'as-is', without any express or implied │
|
||||
│ warranty. In no event will the authors be held liable for any damages │
|
||||
│ arising from the use of this software. │
|
||||
│ │
|
||||
│ Permission is granted to anyone to use this software for any purpose, │
|
||||
│ including commercial applications, and to alter it and redistribute it │
|
||||
│ freely, subject to the following restrictions: │
|
||||
│ │
|
||||
│ 1. The origin of this software must not be misrepresented; you must not │
|
||||
│ claim that you wrote the original software. If you use this software │
|
||||
│ in a product, an acknowledgment in the product documentation would be │
|
||||
│ appreciated but is not required. │
|
||||
│ 2. Altered source versions must be plainly marked as such, and must not be │
|
||||
│ misrepresented as being the original software. │
|
||||
│ 3. This notice may not be removed or altered from any source distribution. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/python/Modules/_sqlite/connection.h"
|
||||
#include "third_party/python/Modules/_sqlite/cursor.h"
|
||||
#include "third_party/python/Modules/_sqlite/microprotocols.h"
|
||||
#include "third_party/python/Modules/_sqlite/prepare_protocol.h"
|
||||
#include "third_party/python/Modules/_sqlite/statement.h"
|
||||
#include "third_party/python/Modules/_sqlite/util.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
pysqlite (zlib license)\\n\
|
||||
Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de>\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
|
||||
/* prototypes */
|
||||
static int pysqlite_check_remaining_sql(const char* tail);
|
||||
|
||||
|
@ -498,7 +505,7 @@ static int pysqlite_check_remaining_sql(const char* tail)
|
|||
|
||||
PyTypeObject pysqlite_StatementType = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
MODULE_NAME ".Statement", /* tp_name */
|
||||
"sqlite3.Statement", /* tp_name */
|
||||
sizeof(pysqlite_Statement), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
(destructor)pysqlite_statement_dealloc, /* tp_dealloc */
|
||||
|
|
57
third_party/python/Modules/_sqlite/util.c
vendored
57
third_party/python/Modules/_sqlite/util.c
vendored
|
@ -1,29 +1,36 @@
|
|||
/* clang-format off */
|
||||
/* util.c - various utility functions
|
||||
*
|
||||
* Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de>
|
||||
*
|
||||
* This file is part of pysqlite.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ │
|
||||
│ Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de> │
|
||||
│ │
|
||||
│ This file is part of pysqlite. │
|
||||
│ │
|
||||
│ This software is provided 'as-is', without any express or implied │
|
||||
│ warranty. In no event will the authors be held liable for any damages │
|
||||
│ arising from the use of this software. │
|
||||
│ │
|
||||
│ Permission is granted to anyone to use this software for any purpose, │
|
||||
│ including commercial applications, and to alter it and redistribute it │
|
||||
│ freely, subject to the following restrictions: │
|
||||
│ │
|
||||
│ 1. The origin of this software must not be misrepresented; you must not │
|
||||
│ claim that you wrote the original software. If you use this software │
|
||||
│ in a product, an acknowledgment in the product documentation would be │
|
||||
│ appreciated but is not required. │
|
||||
│ 2. Altered source versions must be plainly marked as such, and must not be │
|
||||
│ misrepresented as being the original software. │
|
||||
│ 3. This notice may not be removed or altered from any source distribution. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/python/Modules/_sqlite/connection.h"
|
||||
#include "third_party/python/Modules/_sqlite/module.h"
|
||||
|
||||
#include "module.h"
|
||||
#include "connection.h"
|
||||
asm(".ident\t\"\\n\\n\
|
||||
pysqlite (zlib license)\\n\
|
||||
Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de>\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
|
||||
int pysqlite_step(sqlite3_stmt* statement, pysqlite_Connection* connection)
|
||||
{
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
/*[clinic input]
|
||||
preserve
|
||||
[clinic start generated code]*/
|
||||
#include "third_party/python/pyconfig.h"
|
||||
|
||||
PyDoc_STRVAR(os_stat__doc__,
|
||||
"stat($module, /, path, *, dir_fd=None, follow_symlinks=True)\n"
|
||||
|
@ -138,7 +139,7 @@ os_access(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames
|
|||
{
|
||||
PyObject *return_value = NULL;
|
||||
static const char * const _keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL};
|
||||
static _PyArg_Parser _parser = {"O&i|$O&pp:access", _keywords, 0};
|
||||
static _PyArg_Parser _parser = {"O&I|$O&pp:access", _keywords, 0};
|
||||
path_t path = PATH_T_INITIALIZE("access", "path", 0, 0);
|
||||
int mode;
|
||||
int dir_fd = DEFAULT_DIR_FD;
|
||||
|
@ -1862,7 +1863,7 @@ os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
|
|||
|
||||
#endif /* defined(HAVE_FORK) */
|
||||
|
||||
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
|
||||
#if defined(HAVE_SCHED_GET_PRIORITY_MAX)
|
||||
|
||||
PyDoc_STRVAR(os_sched_get_priority_max__doc__,
|
||||
"sched_get_priority_max($module, /, policy)\n"
|
||||
|
@ -1894,9 +1895,9 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
|
||||
#endif /* defined(HAVE_SCHED_GET_PRIORITY_MAX) */
|
||||
|
||||
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
|
||||
#if defined(HAVE_SCHED_GET_PRIORITY_MAX)
|
||||
|
||||
PyDoc_STRVAR(os_sched_get_priority_min__doc__,
|
||||
"sched_get_priority_min($module, /, policy)\n"
|
||||
|
@ -1928,9 +1929,9 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
|
||||
#endif /* defined(HAVE_SCHED_GET_PRIORITY_MAX) */
|
||||
|
||||
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
|
||||
#if defined(HAVE_SCHED_SETSCHEDULER)
|
||||
|
||||
PyDoc_STRVAR(os_sched_getscheduler__doc__,
|
||||
"sched_getscheduler($module, pid, /)\n"
|
||||
|
@ -1961,9 +1962,9 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
|
||||
#endif /* defined(HAVE_SCHED_SETSCHEDULER) */
|
||||
|
||||
#if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM))
|
||||
#if (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM))
|
||||
|
||||
PyDoc_STRVAR(os_sched_param__doc__,
|
||||
"sched_param(sched_priority)\n"
|
||||
|
@ -1995,9 +1996,9 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
#endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)) */
|
||||
#endif /* (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)) */
|
||||
|
||||
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
|
||||
#if defined(HAVE_SCHED_SETSCHEDULER)
|
||||
|
||||
PyDoc_STRVAR(os_sched_setscheduler__doc__,
|
||||
"sched_setscheduler($module, pid, policy, param, /)\n"
|
||||
|
@ -2033,9 +2034,9 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
|
||||
#endif /* defined(HAVE_SCHED_SETSCHEDULER) */
|
||||
|
||||
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
|
||||
#if defined(HAVE_SCHED_SETPARAM)
|
||||
|
||||
PyDoc_STRVAR(os_sched_getparam__doc__,
|
||||
"sched_getparam($module, pid, /)\n"
|
||||
|
@ -2067,9 +2068,9 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
|
||||
#endif /* defined(HAVE_SCHED_SETPARAM) */
|
||||
|
||||
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
|
||||
#if defined(HAVE_SCHED_SETPARAM)
|
||||
|
||||
PyDoc_STRVAR(os_sched_setparam__doc__,
|
||||
"sched_setparam($module, pid, param, /)\n"
|
||||
|
@ -2104,9 +2105,9 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
|
||||
#endif /* defined(HAVE_SCHED_SETPARAM) */
|
||||
|
||||
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
|
||||
#if defined(HAVE_SCHED_RR_GET_INTERVAL)
|
||||
|
||||
PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
|
||||
"sched_rr_get_interval($module, pid, /)\n"
|
||||
|
@ -2142,9 +2143,7 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
|
||||
|
||||
#if defined(HAVE_SCHED_H)
|
||||
#endif /* defined(HAVE_SCHED_RR_GET_INTERVAL) */
|
||||
|
||||
PyDoc_STRVAR(os_sched_yield__doc__,
|
||||
"sched_yield($module, /)\n"
|
||||
|
@ -2164,9 +2163,7 @@ os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
|
|||
return os_sched_yield_impl(module);
|
||||
}
|
||||
|
||||
#endif /* defined(HAVE_SCHED_H) */
|
||||
|
||||
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
|
||||
#if defined(HAVE_SCHED_SETAFFINITY)
|
||||
|
||||
PyDoc_STRVAR(os_sched_setaffinity__doc__,
|
||||
"sched_setaffinity($module, pid, mask, /)\n"
|
||||
|
@ -2199,9 +2196,9 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
|
||||
#endif /* defined(HAVE_SCHED_SETAFFINITY) */
|
||||
|
||||
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
|
||||
#if defined(HAVE_SCHED_SETAFFINITY)
|
||||
|
||||
PyDoc_STRVAR(os_sched_getaffinity__doc__,
|
||||
"sched_getaffinity($module, pid, /)\n"
|
||||
|
@ -2232,7 +2229,7 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
|
||||
#endif /* defined(HAVE_SCHED_SETAFFINITY) */
|
||||
|
||||
#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
|
||||
|
||||
|
@ -3315,9 +3312,9 @@ os_open(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
|
|||
{
|
||||
PyObject *return_value = NULL;
|
||||
static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
|
||||
static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0};
|
||||
static _PyArg_Parser _parser = {"O&I|i$O&:open", _keywords, 0};
|
||||
path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
|
||||
int flags;
|
||||
unsigned flags;
|
||||
int mode = 511;
|
||||
int dir_fd = DEFAULT_DIR_FD;
|
||||
int _return_value;
|
||||
|
@ -4406,7 +4403,7 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
|
||||
#if defined(WCOREDUMP)
|
||||
|
||||
PyDoc_STRVAR(os_WCOREDUMP__doc__,
|
||||
"WCOREDUMP($module, status, /)\n"
|
||||
|
@ -4440,9 +4437,9 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
|
||||
#endif /* defined(WCOREDUMP) */
|
||||
|
||||
#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
|
||||
#if defined(WIFCONTINUED)
|
||||
|
||||
PyDoc_STRVAR(os_WIFCONTINUED__doc__,
|
||||
"WIFCONTINUED($module, /, status)\n"
|
||||
|
@ -4482,9 +4479,9 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
|
||||
#endif /* defined(WIFCONTINUED) */
|
||||
|
||||
#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
|
||||
#if defined(WIFSTOPPED)
|
||||
|
||||
PyDoc_STRVAR(os_WIFSTOPPED__doc__,
|
||||
"WIFSTOPPED($module, /, status)\n"
|
||||
|
@ -4521,9 +4518,9 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
|
||||
#endif /* defined(WIFSTOPPED) */
|
||||
|
||||
#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
|
||||
#if defined(WIFSIGNALED)
|
||||
|
||||
PyDoc_STRVAR(os_WIFSIGNALED__doc__,
|
||||
"WIFSIGNALED($module, /, status)\n"
|
||||
|
@ -4560,9 +4557,9 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
|
||||
#endif /* defined(WIFSIGNALED) */
|
||||
|
||||
#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
|
||||
#if defined(WIFEXITED)
|
||||
|
||||
PyDoc_STRVAR(os_WIFEXITED__doc__,
|
||||
"WIFEXITED($module, /, status)\n"
|
||||
|
@ -4599,9 +4596,9 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
|
||||
#endif /* defined(WIFEXITED) */
|
||||
|
||||
#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
|
||||
#if defined(WEXITSTATUS)
|
||||
|
||||
PyDoc_STRVAR(os_WEXITSTATUS__doc__,
|
||||
"WEXITSTATUS($module, /, status)\n"
|
||||
|
@ -4638,9 +4635,9 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
|
||||
#endif /* defined(WEXITSTATUS) */
|
||||
|
||||
#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
|
||||
#if defined(WTERMSIG)
|
||||
|
||||
PyDoc_STRVAR(os_WTERMSIG__doc__,
|
||||
"WTERMSIG($module, /, status)\n"
|
||||
|
@ -4677,9 +4674,9 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
|
||||
#endif /* defined(WTERMSIG) */
|
||||
|
||||
#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
|
||||
#if defined(WSTOPSIG)
|
||||
|
||||
PyDoc_STRVAR(os_WSTOPSIG__doc__,
|
||||
"WSTOPSIG($module, /, status)\n"
|
||||
|
@ -4716,9 +4713,9 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
|
||||
#endif /* defined(WSTOPSIG) */
|
||||
|
||||
#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
|
||||
#if (defined(HAVE_FSTATVFS))
|
||||
|
||||
PyDoc_STRVAR(os_fstatvfs__doc__,
|
||||
"fstatvfs($module, fd, /)\n"
|
||||
|
@ -4749,9 +4746,9 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
|
||||
#endif /* (defined(HAVE_FSTATVFS)) */
|
||||
|
||||
#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
|
||||
#if (defined(HAVE_STATVFS))
|
||||
|
||||
PyDoc_STRVAR(os_statvfs__doc__,
|
||||
"statvfs($module, /, path)\n"
|
||||
|
@ -4790,7 +4787,7 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
|
||||
#endif /* (defined(HAVE_STATVFS)) */
|
||||
|
||||
#if defined(MS_WINDOWS)
|
||||
|
||||
|
|
161
third_party/python/Modules/config.c
vendored
161
third_party/python/Modules/config.c
vendored
|
@ -24,87 +24,89 @@ redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
|||
/* This file contains the table of built-in modules.
|
||||
See create_builtin() in import.c. */
|
||||
|
||||
#include "third_party/python/Include/pyport.h"
|
||||
#include "third_party/python/Include/pyport.h"
|
||||
#include "third_party/python/Include/Python.h"
|
||||
|
||||
extern PyObject* PyInit__decimal(void);
|
||||
extern PyObject* PyInit_audioop(void);
|
||||
extern PyObject* PyInit_posix(void);
|
||||
extern PyObject* PyInit_errno(void);
|
||||
extern PyObject* PyInit_pwd(void);
|
||||
extern PyObject* PyInit__sre(void);
|
||||
extern PyObject* PyInit__codecs(void);
|
||||
extern PyObject* PyInit__functools(void);
|
||||
extern PyObject* PyInit__operator(void);
|
||||
extern PyObject* PyInit__collections(void);
|
||||
extern PyObject* PyInit_itertools(void);
|
||||
extern PyObject* PyInit_atexit(void);
|
||||
extern PyObject* PyInit__signal(void);
|
||||
extern PyObject* PyInit__stat(void);
|
||||
extern PyObject* PyInit_time(void);
|
||||
extern PyObject* PyInit__locale(void);
|
||||
extern PyObject* PyInit__io(void);
|
||||
extern PyObject* PyInit_zipimport(void);
|
||||
extern PyObject* PyInit_faulthandler(void);
|
||||
extern PyObject* PyInit__tracemalloc(void);
|
||||
extern PyObject* PyInit__symtable(void);
|
||||
extern PyObject* PyInit_array(void);
|
||||
extern PyObject* PyInit_cmath(void);
|
||||
extern PyObject* PyInit_math(void);
|
||||
extern PyObject* PyInit__struct(void);
|
||||
extern PyObject* PyInit__weakref(void);
|
||||
extern PyObject* PyInit__testcapi(void);
|
||||
extern PyObject* PyInit__random(void);
|
||||
extern PyObject* PyInit__elementtree(void);
|
||||
extern PyObject* PyInit__pickle(void);
|
||||
extern PyObject* PyInit__datetime(void);
|
||||
extern PyObject* PyInit__bisect(void);
|
||||
extern PyObject* PyInit__heapq(void);
|
||||
extern PyObject* PyInit_unicodedata(void);
|
||||
extern PyObject* PyInit_fcntl(void);
|
||||
extern PyObject* PyInit_grp(void);
|
||||
extern PyObject* PyInit_select(void);
|
||||
extern PyObject* PyInit_mmap(void);
|
||||
extern PyObject* PyInit__csv(void);
|
||||
extern PyObject* PyInit__socket(void);
|
||||
extern PyObject* PyInit_resource(void);
|
||||
extern PyObject* PyInit__posixsubprocess(void);
|
||||
extern PyObject* PyInit__md5(void);
|
||||
extern PyObject* PyInit__sha1(void);
|
||||
extern PyObject* PyInit__sha256(void);
|
||||
extern PyObject* PyInit__sha512(void);
|
||||
extern PyObject* PyInit__sha3(void);
|
||||
extern PyObject* PyInit_syslog(void);
|
||||
extern PyObject* PyInit_binascii(void);
|
||||
extern PyObject* PyInit_parser(void);
|
||||
extern PyObject* PyInit_fpectl(void);
|
||||
extern PyObject* PyInit_zlib(void);
|
||||
extern PyObject* PyInit_pyexpat(void);
|
||||
extern PyObject* PyInit__multibytecodec(void);
|
||||
extern PyObject* PyInit__codecs_cn(void);
|
||||
extern PyObject* PyInit__codecs_hk(void);
|
||||
extern PyObject* PyInit__codecs_iso2022(void);
|
||||
extern PyObject* PyInit__codecs_jp(void);
|
||||
extern PyObject* PyInit__codecs_kr(void);
|
||||
extern PyObject* PyInit__codecs_tw(void);
|
||||
extern PyObject* PyInit__json(void);
|
||||
extern PyObject* PyInit__lsprof(void);
|
||||
extern PyObject* PyInit__opcode(void);
|
||||
extern PyObject* PyInit_termios(void);
|
||||
PyObject* PyInit__decimal(void);
|
||||
PyObject* PyInit_audioop(void);
|
||||
PyObject* PyInit_posix(void);
|
||||
PyObject* PyInit_errno(void);
|
||||
PyObject* PyInit_pwd(void);
|
||||
PyObject* PyInit__sre(void);
|
||||
PyObject* PyInit__codecs(void);
|
||||
PyObject* PyInit__functools(void);
|
||||
PyObject* PyInit__operator(void);
|
||||
PyObject* PyInit__collections(void);
|
||||
PyObject* PyInit_itertools(void);
|
||||
PyObject* PyInit_atexit(void);
|
||||
PyObject* PyInit__signal(void);
|
||||
PyObject* PyInit__stat(void);
|
||||
PyObject* PyInit_time(void);
|
||||
PyObject* PyInit__locale(void);
|
||||
PyObject* PyInit__io(void);
|
||||
PyObject* PyInit_zipimport(void);
|
||||
PyObject* PyInit_faulthandler(void);
|
||||
PyObject* PyInit__tracemalloc(void);
|
||||
PyObject* PyInit__symtable(void);
|
||||
PyObject* PyInit_array(void);
|
||||
PyObject* PyInit_cmath(void);
|
||||
PyObject* PyInit_math(void);
|
||||
PyObject* PyInit__struct(void);
|
||||
PyObject* PyInit__weakref(void);
|
||||
PyObject* PyInit__testcapi(void);
|
||||
PyObject* PyInit__random(void);
|
||||
PyObject* PyInit__elementtree(void);
|
||||
PyObject* PyInit__pickle(void);
|
||||
PyObject* PyInit__datetime(void);
|
||||
PyObject* PyInit__bisect(void);
|
||||
PyObject* PyInit__heapq(void);
|
||||
PyObject* PyInit_unicodedata(void);
|
||||
PyObject* PyInit_fcntl(void);
|
||||
PyObject* PyInit_grp(void);
|
||||
PyObject* PyInit_select(void);
|
||||
PyObject* PyInit_mmap(void);
|
||||
PyObject* PyInit__csv(void);
|
||||
PyObject* PyInit__socket(void);
|
||||
PyObject* PyInit_resource(void);
|
||||
PyObject* PyInit__posixsubprocess(void);
|
||||
PyObject* PyInit__md5(void);
|
||||
PyObject* PyInit__sha1(void);
|
||||
PyObject* PyInit__sha256(void);
|
||||
PyObject* PyInit__sha512(void);
|
||||
PyObject* PyInit__sha3(void);
|
||||
PyObject* PyInit_syslog(void);
|
||||
PyObject* PyInit_binascii(void);
|
||||
PyObject* PyInit_parser(void);
|
||||
PyObject* PyInit_fpectl(void);
|
||||
PyObject* PyInit_zlib(void);
|
||||
PyObject* PyInit_pyexpat(void);
|
||||
PyObject* PyInit__multibytecodec(void);
|
||||
PyObject* PyInit__codecs_cn(void);
|
||||
PyObject* PyInit__codecs_hk(void);
|
||||
PyObject* PyInit__codecs_iso2022(void);
|
||||
PyObject* PyInit__codecs_jp(void);
|
||||
PyObject* PyInit__codecs_kr(void);
|
||||
PyObject* PyInit__codecs_tw(void);
|
||||
PyObject* PyInit__json(void);
|
||||
PyObject* PyInit__lsprof(void);
|
||||
PyObject* PyInit__opcode(void);
|
||||
PyObject* PyInit_termios(void);
|
||||
PyObject *PyInit__sqlite3(void);
|
||||
|
||||
/* -- ADDMODULE MARKER 1 -- */
|
||||
|
||||
extern PyObject* PyMarshal_Init(void);
|
||||
extern PyObject* PyInit_imp(void);
|
||||
extern PyObject* PyInit_gc(void);
|
||||
extern PyObject* PyInit__ast(void);
|
||||
extern PyObject* _PyWarnings_Init(void);
|
||||
extern PyObject* PyInit__string(void);
|
||||
PyObject* PyMarshal_Init(void);
|
||||
PyObject* PyInit_imp(void);
|
||||
PyObject* PyInit_gc(void);
|
||||
PyObject* PyInit__ast(void);
|
||||
PyObject* _PyWarnings_Init(void);
|
||||
PyObject* PyInit__string(void);
|
||||
|
||||
struct _inittab _PyImport_Inittab[] = {
|
||||
|
||||
{"_decimal", PyInit__decimal},
|
||||
{"posix", PyInit_posix},
|
||||
{"audioop", PyInit_audioop},
|
||||
{"errno", PyInit_errno},
|
||||
{"pwd", PyInit_pwd},
|
||||
{"_sre", PyInit__sre},
|
||||
|
@ -119,7 +121,6 @@ struct _inittab _PyImport_Inittab[] = {
|
|||
{"time", PyInit_time},
|
||||
{"_locale", PyInit__locale},
|
||||
{"_io", PyInit__io},
|
||||
{"zipimport", PyInit_zipimport},
|
||||
{"faulthandler", PyInit_faulthandler},
|
||||
{"_tracemalloc", PyInit__tracemalloc},
|
||||
{"_symtable", PyInit__symtable},
|
||||
|
@ -130,7 +131,6 @@ struct _inittab _PyImport_Inittab[] = {
|
|||
{"_weakref", PyInit__weakref},
|
||||
{"_testcapi", PyInit__testcapi},
|
||||
{"_random", PyInit__random},
|
||||
{"_elementtree", PyInit__elementtree},
|
||||
{"_pickle", PyInit__pickle},
|
||||
{"_datetime", PyInit__datetime},
|
||||
{"_bisect", PyInit__bisect},
|
||||
|
@ -153,19 +153,26 @@ struct _inittab _PyImport_Inittab[] = {
|
|||
{"binascii", PyInit_binascii},
|
||||
{"parser", PyInit_parser},
|
||||
{"fpectl", PyInit_fpectl},
|
||||
{"zlib", PyInit_zlib},
|
||||
{"pyexpat", PyInit_pyexpat},
|
||||
{"_multibytecodec", PyInit__multibytecodec},
|
||||
{"_json", PyInit__json},
|
||||
{"_opcode", PyInit__opcode},
|
||||
{"termios", PyInit_termios},
|
||||
|
||||
#if !IsTiny()
|
||||
{"zlib", PyInit_zlib},
|
||||
{"sqlite3", PyInit__sqlite3},
|
||||
{"zipimport", PyInit_zipimport},
|
||||
{"_elementtree", PyInit__elementtree},
|
||||
{"_codecs_cn", PyInit__codecs_cn},
|
||||
{"_codecs_hk", PyInit__codecs_hk},
|
||||
{"_codecs_iso2022", PyInit__codecs_iso2022},
|
||||
{"_codecs_jp", PyInit__codecs_jp},
|
||||
{"_codecs_kr", PyInit__codecs_kr},
|
||||
{"_codecs_tw", PyInit__codecs_tw},
|
||||
{"_json", PyInit__json},
|
||||
{"audioop", PyInit_audioop},
|
||||
{"_lsprof", PyInit__lsprof},
|
||||
{"_opcode", PyInit__opcode},
|
||||
{"termios", PyInit_termios},
|
||||
#endif
|
||||
|
||||
/* -- ADDMODULE MARKER 2 -- */
|
||||
|
||||
|
|
59
third_party/python/Modules/fspath.c
vendored
Normal file
59
third_party/python/Modules/fspath.c
vendored
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Python 3 │
|
||||
│ https://docs.python.org/3/license.html │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/python/Include/abstract.h"
|
||||
#include "third_party/python/Include/bytesobject.h"
|
||||
#include "third_party/python/Include/object.h"
|
||||
#include "third_party/python/Include/pyerrors.h"
|
||||
#include "third_party/python/Include/unicodeobject.h"
|
||||
/* clang-format off */
|
||||
|
||||
/*
|
||||
Return the file system path representation of the object.
|
||||
|
||||
If the object is str or bytes, then allow it to pass through with
|
||||
an incremented refcount. If the object defines __fspath__(), then
|
||||
return the result of that method. All other types raise a TypeError.
|
||||
*/
|
||||
PyObject *
|
||||
PyOS_FSPath(PyObject *path)
|
||||
{
|
||||
/* For error message reasons, this function is manually inlined in
|
||||
path_converter(). */
|
||||
_Py_IDENTIFIER(__fspath__);
|
||||
PyObject *func = NULL;
|
||||
PyObject *path_repr = NULL;
|
||||
|
||||
if (PyUnicode_Check(path) || PyBytes_Check(path)) {
|
||||
Py_INCREF(path);
|
||||
return path;
|
||||
}
|
||||
|
||||
func = _PyObject_LookupSpecial(path, &PyId___fspath__);
|
||||
if (NULL == func) {
|
||||
return PyErr_Format(PyExc_TypeError,
|
||||
"expected str, bytes or os.PathLike object, "
|
||||
"not %.200s",
|
||||
Py_TYPE(path)->tp_name);
|
||||
}
|
||||
|
||||
path_repr = PyObject_CallFunctionObjArgs(func, NULL);
|
||||
Py_DECREF(func);
|
||||
if (NULL == path_repr) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(PyUnicode_Check(path_repr) || PyBytes_Check(path_repr))) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"expected %.200s.__fspath__() to return str or bytes, "
|
||||
"not %.200s", Py_TYPE(path)->tp_name,
|
||||
Py_TYPE(path_repr)->tp_name);
|
||||
Py_DECREF(path_repr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return path_repr;
|
||||
}
|
2
third_party/python/Modules/getbuildinfo.c
vendored
2
third_party/python/Modules/getbuildinfo.c
vendored
|
@ -38,7 +38,7 @@
|
|||
const char *
|
||||
Py_GetBuildInfo(void)
|
||||
{
|
||||
return "cosmopolitan";
|
||||
return "🐒 Actually Portable Python";
|
||||
}
|
||||
|
||||
const char *
|
||||
|
|
30
third_party/python/Modules/getpath.c
vendored
30
third_party/python/Modules/getpath.c
vendored
|
@ -7,6 +7,7 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "third_party/python/Include/fileutils.h"
|
||||
#include "third_party/python/Include/osdefs.h"
|
||||
#include "third_party/python/Include/pyerrors.h"
|
||||
|
@ -255,10 +256,8 @@ copy_absolute(wchar_t *path, wchar_t *p, size_t pathlen)
|
|||
static void
|
||||
absolutize(wchar_t *path)
|
||||
{
|
||||
wchar_t buffer[MAXPATHLEN+1];
|
||||
|
||||
if (path[0] == SEP)
|
||||
return;
|
||||
wchar_t *buffer = gc(calloc(MAXPATHLEN+1, sizeof(wchar_t)));
|
||||
if (path[0] == SEP) return;
|
||||
copy_absolute(buffer, path, MAXPATHLEN+1);
|
||||
wcscpy(path, buffer);
|
||||
}
|
||||
|
@ -478,19 +477,18 @@ calculate_path(void)
|
|||
wchar_t *path_buffer = NULL;
|
||||
wchar_t *path = NULL;
|
||||
wchar_t *prog = Py_GetProgramName();
|
||||
wchar_t argv0_path[MAXPATHLEN+1];
|
||||
/* wont need zip_path because embedded stdlib inside executable */
|
||||
/* wchar_t zip_path[MAXPATHLEN+1]; */
|
||||
wchar_t *buf;
|
||||
size_t bufsz;
|
||||
wchar_t ape_path[MAXPATHLEN+1];
|
||||
size_t ape_length;
|
||||
wchar_t ape_lib_path[MAXPATHLEN+1];
|
||||
wchar_t ape_exec_path[MAXPATHLEN+1];
|
||||
wchar_t package_path[MAXPATHLEN+1];
|
||||
wchar_t ape_package_path[MAXPATHLEN+1];
|
||||
if(IsWindows())
|
||||
{
|
||||
wchar_t *ape_path = gc(calloc(MAXPATHLEN+1, sizeof(wchar_t)));
|
||||
wchar_t *argv0_path = gc(calloc(MAXPATHLEN+1, sizeof(wchar_t)));
|
||||
wchar_t *ape_lib_path = gc(calloc(MAXPATHLEN+1, sizeof(wchar_t)));
|
||||
wchar_t *ape_exec_path = gc(calloc(MAXPATHLEN+1, sizeof(wchar_t)));
|
||||
wchar_t *package_path = gc(calloc(MAXPATHLEN+1, sizeof(wchar_t)));
|
||||
wchar_t *ape_package_path = gc(calloc(MAXPATHLEN+1, sizeof(wchar_t)));
|
||||
if (IsWindows()) {
|
||||
delimiter[0] = L';';
|
||||
separator[0] = L'\\';
|
||||
}
|
||||
|
@ -543,15 +541,15 @@ calculate_path(void)
|
|||
wcsncpy(prefix,
|
||||
L"third_party/python/Lib",
|
||||
MAXPATHLEN);
|
||||
wcsncpy(prefix,
|
||||
L"zip!.python",
|
||||
MAXPATHLEN);
|
||||
/* wcsncpy(prefix, */
|
||||
/* L"zip!.python", */
|
||||
/* 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)
|
||||
if (wcslen(progpath) > 0 && wcslen(progpath) + 1 < MAXPATHLEN)
|
||||
wcsncpy(ape_path, progpath, MAXPATHLEN);
|
||||
else
|
||||
wcsncpy(ape_path, prog, MAXPATHLEN);
|
||||
|
|
343
third_party/python/Modules/posixmodule.c
vendored
343
third_party/python/Modules/posixmodule.c
vendored
|
@ -11,9 +11,12 @@
|
|||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/makedev.h"
|
||||
#include "libc/calls/struct/dirent.h"
|
||||
#include "libc/calls/struct/winsize.h"
|
||||
#include "libc/calls/termios.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/nt/dll.h"
|
||||
#include "libc/nt/enum/sw.h"
|
||||
#include "libc/runtime/dlfcn.h"
|
||||
#include "libc/runtime/sysconf.h"
|
||||
#include "libc/sock/sock.h"
|
||||
|
@ -46,6 +49,7 @@
|
|||
#include "third_party/python/Include/longobject.h"
|
||||
#include "third_party/python/Include/modsupport.h"
|
||||
#include "third_party/python/Include/objimpl.h"
|
||||
#include "third_party/python/Include/osmodule.h"
|
||||
#include "third_party/python/Include/pyerrors.h"
|
||||
#include "third_party/python/Include/pylifecycle.h"
|
||||
#include "third_party/python/Include/pymacro.h"
|
||||
|
@ -77,7 +81,7 @@ corresponding Unix manual entries for more information on calls.");
|
|||
#undef HAVE_SCHED_SETAFFINITY
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SYS_XATTR_H) && defined(__GLIBC__) && !defined(__FreeBSD_kernel__) && !defined(__GNU__)
|
||||
#if defined(__GLIBC__) && !defined(__FreeBSD_kernel__) && !defined(__GNU__)
|
||||
#define USE_XATTRS
|
||||
#endif
|
||||
|
||||
|
@ -87,11 +91,7 @@ module os
|
|||
[clinic start generated code]*/
|
||||
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=94a0f0f978acae17]*/
|
||||
|
||||
#ifdef HAVE_DIRENT_H
|
||||
#define NAMLEN(dirent) strlen((dirent)->d_name)
|
||||
#else
|
||||
#define NAMLEN(dirent) (dirent)->d_namlen
|
||||
#endif
|
||||
|
||||
#ifndef MAXPATHLEN
|
||||
#if defined(PATH_MAX) && PATH_MAX > 1024 /* TODO: wut? */
|
||||
|
@ -104,18 +104,6 @@ module os
|
|||
#ifdef UNION_WAIT
|
||||
/* Emulate some macros on systems that have a union instead of macros */
|
||||
|
||||
#ifndef WIFEXITED
|
||||
#define WIFEXITED(u_wait) (!(u_wait).w_termsig && !(u_wait).w_coredump)
|
||||
#endif
|
||||
|
||||
#ifndef WEXITSTATUS
|
||||
#define WEXITSTATUS(u_wait) (WIFEXITED(u_wait)?((u_wait).w_retcode):-1)
|
||||
#endif
|
||||
|
||||
#ifndef WTERMSIG
|
||||
#define WTERMSIG(u_wait) ((u_wait).w_termsig)
|
||||
#endif
|
||||
|
||||
#define WAIT_TYPE union wait
|
||||
#define WAIT_STATUS_INT(s) (s.w_status)
|
||||
|
||||
|
@ -1174,7 +1162,7 @@ posix_fildes_fd(int fd, int (*func)(int))
|
|||
it also needs to set "magic" environment variables indicating
|
||||
the per-drive current directory, which are of the form =<drive>: */
|
||||
static BOOL __stdcall
|
||||
win32_wchdir(LPCWSTR path)
|
||||
win32_wchdir(const char16_t * path)
|
||||
{
|
||||
wchar_t path_buf[MAX_PATH], *new_path = path_buf;
|
||||
int result;
|
||||
|
@ -1239,7 +1227,7 @@ find_data_to_file_info(WIN32_FIND_DATAW *pFileData,
|
|||
}
|
||||
|
||||
static BOOL
|
||||
attributes_from_dir(LPCWSTR pszFile, BY_HANDLE_FILE_INFORMATION *info, ULONG *reparse_tag)
|
||||
attributes_from_dir(const char16_t * pszFile, BY_HANDLE_FILE_INFORMATION *info, ULONG *reparse_tag)
|
||||
{
|
||||
HANDLE hFindFile;
|
||||
WIN32_FIND_DATAW FileData;
|
||||
|
@ -3930,7 +3918,7 @@ os_umask_impl(PyObject *module, int mask)
|
|||
/* override the default DeleteFileW behavior so that directory
|
||||
symlinks can be removed with this function, the same as with
|
||||
Unix symlinks */
|
||||
BOOL WINAPI Py_DeleteFileW(LPCWSTR lpFileName)
|
||||
BOOL WINAPI Py_DeleteFileW(const char16_t * lpFileName)
|
||||
{
|
||||
WIN32_FILE_ATTRIBUTE_DATA info;
|
||||
WIN32_FIND_DATAW find_data;
|
||||
|
@ -4248,19 +4236,8 @@ utime_nofollow_symlinks(utime_t *ut, const char *path)
|
|||
static int
|
||||
utime_default(utime_t *ut, const char *path)
|
||||
{
|
||||
#ifdef HAVE_UTIMENSAT
|
||||
UTIME_TO_TIMESPEC;
|
||||
return utimensat(DEFAULT_DIR_FD, path, time, 0);
|
||||
#elif defined(HAVE_UTIMES)
|
||||
UTIME_TO_TIMEVAL;
|
||||
return utimes(path, time);
|
||||
#elif defined(HAVE_UTIME_H)
|
||||
UTIME_TO_UTIMBUF;
|
||||
return utime(path, time);
|
||||
#else
|
||||
UTIME_TO_TIME_T;
|
||||
return utime(path, time);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -5086,7 +5063,6 @@ os_fork_impl(PyObject *module)
|
|||
#endif /* HAVE_FORK */
|
||||
|
||||
|
||||
#ifdef HAVE_SCHED_H
|
||||
#ifdef HAVE_SCHED_GET_PRIORITY_MAX
|
||||
/*[clinic input]
|
||||
os.sched_get_priority_max
|
||||
|
@ -5516,9 +5492,6 @@ error:
|
|||
|
||||
#endif /* HAVE_SCHED_SETAFFINITY */
|
||||
|
||||
#endif /* HAVE_SCHED_H */
|
||||
|
||||
|
||||
/* AIX uses /dev/ptc but is otherwise the same as /dev/ptmx */
|
||||
/* IRIX has both /dev/ptc and /dev/ptmx, use ptmx */
|
||||
#if defined(HAVE_DEV_PTC) && !defined(HAVE_DEV_PTMX)
|
||||
|
@ -6755,8 +6728,6 @@ dir_fd may not be implemented on your platform.\n\
|
|||
If it is unavailable, using it will raise a NotImplementedError.");
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_READLINK
|
||||
|
||||
/* AC 3.5: merge win32 and not together */
|
||||
static PyObject *
|
||||
posix_readlink(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||
|
@ -6799,91 +6770,12 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
#endif /* HAVE_READLINK */
|
||||
|
||||
#if !defined(HAVE_READLINK) && defined(MS_WINDOWS)
|
||||
|
||||
static PyObject *
|
||||
win_readlink(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
const wchar_t *path;
|
||||
DWORD n_bytes_returned;
|
||||
DWORD io_result;
|
||||
PyObject *po, *result;
|
||||
int dir_fd;
|
||||
HANDLE reparse_point_handle;
|
||||
|
||||
char target_buffer[_Py_MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
|
||||
_Py_REPARSE_DATA_BUFFER *rdb = (_Py_REPARSE_DATA_BUFFER *)target_buffer;
|
||||
const wchar_t *print_name;
|
||||
|
||||
static char *keywords[] = {"path", "dir_fd", NULL};
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "U|$O&:readlink", keywords,
|
||||
&po,
|
||||
dir_fd_unavailable, &dir_fd
|
||||
))
|
||||
return NULL;
|
||||
|
||||
path = _PyUnicode_AsUnicode(po);
|
||||
if (path == NULL)
|
||||
return NULL;
|
||||
|
||||
/* First get a handle to the reparse point */
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
reparse_point_handle = CreateFileW(
|
||||
path,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
OPEN_EXISTING,
|
||||
FILE_FLAG_OPEN_REPARSE_POINT|FILE_FLAG_BACKUP_SEMANTICS,
|
||||
0);
|
||||
Py_END_ALLOW_THREADS
|
||||
|
||||
if (reparse_point_handle==INVALID_HANDLE_VALUE)
|
||||
return win32_error_object("readlink", po);
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
/* New call DeviceIoControl to read the reparse point */
|
||||
io_result = DeviceIoControl(
|
||||
reparse_point_handle,
|
||||
FSCTL_GET_REPARSE_POINT,
|
||||
0, 0, /* in buffer */
|
||||
target_buffer, sizeof(target_buffer),
|
||||
&n_bytes_returned,
|
||||
0 /* we're not using OVERLAPPED_IO */
|
||||
);
|
||||
CloseHandle(reparse_point_handle);
|
||||
Py_END_ALLOW_THREADS
|
||||
|
||||
if (io_result==0)
|
||||
return win32_error_object("readlink", po);
|
||||
|
||||
if (rdb->ReparseTag != IO_REPARSE_TAG_SYMLINK)
|
||||
{
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"not a symbolic link");
|
||||
return NULL;
|
||||
}
|
||||
print_name = (wchar_t *)((char*)rdb->SymbolicLinkReparseBuffer.PathBuffer +
|
||||
rdb->SymbolicLinkReparseBuffer.PrintNameOffset);
|
||||
|
||||
result = PyUnicode_FromWideChar(print_name,
|
||||
rdb->SymbolicLinkReparseBuffer.PrintNameLength / sizeof(wchar_t));
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif /* !defined(HAVE_READLINK) && defined(MS_WINDOWS) */
|
||||
|
||||
|
||||
|
||||
#ifdef HAVE_SYMLINK
|
||||
|
||||
#if defined(MS_WINDOWS)
|
||||
|
||||
/* Grab CreateSymbolicLinkW dynamically from kernel32 */
|
||||
static BOOLEAN (CALLBACK *Py_CreateSymbolicLinkW)(LPCWSTR, LPCWSTR, DWORD) = NULL;
|
||||
static BOOLEAN (CALLBACK *Py_CreateSymbolicLinkW)(const char16_t *, const char16_t *, DWORD) = NULL;
|
||||
|
||||
static int
|
||||
check_CreateSymbolicLink(void)
|
||||
|
@ -6947,7 +6839,7 @@ _joinW(WCHAR *dest_path, const WCHAR *root, const WCHAR *rest)
|
|||
|
||||
/* Return True if the path at src relative to dest is a directory */
|
||||
static int
|
||||
_check_dirW(LPCWSTR src, LPCWSTR dest)
|
||||
_check_dirW(const char16_t * src, const char16_t * dest)
|
||||
{
|
||||
WIN32_FILE_ATTRIBUTE_DATA src_info;
|
||||
WCHAR dest_parent[MAX_PATH];
|
||||
|
@ -7434,7 +7326,7 @@ os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#elif defined(HAVE_FCNTL_H) && defined(F_DUP2FD_CLOEXEC)
|
||||
#elif defined(F_DUP2FD_CLOEXEC)
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
if (!inheritable)
|
||||
res = fcntl(fd, F_DUP2FD_CLOEXEC, fd2);
|
||||
|
@ -8673,7 +8565,6 @@ os_strerror_impl(PyObject *module, int code)
|
|||
}
|
||||
|
||||
|
||||
#ifdef HAVE_SYS_WAIT_H
|
||||
#ifdef WCOREDUMP
|
||||
/*[clinic input]
|
||||
os.WCOREDUMP -> bool
|
||||
|
@ -8836,10 +8727,9 @@ os_WSTOPSIG_impl(PyObject *module, int status)
|
|||
return WSTOPSIG(wait_status);
|
||||
}
|
||||
#endif /* WSTOPSIG */
|
||||
#endif /* HAVE_SYS_WAIT_H */
|
||||
|
||||
|
||||
#if defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)
|
||||
#if defined(HAVE_FSTATVFS)
|
||||
#ifdef _SCO_DS
|
||||
/* SCO OpenServer 5.0 and later requires _SVID3 before it reveals the
|
||||
needed definitions in sys/statvfs.h */
|
||||
|
@ -8919,10 +8809,10 @@ os_fstatvfs_impl(PyObject *module, int fd)
|
|||
|
||||
return _pystatvfs_fromstructstatvfs(st);
|
||||
}
|
||||
#endif /* defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H) */
|
||||
#endif /* defined(HAVE_FSTATVFS) */
|
||||
|
||||
|
||||
#if defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)
|
||||
#if defined(HAVE_STATVFS)
|
||||
/*[clinic input]
|
||||
os.statvfs
|
||||
|
||||
|
@ -8965,7 +8855,7 @@ os_statvfs_impl(PyObject *module, path_t *path)
|
|||
|
||||
return _pystatvfs_fromstructstatvfs(st);
|
||||
}
|
||||
#endif /* defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H) */
|
||||
#endif /* defined(HAVE_STATVFS) */
|
||||
|
||||
|
||||
#ifdef MS_WINDOWS
|
||||
|
@ -10053,21 +9943,20 @@ os_abort_impl(PyObject *module)
|
|||
#ifdef MS_WINDOWS
|
||||
/* Grab ShellExecute dynamically from shell32 */
|
||||
static int has_ShellExecute = -1;
|
||||
static HINSTANCE (CALLBACK *Py_ShellExecuteW)(HWND, LPCWSTR, LPCWSTR, LPCWSTR,
|
||||
LPCWSTR, INT);
|
||||
static int64_t (*Py_ShellExecuteW)(int64_t, const char16_t *, const char16_t *,
|
||||
const char16_t *, const char16_t *, int);
|
||||
|
||||
static int
|
||||
check_ShellExecute()
|
||||
{
|
||||
HINSTANCE hShell32;
|
||||
|
||||
int64_t hShell32;
|
||||
/* only recheck */
|
||||
if (-1 == has_ShellExecute) {
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
hShell32 = LoadLibraryW(L"SHELL32");
|
||||
hShell32 = LoadLibrary(u"SHELL32");
|
||||
Py_END_ALLOW_THREADS
|
||||
if (hShell32) {
|
||||
*(FARPROC*)&Py_ShellExecuteW = GetProcAddress(hShell32,
|
||||
"ShellExecuteW");
|
||||
Py_ShellExecuteW = GetProcAddress(hShell32, "ShellExecuteW");
|
||||
has_ShellExecute = Py_ShellExecuteW != NULL;
|
||||
} else {
|
||||
has_ShellExecute = 0;
|
||||
|
@ -10116,8 +10005,7 @@ os_startfile_impl(PyObject *module, path_t *filepath, Py_UNICODE *operation)
|
|||
}
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
rc = Py_ShellExecuteW((HWND)0, operation, filepath->wide,
|
||||
NULL, NULL, SW_SHOWNORMAL);
|
||||
rc = Py_ShellExecuteW(0, operation, filepath->wide, 0, 0, kNtSwShownormal);
|
||||
Py_END_ALLOW_THREADS
|
||||
|
||||
if (rc <= (HINSTANCE)32) {
|
||||
|
@ -10577,7 +10465,6 @@ static PyStructSequence_Desc TerminalSize_desc = {
|
|||
2,
|
||||
};
|
||||
|
||||
#if defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)
|
||||
/* AC 3.5: fd should accept None */
|
||||
PyDoc_STRVAR(termsize__doc__,
|
||||
"Return the size of the terminal window as (columns, lines).\n" \
|
||||
|
@ -10597,9 +10484,9 @@ PyDoc_STRVAR(termsize__doc__,
|
|||
static PyObject*
|
||||
get_terminal_size(PyObject *self, PyObject *args)
|
||||
{
|
||||
struct winsize w;
|
||||
int columns, lines;
|
||||
PyObject *termsize;
|
||||
|
||||
int fd = fileno(stdout);
|
||||
/* Under some conditions stdout may not be connected and
|
||||
* fileno(stdout) may point to an invalid file descriptor. For example
|
||||
|
@ -10608,49 +10495,12 @@ get_terminal_size(PyObject *self, PyObject *args)
|
|||
* If this happens, and the optional fd argument is not present,
|
||||
* the ioctl below will fail returning EBADF. This is what we want.
|
||||
*/
|
||||
|
||||
if (!PyArg_ParseTuple(args, "|i", &fd))
|
||||
return NULL;
|
||||
|
||||
#ifdef TERMSIZE_USE_IOCTL
|
||||
{
|
||||
struct winsize w;
|
||||
if (ioctl(fd, TIOCGWINSZ, &w))
|
||||
return PyErr_SetFromErrno(PyExc_OSError);
|
||||
columns = w.ws_col;
|
||||
lines = w.ws_row;
|
||||
}
|
||||
#endif /* TERMSIZE_USE_IOCTL */
|
||||
|
||||
#ifdef TERMSIZE_USE_CONIO
|
||||
{
|
||||
DWORD nhandle;
|
||||
HANDLE handle;
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
switch (fd) {
|
||||
case 0: nhandle = STD_INPUT_HANDLE;
|
||||
break;
|
||||
case 1: nhandle = STD_OUTPUT_HANDLE;
|
||||
break;
|
||||
case 2: nhandle = STD_ERROR_HANDLE;
|
||||
break;
|
||||
default:
|
||||
return PyErr_Format(PyExc_ValueError, "bad file descriptor");
|
||||
}
|
||||
handle = GetStdHandle(nhandle);
|
||||
if (handle == NULL)
|
||||
return PyErr_Format(PyExc_OSError, "handle cannot be retrieved");
|
||||
if (handle == INVALID_HANDLE_VALUE)
|
||||
return PyErr_SetFromWindowsErr(0);
|
||||
|
||||
if (!GetConsoleScreenBufferInfo(handle, &csbi))
|
||||
return PyErr_SetFromWindowsErr(0);
|
||||
|
||||
columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
|
||||
lines = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
|
||||
}
|
||||
#endif /* TERMSIZE_USE_CONIO */
|
||||
|
||||
if (ioctl(fd, TIOCGWINSZ, &w))
|
||||
return PyErr_SetFromErrno(PyExc_OSError);
|
||||
columns = w.ws_col;
|
||||
lines = w.ws_row;
|
||||
termsize = PyStructSequence_New(&TerminalSizeType);
|
||||
if (termsize == NULL)
|
||||
return NULL;
|
||||
|
@ -10662,8 +10512,6 @@ get_terminal_size(PyObject *self, PyObject *args)
|
|||
}
|
||||
return termsize;
|
||||
}
|
||||
#endif /* defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL) */
|
||||
|
||||
|
||||
/*[clinic input]
|
||||
os.cpu_count
|
||||
|
@ -11075,11 +10923,9 @@ static PyObject *
|
|||
DirEntry_is_file(DirEntry *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
int follow_symlinks = 1;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|$p:DirEntry.is_file",
|
||||
follow_symlinks_keywords, &follow_symlinks))
|
||||
return NULL;
|
||||
|
||||
return DirEntry_py_test_mode(self, follow_symlinks, S_IFREG);
|
||||
}
|
||||
|
||||
|
@ -11629,117 +11475,35 @@ posix_scandir(PyObject *self, PyObject *args, PyObject *kwargs)
|
|||
{
|
||||
ScandirIterator *iterator;
|
||||
static char *keywords[] = {"path", NULL};
|
||||
#ifdef MS_WINDOWS
|
||||
wchar_t *path_strW;
|
||||
#else
|
||||
const char *path;
|
||||
#endif
|
||||
|
||||
iterator = PyObject_New(ScandirIterator, &ScandirIteratorType);
|
||||
if (!iterator)
|
||||
return NULL;
|
||||
bzero(&iterator->path, sizeof(path_t));
|
||||
iterator->path.function_name = "scandir";
|
||||
iterator->path.nullable = 1;
|
||||
|
||||
#ifdef MS_WINDOWS
|
||||
iterator->handle = INVALID_HANDLE_VALUE;
|
||||
#else
|
||||
iterator->dirp = NULL;
|
||||
#endif
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O&:scandir", keywords,
|
||||
path_converter, &iterator->path))
|
||||
goto error;
|
||||
|
||||
#ifdef MS_WINDOWS
|
||||
iterator->first_time = 1;
|
||||
|
||||
path_strW = join_path_filenameW(iterator->path.wide, L"*.*");
|
||||
if (!path_strW)
|
||||
goto error;
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
iterator->handle = FindFirstFileW(path_strW, &iterator->file_data);
|
||||
Py_END_ALLOW_THREADS
|
||||
|
||||
PyeeMem_Free(path_strW);
|
||||
|
||||
if (iterator->handle == INVALID_HANDLE_VALUE) {
|
||||
path_error(&iterator->path);
|
||||
goto error;
|
||||
}
|
||||
#else /* POSIX */
|
||||
if (iterator->path.narrow)
|
||||
path = iterator->path.narrow;
|
||||
else
|
||||
path = ".";
|
||||
|
||||
errno = 0;
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
iterator->dirp = opendir(path);
|
||||
Py_END_ALLOW_THREADS
|
||||
|
||||
if (!iterator->dirp) {
|
||||
path_error(&iterator->path);
|
||||
goto error;
|
||||
}
|
||||
#endif
|
||||
|
||||
return (PyObject *)iterator;
|
||||
|
||||
error:
|
||||
Py_DECREF(iterator);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
Return the file system path representation of the object.
|
||||
|
||||
If the object is str or bytes, then allow it to pass through with
|
||||
an incremented refcount. If the object defines __fspath__(), then
|
||||
return the result of that method. All other types raise a TypeError.
|
||||
*/
|
||||
PyObject *
|
||||
PyOS_FSPath(PyObject *path)
|
||||
{
|
||||
/* For error message reasons, this function is manually inlined in
|
||||
path_converter(). */
|
||||
_Py_IDENTIFIER(__fspath__);
|
||||
PyObject *func = NULL;
|
||||
PyObject *path_repr = NULL;
|
||||
|
||||
if (PyUnicode_Check(path) || PyBytes_Check(path)) {
|
||||
Py_INCREF(path);
|
||||
return path;
|
||||
}
|
||||
|
||||
func = _PyObject_LookupSpecial(path, &PyId___fspath__);
|
||||
if (NULL == func) {
|
||||
return PyErr_Format(PyExc_TypeError,
|
||||
"expected str, bytes or os.PathLike object, "
|
||||
"not %.200s",
|
||||
Py_TYPE(path)->tp_name);
|
||||
}
|
||||
|
||||
path_repr = PyObject_CallFunctionObjArgs(func, NULL);
|
||||
Py_DECREF(func);
|
||||
if (NULL == path_repr) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(PyUnicode_Check(path_repr) || PyBytes_Check(path_repr))) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"expected %.200s.__fspath__() to return str or bytes, "
|
||||
"not %.200s", Py_TYPE(path)->tp_name,
|
||||
Py_TYPE(path_repr)->tp_name);
|
||||
Py_DECREF(path_repr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return path_repr;
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
os.fspath
|
||||
|
||||
|
@ -12004,9 +11768,7 @@ static PyMethodDef posix_methods[] = {
|
|||
OS_REMOVEXATTR_METHODDEF
|
||||
OS_LISTXATTR_METHODDEF
|
||||
|
||||
#if defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)
|
||||
{"get_terminal_size", get_terminal_size, METH_VARARGS, termsize__doc__},
|
||||
#endif
|
||||
OS_CPU_COUNT_METHODDEF
|
||||
OS_GET_INHERITABLE_METHODDEF
|
||||
OS_SET_INHERITABLE_METHODDEF
|
||||
|
@ -12038,9 +11800,9 @@ all_ins(PyObject *m)
|
|||
#ifdef TMP_MAX
|
||||
if (PyModule_AddIntMacro(m, TMP_MAX)) return -1;
|
||||
#endif
|
||||
if (WCONTINUED && PyModule_AddIntMacro(m, WCONTINUED)) return -1;
|
||||
if (WNOHANG && PyModule_AddIntMacro(m, WNOHANG)) return -1;
|
||||
if (PyModule_AddIntMacro(m, WNOHANG)) return -1;
|
||||
if (WUNTRACED && PyModule_AddIntMacro(m, WUNTRACED)) return -1;
|
||||
if (WCONTINUED && PyModule_AddIntMacro(m, WCONTINUED)) return -1;
|
||||
if (PyModule_AddIntMacro(m, O_RDONLY)) return -1;
|
||||
if (PyModule_AddIntMacro(m, O_WRONLY)) return -1;
|
||||
if (PyModule_AddIntMacro(m, O_RDWR)) return -1;
|
||||
|
@ -12084,44 +11846,22 @@ all_ins(PyObject *m)
|
|||
if (PyModule_AddIntMacro(m, SEEK_DATA)) return -1;
|
||||
#endif
|
||||
|
||||
/* MS Windows */
|
||||
if (PyModule_AddIntMacro(m, O_DIRECTORY)) return -1;
|
||||
if (O_RANDOM && PyModule_AddIntMacro(m, O_RANDOM)) return -1;
|
||||
if (O_SEQUENTIAL && PyModule_AddIntMacro(m, O_SEQUENTIAL)) return -1;
|
||||
if (O_ASYNC && PyModule_AddIntMacro(m, O_ASYNC)) return -1;
|
||||
if (O_DIRECT && PyModule_AddIntMacro(m, O_DIRECT)) return -1;
|
||||
if (O_NOFOLLOW && PyModule_AddIntMacro(m, O_NOFOLLOW)) return -1;
|
||||
if (O_NOATIME && PyModule_AddIntMacro(m, O_NOATIME)) return -1;
|
||||
#ifdef O_NOINHERIT
|
||||
/* Don't inherit in child processes. */
|
||||
if (PyModule_AddIntMacro(m, O_NOINHERIT)) return -1;
|
||||
#endif
|
||||
#ifdef _O_SHORT_LIVED
|
||||
/* Optimize for short life (keep in memory). */
|
||||
/* MS forgot to define this one with a non-underscore form too. */
|
||||
if (PyModule_AddIntConstant(m, "O_SHORT_LIVED", _O_SHORT_LIVED)) return -1;
|
||||
#endif
|
||||
#ifdef O_TEMPORARY
|
||||
/* Automatically delete when last handle is closed. */
|
||||
if (PyModule_AddIntMacro(m, O_TEMPORARY)) return -1;
|
||||
#endif
|
||||
#ifdef O_RANDOM
|
||||
/* Optimize for random access. */
|
||||
if (PyModule_AddIntMacro(m, O_RANDOM)) return -1;
|
||||
#endif
|
||||
#ifdef O_SEQUENTIAL
|
||||
/* Optimize for sequential access. */
|
||||
if (PyModule_AddIntMacro(m, O_SEQUENTIAL)) return -1;
|
||||
#endif
|
||||
|
||||
/* Send a SIGIO signal whenever input or output
|
||||
becomes available on file descriptor */
|
||||
if (O_ASYNC && PyModule_AddIntMacro(m, O_ASYNC)) return -1;
|
||||
/* Direct disk access. */
|
||||
if (O_DIRECT && PyModule_AddIntMacro(m, O_DIRECT)) return -1;
|
||||
/* Must be a directory. */
|
||||
if (PyModule_AddIntMacro(m, O_DIRECTORY)) return -1;
|
||||
/* Do not follow links. */
|
||||
if (O_NOFOLLOW && PyModule_AddIntMacro(m, O_NOFOLLOW)) return -1;
|
||||
#ifdef O_NOLINKS
|
||||
/* Fails if link count of the named file is greater than 1 */
|
||||
if (PyModule_AddIntMacro(m, O_NOLINKS)) return -1;
|
||||
#endif
|
||||
/* Do not update the access time. */
|
||||
if (O_NOATIME && PyModule_AddIntMacro(m, O_NOATIME)) return -1;
|
||||
|
||||
/* These come from sysexits.h */
|
||||
if (PyModule_AddIntMacro(m, EX_OK)) return -1;
|
||||
|
@ -12144,7 +11884,6 @@ all_ins(PyObject *m)
|
|||
/* statvfs */
|
||||
if (ST_RDONLY && PyModule_AddIntMacro(m, ST_RDONLY)) return -1;
|
||||
if (ST_NOSUID && PyModule_AddIntMacro(m, ST_NOSUID)) return -1;
|
||||
|
||||
if (ST_NODEV && PyModule_AddIntMacro(m, ST_NODEV)) return -1;
|
||||
if (ST_NOEXEC && PyModule_AddIntMacro(m, ST_NOEXEC)) return -1;
|
||||
if (ST_SYNCHRONOUS && PyModule_AddIntMacro(m, ST_SYNCHRONOUS)) return -1;
|
||||
|
@ -12161,7 +11900,7 @@ all_ins(PyObject *m)
|
|||
if (SF_SYNC && PyModule_AddIntMacro(m, SF_SYNC)) return -1;
|
||||
|
||||
/* constants for posix_fadvise */
|
||||
if (POSIX_FADV_NORMAL && PyModule_AddIntMacro(m, POSIX_FADV_NORMAL)) return -1;
|
||||
if (PyModule_AddIntMacro(m, POSIX_FADV_NORMAL)) return -1;
|
||||
if (POSIX_FADV_SEQUENTIAL && PyModule_AddIntMacro(m, POSIX_FADV_SEQUENTIAL)) return -1;
|
||||
if (POSIX_FADV_RANDOM && PyModule_AddIntMacro(m, POSIX_FADV_RANDOM)) return -1;
|
||||
if (POSIX_FADV_NOREUSE && PyModule_AddIntMacro(m, POSIX_FADV_NOREUSE)) return -1;
|
||||
|
@ -12169,7 +11908,7 @@ all_ins(PyObject *m)
|
|||
if (POSIX_FADV_DONTNEED && PyModule_AddIntMacro(m, POSIX_FADV_DONTNEED)) return -1;
|
||||
|
||||
/* constants for waitid */
|
||||
#if defined(HAVE_SYS_WAIT_H) && defined(HAVE_WAITID)
|
||||
#if defined(HAVE_WAITID)
|
||||
if (P_PID && PyModule_AddIntMacro(m, P_PID)) return -1;
|
||||
if (P_PGID && PyModule_AddIntMacro(m, P_PGID)) return -1;
|
||||
if (P_ALL && PyModule_AddIntMacro(m, P_ALL)) return -1;
|
||||
|
@ -12185,7 +11924,7 @@ all_ins(PyObject *m)
|
|||
/* constants for lockf */
|
||||
if (F_LOCK && PyModule_AddIntMacro(m, F_LOCK)) return -1;
|
||||
if (F_TLOCK && PyModule_AddIntMacro(m, F_TLOCK)) return -1;
|
||||
if (F_ULOCK && PyModule_AddIntMacro(m, F_ULOCK)) return -1;
|
||||
if (PyModule_AddIntMacro(m, F_ULOCK)) return -1;
|
||||
if (F_TEST && PyModule_AddIntMacro(m, F_TEST)) return -1;
|
||||
|
||||
#ifdef HAVE_SPAWNV
|
||||
|
@ -12196,7 +11935,6 @@ all_ins(PyObject *m)
|
|||
if (PyModule_AddIntConstant(m, "P_DETACH", _P_DETACH)) return -1;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SCHED_H
|
||||
#ifdef SCHED_OTHER
|
||||
if (PyModule_AddIntMacro(m, SCHED_OTHER)) return -1;
|
||||
#endif
|
||||
|
@ -12230,7 +11968,6 @@ all_ins(PyObject *m)
|
|||
#ifdef SCHED_FX
|
||||
if (PyModule_AddIntConstant(m, "SCHED_FX", SCHED_FSS)) return -1;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef USE_XATTRS
|
||||
if (PyModule_AddIntMacro(m, XATTR_CREATE)) return -1;
|
||||
|
@ -12262,6 +11999,8 @@ all_ins(PyObject *m)
|
|||
|
||||
if (PyModule_AddIntMacro(m, GRND_RANDOM)) return -1;
|
||||
if (PyModule_AddIntMacro(m, GRND_NONBLOCK)) return -1;
|
||||
if (PyModule_AddIntMacro(m, GRND_NORDRND)) return -1;
|
||||
if (PyModule_AddIntMacro(m, GRND_NOSYSTEM)) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
99
third_party/python/Modules/selectmodule.c
vendored
99
third_party/python/Modules/selectmodule.c
vendored
|
@ -5,10 +5,15 @@
|
|||
│ https://docs.python.org/3/license.html │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nt/efi.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/sock/epoll.h"
|
||||
#include "libc/sock/select.h"
|
||||
#include "libc/sock/sock.h"
|
||||
#include "libc/sysv/consts/epoll.h"
|
||||
#include "libc/sysv/consts/poll.h"
|
||||
#include "third_party/python/Include/abstract.h"
|
||||
#include "third_party/python/Include/boolobject.h"
|
||||
|
@ -24,6 +29,7 @@
|
|||
#include "third_party/python/Include/pymem.h"
|
||||
#include "third_party/python/Include/pytime.h"
|
||||
#include "third_party/python/Include/structmember.h"
|
||||
#include "third_party/python/pyconfig.h"
|
||||
/* clang-format off */
|
||||
|
||||
/* select - Module containing unix select(2) call.
|
||||
|
@ -150,27 +156,10 @@ set2list(fd_set *set, pylist fd2obj[FD_SETSIZE + 1])
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#undef SELECT_USES_HEAP
|
||||
#if FD_SETSIZE > 1024
|
||||
#define SELECT_USES_HEAP
|
||||
#endif /* FD_SETSIZE > 1024 */
|
||||
|
||||
static PyObject *
|
||||
select_select(PyObject *self, PyObject *args)
|
||||
{
|
||||
#ifdef SELECT_USES_HEAP
|
||||
pylist *rfd2obj, *wfd2obj, *efd2obj;
|
||||
#else /* !SELECT_USES_HEAP */
|
||||
/* XXX: All this should probably be implemented as follows:
|
||||
* - find the highest descriptor we're interested in
|
||||
* - add one
|
||||
* - that's the size
|
||||
* See: Stevens, APitUE, $12.5.1
|
||||
*/
|
||||
pylist rfd2obj[FD_SETSIZE + 1];
|
||||
pylist wfd2obj[FD_SETSIZE + 1];
|
||||
pylist efd2obj[FD_SETSIZE + 1];
|
||||
#endif /* SELECT_USES_HEAP */
|
||||
PyObject *ifdlist, *ofdlist, *efdlist;
|
||||
PyObject *ret = NULL;
|
||||
PyObject *timeout_obj = Py_None;
|
||||
|
@ -206,7 +195,6 @@ select_select(PyObject *self, PyObject *args)
|
|||
tvp = &tv;
|
||||
}
|
||||
|
||||
#ifdef SELECT_USES_HEAP
|
||||
/* Allocate memory for the lists */
|
||||
rfd2obj = PyMem_NEW(pylist, FD_SETSIZE + 1);
|
||||
wfd2obj = PyMem_NEW(pylist, FD_SETSIZE + 1);
|
||||
|
@ -217,7 +205,6 @@ select_select(PyObject *self, PyObject *args)
|
|||
if (efd2obj) PyMem_DEL(efd2obj);
|
||||
return PyErr_NoMemory();
|
||||
}
|
||||
#endif /* SELECT_USES_HEAP */
|
||||
|
||||
/* Convert sequences to fd_sets, and get maximum fd number
|
||||
* propagates the Python exception set in seq2set()
|
||||
|
@ -298,11 +285,9 @@ select_select(PyObject *self, PyObject *args)
|
|||
reap_obj(rfd2obj);
|
||||
reap_obj(wfd2obj);
|
||||
reap_obj(efd2obj);
|
||||
#ifdef SELECT_USES_HEAP
|
||||
PyMem_DEL(rfd2obj);
|
||||
PyMem_DEL(wfd2obj);
|
||||
PyMem_DEL(efd2obj);
|
||||
#endif /* SELECT_USES_HEAP */
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1198,12 +1183,6 @@ static int select_have_broken_poll(void)
|
|||
* Inspired by Twisted's _epoll.pyx and select.poll()
|
||||
*/
|
||||
|
||||
#ifdef HAVE_SYS_EPOLL_H
|
||||
#include "libc/sysv/consts/epoll.h"
|
||||
#include "libc/sysv/consts/nr.h"
|
||||
#include "libc/sock/epoll.h"
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
SOCKET epfd; /* epoll control file descriptor */
|
||||
|
@ -2476,51 +2455,29 @@ PyInit_select(void)
|
|||
#endif
|
||||
|
||||
#ifdef HAVE_EPOLL
|
||||
Py_TYPE(&pyEpoll_Type) = &PyType_Type;
|
||||
if (PyType_Ready(&pyEpoll_Type) < 0)
|
||||
return NULL;
|
||||
|
||||
Py_INCREF(&pyEpoll_Type);
|
||||
PyModule_AddObject(m, "epoll", (PyObject *) &pyEpoll_Type);
|
||||
|
||||
PyModule_AddIntMacro(m, EPOLLIN);
|
||||
PyModule_AddIntMacro(m, EPOLLOUT);
|
||||
PyModule_AddIntMacro(m, EPOLLPRI);
|
||||
PyModule_AddIntMacro(m, EPOLLERR);
|
||||
PyModule_AddIntMacro(m, EPOLLHUP);
|
||||
#ifdef EPOLLRDHUP
|
||||
/* Kernel 2.6.17 */
|
||||
PyModule_AddIntMacro(m, EPOLLRDHUP);
|
||||
if (IsLinux() || IsWindows()) {
|
||||
Py_TYPE(&pyEpoll_Type) = &PyType_Type;
|
||||
if (PyType_Ready(&pyEpoll_Type) < 0)
|
||||
return NULL;
|
||||
Py_INCREF(&pyEpoll_Type);
|
||||
PyModule_AddObject(m, "epoll", (PyObject *)&pyEpoll_Type);
|
||||
PyModule_AddIntMacro(m, EPOLLIN);
|
||||
PyModule_AddIntMacro(m, EPOLLOUT);
|
||||
PyModule_AddIntMacro(m, EPOLLPRI);
|
||||
PyModule_AddIntMacro(m, EPOLLERR);
|
||||
PyModule_AddIntMacro(m, EPOLLHUP);
|
||||
PyModule_AddIntMacro(m, EPOLLET);
|
||||
PyModule_AddIntMacro(m, EPOLLEXCLUSIVE);
|
||||
PyModule_AddIntMacro(m, EPOLLRDNORM);
|
||||
PyModule_AddIntMacro(m, EPOLLRDBAND);
|
||||
PyModule_AddIntMacro(m, EPOLLWRNORM);
|
||||
PyModule_AddIntMacro(m, EPOLLWRBAND);
|
||||
PyModule_AddIntMacro(m, EPOLLMSG);
|
||||
PyModule_AddIntMacro(m, EPOLL_CLOEXEC);
|
||||
PyModule_AddIntMacro(m, EPOLLONESHOT);
|
||||
PyModule_AddIntMacro(m, EPOLLRDHUP);
|
||||
}
|
||||
#endif
|
||||
PyModule_AddIntMacro(m, EPOLLET);
|
||||
#ifdef EPOLLONESHOT
|
||||
/* Kernel 2.6.2+ */
|
||||
PyModule_AddIntMacro(m, EPOLLONESHOT);
|
||||
#endif
|
||||
#ifdef EPOLLEXCLUSIVE
|
||||
PyModule_AddIntMacro(m, EPOLLEXCLUSIVE);
|
||||
#endif
|
||||
|
||||
#ifdef EPOLLRDNORM
|
||||
PyModule_AddIntMacro(m, EPOLLRDNORM);
|
||||
#endif
|
||||
#ifdef EPOLLRDBAND
|
||||
PyModule_AddIntMacro(m, EPOLLRDBAND);
|
||||
#endif
|
||||
#ifdef EPOLLWRNORM
|
||||
PyModule_AddIntMacro(m, EPOLLWRNORM);
|
||||
#endif
|
||||
#ifdef EPOLLWRBAND
|
||||
PyModule_AddIntMacro(m, EPOLLWRBAND);
|
||||
#endif
|
||||
#ifdef EPOLLMSG
|
||||
PyModule_AddIntMacro(m, EPOLLMSG);
|
||||
#endif
|
||||
|
||||
#ifdef EPOLL_CLOEXEC
|
||||
PyModule_AddIntMacro(m, EPOLL_CLOEXEC);
|
||||
#endif
|
||||
#endif /* HAVE_EPOLL */
|
||||
|
||||
#ifdef HAVE_KQUEUE
|
||||
kqueue_event_Type.tp_new = PyType_GenericNew;
|
||||
|
|
26
third_party/python/Modules/socketmodule.c
vendored
26
third_party/python/Modules/socketmodule.c
vendored
|
@ -5,6 +5,7 @@
|
|||
│ https://docs.python.org/3/license.html │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/ioctl.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/dns/dns.h"
|
||||
|
@ -15,6 +16,7 @@
|
|||
#include "libc/sysv/consts/af.h"
|
||||
#include "libc/sysv/consts/f.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "libc/sysv/consts/fio.h"
|
||||
#include "libc/sysv/consts/inaddr.h"
|
||||
#include "libc/sysv/consts/ip.h"
|
||||
#include "libc/sysv/consts/ipport.h"
|
||||
|
@ -478,29 +480,9 @@ internal_setblocking(PySocketSockObject *s, int block)
|
|||
#endif
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
#ifndef MS_WINDOWS
|
||||
#if (defined(HAVE_SYS_IOCTL_H) && defined(FIONBIO))
|
||||
block = !block;
|
||||
if (ioctl(s->sock_fd, FIONBIO, (unsigned int *)&block) == -1)
|
||||
goto done;
|
||||
#else
|
||||
delay_flag = fcntl(s->sock_fd, F_GETFL, 0);
|
||||
if (delay_flag == -1)
|
||||
goto done;
|
||||
if (block)
|
||||
new_delay_flag = delay_flag & (~O_NONBLOCK);
|
||||
else
|
||||
new_delay_flag = delay_flag | O_NONBLOCK;
|
||||
if (new_delay_flag != delay_flag)
|
||||
if (fcntl(s->sock_fd, F_SETFL, new_delay_flag) == -1)
|
||||
goto done;
|
||||
#endif
|
||||
#else /* MS_WINDOWS */
|
||||
arg = !block;
|
||||
if (ioctlsocket(s->sock_fd, FIONBIO, &arg) != 0)
|
||||
goto done;
|
||||
#endif /* MS_WINDOWS */
|
||||
|
||||
result = 0;
|
||||
|
||||
done:
|
||||
|
@ -6947,10 +6929,14 @@ PyInit__socket(void)
|
|||
if (TCP_QUICKACK) PyModule_AddIntMacro(m, TCP_QUICKACK);
|
||||
if (TCP_CONGESTION) PyModule_AddIntMacro(m, TCP_CONGESTION);
|
||||
if (TCP_USER_TIMEOUT) PyModule_AddIntMacro(m, TCP_USER_TIMEOUT);
|
||||
if (TCP_SAVE_SYN) PyModule_AddIntMacro(m, TCP_SAVE_SYN);
|
||||
if (TCP_SAVED_SYN) PyModule_AddIntMacro(m, TCP_SAVED_SYN);
|
||||
if (TCP_KEEPCNT && (!IsWindows() || NtGetVersion() >= 10))
|
||||
PyModule_AddIntMacro(m, TCP_KEEPCNT);
|
||||
if (TCP_FASTOPEN && (!IsWindows() || NtGetVersion() >= 10))
|
||||
PyModule_AddIntMacro(m, TCP_FASTOPEN);
|
||||
if (TCP_FASTOPEN_CONNECT)
|
||||
PyModule_AddIntMacro(m, TCP_FASTOPEN_CONNECT);
|
||||
|
||||
#ifdef IPX_TYPE
|
||||
/* IPX options */
|
||||
|
|
115
third_party/python/Modules/termios.c
vendored
115
third_party/python/Modules/termios.c
vendored
|
@ -11,6 +11,7 @@
|
|||
#include "libc/sysv/consts/baud.h"
|
||||
#include "libc/sysv/consts/fio.h"
|
||||
#include "libc/sysv/consts/modem.h"
|
||||
#include "libc/sysv/consts/pty.h"
|
||||
#include "libc/sysv/consts/termios.h"
|
||||
#include "third_party/python/Include/bytesobject.h"
|
||||
#include "third_party/python/Include/fileobject.h"
|
||||
|
@ -359,10 +360,8 @@ PyInit_termios(void)
|
|||
if (B57600) PyModule_AddIntConstant(m, "B57600", B57600);
|
||||
if (B115200) PyModule_AddIntConstant(m, "B115200", B115200);
|
||||
if (B230400) PyModule_AddIntConstant(m, "B230400", B230400);
|
||||
/* TODO(jart): B460800 */
|
||||
if (B500000) PyModule_AddIntConstant(m, "B500000", B500000);
|
||||
if (B576000) PyModule_AddIntConstant(m, "B576000", B576000);
|
||||
/* TODO(jart): B921600 */
|
||||
if (B1000000) PyModule_AddIntConstant(m, "B1000000", B1000000);
|
||||
if (B1152000) PyModule_AddIntConstant(m, "B1152000", B1152000);
|
||||
if (B1500000) PyModule_AddIntConstant(m, "B1500000", B1500000);
|
||||
|
@ -372,9 +371,13 @@ PyInit_termios(void)
|
|||
if (B3500000) PyModule_AddIntConstant(m, "B3500000", B3500000);
|
||||
if (B4000000) PyModule_AddIntConstant(m, "B4000000", B4000000);
|
||||
if (CBAUDEX) PyModule_AddIntConstant(m, "CBAUDEX", CBAUDEX);
|
||||
/* TODO(jart): B460800 */
|
||||
/* TODO(jart): B921600 */
|
||||
/* TODO(jart): B460800 */
|
||||
|
||||
PyModule_AddIntConstant(m, "TCSANOW", TCSANOW);
|
||||
if (TCSADRAIN) PyModule_AddIntConstant(m, "TCSADRAIN", TCSADRAIN);
|
||||
if (TCSAFLUSH) PyModule_AddIntConstant(m, "TCSAFLUSH", TCSAFLUSH);
|
||||
PyModule_AddIntConstant(m, "TCSADRAIN", TCSADRAIN);
|
||||
PyModule_AddIntConstant(m, "TCSAFLUSH", TCSAFLUSH);
|
||||
/* TODO(jart): TCSASOFT */
|
||||
if (TCIFLUSH) PyModule_AddIntConstant(m, "TCIFLUSH", TCIFLUSH);
|
||||
if (TCOFLUSH) PyModule_AddIntConstant(m, "TCOFLUSH", TCOFLUSH);
|
||||
|
@ -436,72 +439,74 @@ PyInit_termios(void)
|
|||
if (HUPCL) PyModule_AddIntConstant(m, "HUPCL", HUPCL);
|
||||
if (CLOCAL) PyModule_AddIntConstant(m, "CLOCAL", CLOCAL);
|
||||
if (CIBAUD) PyModule_AddIntConstant(m, "CIBAUD", CIBAUD);
|
||||
/* TODO(jart): CRTSCTS */
|
||||
if (CS5) PyModule_AddIntConstant(m, "CS5", CS5);
|
||||
if (CS6) PyModule_AddIntConstant(m, "CS6", CS6);
|
||||
if (CS7) PyModule_AddIntConstant(m, "CS7", CS7);
|
||||
if (CS8) PyModule_AddIntConstant(m, "CS8", CS8);
|
||||
if (ISIG) PyModule_AddIntConstant(m, "ISIG", ISIG);
|
||||
if (ICANON) PyModule_AddIntConstant(m, "ICANON", ICANON);
|
||||
PyModule_AddIntConstant(m, "ISIG", ISIG);
|
||||
PyModule_AddIntConstant(m, "ICANON", ICANON);
|
||||
if (XCASE) PyModule_AddIntConstant(m, "XCASE", XCASE);
|
||||
if (ECHO) PyModule_AddIntConstant(m, "ECHO", ECHO);
|
||||
if (ECHOE) PyModule_AddIntConstant(m, "ECHOE", ECHOE);
|
||||
if (ECHOK) PyModule_AddIntConstant(m, "ECHOK", ECHOK);
|
||||
if (ECHONL) PyModule_AddIntConstant(m, "ECHONL", ECHONL);
|
||||
if (ECHOCTL) PyModule_AddIntConstant(m, "ECHOCTL", ECHOCTL);
|
||||
if (ECHOPRT) PyModule_AddIntConstant(m, "ECHOPRT", ECHOPRT);
|
||||
if (ECHOKE) PyModule_AddIntConstant(m, "ECHOKE", ECHOKE);
|
||||
if (FLUSHO) PyModule_AddIntConstant(m, "FLUSHO", FLUSHO);
|
||||
if (NOFLSH) PyModule_AddIntConstant(m, "NOFLSH", NOFLSH);
|
||||
if (TOSTOP) PyModule_AddIntConstant(m, "TOSTOP", TOSTOP);
|
||||
if (PENDIN) PyModule_AddIntConstant(m, "PENDIN", PENDIN);
|
||||
if (IEXTEN) PyModule_AddIntConstant(m, "IEXTEN", IEXTEN);
|
||||
if (VINTR) PyModule_AddIntConstant(m, "VINTR", VINTR);
|
||||
if (VQUIT) PyModule_AddIntConstant(m, "VQUIT", VQUIT);
|
||||
if (VERASE) PyModule_AddIntConstant(m, "VERASE", VERASE);
|
||||
if (VKILL) PyModule_AddIntConstant(m, "VKILL", VKILL);
|
||||
if (VEOF) PyModule_AddIntConstant(m, "VEOF", VEOF);
|
||||
if (VTIME) PyModule_AddIntConstant(m, "VTIME", VTIME);
|
||||
if (VMIN) PyModule_AddIntConstant(m, "VMIN", VMIN);
|
||||
if (VSTART) PyModule_AddIntConstant(m, "VSTART", VSTART);
|
||||
if (VSTOP) PyModule_AddIntConstant(m, "VSTOP", VSTOP);
|
||||
if (VSUSP) PyModule_AddIntConstant(m, "VSUSP", VSUSP);
|
||||
if (VEOL) PyModule_AddIntConstant(m, "VEOL", VEOL);
|
||||
if (VREPRINT) PyModule_AddIntConstant(m, "VREPRINT", VREPRINT);
|
||||
if (VDISCARD) PyModule_AddIntConstant(m, "VDISCARD", VDISCARD);
|
||||
if (VWERASE) PyModule_AddIntConstant(m, "VWERASE", VWERASE);
|
||||
if (VLNEXT) PyModule_AddIntConstant(m, "VLNEXT", VLNEXT);
|
||||
if (VEOL2) PyModule_AddIntConstant(m, "VEOL2", VEOL2);
|
||||
/* TODO(jart): B460800 */
|
||||
PyModule_AddIntConstant(m, "ECHO", ECHO);
|
||||
PyModule_AddIntConstant(m, "ECHOE", ECHOE);
|
||||
PyModule_AddIntConstant(m, "ECHOK", ECHOK);
|
||||
PyModule_AddIntConstant(m, "ECHONL", ECHONL);
|
||||
PyModule_AddIntConstant(m, "ECHOCTL", ECHOCTL);
|
||||
PyModule_AddIntConstant(m, "ECHOPRT", ECHOPRT);
|
||||
PyModule_AddIntConstant(m, "ECHOKE", ECHOKE);
|
||||
PyModule_AddIntConstant(m, "FLUSHO", FLUSHO);
|
||||
PyModule_AddIntConstant(m, "NOFLSH", NOFLSH);
|
||||
PyModule_AddIntConstant(m, "TOSTOP", TOSTOP);
|
||||
PyModule_AddIntConstant(m, "PENDIN", PENDIN);
|
||||
PyModule_AddIntConstant(m, "IEXTEN", IEXTEN);
|
||||
|
||||
/* TODO(jart): CRTSCTS */
|
||||
|
||||
/* termios.c_cc[𝑖] */
|
||||
PyModule_AddIntConstant(m, "VINTR", VINTR);
|
||||
PyModule_AddIntConstant(m, "VQUIT", VQUIT);
|
||||
PyModule_AddIntConstant(m, "VERASE", VERASE);
|
||||
PyModule_AddIntConstant(m, "VKILL", VKILL);
|
||||
PyModule_AddIntConstant(m, "VEOF", VEOF);
|
||||
PyModule_AddIntConstant(m, "VTIME", VTIME);
|
||||
PyModule_AddIntConstant(m, "VMIN", VMIN);
|
||||
if (VSWTC) PyModule_AddIntConstant(m, "VSWTC", VSWTC);
|
||||
PyModule_AddIntConstant(m, "VSTART", VSTART);
|
||||
PyModule_AddIntConstant(m, "VSTOP", VSTOP);
|
||||
PyModule_AddIntConstant(m, "VSUSP", VSUSP);
|
||||
PyModule_AddIntConstant(m, "VEOL", VEOL);
|
||||
PyModule_AddIntConstant(m, "VREPRINT", VREPRINT);
|
||||
PyModule_AddIntConstant(m, "VDISCARD", VDISCARD);
|
||||
PyModule_AddIntConstant(m, "VWERASE", VWERASE);
|
||||
PyModule_AddIntConstant(m, "VLNEXT", VLNEXT);
|
||||
PyModule_AddIntConstant(m, "VEOL2", VEOL2);
|
||||
if (CBAUD) PyModule_AddIntConstant(m, "CBAUD", CBAUD);
|
||||
/* TODO(jart): CDEL */
|
||||
|
||||
/* <sys/ttydefaults.h> */
|
||||
PyModule_AddIntConstant(m, "CEOF", CEOF);
|
||||
PyModule_AddIntConstant(m, "CDSUSP", CDSUSP);
|
||||
PyModule_AddIntConstant(m, "CEOL", CEOL);
|
||||
PyModule_AddIntConstant(m, "CFLUSH", CFLUSH);
|
||||
PyModule_AddIntConstant(m, "CINTR", CINTR);
|
||||
/* TODO(jart): CEOL2 */
|
||||
/* TODO(jart): CEOT */
|
||||
/* TODO(jart): CERASE */
|
||||
/* TODO(jart): CESC */
|
||||
/* TODO(jart): CKILL */
|
||||
/* TODO(jart): CLNEXT */
|
||||
/* TODO(jart): CNUL */
|
||||
/* TODO(jart): COMMON */
|
||||
PyModule_AddIntConstant(m, "CKILL", CKILL);
|
||||
PyModule_AddIntConstant(m, "CLNEXT", CLNEXT);
|
||||
PyModule_AddIntConstant(m, "CEOT", CEOT);
|
||||
PyModule_AddIntConstant(m, "CERASE", CERASE);
|
||||
PyModule_AddIntConstant(m, "CQUIT", CQUIT);
|
||||
PyModule_AddIntConstant(m, "CRPRNT", CRPRNT);
|
||||
PyModule_AddIntConstant(m, "CSTART", CSTART);
|
||||
PyModule_AddIntConstant(m, "CSTOP", CSTOP);
|
||||
PyModule_AddIntConstant(m, "CSUSP", CSUSP);
|
||||
PyModule_AddIntConstant(m, "CWERASE", CWERASE);
|
||||
|
||||
/* ioctl */
|
||||
PyModule_AddIntConstant(m, "FIOCLEX", FIOCLEX);
|
||||
PyModule_AddIntConstant(m, "FIONCLEX", FIONCLEX);
|
||||
/* TODO(jart): CSWTCH */
|
||||
if (CWERASE) PyModule_AddIntConstant(m, "CWERASE", CWERASE);
|
||||
/* TODO(jart): EXTA */
|
||||
/* TODO(jart): EXTB */
|
||||
/* TODO(jart): FIOASYNC */
|
||||
/* TODO(jart): FIONBIO */
|
||||
/* TODO(jart): FIONREAD */
|
||||
PyModule_AddIntConstant(m, "FIONBIO", FIONBIO);
|
||||
PyModule_AddIntConstant(m, "FIONREAD", FIONREAD);
|
||||
PyModule_AddIntConstant(m, "FIOASYNC", FIOASYNC);
|
||||
if (EXTA) PyModule_AddIntConstant(m, "EXTA", EXTA);
|
||||
if (EXTB) PyModule_AddIntConstant(m, "EXTB", EXTB);
|
||||
|
||||
/* TODO(jart): IBSHIFT */
|
||||
/* TODO(jart): CC */
|
||||
/* TODO(jart): MASK */
|
||||
|
@ -533,7 +538,8 @@ PyInit_termios(void)
|
|||
if (TIOCGPGRP) PyModule_AddIntConstant(m, "TIOCGPGRP", TIOCGPGRP);
|
||||
/* TODO(jart): TIOCGSERIAL */
|
||||
/* TODO(jart): TIOCGSOFTCAR */
|
||||
if (TIOCGWINSZ) PyModule_AddIntConstant(m, "TIOCGWINSZ", TIOCGWINSZ);
|
||||
PyModule_AddIntConstant(m, "TIOCGWINSZ", TIOCGWINSZ);
|
||||
PyModule_AddIntConstant(m, "TIOCSWINSZ", TIOCSWINSZ);
|
||||
/* TODO(jart): TIOCINQ */
|
||||
/* TODO(jart): TIOCLINUX */
|
||||
if (TIOCMBIC) PyModule_AddIntConstant(m, "TIOCMBIC", TIOCMBIC);
|
||||
|
@ -555,7 +561,7 @@ PyInit_termios(void)
|
|||
if (TIOCNOTTY) PyModule_AddIntConstant(m, "TIOCNOTTY", TIOCNOTTY);
|
||||
if (TIOCNXCL) PyModule_AddIntConstant(m, "TIOCNXCL", TIOCNXCL);
|
||||
if (TIOCOUTQ) PyModule_AddIntConstant(m, "TIOCOUTQ", TIOCOUTQ);
|
||||
/* TODO(jart): TIOCPKT */
|
||||
if (TIOCPKT != -1) PyModule_AddIntConstant(m, "TIOCPKT", TIOCPKT);
|
||||
/* TODO(jart): DATA */
|
||||
/* TODO(jart): DOSTOP */
|
||||
/* TODO(jart): FLUSHREAD */
|
||||
|
@ -578,7 +584,6 @@ PyInit_termios(void)
|
|||
/* TODO(jart): TIOCSSERIAL */
|
||||
/* TODO(jart): TIOCSSOFTCAR */
|
||||
if (TIOCSTI) PyModule_AddIntConstant(m, "TIOCSTI", TIOCSTI);
|
||||
if (TIOCSWINSZ) PyModule_AddIntConstant(m, "TIOCSWINSZ", TIOCSWINSZ);
|
||||
/* TODO(jart): TIOCTTYGSTRUCT */
|
||||
|
||||
return m;
|
||||
|
|
193
third_party/python/Modules/timemodule.c
vendored
193
third_party/python/Modules/timemodule.c
vendored
|
@ -8,8 +8,14 @@
|
|||
#include "libc/calls/struct/rusage.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/calls/struct/tms.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/nt/accounting.h"
|
||||
#include "libc/nt/runtime.h"
|
||||
#include "libc/runtime/clktck.h"
|
||||
#include "libc/sock/select.h"
|
||||
#include "libc/sysv/consts/clock.h"
|
||||
#include "libc/sysv/consts/rusage.h"
|
||||
#include "libc/time/struct/tm.h"
|
||||
#include "libc/time/time.h"
|
||||
|
@ -31,8 +37,6 @@
|
|||
#include "third_party/python/pyconfig.h"
|
||||
/* clang-format off */
|
||||
|
||||
/* Time module */
|
||||
|
||||
typedef int clockid_t;
|
||||
#undef HAVE_CLOCK_SETTIME
|
||||
|
||||
|
@ -52,16 +56,8 @@ PyDoc_STRVAR(time_doc,
|
|||
Return the current time in seconds since the Epoch.\n\
|
||||
Fractions of a second may be present if the system clock provides them.");
|
||||
|
||||
#if defined(HAVE_CLOCK)
|
||||
|
||||
#ifndef CLOCKS_PER_SEC
|
||||
#ifdef CLK_TCK
|
||||
#ifdef HAVE_CLOCK
|
||||
#define CLOCKS_PER_SEC CLK_TCK
|
||||
#else
|
||||
#define CLOCKS_PER_SEC 1000000
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static PyObject *
|
||||
floatclock(_Py_clock_info_t *info)
|
||||
{
|
||||
|
@ -94,7 +90,6 @@ win_perf_counter(_Py_clock_info_t *info)
|
|||
static LONGLONG ctrStart;
|
||||
LARGE_INTEGER now;
|
||||
double diff;
|
||||
|
||||
if (cpu_frequency == 0) {
|
||||
LARGE_INTEGER freq;
|
||||
QueryPerformanceCounter(&now);
|
||||
|
@ -150,10 +145,8 @@ time_clock_gettime(PyObject *self, PyObject *args)
|
|||
int ret;
|
||||
int clk_id;
|
||||
struct timespec tp;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i:clock_gettime", &clk_id))
|
||||
return NULL;
|
||||
|
||||
ret = clock_gettime((clockid_t)clk_id, &tp);
|
||||
if (ret != 0) {
|
||||
PyErr_SetFromErrno(PyExc_OSError);
|
||||
|
@ -208,16 +201,13 @@ time_clock_getres(PyObject *self, PyObject *args)
|
|||
int ret;
|
||||
int clk_id;
|
||||
struct timespec tp;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i:clock_getres", &clk_id))
|
||||
return NULL;
|
||||
|
||||
ret = clock_getres((clockid_t)clk_id, &tp);
|
||||
if (ret != 0) {
|
||||
PyErr_SetFromErrno(PyExc_OSError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return PyFloat_FromDouble(tp.tv_sec + tp.tv_nsec * 1e-9);
|
||||
}
|
||||
|
||||
|
@ -331,7 +321,6 @@ parse_time_t_args(PyObject *args, const char *format, time_t *pwhen)
|
|||
{
|
||||
PyObject *ot = NULL;
|
||||
time_t whent;
|
||||
|
||||
if (!PyArg_ParseTuple(args, format, &ot))
|
||||
return 0;
|
||||
if (ot == NULL || ot == Py_None) {
|
||||
|
@ -350,10 +339,8 @@ time_gmtime(PyObject *self, PyObject *args)
|
|||
{
|
||||
time_t when;
|
||||
struct tm buf;
|
||||
|
||||
if (!parse_time_t_args(args, "|O:gmtime", &when))
|
||||
return NULL;
|
||||
|
||||
errno = 0;
|
||||
if (_PyTime_gmtime(when, &buf) != 0)
|
||||
return NULL;
|
||||
|
@ -392,7 +379,6 @@ time_localtime(PyObject *self, PyObject *args)
|
|||
{
|
||||
time_t when;
|
||||
struct tm buf;
|
||||
|
||||
if (!parse_time_t_args(args, "|O:localtime", &when))
|
||||
return NULL;
|
||||
if (_PyTime_localtime(when, &buf) != 0)
|
||||
|
@ -733,7 +719,6 @@ time_strptime(PyObject *self, PyObject *args)
|
|||
PyObject *strptime_module = PyImport_ImportModuleNoBlock("_strptime");
|
||||
PyObject *strptime_result;
|
||||
_Py_IDENTIFIER(_strptime_time);
|
||||
|
||||
if (!strptime_module)
|
||||
return NULL;
|
||||
strptime_result = _PyObject_CallMethodId(strptime_module,
|
||||
|
@ -742,7 +727,6 @@ time_strptime(PyObject *self, PyObject *args)
|
|||
return strptime_result;
|
||||
}
|
||||
|
||||
|
||||
PyDoc_STRVAR(strptime_doc,
|
||||
"strptime(string, format) -> struct_time\n\
|
||||
\n\
|
||||
|
@ -777,14 +761,12 @@ time_asctime(PyObject *self, PyObject *args)
|
|||
{
|
||||
PyObject *tup = NULL;
|
||||
struct tm buf;
|
||||
|
||||
if (!PyArg_UnpackTuple(args, "asctime", 0, 1, &tup))
|
||||
return NULL;
|
||||
if (tup == NULL) {
|
||||
time_t tt = time(NULL);
|
||||
if (_PyTime_localtime(tt, &buf) != 0)
|
||||
return NULL;
|
||||
|
||||
} else if (!gettmarg(tup, &buf) || !checktm(&buf))
|
||||
return NULL;
|
||||
return _asctime(&buf);
|
||||
|
@ -954,70 +936,50 @@ Performance counter for benchmarking.");
|
|||
static PyObject*
|
||||
py_process_time(_Py_clock_info_t *info)
|
||||
{
|
||||
#if defined(MS_WINDOWS)
|
||||
HANDLE process;
|
||||
FILETIME creation_time, exit_time, kernel_time, user_time;
|
||||
ULARGE_INTEGER large;
|
||||
bool32 ok;
|
||||
double total;
|
||||
BOOL ok;
|
||||
|
||||
process = GetCurrentProcess();
|
||||
ok = GetProcessTimes(process, &creation_time, &exit_time, &kernel_time, &user_time);
|
||||
if (!ok)
|
||||
return PyErr_SetFromWindowsErr(0);
|
||||
|
||||
large.u.LowPart = kernel_time.dwLowDateTime;
|
||||
large.u.HighPart = kernel_time.dwHighDateTime;
|
||||
total = (double)large.QuadPart;
|
||||
large.u.LowPart = user_time.dwLowDateTime;
|
||||
large.u.HighPart = user_time.dwHighDateTime;
|
||||
total += (double)large.QuadPart;
|
||||
if (info) {
|
||||
info->implementation = "GetProcessTimes()";
|
||||
info->resolution = 1e-7;
|
||||
info->monotonic = 1;
|
||||
info->adjustable = 0;
|
||||
}
|
||||
return PyFloat_FromDouble(total * 1e-7);
|
||||
#else
|
||||
|
||||
#if defined(HAVE_SYS_RESOURCE_H)
|
||||
struct rusage ru;
|
||||
#endif
|
||||
#ifdef HAVE_TIMES
|
||||
struct tms t;
|
||||
static long ticks_per_second = -1;
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_CLOCK_GETTIME) \
|
||||
&& (defined(CLOCK_PROCESS_CPUTIME_ID) || defined(CLOCK_PROF))
|
||||
struct timespec tp;
|
||||
#ifdef CLOCK_PROF
|
||||
const clockid_t clk_id = CLOCK_PROF;
|
||||
const char *function = "clock_gettime(CLOCK_PROF)";
|
||||
#else
|
||||
const clockid_t clk_id = CLOCK_PROCESS_CPUTIME_ID;
|
||||
const char *function = "clock_gettime(CLOCK_PROCESS_CPUTIME_ID)";
|
||||
#endif
|
||||
|
||||
if (clock_gettime(clk_id, &tp) == 0) {
|
||||
int64_t process;
|
||||
clockid_t clk_id;
|
||||
struct rusage ru;
|
||||
const char *function;
|
||||
struct timespec tp, res;
|
||||
struct NtFileTime creation_time, exit_time, kernel_time, user_time;
|
||||
if (IsWindows()) {
|
||||
process = GetCurrentProcess();
|
||||
ok = GetProcessTimes(process, &creation_time, &exit_time, &kernel_time, &user_time);
|
||||
if (!ok) return PyErr_SetFromErrno(PyExc_OSError);
|
||||
total = ReadFileTime(kernel_time) + ReadFileTime(user_time);
|
||||
if (info) {
|
||||
struct timespec res;
|
||||
info->implementation = function;
|
||||
info->implementation = "GetProcessTimes()";
|
||||
info->resolution = 1e-7;
|
||||
info->monotonic = 1;
|
||||
info->adjustable = 0;
|
||||
if (clock_getres(clk_id, &res) == 0)
|
||||
info->resolution = res.tv_sec + res.tv_nsec * 1e-9;
|
||||
else
|
||||
info->resolution = 1e-9;
|
||||
}
|
||||
return PyFloat_FromDouble(tp.tv_sec + tp.tv_nsec * 1e-9);
|
||||
return PyFloat_FromDouble(total * 1e-7);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SYS_RESOURCE_H)
|
||||
if (getrusage(RUSAGE_SELF, &ru) == 0) {
|
||||
double total;
|
||||
if (CLOCK_PROF != -1 || CLOCK_PROCESS_CPUTIME_ID != -1) {
|
||||
if (CLOCK_PROF != -1) {
|
||||
clk_id = CLOCK_PROF;
|
||||
function = "clock_gettime(CLOCK_PROF)";
|
||||
} else {
|
||||
clk_id = CLOCK_PROCESS_CPUTIME_ID;
|
||||
function = "clock_gettime(CLOCK_PROCESS_CPUTIME_ID)";
|
||||
}
|
||||
if (!clock_gettime(clk_id, &tp)) {
|
||||
if (info) {
|
||||
info->implementation = function;
|
||||
info->monotonic = 1;
|
||||
info->adjustable = 0;
|
||||
if (clock_getres(clk_id, &res) == 0)
|
||||
info->resolution = res.tv_sec + res.tv_nsec * 1e-9;
|
||||
else
|
||||
info->resolution = 1e-9;
|
||||
}
|
||||
return PyFloat_FromDouble(tp.tv_sec + tp.tv_nsec * 1e-9);
|
||||
}
|
||||
}
|
||||
if (!getrusage(RUSAGE_SELF, &ru)) {
|
||||
total = ru.ru_utime.tv_sec + ru.ru_utime.tv_usec * 1e-6;
|
||||
total += ru.ru_stime.tv_sec + ru.ru_stime.tv_usec * 1e-6;
|
||||
if (info) {
|
||||
|
@ -1028,41 +990,19 @@ py_process_time(_Py_clock_info_t *info)
|
|||
}
|
||||
return PyFloat_FromDouble(total);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_TIMES
|
||||
if (times(&t) != (clock_t)-1) {
|
||||
double total;
|
||||
|
||||
if (ticks_per_second == -1) {
|
||||
#if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)
|
||||
ticks_per_second = sysconf(_SC_CLK_TCK);
|
||||
if (ticks_per_second < 1)
|
||||
ticks_per_second = -1;
|
||||
#elif defined(HZ)
|
||||
ticks_per_second = HZ;
|
||||
#else
|
||||
ticks_per_second = 60; /* magic fallback value; may be bogus */
|
||||
#endif
|
||||
}
|
||||
|
||||
if (ticks_per_second != -1) {
|
||||
total = (double)t.tms_utime / ticks_per_second;
|
||||
total += (double)t.tms_stime / ticks_per_second;
|
||||
if (info) {
|
||||
info->implementation = "times()";
|
||||
info->monotonic = 1;
|
||||
info->adjustable = 0;
|
||||
info->resolution = 1.0 / ticks_per_second;
|
||||
}
|
||||
return PyFloat_FromDouble(total);
|
||||
if (times(&t) != -1) {
|
||||
total = (double)t.tms_utime / CLK_TCK;
|
||||
total += (double)t.tms_stime / CLK_TCK;
|
||||
if (info) {
|
||||
info->implementation = "times()";
|
||||
info->monotonic = 1;
|
||||
info->adjustable = 0;
|
||||
info->resolution = 1.0 / CLK_TCK;
|
||||
}
|
||||
return PyFloat_FromDouble(total);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Currently, Python 3 requires clock() to build: see issue #22624 */
|
||||
return floatclock(info);
|
||||
#endif
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
@ -1391,28 +1331,11 @@ PyInit_time(void)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_CLOCK_SETTIME) || defined(HAVE_CLOCK_GETRES)
|
||||
|
||||
#ifdef CLOCK_REALTIME
|
||||
PyModule_AddIntMacro(m, CLOCK_REALTIME);
|
||||
#endif
|
||||
#ifdef CLOCK_MONOTONIC
|
||||
PyModule_AddIntMacro(m, CLOCK_MONOTONIC);
|
||||
#endif
|
||||
#ifdef CLOCK_MONOTONIC_RAW
|
||||
PyModule_AddIntMacro(m, CLOCK_MONOTONIC_RAW);
|
||||
#endif
|
||||
#ifdef CLOCK_HIGHRES
|
||||
PyModule_AddIntMacro(m, CLOCK_HIGHRES);
|
||||
#endif
|
||||
#ifdef CLOCK_PROCESS_CPUTIME_ID
|
||||
PyModule_AddIntMacro(m, CLOCK_PROCESS_CPUTIME_ID);
|
||||
#endif
|
||||
#ifdef CLOCK_THREAD_CPUTIME_ID
|
||||
PyModule_AddIntMacro(m, CLOCK_THREAD_CPUTIME_ID);
|
||||
#endif
|
||||
|
||||
#endif /* defined(HAVE_CLOCK_GETTIME) || defined(HAVE_CLOCK_SETTIME) || defined(HAVE_CLOCK_GETRES) */
|
||||
if (CLOCK_MONOTONIC_RAW != -1) PyModule_AddIntMacro(m, CLOCK_MONOTONIC_RAW);
|
||||
if (CLOCK_PROCESS_CPUTIME_ID != -1) PyModule_AddIntMacro(m, CLOCK_PROCESS_CPUTIME_ID);
|
||||
if (CLOCK_THREAD_CPUTIME_ID != -1) PyModule_AddIntMacro(m, CLOCK_THREAD_CPUTIME_ID);
|
||||
|
||||
if (!initialized) {
|
||||
if (PyStructSequence_InitType2(&StructTimeType,
|
||||
|
@ -1458,8 +1381,8 @@ pysleep(_PyTime_t secs)
|
|||
#else
|
||||
_PyTime_t millisecs;
|
||||
unsigned long ul_millis;
|
||||
DWORD rc;
|
||||
HANDLE hInterruptEvent;
|
||||
uint32_t rc;
|
||||
int64_t hInterruptEvent;
|
||||
#endif
|
||||
|
||||
deadline = _PyTime_GetMonotonicClock() + secs;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue