mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-01 08:48:29 +00:00
Improve Python tree-shaking
This commit is contained in:
parent
5bb2275788
commit
4f41f2184d
169 changed files with 4182 additions and 2411 deletions
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/copyfile.h"
|
||||
|
@ -107,6 +108,7 @@ bool no_sanitize_null;
|
|||
bool no_sanitize_alignment;
|
||||
bool no_sanitize_pointer_overflow;
|
||||
|
||||
char *err;
|
||||
char *cmd;
|
||||
char *comdbg;
|
||||
char *cachedcmd;
|
||||
|
@ -338,13 +340,6 @@ int Launch(struct rusage *ru) {
|
|||
return ws;
|
||||
}
|
||||
|
||||
char *GetResourceReport(struct rusage *ru) {
|
||||
char *report = 0;
|
||||
appendf(&report, "\n");
|
||||
AppendResourceReport(&report, ru, "\n");
|
||||
return report;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
size_t n;
|
||||
char *p, **envp;
|
||||
|
@ -673,21 +668,28 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
return 0;
|
||||
} else {
|
||||
p = xasprintf("%s%s %s %d%s: %.*s%s\n", RED2, DescribeCommand(),
|
||||
"exited with", WEXITSTATUS(ws), RESET, command.n, command.p,
|
||||
GetResourceReport(&ru));
|
||||
appendf(&err, "%s%s %s %d%s: ", RED2, DescribeCommand(), "exited with",
|
||||
WEXITSTATUS(ws), RESET);
|
||||
rc = WEXITSTATUS(ws);
|
||||
}
|
||||
} else {
|
||||
p = xasprintf("%s%s %s %s%s: %.*s%s\n", RED2, DescribeCommand(),
|
||||
"terminated by", strsignal(WTERMSIG(ws)), RESET, command.n,
|
||||
command.p, GetResourceReport(&ru));
|
||||
appendf(&err, "%s%s %s %s%s: ", RED2, DescribeCommand(), "terminated by",
|
||||
strsignal(WTERMSIG(ws)), RESET);
|
||||
rc = 128 + WTERMSIG(ws);
|
||||
}
|
||||
|
||||
/*
|
||||
* print full command in the event of error
|
||||
* print command in the event of error
|
||||
*/
|
||||
write(2, p, strlen(p));
|
||||
if (command.n > 2048) {
|
||||
appendd(&err, command.p, 2048);
|
||||
appendw(&err, READ32LE("..."));
|
||||
} else {
|
||||
appendd(&err, command.p, command.n);
|
||||
}
|
||||
appendw(&err, '\n');
|
||||
AppendResourceReport(&err, &ru, "\n");
|
||||
appendw(&err, '\n');
|
||||
write(2, err, appendz(err).i);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -134,3 +134,25 @@ size_t internobj(struct Interner *t, const void *data, size_t size) {
|
|||
size_t intern(struct Interner *t, const char *s) {
|
||||
return internobj(t, s, strlen(s) + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if string is interned.
|
||||
*/
|
||||
bool isinterned(struct Interner *t, const char *s) {
|
||||
unsigned hash;
|
||||
size_t i, n, step;
|
||||
struct InternerObject *it;
|
||||
step = 0;
|
||||
n = strlen(s) + 1;
|
||||
hash = max(1, crc32c(0, s, n));
|
||||
it = (struct InternerObject *)t;
|
||||
do {
|
||||
i = (hash + step * ((step + 1) >> 1)) & (it->n - 1);
|
||||
if (it->p[i].hash == hash && it->p[i].index + n <= it->pool.n &&
|
||||
!memcmp(s, &it->pool.p[it->p[i].index], n)) {
|
||||
return true;
|
||||
}
|
||||
step++;
|
||||
} while (it->p[i].hash);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ void freeinterner(struct Interner *);
|
|||
size_t interncount(const struct Interner *) paramsnonnull();
|
||||
size_t internobj(struct Interner *, const void *, size_t) paramsnonnull();
|
||||
size_t intern(struct Interner *, const char *) paramsnonnull();
|
||||
bool isinterned(struct Interner *, const char *) paramsnonnull();
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue