mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-27 04:50:28 +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
60
third_party/python/Python/flushstdfiles.c
vendored
Normal file
60
third_party/python/Python/flushstdfiles.c
vendored
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*-*- 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/object.h"
|
||||
#include "third_party/python/Include/pyerrors.h"
|
||||
#include "third_party/python/Include/pylifecycle.h"
|
||||
#include "third_party/python/Include/sysmodule.h"
|
||||
/* clang-format off */
|
||||
|
||||
_Py_IDENTIFIER(flush);
|
||||
_Py_IDENTIFIER(stdout);
|
||||
_Py_IDENTIFIER(stderr);
|
||||
|
||||
static int
|
||||
file_is_closed(PyObject *fobj)
|
||||
{
|
||||
int r;
|
||||
PyObject *tmp = PyObject_GetAttrString(fobj, "closed");
|
||||
if (tmp == NULL) {
|
||||
PyErr_Clear();
|
||||
return 0;
|
||||
}
|
||||
r = PyObject_IsTrue(tmp);
|
||||
Py_DECREF(tmp);
|
||||
if (r < 0)
|
||||
PyErr_Clear();
|
||||
return r > 0;
|
||||
}
|
||||
|
||||
int
|
||||
_Py_FlushStdFiles(void)
|
||||
{
|
||||
PyObject *fout = _PySys_GetObjectId(&PyId_stdout);
|
||||
PyObject *ferr = _PySys_GetObjectId(&PyId_stderr);
|
||||
PyObject *tmp;
|
||||
int status = 0;
|
||||
if (fout != NULL && fout != Py_None && !file_is_closed(fout)) {
|
||||
tmp = _PyObject_CallMethodId(fout, &PyId_flush, NULL);
|
||||
if (tmp == NULL) {
|
||||
PyErr_WriteUnraisable(fout);
|
||||
status = -1;
|
||||
}
|
||||
else
|
||||
Py_DECREF(tmp);
|
||||
}
|
||||
if (ferr != NULL && ferr != Py_None && !file_is_closed(ferr)) {
|
||||
tmp = _PyObject_CallMethodId(ferr, &PyId_flush, NULL);
|
||||
if (tmp == NULL) {
|
||||
PyErr_Clear();
|
||||
status = -1;
|
||||
}
|
||||
else
|
||||
Py_DECREF(tmp);
|
||||
}
|
||||
return status;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue