mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-30 16:28:30 +00:00
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:
parent
e2b3c3618e
commit
0d748ad58e
571 changed files with 1306 additions and 1888 deletions
|
@ -94,7 +94,6 @@ void makecontext(ucontext_t *uc, void func(), int argc, ...) {
|
|||
va_list va;
|
||||
long sp, sb;
|
||||
struct Gadget *call;
|
||||
struct StackFrame *sf;
|
||||
|
||||
// allocate call
|
||||
sp = sb = (long)uc->uc_stack.ss_sp;
|
||||
|
|
|
@ -86,8 +86,8 @@ static char *_mktls_below(struct CosmoTib **out_tib) {
|
|||
|
||||
static char *_mktls_above(struct CosmoTib **out_tib) {
|
||||
size_t hiz, siz;
|
||||
struct CosmoTib *tib;
|
||||
char *mem, *dtv, *tls;
|
||||
struct CosmoTib *tib, *old;
|
||||
|
||||
// allocate memory for tdata, tbss, and tib
|
||||
hiz = ROUNDUP(sizeof(*tib) + 2 * sizeof(void *), I(_tls_align));
|
||||
|
|
|
@ -47,7 +47,6 @@ static void _pthread_purge(void) {
|
|||
|
||||
static void _pthread_onfork(int i) {
|
||||
struct AtFork *a;
|
||||
struct PosixThread *pt;
|
||||
unassert(0 <= i && i <= 2);
|
||||
if (!i) pthread_spin_lock(&_atforks.lock);
|
||||
for (a = _atforks.list; a; a = a->p[!i]) {
|
||||
|
@ -91,7 +90,7 @@ void _pthread_onfork_child(void) {
|
|||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
pthread_mutex_init(&__mmi_lock_obj, &attr);
|
||||
pthread_mutex_init(&__fds_lock_obj, &attr);
|
||||
pthread_spin_init(&_pthread_lock, 0);
|
||||
(void)pthread_spin_init(&_pthread_lock, 0);
|
||||
|
||||
// call user-supplied forked child callbacks
|
||||
_pthread_onfork(2);
|
||||
|
|
|
@ -343,7 +343,6 @@ void pthread_testcancel(void) {
|
|||
* in masked mode when the calling thread has been cancelled
|
||||
*/
|
||||
errno_t pthread_testcancel_np(void) {
|
||||
int rc;
|
||||
struct PosixThread *pt;
|
||||
if (!__tls_enabled) return 0;
|
||||
if (!(pt = (struct PosixThread *)__get_tls()->tib_pthread)) return 0;
|
||||
|
|
|
@ -74,14 +74,12 @@ void _pthread_free(struct PosixThread *pt) {
|
|||
void pthread_kill_siblings_np(void) {
|
||||
struct Dll *e, *e2;
|
||||
struct PosixThread *pt, *self;
|
||||
enum PosixThreadStatus status;
|
||||
self = (struct PosixThread *)__get_tls()->tib_pthread;
|
||||
pthread_spin_lock(&_pthread_lock);
|
||||
for (e = dll_first(_pthread_list); e; e = e2) {
|
||||
e2 = dll_next(_pthread_list, e);
|
||||
pt = POSIXTHREAD_CONTAINER(e);
|
||||
if (pt != self) {
|
||||
status = atomic_load_explicit(&pt->status, memory_order_acquire);
|
||||
pthread_kill((pthread_t)pt, SIGKILL);
|
||||
dll_remove(&_pthread_list, e);
|
||||
pthread_spin_unlock(&_pthread_lock);
|
||||
|
@ -95,7 +93,6 @@ static int PosixThread(void *arg, int tid) {
|
|||
void *rc;
|
||||
struct sigaltstack ss;
|
||||
struct PosixThread *pt = arg;
|
||||
enum PosixThreadStatus status;
|
||||
unassert(__get_tls()->tib_tid > 0);
|
||||
if (pt->altstack) {
|
||||
ss.ss_flags = 0;
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "libc/thread/tls.h"
|
||||
|
||||
void _pthread_ungarbage(void) {
|
||||
int i;
|
||||
struct Garbages *g;
|
||||
struct CosmoTib *tib;
|
||||
tib = __get_tls();
|
||||
|
|
|
@ -136,7 +136,7 @@ static struct Semaphore *sem_open_reopen(const char *path) {
|
|||
|
||||
static struct Semaphore *sem_open_get(const sem_t *sem,
|
||||
struct Semaphore ***out_prev) {
|
||||
struct Semaphore *s, *t, **p;
|
||||
struct Semaphore *s, **p;
|
||||
for (p = &g_semaphores.list, s = *p; s; p = &s->next, s = s->next) {
|
||||
if (s && sem == s->sem) {
|
||||
*out_prev = p;
|
||||
|
@ -176,9 +176,10 @@ static struct Semaphore *sem_open_get(const sem_t *sem,
|
|||
sem_t *sem_open(const char *name, int oflag, ...) {
|
||||
sem_t *sem;
|
||||
va_list va;
|
||||
const char *path;
|
||||
struct Semaphore *s;
|
||||
char pathbuf[PATH_MAX];
|
||||
unsigned mode = 0, value = 0;
|
||||
char *path, pathbuf[PATH_MAX];
|
||||
if (oflag & ~(O_CREAT | O_EXCL)) {
|
||||
einval();
|
||||
return SEM_FAILED;
|
||||
|
@ -300,9 +301,10 @@ int sem_close(sem_t *sem) {
|
|||
* @raise ENAMETOOLONG if too long
|
||||
*/
|
||||
int sem_unlink(const char *name) {
|
||||
const char *path;
|
||||
int rc, e = errno;
|
||||
struct Semaphore *s;
|
||||
char *path, pathbuf[PATH_MAX];
|
||||
char pathbuf[PATH_MAX];
|
||||
if (!(path = sem_path_np(name, pathbuf, sizeof(pathbuf)))) return -1;
|
||||
if ((rc = unlink(path)) == -1 && IsWindows() && errno == EACCES) {
|
||||
sem_open_init();
|
||||
|
|
|
@ -53,7 +53,6 @@ static void sem_timedwait_cleanup(void *arg) {
|
|||
*/
|
||||
int sem_timedwait(sem_t *sem, const struct timespec *abstime) {
|
||||
int e, i, v, rc;
|
||||
struct timespec ts;
|
||||
|
||||
e = errno;
|
||||
for (i = 0; i < 7; ++i) {
|
||||
|
|
|
@ -218,11 +218,12 @@ void pthread_testcancel(void);
|
|||
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 && \
|
||||
!defined(__STRICT_ANSI__) && !defined(MODE_DBG)
|
||||
extern const errno_t EBUSY;
|
||||
#define pthread_spin_lock(pSpin) \
|
||||
({ \
|
||||
pthread_spinlock_t *_s = pSpin; \
|
||||
while (__atomic_test_and_set(&_s->_lock, __ATOMIC_ACQUIRE)) donothing; \
|
||||
0; \
|
||||
#define pthread_spin_lock(pSpin) \
|
||||
({ \
|
||||
pthread_spinlock_t *_s = pSpin; \
|
||||
while (__atomic_test_and_set(&_s->_lock, __ATOMIC_ACQUIRE)) { \
|
||||
} \
|
||||
0; \
|
||||
})
|
||||
#define pthread_spin_unlock(pSpin) \
|
||||
({ \
|
||||
|
|
|
@ -12,7 +12,7 @@ COSMOPOLITAN_C_START_
|
|||
* This should be favored over __get_tls() for .privileged code that
|
||||
* can't be self-modified by __enable_tls().
|
||||
*/
|
||||
privileged static inline struct CosmoTib *__get_tls_privileged(void) {
|
||||
__funline struct CosmoTib *__get_tls_privileged(void) {
|
||||
char *tib, *lin = (char *)0x30;
|
||||
if (IsLinux() || IsFreebsd() || IsNetbsd() || IsOpenbsd() || IsMetal()) {
|
||||
asm("mov\t%%fs:(%1),%0" : "=a"(tib) : "r"(lin) : "memory");
|
|
@ -41,7 +41,7 @@
|
|||
* @raise EBUSY if `abstime` was specified and deadline expired
|
||||
* @cancellationpoint
|
||||
*/
|
||||
errno_t _wait0(const atomic_int *ctid, struct timespec *abstime) {
|
||||
errno_t _wait0(atomic_int *ctid, struct timespec *abstime) {
|
||||
int x, e, rc = 0;
|
||||
// "The behavior is undefined if the value specified by the thread
|
||||
// argument to pthread_join() refers to the calling thread."
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_INTRIN_WAIT0_H_
|
||||
#define COSMOPOLITAN_LIBC_INTRIN_WAIT0_H_
|
||||
#include "libc/atomic.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
errno_t _wait0(const atomic_int *, struct timespec *);
|
||||
errno_t _wait0(_Atomic(int) *, struct timespec *);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue