Fix warnings

This change fixes Cosmopolitan so it has fewer opinions about compiler
warnings. The whole repository had to be cleaned up to be buildable in
-Werror -Wall mode. This lets us benefit from things like strict const
checking. Some actual bugs might have been caught too.
This commit is contained in:
Justine Tunney 2023-09-01 20:49:13 -07:00
parent e2b3c3618e
commit 0d748ad58e
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
571 changed files with 1306 additions and 1888 deletions

View file

@ -5353,6 +5353,9 @@ dtrace_function_entry(PyFrameObject *f)
char* filename;
char* funcname;
int lineno;
(void)filename;
(void)funcname;
(void)lineno;
filename = PyUnicode_AsUTF8(f->f_code->co_filename);
funcname = PyUnicode_AsUTF8(f->f_code->co_name);
lineno = PyCode_Addr2Line(f->f_code, f->f_lasti);
@ -5365,6 +5368,9 @@ dtrace_function_return(PyFrameObject *f)
char* filename;
char* funcname;
int lineno;
(void)filename;
(void)funcname;
(void)lineno;
filename = PyUnicode_AsUTF8(f->f_code->co_filename);
funcname = PyUnicode_AsUTF8(f->f_code->co_name);
lineno = PyCode_Addr2Line(f->f_code, f->f_lasti);

View file

@ -100,13 +100,13 @@ cosmo_rdtsc(PyObject *self, PyObject *noargs)
return PyLong_FromUnsignedLong(rdtsc());
}
#ifdef __x86_64__
PyDoc_STRVAR(getcpucore_doc,
"getcpucore($module)\n\
--\n\n\
Returns 0-indexed CPU core on which process is currently scheduled.");
#ifdef __x86_64__
static PyObject *
cosmo_getcpucore(PyObject *self, PyObject *noargs)
{
@ -137,7 +137,6 @@ Similar to zlib.crc32().");
static PyObject *
cosmo_crc32c(PyObject *self, PyObject *args)
{
Py_ssize_t n;
Py_buffer data;
unsigned crc, init = 0;
if (!PyArg_ParseTuple(args, "y*|I:crc32c", &data, &init)) return 0;
@ -283,8 +282,6 @@ cosmo_exit1(PyObject *self, PyObject *args)
_Exit(1);
}
static bool ftrace_installed = 0;
typedef struct {
PyObject_HEAD
} FtracerObject;
@ -327,6 +324,7 @@ static PyTypeObject FtracerType = {
.tp_methods = FtracerObject_methods,
};
#ifdef FTRACE
PyDoc_STRVAR(ftrace_doc,
"ftrace($module)\n\
--\n\n\
@ -337,6 +335,7 @@ Enables logging of C function calls to stderr, e.g.\n\
\n\
Please be warned this prints massive amount of text. In order for it\n\
to work, the concomitant .com.dbg binary needs to be present.");
#endif
static PyObject *
cosmo_ftrace(PyObject *self, PyObject *noargs)

View file

@ -17,7 +17,6 @@
/* clang-format off */
_Py_IDENTIFIER(flush);
_Py_IDENTIFIER(stdout);
_Py_IDENTIFIER(stderr);
/* Import the site module (not into __main__ though) */

View file

@ -865,7 +865,7 @@ PyImport_ExecCodeModuleWithPathnames(const char *name, PyObject *co,
{
struct stat stinfo;
PyObject *m = NULL;
PyObject *nameobj, *pathobj = NULL, *cpathobj = NULL, *external= NULL;
PyObject *nameobj, *pathobj = NULL, *cpathobj = NULL;
nameobj = PyUnicode_FromString(name);
if (nameobj == NULL)
@ -1183,7 +1183,7 @@ _imp_create_builtin(PyObject *module, PyObject *spec)
res = bsearch(&key, Builtins_Lookup.entries, Builtins_Lookup.n, sizeof(initentry), cmp_initentry);
if (res != NULL) {
p = res->tab;
p = (void *)res->tab;
PyModuleDef *def;
if (p->initfunc == NULL) {
/* Cannot re-init internal module ("sys" or "builtins") */
@ -2491,7 +2491,6 @@ static PyObject *SFLObject_get_code(SourcelessFileLoader *self, PyObject *arg) {
FILE *fp = NULL;
PyObject *res = NULL;
char *rawbuf = NULL;
size_t rawlen = 0;
if (!PyArg_Parse(arg, "z:get_code", &name)) return 0;
if (!name) name = self->name;

View file

@ -30,7 +30,6 @@ _Py_InitImport(PyInterpreterState *interp, PyObject *sysmod)
{
PyObject *importlib;
PyObject *impmod;
PyObject *cosmomod;
PyObject *sys_modules;
PyObject *value;

View file

@ -4,6 +4,7 @@
Python 3
https://docs.python.org/3/license.html │
*/
#include "third_party/python/Include/pylifecycle.h"
#include "libc/assert.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
@ -13,8 +14,8 @@
#include "libc/log/log.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/consts/sig.h"
#include "libc/str/locale.h"
#include "libc/sysv/consts/sig.h"
#include "third_party/python/Include/Python-ast.h"
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/ast.h"
@ -37,7 +38,6 @@
#include "third_party/python/Include/parsetok.h"
#include "third_party/python/Include/pydebug.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pylifecycle.h"
#include "third_party/python/Include/pymem.h"
#include "third_party/python/Include/pystrcmp.h"
#include "third_party/python/Include/pytime.h"
@ -53,9 +53,6 @@
/* Python interpreter top-level routines, including init/exit */
_Py_IDENTIFIER(name);
_Py_IDENTIFIER(flush);
_Py_IDENTIFIER(stdout);
_Py_IDENTIFIER(stderr);
/* Forward */

View file

@ -11,8 +11,8 @@
#include "libc/fmt/conv.h"
#include "libc/macros.internal.h"
#include "libc/nexgen32e/rdtsc.h"
#include "libc/stdio/rand.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/rand.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/auxv.h"
#include "libc/sysv/consts/grnd.h"
@ -392,7 +392,6 @@ void
_PyRandom_Init(void)
{
char *env;
const unsigned char *auxrng;
unsigned char *secret = (unsigned char *)&_Py_HashSecret.uc;
Py_ssize_t secret_size = sizeof(_Py_HashSecret_t);
Py_BUILD_ASSERT(sizeof(_Py_HashSecret_t) == sizeof(_Py_HashSecret.uc));
@ -431,7 +430,7 @@ _PyRandom_Init(void)
}
else {
uint64_t x;
int res, i, j;
int i, j;
/* _PyRandom_Init() is called very early in the Python initialization
and so exceptions cannot be used (use raise=0).
_PyRandom_Init() must not block Python initialization: call

View file

@ -1026,11 +1026,6 @@ sys_getwindowsversion(PyObject *self)
int pos = 0;
PyObject *version;
struct NtOsVersionInfo ver;
uint32_t realMajor, realMinor, realBuild;
int64_t hKernel32;
wchar_t kernel32_path[PATH_MAX];
void *verblock;
uint32_t verblock_size;
if (!IsWindows()) {
PyErr_SetString(PyExc_SystemError, "this is not windows");
@ -1055,36 +1050,6 @@ sys_getwindowsversion(PyObject *self)
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wSuiteMask));
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wProductType));
realMajor = ver.dwMajorVersion;
realMinor = ver.dwMinorVersion;
realBuild = ver.dwBuildNumber;
#if 0 // todo(jart): port me
// GetVersion will lie if we are running in a compatibility mode.
// We need to read the version info from a system file resource
// to accurately identify the OS version. If we fail for any reason,
// just return whatever GetVersion said.
hKernel32 = GetModuleHandle("kernel32.dll");
if (hKernel32 && GetModuleFileNameW(hKernel32, kernel32_path, MAX_PATH) &&
(verblock_size = GetFileVersionInfoSizeW(kernel32_path, NULL)) &&
(verblock = PyMem_RawMalloc(verblock_size))) {
VS_FIXEDFILEINFO *ffi;
UINT ffi_len;
if (GetFileVersionInfoW(kernel32_path, 0, verblock_size, verblock) &&
VerQueryValueW(verblock, L"", (LPVOID)&ffi, &ffi_len)) {
realMajor = HIWORD(ffi->dwProductVersionMS);
realMinor = LOWORD(ffi->dwProductVersionMS);
realBuild = HIWORD(ffi->dwProductVersionLS);
}
PyMem_RawFree(verblock);
}
PyStructSequence_SET_ITEM(version, pos++, Py_BuildValue("(kkk)",
realMajor,
realMinor,
realBuild
));
#endif
if (PyErr_Occurred()) {
Py_DECREF(version);
return NULL;