mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 22:02:27 +00:00
Begin incorporating Python unit tests into build
We now build a separate APE binary for each test so they can run in parallel. We've got 148 tests running fast and stable so far.
This commit is contained in:
parent
51904e2687
commit
b5f743cdc3
121 changed files with 4995 additions and 4767 deletions
59
third_party/python/Python/initmain.c
vendored
Normal file
59
third_party/python/Python/initmain.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/dictobject.h"
|
||||
#include "third_party/python/Include/import.h"
|
||||
#include "third_party/python/Include/pyerrors.h"
|
||||
#include "third_party/python/Include/pylifecycle.h"
|
||||
#include "third_party/python/Include/pystate.h"
|
||||
#include "third_party/python/Include/yoink.h"
|
||||
/* clang-format off */
|
||||
|
||||
PYTHON_PROVIDE("__main__");
|
||||
|
||||
void
|
||||
_Py_InitMain(PyInterpreterState *interp)
|
||||
{
|
||||
PyObject *m, *d, *loader, *ann_dict;
|
||||
m = PyImport_AddModule("__main__");
|
||||
if (m == NULL)
|
||||
Py_FatalError("can't create __main__ module");
|
||||
d = PyModule_GetDict(m);
|
||||
ann_dict = PyDict_New();
|
||||
if ((ann_dict == NULL) ||
|
||||
(PyDict_SetItemString(d, "__annotations__", ann_dict) < 0)) {
|
||||
Py_FatalError("Failed to initialize __main__.__annotations__");
|
||||
}
|
||||
Py_DECREF(ann_dict);
|
||||
if (PyDict_GetItemString(d, "__builtins__") == NULL) {
|
||||
PyObject *bimod = PyImport_ImportModule("builtins");
|
||||
if (bimod == NULL) {
|
||||
Py_FatalError("Failed to retrieve builtins module");
|
||||
}
|
||||
if (PyDict_SetItemString(d, "__builtins__", bimod) < 0) {
|
||||
Py_FatalError("Failed to initialize __main__.__builtins__");
|
||||
}
|
||||
Py_DECREF(bimod);
|
||||
}
|
||||
/* Main is a little special - imp.is_builtin("__main__") will return
|
||||
* False, but BuiltinImporter is still the most appropriate initial
|
||||
* setting for its __loader__ attribute. A more suitable value will
|
||||
* be set if __main__ gets further initialized later in the startup
|
||||
* process.
|
||||
*/
|
||||
loader = PyDict_GetItemString(d, "__loader__");
|
||||
if (loader == NULL || loader == Py_None) {
|
||||
PyObject *loader = PyObject_GetAttrString(interp->importlib,
|
||||
"BuiltinImporter");
|
||||
if (loader == NULL) {
|
||||
Py_FatalError("Failed to retrieve BuiltinImporter");
|
||||
}
|
||||
if (PyDict_SetItemString(d, "__loader__", loader) < 0) {
|
||||
Py_FatalError("Failed to initialize __main__.__loader__");
|
||||
}
|
||||
Py_DECREF(loader);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue