mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-30 06:20:28 +00:00
Pay off more technical debt
This makes breaking changes to add underscores to many non-standard function names provided by the c library. MODE=tiny is now tinier and we now use smaller locks that are better for tiny apps in this mode. Some headers have been renamed to be in the same folder as the build package, so it'll be easier to know which build dependency is needed. Certain old misguided interfaces have been removed. Intel intrinsics headers are now listed in libc/isystem (but not in the amalgamation) to help further improve open source compatibility. Header complexity has also been reduced. Lastly, more shell scripts are now available.
This commit is contained in:
parent
b69f3d2488
commit
6f7d0cb1c3
960 changed files with 4072 additions and 4873 deletions
123
libc/log/log.h
123
libc/log/log.h
|
@ -1,13 +1,5 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_LOG_LOG_H_
|
||||
#define COSMOPOLITAN_LIBC_LOG_LOG_H_
|
||||
#include "libc/calls/struct/rusage.h"
|
||||
#include "libc/calls/struct/sigset.h"
|
||||
#include "libc/calls/struct/winsize.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/likely.h"
|
||||
#include "libc/nexgen32e/stackframe.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
#define kLogFatal 0
|
||||
|
@ -31,6 +23,12 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef TINY
|
||||
#define _LOG_TINY 1
|
||||
#else
|
||||
#define _LOG_TINY 0
|
||||
#endif
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
|
@ -38,31 +36,25 @@ extern FILE *__log_file;
|
|||
|
||||
int __watch(void *, size_t);
|
||||
void __die(void) relegated wontreturn; /* print backtrace and abort() */
|
||||
void meminfo(int); /* shows malloc statistics &c. */
|
||||
void memsummary(int); /* light version of same thing */
|
||||
uint16_t getttycols(uint16_t);
|
||||
int getttysize(int, struct winsize *) paramsnonnull();
|
||||
void _meminfo(int); /* shows malloc statistics &c. */
|
||||
void _memsummary(int); /* light version of same thing */
|
||||
bool IsTerminalInarticulate(void) nosideeffect;
|
||||
const char *commandvenv(const char *, const char *);
|
||||
const char *GetAddr2linePath(void);
|
||||
const char *GetGdbPath(void);
|
||||
const char *GetCallerName(const struct StackFrame *);
|
||||
|
||||
void ShowCrashReports(void);
|
||||
void callexitontermination(struct sigset *);
|
||||
bool32 IsDebuggerPresent(bool);
|
||||
bool IsRunningUnderMake(void);
|
||||
const char *GetSiCodeName(int, int);
|
||||
void AppendResourceReport(char **, struct rusage *, const char *);
|
||||
char *__get_symbol_by_addr(int64_t);
|
||||
char *GetSymbolByAddr(int64_t);
|
||||
void PrintGarbage(void);
|
||||
void PrintGarbageNumeric(FILE *);
|
||||
void CheckForMemoryLeaks(void);
|
||||
|
||||
#define showcrashreports() ShowCrashReports()
|
||||
|
||||
#ifndef __STRICT_ANSI__
|
||||
|
||||
#define _LOG_UNLIKELY(x) __builtin_expect(!!(x), 0)
|
||||
|
||||
extern unsigned __log_level; /* log level for runtime check */
|
||||
|
||||
#define LOGGABLE(LEVEL) \
|
||||
|
@ -72,24 +64,22 @@ extern unsigned __log_level; /* log level for runtime check */
|
|||
// log a message with the specified log level (not checking if LOGGABLE)
|
||||
#define LOGF(LEVEL, FMT, ...) \
|
||||
do { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
flogf(LEVEL, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
|
||||
if (!IsTiny()) ++__ftrace; \
|
||||
if (!_LOG_TINY) _log_retrace(); \
|
||||
} while (0)
|
||||
|
||||
// report an error without backtrace and debugger invocation
|
||||
#define FATALF(FMT, ...) \
|
||||
do { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
flogf(kLogError, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
|
||||
__restorewintty(); \
|
||||
_Exit(1); \
|
||||
unreachable; \
|
||||
_log_exit(1); \
|
||||
} while (0)
|
||||
|
||||
#define DIEF(FMT, ...) \
|
||||
do { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
ffatalf(kLogFatal, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
|
||||
unreachable; \
|
||||
} while (0)
|
||||
|
@ -118,102 +108,105 @@ extern unsigned __log_level; /* log level for runtime check */
|
|||
#define VERBOSEF(FMT, ...) \
|
||||
do { \
|
||||
if (LOGGABLE(kLogVerbose)) { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
fverbosef(kLogVerbose, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
|
||||
if (!IsTiny()) ++__ftrace; \
|
||||
if (!_LOG_TINY) _log_retrace(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define DEBUGF(FMT, ...) \
|
||||
do { \
|
||||
if (UNLIKELY(LOGGABLE(kLogDebug))) { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
if (_LOG_UNLIKELY(LOGGABLE(kLogDebug))) { \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
fdebugf(kLogDebug, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
|
||||
if (!IsTiny()) ++__ftrace; \
|
||||
if (!_LOG_TINY) _log_retrace(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define NOISEF(FMT, ...) \
|
||||
do { \
|
||||
if (UNLIKELY(LOGGABLE(kLogNoise))) { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
if (_LOG_UNLIKELY(LOGGABLE(kLogNoise))) { \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
fnoisef(kLogNoise, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
|
||||
if (!IsTiny()) ++__ftrace; \
|
||||
if (!_LOG_TINY) _log_retrace(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define FLOGF(F, FMT, ...) \
|
||||
do { \
|
||||
if (LOGGABLE(kLogInfo)) { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
flogf(kLogInfo, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
|
||||
if (!IsTiny()) ++__ftrace; \
|
||||
if (!_LOG_TINY) _log_retrace(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define FWARNF(F, FMT, ...) \
|
||||
do { \
|
||||
if (LOGGABLE(kLogWarn)) { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
flogf(kLogWarn, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
|
||||
if (!IsTiny()) ++__ftrace; \
|
||||
if (!_LOG_TINY) _log_retrace(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define FFATALF(F, FMT, ...) \
|
||||
do { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
flogf(kLogError, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
|
||||
__restorewintty(); \
|
||||
_Exit(1); \
|
||||
unreachable; \
|
||||
_log_exit(1); \
|
||||
} while (0)
|
||||
|
||||
#define FDEBUGF(F, FMT, ...) \
|
||||
do { \
|
||||
if (UNLIKELY(LOGGABLE(kLogDebug))) { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
if (_LOG_UNLIKELY(LOGGABLE(kLogDebug))) { \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
fdebugf(kLogDebug, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
|
||||
if (!IsTiny()) ++__ftrace; \
|
||||
if (!_LOG_TINY) _log_retrace(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define FNOISEF(F, FMT, ...) \
|
||||
do { \
|
||||
if (UNLIKELY(LOGGABLE(kLogNoise))) { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
if (_LOG_UNLIKELY(LOGGABLE(kLogNoise))) { \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
fnoisef(kLogNoise, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
|
||||
if (!IsTiny()) ++__ftrace; \
|
||||
if (!_LOG_TINY) _log_retrace(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define LOGIFNEG1(FORM) \
|
||||
({ \
|
||||
int e = errno; \
|
||||
autotype(FORM) Ax = (FORM); \
|
||||
if (UNLIKELY(Ax == (typeof(Ax))(-1)) && LOGGABLE(kLogWarn)) { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
__logerrno(__FILE__, __LINE__, #FORM); \
|
||||
if (!IsTiny()) ++__ftrace; \
|
||||
errno = e; \
|
||||
} \
|
||||
Ax; \
|
||||
#define LOGIFNEG1(FORM) \
|
||||
({ \
|
||||
int e = _log_get_errno(); \
|
||||
autotype(FORM) Ax = (FORM); \
|
||||
if (_LOG_UNLIKELY(Ax == (typeof(Ax))(-1)) && LOGGABLE(kLogWarn)) { \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
_log_errno(__FILE__, __LINE__, #FORM); \
|
||||
if (!_LOG_TINY) _log_retrace(); \
|
||||
_log_set_errno(e); \
|
||||
} \
|
||||
Ax; \
|
||||
})
|
||||
|
||||
#define LOGIFNULL(FORM) \
|
||||
({ \
|
||||
int e = errno; \
|
||||
int e = _log_get_errno(); \
|
||||
autotype(FORM) Ax = (FORM); \
|
||||
if (Ax == NULL && LOGGABLE(kLogWarn)) { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
__logerrno(__FILE__, __LINE__, #FORM); \
|
||||
if (!IsTiny()) ++__ftrace; \
|
||||
errno = e; \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
_log_errno(__FILE__, __LINE__, #FORM); \
|
||||
if (!_LOG_TINY) _log_retrace(); \
|
||||
_log_set_errno(e); \
|
||||
} \
|
||||
Ax; \
|
||||
})
|
||||
|
||||
void __logerrno(const char *, int, const char *) relegated;
|
||||
void _log_errno(const char *, int, const char *) relegated;
|
||||
int _log_get_errno(void);
|
||||
void _log_set_errno(int);
|
||||
void _log_untrace(void);
|
||||
void _log_retrace(void);
|
||||
void _log_exit(int) wontreturn;
|
||||
|
||||
#define ARGS unsigned, const char *, int, FILE *, const char *
|
||||
#define ATTR paramsnonnull((5)) printfesque(5)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue