diff --git a/ape/ape.S b/ape/ape.S index b59b31da3..ab8b1bfdf 100644 --- a/ape/ape.S +++ b/ape/ape.S @@ -545,6 +545,22 @@ apesh: .ascii "'\n#'\"\n" # sixth edition shebang // We prefer this because it's a tiny constant one time cost. // We simply printf a 64-byte header and call execve() again. .ascii "o=\"$(command -v \"$0\")\"\n" +#ifdef APE_BUILDSAFE +// This code is intended for binaries in build/bootstrap/. It +// causes them to not self-modify since they're checked-in to +// version control. It assumes cosmopolitan's build prefix is +// being used by convention and that the program has the noop +// flag -n which is used to prime the binary. + .ascii "if [ ${o##o/} = $o ]; then\n" + .ascii " if ! [ o/$o -nt $o ]; then\n" + .ascii " mkdir -p o/${o%/*} || exit\n" + .ascii " cp -f $o o/$o.$$ || exit\n" + .ascii " o/$o.$$ -n || exit\n" + .ascii " mv -f o/$o.$$ o/$o || exit\n" + .ascii " fi\n" + .ascii " exec o/$o \"$@\"\n" + .ascii "fi\n" +#endif #else // The alternative behavior is to copy to $TMPDIR and edit. // This imposes a variety of caveats of its own that should diff --git a/ape/ape.lds b/ape/ape.lds index 3a72d8170..794109bf4 100644 --- a/ape/ape.lds +++ b/ape/ape.lds @@ -201,6 +201,8 @@ SECTIONS { /* Real Mode */ KEEP(*(.head)) + KEEP(*(.apesh)) + KEEP(*(.head2)) KEEP(*(.text.head)) /* Executable & Linkable Format */ diff --git a/ape/ape.mk b/ape/ape.mk index 40903d127..0a75630b0 100644 --- a/ape/ape.mk +++ b/ape/ape.mk @@ -19,6 +19,11 @@ APE = $(APE_DEPS) \ $(APE_OBJS) \ o/$(MODE)/ape/ape.lds +APE_BUILDSAFE = \ + $(APE_DEPS) \ + o/$(MODE)/ape/ape-buildsafe.o \ + o/$(MODE)/ape/ape.lds + APELINK = \ $(COMPILE) \ -ALINK.ape \ @@ -49,6 +54,9 @@ $(APE_OBJS): $(BUILD_FILES) \ o/$(MODE)/ape/ape-no-modify-self.o: ape/ape.S @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -DAPE_NO_MODIFY_SELF $< +o/$(MODE)/ape/ape-buildsafe.o: ape/ape.S + @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -DAPE_BUILDSAFE $< + .PHONY: o/$(MODE)/ape o/$(MODE)/ape: $(APE) \ $(APE_CHECKS) \ diff --git a/build/bootstrap/compile.com b/build/bootstrap/compile.com index 179038020..48e4822ec 100755 Binary files a/build/bootstrap/compile.com and b/build/bootstrap/compile.com differ diff --git a/build/bootstrap/zipobj.com b/build/bootstrap/zipobj.com index bbe95476f..5947dda14 100755 Binary files a/build/bootstrap/zipobj.com and b/build/bootstrap/zipobj.com differ diff --git a/examples/getcpucount.c b/examples/getcpucount.c new file mode 100644 index 000000000..4ed429ad7 --- /dev/null +++ b/examples/getcpucount.c @@ -0,0 +1,25 @@ +#if 0 +/*─────────────────────────────────────────────────────────────────╗ +│ To the extent possible under law, Justine Tunney has waived │ +│ all copyright and related or neighboring rights to this file, │ +│ as it is written in the following disclaimers: │ +│ • http://unlicense.org/ │ +│ • http://creativecommons.org/publicdomain/zero/1.0/ │ +╚─────────────────────────────────────────────────────────────────*/ +#endif +#include "libc/calls/calls.h" +#include "libc/fmt/itoa.h" +#include "libc/runtime/sysconf.h" +#include "libc/stdio/stdio.h" + +int main(int argc, char *argv[]) { + int c, n; + char a[22]; + if ((c = GetCpuCount())) { + n = int64toarray_radix10(c, a); + a[n++] = '\n'; + return write(1, a, n) == n ? 0 : 1; + } else { + return 1; + } +} diff --git a/libc/calls/calls.h b/libc/calls/calls.h index 13dcf4954..e224f0351 100644 --- a/libc/calls/calls.h +++ b/libc/calls/calls.h @@ -84,6 +84,7 @@ int arch_prctl(); int chdir(const char *); int chmod(const char *, uint32_t); int chown(const char *, uint32_t, uint32_t); +int chroot(const char *); int close(int); int closedir(DIR *); int creat(const char *, uint32_t) nodiscard; @@ -100,6 +101,7 @@ int execvp(const char *, char *const[]) paramsnonnull(); int execvpe(const char *, char *const[], char *const[]) paramsnonnull(); int faccessat(int, const char *, int, uint32_t); int fadvise(int, uint64_t, uint64_t, int); +int fchdir(int); int fchmod(int, uint32_t) nothrow; int fchmodat(int, const char *, uint32_t, uint32_t); int fchown(int, uint32_t, uint32_t); @@ -115,13 +117,13 @@ int fsync(int); int ftruncate(int, int64_t); int getdomainname(char *, size_t); int gethostname(char *, size_t); +int getpid(void); int getppid(void); int getpriority(int, unsigned); int getrlimit(int, struct rlimit *); int getrusage(int, struct rusage *); int kill(int, int); int killpg(int, int); -int sigqueue(int, int, const union sigval); int link(const char *, const char *) nothrow; int linkat(int, const char *, int, const char *, uint32_t); int lstat(const char *, struct stat *); @@ -129,6 +131,7 @@ int madvise(void *, uint64_t, int); int mkdir(const char *, uint32_t); int mkdirat(int, const char *, uint32_t); int mkfifo(const char *, uint32_t); +int mkfifoat(int, const char *, uint32_t); int mknod(const char *, uint32_t, uint64_t); int mknodat(int, const char *, int32_t, uint64_t); int mlock(const void *, size_t); @@ -146,6 +149,7 @@ int pipe(int[hasatleast 2]); int pipe2(int[hasatleast 2], int); int posix_fadvise(int, uint64_t, uint64_t, int); int posix_madvise(void *, uint64_t, int); +int prctl(); int raise(int); int readlink(const char *, char *, size_t); int remove(const char *); @@ -171,11 +175,13 @@ int setuid(uint32_t); int sigaction(int, const struct sigaction *, struct sigaction *); int sigignore(int); int sigprocmask(int, const struct sigset *, struct sigset *); +int sigqueue(int, int, const union sigval); int sigsuspend(const struct sigset *); int stat(const char *, struct stat *); int symlink(const char *, const char *); int symlinkat(const char *, int, const char *); int sync_file_range(int, int64_t, int64_t, unsigned); +int sysctl(const int *, unsigned, void *, size_t *, void *, size_t); int sysinfo(struct sysinfo *); int touch(const char *, uint32_t); int truncate(const char *, uint64_t); @@ -189,21 +195,20 @@ int wait(int *); int wait3(int *, int, struct rusage *); int wait4(int, int *, int, struct rusage *); int waitpid(int, int *, int); -ssize_t lseek(int, int64_t, unsigned); -ssize_t pread(int, void *, size_t, int64_t); -ssize_t preadv(int, struct iovec *, int, int64_t); -ssize_t pwrite(int, const void *, size_t, int64_t); -ssize_t pwritev(int, const struct iovec *, int, int64_t); intptr_t syscall(int, ...); -void sync(void); +long ptrace(int, int, void *, void *); long telldir(DIR *); -int getpid(void); long times(struct tms *); sighandler_t signal(int, sighandler_t); size_t GetFileSize(const char *); size_t getfiledescriptorsize(int); ssize_t copy_file_range(int, long *, int, long *, size_t, uint32_t); ssize_t copyfd(int, int64_t *, int, int64_t *, size_t, uint32_t); +ssize_t lseek(int, int64_t, unsigned); +ssize_t pread(int, void *, size_t, int64_t); +ssize_t preadv(int, struct iovec *, int, int64_t); +ssize_t pwrite(int, const void *, size_t, int64_t); +ssize_t pwritev(int, const struct iovec *, int, int64_t); ssize_t read(int, void *, size_t); ssize_t readansi(int, char *, size_t); ssize_t readlinkat(int, const char *, char *, size_t); @@ -219,11 +224,8 @@ uint32_t getsid(int) nosideeffect; uint32_t gettid(void) nosideeffect; uint32_t getuid(void) nosideeffect; uint32_t umask(int32_t); -long ptrace(int, int, void *, void *); -int chroot(const char *); -int prctl(); -int sysctl(const int *, unsigned, void *, size_t *, void *, size_t); -int fchdir(int); +void rewinddir(DIR *); +void sync(void); /*───────────────────────────────────────────────────────────────────────────│─╗ │ cosmopolitan § system calls » formatting ─╬─│┼ diff --git a/libc/calls/cfgetispeed.c b/libc/calls/cfgetispeed.c new file mode 100644 index 000000000..14cc6ba23 --- /dev/null +++ b/libc/calls/cfgetispeed.c @@ -0,0 +1,25 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/termios.h" +#include "libc/sysv/consts/termios.h" + +uint32_t cfgetispeed(const struct termios *t) { + /* return t->c_cflag & CBAUD; */ /* ??? */ + return t->c_ispeed; +} diff --git a/libc/calls/cfgetospeed.c b/libc/calls/cfgetospeed.c new file mode 100644 index 000000000..8b57f02ca --- /dev/null +++ b/libc/calls/cfgetospeed.c @@ -0,0 +1,25 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/termios.h" +#include "libc/sysv/consts/termios.h" + +uint32_t cfgetospeed(const struct termios *t) { + /* return t->c_cflag & CBAUD; */ /* ??? */ + return t->c_ospeed; +} diff --git a/libc/calls/cfmakeraw.c b/libc/calls/cfmakeraw.c new file mode 100644 index 000000000..bb7ca1e9c --- /dev/null +++ b/libc/calls/cfmakeraw.c @@ -0,0 +1,31 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/termios.h" +#include "libc/sysv/consts/termios.h" + +void cfmakeraw(struct termios *t) { + t->c_iflag &= + ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); + t->c_oflag &= ~OPOST; + t->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); + t->c_cflag &= ~(CSIZE | PARENB); + t->c_cflag |= CS8; + t->c_cc[VMIN] = 1; + t->c_cc[VTIME] = 0; +} diff --git a/libc/calls/cfsetispeed.c b/libc/calls/cfsetispeed.c new file mode 100644 index 000000000..6e249b428 --- /dev/null +++ b/libc/calls/cfsetispeed.c @@ -0,0 +1,33 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/termios.h" +#include "libc/sysv/errfuns.h" + +int cfsetispeed(struct termios *t, int speed) { + if (speed) { + if (CBAUD) { + if (speed & ~CBAUD) return einval(); + t->c_cflag &= ~CBAUD; + t->c_cflag |= speed; + } else { + t->c_ispeed = speed; + } + } + return 0; +} diff --git a/libc/calls/cfsetospeed.c b/libc/calls/cfsetospeed.c new file mode 100644 index 000000000..5c2696c0d --- /dev/null +++ b/libc/calls/cfsetospeed.c @@ -0,0 +1,32 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/termios.h" +#include "libc/sysv/consts/termios.h" +#include "libc/sysv/errfuns.h" + +int cfsetospeed(struct termios *t, int speed) { + if (CBAUD) { + if (speed & ~CBAUD) return einval(); + t->c_cflag &= ~CBAUD; + t->c_cflag |= speed; + } else { + t->c_ospeed = speed; + } + return 0; +} diff --git a/libc/calls/fcntl-nt.c b/libc/calls/fcntl-nt.c index b7e563678..1d042fba2 100644 --- a/libc/calls/fcntl-nt.c +++ b/libc/calls/fcntl-nt.c @@ -16,6 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/bits/bits.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/calls/struct/flock.h" @@ -37,6 +38,40 @@ #include "libc/sysv/consts/o.h" #include "libc/sysv/errfuns.h" +static textwindows int sys_fcntl_nt_reservefd(int start) { + int fd; + for (;;) { + fd = start; + if (fd >= g_fds.n) { + if (__ensurefds(fd) == -1) return -1; + } + cmpxchg(&g_fds.f, fd, fd + 1); + if (cmpxchg(&g_fds.p[fd].kind, kFdEmpty, kFdReserved)) { + return fd; + } + } +} + +static textwindows int sys_fcntl_nt_dupfd(int oldfd, int cmd, int start) { + int newfd; + int64_t proc; + if ((newfd = sys_fcntl_nt_reservefd(start)) != -1) { + proc = GetCurrentProcess(); + if (DuplicateHandle(proc, g_fds.p[oldfd].handle, proc, + &g_fds.p[newfd].handle, 0, true, + kNtDuplicateSameAccess)) { + g_fds.p[newfd].kind = g_fds.p[oldfd].kind; + g_fds.p[newfd].flags = cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0; + return newfd; + } else { + __releasefd(newfd); + return __winerr(); + } + } else { + return -1; + } +} + static textwindows int sys_fcntl_nt_lock(struct Fd *f, int cmd, uintptr_t arg) { struct flock *l; uint32_t flags, err; @@ -123,6 +158,8 @@ textwindows int sys_fcntl_nt(int fd, int cmd, uintptr_t arg) { } } else if (cmd == F_SETLK || cmd == F_SETLKW) { return sys_fcntl_nt_lock(g_fds.p + fd, cmd, arg); + } else if (cmd == F_DUPFD || cmd == F_DUPFD_CLOEXEC) { + return sys_fcntl_nt_dupfd(fd, cmd, arg); } else { return einval(); } diff --git a/libc/calls/fstat-nt.c b/libc/calls/fstat-nt.c index eae334b08..41e1352db 100644 --- a/libc/calls/fstat-nt.c +++ b/libc/calls/fstat-nt.c @@ -63,6 +63,7 @@ textwindows int sys_fstat_nt(int64_t handle, struct stat *st) { st->st_size = (uint64_t)wst.nFileSizeHigh << 32 | wst.nFileSizeLow; st->st_blksize = PAGESIZE; st->st_dev = wst.dwVolumeSerialNumber; + st->st_rdev = wst.dwVolumeSerialNumber; st->st_ino = (uint64_t)wst.nFileIndexHigh << 32 | wst.nFileIndexLow; st->st_nlink = wst.nNumberOfLinks; if (GetFileInformationByHandleEx(handle, kNtFileCompressionInfo, &fci, diff --git a/libc/calls/internal.h b/libc/calls/internal.h index 03b439079..069809337 100644 --- a/libc/calls/internal.h +++ b/libc/calls/internal.h @@ -146,7 +146,7 @@ i32 sys_getppid(void) hidden; i32 sys_getpriority(i32, u32) hidden; i32 sys_getrlimit(i32, struct rlimit *) hidden; i32 sys_getrusage(i32, struct rusage *) hidden; -i32 sys_ioctl(i32, u64, void *) hidden; +i32 sys_ioctl(i32, u64, ...) hidden; i32 sys_kill(i32, i32, i32) hidden; i32 sys_linkat(i32, const char *, i32, const char *, i32) hidden; i32 sys_lseek(i32, i64, i64, i64) hidden; @@ -233,6 +233,14 @@ ssize_t WritevUninterruptible(int, struct iovec *, int); void flock2cosmo(uintptr_t); void cosmo2flock(uintptr_t); +int sys_sendfile_xnu(int32_t infd, int32_t outfd, int64_t offset, + int64_t *out_opt_sbytes, const void *opt_hdtr, + int32_t flags) asm("sys_sendfile") hidden; +int sys_sendfile_freebsd(int32_t infd, int32_t outfd, int64_t offset, + size_t nbytes, const void *opt_hdtr, + int64_t *out_opt_sbytes, + int32_t flags) asm("sys_sendfile") hidden; + /*───────────────────────────────────────────────────────────────────────────│─╗ │ cosmopolitan § syscalls » windows nt » veneers ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ diff --git a/libc/calls/ioctl.c b/libc/calls/ioctl.c index 258b1ba66..d52cdaf0d 100644 --- a/libc/calls/ioctl.c +++ b/libc/calls/ioctl.c @@ -27,7 +27,11 @@ * Controls settings on device. * @vforksafe */ -int(ioctl)(int fd, uint64_t request, void *memory) { - __IOCTL_DISPATCH(EQUAL, fd, request, memory); - return ioctl_default(fd, request, memory); +int(ioctl)(int fd, uint64_t request, ...) { + void *arg; + va_list va; + va_start(va, request); + arg = va_arg(va, void *); + va_end(va); + return __IOCTL_DISPATCH(EQUAL, -1, fd, request, arg); } diff --git a/libc/calls/ioctl.h b/libc/calls/ioctl.h index 81497bfab..7b2dedbd3 100644 --- a/libc/calls/ioctl.h +++ b/libc/calls/ioctl.h @@ -1,8 +1,9 @@ #ifndef COSMOPOLITAN_LIBC_CALLS_IOCTL_H_ #define COSMOPOLITAN_LIBC_CALLS_IOCTL_H_ #include "libc/macros.internal.h" -#include "libc/sysv/consts/termios.h" +#include "libc/sysv/consts/fio.h" #include "libc/sysv/consts/sio.h" +#include "libc/sysv/consts/termios.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ @@ -10,35 +11,55 @@ COSMOPOLITAN_C_START_ │ cosmopolitan § system calls » ioctl ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -int ioctl(int, uint64_t, void *); +int ioctl(int, uint64_t, ...); /*───────────────────────────────────────────────────────────────────────────│─╗ │ cosmopolitan § system calls » ioctl » undiamonding (size optimization) ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ #if defined(__GNUC__) && !defined(__STRICT_ANSI__) -#define ioctl(FD, REQUEST, MEMORY) ioctl_dispatch(FD, REQUEST, MEMORY) +#define ioctl(FD, REQUEST, ...) \ + __IOCTL_DISPATCH(__EQUIVALENT, ioctl_default(FD, REQUEST, ##__VA_ARGS__), \ + FD, REQUEST, ##__VA_ARGS__) #define __EQUIVALENT(X, Y) (__builtin_constant_p((X) == (Y)) && ((X) == (Y))) -#define __IOCTL_DISPATCH(CMP, FD, REQUEST, MEMORY) \ - do { \ - if (CMP(request, TIOCGWINSZ)) return ioctl_tiocgwinsz(FD, MEMORY); \ - if (CMP(request, TIOCSWINSZ)) return ioctl_tiocswinsz(FD, MEMORY); \ - if (CMP(request, TCGETS)) return ioctl_tcgets(FD, MEMORY); \ - if (CMP(request, TCSETS)) return ioctl_tcsets(FD, REQUEST, MEMORY); \ - if (CMP(request, TCSETSW)) return ioctl_tcsets(FD, REQUEST, MEMORY); \ - if (CMP(request, TCSETSF)) return ioctl_tcsets(FD, REQUEST, MEMORY); \ - if (CMP(request, SIOCGIFCONF)) return ioctl_siocgifconf(FD, MEMORY); \ - if (CMP(request, SIOCGIFADDR)) return ioctl_siocgifaddr(FD, MEMORY); \ - if (CMP(request, SIOCGIFNETMASK)) return ioctl_siocgifnetmask(FD, MEMORY); \ - if (CMP(request, SIOCGIFBRDADDR)) return ioctl_siocgifbrdaddr(FD, MEMORY); \ - if (CMP(request, SIOCGIFDSTADDR)) return ioctl_siocgifdstaddr(FD, MEMORY); \ - if (CMP(request, SIOCGIFFLAGS)) return ioctl_siocgifflags(FD, MEMORY); \ - } while (0) -/* - if (CMP(request, SIOCGIFFLAGS)) return ioctl_siocgifflags(FD, REQUEST, MEMORY); \ -*/ +#define __IOCTL_DISPATCH(CMP, DEFAULT, FD, REQUEST, ...) \ + ({ \ + int ReZ; \ + if (CMP(REQUEST, TIOCGWINSZ)) { \ + ReZ = ioctl_tiocgwinsz(FD, __VA_ARGS__); \ + } else if (CMP(REQUEST, TIOCSWINSZ)) { \ + ReZ = ioctl_tiocswinsz(FD, __VA_ARGS__); \ + } else if (CMP(REQUEST, TCGETS)) { \ + ReZ = ioctl_tcgets(FD, __VA_ARGS__); \ + } else if (CMP(REQUEST, TCSETS)) { \ + ReZ = ioctl_tcsets(FD, REQUEST, __VA_ARGS__); \ + } else if (CMP(REQUEST, TCSETSW)) { \ + ReZ = ioctl_tcsets(FD, REQUEST, __VA_ARGS__); \ + } else if (CMP(REQUEST, TCSETSF)) { \ + ReZ = ioctl_tcsets(FD, REQUEST, __VA_ARGS__); \ + } else if (CMP(REQUEST, SIOCGIFCONF)) { \ + ReZ = ioctl_siocgifconf(FD, __VA_ARGS__); \ + } else if (CMP(REQUEST, SIOCGIFADDR)) { \ + ReZ = ioctl_siocgifaddr(FD, __VA_ARGS__); \ + } else if (CMP(REQUEST, SIOCGIFNETMASK)) { \ + ReZ = ioctl_siocgifnetmask(FD, __VA_ARGS__); \ + } else if (CMP(REQUEST, SIOCGIFBRDADDR)) { \ + ReZ = ioctl_siocgifbrdaddr(FD, __VA_ARGS__); \ + } else if (CMP(REQUEST, SIOCGIFDSTADDR)) { \ + ReZ = ioctl_siocgifdstaddr(FD, __VA_ARGS__); \ + } else if (CMP(REQUEST, SIOCGIFFLAGS)) { \ + ReZ = ioctl_siocgifflags(FD, __VA_ARGS__); \ + } else if (CMP(REQUEST, FIOCLEX)) { \ + ReZ = ioctl_fioclex(FD); \ + } else if (CMP(REQUEST, FIONCLEX)) { \ + ReZ = ioctl_fionclex(FD); \ + } else { \ + ReZ = DEFAULT; \ + } \ + ReZ; \ + }) int ioctl_tcgets(int, void *); int ioctl_tcgets_nt(int, void *); @@ -55,11 +76,8 @@ int ioctl_siocgifnetmask(int, void *); int ioctl_siocgifbrdaddr(int, void *); int ioctl_siocgifflags(int, void *); int ioctl_default(int, uint64_t, void *); - -forceinline int ioctl_dispatch(int fd, uint64_t request, void *memory) { - __IOCTL_DISPATCH(__EQUIVALENT, fd, request, memory); - return ioctl_default(fd, request, memory); -} +int ioctl_fioclex(int); +int ioctl_fionclex(int); #endif /* GNUC && !ANSI */ COSMOPOLITAN_C_END_ diff --git a/libc/calls/ioctl_fioclex-nt.c b/libc/calls/ioctl_fioclex-nt.c new file mode 100644 index 000000000..d590404b5 --- /dev/null +++ b/libc/calls/ioctl_fioclex-nt.c @@ -0,0 +1,31 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/internal.h" +#include "libc/calls/ioctl.h" +#include "libc/sysv/consts/o.h" +#include "libc/sysv/errfuns.h" + +textwindows int ioctl_fioclex_nt(int fd) { + if (__isfdopen(fd)) { + g_fds.p[fd].flags |= O_CLOEXEC; + return 0; + } else { + return ebadf(); + } +} diff --git a/libc/calls/ioctl_fioclex.c b/libc/calls/ioctl_fioclex.c new file mode 100644 index 000000000..8b963487e --- /dev/null +++ b/libc/calls/ioctl_fioclex.c @@ -0,0 +1,36 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/internal.h" +#include "libc/calls/ioctl.h" +#include "libc/dce.h" + +int ioctl_fioclex_nt(int); + +/** + * Sets "close on exec" on file descriptor the fast way. + * + * @see ioctl(fd, FIOCLEX, 0) dispatches here + */ +int ioctl_fioclex(int fd) { + if (!IsWindows()) { + return sys_ioctl(fd, FIOCLEX, 0); + } else { + return ioctl_fioclex_nt(fd); + } +} diff --git a/libc/calls/ioctl_fionclex-nt.c b/libc/calls/ioctl_fionclex-nt.c new file mode 100644 index 000000000..8390f7ef8 --- /dev/null +++ b/libc/calls/ioctl_fionclex-nt.c @@ -0,0 +1,31 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/internal.h" +#include "libc/calls/ioctl.h" +#include "libc/sysv/consts/o.h" +#include "libc/sysv/errfuns.h" + +textwindows int ioctl_fionclex_nt(int fd) { + if (__isfdopen(fd)) { + g_fds.p[fd].flags &= ~O_CLOEXEC; + return 0; + } else { + return ebadf(); + } +} diff --git a/libc/calls/ioctl_fionclex.c b/libc/calls/ioctl_fionclex.c new file mode 100644 index 000000000..9a8114193 --- /dev/null +++ b/libc/calls/ioctl_fionclex.c @@ -0,0 +1,36 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/internal.h" +#include "libc/calls/ioctl.h" +#include "libc/dce.h" + +int ioctl_fionclex_nt(int); + +/** + * Clears "close on exec" on file descriptor the fast way. + * + * @see ioctl(fd, FIONCLEX, 0) dispatches here + */ +int ioctl_fionclex(int fd) { + if (!IsWindows()) { + return sys_ioctl(fd, FIONCLEX, 0); + } else { + return ioctl_fionclex_nt(fd); + } +} diff --git a/libc/calls/tcdrain.c b/libc/calls/tcdrain.c new file mode 100644 index 000000000..f6220eb98 --- /dev/null +++ b/libc/calls/tcdrain.c @@ -0,0 +1,24 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/internal.h" +#include "libc/calls/termios.h" + +int tcdrain(int fd) { + return ioctl(fd, TCSBRK, (void *)(intptr_t)1); +} diff --git a/libc/calls/tcflow.c b/libc/calls/tcflow.c new file mode 100644 index 000000000..f46f812cc --- /dev/null +++ b/libc/calls/tcflow.c @@ -0,0 +1,26 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/internal.h" +#include "libc/calls/termios.h" +#include "libc/sysv/consts/termios.h" + +int tcflow(int fd, int action) { + /* TODO(jart): BSD support */ + return sys_ioctl(fd, TCXONC, (void *)(intptr_t)action); +} diff --git a/libc/calls/tcflush.c b/libc/calls/tcflush.c new file mode 100644 index 000000000..6a76d3013 --- /dev/null +++ b/libc/calls/tcflush.c @@ -0,0 +1,26 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/internal.h" +#include "libc/calls/termios.h" +#include "libc/sysv/consts/termios.h" + +int tcflush(int fd, int x) { + /* TODO(jart): BSD Support */ + return sys_ioctl(fd, TCFLSH, x); +} diff --git a/libc/calls/tcgetattr.c b/libc/calls/tcgetattr.c index 3d640003f..a520fe460 100644 --- a/libc/calls/tcgetattr.c +++ b/libc/calls/tcgetattr.c @@ -28,4 +28,6 @@ * @return -1 w/ errno on error * @asyncsignalsafe */ -int(tcgetattr)(int fd, struct termios *tio) { return ioctl(fd, TCGETS, tio); } +int(tcgetattr)(int fd, struct termios *tio) { + return ioctl(fd, TCGETS, tio); +} diff --git a/libc/calls/tcgetsid.c b/libc/calls/tcgetsid.c new file mode 100644 index 000000000..8bdbdc04c --- /dev/null +++ b/libc/calls/tcgetsid.c @@ -0,0 +1,27 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/internal.h" +#include "libc/calls/termios.h" +#include "libc/sysv/consts/termios.h" + +int tcgetsid(int fd) { + int sid; + if (sys_ioctl(fd, TIOCGSID, &sid) < 0) return -1; + return sid; +} diff --git a/libc/calls/tcsendbreak.c b/libc/calls/tcsendbreak.c new file mode 100644 index 000000000..2f8299a9d --- /dev/null +++ b/libc/calls/tcsendbreak.c @@ -0,0 +1,34 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/internal.h" +#include "libc/calls/termios.h" +#include "libc/dce.h" +#include "libc/sysv/consts/termios.h" +#include "libc/time/time.h" + +int tcsendbreak(int fd, int len) { + if (!IsBsd()) { + return sys_ioctl(fd, TCSBRK, 0); + } else { + if (sys_ioctl(fd, TIOCSBRK, 0) == -1) return -1; + usleep(400000); + if (sys_ioctl(fd, TIOCCBRK, 0) == -1) return -1; + return 0; + } +} diff --git a/libc/calls/termios.h b/libc/calls/termios.h index 9dfef3902..35ea0b223 100644 --- a/libc/calls/termios.h +++ b/libc/calls/termios.h @@ -26,6 +26,17 @@ int grantpt(int); int unlockpt(int); int posix_openpt(int) nodiscard; +int tcdrain(int); +int tcgetsid(int); +int tcflow(int, int); +int tcflush(int, int); +int tcsendbreak(int, int); +void cfmakeraw(struct termios *); +int cfsetospeed(struct termios *, int); +int cfsetispeed(struct termios *, int); +uint32_t cfgetospeed(const struct termios *); +uint32_t cfgetispeed(const struct termios *); + /*───────────────────────────────────────────────────────────────────────────│─╗ │ cosmopolitan § teletypewriter » undiamonding ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ diff --git a/libc/log/check.h b/libc/log/check.h index 1f72317c4..15a3ecaf3 100644 --- a/libc/log/check.h +++ b/libc/log/check.h @@ -2,11 +2,6 @@ #define COSMOPOLITAN_LIBC_LOG_CHECK_H_ #include "libc/dce.h" #include "libc/macros.internal.h" - -/** - * @fileoverview Modern assertions, courtesy of Elgoog. - */ - #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ @@ -47,9 +42,6 @@ COSMOPOLITAN_C_START_ VAR = (typeof(VAR))__builtin_assume_aligned(VAR, BYTES); \ } while (0) -#if defined(__VSCODE_INTELLISENSE__) -#define __CHK(...) -#else #define __CHK(SUFFIX, OP, WANT, WANTSTR, GOT, GOTSTR, ...) \ do { \ autotype(GOT) Got = (GOT); \ @@ -64,11 +56,7 @@ COSMOPOLITAN_C_START_ unreachable; \ } \ } while (0) -#endif /* defined(__VSCODE_INTELLISENSE__) */ -#if defined(__VSCODE_INTELLISENSE__) -#define __DCHK(...) -#else #ifdef NDEBUG #define __DCHK(SUFFIX, OP, WANT, WANTSTR, GOT, ...) \ do { \ @@ -82,7 +70,6 @@ COSMOPOLITAN_C_START_ #define __DCHK(SUFFIX, OP, WANT, WANTSTR, GOT, GOTSTR, ...) \ __CHK(SUFFIX, OP, WANT, WANTSTR, GOT, GOTSTR, __VA_ARGS__) #endif /* NDEBUG */ -#endif /* defined(__VSCODE_INTELLISENSE__) */ #ifdef NDEBUG #define __DCHK_ALIGNED(BYTES, VAR) @@ -102,6 +89,13 @@ void __check_fail_ge(uint64_t, uint64_t) relegated wontreturn; void __check_fail_gt(uint64_t, uint64_t) relegated wontreturn; void __check_fail_aligned(unsigned, uint64_t) relegated wontreturn; +#ifdef __VSCODE_INTELLISENSE__ +#undef __CHK +#define __CHK(...) +#undef __DCHK +#define __DCHK(...) +#endif + COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_LOG_CHECK_H_ */ diff --git a/third_party/mbedtls/traceme.c b/libc/log/traceme.c similarity index 100% rename from third_party/mbedtls/traceme.c rename to libc/log/traceme.c diff --git a/libc/log/traceme.h b/libc/log/traceme.h new file mode 100644 index 000000000..a7aad06de --- /dev/null +++ b/libc/log/traceme.h @@ -0,0 +1,10 @@ +#ifndef COSMOPOLITAN_LIBC_LOG_TRACEME_H_ +#define COSMOPOLITAN_LIBC_LOG_TRACEME_H_ +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +extern int traceme; + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_LOG_TRACEME_H_ */ diff --git a/libc/nexgen32e/imapxlatab.S b/libc/nexgen32e/imapxlatab.S index 753d740aa..7a9282a15 100644 --- a/libc/nexgen32e/imapxlatab.S +++ b/libc/nexgen32e/imapxlatab.S @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/macros.internal.h" .text.startup -.align 8 // Identity maps 256-byte translation table. // diff --git a/libc/nexgen32e/ktolower.S b/libc/nexgen32e/ktolower.S index c75433330..41fdaad0f 100644 --- a/libc/nexgen32e/ktolower.S +++ b/libc/nexgen32e/ktolower.S @@ -18,23 +18,17 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/macros.internal.h" + .initbss 300,_init_kToLower // ASCII uppercase → lowercase translation tables. // // char kToLower[256]; -// char16_t kToLower16[256]; // -// @note kToLower16 saves 128kb; CMOVcc can't even 8-bit - .initbss 300,_init_kToLower +// @see kToUpper kToLower: .rept 256 .byte 0 .endr .endobj kToLower,globl,hidden -kToLower16: - .rept 256 - .short 0 - .endr - .endobj kToLower16,globl,hidden .previous .init.start 300,_init_kToLower @@ -44,17 +38,11 @@ kToLower16: xor %ecx,%ecx 0: inc %ecx addb $0x20,'A'-1(%rsi,%rcx) - cmp $'Z'-'A',%ecx + cmp $'Z'-'A'+1,%ecx jne 0b - xor %eax,%eax - mov $256,%ecx -0: lodsb - stosw - .loop 0b pop %rsi .init.end 300,_init_kToLower .type gperf_downcase,@object .globl gperf_downcase gperf_downcase = kToLower - .source __FILE__ diff --git a/libc/nexgen32e/bzero.S b/libc/nexgen32e/ktoupper.S similarity index 79% rename from libc/nexgen32e/bzero.S rename to libc/nexgen32e/ktoupper.S index 6bba2d4ca..09546892c 100644 --- a/libc/nexgen32e/bzero.S +++ b/libc/nexgen32e/ktoupper.S @@ -1,5 +1,5 @@ /*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ +│vi: set et ft=asm ts=8 sw=8 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ @@ -18,17 +18,27 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/macros.internal.h" -// Sets memory to zero. + .initbss 300,_init_kToUpper +// ASCII lowercase → uppercase translation tables. // -// C code should always favor memset(), since that's the one we've -// prototyped with the best optimizations. This definition is used -// by old code and sometimes code generators, as a thunk. +// char kToUpper[256]; // -// @param rdi is dest -// @param rsi is the number of bytes to set -// @see memset(), explicit_bzero() -bzero: mov %rsi,%rdx - xor %esi,%esi - jmp MemSet - .endfn bzero,globl - .source __FILE__ +// @see kToLower +kToUpper: + .rept 256 + .byte 0 + .endr + .endobj kToUpper,globl,hidden + .previous + + .init.start 300,_init_kToUpper + push %rdi + call imapxlatab + xchg %rsi,(%rsp) + xor %ecx,%ecx +0: inc %ecx + subb $0x20,'a'-1(%rsi,%rcx) + cmp $'z'-'a'+1,%ecx + jne 0b + pop %rsi + .init.end 300,_init_kToUpper diff --git a/libc/nt/accounting.h b/libc/nt/accounting.h index 696b0c7c4..1b382873d 100644 --- a/libc/nt/accounting.h +++ b/libc/nt/accounting.h @@ -31,6 +31,7 @@ COSMOPOLITAN_C_START_ │ cosmopolitan § new technology » accounting ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ +uint32_t GetMaximumProcessorCount(uint16_t GroupNumber); int GetUserName(char16_t (*buf)[257], uint32_t *in_out_size); bool32 GlobalMemoryStatusEx(struct NtMemoryStatusEx *lpBuffer); int32_t GetExitCodeProcess(int64_t hProcess, uint32_t *lpExitCode); diff --git a/libc/nt/kernel32/GetMaximumProcessorCount.s b/libc/nt/kernel32/GetMaximumProcessorCount.s index 84727f829..80fd83092 100644 --- a/libc/nt/kernel32/GetMaximumProcessorCount.s +++ b/libc/nt/kernel32/GetMaximumProcessorCount.s @@ -1,2 +1,15 @@ .include "o/libc/nt/codegen.inc" .imp kernel32,__imp_GetMaximumProcessorCount,GetMaximumProcessorCount,627 + + .text.windows +GetMaximumProcessorCount: + push %rbp + mov %rsp,%rbp + .profilable + mov %rdi,%rcx + sub $32,%rsp + call *__imp_GetMaximumProcessorCount(%rip) + leave + ret + .endfn GetMaximumProcessorCount,globl + .previous diff --git a/libc/nt/master.sh b/libc/nt/master.sh index a21310191..cce41ca42 100755 --- a/libc/nt/master.sh +++ b/libc/nt/master.sh @@ -2280,7 +2280,7 @@ imp 'GetManagedApplications' GetManagedApplications advapi32 1337 imp 'GetMapMode' GetMapMode gdi32 1671 imp 'GetMappedFileNameA' GetMappedFileNameA KernelBase 594 imp 'GetMappedFileName' GetMappedFileNameW KernelBase 595 -imp 'GetMaximumProcessorCount' GetMaximumProcessorCount kernel32 627 +imp 'GetMaximumProcessorCount' GetMaximumProcessorCount kernel32 627 1 # Windows 7+ imp 'GetMaximumProcessorGroupCount' GetMaximumProcessorGroupCount kernel32 628 imp 'GetMemoryErrorHandlingCapabilities' GetMemoryErrorHandlingCapabilities kernel32 0 # KernelBase imp 'GetMenu' GetMenu user32 1881 1 diff --git a/libc/runtime/getcpucount.c b/libc/runtime/getcpucount.c new file mode 100644 index 000000000..4bd7665d7 --- /dev/null +++ b/libc/runtime/getcpucount.c @@ -0,0 +1,84 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/assert.h" +#include "libc/bits/popcnt.h" +#include "libc/calls/calls.h" +#include "libc/calls/weirdtypes.h" +#include "libc/dce.h" +#include "libc/macros.internal.h" +#include "libc/nt/dll.h" +#include "libc/nt/struct/systeminfo.h" +#include "libc/nt/systeminfo.h" +#include "libc/runtime/runtime.h" + +#define CTL_HW 6 +#define HW_NCPU 3 +#define HW_NCPUONLINE_OPENBSD 25 +#define HW_NCPUONLINE_NETBSD 16 +#define ALL_PROCESSOR_GROUPS 0xffff + +/** + * Returns number of CPUs in system. + * + * On Intel systems with HyperThreading this will return the number of + * cores multiplied by two. + * + * @return cpu count or 0 if it couldn't be determined + */ +unsigned GetCpuCount(void) { + size_t len; + int i, c, n, cmd[2]; + uint64_t cpuset[16]; + uint32_t (*f)(uint16_t); + struct NtSystemInfo sysinfo; + if (IsWindows()) { + if ((f = GetProcAddress(GetModuleHandle("KERNEL32"), + "GetMaximumProcessorCount"))) { + return f(ALL_PROCESSOR_GROUPS); + } else { + GetSystemInfo(&sysinfo); + return sysinfo.dwNumberOfProcessors; + } + } else if (IsBsd()) { + len = sizeof(c); + cmd[0] = CTL_HW; + if (IsOpenbsd()) { + cmd[1] = HW_NCPUONLINE_OPENBSD; + } else if (IsNetbsd()) { + cmd[1] = HW_NCPUONLINE_NETBSD; + } else { + cmd[1] = HW_NCPU; + } + if (!sysctl(cmd, 2, &c, &len, 0, 0)) { + return c; + } else { + return 0; + } + } else { + if ((n = sched_getaffinity(0, sizeof(cpuset), cpuset)) > 0) { + assert(!(n & 7)); + for (n >>= 3, c = i = 0; i < ARRAYLEN(cpuset); ++i) { + c += popcnt(cpuset[i]); + } + return c; + } else { + return 0; + } + } +} diff --git a/libc/runtime/runtime.mk b/libc/runtime/runtime.mk index 7495f6f29..7b50ee9c9 100644 --- a/libc/runtime/runtime.mk +++ b/libc/runtime/runtime.mk @@ -33,6 +33,7 @@ LIBC_RUNTIME_A_CHECKS = \ $(LIBC_RUNTIME_A_HDRS:%=o/$(MODE)/%.ok) LIBC_RUNTIME_A_DIRECTDEPS = \ + LIBC_BITS \ LIBC_CALLS \ LIBC_ELF \ LIBC_FMT \ diff --git a/libc/runtime/sysconf.c b/libc/runtime/sysconf.c index 3fd5699aa..d84f7de89 100644 --- a/libc/runtime/sysconf.c +++ b/libc/runtime/sysconf.c @@ -27,13 +27,15 @@ * - `_SC_CLK_TCK` returns number of clock ticks per second * - `_SC_ARG_MAX` currently always returns 32768 due to Windows * - `_SC_PAGESIZE` currently always returns 65536 due to Windows + * - `_SC_NPROCESSORS_ONLN` returns number of CPUs in the system * - * You are encouraged to undiamond calls to this API as follows: + * Some suggestions: * - * - Use `CLK_TCK` instead of `getconf(_SC_CLK_TCK)` + * - `CLK_TCK` should be favored over `getconf(_SC_CLK_TCK)` * - Use `PAGESIZE` or `FRAMESIZE` instead of `getconf(_SC_PAGESIZE)` */ long sysconf(int name) { + int n; switch (name) { case _SC_ARG_MAX: return ARG_MAX; @@ -41,6 +43,9 @@ long sysconf(int name) { return CLK_TCK; case _SC_PAGESIZE: return FRAMESIZE; + case _SC_NPROCESSORS_ONLN: + n = GetCpuCount(); + return n > 0 ? n : -1; default: return -1; } diff --git a/libc/runtime/sysconf.h b/libc/runtime/sysconf.h index 465ece060..74c70a7f0 100644 --- a/libc/runtime/sysconf.h +++ b/libc/runtime/sysconf.h @@ -1,15 +1,17 @@ #ifndef COSMOPOLITAN_LIBC_RUNTIME_SYSCONF_H_ #define COSMOPOLITAN_LIBC_RUNTIME_SYSCONF_H_ -#define _SC_ARG_MAX 0 -#define _SC_CLK_TCK 2 -#define _SC_PAGESIZE 30 -#define _SC_PAGE_SIZE 30 +#define _SC_ARG_MAX 0 +#define _SC_CLK_TCK 2 +#define _SC_PAGESIZE 30 +#define _SC_PAGE_SIZE 30 +#define _SC_NPROCESSORS_ONLN 1002 #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ long sysconf(int); +unsigned GetCpuCount(void); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/sock/sendfile.c b/libc/sock/sendfile.c index fa092c5e3..101de9d27 100644 --- a/libc/sock/sendfile.c +++ b/libc/sock/sendfile.c @@ -48,13 +48,9 @@ static textwindows ssize_t sendfile_linux2nt(int outfd, int infd, } } -static ssize_t sendfile_linux2netflix(int outfd, int infd, - int64_t *inout_opt_inoffset, - size_t uptobytes) { - int sys_sendfile_netflix(int32_t infd, int32_t outfd, int64_t offset, - size_t nbytes, const void *opt_hdtr, - int64_t *out_opt_sbytes, - int32_t flags) asm("sys_sendfile") hidden; +static ssize_t sendfile_linux2bsd(int outfd, int infd, + int64_t *inout_opt_inoffset, + size_t uptobytes) { int rc; int64_t offset, sbytes; if (inout_opt_inoffset) { @@ -62,8 +58,12 @@ static ssize_t sendfile_linux2netflix(int outfd, int infd, } else if ((offset = lseek(infd, 0, SEEK_CUR)) == -1) { return -1; } - if ((rc = sys_sendfile_netflix(infd, outfd, offset, uptobytes, NULL, &sbytes, - 0)) != -1) { + if (IsFreebsd()) { + rc = sys_sendfile_freebsd(infd, outfd, offset, uptobytes, 0, &sbytes, 0); + } else { + rc = sys_sendfile_xnu(infd, outfd, offset, &sbytes, 0, 0); + } + if (rc != -1) { if (inout_opt_inoffset) *inout_opt_inoffset += sbytes; return sbytes; } else { @@ -92,7 +92,7 @@ ssize_t sendfile(int outfd, int infd, int64_t *inout_opt_inoffset, if (IsLinux()) { return sys_sendfile(outfd, infd, inout_opt_inoffset, uptobytes); } else if (IsFreebsd() || IsXnu()) { - return sendfile_linux2netflix(outfd, infd, inout_opt_inoffset, uptobytes); + return sendfile_linux2bsd(outfd, infd, inout_opt_inoffset, uptobytes); } else if (IsWindows()) { return sendfile_linux2nt(outfd, infd, inout_opt_inoffset, uptobytes); } else { diff --git a/libc/stdio/dirstream.c b/libc/stdio/dirstream.c index 5aafa41b1..7cc4549c6 100644 --- a/libc/stdio/dirstream.c +++ b/libc/stdio/dirstream.c @@ -31,6 +31,7 @@ #include "libc/nt/runtime.h" #include "libc/nt/struct/win32finddata.h" #include "libc/nt/synchronization.h" +#include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/sysv/consts/dt.h" #include "libc/sysv/consts/o.h" @@ -70,6 +71,7 @@ struct dirstream { }; struct { bool isdone; + char16_t *name; struct NtWin32FindData windata; }; }; @@ -110,7 +112,7 @@ struct dirent_netbsd { char d_name[512]; }; -static textwindows DIR *opendir_nt_impl(char16_t name[PATH_MAX], size_t len) { +static textwindows DIR *opendir_nt_impl(char16_t *name, size_t len) { DIR *res; if (len + 2 + 1 <= PATH_MAX) { if (len > 1 && name[len - 1] != u'\\') { @@ -134,21 +136,33 @@ static textwindows DIR *opendir_nt_impl(char16_t name[PATH_MAX], size_t len) { static textwindows noinline DIR *opendir_nt(const char *path) { int len; - char16_t name[PATH_MAX]; - if ((len = __mkntpath(path, name)) == -1) return NULL; - return opendir_nt_impl(name, len); + DIR *res; + char16_t *name; + if ((name = malloc(PATH_MAX * 2))) { + if ((len = __mkntpath(path, name)) != -1 && + (res = opendir_nt_impl(name, len))) { + res->name = name; + return res; + } + free(name); + } + return NULL; } static textwindows noinline DIR *fdopendir_nt(int fd) { DIR *res; - char16_t name[PATH_MAX]; + char16_t *name; if (__isfdkind(fd, kFdFile)) { - if ((res = opendir_nt_impl( - name, GetFinalPathNameByHandle( - g_fds.p[fd].handle, name, ARRAYLEN(name), - kNtFileNameNormalized | kNtVolumeNameDos)))) { - close(fd); - return res; + if ((name = malloc(PATH_MAX * 2))) { + if ((res = opendir_nt_impl( + name, GetFinalPathNameByHandle( + g_fds.p[fd].handle, name, PATH_MAX, + kNtFileNameNormalized | kNtVolumeNameDos)))) { + res->name = name; + close(fd); + return res; + } + free(name); } } else { ebadf(); @@ -217,6 +231,7 @@ DIR *opendir(const char *name) { struct Zipos *zip; struct ZiposUri zipname; if (weaken(__zipos_get) && weaken(__zipos_parseuri)(name, &zipname) != -1) { + ZTRACE("__zipos_opendir(%`'s)", name); zip = weaken(__zipos_get)(); res = calloc(1, sizeof(DIR)); res->iszip = true; @@ -369,6 +384,7 @@ int closedir(DIR *dir) { } else if (!IsWindows()) { rc = close(dir->fd); } else { + free(dir->name); rc = FindClose(dir->fd) ? 0 : __winerr(); } free(dir); @@ -393,3 +409,26 @@ int dirfd(DIR *dir) { if (IsWindows()) return eopnotsupp(); return dir->fd; } + +/** + * Seeks to beginning of directory stream. + */ +void rewinddir(DIR *dir) { + if (dir->iszip) { + dir->tell = 0; + dir->zip.offset = GetZipCdirOffset(weaken(__zipos_get)()->cdir); + } else if (!IsWindows()) { + if (!lseek(dir->fd, 0, SEEK_SET)) { + dir->buf_pos = dir->buf_end = 0; + dir->tell = 0; + } + } else { + FindClose(dir->fd); + if ((dir->fd = FindFirstFile(dir->name, &dir->windata)) != -1) { + dir->isdone = false; + dir->tell = 0; + } else { + dir->isdone = true; + } + } +} diff --git a/libc/str/bzero.c b/libc/str/bzero.c new file mode 100644 index 000000000..3e9da2394 --- /dev/null +++ b/libc/str/bzero.c @@ -0,0 +1,71 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/str/str.h" + +typedef long long xmm_t __attribute__((__vector_size__(16), __aligned__(1))); + +/** + * Sets memory to zero. + */ +void bzero(void *p, size_t n) { + char *b; + uint64_t x; + x = 0; + b = p; + switch (n) { + case 0: + break; + case 1: + __builtin_memcpy(b, &x, 1); + break; + case 2: + __builtin_memcpy(b, &x, 2); + break; + case 3: + __builtin_memcpy(b, &x, 2); + __builtin_memcpy(b + 1, &x, 2); + break; + case 4: + __builtin_memcpy(b, &x, 4); + break; + case 5 ... 7: + __builtin_memcpy(b, &x, 4); + __builtin_memcpy(b + n - 4, &x, 4); + break; + case 8: + __builtin_memcpy(b, &x, 8); + break; + case 9 ... 15: + __builtin_memcpy(b, &x, 8); + __builtin_memcpy(b + n - 8, &x, 8); + break; + case 16: + *(xmm_t *)b = (xmm_t){0}; + break; + default: + while (n > 32) { + *(xmm_t *)(b + n - 16) = (xmm_t){0}; + *(xmm_t *)(b + n - 32) = (xmm_t){0}; + n -= 32; + } + if (n > 16) *(xmm_t *)(b + n - 16) = (xmm_t){0}; + *(xmm_t *)b = (xmm_t){0}; + break; + } +} diff --git a/libc/fmt/dosdatetimetounix.c b/libc/str/dosdatetimetounix.c similarity index 100% rename from libc/fmt/dosdatetimetounix.c rename to libc/str/dosdatetimetounix.c diff --git a/libc/nexgen32e/explicit_bzero.S b/libc/str/explicit_bzero.S similarity index 76% rename from libc/nexgen32e/explicit_bzero.S rename to libc/str/explicit_bzero.S index a7ecaf8d9..96a707de0 100644 --- a/libc/nexgen32e/explicit_bzero.S +++ b/libc/str/explicit_bzero.S @@ -1,7 +1,7 @@ /*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ │vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ @@ -20,30 +20,10 @@ // Sets memory to zero w/ accompanying non-optimizing macro. // -// This is intended for security-conscious applications. This -// implementation also hoses every register the abi allows. A -// concomitant prototype (str.h) countermands compiler magic. +// This is intended for security-conscious applications. // // @param rdi is dest -// @param rsi is the number of bytes to set +// @param rsi is the number of bytes to set explicit_bzero: - .leafprologue - mov %rsi,%rcx - xor %eax,%eax - rep stosb - xor %edx,%edx - xor %edi,%edi - xor %esi,%esi - xor %r8,%r8 - xor %r9,%r9 - xor %r10,%r10 - xor %r11,%r11 - pxor %xmm0,%xmm0 - pxor %xmm1,%xmm1 - pxor %xmm2,%xmm2 - pxor %xmm3,%xmm3 - pxor %xmm4,%xmm4 - pxor %xmm5,%xmm5 - .leafepilogue + jmp bzero .endfn explicit_bzero,globl - .source __FILE__ diff --git a/libc/fmt/kmonthyearday.c b/libc/str/kmonthyearday.c similarity index 100% rename from libc/fmt/kmonthyearday.c rename to libc/str/kmonthyearday.c diff --git a/libc/str/str.h b/libc/str/str.h index 76e1d2786..c864e5842 100644 --- a/libc/str/str.h +++ b/libc/str/str.h @@ -9,7 +9,7 @@ COSMOPOLITAN_C_START_ extern const uint8_t gperf_downcase[256]; extern const uint8_t kToLower[256]; -extern const uint16_t kToLower16[256]; +extern const uint8_t kToUpper[256]; extern const uint8_t kBase36[256]; extern const char16_t kCp437[256]; @@ -80,12 +80,14 @@ wint_t towupper(wint_t); │ cosmopolitan § strings ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ +void bzero(void *, size_t) libcesque; void *memset(void *, int, size_t) memcpyesque; void *memcpy(void *restrict, const void *restrict, size_t) memcpyesque; void *mempcpy(void *restrict, const void *restrict, size_t) memcpyesque; void *memccpy(void *restrict, const void *restrict, int, size_t) memcpyesque; void *memmove(void *, const void *, size_t) memcpyesque; void *memeqmask(void *, const void *, const void *, size_t) memcpyesque; +void explicit_bzero(void *, size_t); size_t strlen(const char *) strlenesque; size_t strnlen(const char *, size_t) strlenesque; @@ -95,8 +97,6 @@ char *index(const char *, int) strlenesque; void *memchr(const void *, int, size_t) strlenesque; char *strchrnul(const char *, int) strlenesque returnsnonnull; void *rawmemchr(const void *, int) strlenesque returnsnonnull; -void bzero(void *, size_t) paramsnonnull() libcesque; -void explicit_bzero(void *, size_t) paramsnonnull() libcesque; size_t strlen16(const char16_t *) strlenesque; size_t strnlen16(const char16_t *, size_t) strlenesque; size_t strnlen16_s(const char16_t *, size_t); @@ -161,6 +161,8 @@ char *strcpy(char *, const char *) memcpyesque; char16_t *strcpy16(char16_t *, const char16_t *) memcpyesque; wchar_t *wcscpy(wchar_t *, const wchar_t *) memcpyesque; char *strncat(char *, const char *, size_t) memcpyesque; +char16_t *strncat16(char16_t *, const char16_t *, size_t) memcpyesque; +wchar_t *wcsncat(wchar_t *, const wchar_t *, size_t) memcpyesque; char *strncpy(char *, const char *, size_t) memcpyesque; char *strtok(char *, const char *) paramsnonnull((2)) libcesque; char *strtok_r(char *, const char *, char **) paramsnonnull((2, 3)); @@ -183,8 +185,7 @@ compatfn wchar_t *wmempcpy(wchar_t *, const wchar_t *, size_t) memcpyesque; compatfn wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t) memcpyesque; int timingsafe_memcmp(const void *, const void *, size_t); void *tinymemccpy(void *, const void *, int, size_t) memcpyesque; -void *memmem(const void *, size_t, const void *, size_t) - paramsnonnull() nothrow nocallback nosideeffect; +void *memmem(const void *, size_t, const void *, size_t) libcesque nosideeffect; char *strerror(int) returnsnonnull nothrow nocallback; long a64l(const char *); char *l64a(long); @@ -325,17 +326,6 @@ char *strsignal(int) returnsnonnull libcesque; DeSt; \ }) -#define explicit_bzero(STR, BYTES) \ - do { \ - void *Str; \ - size_t Bytes; \ - asm volatile("call\texplicit_bzero" \ - : "=D"(Str), "=S"(Bytes) \ - : "0"(STR), "1"(BYTES) \ - : "rax", "rcx", "rdx", "r8", "r9", "r10", "r11", "memory", \ - "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); \ - } while (0) - #else /* hosted+sse2 */ #define mempcpy(DEST, SRC, SIZE) \ diff --git a/libc/str/str.mk b/libc/str/str.mk index 83eaeb721..1b47c9e96 100644 --- a/libc/str/str.mk +++ b/libc/str/str.mk @@ -62,6 +62,10 @@ o/$(MODE)/libc/str/getziplfileuncompressedsize.o: \ OVERRIDE_CFLAGS += \ -Os +o//libc/str/bzero.o: \ + OVERRIDE_CFLAGS += \ + -O2 + o/$(MODE)/libc/str/iswpunct.o \ o/$(MODE)/libc/str/iswupper.o \ o/$(MODE)/libc/str/iswlower.o: \ diff --git a/libc/str/strncat16.c b/libc/str/strncat16.c new file mode 100644 index 000000000..60440c1b1 --- /dev/null +++ b/libc/str/strncat16.c @@ -0,0 +1,39 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/str/str.h" + +/** + * Appends at most 𝑛 shorts from 𝑠 to 𝑑. + * + * @param 𝑑 is both a NUL-terminated string and a buffer, needing + * an ARRAYLEN() of at least strlen16(𝑑)+strnlen16(𝑠,𝑛)+1 + * @param 𝑠 is character array which needn't be NUL-terminated + * @param 𝑛 is maximum number of characters from s to copy + * @return 𝑑 + * @note 𝑑 and 𝑠 can't overlap + * @asyncsignaslenafe + */ +char16_t *strncat16(char16_t *d, const char16_t *s, size_t n) { + size_t i; + char16_t *r = d; + d += strlen16(d); + for (i = 0; i < n && s[i]; ++i) d[i] = s[i]; + d[i] = 0; + return r; +} diff --git a/libc/str/wcsncat.c b/libc/str/wcsncat.c new file mode 100644 index 000000000..7a5e8050c --- /dev/null +++ b/libc/str/wcsncat.c @@ -0,0 +1,39 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/str/str.h" + +/** + * Appends at most 𝑛 wides from 𝑠 to 𝑑. + * + * @param 𝑑 is both a NUL-terminated string and a buffer, needing + * an ARRAYLEN() of at least wcslen(𝑑)+wcsnlen(𝑠,𝑛)+1 + * @param 𝑠 is character array which needn't be NUL-terminated + * @param 𝑛 is maximum number of characters from s to copy + * @return 𝑑 + * @note 𝑑 and 𝑠 can't overlap + * @asyncsignaslenafe + */ +wchar_t *wcsncat(wchar_t *d, const wchar_t *s, size_t n) { + size_t i; + wchar_t *r = d; + d += wcslen(d); + for (i = 0; i < n && s[i]; ++i) d[i] = s[i]; + d[i] = 0; + return r; +} diff --git a/libc/sysv/consts.sh b/libc/sysv/consts.sh index 80e5bc876..c23df5455 100755 --- a/libc/sysv/consts.sh +++ b/libc/sysv/consts.sh @@ -184,9 +184,12 @@ syscon open O_SYNC 0x00101000 0x00000080 0x00000080 0x00000080 0x0000008 syscon open O_NOCTTY 0x00000100 0x00020000 0x00008000 0x00008000 0x00008000 0 # used for remote viewing (default behavior on freebsd) syscon open O_NOATIME 0x00040000 0 0 0 0 0 # optimize away access time update syscon open O_EXEC 0 0 0x00040000 0 0x04000000 0 # it's specified by posix what does it mean +syscon open O_SEARCH 0 0 0x00040000 0 0x00800000 0 # it's specified by posix what does it mean syscon open O_DSYNC 0x00001000 0x00400000 0 0x00000080 0x00010000 0 syscon open O_RSYNC 0x00101000 0 0 0x00000080 0x00020000 0 syscon open O_PATH 0x00200000 0 0 0 0 0 +syscon open O_SHLOCK 0 0x00000010 0x00000010 0x00000010 0x00000010 0 +syscon open O_EXLOCK 0 0x00000020 0x00000020 0x00000020 0x00000020 0 syscon open O_TTY_INIT 0 0 0x00080000 0 0 0 syscon compat O_LARGEFILE 0 0 0 0 0 0 @@ -352,7 +355,7 @@ syscon fcntl2 F_DUPFD 0 0 0 0 0 0 # consensus syscon fcntl2 F_GETFD 1 1 1 1 1 1 # unix consensus & faked nt syscon fcntl2 F_SETFD 2 2 2 2 2 2 # unix consensus & faked nt syscon fcntl3 FD_CLOEXEC 1 1 1 1 1 1 # unix consensus & faked nt -syscon fcntl F_DUPFD_CLOEXEC 0x0406 67 17 10 12 0 +syscon fcntl F_DUPFD_CLOEXEC 0x0406 67 17 10 12 0x0406 # faked nt syscon fcntl2 F_GETFL 3 3 3 3 3 3 # unix consensus & faked nt syscon fcntl2 F_SETFL 4 4 4 4 4 4 # unix consensus & faked nt @@ -398,6 +401,8 @@ syscon fcntl F_ULOCK 0 0 0 0 0 0 # TODO: specified by posix but syscon ioctl FIONBIO 0x5421 0x8004667e 0x8004667e 0x8004667e 0x8004667e 0x8004667e # BSD-The New Technology consensus; FIONBIO is traditional O_NONBLOCK; see F_SETFL for re-imagined api syscon ioctl FIOASYNC 0x5452 0x8004667d 0x8004667d 0x8004667d 0x8004667d 0x8004667d # BSD-The New Technology consensus syscon ioctl FIONREAD 0x541b 0x4004667f 0x4004667f 0x4004667f 0x4004667f 0x4004667f # BSD-The New Technology consensus; bytes waiting in FD's input buffer +syscon ioctl FIOCLEX 0x5451 0x20006601 0x20006601 0x20006601 0x20006601 0x5451 # sets "close on exec" on file descriptor the fast way; faked nt +syscon ioctl FIONCLEX 0x5450 0x20006602 0x20006602 0x20006602 0x20006602 0x5450 # clears "close on exec" on file descriptor the fast way; faked nt #syscon ioctl FIONWRITE 0x0 0x0 0x40046677 0x0 0x0 -1 # [FreeBSD Generalization] bytes queued in FD's output buffer (same as TIOCOUTQ for TTY FDs; see also SO_SNDBUF) #syscon ioctl FIONSPACE 0x0 0x0 0x40046676 0x0 0x0 -1 # [FreeBSD Generalization] capacity of FD's output buffer, e.g. equivalent to TIOCGSERIAL w/ UART syscon ioctl TIOCINQ 0x541b 0x4004667f 0x4004667f 0x4004667f 0x4004667f 0x4004667f # [Linuxism] same as FIONREAD @@ -480,7 +485,11 @@ syscon rlimit RLIMIT_LOCKS 10 127 127 127 127 127 # max flock() / syscon rlimit RLIMIT_SIGPENDING 11 127 127 127 127 127 # max sigqueue() can enqueue; bsd consensus syscon rlimit RLIMIT_MSGQUEUE 12 127 127 127 127 127 # meh posix message queues; bsd consensus syscon rlimit RLIMIT_NICE 13 127 127 127 127 127 # max scheduling priority; 𝑥 ∈ [1,40]; niceness is traditionally displayed as as 𝟸𝟶-𝑥, therefore 𝑥=1 (lowest priority) prints as 19 and 𝑥=40 (highest priority) prints as -20; bsd consensus -syscon rlimit RLIMIT_RTPRIO 14 127 127 127 127 127 # bsd consensus +syscon rlimit RLIMIT_RTPRIO 14 127 127 127 127 127 # woop +syscon rlimit RLIMIT_RTTIME 15 127 127 127 127 127 # woop +syscon rlimit RLIMIT_SWAP 127 127 12 127 127 127 # swap used +syscon rlimit RLIMIT_SBSIZE 127 127 9 127 127 127 # max size of all socket buffers +syscon rlimit RLIMIT_NPTS 127 127 11 127 127 127 # pseudoteletypewriters syscon compat RLIMIT_VMEM 9 5 10 127 10 127 # same as RLIMIT_AS # resource limit special values @@ -1208,14 +1217,21 @@ syscon statvfs ST_RDONLY 1 1 1 1 1 0 # unix consensus syscon statvfs ST_APPEND 0x0100 0 0 0 0 0 syscon statvfs ST_IMMUTABLE 0x0200 0 0 0 0 0 syscon statvfs ST_MANDLOCK 0x40 0 0 0 0 0 -syscon statvfs ST_NOATIME 0x0400 0 0 0 0 0 -syscon statvfs ST_NODEV 4 0 0 0 0 0 +syscon statvfs ST_NOATIME 0x0400 0 0 0x04000000 0 0 +syscon statvfs ST_NODEV 4 0 0 0 0x00000010 0 syscon statvfs ST_NODIRATIME 0x0800 0 0 0 0 0 -syscon statvfs ST_NOEXEC 8 0 0 0 0 0 -syscon statvfs ST_RELATIME 0x1000 0 0 0 0 0 -syscon statvfs ST_SYNCHRONOUS 0x10 0 0 0 0 0 +syscon statvfs ST_NOEXEC 8 0 0 0 4 0 +syscon statvfs ST_RELATIME 0x1000 0 0 0 0x00020000 0 +syscon statvfs ST_SYNCHRONOUS 0x10 0 0 0 2 0 syscon statvfs ST_WRITE 0x80 0 0 0 0 0 +# sendfile() flags +# +# group name GNU/Systemd XNU's Not UNIX! FreeBSD OpenBSD NetBSD The New Technology Commentary +syscon sf SF_NODISKIO 0 0 1 0 0 0 +syscon sf SF_MNOWAIT 0 0 2 0 0 0 +syscon sf SF_SYNC 0 0 4 0 0 0 + # mount flags # # group name GNU/Systemd XNU's Not UNIX! FreeBSD OpenBSD NetBSD The New Technology Commentary @@ -1331,11 +1347,14 @@ syscon termios TIOCSIG 0x40045436 0x2000745f 0x2004745f 0x8004745f 0x800 syscon termios TIOCSPGRP 0x5410 0x80047476 0x80047476 0x80047476 0x80047476 0 # boop syscon termios TIOCSTI 0x5412 0x80017472 0x80017472 0 0 0 # boop syscon termios TIOCGPTN 0x80045430 0 0x4004740f 0 0 0 # boop -syscon termios TIOCGSID 0x5429 0 0x40047463 0x40047463 0x40047463 0 # boop +syscon termios TIOCGSID 0x5429 0x40047463 0x40047463 0x40047463 0x40047463 0 # boop syscon termios TABLDISC 0 0x3 0 0x3 0x3 0 # boop syscon termios SLIPDISC 0 0x4 0x4 0x4 0x4 0 # boop syscon termios PPPDISC 0 0x5 0x5 0x5 0x5 0 # boop -syscon termios TIOCDRAIN 0 0x2000745e 0x2000745e 0x2000745e 0x2000745e 0 # boop +syscon termios TCFLSH 0x540B 0 0 0 0 0 # boop +syscon termios TCSBRK 0x5409 0x2000745e 0x2000745e 0x2000745e 0x2000745e 0 # TIOCDRAIN on BSD +syscon termios TCXONC 0x540A 0 0 0 0 0 # boop +syscon termios TIOCDRAIN 0x5409 0x2000745e 0x2000745e 0x2000745e 0x2000745e 0 # TCSBRK on Linux syscon termios TIOCSTAT 0 0x20007465 0x20007465 0x20007465 0x20007465 0 # boop syscon termios TIOCSTART 0 0x2000746e 0x2000746e 0x2000746e 0x2000746e 0 # boop syscon termios TIOCCDTR 0 0x20007478 0x20007478 0x20007478 0x20007478 0 # boop @@ -1428,6 +1447,7 @@ syscon termios VT1 0b0100000000000000 0b010000000000000000 0b0100000000000 syscon termios FFDLY 0b1000000000000000 0b000100000000000000 0b000100000000000000 0 0 0b1000000000000000 # termios.c_oflag syscon termios FF0 0b0000000000000000 0b000000000000000000 0b000000000000000000 0 0 0b0000000000000000 # termios.c_oflag syscon termios FF1 0b1000000000000000 0b000100000000000000 0b000100000000000000 0 0 0b1000000000000000 # termios.c_oflag +syscon termios CS5 0 0 0 0 0 0 # consensus syscon termios CS6 0b0000000000010000 0b0000000100000000 0b0000000100000000 0b0000000100000000 0b0000000100000000 0b0000000000010000 # termios.c_cflag flag for 6-bit characters syscon termios CS7 0b0000000000100000 0b0000001000000000 0b0000001000000000 0b0000001000000000 0b0000001000000000 0b0000000000100000 # termios.c_cflag flag for 7-bit characters syscon termios CS8 0b0000000000110000 0b0000001100000000 0b0000001100000000 0b0000001100000000 0b0000001100000000 0b0000000000110000 # termios.c_cflag flag for 8-bit characters @@ -1478,6 +1498,13 @@ syscon termios TCION 3 4 4 4 4 0 # bsd consensus syscon termios TCOFLUSH 1 2 2 2 2 0 # bsd consensus syscon termios TCOOFF 0 1 1 1 1 0 # bsd consensus syscon termios TCOON 1 2 2 2 2 0 # bsd consensus +syscon termios CREAD 0x80 0x0800 0x0800 0x0800 0x0800 0 # bsd consensus +syscon termios CSTOPB 0x40 0x0400 0x0400 0x0400 0x0400 0 # bsd consensus +syscon termios HUPCL 0x0400 0x4000 0x4000 0x4000 0x4000 0 # bsd consensus +syscon termios CSTART 17 17 17 17 17 0 # unix consensus +syscon termios CSTOP 19 19 19 19 19 0 # unix consensus +syscon termios CSUSP 26 26 26 26 26 0 # unix consensus +syscon termios CWERASE 23 23 23 23 23 0 # unix consensus # Pseudoteletypewriter Control # @@ -1721,6 +1748,7 @@ syscon misc NL_SETD 1 1 0 1 1 0 syscon rusage RUSAGE_SELF 0 0 0 0 0 0 # unix consensus & faked nt syscon rusage RUSAGE_CHILDREN -1 -1 -1 -1 -1 99 # unix consensus & unavailable on nt +syscon rusage RUSAGE_BOTH -2 99 99 99 99 99 # woop syscon rusage RUSAGE_THREAD 1 99 1 1 1 1 # faked nt & unavailable on xnu syscon misc FSETLOCKING_QUERY 0 0 0 0 0 0 # consensus @@ -1807,8 +1835,6 @@ syscon misc MCAST_EXCLUDE 0 2 2 0 0 0 syscon misc MCAST_MSFILTER 48 0 0 0 0 0 syscon misc AREGTYPE 0 0 0 0 0 0 # consensus -syscon misc B0 0 0 0 0 0 0 # consensus -syscon misc CS5 0 0 0 0 0 0 # consensus syscon misc CTIME 0 0 0 0 0 0 # consensus syscon misc EFD_CLOEXEC 0x080000 0 0 0 0 0 syscon misc EFD_NONBLOCK 0x0800 0 0 0 0 0 @@ -1897,10 +1923,6 @@ syscon misc COPY_VERIFY 58 0 0 0 0 0 syscon misc CQUIT 28 28 28 28 28 0 # unix consensus syscon misc CREPRINT 18 18 18 18 18 0 # unix consensus syscon misc CRPRNT 18 18 18 18 18 0 # unix consensus -syscon misc CSTART 17 17 17 17 17 0 # unix consensus -syscon misc CSTOP 19 19 19 19 19 0 # unix consensus -syscon misc CSUSP 26 26 26 26 26 0 # unix consensus -syscon misc CWERASE 23 23 23 23 23 0 # unix consensus syscon misc DATA 3 3 3 3 3 0 # unix consensus syscon misc DEV_BSIZE 0x0200 0x0200 0x0200 0x0200 0x0200 0 # unix consensus syscon misc DIRTYPE 53 53 53 53 53 0 # unix consensus @@ -2980,46 +3002,46 @@ syscon misc AIO_ALLDONE 2 1 3 0 0 0 syscon misc AIO_NOTCANCELED 1 4 2 0 0 0 syscon misc AIO_CANCELED 0 2 1 0 0 0 +syscon baud B0 0 0 0 0 0 0 # consensus +syscon baud B50 1 50 50 50 50 0 # bsd consensus +syscon baud B75 2 75 75 75 75 0 # bsd consensus +syscon baud B110 3 110 110 110 110 0 # bsd consensus +syscon baud B134 4 134 134 134 134 0 # bsd consensus +syscon baud B150 5 150 150 150 150 0 # bsd consensus +syscon baud B200 6 200 200 200 200 0 # bsd consensus +syscon baud B300 7 300 300 300 300 0 # bsd consensus +syscon baud B600 8 600 600 600 600 0 # bsd consensus +syscon baud B1200 9 0x04b0 0x04b0 0x04b0 0x04b0 0 # bsd consensus +syscon baud B1800 10 0x0708 0x0708 0x0708 0x0708 0 # bsd consensus +syscon baud B2400 11 0x0960 0x0960 0x0960 0x0960 0 # bsd consensus +syscon baud B4800 12 0x12c0 0x12c0 0x12c0 0x12c0 0 # bsd consensus +syscon baud B9600 13 0x2580 0x2580 0x2580 0x2580 0 # bsd consensus +syscon baud B19200 14 0x4b00 0x4b00 0x4b00 0x4b00 0 # bsd consensus +syscon baud B38400 15 0x9600 0x9600 0x9600 0x9600 0 # bsd consensus +syscon baud B57600 0x1001 0xe100 0xe100 0xe100 0xe100 0 # bsd consensus +syscon baud B115200 0x1002 0x01c200 0x01c200 0x01c200 0x01c200 0 # bsd consensus +syscon baud B230400 0x1003 0x038400 0x038400 0x038400 0x038400 0 # bsd consensus +syscon baud B500000 0x1005 0 0 0 0 0 +syscon baud B576000 0x1006 0 0 0 0 0 +syscon baud B1000000 0x1008 0 0 0 0 0 +syscon baud B1152000 0x1009 0 0 0 0 0 +syscon baud B1500000 0x100a 0 0 0 0 0 +syscon baud B2000000 0x100b 0 0 0 0 0 +syscon baud B2500000 0x100c 0 0 0 0 0 +syscon baud B3000000 0x100d 0 0 0 0 0 +syscon baud B3500000 0x100e 0 0 0 0 0 +syscon baud B4000000 0x100f 0 0 0 0 0 + syscon misc ALLOW_MEDIUM_REMOVAL 30 0 0 0 0 0 syscon misc ASU 0 2 2 2 2 0 # bsd consensus syscon misc ATF_NETMASK 0x20 0 0 0 0 0 syscon misc AXSIG 0 0x10 0x10 0x10 0x10 0 # bsd consensus -syscon misc B1000000 0x1008 0 0 0 0 0 -syscon misc B110 3 110 110 110 110 0 # bsd consensus -syscon misc B115200 0x1002 0x01c200 0x01c200 0x01c200 0x01c200 0 # bsd consensus -syscon misc B1152000 0x1009 0 0 0 0 0 -syscon misc B1200 9 0x04b0 0x04b0 0x04b0 0x04b0 0 # bsd consensus -syscon misc B134 4 134 134 134 134 0 # bsd consensus -syscon misc B150 5 150 150 150 150 0 # bsd consensus -syscon misc B1500000 0x100a 0 0 0 0 0 -syscon misc B1800 10 0x0708 0x0708 0x0708 0x0708 0 # bsd consensus -syscon misc B19200 14 0x4b00 0x4b00 0x4b00 0x4b00 0 # bsd consensus -syscon misc B200 6 200 200 200 200 0 # bsd consensus -syscon misc B2000000 0x100b 0 0 0 0 0 -syscon misc B230400 0x1003 0x038400 0x038400 0x038400 0x038400 0 # bsd consensus -syscon misc B2400 11 0x0960 0x0960 0x0960 0x0960 0 # bsd consensus -syscon misc B2500000 0x100c 0 0 0 0 0 -syscon misc B300 7 300 300 300 300 0 # bsd consensus -syscon misc B3000000 0x100d 0 0 0 0 0 -syscon misc B3500000 0x100e 0 0 0 0 0 -syscon misc B38400 15 0x9600 0x9600 0x9600 0x9600 0 # bsd consensus -syscon misc B4000000 0x100f 0 0 0 0 0 -syscon misc B4800 12 0x12c0 0x12c0 0x12c0 0x12c0 0 # bsd consensus -syscon misc B50 1 50 50 50 50 0 # bsd consensus -syscon misc B500000 0x1005 0 0 0 0 0 -syscon misc B57600 0x1001 0xe100 0xe100 0xe100 0xe100 0 # bsd consensus -syscon misc B576000 0x1006 0 0 0 0 0 -syscon misc B600 8 600 600 600 600 0 # bsd consensus -syscon misc B75 2 75 75 75 75 0 # bsd consensus -syscon misc B9600 13 0x2580 0x2580 0x2580 0x2580 0 # bsd consensus syscon misc BITSPERBYTE 8 0 0 0 0 0 syscon misc BLANK_CHECK 8 0 0 0 0 0 syscon misc CHANGE_DEFINITION 0x40 0 0 0 0 0 syscon misc CHARBITS 8 0 0 0 0 0 syscon misc CHECK_CONDITION 1 0 0 0 0 0 syscon misc CONDITION_GOOD 2 0 0 0 0 0 -syscon misc CREAD 0x80 0x0800 0x0800 0x0800 0x0800 0 # bsd consensus -syscon misc CSTOPB 0x40 0x0400 0x0400 0x0400 0x0400 0 # bsd consensus syscon misc DATA_PROTECT 7 0 0 0 0 0 syscon misc DELAYTIMER_MAX 0x7fffffff 0 0 0 0 0 syscon misc DMAXEXP 0x0400 0 0 0 0 0 @@ -3044,7 +3066,6 @@ syscon misc FOPEN_MAX 0x10 20 20 20 20 0 # bsd consensus syscon misc FORMAT_UNIT 4 0 0 0 0 0 syscon misc HARDWARE_ERROR 4 0 0 0 0 0 syscon misc HEAD_OF_QUEUE_TAG 33 0 0 0 0 0 -syscon misc HUPCL 0x0400 0x4000 0x4000 0x4000 0x4000 0 # bsd consensus syscon misc IGMP_MEMBERSHIP_QUERY 17 0 0 0 0 0 syscon misc ILLEGAL_REQUEST 5 0 0 0 0 0 syscon misc INITIATE_RECOVERY 15 0 0 0 0 0 diff --git a/libc/sysv/consts/B0.S b/libc/sysv/consts/B0.S index 3f806bfd6..10c881343 100644 --- a/libc/sysv/consts/B0.S +++ b/libc/sysv/consts/B0.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B0,0,0,0,0,0,0 +.syscon baud,B0,0,0,0,0,0,0 diff --git a/libc/sysv/consts/B1000000.S b/libc/sysv/consts/B1000000.S index a193a7131..a9df538cc 100644 --- a/libc/sysv/consts/B1000000.S +++ b/libc/sysv/consts/B1000000.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B1000000,0x1008,0,0,0,0,0 +.syscon baud,B1000000,0x1008,0,0,0,0,0 diff --git a/libc/sysv/consts/B110.S b/libc/sysv/consts/B110.S index 229ee7c24..f881e71c4 100644 --- a/libc/sysv/consts/B110.S +++ b/libc/sysv/consts/B110.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B110,3,110,110,110,110,0 +.syscon baud,B110,3,110,110,110,110,0 diff --git a/libc/sysv/consts/B115200.S b/libc/sysv/consts/B115200.S index f9462c6f7..03754110b 100644 --- a/libc/sysv/consts/B115200.S +++ b/libc/sysv/consts/B115200.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B115200,0x1002,0x01c200,0x01c200,0x01c200,0x01c200,0 +.syscon baud,B115200,0x1002,0x01c200,0x01c200,0x01c200,0x01c200,0 diff --git a/libc/sysv/consts/B1152000.S b/libc/sysv/consts/B1152000.S index 66553db41..a51390a4e 100644 --- a/libc/sysv/consts/B1152000.S +++ b/libc/sysv/consts/B1152000.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B1152000,0x1009,0,0,0,0,0 +.syscon baud,B1152000,0x1009,0,0,0,0,0 diff --git a/libc/sysv/consts/B1200.S b/libc/sysv/consts/B1200.S index b430d2aa7..4aadfb7fa 100644 --- a/libc/sysv/consts/B1200.S +++ b/libc/sysv/consts/B1200.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B1200,9,0x04b0,0x04b0,0x04b0,0x04b0,0 +.syscon baud,B1200,9,0x04b0,0x04b0,0x04b0,0x04b0,0 diff --git a/libc/sysv/consts/B134.S b/libc/sysv/consts/B134.S index 08ae007b3..72abd7770 100644 --- a/libc/sysv/consts/B134.S +++ b/libc/sysv/consts/B134.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B134,4,134,134,134,134,0 +.syscon baud,B134,4,134,134,134,134,0 diff --git a/libc/sysv/consts/B150.S b/libc/sysv/consts/B150.S index 1708a6b0a..e4551c9cf 100644 --- a/libc/sysv/consts/B150.S +++ b/libc/sysv/consts/B150.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B150,5,150,150,150,150,0 +.syscon baud,B150,5,150,150,150,150,0 diff --git a/libc/sysv/consts/B1500000.S b/libc/sysv/consts/B1500000.S index 59edebc7a..de0391547 100644 --- a/libc/sysv/consts/B1500000.S +++ b/libc/sysv/consts/B1500000.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B1500000,0x100a,0,0,0,0,0 +.syscon baud,B1500000,0x100a,0,0,0,0,0 diff --git a/libc/sysv/consts/B1800.S b/libc/sysv/consts/B1800.S index 97057c678..594d187ac 100644 --- a/libc/sysv/consts/B1800.S +++ b/libc/sysv/consts/B1800.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B1800,10,0x0708,0x0708,0x0708,0x0708,0 +.syscon baud,B1800,10,0x0708,0x0708,0x0708,0x0708,0 diff --git a/libc/sysv/consts/B19200.S b/libc/sysv/consts/B19200.S index 2b938092d..1f1a7dbf9 100644 --- a/libc/sysv/consts/B19200.S +++ b/libc/sysv/consts/B19200.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B19200,14,0x4b00,0x4b00,0x4b00,0x4b00,0 +.syscon baud,B19200,14,0x4b00,0x4b00,0x4b00,0x4b00,0 diff --git a/libc/sysv/consts/B200.S b/libc/sysv/consts/B200.S index 64757f2ea..e0f2164d5 100644 --- a/libc/sysv/consts/B200.S +++ b/libc/sysv/consts/B200.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B200,6,200,200,200,200,0 +.syscon baud,B200,6,200,200,200,200,0 diff --git a/libc/sysv/consts/B2000000.S b/libc/sysv/consts/B2000000.S index 4857b0c3c..1669832a1 100644 --- a/libc/sysv/consts/B2000000.S +++ b/libc/sysv/consts/B2000000.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B2000000,0x100b,0,0,0,0,0 +.syscon baud,B2000000,0x100b,0,0,0,0,0 diff --git a/libc/sysv/consts/B230400.S b/libc/sysv/consts/B230400.S index 68d2874bb..c44512297 100644 --- a/libc/sysv/consts/B230400.S +++ b/libc/sysv/consts/B230400.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B230400,0x1003,0x038400,0x038400,0x038400,0x038400,0 +.syscon baud,B230400,0x1003,0x038400,0x038400,0x038400,0x038400,0 diff --git a/libc/sysv/consts/B2400.S b/libc/sysv/consts/B2400.S index 6a5ab6f87..5ba9c3019 100644 --- a/libc/sysv/consts/B2400.S +++ b/libc/sysv/consts/B2400.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B2400,11,0x0960,0x0960,0x0960,0x0960,0 +.syscon baud,B2400,11,0x0960,0x0960,0x0960,0x0960,0 diff --git a/libc/sysv/consts/B2500000.S b/libc/sysv/consts/B2500000.S index 36e6bcf0d..398957ecb 100644 --- a/libc/sysv/consts/B2500000.S +++ b/libc/sysv/consts/B2500000.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B2500000,0x100c,0,0,0,0,0 +.syscon baud,B2500000,0x100c,0,0,0,0,0 diff --git a/libc/sysv/consts/B300.S b/libc/sysv/consts/B300.S index ede62dcd0..4eb78fd3b 100644 --- a/libc/sysv/consts/B300.S +++ b/libc/sysv/consts/B300.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B300,7,300,300,300,300,0 +.syscon baud,B300,7,300,300,300,300,0 diff --git a/libc/sysv/consts/B3000000.S b/libc/sysv/consts/B3000000.S index 61b7733f1..46aa04775 100644 --- a/libc/sysv/consts/B3000000.S +++ b/libc/sysv/consts/B3000000.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B3000000,0x100d,0,0,0,0,0 +.syscon baud,B3000000,0x100d,0,0,0,0,0 diff --git a/libc/sysv/consts/B3500000.S b/libc/sysv/consts/B3500000.S index a9080990f..c4a88b813 100644 --- a/libc/sysv/consts/B3500000.S +++ b/libc/sysv/consts/B3500000.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B3500000,0x100e,0,0,0,0,0 +.syscon baud,B3500000,0x100e,0,0,0,0,0 diff --git a/libc/sysv/consts/B38400.S b/libc/sysv/consts/B38400.S index 87685a4c2..2b89d8327 100644 --- a/libc/sysv/consts/B38400.S +++ b/libc/sysv/consts/B38400.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B38400,15,0x9600,0x9600,0x9600,0x9600,0 +.syscon baud,B38400,15,0x9600,0x9600,0x9600,0x9600,0 diff --git a/libc/sysv/consts/B4000000.S b/libc/sysv/consts/B4000000.S index b958620ee..53d35ce59 100644 --- a/libc/sysv/consts/B4000000.S +++ b/libc/sysv/consts/B4000000.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B4000000,0x100f,0,0,0,0,0 +.syscon baud,B4000000,0x100f,0,0,0,0,0 diff --git a/libc/sysv/consts/B4800.S b/libc/sysv/consts/B4800.S index 65463c0ff..3ec42ec1c 100644 --- a/libc/sysv/consts/B4800.S +++ b/libc/sysv/consts/B4800.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B4800,12,0x12c0,0x12c0,0x12c0,0x12c0,0 +.syscon baud,B4800,12,0x12c0,0x12c0,0x12c0,0x12c0,0 diff --git a/libc/sysv/consts/B50.S b/libc/sysv/consts/B50.S index 91f1b6128..f226f4ac5 100644 --- a/libc/sysv/consts/B50.S +++ b/libc/sysv/consts/B50.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B50,1,50,50,50,50,0 +.syscon baud,B50,1,50,50,50,50,0 diff --git a/libc/sysv/consts/B500000.S b/libc/sysv/consts/B500000.S index efef699cf..ce55ea22f 100644 --- a/libc/sysv/consts/B500000.S +++ b/libc/sysv/consts/B500000.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B500000,0x1005,0,0,0,0,0 +.syscon baud,B500000,0x1005,0,0,0,0,0 diff --git a/libc/sysv/consts/B57600.S b/libc/sysv/consts/B57600.S index dbdea52c6..c24db80ed 100644 --- a/libc/sysv/consts/B57600.S +++ b/libc/sysv/consts/B57600.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B57600,0x1001,0xe100,0xe100,0xe100,0xe100,0 +.syscon baud,B57600,0x1001,0xe100,0xe100,0xe100,0xe100,0 diff --git a/libc/sysv/consts/B576000.S b/libc/sysv/consts/B576000.S index 62bc5b28d..4e71a6635 100644 --- a/libc/sysv/consts/B576000.S +++ b/libc/sysv/consts/B576000.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B576000,0x1006,0,0,0,0,0 +.syscon baud,B576000,0x1006,0,0,0,0,0 diff --git a/libc/sysv/consts/B600.S b/libc/sysv/consts/B600.S index d4d84c1d0..86ae31586 100644 --- a/libc/sysv/consts/B600.S +++ b/libc/sysv/consts/B600.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B600,8,600,600,600,600,0 +.syscon baud,B600,8,600,600,600,600,0 diff --git a/libc/sysv/consts/B75.S b/libc/sysv/consts/B75.S index 0e552f083..0935d33ad 100644 --- a/libc/sysv/consts/B75.S +++ b/libc/sysv/consts/B75.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B75,2,75,75,75,75,0 +.syscon baud,B75,2,75,75,75,75,0 diff --git a/libc/sysv/consts/B9600.S b/libc/sysv/consts/B9600.S index 5c6f1295e..47bc775bd 100644 --- a/libc/sysv/consts/B9600.S +++ b/libc/sysv/consts/B9600.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,B9600,13,0x2580,0x2580,0x2580,0x2580,0 +.syscon baud,B9600,13,0x2580,0x2580,0x2580,0x2580,0 diff --git a/libc/sysv/consts/CREAD.S b/libc/sysv/consts/CREAD.S index fdebf977c..1eac14cd8 100644 --- a/libc/sysv/consts/CREAD.S +++ b/libc/sysv/consts/CREAD.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,CREAD,0x80,0x0800,0x0800,0x0800,0x0800,0 +.syscon termios,CREAD,0x80,0x0800,0x0800,0x0800,0x0800,0 diff --git a/libc/sysv/consts/CS5.S b/libc/sysv/consts/CS5.S index 39cafe58a..01a9b5895 100644 --- a/libc/sysv/consts/CS5.S +++ b/libc/sysv/consts/CS5.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,CS5,0,0,0,0,0,0 +.syscon termios,CS5,0,0,0,0,0,0 diff --git a/libc/sysv/consts/CSTART.S b/libc/sysv/consts/CSTART.S index 39d478b10..c1bacf88d 100644 --- a/libc/sysv/consts/CSTART.S +++ b/libc/sysv/consts/CSTART.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,CSTART,17,17,17,17,17,0 +.syscon termios,CSTART,17,17,17,17,17,0 diff --git a/libc/sysv/consts/CSTOP.S b/libc/sysv/consts/CSTOP.S index f432f87e1..fb8a62ec6 100644 --- a/libc/sysv/consts/CSTOP.S +++ b/libc/sysv/consts/CSTOP.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,CSTOP,19,19,19,19,19,0 +.syscon termios,CSTOP,19,19,19,19,19,0 diff --git a/libc/sysv/consts/CSTOPB.S b/libc/sysv/consts/CSTOPB.S index 73741361b..0e8700592 100644 --- a/libc/sysv/consts/CSTOPB.S +++ b/libc/sysv/consts/CSTOPB.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,CSTOPB,0x40,0x0400,0x0400,0x0400,0x0400,0 +.syscon termios,CSTOPB,0x40,0x0400,0x0400,0x0400,0x0400,0 diff --git a/libc/sysv/consts/CSUSP.S b/libc/sysv/consts/CSUSP.S index d770baa8e..919249c69 100644 --- a/libc/sysv/consts/CSUSP.S +++ b/libc/sysv/consts/CSUSP.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,CSUSP,26,26,26,26,26,0 +.syscon termios,CSUSP,26,26,26,26,26,0 diff --git a/libc/sysv/consts/CWERASE.S b/libc/sysv/consts/CWERASE.S index 05e800c4d..a19f3365c 100644 --- a/libc/sysv/consts/CWERASE.S +++ b/libc/sysv/consts/CWERASE.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,CWERASE,23,23,23,23,23,0 +.syscon termios,CWERASE,23,23,23,23,23,0 diff --git a/libc/sysv/consts/FIOCLEX.S b/libc/sysv/consts/FIOCLEX.S new file mode 100644 index 000000000..6ee37bad7 --- /dev/null +++ b/libc/sysv/consts/FIOCLEX.S @@ -0,0 +1,2 @@ +#include "libc/sysv/consts/syscon.internal.h" +.syscon ioctl,FIOCLEX,0x5451,0x20006601,0x20006601,0x20006601,0x20006601,0x5451 diff --git a/libc/sysv/consts/FIONCLEX.S b/libc/sysv/consts/FIONCLEX.S new file mode 100644 index 000000000..8113394d1 --- /dev/null +++ b/libc/sysv/consts/FIONCLEX.S @@ -0,0 +1,2 @@ +#include "libc/sysv/consts/syscon.internal.h" +.syscon ioctl,FIONCLEX,0x5450,0x20006602,0x20006602,0x20006602,0x20006602,0x5450 diff --git a/libc/sysv/consts/F_DUPFD_CLOEXEC.S b/libc/sysv/consts/F_DUPFD_CLOEXEC.S index 002378bff..6f74a43d5 100644 --- a/libc/sysv/consts/F_DUPFD_CLOEXEC.S +++ b/libc/sysv/consts/F_DUPFD_CLOEXEC.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon fcntl,F_DUPFD_CLOEXEC,0x0406,67,17,10,12,0 +.syscon fcntl,F_DUPFD_CLOEXEC,0x0406,67,17,10,12,0x0406 diff --git a/libc/sysv/consts/HUPCL.S b/libc/sysv/consts/HUPCL.S index 09b7f5b87..dd03f7ab0 100644 --- a/libc/sysv/consts/HUPCL.S +++ b/libc/sysv/consts/HUPCL.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon misc,HUPCL,0x0400,0x4000,0x4000,0x4000,0x4000,0 +.syscon termios,HUPCL,0x0400,0x4000,0x4000,0x4000,0x4000,0 diff --git a/libc/sysv/consts/O_EXLOCK.S b/libc/sysv/consts/O_EXLOCK.S new file mode 100644 index 000000000..bd8eaa1f3 --- /dev/null +++ b/libc/sysv/consts/O_EXLOCK.S @@ -0,0 +1,2 @@ +#include "libc/sysv/consts/syscon.internal.h" +.syscon open,O_EXLOCK,0,0x00000020,0x00000020,0x00000020,0x00000020,0 diff --git a/libc/sysv/consts/O_SEARCH.S b/libc/sysv/consts/O_SEARCH.S new file mode 100644 index 000000000..361efe674 --- /dev/null +++ b/libc/sysv/consts/O_SEARCH.S @@ -0,0 +1,2 @@ +#include "libc/sysv/consts/syscon.internal.h" +.syscon open,O_SEARCH,0,0,0x00040000,0,0x00800000,0 diff --git a/libc/sysv/consts/O_SHLOCK.S b/libc/sysv/consts/O_SHLOCK.S new file mode 100644 index 000000000..515f78b0c --- /dev/null +++ b/libc/sysv/consts/O_SHLOCK.S @@ -0,0 +1,2 @@ +#include "libc/sysv/consts/syscon.internal.h" +.syscon open,O_SHLOCK,0,0x00000010,0x00000010,0x00000010,0x00000010,0 diff --git a/libc/sysv/consts/RLIMIT_NPTS.S b/libc/sysv/consts/RLIMIT_NPTS.S new file mode 100644 index 000000000..2eb11efae --- /dev/null +++ b/libc/sysv/consts/RLIMIT_NPTS.S @@ -0,0 +1,2 @@ +#include "libc/sysv/consts/syscon.internal.h" +.syscon rlimit,RLIMIT_NPTS,127,127,11,127,127,127 diff --git a/libc/sysv/consts/RLIMIT_RTTIME.S b/libc/sysv/consts/RLIMIT_RTTIME.S new file mode 100644 index 000000000..a0ce0c97c --- /dev/null +++ b/libc/sysv/consts/RLIMIT_RTTIME.S @@ -0,0 +1,2 @@ +#include "libc/sysv/consts/syscon.internal.h" +.syscon rlimit,RLIMIT_RTTIME,15,127,127,127,127,127 diff --git a/libc/sysv/consts/RLIMIT_SBSIZE.S b/libc/sysv/consts/RLIMIT_SBSIZE.S new file mode 100644 index 000000000..7c0d8c733 --- /dev/null +++ b/libc/sysv/consts/RLIMIT_SBSIZE.S @@ -0,0 +1,2 @@ +#include "libc/sysv/consts/syscon.internal.h" +.syscon rlimit,RLIMIT_SBSIZE,127,127,9,127,127,127 diff --git a/libc/sysv/consts/RLIMIT_SWAP.S b/libc/sysv/consts/RLIMIT_SWAP.S new file mode 100644 index 000000000..e050a7b04 --- /dev/null +++ b/libc/sysv/consts/RLIMIT_SWAP.S @@ -0,0 +1,2 @@ +#include "libc/sysv/consts/syscon.internal.h" +.syscon rlimit,RLIMIT_SWAP,127,127,12,127,127,127 diff --git a/libc/sysv/consts/RUSAGE_BOTH.S b/libc/sysv/consts/RUSAGE_BOTH.S new file mode 100644 index 000000000..81a577b18 --- /dev/null +++ b/libc/sysv/consts/RUSAGE_BOTH.S @@ -0,0 +1,2 @@ +#include "libc/sysv/consts/syscon.internal.h" +.syscon rusage,RUSAGE_BOTH,-2,99,99,99,99,99 diff --git a/libc/sysv/consts/SF_MNOWAIT.S b/libc/sysv/consts/SF_MNOWAIT.S new file mode 100644 index 000000000..763cb660a --- /dev/null +++ b/libc/sysv/consts/SF_MNOWAIT.S @@ -0,0 +1,2 @@ +#include "libc/sysv/consts/syscon.internal.h" +.syscon sf,SF_MNOWAIT,0,0,2,0,0,0 diff --git a/libc/sysv/consts/SF_NODISKIO.S b/libc/sysv/consts/SF_NODISKIO.S new file mode 100644 index 000000000..a26612e8b --- /dev/null +++ b/libc/sysv/consts/SF_NODISKIO.S @@ -0,0 +1,2 @@ +#include "libc/sysv/consts/syscon.internal.h" +.syscon sf,SF_NODISKIO,0,0,1,0,0,0 diff --git a/libc/sysv/consts/SF_SYNC.S b/libc/sysv/consts/SF_SYNC.S new file mode 100644 index 000000000..f3cb43f3c --- /dev/null +++ b/libc/sysv/consts/SF_SYNC.S @@ -0,0 +1,2 @@ +#include "libc/sysv/consts/syscon.internal.h" +.syscon sf,SF_SYNC,0,0,4,0,0,0 diff --git a/libc/sysv/consts/ST_NOATIME.S b/libc/sysv/consts/ST_NOATIME.S index 1e4d7b62d..13d80988b 100644 --- a/libc/sysv/consts/ST_NOATIME.S +++ b/libc/sysv/consts/ST_NOATIME.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon statvfs,ST_NOATIME,0x0400,0,0,0,0,0 +.syscon statvfs,ST_NOATIME,0x0400,0,0,0x04000000,0,0 diff --git a/libc/sysv/consts/ST_NODEV.S b/libc/sysv/consts/ST_NODEV.S index 7b8b1e936..af3cc1be2 100644 --- a/libc/sysv/consts/ST_NODEV.S +++ b/libc/sysv/consts/ST_NODEV.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon statvfs,ST_NODEV,4,0,0,0,0,0 +.syscon statvfs,ST_NODEV,4,0,0,0,0x00000010,0 diff --git a/libc/sysv/consts/ST_NOEXEC.S b/libc/sysv/consts/ST_NOEXEC.S index ac55a179d..d105b8d8e 100644 --- a/libc/sysv/consts/ST_NOEXEC.S +++ b/libc/sysv/consts/ST_NOEXEC.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon statvfs,ST_NOEXEC,8,0,0,0,0,0 +.syscon statvfs,ST_NOEXEC,8,0,0,0,4,0 diff --git a/libc/sysv/consts/ST_RELATIME.S b/libc/sysv/consts/ST_RELATIME.S index 6b075f500..b645051db 100644 --- a/libc/sysv/consts/ST_RELATIME.S +++ b/libc/sysv/consts/ST_RELATIME.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon statvfs,ST_RELATIME,0x1000,0,0,0,0,0 +.syscon statvfs,ST_RELATIME,0x1000,0,0,0,0x00020000,0 diff --git a/libc/sysv/consts/ST_SYNCHRONOUS.S b/libc/sysv/consts/ST_SYNCHRONOUS.S index 3ee29b546..9e7308849 100644 --- a/libc/sysv/consts/ST_SYNCHRONOUS.S +++ b/libc/sysv/consts/ST_SYNCHRONOUS.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon statvfs,ST_SYNCHRONOUS,0x10,0,0,0,0,0 +.syscon statvfs,ST_SYNCHRONOUS,0x10,0,0,0,2,0 diff --git a/libc/sysv/consts/TCSBRK.S b/libc/sysv/consts/TCSBRK.S new file mode 100644 index 000000000..059f9c0cf --- /dev/null +++ b/libc/sysv/consts/TCSBRK.S @@ -0,0 +1,2 @@ +#include "libc/sysv/consts/syscon.internal.h" +.syscon termios,TCSBRK,0x5409,0x2000745e,0x2000745e,0x2000745e,0x2000745e,0 diff --git a/libc/sysv/consts/TCXONC.S b/libc/sysv/consts/TCXONC.S new file mode 100644 index 000000000..aa10407d7 --- /dev/null +++ b/libc/sysv/consts/TCXONC.S @@ -0,0 +1,2 @@ +#include "libc/sysv/consts/syscon.internal.h" +.syscon termios,TCXONC,0x540A,0,0,0,0,0 diff --git a/libc/sysv/consts/TIOCDRAIN.S b/libc/sysv/consts/TIOCDRAIN.S index 6d3a7e5df..38e3ec78f 100644 --- a/libc/sysv/consts/TIOCDRAIN.S +++ b/libc/sysv/consts/TIOCDRAIN.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCDRAIN,0,0x2000745e,0x2000745e,0x2000745e,0x2000745e,0 +.syscon termios,TIOCDRAIN,0x5409,0x2000745e,0x2000745e,0x2000745e,0x2000745e,0 diff --git a/libc/sysv/consts/TIOCGSID.S b/libc/sysv/consts/TIOCGSID.S index 8c342d9c2..6418837d3 100644 --- a/libc/sysv/consts/TIOCGSID.S +++ b/libc/sysv/consts/TIOCGSID.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCGSID,0x5429,0,0x40047463,0x40047463,0x40047463,0 +.syscon termios,TIOCGSID,0x5429,0x40047463,0x40047463,0x40047463,0x40047463,0 diff --git a/libc/sysv/consts/baud.h b/libc/sysv/consts/baud.h new file mode 100644 index 000000000..d4e2e8326 --- /dev/null +++ b/libc/sysv/consts/baud.h @@ -0,0 +1,70 @@ +#ifndef COSMOPOLITAN_LIBC_SYSV_CONSTS_BAUD_H_ +#define COSMOPOLITAN_LIBC_SYSV_CONSTS_BAUD_H_ +#include "libc/runtime/symbolic.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +extern const long B0; +extern const long B50; +extern const long B75; +extern const long B110; +extern const long B134; +extern const long B150; +extern const long B200; +extern const long B300; +extern const long B600; +extern const long B1200; +extern const long B1800; +extern const long B2400; +extern const long B4800; +extern const long B9600; +extern const long B19200; +extern const long B38400; +extern const long B57600; +extern const long B115200; +extern const long B230400; +extern const long B500000; +extern const long B576000; +extern const long B1000000; +extern const long B1152000; +extern const long B1500000; +extern const long B2000000; +extern const long B2500000; +extern const long B3000000; +extern const long B3500000; +extern const long B4000000; + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ + +#define B0 LITERALLY(0) +#define B50 SYMBOLIC(B50) +#define B75 SYMBOLIC(B75) +#define B110 SYMBOLIC(B110) +#define B134 SYMBOLIC(B134) +#define B150 SYMBOLIC(B150) +#define B200 SYMBOLIC(B200) +#define B300 SYMBOLIC(B300) +#define B600 SYMBOLIC(B600) +#define B1200 SYMBOLIC(B1200) +#define B1800 SYMBOLIC(B1800) +#define B2400 SYMBOLIC(B2400) +#define B4800 SYMBOLIC(B4800) +#define B9600 SYMBOLIC(B9600) +#define B19200 SYMBOLIC(B19200) +#define B38400 SYMBOLIC(B38400) +#define B57600 SYMBOLIC(B57600) +#define B115200 SYMBOLIC(B115200) +#define B230400 SYMBOLIC(B230400) +#define B500000 SYMBOLIC(B500000) +#define B576000 SYMBOLIC(B576000) +#define B1000000 SYMBOLIC(B1000000) +#define B1152000 SYMBOLIC(B1152000) +#define B1500000 SYMBOLIC(B1500000) +#define B2000000 SYMBOLIC(B2000000) +#define B2500000 SYMBOLIC(B2500000) +#define B3000000 SYMBOLIC(B3000000) +#define B3500000 SYMBOLIC(B3500000) +#define B4000000 SYMBOLIC(B4000000) + +#endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_BAUD_H_ */ diff --git a/libc/sysv/consts/fio.h b/libc/sysv/consts/fio.h index 189edbe7d..dc7a71086 100644 --- a/libc/sysv/consts/fio.h +++ b/libc/sysv/consts/fio.h @@ -4,15 +4,19 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -extern const long FIONBIO; -extern const long FIONREAD; extern const long FIOASYNC; +extern const long FIOCLEX; +extern const long FIONBIO; +extern const long FIONCLEX; +extern const long FIONREAD; COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#define FIONBIO SYMBOLIC(FIONBIO) -#define FIONREAD SYMBOLIC(FIONREAD) #define FIOASYNC SYMBOLIC(FIOASYNC) +#define FIOCLEX SYMBOLIC(FIOCLEX) +#define FIONBIO SYMBOLIC(FIONBIO) +#define FIONCLEX SYMBOLIC(FIONCLEX) +#define FIONREAD SYMBOLIC(FIONREAD) #endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_FIO_H_ */ diff --git a/libc/sysv/consts/o.h b/libc/sysv/consts/o.h index 45ac3b309..e8675f2db 100644 --- a/libc/sysv/consts/o.h +++ b/libc/sysv/consts/o.h @@ -14,6 +14,7 @@ extern const long O_DIRECTORY; extern const long O_DSYNC; extern const long O_EXCL; extern const long O_EXEC; +extern const long O_EXLOCK; extern const long O_LARGEFILE; extern const long O_NDELAY; extern const long O_NOATIME; @@ -24,6 +25,8 @@ extern const long O_PATH; extern const long O_RDONLY; extern const long O_RDWR; extern const long O_RSYNC; +extern const long O_SEARCH; +extern const long O_SHLOCK; extern const long O_SPARSE; extern const long O_SYNC; extern const long O_TMPFILE; @@ -34,31 +37,34 @@ extern const long O_WRONLY; COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#define O_ACCMODE SYMBOLIC(O_ACCMODE) -#define O_APPEND SYMBOLIC(O_APPEND) -#define O_ASYNC SYMBOLIC(O_ASYNC) -#define O_CLOEXEC SYMBOLIC(O_CLOEXEC) -#define O_CREAT SYMBOLIC(O_CREAT) -#define O_DIRECT SYMBOLIC(O_DIRECT) +#define O_ACCMODE SYMBOLIC(O_ACCMODE) +#define O_APPEND SYMBOLIC(O_APPEND) +#define O_ASYNC SYMBOLIC(O_ASYNC) +#define O_CLOEXEC SYMBOLIC(O_CLOEXEC) +#define O_CREAT SYMBOLIC(O_CREAT) +#define O_DIRECT SYMBOLIC(O_DIRECT) #define O_DIRECTORY SYMBOLIC(O_DIRECTORY) -#define O_DSYNC SYMBOLIC(O_DSYNC) -#define O_EXCL SYMBOLIC(O_EXCL) -#define O_EXEC SYMBOLIC(O_EXEC) +#define O_DSYNC SYMBOLIC(O_DSYNC) +#define O_EXCL SYMBOLIC(O_EXCL) +#define O_EXEC SYMBOLIC(O_EXEC) +#define O_EXLOCK SYMBOLIC(O_EXLOCK) #define O_LARGEFILE SYMBOLIC(O_LARGEFILE) -#define O_NDELAY SYMBOLIC(O_NDELAY) -#define O_NOATIME SYMBOLIC(O_NOATIME) -#define O_NOCTTY SYMBOLIC(O_NOCTTY) -#define O_NOFOLLOW SYMBOLIC(O_NOFOLLOW) -#define O_NONBLOCK SYMBOLIC(O_NONBLOCK) -#define O_PATH SYMBOLIC(O_PATH) -#define O_RDONLY SYMBOLIC(O_RDONLY) -#define O_RDWR SYMBOLIC(O_RDWR) -#define O_RSYNC SYMBOLIC(O_RSYNC) -#define O_SPARSE SYMBOLIC(O_SPARSE) -#define O_SYNC SYMBOLIC(O_SYNC) -#define O_TMPFILE SYMBOLIC(O_TMPFILE) -#define O_TRUNC SYMBOLIC(O_TRUNC) -#define O_TTY_INIT SYMBOLIC(O_TTY_INIT) -#define O_WRONLY SYMBOLIC(O_WRONLY) +#define O_NDELAY SYMBOLIC(O_NDELAY) +#define O_NOATIME SYMBOLIC(O_NOATIME) +#define O_NOCTTY SYMBOLIC(O_NOCTTY) +#define O_NOFOLLOW SYMBOLIC(O_NOFOLLOW) +#define O_NONBLOCK SYMBOLIC(O_NONBLOCK) +#define O_PATH SYMBOLIC(O_PATH) +#define O_RDONLY SYMBOLIC(O_RDONLY) +#define O_RDWR SYMBOLIC(O_RDWR) +#define O_RSYNC SYMBOLIC(O_RSYNC) +#define O_SEARCH SYMBOLIC(O_SEARCH) +#define O_SHLOCK SYMBOLIC(O_SHLOCK) +#define O_SPARSE SYMBOLIC(O_SPARSE) +#define O_SYNC SYMBOLIC(O_SYNC) +#define O_TMPFILE SYMBOLIC(O_TMPFILE) +#define O_TRUNC SYMBOLIC(O_TRUNC) +#define O_TTY_INIT SYMBOLIC(O_TTY_INIT) +#define O_WRONLY SYMBOLIC(O_WRONLY) #endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_O_H_ */ diff --git a/libc/sysv/consts/rlimit.h b/libc/sysv/consts/rlimit.h index c847974e4..b5b20041f 100644 --- a/libc/sysv/consts/rlimit.h +++ b/libc/sysv/consts/rlimit.h @@ -13,10 +13,14 @@ #define RLIMIT_NICE SYMBOLIC(RLIMIT_NICE) #define RLIMIT_NOFILE SYMBOLIC(RLIMIT_NOFILE) #define RLIMIT_NPROC SYMBOLIC(RLIMIT_NPROC) +#define RLIMIT_NPTS SYMBOLIC(RLIMIT_NPTS) #define RLIMIT_RSS SYMBOLIC(RLIMIT_RSS) #define RLIMIT_RTPRIO SYMBOLIC(RLIMIT_RTPRIO) +#define RLIMIT_RTTIME SYMBOLIC(RLIMIT_RTTIME) +#define RLIMIT_SBSIZE SYMBOLIC(RLIMIT_SBSIZE) #define RLIMIT_SIGPENDING SYMBOLIC(RLIMIT_SIGPENDING) #define RLIMIT_STACK SYMBOLIC(RLIMIT_STACK) +#define RLIMIT_SWAP SYMBOLIC(RLIMIT_SWAP) #define RLIMIT_VMEM SYMBOLIC(RLIMIT_VMEM) #if !(__ASSEMBLER__ + __LINKER__ + 0) @@ -33,10 +37,14 @@ extern const long RLIMIT_MSGQUEUE; extern const long RLIMIT_NICE; extern const long RLIMIT_NOFILE; extern const long RLIMIT_NPROC; +extern const long RLIMIT_NPTS; extern const long RLIMIT_RSS; extern const long RLIMIT_RTPRIO; +extern const long RLIMIT_RTTIME; +extern const long RLIMIT_SBSIZE; extern const long RLIMIT_SIGPENDING; extern const long RLIMIT_STACK; +extern const long RLIMIT_SWAP; extern const long RLIMIT_VMEM; COSMOPOLITAN_C_END_ diff --git a/libc/sysv/consts/rusage.h b/libc/sysv/consts/rusage.h index c3184300b..420fe13c5 100644 --- a/libc/sysv/consts/rusage.h +++ b/libc/sysv/consts/rusage.h @@ -4,6 +4,7 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ +extern const long RUSAGE_BOTH; extern const long RUSAGE_CHILDREN; extern const long RUSAGE_SELF; extern const long RUSAGE_THREAD; @@ -11,8 +12,9 @@ extern const long RUSAGE_THREAD; COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#define RUSAGE_SELF LITERALLY(0) +#define RUSAGE_BOTH SYMBOLIC(RUSAGE_BOTH) #define RUSAGE_CHILDREN SYMBOLIC(RUSAGE_CHILDREN) -#define RUSAGE_THREAD SYMBOLIC(RUSAGE_THREAD) +#define RUSAGE_SELF LITERALLY(0) +#define RUSAGE_THREAD SYMBOLIC(RUSAGE_THREAD) #endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_RUSAGE_H_ */ diff --git a/libc/sysv/consts/sf.h b/libc/sysv/consts/sf.h new file mode 100644 index 000000000..e4204fba0 --- /dev/null +++ b/libc/sysv/consts/sf.h @@ -0,0 +1,25 @@ +#ifndef COSMOPOLITAN_LIBC_SYSV_CONSTS_SF_H_ +#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SF_H_ +#include "libc/runtime/symbolic.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +struct sf_hdtr { + struct iovec *headers; + int hdr_cnt; + struct iovec *trailers; + int trl_cnt; +}; + +extern const long SF_MNOWAIT; +extern const long SF_NODISKIO; +extern const long SF_SYNC; + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ + +#define SF_MNOWAIT SYMBOLIC(SF_MNOWAIT) +#define SF_NODISKIO SYMBOLIC(SF_NODISKIO) +#define SF_SYNC SYMBOLIC(SF_SYNC) + +#endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_SF_H_ */ diff --git a/libc/sysv/consts/termios.h b/libc/sysv/consts/termios.h index ad9348300..0ddd9d50c 100644 --- a/libc/sysv/consts/termios.h +++ b/libc/sysv/consts/termios.h @@ -5,6 +5,8 @@ COSMOPOLITAN_C_START_ extern const long BRKINT; +extern const long BS1; +extern const long BS2; extern const long BSDLY; extern const long BUSY; extern const long CANBSIZ; @@ -15,11 +17,19 @@ extern const long CEOL; extern const long CIBAUD; extern const long CLOCAL; extern const long CMSPAR; +extern const long CR1; +extern const long CR2; +extern const long CR3; extern const long CRDLY; +extern const long CREAD; +extern const long CS5; extern const long CS6; extern const long CS7; extern const long CS8; extern const long CSIZE; +extern const long CSTOPB; +extern const long CSUSP; +extern const long CWERASE; extern const long ECHO; extern const long ECHOCTL; extern const long ECHOE; @@ -29,9 +39,12 @@ extern const long ECHONL; extern const long ECHOPRT; extern const long ENDRUNDISC; extern const long EXTPROC; +extern const long FF1; +extern const long FF2; extern const long FFDLY; extern const long FLUSHO; extern const long H4DISC; +extern const long HUPCL; extern const long ICANON; extern const long ICRNL; extern const long IEXTEN; @@ -50,6 +63,9 @@ extern const long IXOFF; extern const long IXON; extern const long NCCS; extern const long NETGRAPHDISC; +extern const long NL1; +extern const long NL2; +extern const long NL3; extern const long NLDLY; extern const long NMEADISC; extern const long NOFLSH; @@ -68,15 +84,28 @@ extern const long PENDIN; extern const long PPPDISC; extern const long SLIPDISC; extern const long STRIPDISC; +extern const long TAB1; +extern const long TAB2; +extern const long TAB3; extern const long TABDLY; extern const long TABLDISC; +extern const long TCFLSH; extern const long TCGETS; +extern const long TCIFLUSH; +extern const long TCIOFF; +extern const long TCIOFLUSH; +extern const long TCION; +extern const long TCOFLUSH; +extern const long TCOOFF; +extern const long TCOON; extern const long TCSADRAIN; extern const long TCSAFLUSH; extern const long TCSANOW; +extern const long TCSBRK; extern const long TCSETS; extern const long TCSETSF; extern const long TCSETSW; +extern const long TCXONC; extern const long TIOCCBRK; extern const long TIOCCDTR; extern const long TIOCCHKVERAUTH; @@ -125,8 +154,8 @@ extern const long TOSTOP; extern const long TTYDISC; extern const long VDISCARD; extern const long VEOF; -extern const long VEOL; extern const long VEOL2; +extern const long VEOL; extern const long VERASE; extern const long VERIFY; extern const long VINTR; @@ -139,10 +168,13 @@ extern const long VSTART; extern const long VSTOP; extern const long VSUSP; extern const long VSWTC; +extern const long VT1; +extern const long VT2; extern const long VTDLY; extern const long VTIME; extern const long VWERASE; extern const long XCASE; +extern const long XTABS; COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ @@ -198,10 +230,15 @@ COSMOPOLITAN_C_END_ #define CIBAUD SYMBOLIC(CIBAUD) #define CLOCAL SYMBOLIC(CLOCAL) #define CMSPAR SYMBOLIC(CMSPAR) +#define CREAD SYMBOLIC(CREAD) +#define CS5 SYMBOLIC(CS5) #define CS6 SYMBOLIC(CS6) #define CS7 SYMBOLIC(CS7) #define CS8 SYMBOLIC(CS8) #define CSIZE SYMBOLIC(CSIZE) +#define CSTOPB SYMBOLIC(CSTOPB) +#define CSUSP SYMBOLIC(CSUSP) +#define CWERASE SYMBOLIC(CWERASE) #define ECHO LITERALLY(8) #define ECHOCTL SYMBOLIC(ECHOCTL) #define ECHOE SYMBOLIC(ECHOE) @@ -213,6 +250,7 @@ COSMOPOLITAN_C_END_ #define EXTPROC SYMBOLIC(EXTPROC) #define FLUSHO SYMBOLIC(FLUSHO) #define H4DISC SYMBOLIC(H4DISC) +#define HUPCL SYMBOLIC(HUPCL) #define ICANON SYMBOLIC(ICANON) #define IEXTEN SYMBOLIC(IEXTEN) #define ISIG SYMBOLIC(ISIG) @@ -238,13 +276,24 @@ COSMOPOLITAN_C_END_ #define SLIPDISC SYMBOLIC(SLIPDISC) #define STRIPDISC SYMBOLIC(STRIPDISC) #define TABLDISC SYMBOLIC(TABLDISC) +#define TCFLSH SYMBOLIC(TCFLSH) +#define TCFLSH SYMBOLIC(TCFLSH) #define TCGETS SYMBOLIC(TCGETS) -#define TCSANOW LITERALLY(0) +#define TCIFLUSH SYMBOLIC(TCIFLUSH) +#define TCIOFF SYMBOLIC(TCIOFF) +#define TCIOFLUSH SYMBOLIC(TCIOFLUSH) +#define TCION SYMBOLIC(TCION) +#define TCOFLUSH SYMBOLIC(TCOFLUSH) +#define TCOOFF SYMBOLIC(TCOOFF) +#define TCOON SYMBOLIC(TCOON) #define TCSADRAIN LITERALLY(1) #define TCSAFLUSH LITERALLY(2) +#define TCSANOW LITERALLY(0) +#define TCSBRK SYMBOLIC(TCSBRK) #define TCSETS SYMBOLIC(TCSETS) #define TCSETSF SYMBOLIC(TCSETSF) #define TCSETSW SYMBOLIC(TCSETSW) +#define TCXONC SYMBOLIC(TCXONC) #define TIOCCBRK SYMBOLIC(TIOCCBRK) #define TIOCCDTR SYMBOLIC(TIOCCDTR) #define TIOCCHKVERAUTH SYMBOLIC(TIOCCHKVERAUTH) diff --git a/libc/sysv/consts/waitid.h b/libc/sysv/consts/waitid.h new file mode 100644 index 000000000..3bfd2a4e1 --- /dev/null +++ b/libc/sysv/consts/waitid.h @@ -0,0 +1,18 @@ +#ifndef COSMOPOLITAN_LIBC_SYSV_CONSTS_WAITID_H_ +#define COSMOPOLITAN_LIBC_SYSV_CONSTS_WAITID_H_ +#include "libc/runtime/symbolic.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +extern const long WEXITED; +extern const long WSTOPPED; +extern const long WNOWAIT; + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ + +#define WEXITED SYMBOLIC(WEXITED) +#define WSTOPPED SYMBOLIC(WSTOPPED) +#define WNOWAIT SYMBOLIC(WNOWAIT) + +#endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_WAITID_H_ */ diff --git a/libc/sysv/syscalls.sh b/libc/sysv/syscalls.sh index 24b420e6d..373de9bdc 100755 --- a/libc/sysv/syscalls.sh +++ b/libc/sysv/syscalls.sh @@ -233,7 +233,7 @@ scall lgetxattr 0x17bffffffffff0c0 globl scall llistxattr 0x17effffffffff0c3 globl scall lremovexattr 0x181ffffffffff0c6 globl scall sys_sched_setaffinity 0xfffffffffffff0cb globl hidden -scall sched_getaffinity 0xfffffffffffff0cc globl +scall sched_getaffinity 0xfffffffffffff0cc globl # returns bytes written on success. we polyfill bad posix designs like nice() returning 0, but we won't polyfill a bad unilateral redesign that's just glibc scall cpuset_getaffinity 0xffffff1e7fffffff globl scall cpuset_setaffinity 0xffffff1e8fffffff globl scall io_setup 0xfffffffffffff0ce globl diff --git a/libc/zipos/close.c b/libc/zipos/close.c index 4edce2397..53a143488 100644 --- a/libc/zipos/close.c +++ b/libc/zipos/close.c @@ -20,6 +20,7 @@ #include "libc/calls/internal.h" #include "libc/mem/mem.h" #include "libc/nt/runtime.h" +#include "libc/zip.h" #include "libc/zipos/zipos.internal.h" /** @@ -30,6 +31,9 @@ int __zipos_close(int fd) { struct ZiposHandle *h; h = (struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle; + ZTRACE("__zipos_close(%`'.*s)", + ZIP_CFILE_NAMESIZE(__zipos_get()->map + h->cfile), + ZIP_CFILE_NAME(__zipos_get()->map + h->cfile)); if (!IsWindows()) { sys_close(fd); } else { diff --git a/libc/zipos/find.c b/libc/zipos/find.c index 9263bbd00..ac0847b14 100644 --- a/libc/zipos/find.c +++ b/libc/zipos/find.c @@ -24,13 +24,17 @@ #include "libc/zipos/zipos.internal.h" ssize_t __zipos_find(struct Zipos *zipos, const struct ZiposUri *name) { - size_t i, n, c; + const char *zname; + size_t i, n, c, znamesize; c = GetZipCdirOffset(zipos->cdir); n = GetZipCdirRecords(zipos->cdir); for (i = 0; i < n; ++i, c += ZIP_CFILE_HDRSIZE(zipos->map + c)) { assert(ZIP_CFILE_MAGIC(zipos->map + c) == kZipCfileHdrMagic); - if (name->len == ZIP_CFILE_NAMESIZE(zipos->map + c) && - memcmp(name->path, ZIP_CFILE_NAME(zipos->map + c), name->len) == 0) { + zname = ZIP_CFILE_NAME(zipos->map + c); + znamesize = ZIP_CFILE_NAMESIZE(zipos->map + c); + if ((name->len == znamesize && !memcmp(name->path, zname, name->len)) || + (name->len + 1 == znamesize && !memcmp(name->path, zname, name->len) && + zname[name->len] == '/')) { return c; } } diff --git a/libc/zipos/fstat.c b/libc/zipos/fstat.c index dac003afe..7ecf479f6 100644 --- a/libc/zipos/fstat.c +++ b/libc/zipos/fstat.c @@ -16,6 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/zip.h" #include "libc/zipos/zipos.internal.h" /** @@ -25,5 +26,8 @@ * @asyncsignalsafe */ int __zipos_fstat(const struct ZiposHandle *h, struct stat *st) { + ZTRACE("__zipos_fstat(%`'.*s)", + ZIP_CFILE_NAMESIZE(__zipos_get()->map + h->cfile), + ZIP_CFILE_NAME(__zipos_get()->map + h->cfile)); return __zipos_stat_impl(__zipos_get(), h->cfile, st); } diff --git a/libc/zipos/lseek.c b/libc/zipos/lseek.c index 8d463a335..bbb2df57d 100644 --- a/libc/zipos/lseek.c +++ b/libc/zipos/lseek.c @@ -18,6 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/sysv/errfuns.h" +#include "libc/zip.h" #include "libc/zipos/zipos.internal.h" /** @@ -47,5 +48,8 @@ int64_t __zipos_lseek(struct ZiposHandle *h, int64_t offset, unsigned whence) { return einval(); } h->pos = i; + ZTRACE("__zipos_lseek(%`'.*s, %ld)", + ZIP_CFILE_NAMESIZE(__zipos_get()->map + h->cfile), + ZIP_CFILE_NAME(__zipos_get()->map + h->cfile), i); return i; } diff --git a/libc/zipos/open.c b/libc/zipos/open.c index dfef788ac..9ad19e2e9 100644 --- a/libc/zipos/open.c +++ b/libc/zipos/open.c @@ -18,6 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "ape/relocations.h" #include "libc/assert.h" +#include "libc/bits/weaken.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/calls/struct/sigset.h" @@ -28,6 +29,7 @@ #include "libc/mem/mem.h" #include "libc/nexgen32e/crc32.h" #include "libc/runtime/runtime.h" +#include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/str/undeflate.h" #include "libc/sysv/consts/map.h" @@ -140,11 +142,14 @@ int __zipos_open(const struct ZiposUri *name, unsigned flags, int mode) { if ((zipos = __zipos_get())) { if ((cf = __zipos_find(zipos, name)) != -1) { fd = __zipos_load(zipos, cf, flags, mode); + ZTRACE("__zipos_open(%`'.*s)", name->len, name->path); } else { + ZTRACE("__zipos_open(%`'.*s) enoent", name->len, name->path); fd = enoent(); } } else { fd = enoexec(); + ZTRACE("__zipos_open(%`'.*s) enoexec", name->len, name->path); } return fd; } diff --git a/libc/zipos/parseuri.c b/libc/zipos/parseuri.c index 81326e62b..55505f72f 100644 --- a/libc/zipos/parseuri.c +++ b/libc/zipos/parseuri.c @@ -26,10 +26,11 @@ const char kZiposSchemePrefix[4] hidden = "zip:"; */ ssize_t __zipos_parseuri(const char *uri, struct ZiposUri *out) { size_t len; - if ((len = strlen(uri)) >= sizeof(kZiposSchemePrefix) && len < PATH_MAX && - memcmp(uri, kZiposSchemePrefix, sizeof(kZiposSchemePrefix)) == 0) { - out->path = uri + sizeof(kZiposSchemePrefix); - return (out->len = len - sizeof(kZiposSchemePrefix)); + if ((uri[0] == 'z' && uri[1] == 'i' && uri[2] == 'p' && + (uri[3] == ':' || uri[3] == '!')) && + (len = strlen(uri)) < PATH_MAX) { + out->path = uri + 4; + return (out->len = len - 4); } else { return -1; } diff --git a/libc/zipos/read.c b/libc/zipos/read.c index 6db49ee92..b4060593e 100644 --- a/libc/zipos/read.c +++ b/libc/zipos/read.c @@ -21,8 +21,15 @@ #include "libc/calls/internal.h" #include "libc/calls/struct/iovec.h" #include "libc/str/str.h" +#include "libc/zip.h" #include "libc/zipos/zipos.internal.h" +static size_t GetIovSize(const struct iovec *iov, size_t iovlen) { + size_t i, r; + for (r = i = 0; i < iovlen; ++i) r += iov[i].iov_len; + return r; +} + /** * Reads data from zip store object. * @@ -39,5 +46,9 @@ ssize_t __zipos_read(struct ZiposHandle *h, const struct iovec *iov, memcpy(iov[i].iov_base, h->mem + y, b); } if (opt_offset == -1) h->pos = y; + ZTRACE("__zipos_read(%`'.*s, cap=%ld, off=%ld) → got=%ld", + ZIP_CFILE_NAMESIZE(__zipos_get()->map + h->cfile), + ZIP_CFILE_NAME(__zipos_get()->map + h->cfile), GetIovSize(iov, iovlen), + x, y - x); return y - x; } diff --git a/libc/zipos/stat-impl.c b/libc/zipos/stat-impl.c index 8bb989b6d..702737c63 100644 --- a/libc/zipos/stat-impl.c +++ b/libc/zipos/stat-impl.c @@ -19,11 +19,74 @@ #include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" +#include "libc/fmt/conv.h" #include "libc/str/str.h" #include "libc/sysv/errfuns.h" #include "libc/zip.h" #include "libc/zipos/zipos.internal.h" +static int popcnt3(int x) { + return !!(x & 1) + !!(x & 2) + !!(x & 4); +} + +static struct timespec WindowsTimeToTime(uint64_t x) { + return (struct timespec){x / HECTONANOSECONDS - MODERNITYSECONDS, + x % HECTONANOSECONDS * 100}; +} + +static void GetZipCfileTimestamps(const uint8_t *zcf, struct stat *st) { + const uint8_t *p, *pe; + for (p = ZIP_CFILE_EXTRA(zcf), pe = p + ZIP_CFILE_EXTRASIZE(zcf); p + 4 <= pe; + p += ZIP_EXTRA_SIZE(p)) { + if (ZIP_EXTRA_HEADERID(p) == kZipExtraNtfs && + ZIP_EXTRA_CONTENTSIZE(p) >= 4 + 4 + 8 && + READ16LE(ZIP_EXTRA_CONTENT(p) + 4) == 1 && + READ16LE(ZIP_EXTRA_CONTENT(p) + 6) >= 8) { + st->st_mtim = WindowsTimeToTime(READ64LE(ZIP_EXTRA_CONTENT(p) + 8)); + if (ZIP_EXTRA_CONTENTSIZE(p) >= 4 + 4 + 8 * 2 && + READ16LE(ZIP_EXTRA_CONTENT(p) + 6) >= 16) { + st->st_atim = WindowsTimeToTime(READ64LE(ZIP_EXTRA_CONTENT(p) + 8 * 2)); + } + if (ZIP_EXTRA_CONTENTSIZE(p) >= 4 + 4 + 8 * 3 && + READ16LE(ZIP_EXTRA_CONTENT(p) + 6) >= 24) { + st->st_ctim = WindowsTimeToTime(READ64LE(ZIP_EXTRA_CONTENT(p) + 8 * 3)); + } + return; + } + } + for (p = ZIP_CFILE_EXTRA(zcf), pe = p + ZIP_CFILE_EXTRASIZE(zcf); p + 4 <= pe; + p += ZIP_EXTRA_SIZE(p)) { + if (ZIP_EXTRA_HEADERID(p) == kZipExtraExtendedTimestamp && + ZIP_EXTRA_CONTENTSIZE(p) > 1 && + ZIP_EXTRA_CONTENTSIZE(p) == + 1 + 4 * popcnt3(*ZIP_EXTRA_CONTENT(p) & 7)) { + if (*ZIP_EXTRA_CONTENT(p) & 1) { + st->st_mtim.tv_sec = READ32LE(ZIP_EXTRA_CONTENT(p) + 1); + } + if (*ZIP_EXTRA_CONTENT(p) & 2) { + st->st_atim.tv_sec = READ32LE(ZIP_EXTRA_CONTENT(p) + 1 + + 4 * (*ZIP_EXTRA_CONTENT(p) & 1)); + } + if (*ZIP_EXTRA_CONTENT(p) & 4) { + st->st_ctim.tv_sec = READ32LE(ZIP_EXTRA_CONTENT(p) + 1 + + 4 * popcnt3(*ZIP_EXTRA_CONTENT(p) & 3)); + } + return; + } + } + for (p = ZIP_CFILE_EXTRA(zcf), pe = p + ZIP_CFILE_EXTRASIZE(zcf); p + 4 <= pe; + p += ZIP_EXTRA_SIZE(p)) { + if (ZIP_EXTRA_HEADERID(p) == kZipExtraUnix && + ZIP_EXTRA_CONTENTSIZE(p) >= 4 + 4) { + st->st_atim.tv_sec = (int32_t)READ32LE(ZIP_EXTRA_CONTENT(p) + 0); + st->st_mtim.tv_sec = (int32_t)READ32LE(ZIP_EXTRA_CONTENT(p) + 4); + return; + } + } + st->st_mtim.tv_sec = DosDateTimeToUnix(ZIP_CFILE_LASTMODIFIEDDATE(zcf), + ZIP_CFILE_LASTMODIFIEDTIME(zcf)); +} + int __zipos_stat_impl(struct Zipos *zipos, size_t cf, struct stat *st) { size_t lf; if (zipos && st) { @@ -37,6 +100,7 @@ int __zipos_stat_impl(struct Zipos *zipos, size_t cf, struct stat *st) { st->st_size = GetZipLfileUncompressedSize(zipos->map + lf); st->st_blocks = roundup(GetZipLfileCompressedSize(zipos->map + lf), 512) / 512; + GetZipCfileTimestamps(zipos->map + cf, st); return 0; } else { return einval(); diff --git a/libc/zipos/stat.c b/libc/zipos/stat.c index 18df8bc49..90d1c0a35 100644 --- a/libc/zipos/stat.c +++ b/libc/zipos/stat.c @@ -16,6 +16,8 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/bits/weaken.h" +#include "libc/stdio/stdio.h" #include "libc/sysv/errfuns.h" #include "libc/zipos/zipos.internal.h" @@ -32,9 +34,11 @@ int __zipos_stat(const struct ZiposUri *name, struct stat *st) { if ((cf = __zipos_find(zipos, name)) != -1) { return __zipos_stat_impl(zipos, cf, st); } else { + ZTRACE("__zipos_stat(%`'.*s) → enoent", name->len, name->path); return enoent(); } } else { + ZTRACE("__zipos_stat(%`'.*s) → enoexec", name->len, name->path); return enoexec(); } } diff --git a/libc/zipos/zipos.internal.h b/libc/zipos/zipos.internal.h index c5960d3ab..30e41a4b6 100644 --- a/libc/zipos/zipos.internal.h +++ b/libc/zipos/zipos.internal.h @@ -1,8 +1,15 @@ #ifndef COSMOPOLITAN_LIBC_ZIPOS_ZIPOS_H_ #define COSMOPOLITAN_LIBC_ZIPOS_ZIPOS_H_ +#include "libc/calls/calls.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ +#if 0 +#define ZTRACE(FMT, ...) (dprintf)(2, FMT "\n", ##__VA_ARGS__) +#else +#define ZTRACE(FMT, ...) (void)0 +#endif + struct stat; struct iovec; @@ -26,10 +33,8 @@ struct ZiposHandle { uint8_t *freeme; }; -extern const char kZiposSchemePrefix[4]; - int __zipos_close(int) hidden; -struct Zipos *__zipos_get(void) hidden; +struct Zipos *__zipos_get(void) pureconst hidden; ssize_t __zipos_parseuri(const char *, struct ZiposUri *) hidden; ssize_t __zipos_find(struct Zipos *, const struct ZiposUri *); int __zipos_open(const struct ZiposUri *, unsigned, int) hidden; diff --git a/test/libc/stdio/dirstream_test.c b/test/libc/stdio/dirstream_test.c index 79637c95f..deae414b9 100644 --- a/test/libc/stdio/dirstream_test.c +++ b/test/libc/stdio/dirstream_test.c @@ -65,3 +65,32 @@ TEST(dirstream, zipTest) { closedir(d); EXPECT_TRUE(foundNewYork); } + +TEST(rewinddir, test) { + DIR *dir; + struct dirent *ent; + char *dpath, *file1, *file2; + dpath = gc(xasprintf("%s%s%lu", kTmpPath, "dirstream", rand64())); + file1 = gc(xasprintf("%s/%s", dpath, "foo")); + file2 = gc(xasprintf("%s/%s", dpath, "bar")); + EXPECT_NE(-1, mkdir(dpath, 0755)); + EXPECT_NE(-1, touch(file1, 0644)); + EXPECT_NE(-1, touch(file2, 0644)); + EXPECT_TRUE(NULL != (dir = opendir(dpath))); + readdir(dir); + readdir(dir); + readdir(dir); + rewinddir(dir); + bool hasfoo = false; + bool hasbar = false; + while ((ent = readdir(dir))) { + if (strcmp(ent->d_name, "foo")) hasfoo = true; + if (strcmp(ent->d_name, "bar")) hasbar = true; + } + EXPECT_TRUE(hasfoo); + EXPECT_TRUE(hasbar); + EXPECT_NE(-1, closedir(dir)); + EXPECT_NE(-1, unlink(file2)); + EXPECT_NE(-1, unlink(file1)); + EXPECT_NE(-1, rmdir(dpath)); +} diff --git a/test/libc/str/bzero_test.c b/test/libc/str/bzero_test.c new file mode 100644 index 000000000..6f0ced315 --- /dev/null +++ b/test/libc/str/bzero_test.c @@ -0,0 +1,96 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/mem/mem.h" +#include "libc/rand/rand.h" +#include "libc/runtime/gc.internal.h" +#include "libc/stdio/stdio.h" +#include "libc/str/str.h" +#include "libc/testlib/ezbench.h" +#include "libc/testlib/testlib.h" + +TEST(bzero, test) { + int n; + char *a, *b; + a = gc(malloc(128)); + b = gc(malloc(128)); + for (n = 0; n < 128; ++n) { + rngset(a, 128, rand64, -1); + memcpy(b, a, 128); + bzero(a, n); + memset(b, 0, n); + ASSERT_EQ(0, memcmp(a, b, 128), "%d", n); + } +} + +void explicit_memset(void *, int, size_t) asm("memset"); + +char doge[129]; + +BENCH(bzero, bench) { + EZBENCH2("bzero 0", donothing, explicit_bzero(doge, 0)); + EZBENCH2("memset 0", donothing, explicit_memset(doge, 0, 0)); + EZBENCH2("bzero 1", donothing, explicit_bzero(doge, 1)); + EZBENCH2("memset 1", donothing, explicit_memset(doge, 0, 1)); + EZBENCH2("bzero 2", donothing, explicit_bzero(doge, 2)); + EZBENCH2("memset 2", donothing, explicit_memset(doge, 0, 2)); + EZBENCH2("bzero 4", donothing, explicit_bzero(doge, 4)); + EZBENCH2("memset 4", donothing, explicit_memset(doge, 0, 4)); + EZBENCH2("bzero 8", donothing, explicit_bzero(doge, 8)); + EZBENCH2("memset 8", donothing, explicit_memset(doge, 0, 8)); + EZBENCH2("bzero 16", donothing, explicit_bzero(doge, 16)); + EZBENCH2("memset 16", donothing, explicit_memset(doge, 0, 16)); + EZBENCH2("bzero 31", donothing, explicit_bzero(doge, 31)); + EZBENCH2("memset 31", donothing, explicit_memset(doge, 0, 31)); + EZBENCH2("bzero 32", donothing, explicit_bzero(doge, 32)); + EZBENCH2("memset 32", donothing, explicit_memset(doge, 0, 32)); + EZBENCH2("bzero 33", donothing, explicit_bzero(doge, 33)); + EZBENCH2("memset 33", donothing, explicit_memset(doge, 0, 33)); + EZBENCH2("bzero 64", donothing, explicit_bzero(doge, 64)); + EZBENCH2("memset 64", donothing, explicit_memset(doge, 0, 64)); + EZBENCH2("bzero 127", donothing, explicit_bzero(doge, 127)); + EZBENCH2("memset 127", donothing, explicit_memset(doge, 0, 127)); + EZBENCH2("bzero 128", donothing, explicit_bzero(doge, 128)); + EZBENCH2("memset 128", donothing, explicit_memset(doge, 0, 128)); + EZBENCH2("bzero 0 [misalign]", donothing, explicit_bzero(doge + 1, 0)); + EZBENCH2("memset 0 [misalign]", donothing, explicit_memset(doge + 1, 0, 0)); + EZBENCH2("bzero 1 [misalign]", donothing, explicit_bzero(doge + 1, 1)); + EZBENCH2("memset 1 [misalign]", donothing, explicit_memset(doge + 1, 0, 1)); + EZBENCH2("bzero 2 [misalign]", donothing, explicit_bzero(doge + 1, 2)); + EZBENCH2("memset 2 [misalign]", donothing, explicit_memset(doge + 1, 0, 2)); + EZBENCH2("bzero 4 [misalign]", donothing, explicit_bzero(doge + 1, 4)); + EZBENCH2("memset 4 [misalign]", donothing, explicit_memset(doge + 1, 0, 4)); + EZBENCH2("bzero 8 [misalign]", donothing, explicit_bzero(doge + 1, 8)); + EZBENCH2("memset 8 [misalign]", donothing, explicit_memset(doge + 1, 0, 8)); + EZBENCH2("bzero 16 [misalign]", donothing, explicit_bzero(doge + 1, 16)); + EZBENCH2("memset 16 [misalign]", donothing, explicit_memset(doge + 1, 0, 16)); + EZBENCH2("bzero 31 [misalign]", donothing, explicit_bzero(doge + 1, 31)); + EZBENCH2("memset 31 [misalign]", donothing, explicit_memset(doge + 1, 0, 31)); + EZBENCH2("bzero 32 [misalign]", donothing, explicit_bzero(doge + 1, 32)); + EZBENCH2("memset 32 [misalign]", donothing, explicit_memset(doge + 1, 0, 32)); + EZBENCH2("bzero 33 [misalign]", donothing, explicit_bzero(doge + 1, 33)); + EZBENCH2("memset 33 [misalign]", donothing, explicit_memset(doge + 1, 0, 33)); + EZBENCH2("bzero 64 [misalign]", donothing, explicit_bzero(doge + 1, 64)); + EZBENCH2("memset 64 [misalign]", donothing, explicit_memset(doge + 1, 0, 64)); + EZBENCH2("bzero 127 [misalign]", donothing, explicit_bzero(doge + 1, 127)); + EZBENCH2("memset 127 [misalign]", donothing, + explicit_memset(doge + 1, 0, 127)); + EZBENCH2("bzero 128 [misalign]", donothing, explicit_bzero(doge + 1, 128)); + EZBENCH2("memset 128 [misalign]", donothing, + explicit_memset(doge + 1, 0, 128)); +} diff --git a/test/tool/build/lib/isnocompressext_test.c b/test/tool/build/lib/isnocompressext_test.c new file mode 100644 index 000000000..7c47741cc --- /dev/null +++ b/test/tool/build/lib/isnocompressext_test.c @@ -0,0 +1,27 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/testlib/testlib.h" +#include "tool/build/lib/isnocompressext.h" + +TEST(IsNoCompressExt, test) { + EXPECT_TRUE(IsNoCompressExt("MP4", -1)); + EXPECT_TRUE(IsNoCompressExt("mp4", -1)); + EXPECT_FALSE(IsNoCompressExt("dog", -1)); + EXPECT_TRUE(IsNoCompressExt("dog.mp4", -1)); +} diff --git a/test/tool/build/lib/stripcomponents_test.c b/test/tool/build/lib/stripcomponents_test.c new file mode 100644 index 000000000..c6fa98502 --- /dev/null +++ b/test/tool/build/lib/stripcomponents_test.c @@ -0,0 +1,34 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/testlib/testlib.h" +#include "tool/build/lib/stripcomponents.h" + +TEST(StripComponents, test) { + EXPECT_STREQ("", StripComponents("", 0)); + EXPECT_STREQ("", StripComponents("", 1)); + EXPECT_STREQ("", StripComponents("", 2)); + EXPECT_STREQ("hello", StripComponents("hello", 0)); + EXPECT_STREQ("hello", StripComponents("hello", 1)); + EXPECT_STREQ("hello", StripComponents("hello", 2)); + EXPECT_STREQ("hello", StripComponents("a/b/hello", 3)); + EXPECT_STREQ("hello", StripComponents("a/b/hello", 2)); + EXPECT_STREQ("b/hello", StripComponents("a/b/hello", 1)); + EXPECT_STREQ("hello", StripComponents("a///b/hello", 2)); + EXPECT_STREQ("b/hello", StripComponents("///a/b/hello", 1)); +} diff --git a/third_party/lz4cli/lz4.c b/third_party/lz4cli/lz4.c index 4114fea2a..7f39742a3 100644 --- a/third_party/lz4cli/lz4.c +++ b/third_party/lz4cli/lz4.c @@ -94,6 +94,7 @@ **************************************/ #define LZ4_STATIC_LINKING_ONLY #define LZ4_DISABLE_DEPRECATE_WARNINGS /* due to LZ4_decompress_safe_withPrefix64k */ +#include "libc/assert.h" #include "third_party/lz4cli/lz4.h" /* see also "memory routines" below */ @@ -306,10 +307,6 @@ static const int LZ4_minLength = (MFLIMIT+1); **************************************/ #if defined(LZ4_DEBUG) && (LZ4_DEBUG>=1) #include "libc/runtime/runtime.h" -#else -# ifndef assert -# define assert(condition) ((void)0) -# endif #endif #define LZ4_STATIC_ASSERT(c) { enum { LZ4_static_assert = 1/(int)(!!(c)) }; } /* use after variable declarations */ diff --git a/third_party/mbedtls/aes.h b/third_party/mbedtls/aes.h index 4c9a00e3c..ee98ac7c6 100644 --- a/third_party/mbedtls/aes.h +++ b/third_party/mbedtls/aes.h @@ -108,7 +108,7 @@ void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx ); * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure. */ int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key, - unsigned int keybits ); + unsigned int keybits ); /** * \brief This function sets the decryption key. @@ -126,7 +126,7 @@ int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key, * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure. */ int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key, - unsigned int keybits ); + unsigned int keybits ); #if defined(MBEDTLS_CIPHER_MODE_XTS) /** @@ -194,9 +194,9 @@ int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx, * \return \c 0 on success. */ int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx, - int mode, - const unsigned char input[16], - unsigned char output[16] ); + int mode, + const unsigned char input[16], + unsigned char output[16] ); #if defined(MBEDTLS_CIPHER_MODE_CBC) /** @@ -241,11 +241,11 @@ int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx, * on failure. */ int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx, - int mode, - size_t length, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output ); + int mode, + size_t length, + unsigned char iv[16], + const unsigned char *input, + unsigned char *output ); #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_CIPHER_MODE_XTS) @@ -333,12 +333,12 @@ int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx, * \return \c 0 on success. */ int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx, - int mode, - size_t length, - size_t *iv_off, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output ); + int mode, + size_t length, + size_t *iv_off, + unsigned char iv[16], + const unsigned char *input, + unsigned char *output ); /** * \brief This function performs an AES-CFB8 encryption or decryption @@ -377,11 +377,11 @@ int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx, * \return \c 0 on success. */ int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx, - int mode, - size_t length, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output ); + int mode, + size_t length, + unsigned char iv[16], + const unsigned char *input, + unsigned char *output ); #endif /*MBEDTLS_CIPHER_MODE_CFB */ #if defined(MBEDTLS_CIPHER_MODE_OFB) @@ -431,11 +431,11 @@ int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx, * \return \c 0 on success. */ int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx, - size_t length, - size_t *iv_off, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output ); + size_t length, + size_t *iv_off, + unsigned char iv[16], + const unsigned char *input, + unsigned char *output ); #endif /* MBEDTLS_CIPHER_MODE_OFB */ @@ -517,12 +517,12 @@ int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx, * \return \c 0 on success. */ int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx, - size_t length, - size_t *nc_off, - unsigned char nonce_counter[16], - unsigned char stream_block[16], - const unsigned char *input, - unsigned char *output ); + size_t length, + size_t *nc_off, + unsigned char nonce_counter[16], + unsigned char stream_block[16], + const unsigned char *input, + unsigned char *output ); #endif /* MBEDTLS_CIPHER_MODE_CTR */ /** diff --git a/third_party/mbedtls/bignum.c b/third_party/mbedtls/bignum.c index 4890f3841..8b2d24545 100644 --- a/third_party/mbedtls/bignum.c +++ b/third_party/mbedtls/bignum.c @@ -36,7 +36,6 @@ #include "third_party/mbedtls/platform.h" #include "third_party/mbedtls/profile.h" #include "third_party/mbedtls/select.h" -#include "third_party/mbedtls/traceme.h" asm(".ident\t\"\\n\\n\ Mbed TLS (Apache 2.0)\\n\ diff --git a/third_party/mbedtls/des.c b/third_party/mbedtls/des.c index ff47f19a6..502f5fb89 100644 --- a/third_party/mbedtls/des.c +++ b/third_party/mbedtls/des.c @@ -569,7 +569,7 @@ static void des3_set3key( uint32_t esk[96], * Triple-DES key schedule (168-bit, encryption) */ int mbedtls_des3_set3key_enc( mbedtls_des3_context *ctx, - const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] ) + const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] ) { uint32_t sk[96]; @@ -583,7 +583,7 @@ int mbedtls_des3_set3key_enc( mbedtls_des3_context *ctx, * Triple-DES key schedule (168-bit, decryption) */ int mbedtls_des3_set3key_dec( mbedtls_des3_context *ctx, - const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] ) + const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] ) { uint32_t sk[96]; @@ -598,8 +598,8 @@ int mbedtls_des3_set3key_dec( mbedtls_des3_context *ctx, */ #if !defined(MBEDTLS_DES_CRYPT_ECB_ALT) int mbedtls_des_crypt_ecb( mbedtls_des_context *ctx, - const unsigned char input[8], - unsigned char output[8] ) + const unsigned char input[8], + unsigned char output[8] ) { int i; uint32_t X, Y, T, *SK; @@ -631,11 +631,11 @@ int mbedtls_des_crypt_ecb( mbedtls_des_context *ctx, * DES-CBC buffer encryption/decryption */ int mbedtls_des_crypt_cbc( mbedtls_des_context *ctx, - int mode, - size_t length, - unsigned char iv[8], - const unsigned char *input, - unsigned char *output ) + int mode, + size_t length, + unsigned char iv[8], + const unsigned char *input, + unsigned char *output ) { int i; unsigned char temp[8]; @@ -685,8 +685,8 @@ int mbedtls_des_crypt_cbc( mbedtls_des_context *ctx, */ #if !defined(MBEDTLS_DES3_CRYPT_ECB_ALT) int mbedtls_des3_crypt_ecb( mbedtls_des3_context *ctx, - const unsigned char input[8], - unsigned char output[8] ) + const unsigned char input[8], + unsigned char output[8] ) { int i; uint32_t X, Y, T, *SK; @@ -730,11 +730,11 @@ int mbedtls_des3_crypt_ecb( mbedtls_des3_context *ctx, * 3DES-CBC buffer encryption/decryption */ int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx, - int mode, - size_t length, - unsigned char iv[8], - const unsigned char *input, - unsigned char *output ) + int mode, + size_t length, + unsigned char iv[8], + const unsigned char *input, + unsigned char *output ) { int i; unsigned char temp[8]; diff --git a/third_party/mbedtls/ecp.c b/third_party/mbedtls/ecp.c index 86ab1a99d..557394433 100644 --- a/third_party/mbedtls/ecp.c +++ b/third_party/mbedtls/ecp.c @@ -29,7 +29,6 @@ #include "third_party/mbedtls/hmac_drbg.h" #include "third_party/mbedtls/platform.h" #include "third_party/mbedtls/profile.h" -#include "third_party/mbedtls/traceme.h" asm(".ident\t\"\\n\\n\ Mbed TLS (Apache 2.0)\\n\ diff --git a/third_party/mbedtls/ecp256.c b/third_party/mbedtls/ecp256.c index b149c4522..ebbe25e17 100644 --- a/third_party/mbedtls/ecp256.c +++ b/third_party/mbedtls/ecp256.c @@ -26,7 +26,6 @@ #include "third_party/mbedtls/error.h" #include "third_party/mbedtls/math.h" #include "third_party/mbedtls/profile.h" -#include "third_party/mbedtls/traceme.h" /* clang-format off */ static bool diff --git a/third_party/mbedtls/ecp384.c b/third_party/mbedtls/ecp384.c index ee5199630..488d663d5 100644 --- a/third_party/mbedtls/ecp384.c +++ b/third_party/mbedtls/ecp384.c @@ -26,7 +26,6 @@ #include "third_party/mbedtls/error.h" #include "third_party/mbedtls/math.h" #include "third_party/mbedtls/profile.h" -#include "third_party/mbedtls/traceme.h" /* clang-format off */ static bool diff --git a/third_party/mbedtls/traceme.h b/third_party/mbedtls/traceme.h deleted file mode 100644 index 7fb91b80a..000000000 --- a/third_party/mbedtls/traceme.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef COSMOPOLITAN_THIRD_PARTY_MBEDTLS_TRACEME_H_ -#define COSMOPOLITAN_THIRD_PARTY_MBEDTLS_TRACEME_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -extern int traceme; - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_THIRD_PARTY_MBEDTLS_TRACEME_H_ */ diff --git a/third_party/python/Include/Python-ast.h b/third_party/python/Include/Python-ast.h index 70494b70f..2f54dbba9 100644 --- a/third_party/python/Include/Python-ast.h +++ b/third_party/python/Include/Python-ast.h @@ -1,7 +1,12 @@ +#ifndef COSMOPOLITAN_THIRD_PARTY_PYTHON_INCLUDE_PYTHON_AST_H_ +#define COSMOPOLITAN_THIRD_PARTY_PYTHON_INCLUDE_PYTHON_AST_H_ +#include "third_party/python/Include/asdl.h" +#include "third_party/python/Include/object.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ +/* clang-format off */ /* File automatically generated by Parser/asdl_c.py. */ -#include "asdl.h" - typedef struct _mod *mod_ty; typedef struct _stmt *stmt_ty; @@ -635,3 +640,7 @@ withitem_ty _Py_withitem(expr_ty context_expr, expr_ty optional_vars, PyArena PyObject* PyAST_mod2obj(mod_ty t); mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode); int PyAST_Check(PyObject* obj); + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_THIRD_PARTY_PYTHON_INCLUDE_PYTHON_AST_H_ */ diff --git a/third_party/python/Include/Python.h b/third_party/python/Include/Python.h index 55c75d24e..d1a7c6fb9 100644 --- a/third_party/python/Include/Python.h +++ b/third_party/python/Include/Python.h @@ -1,62 +1,36 @@ #ifndef Py_PYTHON_H #define Py_PYTHON_H -#include "libc/assert.h" -#include "libc/calls/calls.h" -#include "libc/calls/weirdtypes.h" -#include "libc/errno.h" -#include "libc/fmt/conv.h" -#include "libc/fmt/fmt.h" -#include "libc/limits.h" -#include "libc/log/log.h" -#include "libc/mem/mem.h" -#include "libc/rand/rand.h" -#include "libc/runtime/runtime.h" -#include "libc/stdio/stdio.h" -#include "libc/stdio/temp.h" -#include "libc/str/str.h" -#include "libc/sysv/consts/exit.h" -#include "libc/sysv/consts/fileno.h" -#include "libc/sysv/consts/o.h" -#include "third_party/python/Include/patchlevel.h" -#include "third_party/python/Include/pymacconfig.h" -#include "third_party/python/pyconfig.h" /* clang-format off */ +/* + * PYTHON DIAMOND DEPENDENCY HEADER + * + * If your editor isn't able to automatically insert #include lines, + * then this header can make development easier. It's also great for + * making beginner's tutorials simpler and more attractive. + * + * However it's sloppy to use something like this in the long term since + * it's not a scalable dependency model. It makes builds slower, because + * changing any single header will invalidate all the build artifacts. + * + * So please consider doing the conscientious thing and avoid using it! + */ + +#include "libc/errno.h" +#include "third_party/python/pyconfig.h" +#include "third_party/python/Include/patchlevel.h" +#include "third_party/python/pyconfig.h" #include "third_party/python/Include/pyport.h" #include "third_party/python/Include/pymacro.h" - -/* A convenient way for code to know if clang's memory sanitizer is enabled. */ -#if defined(__has_feature) -# if __has_feature(memory_sanitizer) -# if !defined(_Py_MEMORY_SANITIZER) -# define _Py_MEMORY_SANITIZER -# endif -# endif -#endif - #include "third_party/python/Include/pyatomic.h" - -/* Debug-mode build with pymalloc implies PYMALLOC_DEBUG. - * PYMALLOC_DEBUG is in error if pymalloc is not in use. - */ -#if defined(Py_DEBUG) && defined(WITH_PYMALLOC) && !defined(PYMALLOC_DEBUG) -#define PYMALLOC_DEBUG -#endif -#if defined(PYMALLOC_DEBUG) && !defined(WITH_PYMALLOC) -#error "PYMALLOC_DEBUG requires WITH_PYMALLOC" -#endif - #include "third_party/python/Include/pymath.h" #include "third_party/python/Include/pytime.h" #include "third_party/python/Include/pymem.h" - #include "third_party/python/Include/object.h" #include "third_party/python/Include/objimpl.h" #include "third_party/python/Include/typeslots.h" #include "third_party/python/Include/pyhash.h" - #include "third_party/python/Include/pydebug.h" - #include "third_party/python/Include/bytearrayobject.h" #include "third_party/python/Include/bytesobject.h" #include "third_party/python/Include/unicodeobject.h" @@ -89,12 +63,9 @@ #include "third_party/python/Include/weakrefobject.h" #include "third_party/python/Include/structseq.h" #include "third_party/python/Include/namespaceobject.h" - #include "third_party/python/Include/codecs.h" #include "third_party/python/Include/pyerrors.h" - #include "third_party/python/Include/pystate.h" - #include "third_party/python/Include/pyarena.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/pythonrun.h" @@ -104,13 +75,10 @@ #include "third_party/python/Include/osmodule.h" #include "third_party/python/Include/intrcheck.h" #include "third_party/python/Include/import.h" - #include "third_party/python/Include/abstract.h" #include "third_party/python/Include/bltinmodule.h" - #include "third_party/python/Include/compile.h" #include "third_party/python/Include/eval.h" - #include "third_party/python/Include/pyctype.h" #include "third_party/python/Include/pystrtod.h" #include "third_party/python/Include/pystrcmp.h" diff --git a/third_party/python/Include/abstract.h b/third_party/python/Include/abstract.h index 1ccad73fb..0655e9cb9 100644 --- a/third_party/python/Include/abstract.h +++ b/third_party/python/Include/abstract.h @@ -1,1372 +1,1015 @@ #ifndef Py_ABSTRACTOBJECT_H #define Py_ABSTRACTOBJECT_H +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/tupleobject.h" COSMOPOLITAN_C_START_ -/* clang-format off */ + +/* Abstract Object Interface (many thanks to Jim Fulton) */ + +#define PyObject_DelAttrString(O, A) PyObject_SetAttrString((O), (A), NULL) +#define PyObject_DelAttr(O, A) PyObject_SetAttr((O), (A), NULL) +PyObject *PyObject_Call(PyObject *callable_object, PyObject *args, + PyObject *kwargs); + +#ifndef Py_LIMITED_API +PyObject *_PyStack_AsTuple(PyObject **stack, Py_ssize_t nargs); + +PyObject *_PyStack_AsDict(PyObject **values, PyObject *kwnames); + +int _PyStack_UnpackDict(PyObject **args, Py_ssize_t nargs, PyObject *kwargs, + PyObject ***p_stack, PyObject **p_kwnames); + +PyObject *_PyObject_FastCallDict(PyObject *func, PyObject **args, + Py_ssize_t nargs, PyObject *kwargs); + +PyObject *_PyObject_FastCallKeywords(PyObject *func, PyObject **args, + Py_ssize_t nargs, PyObject *kwnames); + +#define _PyObject_FastCall(func, args, nargs) \ + _PyObject_FastCallDict((func), (args), (nargs), NULL) + +#define _PyObject_CallNoArg(func) _PyObject_FastCall((func), NULL, 0) + +#define _PyObject_CallArg1(func, arg) _PyObject_FastCall((func), &(arg), 1) + +PyObject *_PyObject_Call_Prepend(PyObject *func, PyObject *obj, PyObject *args, + PyObject *kwargs); + +PyObject *_Py_CheckFunctionResult(PyObject *func, PyObject *result, + const char *where); +#endif /* Py_LIMITED_API */ + +PyObject *PyObject_CallObject(PyObject *callable_object, PyObject *args); + +/* +Call a callable Python object, callable_object, with +arguments given by the tuple, args. If no arguments are +needed, then args may be NULL. Returns the result of the +call on success, or NULL on failure. This is the equivalent +of the Python expression: o(*args). +*/ + +PyObject *PyObject_CallFunction(PyObject *callable_object, const char *format, + ...); + +/* +Call a callable Python object, callable_object, with a +variable number of C arguments. The C arguments are described +using a mkvalue-style format string. The format may be NULL, +indicating that no arguments are provided. Returns the +result of the call on success, or NULL on failure. This is +the equivalent of the Python expression: o(*args). +*/ + +PyObject *PyObject_CallMethod(PyObject *o, const char *method, + const char *format, ...); + +/* +Call the method named m of object o with a variable number of +C arguments. The C arguments are described by a mkvalue +format string. The format may be NULL, indicating that no +arguments are provided. Returns the result of the call on +success, or NULL on failure. This is the equivalent of the +Python expression: o.method(args). +*/ + +#ifndef Py_LIMITED_API +PyObject *_PyObject_CallMethodId(PyObject *o, _Py_Identifier *method, + const char *format, ...); +/* + Like PyObject_CallMethod, but expect a _Py_Identifier* as the + method name. +*/ +#endif /* !Py_LIMITED_API */ #ifdef PY_SSIZE_T_CLEAN #define PyObject_CallFunction _PyObject_CallFunction_SizeT -#define PyObject_CallMethod _PyObject_CallMethod_SizeT +#define PyObject_CallMethod _PyObject_CallMethod_SizeT #ifndef Py_LIMITED_API #define _PyObject_CallMethodId _PyObject_CallMethodId_SizeT #endif /* !Py_LIMITED_API */ #endif -/* Abstract Object Interface (many thanks to Jim Fulton) */ +PyObject *_PyObject_CallFunction_SizeT(PyObject *callable, const char *format, + ...); +PyObject *_PyObject_CallMethod_SizeT(PyObject *o, const char *name, + const char *format, ...); +#ifndef Py_LIMITED_API +PyObject *_PyObject_CallMethodId_SizeT(PyObject *o, _Py_Identifier *name, + const char *format, ...); +#endif /* !Py_LIMITED_API */ + +PyObject *PyObject_CallFunctionObjArgs(PyObject *callable, ...); /* - PROPOSAL: A Generic Python Object Interface for Python C Modules - -Problem - - Python modules written in C that must access Python objects must do - so through routines whose interfaces are described by a set of - include files. Unfortunately, these routines vary according to the - object accessed. To use these routines, the C programmer must check - the type of the object being used and must call a routine based on - the object type. For example, to access an element of a sequence, - the programmer must determine whether the sequence is a list or a - tuple: - - if(is_tupleobject(o)) - e=gettupleitem(o,i) - else if(is_listitem(o)) - e=getlistitem(o,i) - - If the programmer wants to get an item from another type of object - that provides sequence behavior, there is no clear way to do it - correctly. - - The persistent programmer may peruse object.h and find that the - _typeobject structure provides a means of invoking up to (currently - about) 41 special operators. So, for example, a routine can get an - item from any object that provides sequence behavior. However, to - use this mechanism, the programmer must make their code dependent on - the current Python implementation. - - Also, certain semantics, especially memory management semantics, may - differ by the type of object being used. Unfortunately, these - semantics are not clearly described in the current include files. - An abstract interface providing more consistent semantics is needed. - -Proposal - - I propose the creation of a standard interface (with an associated - library of routines and/or macros) for generically obtaining the - services of Python objects. This proposal can be viewed as one - components of a Python C interface consisting of several components. - - From the viewpoint of C access to Python services, we have (as - suggested by Guido in off-line discussions): - - - "Very high level layer": two or three functions that let you exec or - eval arbitrary Python code given as a string in a module whose name is - given, passing C values in and getting C values out using - mkvalue/getargs style format strings. This does not require the user - to declare any variables of type "PyObject *". This should be enough - to write a simple application that gets Python code from the user, - execs it, and returns the output or errors. (Error handling must also - be part of this API.) - - - "Abstract objects layer": which is the subject of this proposal. - It has many functions operating on objects, and lest you do many - things from C that you can also write in Python, without going - through the Python parser. - - - "Concrete objects layer": This is the public type-dependent - interface provided by the standard built-in types, such as floats, - strings, and lists. This interface exists and is currently - documented by the collection of include files provided with the - Python distributions. - - From the point of view of Python accessing services provided by C - modules: - - - "Python module interface": this interface consist of the basic - routines used to define modules and their members. Most of the - current extensions-writing guide deals with this interface. - - - "Built-in object interface": this is the interface that a new - built-in type must provide and the mechanisms and rules that a - developer of a new built-in type must use and follow. - - This proposal is a "first-cut" that is intended to spur - discussion. See especially the lists of notes. - - The Python C object interface will provide four protocols: object, - numeric, sequence, and mapping. Each protocol consists of a - collection of related operations. If an operation that is not - provided by a particular type is invoked, then a standard exception, - NotImplementedError is raised with an operation name as an argument. - In addition, for convenience this interface defines a set of - constructors for building objects of built-in types. This is needed - so new objects can be returned from C functions that otherwise treat - objects generically. - -Memory Management - - For all of the functions described in this proposal, if a function - retains a reference to a Python object passed as an argument, then the - function will increase the reference count of the object. It is - unnecessary for the caller to increase the reference count of an - argument in anticipation of the object's retention. - - All Python objects returned from functions should be treated as new - objects. Functions that return objects assume that the caller will - retain a reference and the reference count of the object has already - been incremented to account for this fact. A caller that does not - retain a reference to an object that is returned from a function - must decrement the reference count of the object (using - DECREF(object)) to prevent memory leaks. - - Note that the behavior mentioned here is different from the current - behavior for some objects (e.g. lists and tuples) when certain - type-specific routines are called directly (e.g. setlistitem). The - proposed abstraction layer will provide a consistent memory - management interface, correcting for inconsistent behavior for some - built-in types. - -Protocols - -xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ - -/* Object Protocol: */ - - /* Implemented elsewhere: - - int PyObject_Print(PyObject *o, FILE *fp, int flags); - - Print an object, o, on file, fp. Returns -1 on - error. The flags argument is used to enable certain printing - options. The only option currently supported is Py_Print_RAW. - - (What should be said about Py_Print_RAW?) - - */ - - /* Implemented elsewhere: - - int PyObject_HasAttrString(PyObject *o, const char *attr_name); - - Returns 1 if o has the attribute attr_name, and 0 otherwise. - This is equivalent to the Python expression: - hasattr(o,attr_name). - - This function always succeeds. - - */ - - /* Implemented elsewhere: - - PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name); - - Retrieve an attributed named attr_name form object o. - Returns the attribute value on success, or NULL on failure. - This is the equivalent of the Python expression: o.attr_name. - - */ - - /* Implemented elsewhere: - - int PyObject_HasAttr(PyObject *o, PyObject *attr_name); - - Returns 1 if o has the attribute attr_name, and 0 otherwise. - This is equivalent to the Python expression: - hasattr(o,attr_name). - - This function always succeeds. - - */ - - /* Implemented elsewhere: - - PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name); - - Retrieve an attributed named attr_name form object o. - Returns the attribute value on success, or NULL on failure. - This is the equivalent of the Python expression: o.attr_name. - - */ - - - /* Implemented elsewhere: - - int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v); - - Set the value of the attribute named attr_name, for object o, - to the value v. Raise an exception and return -1 on failure; return 0 on - success. This is the equivalent of the Python statement o.attr_name=v. - - */ - - /* Implemented elsewhere: - - int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v); - - Set the value of the attribute named attr_name, for object o, - to the value v. Raise an exception and return -1 on failure; return 0 on - success. This is the equivalent of the Python statement o.attr_name=v. - - */ - - /* implemented as a macro: - - int PyObject_DelAttrString(PyObject *o, const char *attr_name); - - Delete attribute named attr_name, for object o. Returns - -1 on failure. This is the equivalent of the Python - statement: del o.attr_name. - - */ -#define PyObject_DelAttrString(O,A) PyObject_SetAttrString((O),(A),NULL) - - /* implemented as a macro: - - int PyObject_DelAttr(PyObject *o, PyObject *attr_name); - - Delete attribute named attr_name, for object o. Returns -1 - on failure. This is the equivalent of the Python - statement: del o.attr_name. - - */ -#define PyObject_DelAttr(O,A) PyObject_SetAttr((O),(A),NULL) - - /* Implemented elsewhere: - - PyObject *PyObject_Repr(PyObject *o); - - Compute the string representation of object, o. Returns the - string representation on success, NULL on failure. This is - the equivalent of the Python expression: repr(o). - - Called by the repr() built-in function. - - */ - - /* Implemented elsewhere: - - PyObject *PyObject_Str(PyObject *o); - - Compute the string representation of object, o. Returns the - string representation on success, NULL on failure. This is - the equivalent of the Python expression: str(o).) - - Called by the str() and print() built-in functions. - - */ - - /* Declared elsewhere - - PyAPI_FUNC(int) PyCallable_Check(PyObject *o); - - Determine if the object, o, is callable. Return 1 if the - object is callable and 0 otherwise. - - This function always succeeds. - */ - - PyAPI_FUNC(PyObject *) PyObject_Call(PyObject *callable_object, - PyObject *args, PyObject *kwargs); - - /* - Call a callable Python object, callable_object, with - arguments and keywords arguments. The 'args' argument can not be - NULL. - */ - +Call a callable Python object, callable_object, with a +variable number of C arguments. The C arguments are provided +as PyObject * values, terminated by a NULL. Returns the +result of the call on success, or NULL on failure. This is +the equivalent of the Python expression: o(*args). +*/ + +PyObject *PyObject_CallMethodObjArgs(PyObject *o, PyObject *method, ...); #ifndef Py_LIMITED_API - PyAPI_FUNC(PyObject*) _PyStack_AsTuple( - PyObject **stack, - Py_ssize_t nargs); - - /* Convert keyword arguments from the (stack, kwnames) format to a Python - dictionary. - - kwnames must only contains str strings, no subclass, and all keys must - be unique. kwnames is not checked, usually these checks are done before or later - calling _PyStack_AsDict(). For example, _PyArg_ParseStack() raises an - error if a key is not a string. */ - PyAPI_FUNC(PyObject *) _PyStack_AsDict( - PyObject **values, - PyObject *kwnames); - - /* Convert (args, nargs, kwargs: dict) into (stack, nargs, kwnames: tuple). - - Return 0 on success, raise an exception and return -1 on error. - - Write the new stack into *p_stack. If *p_stack is differen than args, it - must be released by PyMem_Free(). - - The stack uses borrowed references. - - The type of keyword keys is not checked, these checks should be done - later (ex: _PyArg_ParseStackAndKeywords). */ - PyAPI_FUNC(int) _PyStack_UnpackDict( - PyObject **args, - Py_ssize_t nargs, - PyObject *kwargs, - PyObject ***p_stack, - PyObject **p_kwnames); - - /* Call the callable object func with the "fast call" calling convention: - args is a C array for positional arguments (nargs is the number of - positional arguments), kwargs is a dictionary for keyword arguments. - - If nargs is equal to zero, args can be NULL. kwargs can be NULL. - nargs must be greater or equal to zero. - - Return the result on success. Raise an exception on return NULL on - error. */ - PyAPI_FUNC(PyObject *) _PyObject_FastCallDict(PyObject *func, - PyObject **args, Py_ssize_t nargs, - PyObject *kwargs); - - /* Call the callable object func with the "fast call" calling convention: - args is a C array for positional arguments followed by values of - keyword arguments. Keys of keyword arguments are stored as a tuple - of strings in kwnames. nargs is the number of positional parameters at - the beginning of stack. The size of kwnames gives the number of keyword - values in the stack after positional arguments. - - kwnames must only contains str strings, no subclass, and all keys must - be unique. - - If nargs is equal to zero and there is no keyword argument (kwnames is - NULL or its size is zero), args can be NULL. - - Return the result on success. Raise an exception and return NULL on - error. */ - PyAPI_FUNC(PyObject *) _PyObject_FastCallKeywords - (PyObject *func, - PyObject **args, - Py_ssize_t nargs, - PyObject *kwnames); - -#define _PyObject_FastCall(func, args, nargs) \ - _PyObject_FastCallDict((func), (args), (nargs), NULL) - -#define _PyObject_CallNoArg(func) \ - _PyObject_FastCall((func), NULL, 0) - -#define _PyObject_CallArg1(func, arg) \ - _PyObject_FastCall((func), &(arg), 1) - - PyAPI_FUNC(PyObject *) _PyObject_Call_Prepend(PyObject *func, - PyObject *obj, PyObject *args, - PyObject *kwargs); - - PyAPI_FUNC(PyObject *) _Py_CheckFunctionResult(PyObject *func, - PyObject *result, - const char *where); -#endif /* Py_LIMITED_API */ - - PyAPI_FUNC(PyObject *) PyObject_CallObject(PyObject *callable_object, - PyObject *args); - - /* - Call a callable Python object, callable_object, with - arguments given by the tuple, args. If no arguments are - needed, then args may be NULL. Returns the result of the - call on success, or NULL on failure. This is the equivalent - of the Python expression: o(*args). - */ - - PyAPI_FUNC(PyObject *) PyObject_CallFunction(PyObject *callable_object, - const char *format, ...); - - /* - Call a callable Python object, callable_object, with a - variable number of C arguments. The C arguments are described - using a mkvalue-style format string. The format may be NULL, - indicating that no arguments are provided. Returns the - result of the call on success, or NULL on failure. This is - the equivalent of the Python expression: o(*args). - */ - - - PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *o, - const char *method, - const char *format, ...); - - /* - Call the method named m of object o with a variable number of - C arguments. The C arguments are described by a mkvalue - format string. The format may be NULL, indicating that no - arguments are provided. Returns the result of the call on - success, or NULL on failure. This is the equivalent of the - Python expression: o.method(args). - */ - -#ifndef Py_LIMITED_API - PyAPI_FUNC(PyObject *) _PyObject_CallMethodId(PyObject *o, - _Py_Identifier *method, - const char *format, ...); - - /* - Like PyObject_CallMethod, but expect a _Py_Identifier* as the - method name. - */ +PyObject *_PyObject_CallMethodIdObjArgs(PyObject *o, + struct _Py_Identifier *method, ...); #endif /* !Py_LIMITED_API */ - PyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable, - const char *format, - ...); - PyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *o, - const char *name, - const char *format, - ...); -#ifndef Py_LIMITED_API - PyAPI_FUNC(PyObject *) _PyObject_CallMethodId_SizeT(PyObject *o, - _Py_Identifier *name, - const char *format, - ...); -#endif /* !Py_LIMITED_API */ +/* +Call the method named m of object o with a variable number of +C arguments. The C arguments are provided as PyObject * +values, terminated by NULL. Returns the result of the call +on success, or NULL on failure. This is the equivalent of +the Python expression: o.method(args). +*/ - PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable, - ...); +/* Implemented elsewhere: - /* - Call a callable Python object, callable_object, with a - variable number of C arguments. The C arguments are provided - as PyObject * values, terminated by a NULL. Returns the - result of the call on success, or NULL on failure. This is - the equivalent of the Python expression: o(*args). - */ +long PyObject_Hash(PyObject *o); +Compute and return the hash, hash_value, of an object, o. On +failure, return -1. This is the equivalent of the Python +expression: hash(o). + */ - PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs(PyObject *o, - PyObject *method, ...); -#ifndef Py_LIMITED_API - PyAPI_FUNC(PyObject *) _PyObject_CallMethodIdObjArgs(PyObject *o, - struct _Py_Identifier *method, - ...); -#endif /* !Py_LIMITED_API */ +/* Implemented elsewhere: - /* - Call the method named m of object o with a variable number of - C arguments. The C arguments are provided as PyObject * - values, terminated by NULL. Returns the result of the call - on success, or NULL on failure. This is the equivalent of - the Python expression: o.method(args). - */ +int PyObject_IsTrue(PyObject *o); +Returns 1 if the object, o, is considered to be true, 0 if o is +considered to be false and -1 on failure. This is equivalent to the +Python expression: not not o + */ - /* Implemented elsewhere: +/* Implemented elsewhere: - long PyObject_Hash(PyObject *o); +int PyObject_Not(PyObject *o); - Compute and return the hash, hash_value, of an object, o. On - failure, return -1. This is the equivalent of the Python - expression: hash(o). - */ +Returns 0 if the object, o, is considered to be true, 1 if o is +considered to be false and -1 on failure. This is equivalent to the +Python expression: not o + */ +PyObject *PyObject_Type(PyObject *o); - /* Implemented elsewhere: +/* +On success, returns a type object corresponding to the object +type of object o. On failure, returns NULL. This is +equivalent to the Python expression: type(o). +*/ - int PyObject_IsTrue(PyObject *o); +Py_ssize_t PyObject_Size(PyObject *o); - Returns 1 if the object, o, is considered to be true, 0 if o is - considered to be false and -1 on failure. This is equivalent to the - Python expression: not not o - */ +/* +Return the size of object o. If the object, o, provides +both sequence and mapping protocols, the sequence size is +returned. On error, -1 is returned. This is the equivalent +to the Python expression: len(o). +*/ - /* Implemented elsewhere: - - int PyObject_Not(PyObject *o); - - Returns 0 if the object, o, is considered to be true, 1 if o is - considered to be false and -1 on failure. This is equivalent to the - Python expression: not o - */ - - PyAPI_FUNC(PyObject *) PyObject_Type(PyObject *o); - - /* - On success, returns a type object corresponding to the object - type of object o. On failure, returns NULL. This is - equivalent to the Python expression: type(o). - */ - - PyAPI_FUNC(Py_ssize_t) PyObject_Size(PyObject *o); - - /* - Return the size of object o. If the object, o, provides - both sequence and mapping protocols, the sequence size is - returned. On error, -1 is returned. This is the equivalent - to the Python expression: len(o). - */ - - /* For DLL compatibility */ +/* For DLL compatibility */ #undef PyObject_Length - PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o); +Py_ssize_t PyObject_Length(PyObject *o); #define PyObject_Length PyObject_Size #ifndef Py_LIMITED_API - PyAPI_FUNC(int) _PyObject_HasLen(PyObject *o); - PyAPI_FUNC(Py_ssize_t) PyObject_LengthHint(PyObject *o, Py_ssize_t); +int _PyObject_HasLen(PyObject *o); +Py_ssize_t PyObject_LengthHint(PyObject *o, Py_ssize_t); #endif - /* - Guess the size of object o using len(o) or o.__length_hint__(). - If neither of those return a non-negative value, then return the - default value. If one of the calls fails, this function returns -1. - */ +/* +Guess the size of object o using len(o) or o.__length_hint__(). +If neither of those return a non-negative value, then return the +default value. If one of the calls fails, this function returns -1. +*/ - PyAPI_FUNC(PyObject *) PyObject_GetItem(PyObject *o, PyObject *key); +PyObject *PyObject_GetItem(PyObject *o, PyObject *key); - /* - Return element of o corresponding to the object, key, or NULL - on failure. This is the equivalent of the Python expression: - o[key]. - */ +/* +Return element of o corresponding to the object, key, or NULL +on failure. This is the equivalent of the Python expression: +o[key]. +*/ - PyAPI_FUNC(int) PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v); +int PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v); - /* - Map the object key to the value v. Raise an exception and return -1 - on failure; return 0 on success. This is the equivalent of the Python - statement o[key]=v. - */ +/* +Map the object key to the value v. Raise an exception and return -1 +on failure; return 0 on success. This is the equivalent of the Python +statement o[key]=v. +*/ - PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, const char *key); +int PyObject_DelItemString(PyObject *o, const char *key); - /* - Remove the mapping for object, key, from the object *o. - Returns -1 on failure. This is equivalent to - the Python statement: del o[key]. - */ +/* +Remove the mapping for object, key, from the object *o. +Returns -1 on failure. This is equivalent to +the Python statement: del o[key]. +*/ - PyAPI_FUNC(int) PyObject_DelItem(PyObject *o, PyObject *key); +int PyObject_DelItem(PyObject *o, PyObject *key); - /* - Delete the mapping for key from *o. Returns -1 on failure. - This is the equivalent of the Python statement: del o[key]. - */ +/* +Delete the mapping for key from *o. Returns -1 on failure. +This is the equivalent of the Python statement: del o[key]. +*/ - /* old buffer API - FIXME: usage of these should all be replaced in Python itself - but for backwards compatibility we will implement them. - Their usage without a corresponding "unlock" mechanism - may create issues (but they would already be there). */ +/* old buffer API + FIXME: usage of these should all be replaced in Python itself + but for backwards compatibility we will implement them. + Their usage without a corresponding "unlock" mechanism + may create issues (but they would already be there). */ - PyAPI_FUNC(int) PyObject_AsCharBuffer(PyObject *obj, - const char **buffer, - Py_ssize_t *buffer_len); +int PyObject_AsCharBuffer(PyObject *obj, const char **buffer, + Py_ssize_t *buffer_len); - /* - Takes an arbitrary object which must support the (character, - single segment) buffer interface and returns a pointer to a - read-only memory location useable as character based input - for subsequent processing. +/* +Takes an arbitrary object which must support the (character, +single segment) buffer interface and returns a pointer to a +read-only memory location useable as character based input +for subsequent processing. - 0 is returned on success. buffer and buffer_len are only - set in case no error occurs. Otherwise, -1 is returned and - an exception set. - */ +0 is returned on success. buffer and buffer_len are only +set in case no error occurs. Otherwise, -1 is returned and +an exception set. +*/ - PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj); +int PyObject_CheckReadBuffer(PyObject *obj); - /* - Checks whether an arbitrary object supports the (character, - single segment) buffer interface. Returns 1 on success, 0 - on failure. - */ +/* +Checks whether an arbitrary object supports the (character, +single segment) buffer interface. Returns 1 on success, 0 +on failure. +*/ - PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj, - const void **buffer, - Py_ssize_t *buffer_len); +int PyObject_AsReadBuffer(PyObject *obj, const void **buffer, + Py_ssize_t *buffer_len); - /* - Same as PyObject_AsCharBuffer() except that this API expects - (readable, single segment) buffer interface and returns a - pointer to a read-only memory location which can contain - arbitrary data. +/* +Same as PyObject_AsCharBuffer() except that this API expects +(readable, single segment) buffer interface and returns a +pointer to a read-only memory location which can contain +arbitrary data. - 0 is returned on success. buffer and buffer_len are only - set in case no error occurs. Otherwise, -1 is returned and - an exception set. - */ +0 is returned on success. buffer and buffer_len are only +set in case no error occurs. Otherwise, -1 is returned and +an exception set. +*/ - PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *obj, - void **buffer, - Py_ssize_t *buffer_len); +int PyObject_AsWriteBuffer(PyObject *obj, void **buffer, + Py_ssize_t *buffer_len); - /* - Takes an arbitrary object which must support the (writable, - single segment) buffer interface and returns a pointer to a - writable memory location in buffer of size buffer_len. +/* +Takes an arbitrary object which must support the (writable, +single segment) buffer interface and returns a pointer to a +writable memory location in buffer of size buffer_len. - 0 is returned on success. buffer and buffer_len are only - set in case no error occurs. Otherwise, -1 is returned and - an exception set. - */ +0 is returned on success. buffer and buffer_len are only +set in case no error occurs. Otherwise, -1 is returned and +an exception set. +*/ - /* new buffer API */ +/* new buffer API */ #ifndef Py_LIMITED_API -#define PyObject_CheckBuffer(obj) \ - (((obj)->ob_type->tp_as_buffer != NULL) && \ - ((obj)->ob_type->tp_as_buffer->bf_getbuffer != NULL)) +#define PyObject_CheckBuffer(obj) \ + (((obj)->ob_type->tp_as_buffer != NULL) && \ + ((obj)->ob_type->tp_as_buffer->bf_getbuffer != NULL)) - /* Return 1 if the getbuffer function is available, otherwise - return 0 */ +/* Return 1 if the getbuffer function is available, otherwise + return 0 */ - PyAPI_FUNC(int) PyObject_GetBuffer(PyObject *obj, Py_buffer *view, - int flags); +int PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags); - /* This is a C-API version of the getbuffer function call. It checks - to make sure object has the required function pointer and issues the - call. Returns -1 and raises an error on failure and returns 0 on - success - */ +/* This is a C-API version of the getbuffer function call. It checks + to make sure object has the required function pointer and issues the + call. Returns -1 and raises an error on failure and returns 0 on + success +*/ +void *PyBuffer_GetPointer(Py_buffer *view, Py_ssize_t *indices); - PyAPI_FUNC(void *) PyBuffer_GetPointer(Py_buffer *view, Py_ssize_t *indices); +/* Get the memory area pointed to by the indices for the buffer given. + Note that view->ndim is the assumed size of indices +*/ - /* Get the memory area pointed to by the indices for the buffer given. - Note that view->ndim is the assumed size of indices - */ +int PyBuffer_SizeFromFormat(const char *); - PyAPI_FUNC(int) PyBuffer_SizeFromFormat(const char *); +/* Return the implied itemsize of the data-format area from a + struct-style description */ - /* Return the implied itemsize of the data-format area from a - struct-style description */ +/* Implementation in memoryobject.c */ +int PyBuffer_ToContiguous(void *buf, Py_buffer *view, Py_ssize_t len, + char order); +int PyBuffer_FromContiguous(Py_buffer *view, void *buf, Py_ssize_t len, + char order); +/* Copy len bytes of data from the contiguous chunk of memory + pointed to by buf into the buffer exported by obj. Return + 0 on success and return -1 and raise a PyBuffer_Error on + error (i.e. the object does not have a buffer interface or + it is not working). - /* Implementation in memoryobject.c */ - PyAPI_FUNC(int) PyBuffer_ToContiguous(void *buf, Py_buffer *view, - Py_ssize_t len, char order); + If fort is 'F', then if the object is multi-dimensional, + then the data will be copied into the array in + Fortran-style (first dimension varies the fastest). If + fort is 'C', then the data will be copied into the array + in C-style (last dimension varies the fastest). If fort + is 'A', then it does not matter and the copy will be made + in whatever way is more efficient. - PyAPI_FUNC(int) PyBuffer_FromContiguous(Py_buffer *view, void *buf, - Py_ssize_t len, char order); +*/ +int PyObject_CopyData(PyObject *dest, PyObject *src); - /* Copy len bytes of data from the contiguous chunk of memory - pointed to by buf into the buffer exported by obj. Return - 0 on success and return -1 and raise a PyBuffer_Error on - error (i.e. the object does not have a buffer interface or - it is not working). +/* Copy the data from the src buffer to the buffer of destination + */ - If fort is 'F', then if the object is multi-dimensional, - then the data will be copied into the array in - Fortran-style (first dimension varies the fastest). If - fort is 'C', then the data will be copied into the array - in C-style (last dimension varies the fastest). If fort - is 'A', then it does not matter and the copy will be made - in whatever way is more efficient. +int PyBuffer_IsContiguous(const Py_buffer *view, char fort); - */ +void PyBuffer_FillContiguousStrides(int ndims, Py_ssize_t *shape, + Py_ssize_t *strides, int itemsize, + char fort); - PyAPI_FUNC(int) PyObject_CopyData(PyObject *dest, PyObject *src); +/* Fill the strides array with byte-strides of a contiguous + (Fortran-style if fort is 'F' or C-style otherwise) + array of the given shape with the given number of bytes + per element. +*/ - /* Copy the data from the src buffer to the buffer of destination - */ +int PyBuffer_FillInfo(Py_buffer *view, PyObject *o, void *buf, Py_ssize_t len, + int readonly, int flags); - PyAPI_FUNC(int) PyBuffer_IsContiguous(const Py_buffer *view, char fort); +/* Fills in a buffer-info structure correctly for an exporter + that can only share a contiguous chunk of memory of + "unsigned bytes" of the given length. Returns 0 on success + and -1 (with raising an error) on error. + */ +void PyBuffer_Release(Py_buffer *view); - PyAPI_FUNC(void) PyBuffer_FillContiguousStrides(int ndims, - Py_ssize_t *shape, - Py_ssize_t *strides, - int itemsize, - char fort); - - /* Fill the strides array with byte-strides of a contiguous - (Fortran-style if fort is 'F' or C-style otherwise) - array of the given shape with the given number of bytes - per element. - */ - - PyAPI_FUNC(int) PyBuffer_FillInfo(Py_buffer *view, PyObject *o, void *buf, - Py_ssize_t len, int readonly, - int flags); - - /* Fills in a buffer-info structure correctly for an exporter - that can only share a contiguous chunk of memory of - "unsigned bytes" of the given length. Returns 0 on success - and -1 (with raising an error) on error. - */ - - PyAPI_FUNC(void) PyBuffer_Release(Py_buffer *view); - - /* Releases a Py_buffer obtained from getbuffer ParseTuple's s*. - */ +/* Releases a Py_buffer obtained from getbuffer ParseTuple's s*. + */ #endif /* Py_LIMITED_API */ - PyAPI_FUNC(PyObject *) PyObject_Format(PyObject* obj, - PyObject *format_spec); - /* - Takes an arbitrary object and returns the result of - calling obj.__format__(format_spec). - */ +PyObject *PyObject_Format(PyObject *obj, PyObject *format_spec); +/* +Takes an arbitrary object and returns the result of +calling obj.__format__(format_spec). +*/ /* Iterators */ - PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *); - /* Takes an object and returns an iterator for it. - This is typically a new iterator but if the argument - is an iterator, this returns itself. */ +PyObject *PyObject_GetIter(PyObject *); +/* Takes an object and returns an iterator for it. +This is typically a new iterator but if the argument +is an iterator, this returns itself. */ -#define PyIter_Check(obj) \ - ((obj)->ob_type->tp_iternext != NULL && \ - (obj)->ob_type->tp_iternext != &_PyObject_NextNotImplemented) +#define PyIter_Check(obj) \ + ((obj)->ob_type->tp_iternext != NULL && \ + (obj)->ob_type->tp_iternext != &_PyObject_NextNotImplemented) - PyAPI_FUNC(PyObject *) PyIter_Next(PyObject *); - /* Takes an iterator object and calls its tp_iternext slot, - returning the next value. If the iterator is exhausted, - this returns NULL without setting an exception. - NULL with an exception means an error occurred. */ +PyObject *PyIter_Next(PyObject *); +/* Takes an iterator object and calls its tp_iternext slot, +returning the next value. If the iterator is exhausted, +this returns NULL without setting an exception. +NULL with an exception means an error occurred. */ /* Number Protocol:*/ - PyAPI_FUNC(int) PyNumber_Check(PyObject *o); +int PyNumber_Check(PyObject *o); - /* - Returns 1 if the object, o, provides numeric protocols, and - false otherwise. +/* +Returns 1 if the object, o, provides numeric protocols, and +false otherwise. - This function always succeeds. - */ +This function always succeeds. +*/ - PyAPI_FUNC(PyObject *) PyNumber_Add(PyObject *o1, PyObject *o2); +PyObject *PyNumber_Add(PyObject *o1, PyObject *o2); - /* - Returns the result of adding o1 and o2, or null on failure. - This is the equivalent of the Python expression: o1+o2. - */ +/* +Returns the result of adding o1 and o2, or null on failure. +This is the equivalent of the Python expression: o1+o2. +*/ - PyAPI_FUNC(PyObject *) PyNumber_Subtract(PyObject *o1, PyObject *o2); +PyObject *PyNumber_Subtract(PyObject *o1, PyObject *o2); - /* - Returns the result of subtracting o2 from o1, or null on - failure. This is the equivalent of the Python expression: - o1-o2. - */ +/* +Returns the result of subtracting o2 from o1, or null on +failure. This is the equivalent of the Python expression: +o1-o2. +*/ - PyAPI_FUNC(PyObject *) PyNumber_Multiply(PyObject *o1, PyObject *o2); +PyObject *PyNumber_Multiply(PyObject *o1, PyObject *o2); - /* - Returns the result of multiplying o1 and o2, or null on - failure. This is the equivalent of the Python expression: - o1*o2. - */ +/* +Returns the result of multiplying o1 and o2, or null on +failure. This is the equivalent of the Python expression: +o1*o2. +*/ -#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 - PyAPI_FUNC(PyObject *) PyNumber_MatrixMultiply(PyObject *o1, PyObject *o2); +#if !defined(Py_LIMITED_API) || Py_LIMITED_API + 0 >= 0x03050000 +PyObject *PyNumber_MatrixMultiply(PyObject *o1, PyObject *o2); - /* - This is the equivalent of the Python expression: o1 @ o2. - */ +/* +This is the equivalent of the Python expression: o1 @ o2. +*/ #endif - PyAPI_FUNC(PyObject *) PyNumber_FloorDivide(PyObject *o1, PyObject *o2); +PyObject *PyNumber_FloorDivide(PyObject *o1, PyObject *o2); - /* - Returns the result of dividing o1 by o2 giving an integral result, - or null on failure. - This is the equivalent of the Python expression: o1//o2. - */ +/* +Returns the result of dividing o1 by o2 giving an integral result, +or null on failure. +This is the equivalent of the Python expression: o1//o2. +*/ - PyAPI_FUNC(PyObject *) PyNumber_TrueDivide(PyObject *o1, PyObject *o2); +PyObject *PyNumber_TrueDivide(PyObject *o1, PyObject *o2); - /* - Returns the result of dividing o1 by o2 giving a float result, - or null on failure. - This is the equivalent of the Python expression: o1/o2. - */ +/* +Returns the result of dividing o1 by o2 giving a float result, +or null on failure. +This is the equivalent of the Python expression: o1/o2. +*/ - PyAPI_FUNC(PyObject *) PyNumber_Remainder(PyObject *o1, PyObject *o2); +PyObject *PyNumber_Remainder(PyObject *o1, PyObject *o2); - /* - Returns the remainder of dividing o1 by o2, or null on - failure. This is the equivalent of the Python expression: - o1%o2. - */ +/* +Returns the remainder of dividing o1 by o2, or null on +failure. This is the equivalent of the Python expression: +o1%o2. +*/ - PyAPI_FUNC(PyObject *) PyNumber_Divmod(PyObject *o1, PyObject *o2); +PyObject *PyNumber_Divmod(PyObject *o1, PyObject *o2); - /* - See the built-in function divmod. Returns NULL on failure. - This is the equivalent of the Python expression: - divmod(o1,o2). - */ +/* +See the built-in function divmod. Returns NULL on failure. +This is the equivalent of the Python expression: +divmod(o1,o2). +*/ - PyAPI_FUNC(PyObject *) PyNumber_Power(PyObject *o1, PyObject *o2, - PyObject *o3); +PyObject *PyNumber_Power(PyObject *o1, PyObject *o2, PyObject *o3); - /* - See the built-in function pow. Returns NULL on failure. - This is the equivalent of the Python expression: - pow(o1,o2,o3), where o3 is optional. - */ +/* +See the built-in function pow. Returns NULL on failure. +This is the equivalent of the Python expression: +pow(o1,o2,o3), where o3 is optional. +*/ - PyAPI_FUNC(PyObject *) PyNumber_Negative(PyObject *o); +PyObject *PyNumber_Negative(PyObject *o); - /* - Returns the negation of o on success, or null on failure. - This is the equivalent of the Python expression: -o. - */ +/* +Returns the negation of o on success, or null on failure. +This is the equivalent of the Python expression: -o. +*/ - PyAPI_FUNC(PyObject *) PyNumber_Positive(PyObject *o); +PyObject *PyNumber_Positive(PyObject *o); - /* - Returns the (what?) of o on success, or NULL on failure. - This is the equivalent of the Python expression: +o. - */ +/* +Returns the (what?) of o on success, or NULL on failure. +This is the equivalent of the Python expression: +o. +*/ - PyAPI_FUNC(PyObject *) PyNumber_Absolute(PyObject *o); +PyObject *PyNumber_Absolute(PyObject *o); - /* - Returns the absolute value of o, or null on failure. This is - the equivalent of the Python expression: abs(o). - */ +/* +Returns the absolute value of o, or null on failure. This is +the equivalent of the Python expression: abs(o). +*/ - PyAPI_FUNC(PyObject *) PyNumber_Invert(PyObject *o); +PyObject *PyNumber_Invert(PyObject *o); - /* - Returns the bitwise negation of o on success, or NULL on - failure. This is the equivalent of the Python expression: - ~o. - */ +/* +Returns the bitwise negation of o on success, or NULL on +failure. This is the equivalent of the Python expression: +~o. +*/ - PyAPI_FUNC(PyObject *) PyNumber_Lshift(PyObject *o1, PyObject *o2); +PyObject *PyNumber_Lshift(PyObject *o1, PyObject *o2); - /* - Returns the result of left shifting o1 by o2 on success, or - NULL on failure. This is the equivalent of the Python - expression: o1 << o2. - */ +/* +Returns the result of left shifting o1 by o2 on success, or +NULL on failure. This is the equivalent of the Python +expression: o1 << o2. +*/ - PyAPI_FUNC(PyObject *) PyNumber_Rshift(PyObject *o1, PyObject *o2); +PyObject *PyNumber_Rshift(PyObject *o1, PyObject *o2); - /* - Returns the result of right shifting o1 by o2 on success, or - NULL on failure. This is the equivalent of the Python - expression: o1 >> o2. - */ +/* +Returns the result of right shifting o1 by o2 on success, or +NULL on failure. This is the equivalent of the Python +expression: o1 >> o2. +*/ - PyAPI_FUNC(PyObject *) PyNumber_And(PyObject *o1, PyObject *o2); +PyObject *PyNumber_And(PyObject *o1, PyObject *o2); - /* - Returns the result of bitwise and of o1 and o2 on success, or - NULL on failure. This is the equivalent of the Python - expression: o1&o2. +/* +Returns the result of bitwise and of o1 and o2 on success, or +NULL on failure. This is the equivalent of the Python +expression: o1&o2. - */ +*/ - PyAPI_FUNC(PyObject *) PyNumber_Xor(PyObject *o1, PyObject *o2); +PyObject *PyNumber_Xor(PyObject *o1, PyObject *o2); - /* - Returns the bitwise exclusive or of o1 by o2 on success, or - NULL on failure. This is the equivalent of the Python - expression: o1^o2. - */ +/* +Returns the bitwise exclusive or of o1 by o2 on success, or +NULL on failure. This is the equivalent of the Python +expression: o1^o2. +*/ - PyAPI_FUNC(PyObject *) PyNumber_Or(PyObject *o1, PyObject *o2); +PyObject *PyNumber_Or(PyObject *o1, PyObject *o2); - /* - Returns the result of bitwise or on o1 and o2 on success, or - NULL on failure. This is the equivalent of the Python - expression: o1|o2. - */ +/* +Returns the result of bitwise or on o1 and o2 on success, or +NULL on failure. This is the equivalent of the Python +expression: o1|o2. +*/ -#define PyIndex_Check(obj) \ - ((obj)->ob_type->tp_as_number != NULL && \ - (obj)->ob_type->tp_as_number->nb_index != NULL) +#define PyIndex_Check(obj) \ + ((obj)->ob_type->tp_as_number != NULL && \ + (obj)->ob_type->tp_as_number->nb_index != NULL) - PyAPI_FUNC(PyObject *) PyNumber_Index(PyObject *o); +PyObject *PyNumber_Index(PyObject *o); - /* - Returns the object converted to a Python int - or NULL with an error raised on failure. - */ +/* +Returns the object converted to a Python int +or NULL with an error raised on failure. +*/ - PyAPI_FUNC(Py_ssize_t) PyNumber_AsSsize_t(PyObject *o, PyObject *exc); +Py_ssize_t PyNumber_AsSsize_t(PyObject *o, PyObject *exc); - /* - Returns the object converted to Py_ssize_t by going through - PyNumber_Index first. If an overflow error occurs while - converting the int to Py_ssize_t, then the second argument - is the error-type to return. If it is NULL, then the overflow error - is cleared and the value is clipped. - */ +/* +Returns the object converted to Py_ssize_t by going through +PyNumber_Index first. If an overflow error occurs while +converting the int to Py_ssize_t, then the second argument +is the error-type to return. If it is NULL, then the overflow error +is cleared and the value is clipped. +*/ - PyAPI_FUNC(PyObject *) PyNumber_Long(PyObject *o); +PyObject *PyNumber_Long(PyObject *o); - /* - Returns the o converted to an integer object on success, or - NULL on failure. This is the equivalent of the Python - expression: int(o). - */ +/* +Returns the o converted to an integer object on success, or +NULL on failure. This is the equivalent of the Python +expression: int(o). +*/ - PyAPI_FUNC(PyObject *) PyNumber_Float(PyObject *o); +PyObject *PyNumber_Float(PyObject *o); - /* - Returns the o converted to a float object on success, or NULL - on failure. This is the equivalent of the Python expression: - float(o). - */ +/* +Returns the o converted to a float object on success, or NULL +on failure. This is the equivalent of the Python expression: +float(o). +*/ /* In-place variants of (some of) the above number protocol functions */ - PyAPI_FUNC(PyObject *) PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2); +PyObject *PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2); - /* - Returns the result of adding o2 to o1, possibly in-place, or null - on failure. This is the equivalent of the Python expression: - o1 += o2. - */ +/* +Returns the result of adding o2 to o1, possibly in-place, or null +on failure. This is the equivalent of the Python expression: +o1 += o2. +*/ - PyAPI_FUNC(PyObject *) PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2); +PyObject *PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2); - /* - Returns the result of subtracting o2 from o1, possibly in-place or - null on failure. This is the equivalent of the Python expression: - o1 -= o2. - */ +/* +Returns the result of subtracting o2 from o1, possibly in-place or +null on failure. This is the equivalent of the Python expression: +o1 -= o2. +*/ - PyAPI_FUNC(PyObject *) PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2); +PyObject *PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2); - /* - Returns the result of multiplying o1 by o2, possibly in-place, or - null on failure. This is the equivalent of the Python expression: - o1 *= o2. - */ +/* +Returns the result of multiplying o1 by o2, possibly in-place, or +null on failure. This is the equivalent of the Python expression: +o1 *= o2. +*/ -#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 - PyAPI_FUNC(PyObject *) PyNumber_InPlaceMatrixMultiply(PyObject *o1, PyObject *o2); +#if !defined(Py_LIMITED_API) || Py_LIMITED_API + 0 >= 0x03050000 +PyObject *PyNumber_InPlaceMatrixMultiply(PyObject *o1, PyObject *o2); - /* - This is the equivalent of the Python expression: o1 @= o2. - */ +/* +This is the equivalent of the Python expression: o1 @= o2. +*/ #endif - PyAPI_FUNC(PyObject *) PyNumber_InPlaceFloorDivide(PyObject *o1, - PyObject *o2); +PyObject *PyNumber_InPlaceFloorDivide(PyObject *o1, PyObject *o2); - /* - Returns the result of dividing o1 by o2 giving an integral result, - possibly in-place, or null on failure. - This is the equivalent of the Python expression: - o1 /= o2. - */ +/* +Returns the result of dividing o1 by o2 giving an integral result, +possibly in-place, or null on failure. +This is the equivalent of the Python expression: +o1 /= o2. +*/ - PyAPI_FUNC(PyObject *) PyNumber_InPlaceTrueDivide(PyObject *o1, - PyObject *o2); +PyObject *PyNumber_InPlaceTrueDivide(PyObject *o1, PyObject *o2); - /* - Returns the result of dividing o1 by o2 giving a float result, - possibly in-place, or null on failure. - This is the equivalent of the Python expression: - o1 /= o2. - */ +/* +Returns the result of dividing o1 by o2 giving a float result, +possibly in-place, or null on failure. +This is the equivalent of the Python expression: +o1 /= o2. +*/ - PyAPI_FUNC(PyObject *) PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2); +PyObject *PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2); - /* - Returns the remainder of dividing o1 by o2, possibly in-place, or - null on failure. This is the equivalent of the Python expression: - o1 %= o2. - */ +/* +Returns the remainder of dividing o1 by o2, possibly in-place, or +null on failure. This is the equivalent of the Python expression: +o1 %= o2. +*/ - PyAPI_FUNC(PyObject *) PyNumber_InPlacePower(PyObject *o1, PyObject *o2, - PyObject *o3); +PyObject *PyNumber_InPlacePower(PyObject *o1, PyObject *o2, PyObject *o3); - /* - Returns the result of raising o1 to the power of o2, possibly - in-place, or null on failure. This is the equivalent of the Python - expression: o1 **= o2, or pow(o1, o2, o3) if o3 is present. - */ +/* +Returns the result of raising o1 to the power of o2, possibly +in-place, or null on failure. This is the equivalent of the Python +expression: o1 **= o2, or pow(o1, o2, o3) if o3 is present. +*/ - PyAPI_FUNC(PyObject *) PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2); +PyObject *PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2); - /* - Returns the result of left shifting o1 by o2, possibly in-place, or - null on failure. This is the equivalent of the Python expression: - o1 <<= o2. - */ +/* +Returns the result of left shifting o1 by o2, possibly in-place, or +null on failure. This is the equivalent of the Python expression: +o1 <<= o2. +*/ - PyAPI_FUNC(PyObject *) PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2); +PyObject *PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2); - /* - Returns the result of right shifting o1 by o2, possibly in-place or - null on failure. This is the equivalent of the Python expression: - o1 >>= o2. - */ +/* +Returns the result of right shifting o1 by o2, possibly in-place or +null on failure. This is the equivalent of the Python expression: +o1 >>= o2. +*/ - PyAPI_FUNC(PyObject *) PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2); +PyObject *PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2); - /* - Returns the result of bitwise and of o1 and o2, possibly in-place, - or null on failure. This is the equivalent of the Python - expression: o1 &= o2. - */ +/* +Returns the result of bitwise and of o1 and o2, possibly in-place, +or null on failure. This is the equivalent of the Python +expression: o1 &= o2. +*/ - PyAPI_FUNC(PyObject *) PyNumber_InPlaceXor(PyObject *o1, PyObject *o2); +PyObject *PyNumber_InPlaceXor(PyObject *o1, PyObject *o2); - /* - Returns the bitwise exclusive or of o1 by o2, possibly in-place, or - null on failure. This is the equivalent of the Python expression: - o1 ^= o2. - */ +/* +Returns the bitwise exclusive or of o1 by o2, possibly in-place, or +null on failure. This is the equivalent of the Python expression: +o1 ^= o2. +*/ - PyAPI_FUNC(PyObject *) PyNumber_InPlaceOr(PyObject *o1, PyObject *o2); +PyObject *PyNumber_InPlaceOr(PyObject *o1, PyObject *o2); - /* - Returns the result of bitwise or of o1 and o2, possibly in-place, - or null on failure. This is the equivalent of the Python - expression: o1 |= o2. - */ +/* +Returns the result of bitwise or of o1 and o2, possibly in-place, +or null on failure. This is the equivalent of the Python +expression: o1 |= o2. +*/ - PyAPI_FUNC(PyObject *) PyNumber_ToBase(PyObject *n, int base); - - /* - Returns the integer n converted to a string with a base, with a base - marker of 0b, 0o or 0x prefixed if applicable. - If n is not an int object, it is converted with PyNumber_Index first. - */ +PyObject *PyNumber_ToBase(PyObject *n, int base); +/* +Returns the integer n converted to a string with a base, with a base +marker of 0b, 0o or 0x prefixed if applicable. +If n is not an int object, it is converted with PyNumber_Index first. +*/ /* Sequence protocol:*/ - PyAPI_FUNC(int) PySequence_Check(PyObject *o); +int PySequence_Check(PyObject *o); - /* - Return 1 if the object provides sequence protocol, and zero - otherwise. +/* +Return 1 if the object provides sequence protocol, and zero +otherwise. - This function always succeeds. - */ +This function always succeeds. +*/ - PyAPI_FUNC(Py_ssize_t) PySequence_Size(PyObject *o); +Py_ssize_t PySequence_Size(PyObject *o); - /* - Return the size of sequence object o, or -1 on failure. - */ +/* +Return the size of sequence object o, or -1 on failure. +*/ - /* For DLL compatibility */ +/* For DLL compatibility */ #undef PySequence_Length - PyAPI_FUNC(Py_ssize_t) PySequence_Length(PyObject *o); +Py_ssize_t PySequence_Length(PyObject *o); #define PySequence_Length PySequence_Size +PyObject *PySequence_Concat(PyObject *o1, PyObject *o2); - PyAPI_FUNC(PyObject *) PySequence_Concat(PyObject *o1, PyObject *o2); +/* +Return the concatenation of o1 and o2 on success, and NULL on +failure. This is the equivalent of the Python +expression: o1+o2. +*/ - /* - Return the concatenation of o1 and o2 on success, and NULL on - failure. This is the equivalent of the Python - expression: o1+o2. - */ +PyObject *PySequence_Repeat(PyObject *o, Py_ssize_t count); - PyAPI_FUNC(PyObject *) PySequence_Repeat(PyObject *o, Py_ssize_t count); +/* +Return the result of repeating sequence object o count times, +or NULL on failure. This is the equivalent of the Python +expression: o1*count. +*/ - /* - Return the result of repeating sequence object o count times, - or NULL on failure. This is the equivalent of the Python - expression: o1*count. - */ +PyObject *PySequence_GetItem(PyObject *o, Py_ssize_t i); - PyAPI_FUNC(PyObject *) PySequence_GetItem(PyObject *o, Py_ssize_t i); +/* +Return the ith element of o, or NULL on failure. This is the +equivalent of the Python expression: o[i]. +*/ - /* - Return the ith element of o, or NULL on failure. This is the - equivalent of the Python expression: o[i]. - */ +PyObject *PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2); - PyAPI_FUNC(PyObject *) PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2); +/* +Return the slice of sequence object o between i1 and i2, or +NULL on failure. This is the equivalent of the Python +expression: o[i1:i2]. +*/ - /* - Return the slice of sequence object o between i1 and i2, or - NULL on failure. This is the equivalent of the Python - expression: o[i1:i2]. - */ +int PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v); - PyAPI_FUNC(int) PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v); +/* +Assign object v to the ith element of o. Raise an exception and return +-1 on failure; return 0 on success. This is the equivalent of the +Python statement o[i]=v. +*/ - /* - Assign object v to the ith element of o. Raise an exception and return - -1 on failure; return 0 on success. This is the equivalent of the - Python statement o[i]=v. - */ +int PySequence_DelItem(PyObject *o, Py_ssize_t i); - PyAPI_FUNC(int) PySequence_DelItem(PyObject *o, Py_ssize_t i); +/* +Delete the ith element of object v. Returns +-1 on failure. This is the equivalent of the Python +statement: del o[i]. +*/ - /* - Delete the ith element of object v. Returns - -1 on failure. This is the equivalent of the Python - statement: del o[i]. - */ +int PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2, PyObject *v); - PyAPI_FUNC(int) PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2, - PyObject *v); +/* +Assign the sequence object, v, to the slice in sequence +object, o, from i1 to i2. Returns -1 on failure. This is the +equivalent of the Python statement: o[i1:i2]=v. +*/ - /* - Assign the sequence object, v, to the slice in sequence - object, o, from i1 to i2. Returns -1 on failure. This is the - equivalent of the Python statement: o[i1:i2]=v. - */ +int PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2); - PyAPI_FUNC(int) PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2); +/* +Delete the slice in sequence object, o, from i1 to i2. +Returns -1 on failure. This is the equivalent of the Python +statement: del o[i1:i2]. +*/ - /* - Delete the slice in sequence object, o, from i1 to i2. - Returns -1 on failure. This is the equivalent of the Python - statement: del o[i1:i2]. - */ +PyObject *PySequence_Tuple(PyObject *o); - PyAPI_FUNC(PyObject *) PySequence_Tuple(PyObject *o); +/* +Returns the sequence, o, as a tuple on success, and NULL on failure. +This is equivalent to the Python expression: tuple(o) +*/ - /* - Returns the sequence, o, as a tuple on success, and NULL on failure. - This is equivalent to the Python expression: tuple(o) - */ +PyObject *PySequence_List(PyObject *o); +/* +Returns the sequence, o, as a list on success, and NULL on failure. +This is equivalent to the Python expression: list(o) +*/ +PyObject *PySequence_Fast(PyObject *o, const char *m); +/* +Return the sequence, o, as a list, unless it's already a +tuple or list. Use PySequence_Fast_GET_ITEM to access the +members of this list, and PySequence_Fast_GET_SIZE to get its length. - PyAPI_FUNC(PyObject *) PySequence_List(PyObject *o); - /* - Returns the sequence, o, as a list on success, and NULL on failure. - This is equivalent to the Python expression: list(o) - */ - - PyAPI_FUNC(PyObject *) PySequence_Fast(PyObject *o, const char* m); - /* - Return the sequence, o, as a list, unless it's already a - tuple or list. Use PySequence_Fast_GET_ITEM to access the - members of this list, and PySequence_Fast_GET_SIZE to get its length. - - Returns NULL on failure. If the object does not support iteration, - raises a TypeError exception with m as the message text. - */ +Returns NULL on failure. If the object does not support iteration, +raises a TypeError exception with m as the message text. +*/ #define PySequence_Fast_GET_SIZE(o) \ - (PyList_Check(o) ? PyList_GET_SIZE(o) : PyTuple_GET_SIZE(o)) - /* - Return the size of o, assuming that o was returned by - PySequence_Fast and is not NULL. - */ + (PyList_Check(o) ? PyList_GET_SIZE(o) : PyTuple_GET_SIZE(o)) +/* +Return the size of o, assuming that o was returned by +PySequence_Fast and is not NULL. +*/ -#define PySequence_Fast_GET_ITEM(o, i)\ - (PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i)) - /* - Return the ith element of o, assuming that o was returned by - PySequence_Fast, and that i is within bounds. - */ +#define PySequence_Fast_GET_ITEM(o, i) \ + (PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i)) +/* +Return the ith element of o, assuming that o was returned by +PySequence_Fast, and that i is within bounds. +*/ -#define PySequence_ITEM(o, i)\ - ( Py_TYPE(o)->tp_as_sequence->sq_item(o, i) ) - /* Assume tp_as_sequence and sq_item exist and that i does not - need to be corrected for a negative index - */ +#define PySequence_ITEM(o, i) (Py_TYPE(o)->tp_as_sequence->sq_item(o, i)) +/* Assume tp_as_sequence and sq_item exist and that i does not +need to be corrected for a negative index +*/ -#define PySequence_Fast_ITEMS(sf) \ - (PyList_Check(sf) ? ((PyListObject *)(sf))->ob_item \ - : ((PyTupleObject *)(sf))->ob_item) - /* Return a pointer to the underlying item array for - an object retured by PySequence_Fast */ +#define PySequence_Fast_ITEMS(sf) \ + (PyList_Check(sf) ? ((PyListObject *)(sf))->ob_item \ + : ((PyTupleObject *)(sf))->ob_item) +/* Return a pointer to the underlying item array for + an object retured by PySequence_Fast */ - PyAPI_FUNC(Py_ssize_t) PySequence_Count(PyObject *o, PyObject *value); +Py_ssize_t PySequence_Count(PyObject *o, PyObject *value); - /* - Return the number of occurrences on value on o, that is, - return the number of keys for which o[key]==value. On - failure, return -1. This is equivalent to the Python - expression: o.count(value). - */ +/* +Return the number of occurrences on value on o, that is, +return the number of keys for which o[key]==value. On +failure, return -1. This is equivalent to the Python +expression: o.count(value). +*/ - PyAPI_FUNC(int) PySequence_Contains(PyObject *seq, PyObject *ob); - /* - Return -1 if error; 1 if ob in seq; 0 if ob not in seq. - Use __contains__ if possible, else _PySequence_IterSearch(). - */ +int PySequence_Contains(PyObject *seq, PyObject *ob); +/* +Return -1 if error; 1 if ob in seq; 0 if ob not in seq. +Use __contains__ if possible, else _PySequence_IterSearch(). +*/ #ifndef Py_LIMITED_API #define PY_ITERSEARCH_COUNT 1 #define PY_ITERSEARCH_INDEX 2 #define PY_ITERSEARCH_CONTAINS 3 - PyAPI_FUNC(Py_ssize_t) _PySequence_IterSearch(PyObject *seq, - PyObject *obj, int operation); +Py_ssize_t _PySequence_IterSearch(PyObject *seq, PyObject *obj, int operation); #endif - /* - Iterate over seq. Result depends on the operation: - PY_ITERSEARCH_COUNT: return # of times obj appears in seq; -1 if - error. - PY_ITERSEARCH_INDEX: return 0-based index of first occurrence of - obj in seq; set ValueError and return -1 if none found; - also return -1 on error. - PY_ITERSEARCH_CONTAINS: return 1 if obj in seq, else 0; -1 on - error. - */ +/* + Iterate over seq. Result depends on the operation: + PY_ITERSEARCH_COUNT: return # of times obj appears in seq; -1 if + error. + PY_ITERSEARCH_INDEX: return 0-based index of first occurrence of + obj in seq; set ValueError and return -1 if none found; + also return -1 on error. + PY_ITERSEARCH_CONTAINS: return 1 if obj in seq, else 0; -1 on + error. +*/ /* For DLL-level backwards compatibility */ #undef PySequence_In - PyAPI_FUNC(int) PySequence_In(PyObject *o, PyObject *value); +int PySequence_In(PyObject *o, PyObject *value); /* For source-level backwards compatibility */ #define PySequence_In PySequence_Contains - /* - Determine if o contains value. If an item in o is equal to - X, return 1, otherwise return 0. On error, return -1. This - is equivalent to the Python expression: value in o. - */ +/* +Determine if o contains value. If an item in o is equal to +X, return 1, otherwise return 0. On error, return -1. This +is equivalent to the Python expression: value in o. +*/ - PyAPI_FUNC(Py_ssize_t) PySequence_Index(PyObject *o, PyObject *value); +Py_ssize_t PySequence_Index(PyObject *o, PyObject *value); - /* - Return the first index for which o[i]=value. On error, - return -1. This is equivalent to the Python - expression: o.index(value). - */ +/* +Return the first index for which o[i]=value. On error, +return -1. This is equivalent to the Python +expression: o.index(value). +*/ /* In-place versions of some of the above Sequence functions. */ - PyAPI_FUNC(PyObject *) PySequence_InPlaceConcat(PyObject *o1, PyObject *o2); +PyObject *PySequence_InPlaceConcat(PyObject *o1, PyObject *o2); - /* - Append o2 to o1, in-place when possible. Return the resulting - object, which could be o1, or NULL on failure. This is the - equivalent of the Python expression: o1 += o2. +/* +Append o2 to o1, in-place when possible. Return the resulting +object, which could be o1, or NULL on failure. This is the +equivalent of the Python expression: o1 += o2. - */ +*/ - PyAPI_FUNC(PyObject *) PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count); +PyObject *PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count); - /* - Repeat o1 by count, in-place when possible. Return the resulting - object, which could be o1, or NULL on failure. This is the - equivalent of the Python expression: o1 *= count. +/* +Repeat o1 by count, in-place when possible. Return the resulting +object, which could be o1, or NULL on failure. This is the +equivalent of the Python expression: o1 *= count. - */ +*/ /* Mapping protocol:*/ - PyAPI_FUNC(int) PyMapping_Check(PyObject *o); +int PyMapping_Check(PyObject *o); - /* - Return 1 if the object provides mapping protocol, and zero - otherwise. +/* +Return 1 if the object provides mapping protocol, and zero +otherwise. - This function always succeeds. - */ +This function always succeeds. +*/ - PyAPI_FUNC(Py_ssize_t) PyMapping_Size(PyObject *o); +Py_ssize_t PyMapping_Size(PyObject *o); - /* - Returns the number of keys in object o on success, and -1 on - failure. For objects that do not provide sequence protocol, - this is equivalent to the Python expression: len(o). - */ +/* +Returns the number of keys in object o on success, and -1 on +failure. For objects that do not provide sequence protocol, +this is equivalent to the Python expression: len(o). +*/ - /* For DLL compatibility */ +/* For DLL compatibility */ #undef PyMapping_Length - PyAPI_FUNC(Py_ssize_t) PyMapping_Length(PyObject *o); +Py_ssize_t PyMapping_Length(PyObject *o); #define PyMapping_Length PyMapping_Size +/* implemented as a macro: - /* implemented as a macro: +int PyMapping_DelItemString(PyObject *o, const char *key); - int PyMapping_DelItemString(PyObject *o, const char *key); +Remove the mapping for object, key, from the object *o. +Returns -1 on failure. This is equivalent to +the Python statement: del o[key]. + */ +#define PyMapping_DelItemString(O, K) PyObject_DelItemString((O), (K)) - Remove the mapping for object, key, from the object *o. - Returns -1 on failure. This is equivalent to - the Python statement: del o[key]. - */ -#define PyMapping_DelItemString(O,K) PyObject_DelItemString((O),(K)) +/* implemented as a macro: - /* implemented as a macro: +int PyMapping_DelItem(PyObject *o, PyObject *key); - int PyMapping_DelItem(PyObject *o, PyObject *key); +Remove the mapping for object, key, from the object *o. +Returns -1 on failure. This is equivalent to +the Python statement: del o[key]. + */ +#define PyMapping_DelItem(O, K) PyObject_DelItem((O), (K)) - Remove the mapping for object, key, from the object *o. - Returns -1 on failure. This is equivalent to - the Python statement: del o[key]. - */ -#define PyMapping_DelItem(O,K) PyObject_DelItem((O),(K)) +int PyMapping_HasKeyString(PyObject *o, const char *key); - PyAPI_FUNC(int) PyMapping_HasKeyString(PyObject *o, const char *key); +/* +On success, return 1 if the mapping object has the key, key, +and 0 otherwise. This is equivalent to the Python expression: +key in o. - /* - On success, return 1 if the mapping object has the key, key, - and 0 otherwise. This is equivalent to the Python expression: - key in o. +This function always succeeds. +*/ - This function always succeeds. - */ +int PyMapping_HasKey(PyObject *o, PyObject *key); - PyAPI_FUNC(int) PyMapping_HasKey(PyObject *o, PyObject *key); +/* +Return 1 if the mapping object has the key, key, +and 0 otherwise. This is equivalent to the Python expression: +key in o. - /* - Return 1 if the mapping object has the key, key, - and 0 otherwise. This is equivalent to the Python expression: - key in o. +This function always succeeds. - This function always succeeds. +*/ - */ +PyObject *PyMapping_Keys(PyObject *o); - PyAPI_FUNC(PyObject *) PyMapping_Keys(PyObject *o); +/* +On success, return a list or tuple of the keys in object o. +On failure, return NULL. +*/ - /* - On success, return a list or tuple of the keys in object o. - On failure, return NULL. - */ +PyObject *PyMapping_Values(PyObject *o); - PyAPI_FUNC(PyObject *) PyMapping_Values(PyObject *o); +/* +On success, return a list or tuple of the values in object o. +On failure, return NULL. +*/ - /* - On success, return a list or tuple of the values in object o. - On failure, return NULL. - */ +PyObject *PyMapping_Items(PyObject *o); - PyAPI_FUNC(PyObject *) PyMapping_Items(PyObject *o); +/* +On success, return a list or tuple of the items in object o, +where each item is a tuple containing a key-value pair. +On failure, return NULL. - /* - On success, return a list or tuple of the items in object o, - where each item is a tuple containing a key-value pair. - On failure, return NULL. +*/ - */ +PyObject *PyMapping_GetItemString(PyObject *o, const char *key); - PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o, - const char *key); +/* +Return element of o corresponding to the object, key, or NULL +on failure. This is the equivalent of the Python expression: +o[key]. +*/ - /* - Return element of o corresponding to the object, key, or NULL - on failure. This is the equivalent of the Python expression: - o[key]. - */ +int PyMapping_SetItemString(PyObject *o, const char *key, PyObject *value); - PyAPI_FUNC(int) PyMapping_SetItemString(PyObject *o, const char *key, - PyObject *value); +/* +Map the object, key, to the value, v. Returns +-1 on failure. This is the equivalent of the Python +statement: o[key]=v. +*/ - /* - Map the object, key, to the value, v. Returns - -1 on failure. This is the equivalent of the Python - statement: o[key]=v. - */ - - -PyAPI_FUNC(int) PyObject_IsInstance(PyObject *object, PyObject *typeorclass); - /* isinstance(object, typeorclass) */ - -PyAPI_FUNC(int) PyObject_IsSubclass(PyObject *object, PyObject *typeorclass); - /* issubclass(object, typeorclass) */ +int PyObject_IsInstance(PyObject *object, PyObject *typeorclass); +/* isinstance(object, typeorclass) */ +int PyObject_IsSubclass(PyObject *object, PyObject *typeorclass); +/* issubclass(object, typeorclass) */ #ifndef Py_LIMITED_API -PyAPI_FUNC(int) _PyObject_RealIsInstance(PyObject *inst, PyObject *cls); +int _PyObject_RealIsInstance(PyObject *inst, PyObject *cls); -PyAPI_FUNC(int) _PyObject_RealIsSubclass(PyObject *derived, PyObject *cls); +int _PyObject_RealIsSubclass(PyObject *derived, PyObject *cls); -PyAPI_FUNC(char *const *) _PySequence_BytesToCharpArray(PyObject* self); +char *const *_PySequence_BytesToCharpArray(PyObject *self); -PyAPI_FUNC(void) _Py_FreeCharPArray(char *const array[]); +void _Py_FreeCharPArray(char *const array[]); /* For internal use by buffer API functions */ -PyAPI_FUNC(void) _Py_add_one_to_index_F(int nd, Py_ssize_t *index, - const Py_ssize_t *shape); -PyAPI_FUNC(void) _Py_add_one_to_index_C(int nd, Py_ssize_t *index, - const Py_ssize_t *shape); +void _Py_add_one_to_index_F(int nd, Py_ssize_t *index, const Py_ssize_t *shape); +void _Py_add_one_to_index_C(int nd, Py_ssize_t *index, const Py_ssize_t *shape); #endif /* !Py_LIMITED_API */ COSMOPOLITAN_C_END_ diff --git a/third_party/python/Include/accu.h b/third_party/python/Include/accu.h index 4a1ff91a4..a22a38ca2 100644 --- a/third_party/python/Include/accu.h +++ b/third_party/python/Include/accu.h @@ -1,6 +1,7 @@ #ifndef Py_LIMITED_API #ifndef Py_ACCU_H #define Py_ACCU_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -11,11 +12,11 @@ typedef struct { PyObject *small; /* Pending small strings */ } _PyAccu; -PyAPI_FUNC(int) _PyAccu_Init(_PyAccu *acc); -PyAPI_FUNC(int) _PyAccu_Accumulate(_PyAccu *acc, PyObject *unicode); -PyAPI_FUNC(PyObject *) _PyAccu_FinishAsList(_PyAccu *acc); -PyAPI_FUNC(PyObject *) _PyAccu_Finish(_PyAccu *acc); -PyAPI_FUNC(void) _PyAccu_Destroy(_PyAccu *acc); +int _PyAccu_Init(_PyAccu *acc); +int _PyAccu_Accumulate(_PyAccu *acc, PyObject *unicode); +PyObject * _PyAccu_FinishAsList(_PyAccu *acc); +PyObject * _PyAccu_Finish(_PyAccu *acc); +void _PyAccu_Destroy(_PyAccu *acc); COSMOPOLITAN_C_END_ #endif /* Py_ACCU_H */ diff --git a/third_party/python/Include/asdl.h b/third_party/python/Include/asdl.h index 94b52f14e..261fc676f 100644 --- a/third_party/python/Include/asdl.h +++ b/third_party/python/Include/asdl.h @@ -1,5 +1,7 @@ #ifndef Py_ASDL_H #define Py_ASDL_H +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyarena.h" /* clang-format off */ typedef PyObject * identifier; diff --git a/third_party/python/Include/ast.h b/third_party/python/Include/ast.h index 325f245b5..fcef91cf9 100644 --- a/third_party/python/Include/ast.h +++ b/third_party/python/Include/ast.h @@ -1,16 +1,19 @@ #ifndef Py_AST_H #define Py_AST_H +#include "third_party/python/Include/Python-ast.h" +#include "third_party/python/Include/node.h" +#include "third_party/python/Include/pythonrun.h" COSMOPOLITAN_C_START_ /* clang-format off */ extern int foo; -PyAPI_FUNC(int) PyAST_Validate(mod_ty); -PyAPI_FUNC(mod_ty) PyAST_FromNode( +int PyAST_Validate(mod_ty); +mod_ty PyAST_FromNode( const node *n, PyCompilerFlags *flags, const char *filename, /* decoded from the filesystem encoding */ PyArena *arena); -PyAPI_FUNC(mod_ty) PyAST_FromNodeObject( +mod_ty PyAST_FromNodeObject( const node *n, PyCompilerFlags *flags, PyObject *filename, diff --git a/third_party/python/Include/bitset.h b/third_party/python/Include/bitset.h index 11544451c..14367dbcf 100644 --- a/third_party/python/Include/bitset.h +++ b/third_party/python/Include/bitset.h @@ -1,5 +1,6 @@ #ifndef Py_BITSET_H #define Py_BITSET_H +#include "third_party/python/Include/pgenheaders.h" COSMOPOLITAN_C_START_ /* clang-format off */ diff --git a/third_party/python/Include/bltinmodule.h b/third_party/python/Include/bltinmodule.h index 3d5fe57c0..e5b47e8dd 100644 --- a/third_party/python/Include/bltinmodule.h +++ b/third_party/python/Include/bltinmodule.h @@ -1,11 +1,12 @@ #ifndef Py_BLTINMODULE_H #define Py_BLTINMODULE_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ -PyAPI_DATA(PyTypeObject) PyFilter_Type; -PyAPI_DATA(PyTypeObject) PyMap_Type; -PyAPI_DATA(PyTypeObject) PyZip_Type; +extern PyTypeObject PyFilter_Type; +extern PyTypeObject PyMap_Type; +extern PyTypeObject PyZip_Type; COSMOPOLITAN_C_END_ #endif /* !Py_BLTINMODULE_H */ diff --git a/third_party/python/Include/boolobject.h b/third_party/python/Include/boolobject.h index cbf0cbee6..bce718f83 100644 --- a/third_party/python/Include/boolobject.h +++ b/third_party/python/Include/boolobject.h @@ -1,9 +1,10 @@ #ifndef Py_BOOLOBJECT_H #define Py_BOOLOBJECT_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ -PyAPI_DATA(PyTypeObject) PyBool_Type; +extern PyTypeObject PyBool_Type; #define PyBool_Check(x) (Py_TYPE(x) == &PyBool_Type) @@ -11,7 +12,7 @@ PyAPI_DATA(PyTypeObject) PyBool_Type; Don't forget to apply Py_INCREF() when returning either!!! */ /* Don't use these directly */ -PyAPI_DATA(struct _longobject) _Py_FalseStruct, _Py_TrueStruct; +extern struct _longobject _Py_FalseStruct, _Py_TrueStruct; /* Use these macros */ #define Py_False ((PyObject *)&_Py_FalseStruct) @@ -22,7 +23,7 @@ PyAPI_DATA(struct _longobject) _Py_FalseStruct, _Py_TrueStruct; #define Py_RETURN_FALSE return Py_INCREF(Py_False), Py_False /* Function to return a bool from a C long */ -PyAPI_FUNC(PyObject *) PyBool_FromLong(long); +PyObject * PyBool_FromLong(long); COSMOPOLITAN_C_END_ #endif /* !Py_BOOLOBJECT_H */ diff --git a/third_party/python/Include/bytearrayobject.h b/third_party/python/Include/bytearrayobject.h index 08b484a2b..8fda41061 100644 --- a/third_party/python/Include/bytearrayobject.h +++ b/third_party/python/Include/bytearrayobject.h @@ -1,5 +1,7 @@ #ifndef Py_BYTEARRAYOBJECT_H #define Py_BYTEARRAYOBJECT_H +#include "libc/assert.h" +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -26,20 +28,20 @@ typedef struct { #endif /* Type object */ -PyAPI_DATA(PyTypeObject) PyByteArray_Type; -PyAPI_DATA(PyTypeObject) PyByteArrayIter_Type; +extern PyTypeObject PyByteArray_Type; +extern PyTypeObject PyByteArrayIter_Type; /* Type check macros */ #define PyByteArray_Check(self) PyObject_TypeCheck(self, &PyByteArray_Type) #define PyByteArray_CheckExact(self) (Py_TYPE(self) == &PyByteArray_Type) /* Direct API functions */ -PyAPI_FUNC(PyObject *) PyByteArray_FromObject(PyObject *); -PyAPI_FUNC(PyObject *) PyByteArray_Concat(PyObject *, PyObject *); -PyAPI_FUNC(PyObject *) PyByteArray_FromStringAndSize(const char *, Py_ssize_t); -PyAPI_FUNC(Py_ssize_t) PyByteArray_Size(PyObject *); -PyAPI_FUNC(char *) PyByteArray_AsString(PyObject *); -PyAPI_FUNC(int) PyByteArray_Resize(PyObject *, Py_ssize_t); +PyObject * PyByteArray_FromObject(PyObject *); +PyObject * PyByteArray_Concat(PyObject *, PyObject *); +PyObject * PyByteArray_FromStringAndSize(const char *, Py_ssize_t); +Py_ssize_t PyByteArray_Size(PyObject *); +char * PyByteArray_AsString(PyObject *); +int PyByteArray_Resize(PyObject *, Py_ssize_t); /* Macros, trading safety for speed */ #ifndef Py_LIMITED_API @@ -48,7 +50,7 @@ PyAPI_FUNC(int) PyByteArray_Resize(PyObject *, Py_ssize_t); Py_SIZE(self) ? ((PyByteArrayObject *)(self))->ob_start : _PyByteArray_empty_string) #define PyByteArray_GET_SIZE(self) (assert(PyByteArray_Check(self)), Py_SIZE(self)) -PyAPI_DATA(char) _PyByteArray_empty_string[]; +extern char _PyByteArray_empty_string[]; #endif COSMOPOLITAN_C_END_ diff --git a/third_party/python/Include/bytes_methods.h b/third_party/python/Include/bytes_methods.h index 7dc173ea3..b4fb4ca4e 100644 --- a/third_party/python/Include/bytes_methods.h +++ b/third_party/python/Include/bytes_methods.h @@ -1,6 +1,8 @@ #ifndef Py_LIMITED_API #ifndef Py_BYTES_CTYPE_H #define Py_BYTES_CTYPE_H +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pymacro.h" /* clang-format off */ /* diff --git a/third_party/python/Include/bytesobject.h b/third_party/python/Include/bytesobject.h index ab789bc51..d3890df4d 100644 --- a/third_party/python/Include/bytesobject.h +++ b/third_party/python/Include/bytesobject.h @@ -1,5 +1,6 @@ #ifndef Py_BYTESOBJECT_H #define Py_BYTESOBJECT_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -35,42 +36,42 @@ typedef struct { } PyBytesObject; #endif -PyAPI_DATA(PyTypeObject) PyBytes_Type; -PyAPI_DATA(PyTypeObject) PyBytesIter_Type; +extern PyTypeObject PyBytes_Type; +extern PyTypeObject PyBytesIter_Type; #define PyBytes_Check(op) \ PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_BYTES_SUBCLASS) #define PyBytes_CheckExact(op) (Py_TYPE(op) == &PyBytes_Type) -PyAPI_FUNC(PyObject *) PyBytes_FromStringAndSize(const char *, Py_ssize_t); -PyAPI_FUNC(PyObject *) PyBytes_FromString(const char *); -PyAPI_FUNC(PyObject *) PyBytes_FromObject(PyObject *); -PyAPI_FUNC(PyObject *) PyBytes_FromFormatV(const char*, va_list) +PyObject * PyBytes_FromStringAndSize(const char *, Py_ssize_t); +PyObject * PyBytes_FromString(const char *); +PyObject * PyBytes_FromObject(PyObject *); +PyObject * PyBytes_FromFormatV(const char*, va_list) Py_GCC_ATTRIBUTE((format(printf, 1, 0))); -PyAPI_FUNC(PyObject *) PyBytes_FromFormat(const char*, ...) +PyObject * PyBytes_FromFormat(const char*, ...) Py_GCC_ATTRIBUTE((format(printf, 1, 2))); -PyAPI_FUNC(Py_ssize_t) PyBytes_Size(PyObject *); -PyAPI_FUNC(char *) PyBytes_AsString(PyObject *); -PyAPI_FUNC(PyObject *) PyBytes_Repr(PyObject *, int); -PyAPI_FUNC(void) PyBytes_Concat(PyObject **, PyObject *); -PyAPI_FUNC(void) PyBytes_ConcatAndDel(PyObject **, PyObject *); +Py_ssize_t PyBytes_Size(PyObject *); +char * PyBytes_AsString(PyObject *); +PyObject * PyBytes_Repr(PyObject *, int); +void PyBytes_Concat(PyObject **, PyObject *); +void PyBytes_ConcatAndDel(PyObject **, PyObject *); #ifndef Py_LIMITED_API -PyAPI_FUNC(int) _PyBytes_Resize(PyObject **, Py_ssize_t); -PyAPI_FUNC(PyObject*) _PyBytes_FormatEx( +int _PyBytes_Resize(PyObject **, Py_ssize_t); +PyObject* _PyBytes_FormatEx( const char *format, Py_ssize_t format_len, PyObject *args, int use_bytearray); -PyAPI_FUNC(PyObject*) _PyBytes_FromHex( +PyObject* _PyBytes_FromHex( PyObject *string, int use_bytearray); #endif -PyAPI_FUNC(PyObject *) PyBytes_DecodeEscape(const char *, Py_ssize_t, +PyObject * PyBytes_DecodeEscape(const char *, Py_ssize_t, const char *, Py_ssize_t, const char *); #ifndef Py_LIMITED_API /* Helper for PyBytes_DecodeEscape that detects invalid escape chars. */ -PyAPI_FUNC(PyObject *) _PyBytes_DecodeEscape(const char *, Py_ssize_t, +PyObject * _PyBytes_DecodeEscape(const char *, Py_ssize_t, const char *, Py_ssize_t, const char *, const char **); @@ -86,7 +87,7 @@ PyAPI_FUNC(PyObject *) _PyBytes_DecodeEscape(const char *, Py_ssize_t, /* _PyBytes_Join(sep, x) is like sep.join(x). sep must be PyBytesObject*, x must be an iterable object. */ #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) _PyBytes_Join(PyObject *sep, PyObject *x); +PyObject * _PyBytes_Join(PyObject *sep, PyObject *x); #endif /* Provides access to the internal data buffer and size of a string @@ -94,7 +95,7 @@ PyAPI_FUNC(PyObject *) _PyBytes_Join(PyObject *sep, PyObject *x); NULL as *len parameter will force the string buffer to be 0-terminated (passing a string with embedded NULL characters will cause an exception). */ -PyAPI_FUNC(int) PyBytes_AsStringAndSize( +int PyBytes_AsStringAndSize( PyObject *obj, /* string or Unicode object */ char **s, /* pointer to buffer variable */ Py_ssize_t *len /* pointer to length variable or NULL @@ -106,7 +107,7 @@ PyAPI_FUNC(int) PyBytes_AsStringAndSize( into the string pointed to by buffer. For the argument descriptions, see Objects/stringlib/localeutil.h */ #ifndef Py_LIMITED_API -PyAPI_FUNC(Py_ssize_t) _PyBytes_InsertThousandsGroupingLocale(char *buffer, +Py_ssize_t _PyBytes_InsertThousandsGroupingLocale(char *buffer, Py_ssize_t n_buffer, char *digits, Py_ssize_t n_digits, @@ -115,7 +116,7 @@ PyAPI_FUNC(Py_ssize_t) _PyBytes_InsertThousandsGroupingLocale(char *buffer, /* Using explicit passed-in values, insert the thousands grouping into the string pointed to by buffer. For the argument descriptions, see Objects/stringlib/localeutil.h */ -PyAPI_FUNC(Py_ssize_t) _PyBytes_InsertThousandsGrouping(char *buffer, +Py_ssize_t _PyBytes_InsertThousandsGrouping(char *buffer, Py_ssize_t n_buffer, char *digits, Py_ssize_t n_digits, @@ -162,21 +163,21 @@ typedef struct { By default, the overallocation is disabled. Set the overallocate attribute to control the allocation of the buffer. */ -PyAPI_FUNC(void) _PyBytesWriter_Init(_PyBytesWriter *writer); +void _PyBytesWriter_Init(_PyBytesWriter *writer); /* Get the buffer content and reset the writer. Return a bytes object, or a bytearray object if use_bytearray is non-zero. Raise an exception and return NULL on error. */ -PyAPI_FUNC(PyObject *) _PyBytesWriter_Finish(_PyBytesWriter *writer, +PyObject * _PyBytesWriter_Finish(_PyBytesWriter *writer, void *str); /* Deallocate memory of a writer (clear its internal buffer). */ -PyAPI_FUNC(void) _PyBytesWriter_Dealloc(_PyBytesWriter *writer); +void _PyBytesWriter_Dealloc(_PyBytesWriter *writer); /* Allocate the buffer to write size bytes. Return the pointer to the beginning of buffer data. Raise an exception and return NULL on error. */ -PyAPI_FUNC(void*) _PyBytesWriter_Alloc(_PyBytesWriter *writer, +void* _PyBytesWriter_Alloc(_PyBytesWriter *writer, Py_ssize_t size); /* Ensure that the buffer is large enough to write *size* bytes. @@ -185,7 +186,7 @@ PyAPI_FUNC(void*) _PyBytesWriter_Alloc(_PyBytesWriter *writer, str is the current pointer inside the buffer. Return the updated current pointer inside the buffer. Raise an exception and return NULL on error. */ -PyAPI_FUNC(void*) _PyBytesWriter_Prepare(_PyBytesWriter *writer, +void* _PyBytesWriter_Prepare(_PyBytesWriter *writer, void *str, Py_ssize_t size); @@ -200,13 +201,13 @@ PyAPI_FUNC(void*) _PyBytesWriter_Prepare(_PyBytesWriter *writer, See also _PyBytesWriter_Prepare(). */ -PyAPI_FUNC(void*) _PyBytesWriter_Resize(_PyBytesWriter *writer, +void* _PyBytesWriter_Resize(_PyBytesWriter *writer, void *str, Py_ssize_t size); /* Write bytes. Raise an exception and return NULL on error. */ -PyAPI_FUNC(void*) _PyBytesWriter_WriteBytes(_PyBytesWriter *writer, +void* _PyBytesWriter_WriteBytes(_PyBytesWriter *writer, void *str, const void *bytes, Py_ssize_t size); diff --git a/third_party/python/Include/cellobject.h b/third_party/python/Include/cellobject.h index 73ab55afd..d7bc810a9 100644 --- a/third_party/python/Include/cellobject.h +++ b/third_party/python/Include/cellobject.h @@ -1,6 +1,7 @@ #ifndef Py_LIMITED_API #ifndef Py_CELLOBJECT_H #define Py_CELLOBJECT_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -9,13 +10,13 @@ typedef struct { PyObject *ob_ref; /* Content of the cell or NULL when empty */ } PyCellObject; -PyAPI_DATA(PyTypeObject) PyCell_Type; +extern PyTypeObject PyCell_Type; #define PyCell_Check(op) (Py_TYPE(op) == &PyCell_Type) -PyAPI_FUNC(PyObject *) PyCell_New(PyObject *); -PyAPI_FUNC(PyObject *) PyCell_Get(PyObject *); -PyAPI_FUNC(int) PyCell_Set(PyObject *, PyObject *); +PyObject * PyCell_New(PyObject *); +PyObject * PyCell_Get(PyObject *); +int PyCell_Set(PyObject *, PyObject *); #define PyCell_GET(op) (((PyCellObject *)(op))->ob_ref) #define PyCell_SET(op, v) (((PyCellObject *)(op))->ob_ref = v) diff --git a/third_party/python/Include/ceval.h b/third_party/python/Include/ceval.h index c949b817f..abe454d42 100644 --- a/third_party/python/Include/ceval.h +++ b/third_party/python/Include/ceval.h @@ -1,53 +1,53 @@ #ifndef Py_CEVAL_H #define Py_CEVAL_H +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pystate.h" +#include "third_party/python/Include/pythonrun.h" COSMOPOLITAN_C_START_ /* clang-format off */ /* Interface to random parts in ceval.c */ -PyAPI_FUNC(PyObject *) PyEval_CallObjectWithKeywords( +PyObject * PyEval_CallObjectWithKeywords( PyObject *func, PyObject *args, PyObject *kwargs); /* Inline this */ #define PyEval_CallObject(func,arg) \ PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL) -PyAPI_FUNC(PyObject *) PyEval_CallFunction(PyObject *obj, - const char *format, ...); -PyAPI_FUNC(PyObject *) PyEval_CallMethod(PyObject *obj, - const char *methodname, - const char *format, ...); +PyObject * PyEval_CallFunction(PyObject *, const char *, ...); +PyObject * PyEval_CallMethod(PyObject *, const char *, const char *, ...); #ifndef Py_LIMITED_API -PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *); -PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *); -PyAPI_FUNC(void) _PyEval_SetCoroutineWrapper(PyObject *); -PyAPI_FUNC(PyObject *) _PyEval_GetCoroutineWrapper(void); -PyAPI_FUNC(void) _PyEval_SetAsyncGenFirstiter(PyObject *); -PyAPI_FUNC(PyObject *) _PyEval_GetAsyncGenFirstiter(void); -PyAPI_FUNC(void) _PyEval_SetAsyncGenFinalizer(PyObject *); -PyAPI_FUNC(PyObject *) _PyEval_GetAsyncGenFinalizer(void); +void PyEval_SetProfile(Py_tracefunc, PyObject *); +void PyEval_SetTrace(Py_tracefunc, PyObject *); +void _PyEval_SetCoroutineWrapper(PyObject *); +PyObject * _PyEval_GetCoroutineWrapper(void); +void _PyEval_SetAsyncGenFirstiter(PyObject *); +PyObject * _PyEval_GetAsyncGenFirstiter(void); +void _PyEval_SetAsyncGenFinalizer(PyObject *); +PyObject * _PyEval_GetAsyncGenFinalizer(void); #endif struct _frame; /* Avoid including frameobject.h */ -PyAPI_FUNC(PyObject *) PyEval_GetBuiltins(void); -PyAPI_FUNC(PyObject *) PyEval_GetGlobals(void); -PyAPI_FUNC(PyObject *) PyEval_GetLocals(void); -PyAPI_FUNC(struct _frame *) PyEval_GetFrame(void); +PyObject * PyEval_GetBuiltins(void); +PyObject * PyEval_GetGlobals(void); +PyObject * PyEval_GetLocals(void); +struct _frame * PyEval_GetFrame(void); #ifndef Py_LIMITED_API /* Helper to look up a builtin object */ -PyAPI_FUNC(PyObject *) _PyEval_GetBuiltinId(_Py_Identifier *); +PyObject * _PyEval_GetBuiltinId(_Py_Identifier *); /* Look at the current frame's (if any) code's co_flags, and turn on the corresponding compiler flags in cf->cf_flags. Return 1 if any flag was set, else return 0. */ -PyAPI_FUNC(int) PyEval_MergeCompilerFlags(PyCompilerFlags *cf); +int PyEval_MergeCompilerFlags(PyCompilerFlags *cf); #endif -PyAPI_FUNC(int) Py_AddPendingCall(int (*func)(void *), void *arg); -PyAPI_FUNC(void) _PyEval_SignalReceived(void); -PyAPI_FUNC(int) Py_MakePendingCalls(void); +int Py_AddPendingCall(int (*func)(void *), void *arg); +void _PyEval_SignalReceived(void); +int Py_MakePendingCalls(void); /* Protection against deeply nested recursive calls @@ -74,8 +74,8 @@ PyAPI_FUNC(int) Py_MakePendingCalls(void); http://mail.python.org/pipermail/python-dev/2008-August/082106.html for some observations. */ -PyAPI_FUNC(void) Py_SetRecursionLimit(int); -PyAPI_FUNC(int) Py_GetRecursionLimit(void); +void Py_SetRecursionLimit(int); +int Py_GetRecursionLimit(void); #define Py_EnterRecursiveCall(where) \ (_Py_MakeRecCheck(PyThreadState_GET()->recursion_depth) && \ @@ -84,8 +84,8 @@ PyAPI_FUNC(int) Py_GetRecursionLimit(void); do{ if(_Py_MakeEndRecCheck(PyThreadState_GET()->recursion_depth)) \ PyThreadState_GET()->overflowed = 0; \ } while(0) -PyAPI_FUNC(int) _Py_CheckRecursiveCall(const char *where); -PyAPI_DATA(int) _Py_CheckRecursionLimit; +int _Py_CheckRecursiveCall(const char *where); +extern int _Py_CheckRecursionLimit; #ifdef USE_STACKCHECK /* With USE_STACKCHECK, we artificially decrement the recursion limit in order @@ -118,14 +118,14 @@ PyAPI_DATA(int) _Py_CheckRecursionLimit; PyThreadState_GET()->recursion_critical = _old; \ } while(0); -PyAPI_FUNC(const char *) PyEval_GetFuncName(PyObject *); -PyAPI_FUNC(const char *) PyEval_GetFuncDesc(PyObject *); +const char * PyEval_GetFuncName(PyObject *); +const char * PyEval_GetFuncDesc(PyObject *); -PyAPI_FUNC(PyObject *) PyEval_GetCallStats(PyObject *); -PyAPI_FUNC(PyObject *) PyEval_EvalFrame(struct _frame *); -PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(struct _frame *f, int exc); +PyObject * PyEval_GetCallStats(PyObject *); +PyObject * PyEval_EvalFrame(struct _frame *); +PyObject * PyEval_EvalFrameEx(struct _frame *f, int exc); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(struct _frame *f, int exc); +PyObject * _PyEval_EvalFrameDefault(struct _frame *f, int exc); #endif /* Interface for threads. @@ -173,29 +173,29 @@ PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(struct _frame *f, int exc); mechanism! */ -PyAPI_FUNC(PyThreadState *) PyEval_SaveThread(void); -PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *); +PyThreadState * PyEval_SaveThread(void); +void PyEval_RestoreThread(PyThreadState *); #ifdef WITH_THREAD -PyAPI_FUNC(int) PyEval_ThreadsInitialized(void); -PyAPI_FUNC(void) PyEval_InitThreads(void); +int PyEval_ThreadsInitialized(void); +void PyEval_InitThreads(void); #ifndef Py_LIMITED_API -PyAPI_FUNC(void) _PyEval_FiniThreads(void); +void _PyEval_FiniThreads(void); #endif /* !Py_LIMITED_API */ -PyAPI_FUNC(void) PyEval_AcquireLock(void); -PyAPI_FUNC(void) PyEval_ReleaseLock(void); -PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate); -PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate); -PyAPI_FUNC(void) PyEval_ReInitThreads(void); +void PyEval_AcquireLock(void); +void PyEval_ReleaseLock(void); +void PyEval_AcquireThread(PyThreadState *tstate); +void PyEval_ReleaseThread(PyThreadState *tstate); +void PyEval_ReInitThreads(void); #ifndef Py_LIMITED_API -PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds); -PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void); +void _PyEval_SetSwitchInterval(unsigned long microseconds); +unsigned long _PyEval_GetSwitchInterval(void); #endif #ifndef Py_LIMITED_API -PyAPI_FUNC(Py_ssize_t) _PyEval_RequestCodeExtraIndex(freefunc); +Py_ssize_t _PyEval_RequestCodeExtraIndex(freefunc); #endif #define Py_BEGIN_ALLOW_THREADS { \ @@ -216,9 +216,9 @@ PyAPI_FUNC(Py_ssize_t) _PyEval_RequestCodeExtraIndex(freefunc); #endif /* !WITH_THREAD */ #ifndef Py_LIMITED_API -PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, Py_ssize_t *); -PyAPI_FUNC(int) _PyEval_SliceIndexNotNone(PyObject *, Py_ssize_t *); -PyAPI_FUNC(void) _PyEval_SignalAsyncExc(void); +int _PyEval_SliceIndex(PyObject *, Py_ssize_t *); +int _PyEval_SliceIndexNotNone(PyObject *, Py_ssize_t *); +void _PyEval_SignalAsyncExc(void); #endif /* Masks and values used by FORMAT_VALUE opcode. */ diff --git a/third_party/python/Include/classobject.h b/third_party/python/Include/classobject.h index 50705a214..5844011c5 100644 --- a/third_party/python/Include/classobject.h +++ b/third_party/python/Include/classobject.h @@ -1,6 +1,7 @@ #ifndef Py_LIMITED_API #ifndef Py_CLASSOBJECT_H #define Py_CLASSOBJECT_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -11,14 +12,14 @@ typedef struct { PyObject *im_weakreflist; /* List of weak references */ } PyMethodObject; -PyAPI_DATA(PyTypeObject) PyMethod_Type; +extern PyTypeObject PyMethod_Type; #define PyMethod_Check(op) ((op)->ob_type == &PyMethod_Type) -PyAPI_FUNC(PyObject *) PyMethod_New(PyObject *, PyObject *); +PyObject * PyMethod_New(PyObject *, PyObject *); -PyAPI_FUNC(PyObject *) PyMethod_Function(PyObject *); -PyAPI_FUNC(PyObject *) PyMethod_Self(PyObject *); +PyObject * PyMethod_Function(PyObject *); +PyObject * PyMethod_Self(PyObject *); /* Macros for direct access to these values. Type checks are *not* done, so use with care. */ @@ -27,19 +28,19 @@ PyAPI_FUNC(PyObject *) PyMethod_Self(PyObject *); #define PyMethod_GET_SELF(meth) \ (((PyMethodObject *)meth) -> im_self) -PyAPI_FUNC(int) PyMethod_ClearFreeList(void); +int PyMethod_ClearFreeList(void); typedef struct { PyObject_HEAD PyObject *func; } PyInstanceMethodObject; -PyAPI_DATA(PyTypeObject) PyInstanceMethod_Type; +extern PyTypeObject PyInstanceMethod_Type; #define PyInstanceMethod_Check(op) ((op)->ob_type == &PyInstanceMethod_Type) -PyAPI_FUNC(PyObject *) PyInstanceMethod_New(PyObject *); -PyAPI_FUNC(PyObject *) PyInstanceMethod_Function(PyObject *); +PyObject * PyInstanceMethod_New(PyObject *); +PyObject * PyInstanceMethod_Function(PyObject *); /* Macros for direct access to these values. Type checks are *not* done, so use with care. */ diff --git a/third_party/python/Include/code.h b/third_party/python/Include/code.h index 511c73b5d..049d6c106 100644 --- a/third_party/python/Include/code.h +++ b/third_party/python/Include/code.h @@ -1,84 +1,83 @@ #ifndef Py_LIMITED_API #ifndef Py_CODE_H #define Py_CODE_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ -/* clang-format off */ typedef uint16_t _Py_CODEUNIT; #ifdef WORDS_BIGENDIAN -# define _Py_OPCODE(word) ((word) >> 8) -# define _Py_OPARG(word) ((word) & 255) +#define _Py_OPCODE(word) ((word) >> 8) +#define _Py_OPARG(word) ((word)&255) #else -# define _Py_OPCODE(word) ((word) & 255) -# define _Py_OPARG(word) ((word) >> 8) +#define _Py_OPCODE(word) ((word)&255) +#define _Py_OPARG(word) ((word) >> 8) #endif /* Bytecode object */ typedef struct { - PyObject_HEAD - int co_argcount; /* #arguments, except *args */ - int co_kwonlyargcount; /* #keyword only arguments */ - int co_nlocals; /* #local variables */ - int co_stacksize; /* #entries needed for evaluation stack */ - int co_flags; /* CO_..., see below */ - int co_firstlineno; /* first source line number */ - PyObject *co_code; /* instruction opcodes */ - PyObject *co_consts; /* list (constants used) */ - PyObject *co_names; /* list of strings (names used) */ - PyObject *co_varnames; /* tuple of strings (local variable names) */ - PyObject *co_freevars; /* tuple of strings (free variable names) */ - PyObject *co_cellvars; /* tuple of strings (cell variable names) */ - /* The rest aren't used in either hash or comparisons, except for co_name, - used in both. This is done to preserve the name and line number - for tracebacks and debuggers; otherwise, constant de-duplication - would collapse identical functions/lambdas defined on different lines. - */ - unsigned char *co_cell2arg; /* Maps cell vars which are arguments. */ - PyObject *co_filename; /* unicode (where it was loaded from) */ - PyObject *co_name; /* unicode (name, for reference) */ - PyObject *co_lnotab; /* string (encoding addr<->lineno mapping) See - Objects/lnotab_notes.txt for details. */ - void *co_zombieframe; /* for optimization only (see frameobject.c) */ - PyObject *co_weakreflist; /* to support weakrefs to code objects */ - /* Scratch space for extra data relating to the code object. - Type is a void* to keep the format private in codeobject.c to force - people to go through the proper APIs. */ - void *co_extra; + PyObject_HEAD int co_argcount; /* #arguments, except *args */ + int co_kwonlyargcount; /* #keyword only arguments */ + int co_nlocals; /* #local variables */ + int co_stacksize; /* #entries needed for evaluation stack */ + int co_flags; /* CO_..., see below */ + int co_firstlineno; /* first source line number */ + PyObject *co_code; /* instruction opcodes */ + PyObject *co_consts; /* list (constants used) */ + PyObject *co_names; /* list of strings (names used) */ + PyObject *co_varnames; /* tuple of strings (local variable names) */ + PyObject *co_freevars; /* tuple of strings (free variable names) */ + PyObject *co_cellvars; /* tuple of strings (cell variable names) */ + /* The rest aren't used in either hash or comparisons, except for co_name, + used in both. This is done to preserve the name and line number + for tracebacks and debuggers; otherwise, constant de-duplication + would collapse identical functions/lambdas defined on different lines. + */ + unsigned char *co_cell2arg; /* Maps cell vars which are arguments. */ + PyObject *co_filename; /* unicode (where it was loaded from) */ + PyObject *co_name; /* unicode (name, for reference) */ + PyObject *co_lnotab; /* string (encoding addr<->lineno mapping) See + Objects/lnotab_notes.txt for details. */ + void *co_zombieframe; /* for optimization only (see frameobject.c) */ + PyObject *co_weakreflist; /* to support weakrefs to code objects */ + /* Scratch space for extra data relating to the code object. + Type is a void* to keep the format private in codeobject.c to force + people to go through the proper APIs. */ + void *co_extra; } PyCodeObject; /* Masks for co_flags above */ -#define CO_OPTIMIZED 0x0001 -#define CO_NEWLOCALS 0x0002 -#define CO_VARARGS 0x0004 -#define CO_VARKEYWORDS 0x0008 -#define CO_NESTED 0x0010 -#define CO_GENERATOR 0x0020 +#define CO_OPTIMIZED 0x0001 +#define CO_NEWLOCALS 0x0002 +#define CO_VARARGS 0x0004 +#define CO_VARKEYWORDS 0x0008 +#define CO_NESTED 0x0010 +#define CO_GENERATOR 0x0020 /* The CO_NOFREE flag is set if there are no free or cell variables. This information is redundant, but it allows a single flag test to determine whether there is any extra work to be done when the call frame it setup. */ -#define CO_NOFREE 0x0040 +#define CO_NOFREE 0x0040 /* The CO_COROUTINE flag is set for coroutine functions (defined with ``async def`` keywords) */ -#define CO_COROUTINE 0x0080 -#define CO_ITERABLE_COROUTINE 0x0100 -#define CO_ASYNC_GENERATOR 0x0200 +#define CO_COROUTINE 0x0080 +#define CO_ITERABLE_COROUTINE 0x0100 +#define CO_ASYNC_GENERATOR 0x0200 /* These are no longer used. */ #if 0 -#define CO_GENERATOR_ALLOWED 0x1000 +#define CO_GENERATOR_ALLOWED 0x1000 #endif -#define CO_FUTURE_DIVISION 0x2000 -#define CO_FUTURE_ABSOLUTE_IMPORT 0x4000 /* do absolute imports by default */ -#define CO_FUTURE_WITH_STATEMENT 0x8000 -#define CO_FUTURE_PRINT_FUNCTION 0x10000 +#define CO_FUTURE_DIVISION 0x2000 +#define CO_FUTURE_ABSOLUTE_IMPORT 0x4000 /* do absolute imports by default */ +#define CO_FUTURE_WITH_STATEMENT 0x8000 +#define CO_FUTURE_PRINT_FUNCTION 0x10000 #define CO_FUTURE_UNICODE_LITERALS 0x20000 #define CO_FUTURE_BARRY_AS_BDFL 0x40000 -#define CO_FUTURE_GENERATOR_STOP 0x80000 +#define CO_FUTURE_GENERATOR_STOP 0x80000 /* This value is found in the co_cell2arg array when the associated cell variable does not correspond to an argument. The maximum number of @@ -92,39 +91,37 @@ typedef struct { #define CO_MAXBLOCKS 20 /* Max static block nesting within a function */ -PyAPI_DATA(PyTypeObject) PyCode_Type; +extern PyTypeObject PyCode_Type; -#define PyCode_Check(op) (Py_TYPE(op) == &PyCode_Type) +#define PyCode_Check(op) (Py_TYPE(op) == &PyCode_Type) #define PyCode_GetNumFree(op) (PyTuple_GET_SIZE((op)->co_freevars)) /* Public interface */ -PyAPI_FUNC(PyCodeObject *) PyCode_New( - int, int, int, int, int, PyObject *, PyObject *, - PyObject *, PyObject *, PyObject *, PyObject *, - PyObject *, PyObject *, int, PyObject *); - /* same as struct above */ +PyCodeObject *PyCode_New(int, int, int, int, int, PyObject *, PyObject *, + PyObject *, PyObject *, PyObject *, PyObject *, + PyObject *, PyObject *, int, PyObject *); +/* same as struct above */ /* Creates a new empty code object with the specified source location. */ -PyAPI_FUNC(PyCodeObject *) -PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno); +PyCodeObject *PyCode_NewEmpty(const char *filename, const char *funcname, + int firstlineno); /* Return the line number associated with the specified bytecode index in this code object. If you just need the line number of a frame, use PyFrame_GetLineNumber() instead. */ -PyAPI_FUNC(int) PyCode_Addr2Line(PyCodeObject *, int); +int PyCode_Addr2Line(PyCodeObject *, int); /* for internal use only */ typedef struct _addr_pair { - int ap_lower; - int ap_upper; + int ap_lower; + int ap_upper; } PyAddrPair; #ifndef Py_LIMITED_API -/* Update *bounds to describe the first and one-past-the-last instructions in the - same line as lasti. Return the number of that line. +/* Update *bounds to describe the first and one-past-the-last instructions in + the same line as lasti. Return the number of that line. */ -PyAPI_FUNC(int) _PyCode_CheckLineNumber(PyCodeObject* co, - int lasti, PyAddrPair *bounds); +int _PyCode_CheckLineNumber(PyCodeObject *co, int lasti, PyAddrPair *bounds); /* Create a comparable key used to compare constants taking in account the * object type. It is used to make sure types are not coerced (e.g., float and @@ -133,18 +130,15 @@ PyAPI_FUNC(int) _PyCode_CheckLineNumber(PyCodeObject* co, * Return (type(obj), obj, ...): a tuple with variable size (at least 2 items) * depending on the type and the value. The type is the first item to not * compare bytes and str which can raise a BytesWarning exception. */ -PyAPI_FUNC(PyObject*) _PyCode_ConstantKey(PyObject *obj); +PyObject *_PyCode_ConstantKey(PyObject *obj); #endif -PyAPI_FUNC(PyObject*) PyCode_Optimize(PyObject *code, PyObject* consts, - PyObject *names, PyObject *lnotab); - +PyObject *PyCode_Optimize(PyObject *code, PyObject *consts, PyObject *names, + PyObject *lnotab); #ifndef Py_LIMITED_API -PyAPI_FUNC(int) _PyCode_GetExtra(PyObject *code, Py_ssize_t index, - void **extra); -PyAPI_FUNC(int) _PyCode_SetExtra(PyObject *code, Py_ssize_t index, - void *extra); +int _PyCode_GetExtra(PyObject *code, Py_ssize_t index, void **extra); +int _PyCode_SetExtra(PyObject *code, Py_ssize_t index, void *extra); #endif COSMOPOLITAN_C_END_ diff --git a/third_party/python/Include/codecs.h b/third_party/python/Include/codecs.h index 6619b734b..41ef6e1b9 100644 --- a/third_party/python/Include/codecs.h +++ b/third_party/python/Include/codecs.h @@ -1,5 +1,6 @@ #ifndef Py_CODECREGISTRY_H #define Py_CODECREGISTRY_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -22,7 +23,7 @@ Copyright (c) Corporation for National Research Initiatives. The search_function's refcount is incremented by this function. */ -PyAPI_FUNC(int) PyCodec_Register( +int PyCodec_Register( PyObject *search_function ); @@ -45,11 +46,11 @@ PyAPI_FUNC(int) PyCodec_Register( */ #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) _PyCodec_Lookup( +PyObject * _PyCodec_Lookup( const char *encoding ); -PyAPI_FUNC(int) _PyCodec_Forget( +int _PyCodec_Forget( const char *encoding ); #endif @@ -61,7 +62,7 @@ PyAPI_FUNC(int) _PyCodec_Forget( */ -PyAPI_FUNC(int) PyCodec_KnownEncoding( +int PyCodec_KnownEncoding( const char *encoding ); @@ -75,7 +76,7 @@ PyAPI_FUNC(int) PyCodec_KnownEncoding( */ -PyAPI_FUNC(PyObject *) PyCodec_Encode( +PyObject * PyCodec_Encode( PyObject *object, const char *encoding, const char *errors @@ -91,7 +92,7 @@ PyAPI_FUNC(PyObject *) PyCodec_Encode( */ -PyAPI_FUNC(PyObject *) PyCodec_Decode( +PyObject * PyCodec_Decode( PyObject *object, const char *encoding, const char *errors @@ -111,18 +112,18 @@ PyAPI_FUNC(PyObject *) PyCodec_Decode( in Python 3.5+? */ -PyAPI_FUNC(PyObject *) _PyCodec_LookupTextEncoding( +PyObject * _PyCodec_LookupTextEncoding( const char *encoding, const char *alternate_command ); -PyAPI_FUNC(PyObject *) _PyCodec_EncodeText( +PyObject * _PyCodec_EncodeText( PyObject *object, const char *encoding, const char *errors ); -PyAPI_FUNC(PyObject *) _PyCodec_DecodeText( +PyObject * _PyCodec_DecodeText( PyObject *object, const char *encoding, const char *errors @@ -131,12 +132,12 @@ PyAPI_FUNC(PyObject *) _PyCodec_DecodeText( /* These two aren't actually text encoding specific, but _io.TextIOWrapper * is the only current API consumer. */ -PyAPI_FUNC(PyObject *) _PyCodecInfo_GetIncrementalDecoder( +PyObject * _PyCodecInfo_GetIncrementalDecoder( PyObject *codec_info, const char *errors ); -PyAPI_FUNC(PyObject *) _PyCodecInfo_GetIncrementalEncoder( +PyObject * _PyCodecInfo_GetIncrementalEncoder( PyObject *codec_info, const char *errors ); @@ -154,33 +155,33 @@ PyAPI_FUNC(PyObject *) _PyCodecInfo_GetIncrementalEncoder( /* Get an encoder function for the given encoding. */ -PyAPI_FUNC(PyObject *) PyCodec_Encoder( +PyObject * PyCodec_Encoder( const char *encoding ); /* Get a decoder function for the given encoding. */ -PyAPI_FUNC(PyObject *) PyCodec_Decoder( +PyObject * PyCodec_Decoder( const char *encoding ); /* Get an IncrementalEncoder object for the given encoding. */ -PyAPI_FUNC(PyObject *) PyCodec_IncrementalEncoder( +PyObject * PyCodec_IncrementalEncoder( const char *encoding, const char *errors ); /* Get an IncrementalDecoder object function for the given encoding. */ -PyAPI_FUNC(PyObject *) PyCodec_IncrementalDecoder( +PyObject * PyCodec_IncrementalDecoder( const char *encoding, const char *errors ); /* Get a StreamReader factory function for the given encoding. */ -PyAPI_FUNC(PyObject *) PyCodec_StreamReader( +PyObject * PyCodec_StreamReader( const char *encoding, PyObject *stream, const char *errors @@ -188,7 +189,7 @@ PyAPI_FUNC(PyObject *) PyCodec_StreamReader( /* Get a StreamWriter factory function for the given encoding. */ -PyAPI_FUNC(PyObject *) PyCodec_StreamWriter( +PyObject * PyCodec_StreamWriter( const char *encoding, PyObject *stream, const char *errors @@ -202,35 +203,35 @@ PyAPI_FUNC(PyObject *) PyCodec_StreamWriter( callback name, when name is specified as the error parameter in the call to the encode/decode function. Return 0 on success, -1 on error */ -PyAPI_FUNC(int) PyCodec_RegisterError(const char *name, PyObject *error); +int PyCodec_RegisterError(const char *name, PyObject *error); /* Lookup the error handling callback function registered under the given name. As a special case NULL can be passed, in which case the error handling callback for "strict" will be returned. */ -PyAPI_FUNC(PyObject *) PyCodec_LookupError(const char *name); +PyObject * PyCodec_LookupError(const char *name); /* raise exc as an exception */ -PyAPI_FUNC(PyObject *) PyCodec_StrictErrors(PyObject *exc); +PyObject * PyCodec_StrictErrors(PyObject *exc); /* ignore the unicode error, skipping the faulty input */ -PyAPI_FUNC(PyObject *) PyCodec_IgnoreErrors(PyObject *exc); +PyObject * PyCodec_IgnoreErrors(PyObject *exc); /* replace the unicode encode error with ? or U+FFFD */ -PyAPI_FUNC(PyObject *) PyCodec_ReplaceErrors(PyObject *exc); +PyObject * PyCodec_ReplaceErrors(PyObject *exc); /* replace the unicode encode error with XML character references */ -PyAPI_FUNC(PyObject *) PyCodec_XMLCharRefReplaceErrors(PyObject *exc); +PyObject * PyCodec_XMLCharRefReplaceErrors(PyObject *exc); /* replace the unicode encode error with backslash escapes (\x, \u and \U) */ -PyAPI_FUNC(PyObject *) PyCodec_BackslashReplaceErrors(PyObject *exc); +PyObject * PyCodec_BackslashReplaceErrors(PyObject *exc); #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 /* replace the unicode encode error with backslash escapes (\N, \x, \u and \U) */ -PyAPI_FUNC(PyObject *) PyCodec_NameReplaceErrors(PyObject *exc); +PyObject * PyCodec_NameReplaceErrors(PyObject *exc); #endif #ifndef Py_LIMITED_API -PyAPI_DATA(const char *) Py_hexdigits; +extern const char * Py_hexdigits; #endif COSMOPOLITAN_C_END_ diff --git a/third_party/python/Include/compile.h b/third_party/python/Include/compile.h index 6a76013c0..845b3bcf6 100644 --- a/third_party/python/Include/compile.h +++ b/third_party/python/Include/compile.h @@ -1,6 +1,8 @@ #ifndef Py_COMPILE_H #define Py_COMPILE_H #include "third_party/python/Include/code.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pythonrun.h" COSMOPOLITAN_C_START_ #define Py_single_input 256 @@ -12,7 +14,7 @@ COSMOPOLITAN_C_START_ /* Public interface */ struct _node; /* Declare the existence of this type */ -PyAPI_FUNC(PyCodeObject *) PyNode_Compile(struct _node *, const char *); +PyCodeObject * PyNode_Compile(struct _node *, const char *); /* Future feature support */ @@ -33,32 +35,32 @@ typedef struct { struct _mod; /* Declare the existence of this type */ #define PyAST_Compile(mod, s, f, ar) PyAST_CompileEx(mod, s, f, -1, ar) -PyAPI_FUNC(PyCodeObject *) PyAST_CompileEx( +PyCodeObject * PyAST_CompileEx( struct _mod *mod, const char *filename, /* decoded from the filesystem encoding */ PyCompilerFlags *flags, int optimize, PyArena *arena); -PyAPI_FUNC(PyCodeObject *) PyAST_CompileObject( +PyCodeObject * PyAST_CompileObject( struct _mod *mod, PyObject *filename, PyCompilerFlags *flags, int optimize, PyArena *arena); -PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromAST( +PyFutureFeatures * PyFuture_FromAST( struct _mod * mod, const char *filename /* decoded from the filesystem encoding */ ); -PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromASTObject( +PyFutureFeatures * PyFuture_FromASTObject( struct _mod * mod, PyObject *filename ); /* _Py_Mangle is defined in compile.c */ -PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name); +PyObject* _Py_Mangle(PyObject *p, PyObject *name); #define PY_INVALID_STACK_EFFECT INT_MAX -PyAPI_FUNC(int) PyCompile_OpcodeStackEffect(int opcode, int oparg); +int PyCompile_OpcodeStackEffect(int opcode, int oparg); #endif /* !Py_LIMITED_API */ COSMOPOLITAN_C_END_ diff --git a/third_party/python/Include/complexobject.h b/third_party/python/Include/complexobject.h index 0377f9899..8cca115c0 100644 --- a/third_party/python/Include/complexobject.h +++ b/third_party/python/Include/complexobject.h @@ -1,5 +1,7 @@ #ifndef Py_COMPLEXOBJECT_H #define Py_COMPLEXOBJECT_H +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/unicodeobject.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -11,13 +13,13 @@ typedef struct { /* Operations on complex numbers from complexmodule.c */ -PyAPI_FUNC(Py_complex) _Py_c_sum(Py_complex, Py_complex); -PyAPI_FUNC(Py_complex) _Py_c_diff(Py_complex, Py_complex); -PyAPI_FUNC(Py_complex) _Py_c_neg(Py_complex); -PyAPI_FUNC(Py_complex) _Py_c_prod(Py_complex, Py_complex); -PyAPI_FUNC(Py_complex) _Py_c_quot(Py_complex, Py_complex); -PyAPI_FUNC(Py_complex) _Py_c_pow(Py_complex, Py_complex); -PyAPI_FUNC(double) _Py_c_abs(Py_complex); +Py_complex _Py_c_sum(Py_complex, Py_complex); +Py_complex _Py_c_diff(Py_complex, Py_complex); +Py_complex _Py_c_neg(Py_complex); +Py_complex _Py_c_prod(Py_complex, Py_complex); +Py_complex _Py_c_quot(Py_complex, Py_complex); +Py_complex _Py_c_pow(Py_complex, Py_complex); +double _Py_c_abs(Py_complex); #endif /* Complex object interface */ @@ -33,26 +35,26 @@ typedef struct { } PyComplexObject; #endif -PyAPI_DATA(PyTypeObject) PyComplex_Type; +extern PyTypeObject PyComplex_Type; #define PyComplex_Check(op) PyObject_TypeCheck(op, &PyComplex_Type) #define PyComplex_CheckExact(op) (Py_TYPE(op) == &PyComplex_Type) #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) PyComplex_FromCComplex(Py_complex); +PyObject * PyComplex_FromCComplex(Py_complex); #endif -PyAPI_FUNC(PyObject *) PyComplex_FromDoubles(double real, double imag); +PyObject * PyComplex_FromDoubles(double real, double imag); -PyAPI_FUNC(double) PyComplex_RealAsDouble(PyObject *op); -PyAPI_FUNC(double) PyComplex_ImagAsDouble(PyObject *op); +double PyComplex_RealAsDouble(PyObject *op); +double PyComplex_ImagAsDouble(PyObject *op); #ifndef Py_LIMITED_API -PyAPI_FUNC(Py_complex) PyComplex_AsCComplex(PyObject *op); +Py_complex PyComplex_AsCComplex(PyObject *op); #endif /* Format the object based on the format_spec, as defined in PEP 3101 (Advanced String Formatting). */ #ifndef Py_LIMITED_API -PyAPI_FUNC(int) _PyComplex_FormatAdvancedWriter( +int _PyComplex_FormatAdvancedWriter( _PyUnicodeWriter *writer, PyObject *obj, PyObject *format_spec, diff --git a/third_party/python/Include/datetime.h b/third_party/python/Include/datetime.h index 297cbcdd0..d1f11b34a 100644 --- a/third_party/python/Include/datetime.h +++ b/third_party/python/Include/datetime.h @@ -1,6 +1,7 @@ #ifndef Py_LIMITED_API #ifndef DATETIME_H #define DATETIME_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ diff --git a/third_party/python/Include/descrobject.h b/third_party/python/Include/descrobject.h index 52e5cc016..bc917eba4 100644 --- a/third_party/python/Include/descrobject.h +++ b/third_party/python/Include/descrobject.h @@ -1,5 +1,8 @@ #ifndef Py_DESCROBJECT_H #define Py_DESCROBJECT_H +#include "third_party/python/Include/methodobject.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyport.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -70,34 +73,34 @@ typedef struct { } PyWrapperDescrObject; #endif /* Py_LIMITED_API */ -PyAPI_DATA(PyTypeObject) PyClassMethodDescr_Type; -PyAPI_DATA(PyTypeObject) PyGetSetDescr_Type; -PyAPI_DATA(PyTypeObject) PyMemberDescr_Type; -PyAPI_DATA(PyTypeObject) PyMethodDescr_Type; -PyAPI_DATA(PyTypeObject) PyWrapperDescr_Type; -PyAPI_DATA(PyTypeObject) PyDictProxy_Type; +extern PyTypeObject PyClassMethodDescr_Type; +extern PyTypeObject PyGetSetDescr_Type; +extern PyTypeObject PyMemberDescr_Type; +extern PyTypeObject PyMethodDescr_Type; +extern PyTypeObject PyWrapperDescr_Type; +extern PyTypeObject PyDictProxy_Type; #ifndef Py_LIMITED_API -PyAPI_DATA(PyTypeObject) _PyMethodWrapper_Type; +extern PyTypeObject _PyMethodWrapper_Type; #endif /* Py_LIMITED_API */ -PyAPI_FUNC(PyObject *) PyDescr_NewMethod(PyTypeObject *, PyMethodDef *); -PyAPI_FUNC(PyObject *) PyDescr_NewClassMethod(PyTypeObject *, PyMethodDef *); +PyObject * PyDescr_NewMethod(PyTypeObject *, PyMethodDef *); +PyObject * PyDescr_NewClassMethod(PyTypeObject *, PyMethodDef *); struct PyMemberDef; /* forward declaration for following prototype */ -PyAPI_FUNC(PyObject *) PyDescr_NewMember(PyTypeObject *, +PyObject * PyDescr_NewMember(PyTypeObject *, struct PyMemberDef *); -PyAPI_FUNC(PyObject *) PyDescr_NewGetSet(PyTypeObject *, +PyObject * PyDescr_NewGetSet(PyTypeObject *, struct PyGetSetDef *); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) PyDescr_NewWrapper(PyTypeObject *, +PyObject * PyDescr_NewWrapper(PyTypeObject *, struct wrapperbase *, void *); #define PyDescr_IsData(d) (Py_TYPE(d)->tp_descr_set != NULL) #endif -PyAPI_FUNC(PyObject *) PyDictProxy_New(PyObject *); -PyAPI_FUNC(PyObject *) PyWrapper_New(PyObject *, PyObject *); +PyObject * PyDictProxy_New(PyObject *); +PyObject * PyWrapper_New(PyObject *, PyObject *); -PyAPI_DATA(PyTypeObject) PyProperty_Type; +extern PyTypeObject PyProperty_Type; COSMOPOLITAN_C_END_ #endif /* !Py_DESCROBJECT_H */ diff --git a/third_party/python/Include/dictobject.h b/third_party/python/Include/dictobject.h index f7da9da57..c649f213a 100644 --- a/third_party/python/Include/dictobject.h +++ b/third_party/python/Include/dictobject.h @@ -1,5 +1,6 @@ #ifndef Py_DICTOBJECT_H #define Py_DICTOBJECT_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -45,13 +46,13 @@ typedef struct { #endif /* Py_LIMITED_API */ -PyAPI_DATA(PyTypeObject) PyDict_Type; -PyAPI_DATA(PyTypeObject) PyDictIterKey_Type; -PyAPI_DATA(PyTypeObject) PyDictIterValue_Type; -PyAPI_DATA(PyTypeObject) PyDictIterItem_Type; -PyAPI_DATA(PyTypeObject) PyDictKeys_Type; -PyAPI_DATA(PyTypeObject) PyDictItems_Type; -PyAPI_DATA(PyTypeObject) PyDictValues_Type; +extern PyTypeObject PyDict_Type; +extern PyTypeObject PyDictIterKey_Type; +extern PyTypeObject PyDictIterValue_Type; +extern PyTypeObject PyDictIterItem_Type; +extern PyTypeObject PyDictKeys_Type; +extern PyTypeObject PyDictItems_Type; +extern PyTypeObject PyDictValues_Type; #define PyDict_Check(op) \ PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS) @@ -64,71 +65,71 @@ PyAPI_DATA(PyTypeObject) PyDictValues_Type; (PyDictKeys_Check(op) || PyDictItems_Check(op)) -PyAPI_FUNC(PyObject *) PyDict_New(void); -PyAPI_FUNC(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key); +PyObject * PyDict_New(void); +PyObject * PyDict_GetItem(PyObject *mp, PyObject *key); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) _PyDict_GetItem_KnownHash(PyObject *mp, PyObject *key, +PyObject * _PyDict_GetItem_KnownHash(PyObject *mp, PyObject *key, Py_hash_t hash); #endif -PyAPI_FUNC(PyObject *) PyDict_GetItemWithError(PyObject *mp, PyObject *key); +PyObject * PyDict_GetItemWithError(PyObject *mp, PyObject *key); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) _PyDict_GetItemIdWithError(PyObject *dp, +PyObject * _PyDict_GetItemIdWithError(PyObject *dp, struct _Py_Identifier *key); -PyAPI_FUNC(PyObject *) PyDict_SetDefault( +PyObject * PyDict_SetDefault( PyObject *mp, PyObject *key, PyObject *defaultobj); #endif -PyAPI_FUNC(int) PyDict_SetItem(PyObject *mp, PyObject *key, PyObject *item); +int PyDict_SetItem(PyObject *mp, PyObject *key, PyObject *item); #ifndef Py_LIMITED_API -PyAPI_FUNC(int) _PyDict_SetItem_KnownHash(PyObject *mp, PyObject *key, +int _PyDict_SetItem_KnownHash(PyObject *mp, PyObject *key, PyObject *item, Py_hash_t hash); #endif -PyAPI_FUNC(int) PyDict_DelItem(PyObject *mp, PyObject *key); +int PyDict_DelItem(PyObject *mp, PyObject *key); #ifndef Py_LIMITED_API -PyAPI_FUNC(int) _PyDict_DelItem_KnownHash(PyObject *mp, PyObject *key, +int _PyDict_DelItem_KnownHash(PyObject *mp, PyObject *key, Py_hash_t hash); -PyAPI_FUNC(int) _PyDict_DelItemIf(PyObject *mp, PyObject *key, +int _PyDict_DelItemIf(PyObject *mp, PyObject *key, int (*predicate)(PyObject *value)); #endif -PyAPI_FUNC(void) PyDict_Clear(PyObject *mp); -PyAPI_FUNC(int) PyDict_Next( +void PyDict_Clear(PyObject *mp); +int PyDict_Next( PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value); #ifndef Py_LIMITED_API PyDictKeysObject *_PyDict_NewKeysForClass(void); -PyAPI_FUNC(PyObject *) PyObject_GenericGetDict(PyObject *, void *); -PyAPI_FUNC(int) _PyDict_Next( +PyObject * PyObject_GenericGetDict(PyObject *, void *); +int _PyDict_Next( PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value, Py_hash_t *hash); PyObject *_PyDictView_New(PyObject *, PyTypeObject *); #endif -PyAPI_FUNC(PyObject *) PyDict_Keys(PyObject *mp); -PyAPI_FUNC(PyObject *) PyDict_Values(PyObject *mp); -PyAPI_FUNC(PyObject *) PyDict_Items(PyObject *mp); -PyAPI_FUNC(Py_ssize_t) PyDict_Size(PyObject *mp); -PyAPI_FUNC(PyObject *) PyDict_Copy(PyObject *mp); -PyAPI_FUNC(int) PyDict_Contains(PyObject *mp, PyObject *key); +PyObject * PyDict_Keys(PyObject *mp); +PyObject * PyDict_Values(PyObject *mp); +PyObject * PyDict_Items(PyObject *mp); +Py_ssize_t PyDict_Size(PyObject *mp); +PyObject * PyDict_Copy(PyObject *mp); +int PyDict_Contains(PyObject *mp, PyObject *key); #ifndef Py_LIMITED_API -PyAPI_FUNC(int) _PyDict_Contains(PyObject *mp, PyObject *key, Py_hash_t hash); -PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused); -PyAPI_FUNC(void) _PyDict_MaybeUntrack(PyObject *mp); -PyAPI_FUNC(int) _PyDict_HasOnlyStringKeys(PyObject *mp); +int _PyDict_Contains(PyObject *mp, PyObject *key, Py_hash_t hash); +PyObject * _PyDict_NewPresized(Py_ssize_t minused); +void _PyDict_MaybeUntrack(PyObject *mp); +int _PyDict_HasOnlyStringKeys(PyObject *mp); Py_ssize_t _PyDict_KeysSize(PyDictKeysObject *keys); Py_ssize_t _PyDict_SizeOf(PyDictObject *); -PyAPI_FUNC(PyObject *) _PyDict_Pop(PyObject *, PyObject *, PyObject *); +PyObject * _PyDict_Pop(PyObject *, PyObject *, PyObject *); PyObject *_PyDict_Pop_KnownHash(PyObject *, PyObject *, Py_hash_t, PyObject *); PyObject *_PyDict_FromKeys(PyObject *, PyObject *, PyObject *); #define _PyDict_HasSplitTable(d) ((d)->ma_values != NULL) -PyAPI_FUNC(int) PyDict_ClearFreeList(void); +int PyDict_ClearFreeList(void); #endif /* PyDict_Update(mp, other) is equivalent to PyDict_Merge(mp, other, 1). */ -PyAPI_FUNC(int) PyDict_Update(PyObject *mp, PyObject *other); +int PyDict_Update(PyObject *mp, PyObject *other); /* PyDict_Merge updates/merges from a mapping object (an object that supports PyMapping_Keys() and PyObject_GetItem()). If override is true, the last occurrence of a key wins, else the first. The Python dict.update(other) is equivalent to PyDict_Merge(dict, other, 1). */ -PyAPI_FUNC(int) PyDict_Merge(PyObject *mp, +int PyDict_Merge(PyObject *mp, PyObject *other, int override); @@ -138,8 +139,8 @@ PyAPI_FUNC(int) PyDict_Merge(PyObject *mp, of a key wins, if override is 2, a KeyError with conflicting key as argument is raised. */ -PyAPI_FUNC(int) _PyDict_MergeEx(PyObject *mp, PyObject *other, int override); -PyAPI_FUNC(PyObject *) _PyDictView_Intersect(PyObject* self, PyObject *other); +int _PyDict_MergeEx(PyObject *mp, PyObject *other, int override); +PyObject * _PyDictView_Intersect(PyObject* self, PyObject *other); #endif /* PyDict_MergeFromSeq2 updates/merges from an iterable object producing @@ -147,23 +148,23 @@ PyAPI_FUNC(PyObject *) _PyDictView_Intersect(PyObject* self, PyObject *other); of a key wins, else the first. The Python dict constructor dict(seq2) is equivalent to dict={}; PyDict_MergeFromSeq(dict, seq2, 1). */ -PyAPI_FUNC(int) PyDict_MergeFromSeq2(PyObject *d, +int PyDict_MergeFromSeq2(PyObject *d, PyObject *seq2, int override); -PyAPI_FUNC(PyObject *) PyDict_GetItemString(PyObject *dp, const char *key); +PyObject * PyDict_GetItemString(PyObject *dp, const char *key); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) _PyDict_GetItemId(PyObject *dp, struct _Py_Identifier *key); +PyObject * _PyDict_GetItemId(PyObject *dp, struct _Py_Identifier *key); #endif /* !Py_LIMITED_API */ -PyAPI_FUNC(int) PyDict_SetItemString(PyObject *dp, const char *key, PyObject *item); +int PyDict_SetItemString(PyObject *dp, const char *key, PyObject *item); #ifndef Py_LIMITED_API -PyAPI_FUNC(int) _PyDict_SetItemId(PyObject *dp, struct _Py_Identifier *key, PyObject *item); +int _PyDict_SetItemId(PyObject *dp, struct _Py_Identifier *key, PyObject *item); #endif /* !Py_LIMITED_API */ -PyAPI_FUNC(int) PyDict_DelItemString(PyObject *dp, const char *key); +int PyDict_DelItemString(PyObject *dp, const char *key); #ifndef Py_LIMITED_API -PyAPI_FUNC(int) _PyDict_DelItemId(PyObject *mp, struct _Py_Identifier *key); -PyAPI_FUNC(void) _PyDict_DebugMallocStats(FILE *out); +int _PyDict_DelItemId(PyObject *mp, struct _Py_Identifier *key); +void _PyDict_DebugMallocStats(FILE *out); int _PyObjectDict_SetItem(PyTypeObject *tp, PyObject **dictptr, PyObject *name, PyObject *value); PyObject *_PyDict_LoadGlobal(PyDictObject *, PyDictObject *, PyObject *); diff --git a/third_party/python/Include/dtoa.h b/third_party/python/Include/dtoa.h index 4646dc94c..0315d4f91 100644 --- a/third_party/python/Include/dtoa.h +++ b/third_party/python/Include/dtoa.h @@ -3,12 +3,12 @@ COSMOPOLITAN_C_START_ /* clang-format off */ -PyAPI_FUNC(double) _Py_dg_strtod(const char *str, char **ptr); -PyAPI_FUNC(char *) _Py_dg_dtoa(double d, int mode, int ndigits, +double _Py_dg_strtod(const char *str, char **ptr); +char * _Py_dg_dtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve); -PyAPI_FUNC(void) _Py_dg_freedtoa(char *s); -PyAPI_FUNC(double) _Py_dg_stdnan(int sign); -PyAPI_FUNC(double) _Py_dg_infinity(int sign); +void _Py_dg_freedtoa(char *s); +double _Py_dg_stdnan(int sign); +double _Py_dg_infinity(int sign); COSMOPOLITAN_C_END_ #endif diff --git a/third_party/python/Include/dynamic_annotations.h b/third_party/python/Include/dynamic_annotations.h index 67ba5f2d0..4d3b55fe2 100644 --- a/third_party/python/Include/dynamic_annotations.h +++ b/third_party/python/Include/dynamic_annotations.h @@ -1,3 +1,9 @@ +#ifndef __DYNAMIC_ANNOTATIONS_H__ +#define __DYNAMIC_ANNOTATIONS_H__ +#ifndef DYNAMIC_ANNOTATIONS_ENABLED +#define DYNAMIC_ANNOTATIONS_ENABLED 0 +#endif +#if DYNAMIC_ANNOTATIONS_ENABLED != 0 /* clang-format off */ /* Copyright (c) 2008-2009, Google Inc. @@ -55,15 +61,6 @@ Macros are defined as calls to non-inlinable empty functions that are intercepted by Valgrind. */ -#ifndef __DYNAMIC_ANNOTATIONS_H__ -#define __DYNAMIC_ANNOTATIONS_H__ - -#ifndef DYNAMIC_ANNOTATIONS_ENABLED -# define DYNAMIC_ANNOTATIONS_ENABLED 0 -#endif - -#if DYNAMIC_ANNOTATIONS_ENABLED != 0 - /* ------------------------------------------------------------- Annotations useful when implementing condition variables such as CondVar, using conditional critical sections (Await/LockWhen) and when constructing @@ -324,54 +321,8 @@ #define _Py_ANNOTATE_FLUSH_STATE() \ AnnotateFlushState(__FILE__, __LINE__) - -#else /* DYNAMIC_ANNOTATIONS_ENABLED == 0 */ - -#define _Py_ANNOTATE_RWLOCK_CREATE(lock) /* empty */ -#define _Py_ANNOTATE_RWLOCK_DESTROY(lock) /* empty */ -#define _Py_ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) /* empty */ -#define _Py_ANNOTATE_RWLOCK_RELEASED(lock, is_w) /* empty */ -#define _Py_ANNOTATE_BARRIER_INIT(barrier, count, reinitialization_allowed) /* */ -#define _Py_ANNOTATE_BARRIER_WAIT_BEFORE(barrier) /* empty */ -#define _Py_ANNOTATE_BARRIER_WAIT_AFTER(barrier) /* empty */ -#define _Py_ANNOTATE_BARRIER_DESTROY(barrier) /* empty */ -#define _Py_ANNOTATE_CONDVAR_LOCK_WAIT(cv, lock) /* empty */ -#define _Py_ANNOTATE_CONDVAR_WAIT(cv) /* empty */ -#define _Py_ANNOTATE_CONDVAR_SIGNAL(cv) /* empty */ -#define _Py_ANNOTATE_CONDVAR_SIGNAL_ALL(cv) /* empty */ -#define _Py_ANNOTATE_HAPPENS_BEFORE(obj) /* empty */ -#define _Py_ANNOTATE_HAPPENS_AFTER(obj) /* empty */ -#define _Py_ANNOTATE_PUBLISH_MEMORY_RANGE(address, size) /* empty */ -#define _Py_ANNOTATE_UNPUBLISH_MEMORY_RANGE(address, size) /* empty */ -#define _Py_ANNOTATE_SWAP_MEMORY_RANGE(address, size) /* empty */ -#define _Py_ANNOTATE_PCQ_CREATE(pcq) /* empty */ -#define _Py_ANNOTATE_PCQ_DESTROY(pcq) /* empty */ -#define _Py_ANNOTATE_PCQ_PUT(pcq) /* empty */ -#define _Py_ANNOTATE_PCQ_GET(pcq) /* empty */ -#define _Py_ANNOTATE_NEW_MEMORY(address, size) /* empty */ -#define _Py_ANNOTATE_EXPECT_RACE(address, description) /* empty */ -#define _Py_ANNOTATE_BENIGN_RACE(address, description) /* empty */ -#define _Py_ANNOTATE_BENIGN_RACE_SIZED(address, size, description) /* empty */ -#define _Py_ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX(mu) /* empty */ -#define _Py_ANNOTATE_MUTEX_IS_USED_AS_CONDVAR(mu) /* empty */ -#define _Py_ANNOTATE_TRACE_MEMORY(arg) /* empty */ -#define _Py_ANNOTATE_THREAD_NAME(name) /* empty */ -#define _Py_ANNOTATE_IGNORE_READS_BEGIN() /* empty */ -#define _Py_ANNOTATE_IGNORE_READS_END() /* empty */ -#define _Py_ANNOTATE_IGNORE_WRITES_BEGIN() /* empty */ -#define _Py_ANNOTATE_IGNORE_WRITES_END() /* empty */ -#define _Py_ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() /* empty */ -#define _Py_ANNOTATE_IGNORE_READS_AND_WRITES_END() /* empty */ -#define _Py_ANNOTATE_IGNORE_SYNC_BEGIN() /* empty */ -#define _Py_ANNOTATE_IGNORE_SYNC_END() /* empty */ -#define _Py_ANNOTATE_ENABLE_RACE_DETECTION(enable) /* empty */ -#define _Py_ANNOTATE_NO_OP(arg) /* empty */ -#define _Py_ANNOTATE_FLUSH_STATE() /* empty */ - -#endif /* DYNAMIC_ANNOTATIONS_ENABLED */ - -/* Use the macros above rather than using these functions directly. */ COSMOPOLITAN_C_START_ + void AnnotateRWLockCreate(const char *file, int line, const volatile void *lock); void AnnotateRWLockDestroy(const char *file, int line, @@ -457,24 +408,22 @@ int RunningOnValgrind(void); COSMOPOLITAN_C_END_ -#if DYNAMIC_ANNOTATIONS_ENABLED != 0 && defined(__cplusplus) - - /* _Py_ANNOTATE_UNPROTECTED_READ is the preferred way to annotate racey reads. - - Instead of doing - _Py_ANNOTATE_IGNORE_READS_BEGIN(); - ... = x; - _Py_ANNOTATE_IGNORE_READS_END(); - one can use - ... = _Py_ANNOTATE_UNPROTECTED_READ(x); */ - template - inline T _Py_ANNOTATE_UNPROTECTED_READ(const volatile T &x) { - _Py_ANNOTATE_IGNORE_READS_BEGIN(); - T res = x; - _Py_ANNOTATE_IGNORE_READS_END(); - return res; - } - /* Apply _Py_ANNOTATE_BENIGN_RACE_SIZED to a static variable. */ +#ifdef __cplusplus +/* _Py_ANNOTATE_UNPROTECTED_READ is the preferred way to annotate racey reads. + Instead of doing + _Py_ANNOTATE_IGNORE_READS_BEGIN(); + ... = x; + _Py_ANNOTATE_IGNORE_READS_END(); + one can use + ... = _Py_ANNOTATE_UNPROTECTED_READ(x); */ +template +inline T _Py_ANNOTATE_UNPROTECTED_READ(const volatile T &x) { + _Py_ANNOTATE_IGNORE_READS_BEGIN(); + T res = x; + _Py_ANNOTATE_IGNORE_READS_END(); + return res; +} +/* Apply _Py_ANNOTATE_BENIGN_RACE_SIZED to a static variable. */ #define _Py_ANNOTATE_BENIGN_RACE_STATIC(static_var, description) \ namespace { \ class static_var ## _annotator { \ @@ -487,11 +436,50 @@ COSMOPOLITAN_C_END_ }; \ static static_var ## _annotator the ## static_var ## _annotator;\ } -#else /* DYNAMIC_ANNOTATIONS_ENABLED == 0 */ +#endif /* __cplusplus */ +#else /* DYNAMIC_ANNOTATIONS_ENABLED == 0 */ +#define _Py_ANNOTATE_RWLOCK_CREATE(lock) +#define _Py_ANNOTATE_RWLOCK_DESTROY(lock) +#define _Py_ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) +#define _Py_ANNOTATE_RWLOCK_RELEASED(lock, is_w) +#define _Py_ANNOTATE_BARRIER_INIT(barrier, count, reinitialization_allowed) /* */ +#define _Py_ANNOTATE_BARRIER_WAIT_BEFORE(barrier) +#define _Py_ANNOTATE_BARRIER_WAIT_AFTER(barrier) +#define _Py_ANNOTATE_BARRIER_DESTROY(barrier) +#define _Py_ANNOTATE_CONDVAR_LOCK_WAIT(cv, lock) +#define _Py_ANNOTATE_CONDVAR_WAIT(cv) +#define _Py_ANNOTATE_CONDVAR_SIGNAL(cv) +#define _Py_ANNOTATE_CONDVAR_SIGNAL_ALL(cv) +#define _Py_ANNOTATE_HAPPENS_BEFORE(obj) +#define _Py_ANNOTATE_HAPPENS_AFTER(obj) +#define _Py_ANNOTATE_PUBLISH_MEMORY_RANGE(address, size) +#define _Py_ANNOTATE_UNPUBLISH_MEMORY_RANGE(address, size) +#define _Py_ANNOTATE_SWAP_MEMORY_RANGE(address, size) +#define _Py_ANNOTATE_PCQ_CREATE(pcq) +#define _Py_ANNOTATE_PCQ_DESTROY(pcq) +#define _Py_ANNOTATE_PCQ_PUT(pcq) +#define _Py_ANNOTATE_PCQ_GET(pcq) +#define _Py_ANNOTATE_NEW_MEMORY(address, size) +#define _Py_ANNOTATE_EXPECT_RACE(address, description) +#define _Py_ANNOTATE_BENIGN_RACE(address, description) +#define _Py_ANNOTATE_BENIGN_RACE_SIZED(address, size, description) +#define _Py_ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX(mu) +#define _Py_ANNOTATE_MUTEX_IS_USED_AS_CONDVAR(mu) +#define _Py_ANNOTATE_TRACE_MEMORY(arg) +#define _Py_ANNOTATE_THREAD_NAME(name) +#define _Py_ANNOTATE_IGNORE_READS_BEGIN() +#define _Py_ANNOTATE_IGNORE_READS_END() +#define _Py_ANNOTATE_IGNORE_WRITES_BEGIN() +#define _Py_ANNOTATE_IGNORE_WRITES_END() +#define _Py_ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() +#define _Py_ANNOTATE_IGNORE_READS_AND_WRITES_END() +#define _Py_ANNOTATE_IGNORE_SYNC_BEGIN() +#define _Py_ANNOTATE_IGNORE_SYNC_END() +#define _Py_ANNOTATE_ENABLE_RACE_DETECTION(enable) +#define _Py_ANNOTATE_NO_OP(arg) +#define _Py_ANNOTATE_FLUSH_STATE() #define _Py_ANNOTATE_UNPROTECTED_READ(x) (x) -#define _Py_ANNOTATE_BENIGN_RACE_STATIC(static_var, description) /* empty */ - -#endif /* DYNAMIC_ANNOTATIONS_ENABLED */ - +#define _Py_ANNOTATE_BENIGN_RACE_STATIC(static_var, description) +#endif /* DYNAMIC_ANNOTATIONS_ENABLED */ #endif /* __DYNAMIC_ANNOTATIONS_H__ */ diff --git a/third_party/python/Include/enumobject.h b/third_party/python/Include/enumobject.h index ededaea41..dc1c8cebf 100644 --- a/third_party/python/Include/enumobject.h +++ b/third_party/python/Include/enumobject.h @@ -1,10 +1,11 @@ #ifndef Py_ENUMOBJECT_H #define Py_ENUMOBJECT_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ -PyAPI_DATA(PyTypeObject) PyEnum_Type; -PyAPI_DATA(PyTypeObject) PyReversed_Type; +extern PyTypeObject PyEnum_Type; +extern PyTypeObject PyReversed_Type; COSMOPOLITAN_C_END_ #endif /* !Py_ENUMOBJECT_H */ diff --git a/third_party/python/Include/eval.h b/third_party/python/Include/eval.h index 65c1ccac7..3fccde7c5 100644 --- a/third_party/python/Include/eval.h +++ b/third_party/python/Include/eval.h @@ -1,11 +1,12 @@ #ifndef Py_EVAL_H #define Py_EVAL_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ -PyAPI_FUNC(PyObject *) PyEval_EvalCode(PyObject *, PyObject *, PyObject *); +PyObject * PyEval_EvalCode(PyObject *, PyObject *, PyObject *); -PyAPI_FUNC(PyObject *) PyEval_EvalCodeEx(PyObject *co, +PyObject * PyEval_EvalCodeEx(PyObject *co, PyObject *globals, PyObject *locals, PyObject **args, int argc, @@ -14,7 +15,7 @@ PyAPI_FUNC(PyObject *) PyEval_EvalCodeEx(PyObject *co, PyObject *kwdefs, PyObject *closure); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) _PyEval_CallTracing(PyObject *func, PyObject *args); +PyObject * _PyEval_CallTracing(PyObject *func, PyObject *args); #endif COSMOPOLITAN_C_END_ diff --git a/third_party/python/Include/fileobject.h b/third_party/python/Include/fileobject.h index 2056b02dc..36e0e0f72 100644 --- a/third_party/python/Include/fileobject.h +++ b/third_party/python/Include/fileobject.h @@ -1,37 +1,38 @@ #ifndef Py_FILEOBJECT_H #define Py_FILEOBJECT_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ #define PY_STDIOTEXTMODE "b" -PyAPI_FUNC(PyObject *) PyFile_FromFd(int, const char *, const char *, int, +PyObject * PyFile_FromFd(int, const char *, const char *, int, const char *, const char *, const char *, int); -PyAPI_FUNC(PyObject *) PyFile_GetLine(PyObject *, int); -PyAPI_FUNC(int) PyFile_WriteObject(PyObject *, PyObject *, int); -PyAPI_FUNC(int) PyFile_WriteString(const char *, PyObject *); -PyAPI_FUNC(int) PyObject_AsFileDescriptor(PyObject *); +PyObject * PyFile_GetLine(PyObject *, int); +int PyFile_WriteObject(PyObject *, PyObject *, int); +int PyFile_WriteString(const char *, PyObject *); +int PyObject_AsFileDescriptor(PyObject *); #ifndef Py_LIMITED_API -PyAPI_FUNC(char *) Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *); +char * Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *); #endif /* The default encoding used by the platform file system APIs If non-NULL, this is different than the default encoding for strings */ -PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding; +extern const char * Py_FileSystemDefaultEncoding; #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03060000 -PyAPI_DATA(const char *) Py_FileSystemDefaultEncodeErrors; +extern const char * Py_FileSystemDefaultEncodeErrors; #endif -PyAPI_DATA(int) Py_HasFileSystemDefaultEncoding; +extern int Py_HasFileSystemDefaultEncoding; /* Internal API The std printer acts as a preliminary sys.stderr until the new io infrastructure is in place. */ #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) PyFile_NewStdPrinter(int); -PyAPI_DATA(PyTypeObject) PyStdPrinter_Type; +PyObject * PyFile_NewStdPrinter(int); +extern PyTypeObject PyStdPrinter_Type; #endif /* Py_LIMITED_API */ /* A routine to check if a file descriptor can be select()-ed. */ diff --git a/third_party/python/Include/fileutils.h b/third_party/python/Include/fileutils.h index 170711b8a..9c93a58e3 100644 --- a/third_party/python/Include/fileutils.h +++ b/third_party/python/Include/fileutils.h @@ -1,31 +1,33 @@ #ifndef Py_FILEUTILS_H #define Py_FILEUTILS_H +#include "libc/calls/struct/stat.h" +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 -PyAPI_FUNC(wchar_t *) Py_DecodeLocale( +wchar_t * Py_DecodeLocale( const char *arg, size_t *size); -PyAPI_FUNC(char*) Py_EncodeLocale( +char* Py_EncodeLocale( const wchar_t *text, size_t *error_pos); #endif #ifndef Py_LIMITED_API -PyAPI_FUNC(wchar_t *) _Py_DecodeLocaleEx( +wchar_t * _Py_DecodeLocaleEx( const char *arg, size_t *size, int current_locale); -PyAPI_FUNC(char*) _Py_EncodeLocaleEx( +char* _Py_EncodeLocaleEx( const wchar_t *text, size_t *error_pos, int current_locale); -PyAPI_FUNC(PyObject *) _Py_device_encoding(int); +PyObject * _Py_device_encoding(int); #if defined(MS_WINDOWS) || defined(__APPLE__) /* On Windows, the count parameter of read() is an int (bpo-9015, bpo-9611). @@ -62,88 +64,88 @@ struct _Py_stat_struct { # define _Py_stat_struct stat #endif -PyAPI_FUNC(int) _Py_fstat( +int _Py_fstat( int fd, struct _Py_stat_struct *status); -PyAPI_FUNC(int) _Py_fstat_noraise( +int _Py_fstat_noraise( int fd, struct _Py_stat_struct *status); -PyAPI_FUNC(int) _Py_stat( +int _Py_stat( PyObject *path, struct stat *status); -PyAPI_FUNC(int) _Py_open( +int _Py_open( const char *pathname, int flags); -PyAPI_FUNC(int) _Py_open_noraise( +int _Py_open_noraise( const char *pathname, int flags); -PyAPI_FUNC(FILE *) _Py_wfopen( +FILE * _Py_wfopen( const wchar_t *path, const wchar_t *mode); -PyAPI_FUNC(FILE*) _Py_fopen( +FILE* _Py_fopen( const char *pathname, const char *mode); -PyAPI_FUNC(FILE*) _Py_fopen_obj( +FILE* _Py_fopen_obj( PyObject *path, const char *mode); -PyAPI_FUNC(Py_ssize_t) _Py_read( +Py_ssize_t _Py_read( int fd, void *buf, size_t count); -PyAPI_FUNC(Py_ssize_t) _Py_write( +Py_ssize_t _Py_write( int fd, const void *buf, size_t count); -PyAPI_FUNC(Py_ssize_t) _Py_write_noraise( +Py_ssize_t _Py_write_noraise( int fd, const void *buf, size_t count); #ifdef HAVE_READLINK -PyAPI_FUNC(int) _Py_wreadlink( +int _Py_wreadlink( const wchar_t *path, wchar_t *buf, size_t bufsiz); #endif #ifdef HAVE_REALPATH -PyAPI_FUNC(wchar_t*) _Py_wrealpath( +wchar_t* _Py_wrealpath( const wchar_t *path, wchar_t *resolved_path, size_t resolved_path_size); #endif -PyAPI_FUNC(wchar_t*) _Py_wgetcwd( +wchar_t* _Py_wgetcwd( wchar_t *buf, size_t size); -PyAPI_FUNC(int) _Py_get_inheritable(int fd); +int _Py_get_inheritable(int fd); -PyAPI_FUNC(int) _Py_set_inheritable(int fd, int inheritable, +int _Py_set_inheritable(int fd, int inheritable, int *atomic_flag_works); -PyAPI_FUNC(int) _Py_set_inheritable_async_safe(int fd, int inheritable, +int _Py_set_inheritable_async_safe(int fd, int inheritable, int *atomic_flag_works); -PyAPI_FUNC(int) _Py_dup(int fd); +int _Py_dup(int fd); #ifndef MS_WINDOWS -PyAPI_FUNC(int) _Py_get_blocking(int fd); +int _Py_get_blocking(int fd); -PyAPI_FUNC(int) _Py_set_blocking(int fd, int blocking); +int _Py_set_blocking(int fd, int blocking); #endif /* !MS_WINDOWS */ -PyAPI_FUNC(int) _Py_GetLocaleconvNumeric( +int _Py_GetLocaleconvNumeric( PyObject **decimal_point, PyObject **thousands_sep, const char **grouping); diff --git a/third_party/python/Include/floatobject.h b/third_party/python/Include/floatobject.h index 4c387204b..3513dd50d 100644 --- a/third_party/python/Include/floatobject.h +++ b/third_party/python/Include/floatobject.h @@ -1,5 +1,7 @@ #ifndef Py_FLOATOBJECT_H #define Py_FLOATOBJECT_H +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/unicodeobject.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -10,7 +12,7 @@ typedef struct { } PyFloatObject; #endif -PyAPI_DATA(PyTypeObject) PyFloat_Type; +extern PyTypeObject PyFloat_Type; #define PyFloat_Check(op) PyObject_TypeCheck(op, &PyFloat_Type) #define PyFloat_CheckExact(op) (Py_TYPE(op) == &PyFloat_Type) @@ -26,19 +28,19 @@ PyAPI_DATA(PyTypeObject) PyFloat_Type; return PyFloat_FromDouble(-Py_HUGE_VAL); \ } while(0) -PyAPI_FUNC(double) PyFloat_GetMax(void); -PyAPI_FUNC(double) PyFloat_GetMin(void); -PyAPI_FUNC(PyObject *) PyFloat_GetInfo(void); +double PyFloat_GetMax(void); +double PyFloat_GetMin(void); +PyObject * PyFloat_GetInfo(void); /* Return Python float from string PyObject. */ -PyAPI_FUNC(PyObject *) PyFloat_FromString(PyObject*); +PyObject * PyFloat_FromString(PyObject*); /* Return Python float from C double. */ -PyAPI_FUNC(PyObject *) PyFloat_FromDouble(double); +PyObject * PyFloat_FromDouble(double); /* Extract C double from Python float. The macro version trades safety for speed. */ -PyAPI_FUNC(double) PyFloat_AsDouble(PyObject *); +double PyFloat_AsDouble(PyObject *); #ifndef Py_LIMITED_API #define PyFloat_AS_DOUBLE(op) (((PyFloatObject *)(op))->ob_fval) #endif @@ -76,18 +78,18 @@ PyAPI_FUNC(double) PyFloat_AsDouble(PyObject *); * 1): What this does is undefined if x is a NaN or infinity. * 2): -0.0 and +0.0 produce the same string. */ -PyAPI_FUNC(int) _PyFloat_Pack2(double x, unsigned char *p, int le); -PyAPI_FUNC(int) _PyFloat_Pack4(double x, unsigned char *p, int le); -PyAPI_FUNC(int) _PyFloat_Pack8(double x, unsigned char *p, int le); +int _PyFloat_Pack2(double x, unsigned char *p, int le); +int _PyFloat_Pack4(double x, unsigned char *p, int le); +int _PyFloat_Pack8(double x, unsigned char *p, int le); /* Needed for the old way for marshal to store a floating point number. Returns the string length copied into p, -1 on error. */ -PyAPI_FUNC(int) _PyFloat_Repr(double x, char *p, size_t len); +int _PyFloat_Repr(double x, char *p, size_t len); /* Used to get the important decimal digits of a double */ -PyAPI_FUNC(int) _PyFloat_Digits(char *buf, double v, int *signum); -PyAPI_FUNC(void) _PyFloat_DigitsInit(void); +int _PyFloat_Digits(char *buf, double v, int *signum); +void _PyFloat_DigitsInit(void); /* The unpack routines read 2, 4 or 8 bytes, starting at p. le is a bool * argument, true if the string is in little-endian format (exponent @@ -97,18 +99,18 @@ PyAPI_FUNC(void) _PyFloat_DigitsInit(void); * OverflowError). Note that on a non-IEEE platform this will refuse * to unpack a string that represents a NaN or infinity. */ -PyAPI_FUNC(double) _PyFloat_Unpack2(const unsigned char *p, int le); -PyAPI_FUNC(double) _PyFloat_Unpack4(const unsigned char *p, int le); -PyAPI_FUNC(double) _PyFloat_Unpack8(const unsigned char *p, int le); +double _PyFloat_Unpack2(const unsigned char *p, int le); +double _PyFloat_Unpack4(const unsigned char *p, int le); +double _PyFloat_Unpack8(const unsigned char *p, int le); /* free list api */ -PyAPI_FUNC(int) PyFloat_ClearFreeList(void); +int PyFloat_ClearFreeList(void); -PyAPI_FUNC(void) _PyFloat_DebugMallocStats(FILE* out); +void _PyFloat_DebugMallocStats(FILE* out); /* Format the object based on the format_spec, as defined in PEP 3101 (Advanced String Formatting). */ -PyAPI_FUNC(int) _PyFloat_FormatAdvancedWriter( +int _PyFloat_FormatAdvancedWriter( _PyUnicodeWriter *writer, PyObject *obj, PyObject *format_spec, diff --git a/third_party/python/Include/frameobject.h b/third_party/python/Include/frameobject.h index 25a83042f..4e52a5678 100644 --- a/third_party/python/Include/frameobject.h +++ b/third_party/python/Include/frameobject.h @@ -1,6 +1,9 @@ #ifndef Py_LIMITED_API #ifndef Py_FRAMEOBJECT_H #define Py_FRAMEOBJECT_H +#include "third_party/python/Include/code.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pystate.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -51,38 +54,38 @@ typedef struct _frame { /* Standard object interface */ -PyAPI_DATA(PyTypeObject) PyFrame_Type; +extern PyTypeObject PyFrame_Type; #define PyFrame_Check(op) (Py_TYPE(op) == &PyFrame_Type) -PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *, - PyObject *, PyObject *); +PyFrameObject * PyFrame_New(PyThreadState *, PyCodeObject *, + PyObject *, PyObject *); /* The rest of the interface is specific for frame objects */ /* Block management functions */ -PyAPI_FUNC(void) PyFrame_BlockSetup(PyFrameObject *, int, int, int); -PyAPI_FUNC(PyTryBlock *) PyFrame_BlockPop(PyFrameObject *); +void PyFrame_BlockSetup(PyFrameObject *, int, int, int); +PyTryBlock * PyFrame_BlockPop(PyFrameObject *); /* Extend the value stack */ -PyAPI_FUNC(PyObject **) PyFrame_ExtendStack(PyFrameObject *, int, int); +PyObject ** PyFrame_ExtendStack(PyFrameObject *, int, int); /* Conversions between "fast locals" and locals in dictionary */ -PyAPI_FUNC(void) PyFrame_LocalsToFast(PyFrameObject *, int); +void PyFrame_LocalsToFast(PyFrameObject *, int); -PyAPI_FUNC(int) PyFrame_FastToLocalsWithError(PyFrameObject *f); -PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *); +int PyFrame_FastToLocalsWithError(PyFrameObject *f); +void PyFrame_FastToLocals(PyFrameObject *); -PyAPI_FUNC(int) PyFrame_ClearFreeList(void); +int PyFrame_ClearFreeList(void); -PyAPI_FUNC(void) _PyFrame_DebugMallocStats(FILE *out); +void _PyFrame_DebugMallocStats(FILE *out); /* Return the line of code the frame is currently executing. */ -PyAPI_FUNC(int) PyFrame_GetLineNumber(PyFrameObject *); +int PyFrame_GetLineNumber(PyFrameObject *); COSMOPOLITAN_C_END_ #endif /* !Py_FRAMEOBJECT_H */ diff --git a/third_party/python/Include/funcobject.h b/third_party/python/Include/funcobject.h index bcca715e7..007f7b1d4 100644 --- a/third_party/python/Include/funcobject.h +++ b/third_party/python/Include/funcobject.h @@ -1,6 +1,7 @@ #ifndef Py_LIMITED_API #ifndef Py_FUNCOBJECT_H #define Py_FUNCOBJECT_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -37,32 +38,32 @@ typedef struct { */ } PyFunctionObject; -PyAPI_DATA(PyTypeObject) PyFunction_Type; +extern PyTypeObject PyFunction_Type; #define PyFunction_Check(op) (Py_TYPE(op) == &PyFunction_Type) -PyAPI_FUNC(PyObject *) PyFunction_New(PyObject *, PyObject *); -PyAPI_FUNC(PyObject *) PyFunction_NewWithQualName(PyObject *, PyObject *, PyObject *); -PyAPI_FUNC(PyObject *) PyFunction_GetCode(PyObject *); -PyAPI_FUNC(PyObject *) PyFunction_GetGlobals(PyObject *); -PyAPI_FUNC(PyObject *) PyFunction_GetModule(PyObject *); -PyAPI_FUNC(PyObject *) PyFunction_GetDefaults(PyObject *); -PyAPI_FUNC(int) PyFunction_SetDefaults(PyObject *, PyObject *); -PyAPI_FUNC(PyObject *) PyFunction_GetKwDefaults(PyObject *); -PyAPI_FUNC(int) PyFunction_SetKwDefaults(PyObject *, PyObject *); -PyAPI_FUNC(PyObject *) PyFunction_GetClosure(PyObject *); -PyAPI_FUNC(int) PyFunction_SetClosure(PyObject *, PyObject *); -PyAPI_FUNC(PyObject *) PyFunction_GetAnnotations(PyObject *); -PyAPI_FUNC(int) PyFunction_SetAnnotations(PyObject *, PyObject *); +PyObject * PyFunction_New(PyObject *, PyObject *); +PyObject * PyFunction_NewWithQualName(PyObject *, PyObject *, PyObject *); +PyObject * PyFunction_GetCode(PyObject *); +PyObject * PyFunction_GetGlobals(PyObject *); +PyObject * PyFunction_GetModule(PyObject *); +PyObject * PyFunction_GetDefaults(PyObject *); +int PyFunction_SetDefaults(PyObject *, PyObject *); +PyObject * PyFunction_GetKwDefaults(PyObject *); +int PyFunction_SetKwDefaults(PyObject *, PyObject *); +PyObject * PyFunction_GetClosure(PyObject *); +int PyFunction_SetClosure(PyObject *, PyObject *); +PyObject * PyFunction_GetAnnotations(PyObject *); +int PyFunction_SetAnnotations(PyObject *, PyObject *); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) _PyFunction_FastCallDict( +PyObject * _PyFunction_FastCallDict( PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs); -PyAPI_FUNC(PyObject *) _PyFunction_FastCallKeywords( +PyObject * _PyFunction_FastCallKeywords( PyObject *func, PyObject **stack, Py_ssize_t nargs, @@ -87,11 +88,11 @@ PyAPI_FUNC(PyObject *) _PyFunction_FastCallKeywords( (((PyFunctionObject *)func) -> func_annotations) /* The classmethod and staticmethod types lives here, too */ -PyAPI_DATA(PyTypeObject) PyClassMethod_Type; -PyAPI_DATA(PyTypeObject) PyStaticMethod_Type; +extern PyTypeObject PyClassMethod_Type; +extern PyTypeObject PyStaticMethod_Type; -PyAPI_FUNC(PyObject *) PyClassMethod_New(PyObject *); -PyAPI_FUNC(PyObject *) PyStaticMethod_New(PyObject *); +PyObject * PyClassMethod_New(PyObject *); +PyObject * PyStaticMethod_New(PyObject *); COSMOPOLITAN_C_END_ #endif /* !Py_FUNCOBJECT_H */ diff --git a/third_party/python/Include/genobject.h b/third_party/python/Include/genobject.h index 2b2b6e07c..f261e8fdb 100644 --- a/third_party/python/Include/genobject.h +++ b/third_party/python/Include/genobject.h @@ -1,6 +1,7 @@ #ifndef Py_LIMITED_API #ifndef Py_GENOBJECT_H #define Py_GENOBJECT_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -28,35 +29,35 @@ typedef struct { _PyGenObject_HEAD(gi) } PyGenObject; -PyAPI_DATA(PyTypeObject) PyGen_Type; +extern PyTypeObject PyGen_Type; #define PyGen_Check(op) PyObject_TypeCheck(op, &PyGen_Type) #define PyGen_CheckExact(op) (Py_TYPE(op) == &PyGen_Type) -PyAPI_FUNC(PyObject *) PyGen_New(struct _frame *); -PyAPI_FUNC(PyObject *) PyGen_NewWithQualName(struct _frame *, +PyObject * PyGen_New(struct _frame *); +PyObject * PyGen_NewWithQualName(struct _frame *, PyObject *name, PyObject *qualname); -PyAPI_FUNC(int) PyGen_NeedsFinalizing(PyGenObject *); -PyAPI_FUNC(int) _PyGen_SetStopIterationValue(PyObject *); -PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **); -PyAPI_FUNC(PyObject *) _PyGen_Send(PyGenObject *, PyObject *); +int PyGen_NeedsFinalizing(PyGenObject *); +int _PyGen_SetStopIterationValue(PyObject *); +int _PyGen_FetchStopIterationValue(PyObject **); +PyObject * _PyGen_Send(PyGenObject *, PyObject *); PyObject *_PyGen_yf(PyGenObject *); -PyAPI_FUNC(void) _PyGen_Finalize(PyObject *self); +void _PyGen_Finalize(PyObject *self); #ifndef Py_LIMITED_API typedef struct { _PyGenObject_HEAD(cr) } PyCoroObject; -PyAPI_DATA(PyTypeObject) PyCoro_Type; -PyAPI_DATA(PyTypeObject) _PyCoroWrapper_Type; +extern PyTypeObject PyCoro_Type; +extern PyTypeObject _PyCoroWrapper_Type; -PyAPI_DATA(PyTypeObject) _PyAIterWrapper_Type; +extern PyTypeObject _PyAIterWrapper_Type; PyObject *_PyAIterWrapper_New(PyObject *aiter); #define PyCoro_CheckExact(op) (Py_TYPE(op) == &PyCoro_Type) PyObject *_PyCoro_GetAwaitableIter(PyObject *o); -PyAPI_FUNC(PyObject *) PyCoro_New(struct _frame *, +PyObject * PyCoro_New(struct _frame *, PyObject *name, PyObject *qualname); /* Asynchronous Generators */ @@ -75,12 +76,12 @@ typedef struct { int ag_closed; } PyAsyncGenObject; -PyAPI_DATA(PyTypeObject) PyAsyncGen_Type; -PyAPI_DATA(PyTypeObject) _PyAsyncGenASend_Type; -PyAPI_DATA(PyTypeObject) _PyAsyncGenWrappedValue_Type; -PyAPI_DATA(PyTypeObject) _PyAsyncGenAThrow_Type; +extern PyTypeObject PyAsyncGen_Type; +extern PyTypeObject _PyAsyncGenASend_Type; +extern PyTypeObject _PyAsyncGenWrappedValue_Type; +extern PyTypeObject _PyAsyncGenAThrow_Type; -PyAPI_FUNC(PyObject *) PyAsyncGen_New(struct _frame *, +PyObject * PyAsyncGen_New(struct _frame *, PyObject *name, PyObject *qualname); #define PyAsyncGen_CheckExact(op) (Py_TYPE(op) == &PyAsyncGen_Type) diff --git a/third_party/python/Include/grammar.h b/third_party/python/Include/grammar.h index 07057a852..06c19c8b0 100644 --- a/third_party/python/Include/grammar.h +++ b/third_party/python/Include/grammar.h @@ -1,5 +1,6 @@ #ifndef Py_GRAMMAR_H #define Py_GRAMMAR_H +#include "libc/stdio/stdio.h" #include "third_party/python/Include/bitset.h" COSMOPOLITAN_C_START_ /* clang-format off */ diff --git a/third_party/python/Include/import.h b/third_party/python/Include/import.h index 58eff3e6e..98ff5672b 100644 --- a/third_party/python/Include/import.h +++ b/third_party/python/Include/import.h @@ -1,54 +1,55 @@ #ifndef Py_IMPORT_H #define Py_IMPORT_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ #ifndef Py_LIMITED_API -PyAPI_FUNC(void) _PyImportZip_Init(void); +void _PyImportZip_Init(void); PyMODINIT_FUNC PyInit_imp(void); #endif /* !Py_LIMITED_API */ -PyAPI_FUNC(long) PyImport_GetMagicNumber(void); -PyAPI_FUNC(const char *) PyImport_GetMagicTag(void); -PyAPI_FUNC(PyObject *) PyImport_ExecCodeModule( +long PyImport_GetMagicNumber(void); +const char * PyImport_GetMagicTag(void); +PyObject * PyImport_ExecCodeModule( const char *name, /* UTF-8 encoded string */ PyObject *co ); -PyAPI_FUNC(PyObject *) PyImport_ExecCodeModuleEx( +PyObject * PyImport_ExecCodeModuleEx( const char *name, /* UTF-8 encoded string */ PyObject *co, const char *pathname /* decoded from the filesystem encoding */ ); -PyAPI_FUNC(PyObject *) PyImport_ExecCodeModuleWithPathnames( +PyObject * PyImport_ExecCodeModuleWithPathnames( const char *name, /* UTF-8 encoded string */ PyObject *co, const char *pathname, /* decoded from the filesystem encoding */ const char *cpathname /* decoded from the filesystem encoding */ ); #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 -PyAPI_FUNC(PyObject *) PyImport_ExecCodeModuleObject( +PyObject * PyImport_ExecCodeModuleObject( PyObject *name, PyObject *co, PyObject *pathname, PyObject *cpathname ); #endif -PyAPI_FUNC(PyObject *) PyImport_GetModuleDict(void); +PyObject * PyImport_GetModuleDict(void); #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 -PyAPI_FUNC(PyObject *) PyImport_AddModuleObject( +PyObject * PyImport_AddModuleObject( PyObject *name ); #endif -PyAPI_FUNC(PyObject *) PyImport_AddModule( +PyObject * PyImport_AddModule( const char *name /* UTF-8 encoded string */ ); -PyAPI_FUNC(PyObject *) PyImport_ImportModule( +PyObject * PyImport_ImportModule( const char *name /* UTF-8 encoded string */ ); -PyAPI_FUNC(PyObject *) PyImport_ImportModuleNoBlock( +PyObject * PyImport_ImportModuleNoBlock( const char *name /* UTF-8 encoded string */ ); -PyAPI_FUNC(PyObject *) PyImport_ImportModuleLevel( +PyObject * PyImport_ImportModuleLevel( const char *name, /* UTF-8 encoded string */ PyObject *globals, PyObject *locals, @@ -56,7 +57,7 @@ PyAPI_FUNC(PyObject *) PyImport_ImportModuleLevel( int level ); #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 -PyAPI_FUNC(PyObject *) PyImport_ImportModuleLevelObject( +PyObject * PyImport_ImportModuleLevelObject( PyObject *name, PyObject *globals, PyObject *locals, @@ -68,51 +69,51 @@ PyAPI_FUNC(PyObject *) PyImport_ImportModuleLevelObject( #define PyImport_ImportModuleEx(n, g, l, f) \ PyImport_ImportModuleLevel(n, g, l, f, 0) -PyAPI_FUNC(PyObject *) PyImport_GetImporter(PyObject *path); -PyAPI_FUNC(PyObject *) PyImport_Import(PyObject *name); -PyAPI_FUNC(PyObject *) PyImport_ReloadModule(PyObject *m); -PyAPI_FUNC(void) PyImport_Cleanup(void); +PyObject * PyImport_GetImporter(PyObject *path); +PyObject * PyImport_Import(PyObject *name); +PyObject * PyImport_ReloadModule(PyObject *m); +void PyImport_Cleanup(void); #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 -PyAPI_FUNC(int) PyImport_ImportFrozenModuleObject( +int PyImport_ImportFrozenModuleObject( PyObject *name ); #endif -PyAPI_FUNC(int) PyImport_ImportFrozenModule( +int PyImport_ImportFrozenModule( const char *name /* UTF-8 encoded string */ ); #ifndef Py_LIMITED_API #ifdef WITH_THREAD -PyAPI_FUNC(void) _PyImport_AcquireLock(void); -PyAPI_FUNC(int) _PyImport_ReleaseLock(void); +void _PyImport_AcquireLock(void); +int _PyImport_ReleaseLock(void); #else #define _PyImport_AcquireLock() #define _PyImport_ReleaseLock() 1 #endif -PyAPI_FUNC(void) _PyImport_ReInitLock(void); +void _PyImport_ReInitLock(void); -PyAPI_FUNC(PyObject *) _PyImport_FindBuiltin( +PyObject * _PyImport_FindBuiltin( const char *name /* UTF-8 encoded string */ ); -PyAPI_FUNC(PyObject *) _PyImport_FindExtensionObject(PyObject *, PyObject *); -PyAPI_FUNC(int) _PyImport_FixupBuiltin( +PyObject * _PyImport_FindExtensionObject(PyObject *, PyObject *); +int _PyImport_FixupBuiltin( PyObject *mod, const char *name /* UTF-8 encoded string */ ); -PyAPI_FUNC(int) _PyImport_FixupExtensionObject(PyObject*, PyObject *, PyObject *); +int _PyImport_FixupExtensionObject(PyObject*, PyObject *, PyObject *); struct _inittab { const char *name; /* ASCII encoded string */ PyObject* (*initfunc)(void); }; -PyAPI_DATA(struct _inittab *) PyImport_Inittab; -PyAPI_FUNC(int) PyImport_ExtendInittab(struct _inittab *newtab); +extern struct _inittab * PyImport_Inittab; +int PyImport_ExtendInittab(struct _inittab *newtab); #endif /* Py_LIMITED_API */ -PyAPI_DATA(PyTypeObject) PyNullImporter_Type; +extern PyTypeObject PyNullImporter_Type; -PyAPI_FUNC(int) PyImport_AppendInittab( +int PyImport_AppendInittab( const char *name, /* ASCII encoded string */ PyObject* (*initfunc)(void) ); @@ -127,7 +128,7 @@ struct _frozen { /* Embedding apps may change this pointer to point to their favorite collection of frozen modules: */ -PyAPI_DATA(const struct _frozen *) PyImport_FrozenModules; +extern const struct _frozen * PyImport_FrozenModules; #endif COSMOPOLITAN_C_END_ diff --git a/third_party/python/Include/intrcheck.h b/third_party/python/Include/intrcheck.h index 48cab065d..92b444b8a 100644 --- a/third_party/python/Include/intrcheck.h +++ b/third_party/python/Include/intrcheck.h @@ -3,16 +3,16 @@ COSMOPOLITAN_C_START_ /* clang-format off */ -PyAPI_FUNC(int) PyOS_InterruptOccurred(void); -PyAPI_FUNC(void) PyOS_InitInterrupts(void); -PyAPI_FUNC(void) PyOS_AfterFork(void); +int PyOS_InterruptOccurred(void); +void PyOS_InitInterrupts(void); +void PyOS_AfterFork(void); #ifndef Py_LIMITED_API -PyAPI_FUNC(int) _PyOS_IsMainThread(void); +int _PyOS_IsMainThread(void); #ifdef MS_WINDOWS /* windows.h is not included by Python.h so use void* instead of HANDLE */ -PyAPI_FUNC(void*) _PyOS_SigintEvent(void); +void* _PyOS_SigintEvent(void); #endif #endif /* !Py_LIMITED_API */ diff --git a/third_party/python/Include/iterobject.h b/third_party/python/Include/iterobject.h index d082448c2..4e131765d 100644 --- a/third_party/python/Include/iterobject.h +++ b/third_party/python/Include/iterobject.h @@ -1,20 +1,21 @@ #ifndef Py_ITEROBJECT_H #define Py_ITEROBJECT_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ -PyAPI_DATA(PyTypeObject) PySeqIter_Type; -PyAPI_DATA(PyTypeObject) PyCallIter_Type; -PyAPI_DATA(PyTypeObject) PyCmpWrapper_Type; +extern PyTypeObject PySeqIter_Type; +extern PyTypeObject PyCallIter_Type; +extern PyTypeObject PyCmpWrapper_Type; #define PySeqIter_Check(op) (Py_TYPE(op) == &PySeqIter_Type) -PyAPI_FUNC(PyObject *) PySeqIter_New(PyObject *); +PyObject * PySeqIter_New(PyObject *); #define PyCallIter_Check(op) (Py_TYPE(op) == &PyCallIter_Type) -PyAPI_FUNC(PyObject *) PyCallIter_New(PyObject *, PyObject *); +PyObject * PyCallIter_New(PyObject *, PyObject *); COSMOPOLITAN_C_END_ #endif /* !Py_ITEROBJECT_H */ diff --git a/third_party/python/Include/listobject.h b/third_party/python/Include/listobject.h index 4708aee4c..f3fad575a 100644 --- a/third_party/python/Include/listobject.h +++ b/third_party/python/Include/listobject.h @@ -1,5 +1,6 @@ #ifndef Py_LISTOBJECT_H #define Py_LISTOBJECT_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -38,31 +39,31 @@ typedef struct { } PyListObject; #endif -PyAPI_DATA(PyTypeObject) PyList_Type; -PyAPI_DATA(PyTypeObject) PyListIter_Type; -PyAPI_DATA(PyTypeObject) PyListRevIter_Type; -PyAPI_DATA(PyTypeObject) PySortWrapper_Type; +extern PyTypeObject PyList_Type; +extern PyTypeObject PyListIter_Type; +extern PyTypeObject PyListRevIter_Type; +extern PyTypeObject PySortWrapper_Type; #define PyList_Check(op) \ PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS) #define PyList_CheckExact(op) (Py_TYPE(op) == &PyList_Type) -PyAPI_FUNC(PyObject *) PyList_New(Py_ssize_t size); -PyAPI_FUNC(Py_ssize_t) PyList_Size(PyObject *); -PyAPI_FUNC(PyObject *) PyList_GetItem(PyObject *, Py_ssize_t); -PyAPI_FUNC(int) PyList_SetItem(PyObject *, Py_ssize_t, PyObject *); -PyAPI_FUNC(int) PyList_Insert(PyObject *, Py_ssize_t, PyObject *); -PyAPI_FUNC(int) PyList_Append(PyObject *, PyObject *); -PyAPI_FUNC(PyObject *) PyList_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t); -PyAPI_FUNC(int) PyList_SetSlice(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *); -PyAPI_FUNC(int) PyList_Sort(PyObject *); -PyAPI_FUNC(int) PyList_Reverse(PyObject *); -PyAPI_FUNC(PyObject *) PyList_AsTuple(PyObject *); +PyObject * PyList_New(Py_ssize_t size); +Py_ssize_t PyList_Size(PyObject *); +PyObject * PyList_GetItem(PyObject *, Py_ssize_t); +int PyList_SetItem(PyObject *, Py_ssize_t, PyObject *); +int PyList_Insert(PyObject *, Py_ssize_t, PyObject *); +int PyList_Append(PyObject *, PyObject *); +PyObject * PyList_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t); +int PyList_SetSlice(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *); +int PyList_Sort(PyObject *); +int PyList_Reverse(PyObject *); +PyObject * PyList_AsTuple(PyObject *); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) _PyList_Extend(PyListObject *, PyObject *); +PyObject * _PyList_Extend(PyListObject *, PyObject *); -PyAPI_FUNC(int) PyList_ClearFreeList(void); -PyAPI_FUNC(void) _PyList_DebugMallocStats(FILE *out); +int PyList_ClearFreeList(void); +void _PyList_DebugMallocStats(FILE *out); #endif /* Macro, trading safety for speed */ diff --git a/third_party/python/Include/longintrepr.h b/third_party/python/Include/longintrepr.h index 5e8fa3a52..39760ba3d 100644 --- a/third_party/python/Include/longintrepr.h +++ b/third_party/python/Include/longintrepr.h @@ -1,7 +1,8 @@ #ifndef Py_LIMITED_API #ifndef Py_LONGINTREPR_H #define Py_LONGINTREPR_H -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/object.h" #include "third_party/python/Include/pyport.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -87,10 +88,10 @@ struct _longobject { digit ob_digit[1]; }; -PyAPI_FUNC(PyLongObject *) _PyLong_New(Py_ssize_t); +PyLongObject * _PyLong_New(Py_ssize_t); /* Return a copy of src. */ -PyAPI_FUNC(PyObject *) _PyLong_Copy(PyLongObject *src); +PyObject * _PyLong_Copy(PyLongObject *src); COSMOPOLITAN_C_END_ #endif /* !Py_LONGINTREPR_H */ diff --git a/third_party/python/Include/longobject.h b/third_party/python/Include/longobject.h index c0dac0121..7863106b9 100644 --- a/third_party/python/Include/longobject.h +++ b/third_party/python/Include/longobject.h @@ -1,5 +1,8 @@ #ifndef Py_LONGOBJECT_H #define Py_LONGOBJECT_H +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/unicodeobject.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -7,27 +10,27 @@ COSMOPOLITAN_C_START_ typedef struct _longobject PyLongObject; /* Revealed in longintrepr.h */ -PyAPI_DATA(PyTypeObject) PyLong_Type; +extern PyTypeObject PyLong_Type; #define PyLong_Check(op) \ PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS) #define PyLong_CheckExact(op) (Py_TYPE(op) == &PyLong_Type) -PyAPI_FUNC(PyObject *) PyLong_FromLong(long); -PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLong(unsigned long); -PyAPI_FUNC(PyObject *) PyLong_FromSize_t(size_t); -PyAPI_FUNC(PyObject *) PyLong_FromSsize_t(Py_ssize_t); -PyAPI_FUNC(PyObject *) PyLong_FromDouble(double); -PyAPI_FUNC(long) PyLong_AsLong(PyObject *); -PyAPI_FUNC(long) PyLong_AsLongAndOverflow(PyObject *, int *); -PyAPI_FUNC(Py_ssize_t) PyLong_AsSsize_t(PyObject *); -PyAPI_FUNC(size_t) PyLong_AsSize_t(PyObject *); -PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLong(PyObject *); -PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLongMask(PyObject *); +PyObject * PyLong_FromLong(long); +PyObject * PyLong_FromUnsignedLong(unsigned long); +PyObject * PyLong_FromSize_t(size_t); +PyObject * PyLong_FromSsize_t(Py_ssize_t); +PyObject * PyLong_FromDouble(double); +long PyLong_AsLong(PyObject *); +long PyLong_AsLongAndOverflow(PyObject *, int *); +Py_ssize_t PyLong_AsSsize_t(PyObject *); +size_t PyLong_AsSize_t(PyObject *); +unsigned long PyLong_AsUnsignedLong(PyObject *); +unsigned long PyLong_AsUnsignedLongMask(PyObject *); #ifndef Py_LIMITED_API -PyAPI_FUNC(int) _PyLong_AsInt(PyObject *); +int _PyLong_AsInt(PyObject *); #endif -PyAPI_FUNC(PyObject *) PyLong_GetInfo(void); +PyObject * PyLong_GetInfo(void); /* It may be useful in the future. I've added it in the PyInt -> PyLong cleanup to keep the extra information. [CH] */ @@ -66,7 +69,7 @@ PyAPI_FUNC(PyObject *) PyLong_GetInfo(void); /* Used by Python/mystrtoul.c, _PyBytes_FromHex(), _PyBytes_DecodeEscapeRecode(), etc. */ #ifndef Py_LIMITED_API -PyAPI_DATA(unsigned char) _PyLong_DigitValue[256]; +extern unsigned char _PyLong_DigitValue[256]; #endif /* _PyLong_Frexp returns a double x and an exponent e such that the @@ -76,25 +79,25 @@ PyAPI_DATA(unsigned char) _PyLong_DigitValue[256]; possible if the number of bits doesn't fit into a Py_ssize_t, sets OverflowError and returns -1.0 for x, 0 for e. */ #ifndef Py_LIMITED_API -PyAPI_FUNC(double) _PyLong_Frexp(PyLongObject *a, Py_ssize_t *e); +double _PyLong_Frexp(PyLongObject *a, Py_ssize_t *e); #endif -PyAPI_FUNC(double) PyLong_AsDouble(PyObject *); -PyAPI_FUNC(PyObject *) PyLong_FromVoidPtr(void *); -PyAPI_FUNC(void *) PyLong_AsVoidPtr(PyObject *); +double PyLong_AsDouble(PyObject *); +PyObject * PyLong_FromVoidPtr(void *); +void * PyLong_AsVoidPtr(PyObject *); -PyAPI_FUNC(PyObject *) PyLong_FromLongLong(long long); -PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLongLong(unsigned long long); -PyAPI_FUNC(long long) PyLong_AsLongLong(PyObject *); -PyAPI_FUNC(unsigned long long) PyLong_AsUnsignedLongLong(PyObject *); -PyAPI_FUNC(unsigned long long) PyLong_AsUnsignedLongLongMask(PyObject *); -PyAPI_FUNC(long long) PyLong_AsLongLongAndOverflow(PyObject *, int *); +PyObject * PyLong_FromLongLong(long long); +PyObject * PyLong_FromUnsignedLongLong(unsigned long long); +long long PyLong_AsLongLong(PyObject *); +unsigned long long PyLong_AsUnsignedLongLong(PyObject *); +unsigned long long PyLong_AsUnsignedLongLongMask(PyObject *); +long long PyLong_AsLongLongAndOverflow(PyObject *, int *); -PyAPI_FUNC(PyObject *) PyLong_FromString(const char *, char **, int); +PyObject * PyLong_FromString(const char *, char **, int); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) PyLong_FromUnicode(Py_UNICODE*, Py_ssize_t, int); -PyAPI_FUNC(PyObject *) PyLong_FromUnicodeObject(PyObject *u, int base); -PyAPI_FUNC(PyObject *) _PyLong_FromBytes(const char *, Py_ssize_t, int); +PyObject * PyLong_FromUnicode(Py_UNICODE*, Py_ssize_t, int); +PyObject * PyLong_FromUnicodeObject(PyObject *u, int base); +PyObject * _PyLong_FromBytes(const char *, Py_ssize_t, int); #endif #ifndef Py_LIMITED_API @@ -102,7 +105,7 @@ PyAPI_FUNC(PyObject *) _PyLong_FromBytes(const char *, Py_ssize_t, int); v must not be NULL, and must be a normalized long. There are no error cases. */ -PyAPI_FUNC(int) _PyLong_Sign(PyObject *v); +int _PyLong_Sign(PyObject *v); /* _PyLong_NumBits. Return the number of bits needed to represent the @@ -112,7 +115,7 @@ PyAPI_FUNC(int) _PyLong_Sign(PyObject *v); (size_t)-1 is returned and OverflowError set if the true result doesn't fit in a size_t. */ -PyAPI_FUNC(size_t) _PyLong_NumBits(PyObject *v); +size_t _PyLong_NumBits(PyObject *v); /* _PyLong_DivmodNear. Given integers a and b, compute the nearest integer q to the exact quotient a / b, rounding to the nearest even integer @@ -120,7 +123,7 @@ PyAPI_FUNC(size_t) _PyLong_NumBits(PyObject *v); will satisfy abs(r) <= abs(b)/2, with equality possible only if q is even. */ -PyAPI_FUNC(PyObject *) _PyLong_DivmodNear(PyObject *, PyObject *); +PyObject * _PyLong_DivmodNear(PyObject *, PyObject *); /* _PyLong_FromByteArray: View the n unsigned bytes as a binary integer in base 256, and return a Python int with the same numeric value. @@ -135,7 +138,7 @@ PyAPI_FUNC(PyObject *) _PyLong_DivmodNear(PyObject *, PyObject *); + Return NULL with the appropriate exception set if there's not enough memory to create the Python int. */ -PyAPI_FUNC(PyObject *) _PyLong_FromByteArray( +PyObject * _PyLong_FromByteArray( const unsigned char* bytes, size_t n, int little_endian, int is_signed); @@ -158,7 +161,7 @@ PyAPI_FUNC(PyObject *) _PyLong_FromByteArray( being large enough to hold a sign bit. OverflowError is set in this case, but bytes holds the least-significant n bytes of the true value. */ -PyAPI_FUNC(int) _PyLong_AsByteArray(PyLongObject* v, +int _PyLong_AsByteArray(PyLongObject* v, unsigned char* bytes, size_t n, int little_endian, int is_signed); @@ -167,19 +170,19 @@ PyAPI_FUNC(int) _PyLong_AsByteArray(PyLongObject* v, nb_int slot is not available or the result of the call to nb_int returns something not of type int. */ -PyAPI_FUNC(PyLongObject *)_PyLong_FromNbInt(PyObject *); +PyLongObject *_PyLong_FromNbInt(PyObject *); /* _PyLong_Format: Convert the long to a string object with given base, appending a base prefix of 0[box] if base is 2, 8 or 16. */ -PyAPI_FUNC(PyObject *) _PyLong_Format(PyObject *obj, int base); +PyObject * _PyLong_Format(PyObject *obj, int base); -PyAPI_FUNC(int) _PyLong_FormatWriter( +int _PyLong_FormatWriter( _PyUnicodeWriter *writer, PyObject *obj, int base, int alternate); -PyAPI_FUNC(char*) _PyLong_FormatBytesWriter( +char* _PyLong_FormatBytesWriter( _PyBytesWriter *writer, char *str, PyObject *obj, @@ -188,7 +191,7 @@ PyAPI_FUNC(char*) _PyLong_FormatBytesWriter( /* Format the object based on the format_spec, as defined in PEP 3101 (Advanced String Formatting). */ -PyAPI_FUNC(int) _PyLong_FormatAdvancedWriter( +int _PyLong_FormatAdvancedWriter( _PyUnicodeWriter *writer, PyObject *obj, PyObject *format_spec, @@ -199,12 +202,12 @@ PyAPI_FUNC(int) _PyLong_FormatAdvancedWriter( /* These aren't really part of the int object, but they're handy. The functions are in Python/mystrtoul.c. */ -PyAPI_FUNC(unsigned long) PyOS_strtoul(const char *, char **, int); -PyAPI_FUNC(long) PyOS_strtol(const char *, char **, int); +unsigned long PyOS_strtoul(const char *, char **, int); +long PyOS_strtol(const char *, char **, int); #ifndef Py_LIMITED_API /* For use by the gcd function in mathmodule.c */ -PyAPI_FUNC(PyObject *) _PyLong_GCD(PyObject *, PyObject *); +PyObject * _PyLong_GCD(PyObject *, PyObject *); #endif /* !Py_LIMITED_API */ COSMOPOLITAN_C_END_ diff --git a/third_party/python/Include/marshal.h b/third_party/python/Include/marshal.h index e282bca6c..3ca0ecd3c 100644 --- a/third_party/python/Include/marshal.h +++ b/third_party/python/Include/marshal.h @@ -1,21 +1,22 @@ #ifndef Py_MARSHAL_H #define Py_MARSHAL_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ #define Py_MARSHAL_VERSION 4 -PyAPI_FUNC(void) PyMarshal_WriteLongToFile(long, FILE *, int); -PyAPI_FUNC(void) PyMarshal_WriteObjectToFile(PyObject *, FILE *, int); -PyAPI_FUNC(PyObject *) PyMarshal_WriteObjectToString(PyObject *, int); +void PyMarshal_WriteLongToFile(long, FILE *, int); +void PyMarshal_WriteObjectToFile(PyObject *, FILE *, int); +PyObject * PyMarshal_WriteObjectToString(PyObject *, int); #ifndef Py_LIMITED_API -PyAPI_FUNC(long) PyMarshal_ReadLongFromFile(FILE *); -PyAPI_FUNC(int) PyMarshal_ReadShortFromFile(FILE *); -PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromFile(FILE *); -PyAPI_FUNC(PyObject *) PyMarshal_ReadLastObjectFromFile(FILE *); +long PyMarshal_ReadLongFromFile(FILE *); +int PyMarshal_ReadShortFromFile(FILE *); +PyObject * PyMarshal_ReadObjectFromFile(FILE *); +PyObject * PyMarshal_ReadLastObjectFromFile(FILE *); #endif -PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(const char *, Py_ssize_t); +PyObject * PyMarshal_ReadObjectFromString(const char *, Py_ssize_t); COSMOPOLITAN_C_END_ #endif /* !Py_MARSHAL_H */ diff --git a/third_party/python/Include/memoryobject.h b/third_party/python/Include/memoryobject.h index c0e2d47b1..b01316e52 100644 --- a/third_party/python/Include/memoryobject.h +++ b/third_party/python/Include/memoryobject.h @@ -1,12 +1,13 @@ #ifndef Py_MEMORYOBJECT_H #define Py_MEMORYOBJECT_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ #ifndef Py_LIMITED_API -PyAPI_DATA(PyTypeObject) _PyManagedBuffer_Type; +extern PyTypeObject _PyManagedBuffer_Type; #endif -PyAPI_DATA(PyTypeObject) PyMemoryView_Type; +extern PyTypeObject PyMemoryView_Type; #define PyMemoryView_Check(op) (Py_TYPE(op) == &PyMemoryView_Type) @@ -17,15 +18,15 @@ PyAPI_DATA(PyTypeObject) PyMemoryView_Type; #define PyMemoryView_GET_BASE(op) (((PyMemoryViewObject *)(op))->view.obj) #endif -PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base); +PyObject * PyMemoryView_FromObject(PyObject *base); #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 -PyAPI_FUNC(PyObject *) PyMemoryView_FromMemory(char *mem, Py_ssize_t size, +PyObject * PyMemoryView_FromMemory(char *mem, Py_ssize_t size, int flags); #endif #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) PyMemoryView_FromBuffer(Py_buffer *info); +PyObject * PyMemoryView_FromBuffer(Py_buffer *info); #endif -PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base, +PyObject * PyMemoryView_GetContiguous(PyObject *base, int buffertype, char order); diff --git a/third_party/python/Include/methodobject.h b/third_party/python/Include/methodobject.h index db052dac5..3e74490ee 100644 --- a/third_party/python/Include/methodobject.h +++ b/third_party/python/Include/methodobject.h @@ -1,5 +1,7 @@ #ifndef Py_METHODOBJECT_H #define Py_METHODOBJECT_H +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyport.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -7,7 +9,7 @@ COSMOPOLITAN_C_START_ not Python methods in user-defined classes. See classobject.h for the latter. */ -PyAPI_DATA(PyTypeObject) PyCFunction_Type; +extern PyTypeObject PyCFunction_Type; #define PyCFunction_Check(op) (Py_TYPE(op) == &PyCFunction_Type) @@ -18,9 +20,9 @@ typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *, PyObject *); typedef PyObject *(*PyNoArgsFunction)(PyObject *); -PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *); -PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *); -PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *); +PyCFunction PyCFunction_GetFunction(PyObject *); +PyObject * PyCFunction_GetSelf(PyObject *); +int PyCFunction_GetFlags(PyObject *); /* Macros for direct access to these values. Type checks are *not* done, so use with care. */ @@ -33,15 +35,15 @@ PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *); #define PyCFunction_GET_FLAGS(func) \ (((PyCFunctionObject *)func) -> m_ml -> ml_flags) #endif -PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *); +PyObject * PyCFunction_Call(PyObject *, PyObject *, PyObject *); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) _PyCFunction_FastCallDict(PyObject *func, +PyObject * _PyCFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs); -PyAPI_FUNC(PyObject *) _PyCFunction_FastCallKeywords(PyObject *func, +PyObject * _PyCFunction_FastCallKeywords(PyObject *func, PyObject **stack, Py_ssize_t nargs, PyObject *kwnames); @@ -57,7 +59,7 @@ struct PyMethodDef { typedef struct PyMethodDef PyMethodDef; #define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL) -PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *, +PyObject * PyCFunction_NewEx(PyMethodDef *, PyObject *, PyObject *); /* Flag passed to newmethodobject */ @@ -93,11 +95,11 @@ typedef struct { } PyCFunctionObject; #endif -PyAPI_FUNC(int) PyCFunction_ClearFreeList(void); +int PyCFunction_ClearFreeList(void); #ifndef Py_LIMITED_API -PyAPI_FUNC(void) _PyCFunction_DebugMallocStats(FILE *out); -PyAPI_FUNC(void) _PyMethod_DebugMallocStats(FILE *out); +void _PyCFunction_DebugMallocStats(FILE *out); +void _PyMethod_DebugMallocStats(FILE *out); #endif COSMOPOLITAN_C_END_ diff --git a/third_party/python/Include/modsupport.h b/third_party/python/Include/modsupport.h index be0165656..cd7242fcf 100644 --- a/third_party/python/Include/modsupport.h +++ b/third_party/python/Include/modsupport.h @@ -1,5 +1,8 @@ #ifndef Py_MODSUPPORT_H #define Py_MODSUPPORT_H +#include "third_party/python/Include/methodobject.h" +#include "third_party/python/Include/moduleobject.h" +#include "third_party/python/Include/object.h" #pragma GCC diagnostic ignored "-Wredundant-decls" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -16,30 +19,30 @@ COSMOPOLITAN_C_START_ #define Py_VaBuildValue _Py_VaBuildValue_SizeT #else #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) _Py_VaBuildValue_SizeT(const char *, va_list); +PyObject * _Py_VaBuildValue_SizeT(const char *, va_list); #endif /* !Py_LIMITED_API */ #endif /* Due to a glitch in 3.2, the _SizeT versions weren't exported from the DLL. */ #if !defined(PY_SSIZE_T_CLEAN) || !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 -PyAPI_FUNC(int) PyArg_Parse(PyObject *, const char *, ...); -PyAPI_FUNC(int) PyArg_ParseTuple(PyObject *, const char *, ...); -PyAPI_FUNC(int) PyArg_ParseTupleAndKeywords(PyObject *, PyObject *, +int PyArg_Parse(PyObject *, const char *, ...); +int PyArg_ParseTuple(PyObject *, const char *, ...); +int PyArg_ParseTupleAndKeywords(PyObject *, PyObject *, const char *, char **, ...); -PyAPI_FUNC(int) PyArg_VaParse(PyObject *, const char *, va_list); -PyAPI_FUNC(int) PyArg_VaParseTupleAndKeywords(PyObject *, PyObject *, +int PyArg_VaParse(PyObject *, const char *, va_list); +int PyArg_VaParseTupleAndKeywords(PyObject *, PyObject *, const char *, char **, va_list); #endif -PyAPI_FUNC(int) PyArg_ValidateKeywordArguments(PyObject *); -PyAPI_FUNC(int) PyArg_UnpackTuple(PyObject *, const char *, Py_ssize_t, Py_ssize_t, ...); -PyAPI_FUNC(PyObject *) Py_BuildValue(const char *, ...); -PyAPI_FUNC(PyObject *) _Py_BuildValue_SizeT(const char *, ...); +int PyArg_ValidateKeywordArguments(PyObject *); +int PyArg_UnpackTuple(PyObject *, const char *, Py_ssize_t, Py_ssize_t, ...); +PyObject * Py_BuildValue(const char *, ...); +PyObject * _Py_BuildValue_SizeT(const char *, ...); #ifndef Py_LIMITED_API -PyAPI_FUNC(int) _PyArg_NoKeywords(const char *funcname, PyObject *kw); -PyAPI_FUNC(int) _PyArg_NoPositional(const char *funcname, PyObject *args); +int _PyArg_NoKeywords(const char *funcname, PyObject *kw); +int _PyArg_NoPositional(const char *funcname, PyObject *args); #endif -PyAPI_FUNC(PyObject *) Py_VaBuildValue(const char *, va_list); +PyObject * Py_VaBuildValue(const char *, va_list); #ifndef Py_LIMITED_API typedef struct _PyArg_Parser { @@ -58,26 +61,26 @@ typedef struct _PyArg_Parser { #define _PyArg_ParseStack _PyArg_ParseStack_SizeT #define _PyArg_VaParseTupleAndKeywordsFast _PyArg_VaParseTupleAndKeywordsFast_SizeT #endif -PyAPI_FUNC(int) _PyArg_ParseTupleAndKeywordsFast(PyObject *, PyObject *, +int _PyArg_ParseTupleAndKeywordsFast(PyObject *, PyObject *, struct _PyArg_Parser *, ...); -PyAPI_FUNC(int) _PyArg_ParseStack(PyObject **args, Py_ssize_t nargs, PyObject *kwnames, +int _PyArg_ParseStack(PyObject **args, Py_ssize_t nargs, PyObject *kwnames, struct _PyArg_Parser *, ...); -PyAPI_FUNC(int) _PyArg_VaParseTupleAndKeywordsFast(PyObject *, PyObject *, +int _PyArg_VaParseTupleAndKeywordsFast(PyObject *, PyObject *, struct _PyArg_Parser *, va_list); void _PyArg_Fini(void); #endif -PyAPI_FUNC(int) PyModule_AddObject(PyObject *, const char *, PyObject *); -PyAPI_FUNC(int) PyModule_AddIntConstant(PyObject *, const char *, long); -PyAPI_FUNC(int) PyModule_AddStringConstant(PyObject *, const char *, const char *); +int PyModule_AddObject(PyObject *, const char *, PyObject *); +int PyModule_AddIntConstant(PyObject *, const char *, long); +int PyModule_AddStringConstant(PyObject *, const char *, const char *); #define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c) #define PyModule_AddStringMacro(m, c) PyModule_AddStringConstant(m, #c, c) #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 /* New in 3.5 */ -PyAPI_FUNC(int) PyModule_SetDocString(PyObject *, const char *); -PyAPI_FUNC(int) PyModule_AddFunctions(PyObject *, PyMethodDef *); -PyAPI_FUNC(int) PyModule_ExecDef(PyObject *module, PyModuleDef *def); +int PyModule_SetDocString(PyObject *, const char *); +int PyModule_AddFunctions(PyObject *, PyMethodDef *); +int PyModule_ExecDef(PyObject *module, PyModuleDef *def); #endif #define Py_CLEANUP_SUPPORTED 0x20000 @@ -142,7 +145,7 @@ PyAPI_FUNC(int) PyModule_ExecDef(PyObject *module, PyModuleDef *def); #define PyModule_FromDefAndSpec2 PyModule_FromDefAndSpec2TraceRefs #endif -PyAPI_FUNC(PyObject *) PyModule_Create2(struct PyModuleDef*, +PyObject * PyModule_Create2(struct PyModuleDef*, int apiver); #ifdef Py_LIMITED_API @@ -155,7 +158,7 @@ PyAPI_FUNC(PyObject *) PyModule_Create2(struct PyModuleDef*, #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 /* New in 3.5 */ -PyAPI_FUNC(PyObject *) PyModule_FromDefAndSpec2(PyModuleDef *def, +PyObject * PyModule_FromDefAndSpec2(PyModuleDef *def, PyObject *spec, int module_api_version); @@ -169,7 +172,7 @@ PyAPI_FUNC(PyObject *) PyModule_FromDefAndSpec2(PyModuleDef *def, #endif /* New in 3.5 */ #ifndef Py_LIMITED_API -PyAPI_DATA(char *) _Py_PackageContext; +extern char * _Py_PackageContext; #endif COSMOPOLITAN_C_END_ diff --git a/third_party/python/Include/moduleobject.h b/third_party/python/Include/moduleobject.h index 67dbc0d72..2ed00d6e6 100644 --- a/third_party/python/Include/moduleobject.h +++ b/third_party/python/Include/moduleobject.h @@ -1,39 +1,41 @@ #ifndef Py_MODULEOBJECT_H #define Py_MODULEOBJECT_H +#include "third_party/python/Include/methodobject.h" +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ -PyAPI_DATA(PyTypeObject) PyModule_Type; +extern PyTypeObject PyModule_Type; #define PyModule_Check(op) PyObject_TypeCheck(op, &PyModule_Type) #define PyModule_CheckExact(op) (Py_TYPE(op) == &PyModule_Type) #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 -PyAPI_FUNC(PyObject *) PyModule_NewObject( +PyObject * PyModule_NewObject( PyObject *name ); #endif -PyAPI_FUNC(PyObject *) PyModule_New( +PyObject * PyModule_New( const char *name /* UTF-8 encoded string */ ); -PyAPI_FUNC(PyObject *) PyModule_GetDict(PyObject *); +PyObject * PyModule_GetDict(PyObject *); #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 -PyAPI_FUNC(PyObject *) PyModule_GetNameObject(PyObject *); +PyObject * PyModule_GetNameObject(PyObject *); #endif -PyAPI_FUNC(const char *) PyModule_GetName(PyObject *); -PyAPI_FUNC(const char *) PyModule_GetFilename(PyObject *); -PyAPI_FUNC(PyObject *) PyModule_GetFilenameObject(PyObject *); +const char * PyModule_GetName(PyObject *); +const char * PyModule_GetFilename(PyObject *); +PyObject * PyModule_GetFilenameObject(PyObject *); #ifndef Py_LIMITED_API -PyAPI_FUNC(void) _PyModule_Clear(PyObject *); -PyAPI_FUNC(void) _PyModule_ClearDict(PyObject *); +void _PyModule_Clear(PyObject *); +void _PyModule_ClearDict(PyObject *); #endif -PyAPI_FUNC(struct PyModuleDef*) PyModule_GetDef(PyObject*); -PyAPI_FUNC(void*) PyModule_GetState(PyObject*); +struct PyModuleDef* PyModule_GetDef(PyObject*); +void* PyModule_GetState(PyObject*); #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 /* New in 3.5 */ -PyAPI_FUNC(PyObject *) PyModuleDef_Init(struct PyModuleDef*); -PyAPI_DATA(PyTypeObject) PyModuleDef_Type; +PyObject * PyModuleDef_Init(struct PyModuleDef*); +extern PyTypeObject PyModuleDef_Type; #endif typedef struct PyModuleDef_Base { diff --git a/third_party/python/Include/namespaceobject.h b/third_party/python/Include/namespaceobject.h index 44d9270dc..634694bc1 100644 --- a/third_party/python/Include/namespaceobject.h +++ b/third_party/python/Include/namespaceobject.h @@ -1,12 +1,13 @@ #ifndef NAMESPACEOBJECT_H #define NAMESPACEOBJECT_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ #ifndef Py_LIMITED_API -PyAPI_DATA(PyTypeObject) _PyNamespace_Type; +extern PyTypeObject _PyNamespace_Type; -PyAPI_FUNC(PyObject *) _PyNamespace_New(PyObject *kwds); +PyObject * _PyNamespace_New(PyObject *kwds); #endif /* !Py_LIMITED_API */ COSMOPOLITAN_C_END_ diff --git a/third_party/python/Include/node.h b/third_party/python/Include/node.h index 7b9a844a3..19a10f801 100644 --- a/third_party/python/Include/node.h +++ b/third_party/python/Include/node.h @@ -1,5 +1,6 @@ #ifndef Py_NODE_H #define Py_NODE_H +#include "third_party/python/Include/pyport.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -12,12 +13,12 @@ typedef struct _node { struct _node *n_child; } node; -PyAPI_FUNC(node *) PyNode_New(int type); -PyAPI_FUNC(int) PyNode_AddChild(node *n, int type, +node * PyNode_New(int type); +int PyNode_AddChild(node *n, int type, char *str, int lineno, int col_offset); -PyAPI_FUNC(void) PyNode_Free(node *n); +void PyNode_Free(node *n); #ifndef Py_LIMITED_API -PyAPI_FUNC(Py_ssize_t) _PyNode_SizeOf(node *n); +Py_ssize_t _PyNode_SizeOf(node *n); #endif /* Node access functions */ @@ -32,7 +33,7 @@ PyAPI_FUNC(Py_ssize_t) _PyNode_SizeOf(node *n); /* Assert that the type of a node is what we expect */ #define REQ(n, type) assert(TYPE(n) == (type)) -PyAPI_FUNC(void) PyNode_ListTree(node *); +void PyNode_ListTree(node *); COSMOPOLITAN_C_END_ #endif /* !Py_NODE_H */ diff --git a/third_party/python/Include/object.h b/third_party/python/Include/object.h index d46d2aa19..30094355d 100644 --- a/third_party/python/Include/object.h +++ b/third_party/python/Include/object.h @@ -1,5 +1,8 @@ #ifndef Py_OBJECT_H -#define Py_OBJECT_H +#define Py_OBJECT_H /* DO NOT INCLUDE pystate.h */ +#include "libc/stdio/stdio.h" +#include "third_party/python/Include/op.h" +#include "third_party/python/Include/pyport.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -446,12 +449,12 @@ typedef struct{ PyType_Slot *slots; /* terminated by slot==0. */ } PyType_Spec; -PyAPI_FUNC(PyObject*) PyType_FromSpec(PyType_Spec*); +PyObject* PyType_FromSpec(PyType_Spec*); #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 -PyAPI_FUNC(PyObject*) PyType_FromSpecWithBases(PyType_Spec*, PyObject*); +PyObject* PyType_FromSpecWithBases(PyType_Spec*, PyObject*); #endif #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03040000 -PyAPI_FUNC(void*) PyType_GetSlot(PyTypeObject*, int); +void* PyType_GetSlot(PyTypeObject*, int); #endif #ifndef Py_LIMITED_API @@ -480,100 +483,100 @@ typedef struct _heaptypeobject { #endif /* Generic type check */ -PyAPI_FUNC(int) PyType_IsSubtype(PyTypeObject *, PyTypeObject *); +int PyType_IsSubtype(PyTypeObject *, PyTypeObject *); #define PyObject_TypeCheck(ob, tp) \ (Py_TYPE(ob) == (tp) || PyType_IsSubtype(Py_TYPE(ob), (tp))) -PyAPI_DATA(PyTypeObject) PyType_Type; /* built-in 'type' */ -PyAPI_DATA(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */ -PyAPI_DATA(PyTypeObject) PySuper_Type; /* built-in 'super' */ +extern PyTypeObject PyType_Type; /* built-in 'type' */ +extern PyTypeObject PyBaseObject_Type; /* built-in 'object' */ +extern PyTypeObject PySuper_Type; /* built-in 'super' */ -PyAPI_FUNC(unsigned long) PyType_GetFlags(PyTypeObject*); +unsigned long PyType_GetFlags(PyTypeObject*); #define PyType_Check(op) \ PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS) #define PyType_CheckExact(op) (Py_TYPE(op) == &PyType_Type) -PyAPI_FUNC(int) PyType_Ready(PyTypeObject *); -PyAPI_FUNC(PyObject *) PyType_GenericAlloc(PyTypeObject *, Py_ssize_t); -PyAPI_FUNC(PyObject *) PyType_GenericNew(PyTypeObject *, +int PyType_Ready(PyTypeObject *); +PyObject * PyType_GenericAlloc(PyTypeObject *, Py_ssize_t); +PyObject * PyType_GenericNew(PyTypeObject *, PyObject *, PyObject *); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *); -PyAPI_FUNC(PyObject *) _PyType_LookupId(PyTypeObject *, _Py_Identifier *); -PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, _Py_Identifier *); -PyAPI_FUNC(PyTypeObject *) _PyType_CalculateMetaclass(PyTypeObject *, PyObject *); +PyObject * _PyType_Lookup(PyTypeObject *, PyObject *); +PyObject * _PyType_LookupId(PyTypeObject *, _Py_Identifier *); +PyObject * _PyObject_LookupSpecial(PyObject *, _Py_Identifier *); +PyTypeObject * _PyType_CalculateMetaclass(PyTypeObject *, PyObject *); #endif -PyAPI_FUNC(unsigned int) PyType_ClearCache(void); -PyAPI_FUNC(void) PyType_Modified(PyTypeObject *); +unsigned int PyType_ClearCache(void); +void PyType_Modified(PyTypeObject *); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) _PyType_GetDocFromInternalDoc(const char *, const char *); -PyAPI_FUNC(PyObject *) _PyType_GetTextSignatureFromInternalDoc(const char *, const char *); +PyObject * _PyType_GetDocFromInternalDoc(const char *, const char *); +PyObject * _PyType_GetTextSignatureFromInternalDoc(const char *, const char *); #endif /* Generic operations on objects */ #ifndef Py_LIMITED_API struct _Py_Identifier; -PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int); -PyAPI_FUNC(void) _Py_BreakPoint(void); -PyAPI_FUNC(void) _PyObject_Dump(PyObject *); -PyAPI_FUNC(int) _PyObject_IsFreed(PyObject *); +int PyObject_Print(PyObject *, FILE *, int); +void _Py_BreakPoint(void); +void _PyObject_Dump(PyObject *); +int _PyObject_IsFreed(PyObject *); #endif -PyAPI_FUNC(PyObject *) PyObject_Repr(PyObject *); -PyAPI_FUNC(PyObject *) PyObject_Str(PyObject *); -PyAPI_FUNC(PyObject *) PyObject_ASCII(PyObject *); -PyAPI_FUNC(PyObject *) PyObject_Bytes(PyObject *); -PyAPI_FUNC(PyObject *) PyObject_RichCompare(PyObject *, PyObject *, int); -PyAPI_FUNC(int) PyObject_RichCompareBool(PyObject *, PyObject *, int); -PyAPI_FUNC(PyObject *) PyObject_GetAttrString(PyObject *, const char *); -PyAPI_FUNC(int) PyObject_SetAttrString(PyObject *, const char *, PyObject *); -PyAPI_FUNC(int) PyObject_HasAttrString(PyObject *, const char *); -PyAPI_FUNC(PyObject *) PyObject_GetAttr(PyObject *, PyObject *); -PyAPI_FUNC(int) PyObject_SetAttr(PyObject *, PyObject *, PyObject *); -PyAPI_FUNC(int) PyObject_HasAttr(PyObject *, PyObject *); +PyObject * PyObject_Repr(PyObject *); +PyObject * PyObject_Str(PyObject *); +PyObject * PyObject_ASCII(PyObject *); +PyObject * PyObject_Bytes(PyObject *); +PyObject * PyObject_RichCompare(PyObject *, PyObject *, int); +int PyObject_RichCompareBool(PyObject *, PyObject *, int); +PyObject * PyObject_GetAttrString(PyObject *, const char *); +int PyObject_SetAttrString(PyObject *, const char *, PyObject *); +int PyObject_HasAttrString(PyObject *, const char *); +PyObject * PyObject_GetAttr(PyObject *, PyObject *); +int PyObject_SetAttr(PyObject *, PyObject *, PyObject *); +int PyObject_HasAttr(PyObject *, PyObject *); #ifndef Py_LIMITED_API -PyAPI_FUNC(int) _PyObject_IsAbstract(PyObject *); -PyAPI_FUNC(PyObject *) _PyObject_GetAttrId(PyObject *, struct _Py_Identifier *); -PyAPI_FUNC(int) _PyObject_SetAttrId(PyObject *, struct _Py_Identifier *, PyObject *); -PyAPI_FUNC(int) _PyObject_HasAttrId(PyObject *, struct _Py_Identifier *); -PyAPI_FUNC(PyObject **) _PyObject_GetDictPtr(PyObject *); +int _PyObject_IsAbstract(PyObject *); +PyObject * _PyObject_GetAttrId(PyObject *, struct _Py_Identifier *); +int _PyObject_SetAttrId(PyObject *, struct _Py_Identifier *, PyObject *); +int _PyObject_HasAttrId(PyObject *, struct _Py_Identifier *); +PyObject ** _PyObject_GetDictPtr(PyObject *); #endif -PyAPI_FUNC(PyObject *) PyObject_SelfIter(PyObject *); +PyObject * PyObject_SelfIter(PyObject *); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) _PyObject_NextNotImplemented(PyObject *); +PyObject * _PyObject_NextNotImplemented(PyObject *); #endif -PyAPI_FUNC(PyObject *) PyObject_GenericGetAttr(PyObject *, PyObject *); -PyAPI_FUNC(int) PyObject_GenericSetAttr(PyObject *, +PyObject * PyObject_GenericGetAttr(PyObject *, PyObject *); +int PyObject_GenericSetAttr(PyObject *, PyObject *, PyObject *); #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 -PyAPI_FUNC(int) PyObject_GenericSetDict(PyObject *, PyObject *, void *); +int PyObject_GenericSetDict(PyObject *, PyObject *, void *); #endif -PyAPI_FUNC(Py_hash_t) PyObject_Hash(PyObject *); -PyAPI_FUNC(Py_hash_t) PyObject_HashNotImplemented(PyObject *); -PyAPI_FUNC(int) PyObject_IsTrue(PyObject *); -PyAPI_FUNC(int) PyObject_Not(PyObject *); -PyAPI_FUNC(int) PyCallable_Check(PyObject *); +Py_hash_t PyObject_Hash(PyObject *); +Py_hash_t PyObject_HashNotImplemented(PyObject *); +int PyObject_IsTrue(PyObject *); +int PyObject_Not(PyObject *); +int PyCallable_Check(PyObject *); -PyAPI_FUNC(void) PyObject_ClearWeakRefs(PyObject *); +void PyObject_ClearWeakRefs(PyObject *); #ifndef Py_LIMITED_API -PyAPI_FUNC(void) PyObject_CallFinalizer(PyObject *); -PyAPI_FUNC(int) PyObject_CallFinalizerFromDealloc(PyObject *); +void PyObject_CallFinalizer(PyObject *); +int PyObject_CallFinalizerFromDealloc(PyObject *); #endif #ifndef Py_LIMITED_API /* Same as PyObject_Generic{Get,Set}Attr, but passing the attributes dict as the last parameter. */ -PyAPI_FUNC(PyObject *) +PyObject * _PyObject_GenericGetAttrWithDict(PyObject *, PyObject *, PyObject *); -PyAPI_FUNC(int) +int _PyObject_GenericSetAttrWithDict(PyObject *, PyObject *, PyObject *, PyObject *); #endif /* !Py_LIMITED_API */ /* Helper to look up a builtin object */ #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) +PyObject * _PyObject_GetBuiltin(const char *name); #endif @@ -582,12 +585,12 @@ _PyObject_GetBuiltin(const char *name); returning the names of the current locals. In this case, if there are no current locals, NULL is returned, and PyErr_Occurred() is false. */ -PyAPI_FUNC(PyObject *) PyObject_Dir(PyObject *); +PyObject * PyObject_Dir(PyObject *); /* Helpers for printing recursive container types */ -PyAPI_FUNC(int) Py_ReprEnter(PyObject *); -PyAPI_FUNC(void) Py_ReprLeave(PyObject *); +int Py_ReprEnter(PyObject *); +void Py_ReprLeave(PyObject *); /* Flag bits for printing: */ #define Py_PRINT_RAW 1 /* No string quotes etc. */ @@ -711,10 +714,10 @@ you can count such references to the type object.) * #ifdefs (we used to do that -- it was impenetrable). */ #ifdef Py_REF_DEBUG -PyAPI_DATA(Py_ssize_t) _Py_RefTotal; -PyAPI_FUNC(void) _Py_NegativeRefcount(const char *fname, +extern Py_ssize_t _Py_RefTotal; +void _Py_NegativeRefcount(const char *fname, int lineno, PyObject *op); -PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void); +Py_ssize_t _Py_GetRefTotal(void); #define _Py_INC_REFTOTAL _Py_RefTotal++ #define _Py_DEC_REFTOTAL _Py_RefTotal-- #define _Py_REF_DEBUG_COMMA , @@ -726,7 +729,7 @@ PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void); /* Py_REF_DEBUG also controls the display of refcounts and memory block * allocations at the interactive prompt and at interpreter shutdown */ -PyAPI_FUNC(void) _PyDebug_PrintTotalRefs(void); +void _PyDebug_PrintTotalRefs(void); #define _PY_DEBUG_PRINT_TOTAL_REFS() _PyDebug_PrintTotalRefs() #else #define _Py_INC_REFTOTAL @@ -737,8 +740,8 @@ PyAPI_FUNC(void) _PyDebug_PrintTotalRefs(void); #endif /* Py_REF_DEBUG */ #ifdef COUNT_ALLOCS -PyAPI_FUNC(void) inc_count(PyTypeObject *); -PyAPI_FUNC(void) dec_count(PyTypeObject *); +void inc_count(PyTypeObject *); +void dec_count(PyTypeObject *); #define _Py_INC_TPALLOCS(OP) inc_count(Py_TYPE(OP)) #define _Py_INC_TPFREES(OP) dec_count(Py_TYPE(OP)) #define _Py_DEC_TPFREES(OP) Py_TYPE(OP)->tp_frees-- @@ -752,12 +755,12 @@ PyAPI_FUNC(void) dec_count(PyTypeObject *); #ifdef Py_TRACE_REFS /* Py_TRACE_REFS is such major surgery that we call external routines. */ -PyAPI_FUNC(void) _Py_NewReference(PyObject *); -PyAPI_FUNC(void) _Py_ForgetReference(PyObject *); -PyAPI_FUNC(void) _Py_Dealloc(PyObject *); -PyAPI_FUNC(void) _Py_PrintReferences(FILE *); -PyAPI_FUNC(void) _Py_PrintReferenceAddresses(FILE *); -PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force); +void _Py_NewReference(PyObject *); +void _Py_ForgetReference(PyObject *); +void _Py_Dealloc(PyObject *); +void _Py_PrintReferences(FILE *); +void _Py_PrintReferenceAddresses(FILE *); +void _Py_AddToAllObjects(PyObject *, int force); #else /* Without Py_TRACE_REFS, there's little enough to do that we expand code @@ -771,7 +774,7 @@ PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force); #define _Py_ForgetReference(op) _Py_INC_TPFREES(op) #ifdef Py_LIMITED_API -PyAPI_FUNC(void) _Py_Dealloc(PyObject *); +void _Py_Dealloc(PyObject *); #else #define _Py_Dealloc(op) ( \ _Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA \ @@ -891,12 +894,12 @@ PyAPI_FUNC(void) _Py_Dealloc(PyObject *); These are provided as conveniences to Python runtime embedders, so that they can have object code that is not dependent on Python compilation flags. */ -PyAPI_FUNC(void) Py_IncRef(PyObject *); -PyAPI_FUNC(void) Py_DecRef(PyObject *); +void Py_IncRef(PyObject *); +void Py_DecRef(PyObject *); #ifndef Py_LIMITED_API -PyAPI_DATA(PyTypeObject) _PyNone_Type; -PyAPI_DATA(PyTypeObject) _PyNotImplemented_Type; +extern PyTypeObject _PyNone_Type; +extern PyTypeObject _PyNotImplemented_Type; #endif /* !Py_LIMITED_API */ /* @@ -905,7 +908,7 @@ where NULL (nil) is not suitable (since NULL often means 'error'). Don't forget to apply Py_INCREF() when returning this value!!! */ -PyAPI_DATA(PyObject) _Py_NoneStruct; /* Don't use this directly */ +extern PyObject _Py_NoneStruct; /* Don't use this directly */ #define Py_None (&_Py_NoneStruct) /* Macro for returning Py_None from a function */ @@ -915,26 +918,18 @@ PyAPI_DATA(PyObject) _Py_NoneStruct; /* Don't use this directly */ Py_NotImplemented is a singleton used to signal that an operation is not implemented for a given type combination. */ -PyAPI_DATA(PyObject) _Py_NotImplementedStruct; /* Don't use this directly */ +extern PyObject _Py_NotImplementedStruct; /* Don't use this directly */ #define Py_NotImplemented (&_Py_NotImplementedStruct) /* Macro for returning Py_NotImplemented from a function */ #define Py_RETURN_NOTIMPLEMENTED \ return Py_INCREF(Py_NotImplemented), Py_NotImplemented -/* Rich comparison opcodes */ -#define Py_LT 0 -#define Py_LE 1 -#define Py_EQ 2 -#define Py_NE 3 -#define Py_GT 4 -#define Py_GE 5 - #ifndef Py_LIMITED_API /* Maps Py_LT to Py_GT, ..., Py_GE to Py_LE. * Defined in object.c. */ -PyAPI_DATA(int) _Py_SwappedOp[]; +extern int _Py_SwappedOp[]; #endif /* !Py_LIMITED_API */ @@ -1035,15 +1030,15 @@ with the call stack never exceeding a depth of PyTrash_UNWIND_LEVEL. #ifndef Py_LIMITED_API /* This is the old private API, invoked by the macros before 3.2.4. Kept for binary compatibility of extensions using the stable ABI. */ -PyAPI_FUNC(void) _PyTrash_deposit_object(PyObject*); -PyAPI_FUNC(void) _PyTrash_destroy_chain(void); -PyAPI_DATA(int) _PyTrash_delete_nesting; -PyAPI_DATA(PyObject *) _PyTrash_delete_later; +void _PyTrash_deposit_object(PyObject*); +void _PyTrash_destroy_chain(void); +extern int _PyTrash_delete_nesting; +extern PyObject * _PyTrash_delete_later; #endif /* !Py_LIMITED_API */ /* The new thread-safe private API, invoked by the macros below. */ -PyAPI_FUNC(void) _PyTrash_thread_deposit_object(PyObject*); -PyAPI_FUNC(void) _PyTrash_thread_destroy_chain(void); +void _PyTrash_thread_deposit_object(PyObject*); +void _PyTrash_thread_destroy_chain(void); #define PyTrash_UNWIND_LEVEL 50 @@ -1063,10 +1058,10 @@ PyAPI_FUNC(void) _PyTrash_thread_destroy_chain(void); } while (0); #ifndef Py_LIMITED_API -PyAPI_FUNC(void) +void _PyDebugAllocatorStats(FILE *out, const char *block_name, int num_blocks, size_t sizeof_block); -PyAPI_FUNC(void) +void _PyObject_DebugTypeStats(FILE *out); #endif /* ifndef Py_LIMITED_API */ diff --git a/third_party/python/Include/objimpl.h b/third_party/python/Include/objimpl.h index 375a82353..2babc3632 100644 --- a/third_party/python/Include/objimpl.h +++ b/third_party/python/Include/objimpl.h @@ -1,108 +1,30 @@ #ifndef Py_OBJIMPL_H #define Py_OBJIMPL_H +#include "libc/assert.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" #include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/tupleobject.h" COSMOPOLITAN_C_START_ /* clang-format off */ -/* BEWARE: - - Each interface exports both functions and macros. Extension modules should - use the functions, to ensure binary compatibility across Python versions. - Because the Python implementation is free to change internal details, and - the macros may (or may not) expose details for speed, if you do use the - macros you must recompile your extensions with each Python release. - - Never mix calls to PyObject_ memory functions with calls to the platform - malloc/realloc/ calloc/free, or with calls to PyMem_. -*/ - -/* -Functions and macros for modules that implement new object types. - - - PyObject_New(type, typeobj) allocates memory for a new object of the given - type, and initializes part of it. 'type' must be the C structure type used - to represent the object, and 'typeobj' the address of the corresponding - type object. Reference count and type pointer are filled in; the rest of - the bytes of the object are *undefined*! The resulting expression type is - 'type *'. The size of the object is determined by the tp_basicsize field - of the type object. - - - PyObject_NewVar(type, typeobj, n) is similar but allocates a variable-size - object with room for n items. In addition to the refcount and type pointer - fields, this also fills in the ob_size field. - - - PyObject_Del(op) releases the memory allocated for an object. It does not - run a destructor -- it only frees the memory. PyObject_Free is identical. - - - PyObject_Init(op, typeobj) and PyObject_InitVar(op, typeobj, n) don't - allocate memory. Instead of a 'type' parameter, they take a pointer to a - new object (allocated by an arbitrary allocator), and initialize its object - header fields. - -Note that objects created with PyObject_{New, NewVar} are allocated using the -specialized Python allocator (implemented in obmalloc.c), if WITH_PYMALLOC is -enabled. In addition, a special debugging allocator is used if PYMALLOC_DEBUG -is also #defined. - -In case a specific form of memory management is needed (for example, if you -must use the platform malloc heap(s), or shared memory, or C++ local storage or -operator new), you must first allocate the object with your custom allocator, -then pass its pointer to PyObject_{Init, InitVar} for filling in its Python- -specific fields: reference count, type pointer, possibly others. You should -be aware that Python has no control over these objects because they don't -cooperate with the Python memory manager. Such objects may not be eligible -for automatic garbage collection and you have to make sure that they are -released accordingly whenever their destructor gets called (cf. the specific -form of memory management you're using). - -Unless you have specific memory management requirements, use -PyObject_{New, NewVar, Del}. -*/ - -/* - * Raw object memory interface - * =========================== - */ - -/* Functions to call the same malloc/realloc/free as used by Python's - object allocator. If WITH_PYMALLOC is enabled, these may differ from - the platform malloc/realloc/free. The Python object allocator is - designed for fast, cache-conscious allocation of many "small" objects, - and with low hidden memory overhead. - - PyObject_Malloc(0) returns a unique non-NULL pointer if possible. - - PyObject_Realloc(NULL, n) acts like PyObject_Malloc(n). - PyObject_Realloc(p != NULL, 0) does not return NULL, or free the memory - at p. - - Returned pointers must be checked for NULL explicitly; no action is - performed on failure other than to return NULL (no warning it printed, no - exception is set, etc). - - For allocating objects, use PyObject_{New, NewVar} instead whenever - possible. The PyObject_{Malloc, Realloc, Free} family is exposed - so that you can exploit Python's small-block allocator for non-object - uses. If you must use these routines to allocate object memory, make sure - the object gets initialized via PyObject_{Init, InitVar} after obtaining - the raw memory. -*/ -PyAPI_FUNC(void *) PyObject_Malloc(size_t size); +void * PyObject_Malloc(size_t size); #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 -PyAPI_FUNC(void *) PyObject_Calloc(size_t nelem, size_t elsize); +void * PyObject_Calloc(size_t nelem, size_t elsize); #endif -PyAPI_FUNC(void *) PyObject_Realloc(void *ptr, size_t new_size); -PyAPI_FUNC(void) PyObject_Free(void *ptr); +void * PyObject_Realloc(void *ptr, size_t new_size); +void PyObject_Free(void *ptr); #ifndef Py_LIMITED_API /* This function returns the number of allocated memory blocks, regardless of size */ -PyAPI_FUNC(Py_ssize_t) _Py_GetAllocatedBlocks(void); +Py_ssize_t _Py_GetAllocatedBlocks(void); #endif /* !Py_LIMITED_API */ /* Macros */ #ifdef WITH_PYMALLOC #ifndef Py_LIMITED_API -PyAPI_FUNC(void) _PyObject_DebugMallocStats(FILE *out); +void _PyObject_DebugMallocStats(FILE *out); #endif /* #ifndef Py_LIMITED_API */ #endif @@ -120,11 +42,11 @@ PyAPI_FUNC(void) _PyObject_DebugMallocStats(FILE *out); */ /* Functions */ -PyAPI_FUNC(PyObject *) PyObject_Init(PyObject *, PyTypeObject *); -PyAPI_FUNC(PyVarObject *) PyObject_InitVar(PyVarObject *, +PyObject * PyObject_Init(PyObject *, PyTypeObject *); +PyVarObject * PyObject_InitVar(PyVarObject *, PyTypeObject *, Py_ssize_t); -PyAPI_FUNC(PyObject *) _PyObject_New(PyTypeObject *); -PyAPI_FUNC(PyVarObject *) _PyObject_NewVar(PyTypeObject *, Py_ssize_t); +PyObject * _PyObject_New(PyTypeObject *); +PyVarObject * _PyObject_NewVar(PyTypeObject *, Py_ssize_t); #define PyObject_New(type, typeobj) \ ( (type *) _PyObject_New(typeobj) ) @@ -209,10 +131,10 @@ typedef struct { } PyObjectArenaAllocator; /* Get the arena allocator. */ -PyAPI_FUNC(void) PyObject_GetArenaAllocator(PyObjectArenaAllocator *allocator); +void PyObject_GetArenaAllocator(PyObjectArenaAllocator *allocator); /* Set the arena allocator. */ -PyAPI_FUNC(void) PyObject_SetArenaAllocator(PyObjectArenaAllocator *allocator); +void PyObject_SetArenaAllocator(PyObjectArenaAllocator *allocator); #endif @@ -222,11 +144,11 @@ PyAPI_FUNC(void) PyObject_SetArenaAllocator(PyObjectArenaAllocator *allocator); */ /* C equivalent of gc.collect() which ignores the state of gc.enabled. */ -PyAPI_FUNC(Py_ssize_t) PyGC_Collect(void); +Py_ssize_t PyGC_Collect(void); #ifndef Py_LIMITED_API -PyAPI_FUNC(Py_ssize_t) _PyGC_CollectNoFail(void); -PyAPI_FUNC(Py_ssize_t) _PyGC_CollectIfEnabled(void); +Py_ssize_t _PyGC_CollectNoFail(void); +Py_ssize_t _PyGC_CollectIfEnabled(void); #endif /* Test if a type has a GC head */ @@ -236,7 +158,7 @@ PyAPI_FUNC(Py_ssize_t) _PyGC_CollectIfEnabled(void); #define PyObject_IS_GC(o) (PyType_IS_GC(Py_TYPE(o)) && \ (Py_TYPE(o)->tp_is_gc == NULL || Py_TYPE(o)->tp_is_gc(o))) -PyAPI_FUNC(PyVarObject *) _PyObject_GC_Resize(PyVarObject *, Py_ssize_t); +PyVarObject * _PyObject_GC_Resize(PyVarObject *, Py_ssize_t); #define PyObject_GC_Resize(type, op, n) \ ( (type *) _PyObject_GC_Resize((PyVarObject *)(op), (n)) ) @@ -321,14 +243,14 @@ extern PyGC_Head *_PyGC_generation0; #endif /* Py_LIMITED_API */ #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) _PyObject_GC_Malloc(size_t size); -PyAPI_FUNC(PyObject *) _PyObject_GC_Calloc(size_t size); +PyObject * _PyObject_GC_Malloc(size_t size); +PyObject * _PyObject_GC_Calloc(size_t size); #endif /* !Py_LIMITED_API */ -PyAPI_FUNC(PyObject *) _PyObject_GC_New(PyTypeObject *); -PyAPI_FUNC(PyVarObject *) _PyObject_GC_NewVar(PyTypeObject *, Py_ssize_t); -PyAPI_FUNC(void) PyObject_GC_Track(void *); -PyAPI_FUNC(void) PyObject_GC_UnTrack(void *); -PyAPI_FUNC(void) PyObject_GC_Del(void *); +PyObject * _PyObject_GC_New(PyTypeObject *); +PyVarObject * _PyObject_GC_NewVar(PyTypeObject *, Py_ssize_t); +void PyObject_GC_Track(void *); +void PyObject_GC_UnTrack(void *); +void PyObject_GC_Del(void *); #define PyObject_GC_New(type, typeobj) \ ( (type *) _PyObject_GC_New(typeobj) ) diff --git a/third_party/python/Include/odictobject.h b/third_party/python/Include/odictobject.h index 7accf3461..af70326e0 100644 --- a/third_party/python/Include/odictobject.h +++ b/third_party/python/Include/odictobject.h @@ -1,5 +1,6 @@ #ifndef Py_ODICTOBJECT_H #define Py_ODICTOBJECT_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -10,19 +11,19 @@ COSMOPOLITAN_C_START_ typedef struct _odictobject PyODictObject; -PyAPI_DATA(PyTypeObject) PyODict_Type; -PyAPI_DATA(PyTypeObject) PyODictIter_Type; -PyAPI_DATA(PyTypeObject) PyODictKeys_Type; -PyAPI_DATA(PyTypeObject) PyODictItems_Type; -PyAPI_DATA(PyTypeObject) PyODictValues_Type; +extern PyTypeObject PyODict_Type; +extern PyTypeObject PyODictIter_Type; +extern PyTypeObject PyODictKeys_Type; +extern PyTypeObject PyODictItems_Type; +extern PyTypeObject PyODictValues_Type; #define PyODict_Check(op) PyObject_TypeCheck(op, &PyODict_Type) #define PyODict_CheckExact(op) (Py_TYPE(op) == &PyODict_Type) #define PyODict_SIZE(op) ((PyDictObject *)op)->ma_used -PyAPI_FUNC(PyObject *) PyODict_New(void); -PyAPI_FUNC(int) PyODict_SetItem(PyObject *od, PyObject *key, PyObject *item); -PyAPI_FUNC(int) PyODict_DelItem(PyObject *od, PyObject *key); +PyObject * PyODict_New(void); +int PyODict_SetItem(PyObject *od, PyObject *key, PyObject *item); +int PyODict_DelItem(PyObject *od, PyObject *key); /* wrappers around PyDict* functions */ #define PyODict_GetItem(od, key) PyDict_GetItem((PyObject *)od, key) diff --git a/third_party/python/Include/op.h b/third_party/python/Include/op.h new file mode 100644 index 000000000..6d7a1140d --- /dev/null +++ b/third_party/python/Include/op.h @@ -0,0 +1,12 @@ +#ifndef COSMOPOLITAN_THIRD_PARTY_PYTHON_INCLUDE_OP_H_ +#define COSMOPOLITAN_THIRD_PARTY_PYTHON_INCLUDE_OP_H_ + +/* Rich comparison opcodes */ +#define Py_LT 0 +#define Py_LE 1 +#define Py_EQ 2 +#define Py_NE 3 +#define Py_GT 4 +#define Py_GE 5 + +#endif /* COSMOPOLITAN_THIRD_PARTY_PYTHON_INCLUDE_OP_H_ */ diff --git a/third_party/python/Include/opcode.h b/third_party/python/Include/opcode.h index edc4b82e3..d8b41c711 100644 --- a/third_party/python/Include/opcode.h +++ b/third_party/python/Include/opcode.h @@ -1,5 +1,6 @@ #ifndef Py_OPCODE_H #define Py_OPCODE_H +#include "third_party/python/Include/op.h" COSMOPOLITAN_C_START_ /* clang-format off */ /* Auto-generated by Tools/scripts/generate_opcode_h.py */ @@ -131,7 +132,6 @@ COSMOPOLITAN_C_START_ remaining private.*/ #define EXCEPT_HANDLER 257 - enum cmp_op {PyCmp_LT=Py_LT, PyCmp_LE=Py_LE, PyCmp_EQ=Py_EQ, PyCmp_NE=Py_NE, PyCmp_GT=Py_GT, PyCmp_GE=Py_GE, PyCmp_IN, PyCmp_NOT_IN, PyCmp_IS, PyCmp_IS_NOT, PyCmp_EXC_MATCH, PyCmp_BAD}; diff --git a/third_party/python/Include/osmodule.h b/third_party/python/Include/osmodule.h index 1be0db89d..73226fed9 100644 --- a/third_party/python/Include/osmodule.h +++ b/third_party/python/Include/osmodule.h @@ -1,10 +1,11 @@ #ifndef Py_OSMODULE_H #define Py_OSMODULE_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03060000 -PyAPI_FUNC(PyObject *) PyOS_FSPath(PyObject *path); +PyObject * PyOS_FSPath(PyObject *path); #endif COSMOPOLITAN_C_END_ diff --git a/third_party/python/Include/parsetok.h b/third_party/python/Include/parsetok.h index 09d230191..30b1e844e 100644 --- a/third_party/python/Include/parsetok.h +++ b/third_party/python/Include/parsetok.h @@ -1,6 +1,9 @@ #ifndef Py_LIMITED_API #ifndef Py_PARSETOK_H #define Py_PARSETOK_H +#include "third_party/python/Include/grammar.h" +#include "third_party/python/Include/node.h" +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -32,15 +35,15 @@ typedef struct { #define PyPARSE_IGNORE_COOKIE 0x0010 #define PyPARSE_BARRY_AS_BDFL 0x0020 -PyAPI_FUNC(node *) PyParser_ParseString(const char *, grammar *, int, +node * PyParser_ParseString(const char *, grammar *, int, perrdetail *); -PyAPI_FUNC(node *) PyParser_ParseFile (FILE *, const char *, grammar *, int, +node * PyParser_ParseFile (FILE *, const char *, grammar *, int, const char *, const char *, perrdetail *); -PyAPI_FUNC(node *) PyParser_ParseStringFlags(const char *, grammar *, int, +node * PyParser_ParseStringFlags(const char *, grammar *, int, perrdetail *, int); -PyAPI_FUNC(node *) PyParser_ParseFileFlags( +node * PyParser_ParseFileFlags( FILE *fp, const char *filename, /* decoded from the filesystem encoding */ const char *enc, @@ -50,7 +53,7 @@ PyAPI_FUNC(node *) PyParser_ParseFileFlags( const char *ps2, perrdetail *err_ret, int flags); -PyAPI_FUNC(node *) PyParser_ParseFileFlagsEx( +node * PyParser_ParseFileFlagsEx( FILE *fp, const char *filename, /* decoded from the filesystem encoding */ const char *enc, @@ -60,7 +63,7 @@ PyAPI_FUNC(node *) PyParser_ParseFileFlagsEx( const char *ps2, perrdetail *err_ret, int *flags); -PyAPI_FUNC(node *) PyParser_ParseFileObject( +node * PyParser_ParseFileObject( FILE *fp, PyObject *filename, const char *enc, @@ -71,21 +74,21 @@ PyAPI_FUNC(node *) PyParser_ParseFileObject( perrdetail *err_ret, int *flags); -PyAPI_FUNC(node *) PyParser_ParseStringFlagsFilename( +node * PyParser_ParseStringFlagsFilename( const char *s, const char *filename, /* decoded from the filesystem encoding */ grammar *g, int start, perrdetail *err_ret, int flags); -PyAPI_FUNC(node *) PyParser_ParseStringFlagsFilenameEx( +node * PyParser_ParseStringFlagsFilenameEx( const char *s, const char *filename, /* decoded from the filesystem encoding */ grammar *g, int start, perrdetail *err_ret, int *flags); -PyAPI_FUNC(node *) PyParser_ParseStringObject( +node * PyParser_ParseStringObject( const char *s, PyObject *filename, grammar *g, @@ -95,8 +98,8 @@ PyAPI_FUNC(node *) PyParser_ParseStringObject( /* Note that the following functions are defined in pythonrun.c, not in parsetok.c */ -PyAPI_FUNC(void) PyParser_SetError(perrdetail *); -PyAPI_FUNC(void) PyParser_ClearError(perrdetail *); +void PyParser_SetError(perrdetail *); +void PyParser_ClearError(perrdetail *); COSMOPOLITAN_C_END_ #endif /* !Py_PARSETOK_H */ diff --git a/third_party/python/Include/pgen.h b/third_party/python/Include/pgen.h index b24f0406d..288de3a11 100644 --- a/third_party/python/Include/pgen.h +++ b/third_party/python/Include/pgen.h @@ -1,5 +1,6 @@ #ifndef Py_PGEN_H #define Py_PGEN_H +#include "third_party/python/Include/grammar.h" COSMOPOLITAN_C_START_ /* clang-format off */ diff --git a/third_party/python/Include/pgenheaders.h b/third_party/python/Include/pgenheaders.h index 00e14b1f9..8fbf2ef77 100644 --- a/third_party/python/Include/pgenheaders.h +++ b/third_party/python/Include/pgenheaders.h @@ -1,12 +1,12 @@ #ifndef Py_PGENHEADERS_H #define Py_PGENHEADERS_H -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/pyport.h" COSMOPOLITAN_C_START_ /* clang-format off */ -PyAPI_FUNC(void) PySys_WriteStdout(const char *format, ...) +void PySys_WriteStdout(const char *format, ...) Py_GCC_ATTRIBUTE((format(printf, 1, 2))); -PyAPI_FUNC(void) PySys_WriteStderr(const char *format, ...) +void PySys_WriteStderr(const char *format, ...) Py_GCC_ATTRIBUTE((format(printf, 1, 2))); #define addarc _Py_addarc diff --git a/third_party/python/Include/py_curses.h b/third_party/python/Include/py_curses.h index 0eeb78d56..57b2dc351 100644 --- a/third_party/python/Include/py_curses.h +++ b/third_party/python/Include/py_curses.h @@ -1,5 +1,6 @@ #ifndef Py_CURSES_H #define Py_CURSES_H +#include "third_party/python/Include/object.h" /* clang-format off */ #if !defined(HAVE_CURSES_IS_PAD) && defined(WINDOW_HAS_FLAGS) diff --git a/third_party/python/Include/pyarena.h b/third_party/python/Include/pyarena.h index a31571198..f02410fa8 100644 --- a/third_party/python/Include/pyarena.h +++ b/third_party/python/Include/pyarena.h @@ -1,6 +1,7 @@ #ifndef Py_LIMITED_API #ifndef Py_PYARENA_H #define Py_PYARENA_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -28,8 +29,8 @@ typedef struct _arena PyArena; XXX block_new(DEFAULT_BLOCK_SIZE) returns NULL, that's passed on but XXX an exception is not set in that case). */ -PyAPI_FUNC(PyArena *) PyArena_New(void); -PyAPI_FUNC(void) PyArena_Free(PyArena *); +PyArena * PyArena_New(void); +void PyArena_Free(PyArena *); /* Mostly like malloc(), return the address of a block of memory spanning * `size` bytes, or return NULL (without setting an exception) if enough @@ -43,13 +44,13 @@ PyAPI_FUNC(void) PyArena_Free(PyArena *); * until PyArena_Free(ar) is called, at which point all pointers obtained * from the arena `ar` become invalid simultaneously. */ -PyAPI_FUNC(void *) PyArena_Malloc(PyArena *, size_t size); +void * PyArena_Malloc(PyArena *, size_t size); /* This routine isn't a proper arena allocation routine. It takes * a PyObject* and records it so that it can be DECREFed when the * arena is freed. */ -PyAPI_FUNC(int) PyArena_AddPyObject(PyArena *, PyObject *); +int PyArena_AddPyObject(PyArena *, PyObject *); COSMOPOLITAN_C_END_ #endif /* !Py_PYARENA_H */ diff --git a/third_party/python/Include/pyatomic.h b/third_party/python/Include/pyatomic.h index cc298b909..4fd5a7453 100644 --- a/third_party/python/Include/pyatomic.h +++ b/third_party/python/Include/pyatomic.h @@ -1,6 +1,7 @@ #ifndef Py_ATOMIC_H #define Py_ATOMIC_H #ifdef Py_BUILD_CORE +#include "libc/assert.h" #include "third_party/python/Include/dynamic_annotations.h" #include "third_party/python/pyconfig.h" /* clang-format off */ diff --git a/third_party/python/Include/pycapsule.h b/third_party/python/Include/pycapsule.h index e11f0097a..c6e40dfd1 100644 --- a/third_party/python/Include/pycapsule.h +++ b/third_party/python/Include/pycapsule.h @@ -1,5 +1,6 @@ #ifndef Py_CAPSULE_H #define Py_CAPSULE_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -16,37 +17,37 @@ COSMOPOLITAN_C_START_ documentation. */ -PyAPI_DATA(PyTypeObject) PyCapsule_Type; +extern PyTypeObject PyCapsule_Type; typedef void (*PyCapsule_Destructor)(PyObject *); #define PyCapsule_CheckExact(op) (Py_TYPE(op) == &PyCapsule_Type) -PyAPI_FUNC(PyObject *) PyCapsule_New( +PyObject * PyCapsule_New( void *pointer, const char *name, PyCapsule_Destructor destructor); -PyAPI_FUNC(void *) PyCapsule_GetPointer(PyObject *capsule, const char *name); +void * PyCapsule_GetPointer(PyObject *capsule, const char *name); -PyAPI_FUNC(PyCapsule_Destructor) PyCapsule_GetDestructor(PyObject *capsule); +PyCapsule_Destructor PyCapsule_GetDestructor(PyObject *capsule); -PyAPI_FUNC(const char *) PyCapsule_GetName(PyObject *capsule); +const char * PyCapsule_GetName(PyObject *capsule); -PyAPI_FUNC(void *) PyCapsule_GetContext(PyObject *capsule); +void * PyCapsule_GetContext(PyObject *capsule); -PyAPI_FUNC(int) PyCapsule_IsValid(PyObject *capsule, const char *name); +int PyCapsule_IsValid(PyObject *capsule, const char *name); -PyAPI_FUNC(int) PyCapsule_SetPointer(PyObject *capsule, void *pointer); +int PyCapsule_SetPointer(PyObject *capsule, void *pointer); -PyAPI_FUNC(int) PyCapsule_SetDestructor(PyObject *capsule, PyCapsule_Destructor destructor); +int PyCapsule_SetDestructor(PyObject *capsule, PyCapsule_Destructor destructor); -PyAPI_FUNC(int) PyCapsule_SetName(PyObject *capsule, const char *name); +int PyCapsule_SetName(PyObject *capsule, const char *name); -PyAPI_FUNC(int) PyCapsule_SetContext(PyObject *capsule, void *context); +int PyCapsule_SetContext(PyObject *capsule, void *context); -PyAPI_FUNC(void *) PyCapsule_Import( +void * PyCapsule_Import( const char *name, /* UTF-8 encoded string */ int no_block); diff --git a/third_party/python/Include/pyctype.h b/third_party/python/Include/pyctype.h index 08bfb3b5a..15f8f3923 100644 --- a/third_party/python/Include/pyctype.h +++ b/third_party/python/Include/pyctype.h @@ -1,34 +1,41 @@ #ifndef Py_LIMITED_API #ifndef PYCTYPE_H #define PYCTYPE_H -/* clang-format off */ +#include "libc/str/str.h" -#define PY_CTF_LOWER 0x01 -#define PY_CTF_UPPER 0x02 -#define PY_CTF_ALPHA (PY_CTF_LOWER|PY_CTF_UPPER) -#define PY_CTF_DIGIT 0x04 -#define PY_CTF_ALNUM (PY_CTF_ALPHA|PY_CTF_DIGIT) -#define PY_CTF_SPACE 0x08 -#define PY_CTF_XDIGIT 0x10 +#define Py_TOLOWER(c) kToLower[255 & (c)] +#define Py_TOUPPER(c) kToUpper[255 & (c)] -PyAPI_DATA(const unsigned int) _Py_ctype_table[256]; +forceinline bool Py_ISDIGIT(unsigned char c) { + return '0' <= c && c <= '9'; +} -/* Unlike their C counterparts, the following macros are not meant to - * handle an int with any of the values [EOF, 0-UCHAR_MAX]. The argument - * must be a signed/unsigned char. */ -#define Py_ISLOWER(c) (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_LOWER) -#define Py_ISUPPER(c) (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_UPPER) -#define Py_ISALPHA(c) (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_ALPHA) -#define Py_ISDIGIT(c) (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_DIGIT) -#define Py_ISXDIGIT(c) (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_XDIGIT) -#define Py_ISALNUM(c) (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_ALNUM) -#define Py_ISSPACE(c) (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_SPACE) +forceinline bool Py_ISLOWER(unsigned char c) { + return 'a' <= c && c <= 'z'; +} -PyAPI_DATA(const unsigned char) _Py_ctype_tolower[256]; -PyAPI_DATA(const unsigned char) _Py_ctype_toupper[256]; +forceinline bool Py_ISUPPER(unsigned char c) { + return 'A' <= c && c <= 'Z'; +} -#define Py_TOLOWER(c) (_Py_ctype_tolower[Py_CHARMASK(c)]) -#define Py_TOUPPER(c) (_Py_ctype_toupper[Py_CHARMASK(c)]) +forceinline bool Py_ISALPHA(unsigned char c) { + return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'); +} + +forceinline bool Py_ISALNUM(unsigned char c) { + return ('0' <= c && c <= '9') || ('A' <= c && c <= 'Z') || + ('a' <= c && c <= 'z'); +} + +forceinline bool Py_ISSPACE(unsigned char c) { + return c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\f' || + c == '\v'; +} + +forceinline bool Py_ISXDIGIT(unsigned char c) { + return ('0' <= c && c <= '9') || ('A' <= c && c <= 'F') || + ('a' <= c && c <= 'f'); +} #endif /* !PYCTYPE_H */ #endif /* !Py_LIMITED_API */ diff --git a/third_party/python/Include/pydebug.h b/third_party/python/Include/pydebug.h index 21a0113e6..b2738ec84 100644 --- a/third_party/python/Include/pydebug.h +++ b/third_party/python/Include/pydebug.h @@ -6,25 +6,25 @@ COSMOPOLITAN_C_START_ /* These global variable are defined in pylifecycle.c */ /* XXX (ncoghlan): move these declarations to pylifecycle.h? */ -PyAPI_DATA(int) Py_DebugFlag; -PyAPI_DATA(int) Py_VerboseFlag; -PyAPI_DATA(int) Py_QuietFlag; -PyAPI_DATA(int) Py_InteractiveFlag; -PyAPI_DATA(int) Py_InspectFlag; -PyAPI_DATA(int) Py_OptimizeFlag; -PyAPI_DATA(int) Py_NoSiteFlag; -PyAPI_DATA(int) Py_BytesWarningFlag; -PyAPI_DATA(int) Py_UseClassExceptionsFlag; -PyAPI_DATA(int) Py_FrozenFlag; -PyAPI_DATA(int) Py_IgnoreEnvironmentFlag; -PyAPI_DATA(int) Py_DontWriteBytecodeFlag; -PyAPI_DATA(int) Py_NoUserSiteDirectory; -PyAPI_DATA(int) Py_UnbufferedStdioFlag; -PyAPI_DATA(int) Py_HashRandomizationFlag; -PyAPI_DATA(int) Py_IsolatedFlag; +extern int Py_DebugFlag; +extern int Py_VerboseFlag; +extern int Py_QuietFlag; +extern int Py_InteractiveFlag; +extern int Py_InspectFlag; +extern int Py_OptimizeFlag; +extern int Py_NoSiteFlag; +extern int Py_BytesWarningFlag; +extern int Py_UseClassExceptionsFlag; +extern int Py_FrozenFlag; +extern int Py_IgnoreEnvironmentFlag; +extern int Py_DontWriteBytecodeFlag; +extern int Py_NoUserSiteDirectory; +extern int Py_UnbufferedStdioFlag; +extern int Py_HashRandomizationFlag; +extern int Py_IsolatedFlag; #ifdef MS_WINDOWS -PyAPI_DATA(int) Py_LegacyWindowsStdioFlag; +extern int Py_LegacyWindowsStdioFlag; #endif /* this is a wrapper around getenv() that pays attention to diff --git a/third_party/python/Include/pydtrace.h b/third_party/python/Include/pydtrace.h index 2c0103172..ffbe4d146 100644 --- a/third_party/python/Include/pydtrace.h +++ b/third_party/python/Include/pydtrace.h @@ -2,74 +2,25 @@ #define Py_DTRACE_H COSMOPOLITAN_C_START_ -#ifdef WITH_DTRACE -#include "pydtrace_probes.h" +#define PyDTrace_LINE(arg0, arg1, arg2) +#define PyDTrace_FUNCTION_ENTRY(arg0, arg1, arg2) +#define PyDTrace_FUNCTION_RETURN(arg0, arg1, arg2) +#define PyDTrace_GC_START(arg0) +#define PyDTrace_GC_DONE(arg0) +#define PyDTrace_INSTANCE_NEW_START(arg0) +#define PyDTrace_INSTANCE_NEW_DONE(arg0) +#define PyDTrace_INSTANCE_DELETE_START(arg0) +#define PyDTrace_INSTANCE_DELETE_DONE(arg0) -/* pydtrace_probes.h, on systems with DTrace, is auto-generated to include - `PyDTrace_{PROBE}` and `PyDTrace_{PROBE}_ENABLED()` macros for every probe - defined in pydtrace_provider.d. - - Calling these functions must be guarded by a `PyDTrace_{PROBE}_ENABLED()` - check to minimize performance impact when probing is off. For example: - - if (PyDTrace_FUNCTION_ENTRY_ENABLED()) - PyDTrace_FUNCTION_ENTRY(f); -*/ - -#else - -/* Without DTrace, compile to nothing. */ - -static inline void PyDTrace_LINE(const char *arg0, const char *arg1, int arg2) { -} -static inline void PyDTrace_FUNCTION_ENTRY(const char *arg0, const char *arg1, - int arg2) { -} -static inline void PyDTrace_FUNCTION_RETURN(const char *arg0, const char *arg1, - int arg2) { -} -static inline void PyDTrace_GC_START(int arg0) { -} -static inline void PyDTrace_GC_DONE(int arg0) { -} -static inline void PyDTrace_INSTANCE_NEW_START(int arg0) { -} -static inline void PyDTrace_INSTANCE_NEW_DONE(int arg0) { -} -static inline void PyDTrace_INSTANCE_DELETE_START(int arg0) { -} -static inline void PyDTrace_INSTANCE_DELETE_DONE(int arg0) { -} - -static inline int PyDTrace_LINE_ENABLED(void) { - return 0; -} -static inline int PyDTrace_FUNCTION_ENTRY_ENABLED(void) { - return 0; -} -static inline int PyDTrace_FUNCTION_RETURN_ENABLED(void) { - return 0; -} -static inline int PyDTrace_GC_START_ENABLED(void) { - return 0; -} -static inline int PyDTrace_GC_DONE_ENABLED(void) { - return 0; -} -static inline int PyDTrace_INSTANCE_NEW_START_ENABLED(void) { - return 0; -} -static inline int PyDTrace_INSTANCE_NEW_DONE_ENABLED(void) { - return 0; -} -static inline int PyDTrace_INSTANCE_DELETE_START_ENABLED(void) { - return 0; -} -static inline int PyDTrace_INSTANCE_DELETE_DONE_ENABLED(void) { - return 0; -} - -#endif /* !WITH_DTRACE */ +#define PyDTrace_LINE_ENABLED() 0 +#define PyDTrace_FUNCTION_ENTRY_ENABLED() 0 +#define PyDTrace_FUNCTION_RETURN_ENABLED() 0 +#define PyDTrace_GC_START_ENABLED() 0 +#define PyDTrace_GC_DONE_ENABLED() 0 +#define PyDTrace_INSTANCE_NEW_START_ENABLED() 0 +#define PyDTrace_INSTANCE_NEW_DONE_ENABLED() 0 +#define PyDTrace_INSTANCE_DELETE_START_ENABLED() 0 +#define PyDTrace_INSTANCE_DELETE_DONE_ENABLED() 0 COSMOPOLITAN_C_END_ #endif /* !Py_DTRACE_H */ diff --git a/third_party/python/Include/pyerrors.h b/third_party/python/Include/pyerrors.h index 97891db16..ebafe37c4 100644 --- a/third_party/python/Include/pyerrors.h +++ b/third_party/python/Include/pyerrors.h @@ -1,5 +1,7 @@ #ifndef Py_ERRORS_H #define Py_ERRORS_H +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/unicodeobject.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -71,22 +73,22 @@ typedef PyOSErrorObject PyWindowsErrorObject; /* Error handling definitions */ -PyAPI_FUNC(void) PyErr_SetNone(PyObject *); -PyAPI_FUNC(void) PyErr_SetObject(PyObject *, PyObject *); +void PyErr_SetNone(PyObject *); +void PyErr_SetObject(PyObject *, PyObject *); #ifndef Py_LIMITED_API -PyAPI_FUNC(void) _PyErr_SetKeyError(PyObject *); +void _PyErr_SetKeyError(PyObject *); #endif -PyAPI_FUNC(void) PyErr_SetString( +void PyErr_SetString( PyObject *exception, const char *string /* decoded from utf-8 */ ); -PyAPI_FUNC(PyObject *) PyErr_Occurred(void); -PyAPI_FUNC(void) PyErr_Clear(void); -PyAPI_FUNC(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **); -PyAPI_FUNC(void) PyErr_Restore(PyObject *, PyObject *, PyObject *); +PyObject * PyErr_Occurred(void); +void PyErr_Clear(void); +void PyErr_Fetch(PyObject **, PyObject **, PyObject **); +void PyErr_Restore(PyObject *, PyObject *, PyObject *); #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 -PyAPI_FUNC(void) PyErr_GetExcInfo(PyObject **, PyObject **, PyObject **); -PyAPI_FUNC(void) PyErr_SetExcInfo(PyObject *, PyObject *, PyObject *); +void PyErr_GetExcInfo(PyObject **, PyObject **, PyObject **); +void PyErr_SetExcInfo(PyObject *, PyObject *, PyObject *); #endif #if defined(__clang__) || \ @@ -99,7 +101,7 @@ PyAPI_FUNC(void) PyErr_SetExcInfo(PyObject *, PyObject *, PyObject *); #endif /* Defined in Python/pylifecycle.c */ -PyAPI_FUNC(void) Py_FatalError(const char *message) _Py_NO_RETURN; +void Py_FatalError(const char *message) _Py_NO_RETURN; #if defined(Py_DEBUG) || defined(Py_LIMITED_API) #define _PyErr_OCCURRED() PyErr_Occurred() @@ -108,23 +110,23 @@ PyAPI_FUNC(void) Py_FatalError(const char *message) _Py_NO_RETURN; #endif /* Error testing and normalization */ -PyAPI_FUNC(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *); -PyAPI_FUNC(int) PyErr_ExceptionMatches(PyObject *); -PyAPI_FUNC(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**); +int PyErr_GivenExceptionMatches(PyObject *, PyObject *); +int PyErr_ExceptionMatches(PyObject *); +void PyErr_NormalizeException(PyObject**, PyObject**, PyObject**); /* Traceback manipulation (PEP 3134) */ -PyAPI_FUNC(int) PyException_SetTraceback(PyObject *, PyObject *); -PyAPI_FUNC(PyObject *) PyException_GetTraceback(PyObject *); +int PyException_SetTraceback(PyObject *, PyObject *); +PyObject * PyException_GetTraceback(PyObject *); /* Cause manipulation (PEP 3134) */ -PyAPI_FUNC(PyObject *) PyException_GetCause(PyObject *); -PyAPI_FUNC(void) PyException_SetCause(PyObject *, PyObject *); +PyObject * PyException_GetCause(PyObject *); +void PyException_SetCause(PyObject *, PyObject *); /* Context manipulation (PEP 3134) */ -PyAPI_FUNC(PyObject *) PyException_GetContext(PyObject *); -PyAPI_FUNC(void) PyException_SetContext(PyObject *, PyObject *); +PyObject * PyException_GetContext(PyObject *); +void PyException_SetContext(PyObject *, PyObject *); #ifndef Py_LIMITED_API -PyAPI_FUNC(void) _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *); +void _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *); #endif /* */ @@ -144,119 +146,119 @@ PyAPI_FUNC(void) _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *); /* Predefined exceptions */ -PyAPI_DATA(PyObject *) PyExc_BaseException; -PyAPI_DATA(PyObject *) PyExc_Exception; +extern PyObject * PyExc_BaseException; +extern PyObject * PyExc_Exception; #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 -PyAPI_DATA(PyObject *) PyExc_StopAsyncIteration; +extern PyObject * PyExc_StopAsyncIteration; #endif -PyAPI_DATA(PyObject *) PyExc_StopIteration; -PyAPI_DATA(PyObject *) PyExc_GeneratorExit; -PyAPI_DATA(PyObject *) PyExc_ArithmeticError; -PyAPI_DATA(PyObject *) PyExc_LookupError; +extern PyObject * PyExc_StopIteration; +extern PyObject * PyExc_GeneratorExit; +extern PyObject * PyExc_ArithmeticError; +extern PyObject * PyExc_LookupError; -PyAPI_DATA(PyObject *) PyExc_AssertionError; -PyAPI_DATA(PyObject *) PyExc_AttributeError; -PyAPI_DATA(PyObject *) PyExc_BufferError; -PyAPI_DATA(PyObject *) PyExc_EOFError; -PyAPI_DATA(PyObject *) PyExc_FloatingPointError; -PyAPI_DATA(PyObject *) PyExc_OSError; -PyAPI_DATA(PyObject *) PyExc_ImportError; +extern PyObject * PyExc_AssertionError; +extern PyObject * PyExc_AttributeError; +extern PyObject * PyExc_BufferError; +extern PyObject * PyExc_EOFError; +extern PyObject * PyExc_FloatingPointError; +extern PyObject * PyExc_OSError; +extern PyObject * PyExc_ImportError; #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03060000 -PyAPI_DATA(PyObject *) PyExc_ModuleNotFoundError; +extern PyObject * PyExc_ModuleNotFoundError; #endif -PyAPI_DATA(PyObject *) PyExc_IndexError; -PyAPI_DATA(PyObject *) PyExc_KeyError; -PyAPI_DATA(PyObject *) PyExc_KeyboardInterrupt; -PyAPI_DATA(PyObject *) PyExc_MemoryError; -PyAPI_DATA(PyObject *) PyExc_NameError; -PyAPI_DATA(PyObject *) PyExc_OverflowError; -PyAPI_DATA(PyObject *) PyExc_RuntimeError; +extern PyObject * PyExc_IndexError; +extern PyObject * PyExc_KeyError; +extern PyObject * PyExc_KeyboardInterrupt; +extern PyObject * PyExc_MemoryError; +extern PyObject * PyExc_NameError; +extern PyObject * PyExc_OverflowError; +extern PyObject * PyExc_RuntimeError; #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 -PyAPI_DATA(PyObject *) PyExc_RecursionError; +extern PyObject * PyExc_RecursionError; #endif -PyAPI_DATA(PyObject *) PyExc_NotImplementedError; -PyAPI_DATA(PyObject *) PyExc_SyntaxError; -PyAPI_DATA(PyObject *) PyExc_IndentationError; -PyAPI_DATA(PyObject *) PyExc_TabError; -PyAPI_DATA(PyObject *) PyExc_ReferenceError; -PyAPI_DATA(PyObject *) PyExc_SystemError; -PyAPI_DATA(PyObject *) PyExc_SystemExit; -PyAPI_DATA(PyObject *) PyExc_TypeError; -PyAPI_DATA(PyObject *) PyExc_UnboundLocalError; -PyAPI_DATA(PyObject *) PyExc_UnicodeError; -PyAPI_DATA(PyObject *) PyExc_UnicodeEncodeError; -PyAPI_DATA(PyObject *) PyExc_UnicodeDecodeError; -PyAPI_DATA(PyObject *) PyExc_UnicodeTranslateError; -PyAPI_DATA(PyObject *) PyExc_ValueError; -PyAPI_DATA(PyObject *) PyExc_ZeroDivisionError; +extern PyObject * PyExc_NotImplementedError; +extern PyObject * PyExc_SyntaxError; +extern PyObject * PyExc_IndentationError; +extern PyObject * PyExc_TabError; +extern PyObject * PyExc_ReferenceError; +extern PyObject * PyExc_SystemError; +extern PyObject * PyExc_SystemExit; +extern PyObject * PyExc_TypeError; +extern PyObject * PyExc_UnboundLocalError; +extern PyObject * PyExc_UnicodeError; +extern PyObject * PyExc_UnicodeEncodeError; +extern PyObject * PyExc_UnicodeDecodeError; +extern PyObject * PyExc_UnicodeTranslateError; +extern PyObject * PyExc_ValueError; +extern PyObject * PyExc_ZeroDivisionError; #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 -PyAPI_DATA(PyObject *) PyExc_BlockingIOError; -PyAPI_DATA(PyObject *) PyExc_BrokenPipeError; -PyAPI_DATA(PyObject *) PyExc_ChildProcessError; -PyAPI_DATA(PyObject *) PyExc_ConnectionError; -PyAPI_DATA(PyObject *) PyExc_ConnectionAbortedError; -PyAPI_DATA(PyObject *) PyExc_ConnectionRefusedError; -PyAPI_DATA(PyObject *) PyExc_ConnectionResetError; -PyAPI_DATA(PyObject *) PyExc_FileExistsError; -PyAPI_DATA(PyObject *) PyExc_FileNotFoundError; -PyAPI_DATA(PyObject *) PyExc_InterruptedError; -PyAPI_DATA(PyObject *) PyExc_IsADirectoryError; -PyAPI_DATA(PyObject *) PyExc_NotADirectoryError; -PyAPI_DATA(PyObject *) PyExc_PermissionError; -PyAPI_DATA(PyObject *) PyExc_ProcessLookupError; -PyAPI_DATA(PyObject *) PyExc_TimeoutError; +extern PyObject * PyExc_BlockingIOError; +extern PyObject * PyExc_BrokenPipeError; +extern PyObject * PyExc_ChildProcessError; +extern PyObject * PyExc_ConnectionError; +extern PyObject * PyExc_ConnectionAbortedError; +extern PyObject * PyExc_ConnectionRefusedError; +extern PyObject * PyExc_ConnectionResetError; +extern PyObject * PyExc_FileExistsError; +extern PyObject * PyExc_FileNotFoundError; +extern PyObject * PyExc_InterruptedError; +extern PyObject * PyExc_IsADirectoryError; +extern PyObject * PyExc_NotADirectoryError; +extern PyObject * PyExc_PermissionError; +extern PyObject * PyExc_ProcessLookupError; +extern PyObject * PyExc_TimeoutError; #endif /* Compatibility aliases */ -PyAPI_DATA(PyObject *) PyExc_EnvironmentError; -PyAPI_DATA(PyObject *) PyExc_IOError; +extern PyObject * PyExc_EnvironmentError; +extern PyObject * PyExc_IOError; #ifdef MS_WINDOWS -PyAPI_DATA(PyObject *) PyExc_WindowsError; +extern PyObject * PyExc_WindowsError; #endif /* Predefined warning categories */ -PyAPI_DATA(PyObject *) PyExc_Warning; -PyAPI_DATA(PyObject *) PyExc_UserWarning; -PyAPI_DATA(PyObject *) PyExc_DeprecationWarning; -PyAPI_DATA(PyObject *) PyExc_PendingDeprecationWarning; -PyAPI_DATA(PyObject *) PyExc_SyntaxWarning; -PyAPI_DATA(PyObject *) PyExc_RuntimeWarning; -PyAPI_DATA(PyObject *) PyExc_FutureWarning; -PyAPI_DATA(PyObject *) PyExc_ImportWarning; -PyAPI_DATA(PyObject *) PyExc_UnicodeWarning; -PyAPI_DATA(PyObject *) PyExc_BytesWarning; -PyAPI_DATA(PyObject *) PyExc_ResourceWarning; +extern PyObject * PyExc_Warning; +extern PyObject * PyExc_UserWarning; +extern PyObject * PyExc_DeprecationWarning; +extern PyObject * PyExc_PendingDeprecationWarning; +extern PyObject * PyExc_SyntaxWarning; +extern PyObject * PyExc_RuntimeWarning; +extern PyObject * PyExc_FutureWarning; +extern PyObject * PyExc_ImportWarning; +extern PyObject * PyExc_UnicodeWarning; +extern PyObject * PyExc_BytesWarning; +extern PyObject * PyExc_ResourceWarning; /* Convenience functions */ -PyAPI_FUNC(int) PyErr_BadArgument(void); -PyAPI_FUNC(PyObject *) PyErr_NoMemory(void); -PyAPI_FUNC(PyObject *) PyErr_SetFromErrno(PyObject *); -PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilenameObject( +int PyErr_BadArgument(void); +PyObject * PyErr_NoMemory(void); +PyObject * PyErr_SetFromErrno(PyObject *); +PyObject * PyErr_SetFromErrnoWithFilenameObject( PyObject *, PyObject *); #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03040000 -PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilenameObjects( +PyObject * PyErr_SetFromErrnoWithFilenameObjects( PyObject *, PyObject *, PyObject *); #endif -PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilename( +PyObject * PyErr_SetFromErrnoWithFilename( PyObject *exc, const char *filename /* decoded from the filesystem encoding */ ); #if defined(MS_WINDOWS) && !defined(Py_LIMITED_API) -PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithUnicodeFilename( +PyObject * PyErr_SetFromErrnoWithUnicodeFilename( PyObject *, const Py_UNICODE *); #endif /* MS_WINDOWS */ -PyAPI_FUNC(PyObject *) PyErr_Format( +PyObject * PyErr_Format( PyObject *exception, const char *format, /* ASCII-encoded string */ ... ); #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 -PyAPI_FUNC(PyObject *) PyErr_FormatV( +PyObject * PyErr_FormatV( PyObject *exception, const char *format, va_list vargs); @@ -266,7 +268,7 @@ PyAPI_FUNC(PyObject *) PyErr_FormatV( /* Like PyErr_Format(), but saves current exception as __context__ and __cause__. */ -PyAPI_FUNC(PyObject *) _PyErr_FormatFromCause( +PyObject * _PyErr_FormatFromCause( PyObject *exception, const char *format, /* ASCII-encoded string */ ... @@ -274,56 +276,56 @@ PyAPI_FUNC(PyObject *) _PyErr_FormatFromCause( #endif #ifdef MS_WINDOWS -PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename( +PyObject * PyErr_SetFromWindowsErrWithFilename( int ierr, const char *filename /* decoded from the filesystem encoding */ ); #ifndef Py_LIMITED_API /* XXX redeclare to use WSTRING */ -PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithUnicodeFilename( +PyObject * PyErr_SetFromWindowsErrWithUnicodeFilename( int, const Py_UNICODE *); #endif -PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErr(int); -PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObject( +PyObject * PyErr_SetFromWindowsErr(int); +PyObject * PyErr_SetExcFromWindowsErrWithFilenameObject( PyObject *,int, PyObject *); #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03040000 -PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObjects( +PyObject * PyErr_SetExcFromWindowsErrWithFilenameObjects( PyObject *,int, PyObject *, PyObject *); #endif -PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilename( +PyObject * PyErr_SetExcFromWindowsErrWithFilename( PyObject *exc, int ierr, const char *filename /* decoded from the filesystem encoding */ ); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithUnicodeFilename( +PyObject * PyErr_SetExcFromWindowsErrWithUnicodeFilename( PyObject *,int, const Py_UNICODE *); #endif -PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int); +PyObject * PyErr_SetExcFromWindowsErr(PyObject *, int); #endif /* MS_WINDOWS */ #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03060000 -PyAPI_FUNC(PyObject *) PyErr_SetImportErrorSubclass(PyObject *, PyObject *, +PyObject * PyErr_SetImportErrorSubclass(PyObject *, PyObject *, PyObject *, PyObject *); #endif #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 -PyAPI_FUNC(PyObject *) PyErr_SetImportError(PyObject *, PyObject *, +PyObject * PyErr_SetImportError(PyObject *, PyObject *, PyObject *); #endif /* Export the old function so that the existing API remains available: */ -PyAPI_FUNC(void) PyErr_BadInternalCall(void); -PyAPI_FUNC(void) _PyErr_BadInternalCall(const char *filename, int lineno); +void PyErr_BadInternalCall(void); +void _PyErr_BadInternalCall(const char *filename, int lineno); /* Mask the old API with a call to the new API for code compiled under Python 2.0: */ #define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__) /* Function to create a new exception */ -PyAPI_FUNC(PyObject *) PyErr_NewException( +PyObject * PyErr_NewException( const char *name, PyObject *base, PyObject *dict); -PyAPI_FUNC(PyObject *) PyErr_NewExceptionWithDoc( +PyObject * PyErr_NewExceptionWithDoc( const char *name, const char *doc, PyObject *base, PyObject *dict); -PyAPI_FUNC(void) PyErr_WriteUnraisable(PyObject *); +void PyErr_WriteUnraisable(PyObject *); /* In exceptions.c */ #ifndef Py_LIMITED_API @@ -340,7 +342,7 @@ PyAPI_FUNC(void) PyErr_WriteUnraisable(PyObject *); * Returns a borrowed reference to the new exception (if any), NULL if the * existing exception was left in place. */ -PyAPI_FUNC(PyObject *) _PyErr_TrySetFromCause( +PyObject * _PyErr_TrySetFromCause( const char *prefix_format, /* ASCII-encoded string */ ... ); @@ -348,8 +350,8 @@ PyAPI_FUNC(PyObject *) _PyErr_TrySetFromCause( /* In sigcheck.c or signalmodule.c */ -PyAPI_FUNC(int) PyErr_CheckSignals(void); -PyAPI_FUNC(void) PyErr_SetInterrupt(void); +int PyErr_CheckSignals(void); +void PyErr_SetInterrupt(void); /* In signalmodule.c */ #ifndef Py_LIMITED_API @@ -357,24 +359,24 @@ int PySignal_SetWakeupFd(int fd); #endif /* Support for adding program text to SyntaxErrors */ -PyAPI_FUNC(void) PyErr_SyntaxLocation( +void PyErr_SyntaxLocation( const char *filename, /* decoded from the filesystem encoding */ int lineno); -PyAPI_FUNC(void) PyErr_SyntaxLocationEx( +void PyErr_SyntaxLocationEx( const char *filename, /* decoded from the filesystem encoding */ int lineno, int col_offset); #ifndef Py_LIMITED_API -PyAPI_FUNC(void) PyErr_SyntaxLocationObject( +void PyErr_SyntaxLocationObject( PyObject *filename, int lineno, int col_offset); #endif -PyAPI_FUNC(PyObject *) PyErr_ProgramText( +PyObject * PyErr_ProgramText( const char *filename, /* decoded from the filesystem encoding */ int lineno); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) PyErr_ProgramTextObject( +PyObject * PyErr_ProgramTextObject( PyObject *filename, int lineno); #endif @@ -383,7 +385,7 @@ PyAPI_FUNC(PyObject *) PyErr_ProgramTextObject( exceptions from C */ /* create a UnicodeDecodeError object */ -PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_Create( +PyObject * PyUnicodeDecodeError_Create( const char *encoding, /* UTF-8 encoded string */ const char *object, Py_ssize_t length, @@ -394,7 +396,7 @@ PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_Create( /* create a UnicodeEncodeError object */ #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_Create( +PyObject * PyUnicodeEncodeError_Create( const char *encoding, /* UTF-8 encoded string */ const Py_UNICODE *object, Py_ssize_t length, @@ -406,14 +408,14 @@ PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_Create( /* create a UnicodeTranslateError object */ #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_Create( +PyObject * PyUnicodeTranslateError_Create( const Py_UNICODE *object, Py_ssize_t length, Py_ssize_t start, Py_ssize_t end, const char *reason /* UTF-8 encoded string */ ); -PyAPI_FUNC(PyObject *) _PyUnicodeTranslateError_Create( +PyObject * _PyUnicodeTranslateError_Create( PyObject *object, Py_ssize_t start, Py_ssize_t end, @@ -422,54 +424,54 @@ PyAPI_FUNC(PyObject *) _PyUnicodeTranslateError_Create( #endif /* get the encoding attribute */ -PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetEncoding(PyObject *); -PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetEncoding(PyObject *); +PyObject * PyUnicodeEncodeError_GetEncoding(PyObject *); +PyObject * PyUnicodeDecodeError_GetEncoding(PyObject *); /* get the object attribute */ -PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetObject(PyObject *); -PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetObject(PyObject *); -PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetObject(PyObject *); +PyObject * PyUnicodeEncodeError_GetObject(PyObject *); +PyObject * PyUnicodeDecodeError_GetObject(PyObject *); +PyObject * PyUnicodeTranslateError_GetObject(PyObject *); /* get the value of the start attribute (the int * may not be NULL) return 0 on success, -1 on failure */ -PyAPI_FUNC(int) PyUnicodeEncodeError_GetStart(PyObject *, Py_ssize_t *); -PyAPI_FUNC(int) PyUnicodeDecodeError_GetStart(PyObject *, Py_ssize_t *); -PyAPI_FUNC(int) PyUnicodeTranslateError_GetStart(PyObject *, Py_ssize_t *); +int PyUnicodeEncodeError_GetStart(PyObject *, Py_ssize_t *); +int PyUnicodeDecodeError_GetStart(PyObject *, Py_ssize_t *); +int PyUnicodeTranslateError_GetStart(PyObject *, Py_ssize_t *); /* assign a new value to the start attribute return 0 on success, -1 on failure */ -PyAPI_FUNC(int) PyUnicodeEncodeError_SetStart(PyObject *, Py_ssize_t); -PyAPI_FUNC(int) PyUnicodeDecodeError_SetStart(PyObject *, Py_ssize_t); -PyAPI_FUNC(int) PyUnicodeTranslateError_SetStart(PyObject *, Py_ssize_t); +int PyUnicodeEncodeError_SetStart(PyObject *, Py_ssize_t); +int PyUnicodeDecodeError_SetStart(PyObject *, Py_ssize_t); +int PyUnicodeTranslateError_SetStart(PyObject *, Py_ssize_t); /* get the value of the end attribute (the int *may not be NULL) return 0 on success, -1 on failure */ -PyAPI_FUNC(int) PyUnicodeEncodeError_GetEnd(PyObject *, Py_ssize_t *); -PyAPI_FUNC(int) PyUnicodeDecodeError_GetEnd(PyObject *, Py_ssize_t *); -PyAPI_FUNC(int) PyUnicodeTranslateError_GetEnd(PyObject *, Py_ssize_t *); +int PyUnicodeEncodeError_GetEnd(PyObject *, Py_ssize_t *); +int PyUnicodeDecodeError_GetEnd(PyObject *, Py_ssize_t *); +int PyUnicodeTranslateError_GetEnd(PyObject *, Py_ssize_t *); /* assign a new value to the end attribute return 0 on success, -1 on failure */ -PyAPI_FUNC(int) PyUnicodeEncodeError_SetEnd(PyObject *, Py_ssize_t); -PyAPI_FUNC(int) PyUnicodeDecodeError_SetEnd(PyObject *, Py_ssize_t); -PyAPI_FUNC(int) PyUnicodeTranslateError_SetEnd(PyObject *, Py_ssize_t); +int PyUnicodeEncodeError_SetEnd(PyObject *, Py_ssize_t); +int PyUnicodeDecodeError_SetEnd(PyObject *, Py_ssize_t); +int PyUnicodeTranslateError_SetEnd(PyObject *, Py_ssize_t); /* get the value of the reason attribute */ -PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetReason(PyObject *); -PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetReason(PyObject *); -PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetReason(PyObject *); +PyObject * PyUnicodeEncodeError_GetReason(PyObject *); +PyObject * PyUnicodeDecodeError_GetReason(PyObject *); +PyObject * PyUnicodeTranslateError_GetReason(PyObject *); /* assign a new value to the reason attribute return 0 on success, -1 on failure */ -PyAPI_FUNC(int) PyUnicodeEncodeError_SetReason( +int PyUnicodeEncodeError_SetReason( PyObject *exc, const char *reason /* UTF-8 encoded string */ ); -PyAPI_FUNC(int) PyUnicodeDecodeError_SetReason( +int PyUnicodeDecodeError_SetReason( PyObject *exc, const char *reason /* UTF-8 encoded string */ ); -PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason( +int PyUnicodeTranslateError_SetReason( PyObject *exc, const char *reason /* UTF-8 encoded string */ ); @@ -488,9 +490,9 @@ PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason( # define vsnprintf _vsnprintf #endif -PyAPI_FUNC(int) PyOS_snprintf(char *str, size_t size, const char *format, ...) +int PyOS_snprintf(char *str, size_t size, const char *format, ...) Py_GCC_ATTRIBUTE((format(printf, 3, 4))); -PyAPI_FUNC(int) PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va) +int PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va) Py_GCC_ATTRIBUTE((format(printf, 3, 0))); COSMOPOLITAN_C_END_ diff --git a/third_party/python/Include/pyexpat.h b/third_party/python/Include/pyexpat.h index 8694275f2..bf05bf873 100644 --- a/third_party/python/Include/pyexpat.h +++ b/third_party/python/Include/pyexpat.h @@ -1,8 +1,10 @@ +#ifndef COSMOPOLITAN_THIRD_PARTY_PYTHON_INCLUDE_PYEXPAT_H_ +#define COSMOPOLITAN_THIRD_PARTY_PYTHON_INCLUDE_PYEXPAT_H_ +#include "third_party/python/Modules/expat/expat.h" +#include "third_party/python/Modules/expat/expat_external.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ /* clang-format off */ -/* Stuff to export relevant 'expat' entry points from pyexpat to other - * parser modules, such as cElementTree. */ - -/* note: you must import expat.h before importing this module! */ #define PyExpat_CAPI_MAGIC "pyexpat.expat_CAPI 1.1" #define PyExpat_CAPSULE_NAME "pyexpat.expat_CAPI" @@ -54,3 +56,7 @@ struct PyExpat_CAPI /* always add new stuff to the end! */ }; + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_THIRD_PARTY_PYTHON_INCLUDE_PYEXPAT_H_ */ diff --git a/third_party/python/Include/pygetopt.h b/third_party/python/Include/pygetopt.h index 0d94c380b..c16734056 100644 --- a/third_party/python/Include/pygetopt.h +++ b/third_party/python/Include/pygetopt.h @@ -4,13 +4,13 @@ COSMOPOLITAN_C_START_ /* clang-format off */ #ifndef Py_LIMITED_API -PyAPI_DATA(int) _PyOS_opterr; -PyAPI_DATA(int) _PyOS_optind; -PyAPI_DATA(wchar_t *) _PyOS_optarg; +extern int _PyOS_opterr; +extern int _PyOS_optind; +extern wchar_t * _PyOS_optarg; -PyAPI_FUNC(void) _PyOS_ResetGetOpt(void); +void _PyOS_ResetGetOpt(void); -PyAPI_FUNC(int) _PyOS_GetOpt(int argc, wchar_t **argv, wchar_t *optstring); +int _PyOS_GetOpt(int argc, wchar_t **argv, wchar_t *optstring); #endif /* !Py_LIMITED_API */ COSMOPOLITAN_C_END_ diff --git a/third_party/python/Include/pyhash.h b/third_party/python/Include/pyhash.h index bba1a804b..058d66551 100644 --- a/third_party/python/Include/pyhash.h +++ b/third_party/python/Include/pyhash.h @@ -1,13 +1,14 @@ #ifndef Py_HASH_H #define Py_HASH_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ /* Helpers for hash functions */ #ifndef Py_LIMITED_API -PyAPI_FUNC(Py_hash_t) _Py_HashDouble(double); -PyAPI_FUNC(Py_hash_t) _Py_HashPointer(void*); -PyAPI_FUNC(Py_hash_t) _Py_HashBytes(const void*, Py_ssize_t); +Py_hash_t _Py_HashDouble(double); +Py_hash_t _Py_HashPointer(void*); +Py_hash_t _Py_HashBytes(const void*, Py_ssize_t); #endif /* Prime multiplier used in string and various other hashes. */ @@ -72,11 +73,11 @@ typedef union { Py_hash_t hashsalt; } expat; } _Py_HashSecret_t; -PyAPI_DATA(_Py_HashSecret_t) _Py_HashSecret; +extern _Py_HashSecret_t _Py_HashSecret; #endif #ifdef Py_DEBUG -PyAPI_DATA(int) _Py_HashSecret_Initialized; +extern int _Py_HashSecret_Initialized; #endif @@ -89,7 +90,7 @@ typedef struct { const int seed_bits; } PyHash_FuncDef; -PyAPI_FUNC(PyHash_FuncDef*) PyHash_GetFuncDef(void); +PyHash_FuncDef* PyHash_GetFuncDef(void); #endif diff --git a/third_party/python/Include/pylifecycle.h b/third_party/python/Include/pylifecycle.h index 53d6e7e16..31d15aaf3 100644 --- a/third_party/python/Include/pylifecycle.h +++ b/third_party/python/Include/pylifecycle.h @@ -1,124 +1,126 @@ #ifndef Py_PYLIFECYCLE_H #define Py_PYLIFECYCLE_H +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pystate.h" COSMOPOLITAN_C_START_ /* clang-format off */ -PyAPI_FUNC(void) Py_SetProgramName(wchar_t *); -PyAPI_FUNC(wchar_t *) Py_GetProgramName(void); +void Py_SetProgramName(wchar_t *); +wchar_t * Py_GetProgramName(void); -PyAPI_FUNC(void) Py_SetPythonHome(wchar_t *); -PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void); +void Py_SetPythonHome(wchar_t *); +wchar_t * Py_GetPythonHome(void); #ifndef Py_LIMITED_API /* Only used by applications that embed the interpreter and need to * override the standard encoding determination mechanism */ -PyAPI_FUNC(int) Py_SetStandardStreamEncoding(const char *encoding, +int Py_SetStandardStreamEncoding(const char *encoding, const char *errors); #endif -PyAPI_FUNC(void) Py_Initialize(void); -PyAPI_FUNC(void) Py_InitializeEx(int); +void Py_Initialize(void); +void Py_InitializeEx(int); #ifndef Py_LIMITED_API -PyAPI_FUNC(void) _Py_InitializeEx_Private(int, int); +void _Py_InitializeEx_Private(int, int); #endif -PyAPI_FUNC(void) Py_Finalize(void); +void Py_Finalize(void); #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03060000 -PyAPI_FUNC(int) Py_FinalizeEx(void); +int Py_FinalizeEx(void); #endif -PyAPI_FUNC(int) Py_IsInitialized(void); -PyAPI_FUNC(PyThreadState *) Py_NewInterpreter(void); -PyAPI_FUNC(void) Py_EndInterpreter(PyThreadState *); +int Py_IsInitialized(void); +PyThreadState * Py_NewInterpreter(void); +void Py_EndInterpreter(PyThreadState *); /* Py_PyAtExit is for the atexit module, Py_AtExit is for low-level * exit functions. */ #ifndef Py_LIMITED_API -PyAPI_FUNC(void) _Py_PyAtExit(void (*func)(void)); +void _Py_PyAtExit(void (*func)(void)); #endif -PyAPI_FUNC(int) Py_AtExit(void (*func)(void)); +int Py_AtExit(void (*func)(void)); -PyAPI_FUNC(void) Py_Exit(int); +void Py_Exit(int); /* Restore signals that the interpreter has called SIG_IGN on to SIG_DFL. */ #ifndef Py_LIMITED_API -PyAPI_FUNC(void) _Py_RestoreSignals(void); +void _Py_RestoreSignals(void); -PyAPI_FUNC(int) Py_FdIsInteractive(FILE *, const char *); +int Py_FdIsInteractive(FILE *, const char *); #endif /* Bootstrap __main__ (defined in Modules/main.c) */ -PyAPI_FUNC(int) Py_Main(int argc, wchar_t **argv); +int Py_Main(int argc, wchar_t **argv); /* In getpath.c */ -PyAPI_FUNC(wchar_t *) Py_GetProgramFullPath(void); -PyAPI_FUNC(wchar_t *) Py_GetPrefix(void); -PyAPI_FUNC(wchar_t *) Py_GetExecPrefix(void); -PyAPI_FUNC(wchar_t *) Py_GetPath(void); -PyAPI_FUNC(void) Py_SetPath(const wchar_t *); +wchar_t * Py_GetProgramFullPath(void); +wchar_t * Py_GetPrefix(void); +wchar_t * Py_GetExecPrefix(void); +wchar_t * Py_GetPath(void); +void Py_SetPath(const wchar_t *); #ifdef MS_WINDOWS int _Py_CheckPython3(); #endif /* In their own files */ -PyAPI_FUNC(const char *) Py_GetVersion(void); -PyAPI_FUNC(const char *) Py_GetPlatform(void); -PyAPI_FUNC(const char *) Py_GetCopyright(void); -PyAPI_FUNC(const char *) Py_GetCompiler(void); -PyAPI_FUNC(const char *) Py_GetBuildInfo(void); +const char * Py_GetVersion(void); +const char * Py_GetPlatform(void); +const char * Py_GetCopyright(void); +const char * Py_GetCompiler(void); +const char * Py_GetBuildInfo(void); #ifndef Py_LIMITED_API -PyAPI_FUNC(const char *) _Py_gitidentifier(void); -PyAPI_FUNC(const char *) _Py_gitversion(void); +const char * _Py_gitidentifier(void); +const char * _Py_gitversion(void); #endif /* Internal -- various one-time initializations */ #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) _PyBuiltin_Init(void); -PyAPI_FUNC(PyObject *) _PySys_Init(void); -PyAPI_FUNC(void) _PyImport_Init(void); -PyAPI_FUNC(void) _PyExc_Init(PyObject * bltinmod); -PyAPI_FUNC(void) _PyImportHooks_Init(void); -PyAPI_FUNC(int) _PyFrame_Init(void); -PyAPI_FUNC(int) _PyFloat_Init(void); -PyAPI_FUNC(int) PyByteArray_Init(void); -PyAPI_FUNC(void) _PyRandom_Init(void); +PyObject * _PyBuiltin_Init(void); +PyObject * _PySys_Init(void); +void _PyImport_Init(void); +void _PyExc_Init(PyObject * bltinmod); +void _PyImportHooks_Init(void); +int _PyFrame_Init(void); +int _PyFloat_Init(void); +int PyByteArray_Init(void); +void _PyRandom_Init(void); #endif /* Various internal finalizers */ #ifndef Py_LIMITED_API -PyAPI_FUNC(void) _PyExc_Fini(void); -PyAPI_FUNC(void) _PyImport_Fini(void); -PyAPI_FUNC(void) PyMethod_Fini(void); -PyAPI_FUNC(void) PyFrame_Fini(void); -PyAPI_FUNC(void) PyCFunction_Fini(void); -PyAPI_FUNC(void) PyDict_Fini(void); -PyAPI_FUNC(void) PyTuple_Fini(void); -PyAPI_FUNC(void) PyList_Fini(void); -PyAPI_FUNC(void) PySet_Fini(void); -PyAPI_FUNC(void) PyBytes_Fini(void); -PyAPI_FUNC(void) PyByteArray_Fini(void); -PyAPI_FUNC(void) PyFloat_Fini(void); -PyAPI_FUNC(void) PyOS_FiniInterrupts(void); -PyAPI_FUNC(void) _PyGC_DumpShutdownStats(void); -PyAPI_FUNC(void) _PyGC_Fini(void); -PyAPI_FUNC(void) PySlice_Fini(void); -PyAPI_FUNC(void) _PyType_Fini(void); -PyAPI_FUNC(void) _PyRandom_Fini(void); -PyAPI_FUNC(void) PyAsyncGen_Fini(void); +void _PyExc_Fini(void); +void _PyImport_Fini(void); +void PyMethod_Fini(void); +void PyFrame_Fini(void); +void PyCFunction_Fini(void); +void PyDict_Fini(void); +void PyTuple_Fini(void); +void PyList_Fini(void); +void PySet_Fini(void); +void PyBytes_Fini(void); +void PyByteArray_Fini(void); +void PyFloat_Fini(void); +void PyOS_FiniInterrupts(void); +void _PyGC_DumpShutdownStats(void); +void _PyGC_Fini(void); +void PySlice_Fini(void); +void _PyType_Fini(void); +void _PyRandom_Fini(void); +void PyAsyncGen_Fini(void); -PyAPI_DATA(PyThreadState *) _Py_Finalizing; +extern PyThreadState * _Py_Finalizing; #endif /* Signals */ typedef void (*PyOS_sighandler_t)(int); -PyAPI_FUNC(PyOS_sighandler_t) PyOS_getsig(int); -PyAPI_FUNC(PyOS_sighandler_t) PyOS_setsig(int, PyOS_sighandler_t); +PyOS_sighandler_t PyOS_getsig(int); +PyOS_sighandler_t PyOS_setsig(int, PyOS_sighandler_t); #ifndef Py_LIMITED_API /* Random */ -PyAPI_FUNC(int) _PyOS_URandom(void *buffer, Py_ssize_t size); -PyAPI_FUNC(int) _PyOS_URandomNonblock(void *buffer, Py_ssize_t size); +int _PyOS_URandom(void *buffer, Py_ssize_t size); +int _PyOS_URandomNonblock(void *buffer, Py_ssize_t size); #endif /* !Py_LIMITED_API */ COSMOPOLITAN_C_END_ diff --git a/third_party/python/Include/pymacconfig.h b/third_party/python/Include/pymacconfig.h deleted file mode 100644 index b3ce31829..000000000 --- a/third_party/python/Include/pymacconfig.h +++ /dev/null @@ -1,104 +0,0 @@ -#ifndef PYMACCONFIG_H -#define PYMACCONFIG_H -/* clang-format off */ - - /* - * This file moves some of the autoconf magic to compile-time - * when building on MacOSX. This is needed for building 4-way - * universal binaries and for 64-bit universal binaries because - * the values redefined below aren't configure-time constant but - * only compile-time constant in these scenarios. - */ - -#if defined(__APPLE__) - -# undef SIZEOF_LONG -# undef SIZEOF_PTHREAD_T -# undef SIZEOF_SIZE_T -# undef SIZEOF_TIME_T -# undef SIZEOF_VOID_P -# undef SIZEOF__BOOL -# undef SIZEOF_UINTPTR_T -# undef SIZEOF_PTHREAD_T -# undef WORDS_BIGENDIAN -# undef DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754 -# undef DOUBLE_IS_BIG_ENDIAN_IEEE754 -# undef DOUBLE_IS_LITTLE_ENDIAN_IEEE754 -# undef HAVE_GCC_ASM_FOR_X87 - -# undef VA_LIST_IS_ARRAY -# if defined(__LP64__) && defined(__x86_64__) -# define VA_LIST_IS_ARRAY 1 -# endif - -# undef HAVE_LARGEFILE_SUPPORT -# ifndef __LP64__ -# define HAVE_LARGEFILE_SUPPORT 1 -# endif - -# undef SIZEOF_LONG -# ifdef __LP64__ -# define SIZEOF__BOOL 1 -# define SIZEOF__BOOL 1 -# define SIZEOF_LONG 8 -# define SIZEOF_PTHREAD_T 8 -# define SIZEOF_SIZE_T 8 -# define SIZEOF_TIME_T 8 -# define SIZEOF_VOID_P 8 -# define SIZEOF_UINTPTR_T 8 -# define SIZEOF_PTHREAD_T 8 -# else -# ifdef __ppc__ -# define SIZEOF__BOOL 4 -# else -# define SIZEOF__BOOL 1 -# endif -# define SIZEOF_LONG 4 -# define SIZEOF_PTHREAD_T 4 -# define SIZEOF_SIZE_T 4 -# define SIZEOF_TIME_T 4 -# define SIZEOF_VOID_P 4 -# define SIZEOF_UINTPTR_T 4 -# define SIZEOF_PTHREAD_T 4 -# endif - -# if defined(__LP64__) - /* MacOSX 10.4 (the first release to support 64-bit code - * at all) only supports 64-bit in the UNIX layer. - * Therefore suppress the toolbox-glue in 64-bit mode. - */ - - /* In 64-bit mode setpgrp always has no arguments, in 32-bit - * mode that depends on the compilation environment - */ -# undef SETPGRP_HAVE_ARG - -# endif - -#ifdef __BIG_ENDIAN__ -#define WORDS_BIGENDIAN 1 -#define DOUBLE_IS_BIG_ENDIAN_IEEE754 -#else -#define DOUBLE_IS_LITTLE_ENDIAN_IEEE754 -#endif /* __BIG_ENDIAN */ - -#ifdef __i386__ -# define HAVE_GCC_ASM_FOR_X87 -#endif - - /* - * The definition in pyconfig.h is only valid on the OS release - * where configure ran on and not necessarily for all systems where - * the executable can be used on. - * - * Specifically: OSX 10.4 has limited supported for '%zd', while - * 10.5 has full support for '%zd'. A binary built on 10.5 won't - * work properly on 10.4 unless we suppress the definition - * of PY_FORMAT_SIZE_T - */ -#undef PY_FORMAT_SIZE_T - - -#endif /* defined(_APPLE__) */ - -#endif /* PYMACCONFIG_H */ diff --git a/third_party/python/Include/pymath.h b/third_party/python/Include/pymath.h index a113e2b8a..88b9aaa1a 100644 --- a/third_party/python/Include/pymath.h +++ b/third_party/python/Include/pymath.h @@ -1,5 +1,6 @@ #ifndef Py_PYMATH_H #define Py_PYMATH_H +#include "libc/math.h" #include "third_party/python/pyconfig.h" /* clang-format off */ @@ -69,7 +70,7 @@ extern double pow(double, double); #ifndef Py_LIMITED_API #ifndef Py_FORCE_DOUBLE #ifdef X87_DOUBLE_ROUNDING -PyAPI_FUNC(double) _Py_force_double(double); +double _Py_force_double(double); #define Py_FORCE_DOUBLE(X) (_Py_force_double(X)) #else #define Py_FORCE_DOUBLE(X) (X) @@ -79,8 +80,8 @@ PyAPI_FUNC(double) _Py_force_double(double); #ifndef Py_LIMITED_API #ifdef HAVE_GCC_ASM_FOR_X87 -PyAPI_FUNC(unsigned short) _Py_get_387controlword(void); -PyAPI_FUNC(void) _Py_set_387controlword(unsigned short); +unsigned short _Py_get_387controlword(void); +void _Py_set_387controlword(unsigned short); #endif #endif diff --git a/third_party/python/Include/pymem.h b/third_party/python/Include/pymem.h index 68642f604..bd9573fe4 100644 --- a/third_party/python/Include/pymem.h +++ b/third_party/python/Include/pymem.h @@ -1,21 +1,32 @@ #ifndef Py_PYMEM_H #define Py_PYMEM_H +#include "third_party/python/Include/object.h" #include "third_party/python/Include/pyport.h" COSMOPOLITAN_C_START_ /* clang-format off */ +/* Debug-mode build with pymalloc implies PYMALLOC_DEBUG. + * PYMALLOC_DEBUG is in error if pymalloc is not in use. + */ +#if defined(Py_DEBUG) && defined(WITH_PYMALLOC) && !defined(PYMALLOC_DEBUG) +#define PYMALLOC_DEBUG +#endif +#if defined(PYMALLOC_DEBUG) && !defined(WITH_PYMALLOC) +#error "PYMALLOC_DEBUG requires WITH_PYMALLOC" +#endif + #ifndef Py_LIMITED_API -PyAPI_FUNC(void *) PyMem_RawMalloc(size_t size); -PyAPI_FUNC(void *) PyMem_RawCalloc(size_t nelem, size_t elsize); -PyAPI_FUNC(void *) PyMem_RawRealloc(void *ptr, size_t new_size); -PyAPI_FUNC(void) PyMem_RawFree(void *ptr); +void * PyMem_RawMalloc(size_t size); +void * PyMem_RawCalloc(size_t nelem, size_t elsize); +void * PyMem_RawRealloc(void *ptr, size_t new_size); +void PyMem_RawFree(void *ptr); /* Configure the Python memory allocators. Pass NULL to use default allocators. */ -PyAPI_FUNC(int) _PyMem_SetupAllocators(const char *opt); +int _PyMem_SetupAllocators(const char *opt); #ifdef WITH_PYMALLOC -PyAPI_FUNC(int) _PyMem_PymallocEnabled(void); +int _PyMem_PymallocEnabled(void); #endif /* Identifier of an address space (domain) in tracemalloc */ @@ -28,7 +39,7 @@ typedef unsigned int _PyTraceMalloc_domain_t; Return -2 if tracemalloc is disabled. If memory block is already tracked, update the existing trace. */ -PyAPI_FUNC(int) _PyTraceMalloc_Track( +int _PyTraceMalloc_Track( _PyTraceMalloc_domain_t domain, uintptr_t ptr, size_t size); @@ -37,7 +48,7 @@ PyAPI_FUNC(int) _PyTraceMalloc_Track( Do nothing if the block was not tracked. Return -2 if tracemalloc is disabled, otherwise return 0. */ -PyAPI_FUNC(int) _PyTraceMalloc_Untrack( +int _PyTraceMalloc_Untrack( _PyTraceMalloc_domain_t domain, uintptr_t ptr); @@ -49,11 +60,11 @@ PyAPI_FUNC(int) _PyTraceMalloc_Untrack( is not tracked by tracemalloc. Raise an exception and return NULL on error. */ -PyAPI_FUNC(PyObject*) _PyTraceMalloc_GetTraceback( +PyObject* _PyTraceMalloc_GetTraceback( _PyTraceMalloc_domain_t domain, uintptr_t ptr); -PyAPI_FUNC(int) _PyMem_IsFreed(void *ptr, size_t size); +int _PyMem_IsFreed(void *ptr, size_t size); #endif /* !defined(Py_LIMITED_API) */ @@ -95,16 +106,16 @@ PyAPI_FUNC(int) _PyMem_IsFreed(void *ptr, size_t size); performed on failure (no exception is set, no warning is printed, etc). */ -PyAPI_FUNC(void *) PyMem_Malloc(size_t size); +void * PyMem_Malloc(size_t size); #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 -PyAPI_FUNC(void *) PyMem_Calloc(size_t nelem, size_t elsize); +void * PyMem_Calloc(size_t nelem, size_t elsize); #endif -PyAPI_FUNC(void *) PyMem_Realloc(void *ptr, size_t new_size); -PyAPI_FUNC(void) PyMem_Free(void *ptr); +void * PyMem_Realloc(void *ptr, size_t new_size); +void PyMem_Free(void *ptr); #ifndef Py_LIMITED_API -PyAPI_FUNC(char *) _PyMem_RawStrdup(const char *str); -PyAPI_FUNC(char *) _PyMem_Strdup(const char *str); +char * _PyMem_RawStrdup(const char *str); +char * _PyMem_Strdup(const char *str); #endif /* Macros. */ @@ -185,7 +196,7 @@ typedef struct { } PyMemAllocatorEx; /* Get the memory block allocator of the specified domain. */ -PyAPI_FUNC(void) PyMem_GetAllocator(PyMemAllocatorDomain domain, +void PyMem_GetAllocator(PyMemAllocatorDomain domain, PyMemAllocatorEx *allocator); /* Set the memory block allocator of the specified domain. @@ -199,7 +210,7 @@ PyAPI_FUNC(void) PyMem_GetAllocator(PyMemAllocatorDomain domain, If the new allocator is not a hook (don't call the previous allocator), the PyMem_SetupDebugHooks() function must be called to reinstall the debug hooks on top on the new allocator. */ -PyAPI_FUNC(void) PyMem_SetAllocator(PyMemAllocatorDomain domain, +void PyMem_SetAllocator(PyMemAllocatorDomain domain, PyMemAllocatorEx *allocator); /* Setup hooks to detect bugs in the following Python memory allocator @@ -218,7 +229,7 @@ PyAPI_FUNC(void) PyMem_SetAllocator(PyMemAllocatorDomain domain, - detect write after the end of the buffer (buffer overflow) The function does nothing if Python is not compiled is debug mode. */ -PyAPI_FUNC(void) PyMem_SetupDebugHooks(void); +void PyMem_SetupDebugHooks(void); #endif COSMOPOLITAN_C_END_ diff --git a/third_party/python/Include/pyport.h b/third_party/python/Include/pyport.h index 58cae2ffa..cd7a44257 100644 --- a/third_party/python/Include/pyport.h +++ b/third_party/python/Include/pyport.h @@ -1,63 +1,15 @@ #ifndef Py_PYPORT_H #define Py_PYPORT_H -#include "libc/calls/calls.h" -#include "libc/calls/termios.h" -#include "libc/calls/weirdtypes.h" #include "libc/limits.h" -#include "libc/math.h" -#include "libc/str/str.h" -#include "libc/sysv/consts/clock.h" -#include "libc/sysv/consts/itimer.h" -#include "libc/sysv/consts/s.h" -#include "libc/sysv/consts/sched.h" -#include "libc/sysv/consts/termios.h" -#include "libc/time/time.h" +#include "third_party/python/Include/pymath.h" #include "third_party/python/pyconfig.h" /* clang-format off */ -/************************************************************************** -Symbols and macros to supply platform-independent interfaces to basic -C language & library operations whose spellings vary across platforms. - -Please try to make documentation here as clear as possible: by definition, -the stuff here is trying to illuminate C's darkest corners. - -Config #defines referenced here: - -SIGNED_RIGHT_SHIFT_ZERO_FILLS -Meaning: To be defined iff i>>j does not extend the sign bit when i is a - signed integral type and i < 0. -Used in: Py_ARITHMETIC_RIGHT_SHIFT - -Py_DEBUG -Meaning: Extra checks compiled in for debug mode. -Used in: Py_SAFE_DOWNCAST - -**************************************************************************/ - -/* typedefs for some C9X-defined synonyms for integral types. - * - * The names in Python are exactly the same as the C9X names, except with a - * Py_ prefix. Until C9X is universally implemented, this is the only way - * to ensure that Python gets reliable names that don't conflict with names - * in non-Python code that are playing their own tricks to define the C9X - * names. - * - * NOTE: don't go nuts here! Python has no use for *most* of the C9X - * integral synonyms. Only define the ones we actually need. - */ - -/* long long is required. Ensure HAVE_LONG_LONG is defined for compatibility. */ -#ifndef HAVE_LONG_LONG #define HAVE_LONG_LONG 1 -#endif -#ifndef PY_LONG_LONG #define PY_LONG_LONG long long -/* If LLONG_MAX is defined in limits.h, use that. */ #define PY_LLONG_MIN LLONG_MIN #define PY_LLONG_MAX LLONG_MAX #define PY_ULLONG_MAX ULLONG_MAX -#endif #define PY_UINT32_T uint32_t #define PY_UINT64_T uint64_t @@ -112,78 +64,11 @@ typedef Py_ssize_t Py_ssize_clean_t; typedef int Py_ssize_clean_t; #endif -/* Largest possible value of size_t. */ #define PY_SIZE_MAX SIZE_MAX - -/* Largest positive value of type Py_ssize_t. */ #define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1) >> 1)) -/* Smallest negative value of type Py_ssize_t. */ #define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX - 1) -/* PY_FORMAT_SIZE_T is a platform-specific modifier for use in a printf - * format to convert an argument with the width of a size_t or Py_ssize_t. - * C99 introduced "z" for this purpose, but not all platforms support that; - * e.g., MS compilers use "I" instead. - * - * These "high level" Python format functions interpret "z" correctly on - * all platforms (Python interprets the format string itself, and does whatever - * the platform C requires to convert a size_t/Py_ssize_t argument): - * - * PyBytes_FromFormat - * PyErr_Format - * PyBytes_FromFormatV - * PyUnicode_FromFormatV - * - * Lower-level uses require that you interpolate the correct format modifier - * yourself (e.g., calling printf, fprintf, sprintf, PyOS_snprintf); for - * example, - * - * Py_ssize_t index; - * fprintf(stderr, "index %" PY_FORMAT_SIZE_T "d sucks\n", index); - * - * That will expand to %ld, or %Id, or to something else correct for a - * Py_ssize_t on the platform. - */ -#ifndef PY_FORMAT_SIZE_T -#if SIZEOF_SIZE_T == SIZEOF_INT && !defined(__APPLE__) -#define PY_FORMAT_SIZE_T "" -#elif SIZEOF_SIZE_T == SIZEOF_LONG -#define PY_FORMAT_SIZE_T "l" -#elif defined(MS_WINDOWS) -#define PY_FORMAT_SIZE_T "I" -#else -#error "This platform's pyconfig.h needs to define PY_FORMAT_SIZE_T" -#endif -#endif - -/* Py_LOCAL can be used instead of static to get the fastest possible calling - * convention for functions that are local to a given module. - * - * Py_LOCAL_INLINE does the same thing, and also explicitly requests inlining, - * for platforms that support that. - * - * If PY_LOCAL_AGGRESSIVE is defined before python.h is included, more - * "aggressive" inlining/optimization is enabled for the entire module. This - * may lead to code bloat, and may slow things down for those reasons. It may - * also lead to errors, if the code relies on pointer aliasing. Use with - * care. - * - * NOTE: You can only use this for functions that are entirely local to a - * module; functions that are exported via method tables, callbacks, etc, - * should keep using static. - */ - -#if defined(_MSC_VER) -#if defined(PY_LOCAL_AGGRESSIVE) -/* enable more aggressive optimization for visual studio */ -#pragma optimize("agtw", on) -#endif -/* ignore warnings if the compiler decides not to inline a function */ -#pragma warning(disable : 4710) -/* fastest possible local call under MSVC */ -#define Py_LOCAL(type) static type __fastcall -#define Py_LOCAL_INLINE(type) static __inline type __fastcall -#elif defined(USE_INLINE) +#ifdef USE_INLINE #define Py_LOCAL(type) static type #define Py_LOCAL_INLINE(type) static inline type #else @@ -191,36 +76,7 @@ typedef int Py_ssize_clean_t; #define Py_LOCAL_INLINE(type) static type #endif -/* Py_MEMCPY is kept for backwards compatibility, - * see https://bugs.python.org/issue28126 */ -#define Py_MEMCPY memcpy - -COSMOPOLITAN_C_START_ - -/* Py_ARITHMETIC_RIGHT_SHIFT - * C doesn't define whether a right-shift of a signed integer sign-extends - * or zero-fills. Here a macro to force sign extension: - * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) - * Return I >> J, forcing sign extension. Arithmetically, return the - * floor of I/2**J. - * Requirements: - * I should have signed integer type. In the terminology of C99, this can - * be either one of the five standard signed integer types (signed char, - * short, int, long, long long) or an extended signed integer type. - * J is an integer >= 0 and strictly less than the number of bits in the - * type of I (because C doesn't define what happens for J outside that - * range either). - * TYPE used to specify the type of I, but is now ignored. It's been left - * in for backwards compatibility with versions <= 2.6 or 3.0. - * Caution: - * I may be evaluated more than once. - */ -#ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS -#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \ - ((I) < 0 ? -1 - ((-1 - (I)) >> (J)) : (I) >> (J)) -#else #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J)) -#endif /* Py_FORCE_EXPANSION(X) * "Simply" returns its argument. However, macro expansions within the @@ -345,8 +201,6 @@ COSMOPOLITAN_C_START_ _Py_set_387controlword(old_387controlword) #endif -/* get and set x87 control word for VisualStudio/x86 */ - /* default definitions are empty */ #ifndef HAVE_PY_SET_53BIT_PRECISION #define _Py_SET_53BIT_PRECISION_HEADER @@ -354,18 +208,6 @@ COSMOPOLITAN_C_START_ #define _Py_SET_53BIT_PRECISION_END #endif -/* If we can't guarantee 53-bit precision, don't use the code - in Python/dtoa.c, but fall back to standard code. This - means that repr of a float will be long (17 sig digits). - - Realistically, there are two things that could go wrong: - - (1) doubles aren't IEEE 754 doubles, or - (2) we're on x86 with the rounding precision set to 64-bits - (extended precision), and we don't know how to change - the rounding precision. - */ - #if !defined(DOUBLE_IS_LITTLE_ENDIAN_IEEE754) && \ !defined(DOUBLE_IS_BIG_ENDIAN_IEEE754) && \ !defined(DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754) @@ -393,73 +235,21 @@ COSMOPOLITAN_C_START_ #define Py_DEPRECATED(VERSION_UNUSED) #endif -/************************************************************************** -Prototypes that are missing from the standard include files on some systems -(and possibly only some versions of such systems.) - -Please be conservative with adding new ones, document them and enclose them -in platform-specific #ifdefs. -**************************************************************************/ - -#ifdef SOLARIS -/* Unchecked */ -extern int gethostname(char *, int); -#endif - -#ifdef HAVE__GETPTY -extern char *_getpty(int *, int, mode_t, int); -#endif - -#if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) -#if !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) -/* BSDI does not supply a prototype for the 'openpty' and 'forkpty' - functions, even though they are included in libutil. */ -extern int openpty(int *, int *, char *, struct termios *, struct winsize *); -extern pid_t forkpty(int *, char *, struct termios *, struct winsize *); -#endif /* !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) */ -#endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */ - -/* Declarations for symbol visibility. - - PyAPI_FUNC(type): Declares a public Python API function and return type - PyAPI_DATA(type): Declares public Python data and its type - PyMODINIT_FUNC: A Python module init function. If these functions are - inside the Python core, they are private to the core. - If in an extension module, it may be declared with - external linkage depending on the platform. - - As a number of platforms support/require "__declspec(dllimport/dllexport)", - we support a HAVE_DECLSPEC_DLL macro to save duplication. -*/ - -#define PyAPI_FUNC(RTYPE) RTYPE -#define PyAPI_DATA(RTYPE) extern RTYPE +#define RTYPE RTYPE #ifdef __cplusplus #define PyMODINIT_FUNC extern "C" PyObject * #else #define PyMODINIT_FUNC PyObject * #endif -/* limits.h constants that may be missing */ - #ifndef LONG_BIT #define LONG_BIT (8 * SIZEOF_LONG) #endif #if LONG_BIT != 8 * SIZEOF_LONG -/* 04-Oct-2000 LONG_BIT is apparently (mis)defined as 64 on some recent - * 32-bit platforms using gcc. We try to catch that here at compile-time - * rather than waiting for integer multiplication to trigger bogus - * overflows. - */ -#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)." +#error "LONG_BIT wrong" #endif -COSMOPOLITAN_C_END_ - -/* - * Hide GCC attributes from compilers that don't support them. - */ #if (!defined(__GNUC__) || __GNUC__ < 2 || \ (__GNUC__ == 2 && __GNUC_MINOR__ < 7)) #define Py_GCC_ATTRIBUTE(x) @@ -467,22 +257,12 @@ COSMOPOLITAN_C_END_ #define Py_GCC_ATTRIBUTE(x) __attribute__(x) #endif -/* - * Specify alignment on compilers that support it. - */ #if defined(__GNUC__) && __GNUC__ >= 3 -#define Py_ALIGNED(x) __attribute__((aligned(x))) +#define Py_ALIGNED(x) __attribute__((__aligned__(x))) #else #define Py_ALIGNED(x) #endif -/* Eliminate end-of-loop code not reached warnings from SunPro C - * when using do{...}while(0) macros - */ -#ifdef __SUNPRO_C -#pragma error_messages(off, E_END_OF_LOOP_CODE_NOT_REACHED) -#endif - #ifndef Py_LL #define Py_LL(x) x##LL #endif @@ -493,12 +273,6 @@ COSMOPOLITAN_C_END_ #define Py_VA_COPY va_copy -/* - * Convenient macros to deal with endianness of the platform. WORDS_BIGENDIAN is - * detected by configure and defined in pyconfig.h. The code in pyconfig.h - * also takes care of Apple's universal builds. - */ - #ifdef WORDS_BIGENDIAN #define PY_BIG_ENDIAN 1 #define PY_LITTLE_ENDIAN 0 diff --git a/third_party/python/Include/pystate.h b/third_party/python/Include/pystate.h index 1e52b4f33..220b632db 100644 --- a/third_party/python/Include/pystate.h +++ b/third_party/python/Include/pystate.h @@ -1,5 +1,8 @@ #ifndef Py_PYSTATE_H #define Py_PYSTATE_H +#include "third_party/python/Include/moduleobject.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyatomic.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -161,53 +164,53 @@ typedef struct _ts { #endif -PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_New(void); -PyAPI_FUNC(void) PyInterpreterState_Clear(PyInterpreterState *); -PyAPI_FUNC(void) PyInterpreterState_Delete(PyInterpreterState *); +PyInterpreterState * PyInterpreterState_New(void); +void PyInterpreterState_Clear(PyInterpreterState *); +void PyInterpreterState_Delete(PyInterpreterState *); #ifndef Py_LIMITED_API -PyAPI_FUNC(int) _PyState_AddModule(PyObject*, struct PyModuleDef*); +int _PyState_AddModule(PyObject*, struct PyModuleDef*); #endif /* !Py_LIMITED_API */ #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 /* New in 3.3 */ -PyAPI_FUNC(int) PyState_AddModule(PyObject*, struct PyModuleDef*); -PyAPI_FUNC(int) PyState_RemoveModule(struct PyModuleDef*); +int PyState_AddModule(PyObject*, struct PyModuleDef*); +int PyState_RemoveModule(struct PyModuleDef*); #endif -PyAPI_FUNC(PyObject*) PyState_FindModule(struct PyModuleDef*); +PyObject* PyState_FindModule(struct PyModuleDef*); #ifndef Py_LIMITED_API -PyAPI_FUNC(void) _PyState_ClearModules(void); +void _PyState_ClearModules(void); #endif -PyAPI_FUNC(PyThreadState *) PyThreadState_New(PyInterpreterState *); +PyThreadState * PyThreadState_New(PyInterpreterState *); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyThreadState *) _PyThreadState_Prealloc(PyInterpreterState *); -PyAPI_FUNC(void) _PyThreadState_Init(PyThreadState *); +PyThreadState * _PyThreadState_Prealloc(PyInterpreterState *); +void _PyThreadState_Init(PyThreadState *); #endif /* !Py_LIMITED_API */ -PyAPI_FUNC(void) PyThreadState_Clear(PyThreadState *); -PyAPI_FUNC(void) PyThreadState_Delete(PyThreadState *); +void PyThreadState_Clear(PyThreadState *); +void PyThreadState_Delete(PyThreadState *); #ifndef Py_LIMITED_API -PyAPI_FUNC(void) _PyThreadState_DeleteExcept(PyThreadState *tstate); +void _PyThreadState_DeleteExcept(PyThreadState *tstate); #endif /* !Py_LIMITED_API */ #ifdef WITH_THREAD -PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void); +void PyThreadState_DeleteCurrent(void); #ifndef Py_LIMITED_API -PyAPI_FUNC(void) _PyGILState_Reinit(void); +void _PyGILState_Reinit(void); #endif /* !Py_LIMITED_API */ #endif /* Return the current thread state. The global interpreter lock must be held. * When the current thread state is NULL, this issues a fatal error (so that * the caller needn't check for NULL). */ -PyAPI_FUNC(PyThreadState *) PyThreadState_Get(void); +PyThreadState * PyThreadState_Get(void); #ifndef Py_LIMITED_API /* Similar to PyThreadState_Get(), but don't issue a fatal error * if it is NULL. */ -PyAPI_FUNC(PyThreadState *) _PyThreadState_UncheckedGet(void); +PyThreadState * _PyThreadState_UncheckedGet(void); #endif /* !Py_LIMITED_API */ -PyAPI_FUNC(PyThreadState *) PyThreadState_Swap(PyThreadState *); -PyAPI_FUNC(PyObject *) PyThreadState_GetDict(void); -PyAPI_FUNC(int) PyThreadState_SetAsyncExc(long, PyObject *); +PyThreadState * PyThreadState_Swap(PyThreadState *); +PyObject * PyThreadState_GetDict(void); +int PyThreadState_SetAsyncExc(long, PyObject *); /* Variable and macro for in-line access to current thread state */ @@ -215,7 +218,7 @@ PyAPI_FUNC(int) PyThreadState_SetAsyncExc(long, PyObject *); /* Assuming the current thread holds the GIL, this is the PyThreadState for the current thread. */ #ifdef Py_BUILD_CORE -PyAPI_DATA(_Py_atomic_address) _PyThreadState_Current; +extern _Py_atomic_address _PyThreadState_Current; # define PyThreadState_GET() \ ((PyThreadState*)_Py_atomic_load_relaxed(&_PyThreadState_Current)) #else @@ -249,7 +252,7 @@ typedef Failure is a fatal error. */ -PyAPI_FUNC(PyGILState_STATE) PyGILState_Ensure(void); +PyGILState_STATE PyGILState_Ensure(void); /* Release any resources previously acquired. After this call, Python's state will be the same as it was prior to the corresponding @@ -259,7 +262,7 @@ PyAPI_FUNC(PyGILState_STATE) PyGILState_Ensure(void); Every call to PyGILState_Ensure must be matched by a call to PyGILState_Release on the same thread. */ -PyAPI_FUNC(void) PyGILState_Release(PyGILState_STATE); +void PyGILState_Release(PyGILState_STATE); /* Helper/diagnostic function - get the current thread state for this thread. May return NULL if no GILState API has been used @@ -267,25 +270,25 @@ PyAPI_FUNC(void) PyGILState_Release(PyGILState_STATE); thread-state, even if no auto-thread-state call has been made on the main thread. */ -PyAPI_FUNC(PyThreadState *) PyGILState_GetThisThreadState(void); +PyThreadState * PyGILState_GetThisThreadState(void); #ifndef Py_LIMITED_API /* Issue #26558: Flag to disable PyGILState_Check(). If set to non-zero, PyGILState_Check() always return 1. */ -PyAPI_DATA(int) _PyGILState_check_enabled; +extern int _PyGILState_check_enabled; /* Helper/diagnostic function - return 1 if the current thread currently holds the GIL, 0 otherwise. The function returns 1 if _PyGILState_check_enabled is non-zero. */ -PyAPI_FUNC(int) PyGILState_Check(void); +int PyGILState_Check(void); /* Unsafe function to get the single PyInterpreterState used by this process' GILState implementation. Return NULL before _PyGILState_Init() is called and after _PyGILState_Fini() is called. */ -PyAPI_FUNC(PyInterpreterState *) _PyGILState_GetInterpreterStateUnsafe(void); +PyInterpreterState * _PyGILState_GetInterpreterStateUnsafe(void); #endif #endif /* #ifdef WITH_THREAD */ @@ -294,23 +297,23 @@ PyAPI_FUNC(PyInterpreterState *) _PyGILState_GetInterpreterStateUnsafe(void); thread id to that thread's current frame. */ #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) _PyThread_CurrentFrames(void); +PyObject * _PyThread_CurrentFrames(void); #endif /* Routines for advanced debuggers, requested by David Beazley. Don't use unless you know what you are doing! */ #ifndef Py_LIMITED_API -PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Head(void); -PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Next(PyInterpreterState *); -PyAPI_FUNC(PyThreadState *) PyInterpreterState_ThreadHead(PyInterpreterState *); -PyAPI_FUNC(PyThreadState *) PyThreadState_Next(PyThreadState *); +PyInterpreterState * PyInterpreterState_Head(void); +PyInterpreterState * PyInterpreterState_Next(PyInterpreterState *); +PyThreadState * PyInterpreterState_ThreadHead(PyInterpreterState *); +PyThreadState * PyThreadState_Next(PyThreadState *); typedef struct _frame *(*PyThreadFrameGetter)(PyThreadState *self_); #endif /* hook for PyEval_GetFrame(), requested for Psyco */ #ifndef Py_LIMITED_API -PyAPI_DATA(PyThreadFrameGetter) _PyThreadState_GetFrame; +extern PyThreadFrameGetter _PyThreadState_GetFrame; #endif COSMOPOLITAN_C_END_ diff --git a/third_party/python/Include/pystrcmp.h b/third_party/python/Include/pystrcmp.h index 2a62ff228..275b3bca0 100644 --- a/third_party/python/Include/pystrcmp.h +++ b/third_party/python/Include/pystrcmp.h @@ -1,10 +1,11 @@ #ifndef Py_STRCMP_H #define Py_STRCMP_H +#include "third_party/python/Include/pyport.h" COSMOPOLITAN_C_START_ /* clang-format off */ -PyAPI_FUNC(int) PyOS_mystrnicmp(const char *, const char *, Py_ssize_t); -PyAPI_FUNC(int) PyOS_mystricmp(const char *, const char *); +int PyOS_mystrnicmp(const char *, const char *, Py_ssize_t); +int PyOS_mystricmp(const char *, const char *); #ifdef MS_WINDOWS #define PyOS_strnicmp strnicmp diff --git a/third_party/python/Include/pystrhex.h b/third_party/python/Include/pystrhex.h index bf5a44e3a..4da0d6a39 100644 --- a/third_party/python/Include/pystrhex.h +++ b/third_party/python/Include/pystrhex.h @@ -1,13 +1,14 @@ #ifndef Py_STRHEX_H #define Py_STRHEX_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ #ifndef Py_LIMITED_API /* Returns a str() containing the hex representation of argbuf. */ -PyAPI_FUNC(PyObject*) _Py_strhex(const char* argbuf, const Py_ssize_t arglen); +PyObject* _Py_strhex(const char* argbuf, const Py_ssize_t arglen); /* Returns a bytes() containing the ASCII hex representation of argbuf. */ -PyAPI_FUNC(PyObject*) _Py_strhex_bytes(const char* argbuf, const Py_ssize_t arglen); +PyObject* _Py_strhex_bytes(const char* argbuf, const Py_ssize_t arglen); #endif /* !Py_LIMITED_API */ COSMOPOLITAN_C_END_ diff --git a/third_party/python/Include/pystrtod.h b/third_party/python/Include/pystrtod.h index b1055f060..43d55a137 100644 --- a/third_party/python/Include/pystrtod.h +++ b/third_party/python/Include/pystrtod.h @@ -1,26 +1,27 @@ #ifndef Py_STRTOD_H #define Py_STRTOD_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ -PyAPI_FUNC(double) PyOS_string_to_double(const char *str, +double PyOS_string_to_double(const char *str, char **endptr, PyObject *overflow_exception); /* The caller is responsible for calling PyMem_Free to free the buffer that's is returned. */ -PyAPI_FUNC(char *) PyOS_double_to_string(double val, +char * PyOS_double_to_string(double val, char format_code, int precision, int flags, int *type); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) _Py_string_to_number_with_underscores( +PyObject * _Py_string_to_number_with_underscores( const char *str, Py_ssize_t len, const char *what, PyObject *obj, void *arg, PyObject *(*innerfunc)(const char *, Py_ssize_t, void *)); -PyAPI_FUNC(double) _Py_parse_inf_or_nan(const char *p, char **endptr); +double _Py_parse_inf_or_nan(const char *p, char **endptr); #endif diff --git a/third_party/python/Include/pythonrun.h b/third_party/python/Include/pythonrun.h index 478a27a0c..0ceb45611 100644 --- a/third_party/python/Include/pythonrun.h +++ b/third_party/python/Include/pythonrun.h @@ -1,5 +1,8 @@ #ifndef Py_PYTHONRUN_H #define Py_PYTHONRUN_H +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyarena.h" +#include "third_party/python/Include/pystate.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -20,44 +23,44 @@ typedef struct { #endif #ifndef Py_LIMITED_API -PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *); -PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *); -PyAPI_FUNC(int) PyRun_AnyFileExFlags( +int PyRun_SimpleStringFlags(const char *, PyCompilerFlags *); +int PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *); +int PyRun_AnyFileExFlags( FILE *fp, const char *filename, /* decoded from the filesystem encoding */ int closeit, PyCompilerFlags *flags); -PyAPI_FUNC(int) PyRun_SimpleFileExFlags( +int PyRun_SimpleFileExFlags( FILE *fp, const char *filename, /* decoded from the filesystem encoding */ int closeit, PyCompilerFlags *flags); -PyAPI_FUNC(int) PyRun_InteractiveOneFlags( +int PyRun_InteractiveOneFlags( FILE *fp, const char *filename, /* decoded from the filesystem encoding */ PyCompilerFlags *flags); -PyAPI_FUNC(int) PyRun_InteractiveOneObject( +int PyRun_InteractiveOneObject( FILE *fp, PyObject *filename, PyCompilerFlags *flags); -PyAPI_FUNC(int) PyRun_InteractiveLoopFlags( +int PyRun_InteractiveLoopFlags( FILE *fp, const char *filename, /* decoded from the filesystem encoding */ PyCompilerFlags *flags); -PyAPI_FUNC(struct _mod *) PyParser_ASTFromString( +struct _mod * PyParser_ASTFromString( const char *s, const char *filename, /* decoded from the filesystem encoding */ int start, PyCompilerFlags *flags, PyArena *arena); -PyAPI_FUNC(struct _mod *) PyParser_ASTFromStringObject( +struct _mod * PyParser_ASTFromStringObject( const char *s, PyObject *filename, int start, PyCompilerFlags *flags, PyArena *arena); -PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile( +struct _mod * PyParser_ASTFromFile( FILE *fp, const char *filename, /* decoded from the filesystem encoding */ const char* enc, @@ -67,7 +70,7 @@ PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile( PyCompilerFlags *flags, int *errcode, PyArena *arena); -PyAPI_FUNC(struct _mod *) PyParser_ASTFromFileObject( +struct _mod * PyParser_ASTFromFileObject( FILE *fp, PyObject *filename, const char* enc, @@ -85,21 +88,21 @@ PyAPI_FUNC(struct _mod *) PyParser_ASTFromFileObject( #define PyParser_SimpleParseFile(FP, S, B) \ PyParser_SimpleParseFileFlags(FP, S, B, 0) #endif -PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(const char *, int, +struct _node * PyParser_SimpleParseStringFlags(const char *, int, int); #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 -PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlagsFilename(const char *, +struct _node * PyParser_SimpleParseStringFlagsFilename(const char *, const char *, int, int); #endif -PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *, +struct _node * PyParser_SimpleParseFileFlags(FILE *, const char *, int, int); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *, +PyObject * PyRun_StringFlags(const char *, int, PyObject *, PyObject *, PyCompilerFlags *); -PyAPI_FUNC(PyObject *) PyRun_FileExFlags( +PyObject * PyRun_FileExFlags( FILE *fp, const char *filename, /* decoded from the filesystem encoding */ int start, @@ -110,36 +113,36 @@ PyAPI_FUNC(PyObject *) PyRun_FileExFlags( #endif #ifdef Py_LIMITED_API -PyAPI_FUNC(PyObject *) Py_CompileString(const char *, const char *, int); +PyObject * Py_CompileString(const char *, const char *, int); #else #define Py_CompileString(str, p, s) Py_CompileStringExFlags(str, p, s, NULL, -1) #define Py_CompileStringFlags(str, p, s, f) Py_CompileStringExFlags(str, p, s, f, -1) -PyAPI_FUNC(PyObject *) Py_CompileStringExFlags( +PyObject * Py_CompileStringExFlags( const char *str, const char *filename, /* decoded from the filesystem encoding */ int start, PyCompilerFlags *flags, int optimize); -PyAPI_FUNC(PyObject *) Py_CompileStringObject( +PyObject * Py_CompileStringObject( const char *str, PyObject *filename, int start, PyCompilerFlags *flags, int optimize); #endif -PyAPI_FUNC(struct symtable *) Py_SymtableString( +struct symtable * Py_SymtableString( const char *str, const char *filename, /* decoded from the filesystem encoding */ int start); #ifndef Py_LIMITED_API -PyAPI_FUNC(struct symtable *) Py_SymtableStringObject( +struct symtable * Py_SymtableStringObject( const char *str, PyObject *filename, int start); #endif -PyAPI_FUNC(void) PyErr_Print(void); -PyAPI_FUNC(void) PyErr_PrintEx(int); -PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *); +void PyErr_Print(void); +void PyErr_PrintEx(int); +void PyErr_Display(PyObject *, PyObject *, PyObject *); #ifndef Py_LIMITED_API /* Use macros for a bunch of old variants */ @@ -164,12 +167,12 @@ PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *); /* Stuff with no proper home (yet) */ #ifndef Py_LIMITED_API -PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, const char *); +char * PyOS_Readline(FILE *, FILE *, const char *); #endif -PyAPI_DATA(int) (*PyOS_InputHook)(void); -PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, const char *); +extern int (*PyOS_InputHook)(void); +extern char *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, const char *); #ifndef Py_LIMITED_API -PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState; +extern PyThreadState* _PyOS_ReadlineTState; #endif /* Stack size, in "pointers" (so we get extra safety margins @@ -184,7 +187,7 @@ PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState; #ifdef USE_STACKCHECK /* Check that we aren't overflowing our stack */ -PyAPI_FUNC(int) PyOS_CheckStack(void); +int PyOS_CheckStack(void); #endif COSMOPOLITAN_C_END_ diff --git a/third_party/python/Include/pythread.h b/third_party/python/Include/pythread.h index c3a5701a4..be42b75fc 100644 --- a/third_party/python/Include/pythread.h +++ b/third_party/python/Include/pythread.h @@ -1,5 +1,6 @@ #ifndef Py_PYTHREAD_H #define Py_PYTHREAD_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -14,14 +15,14 @@ typedef enum PyLockStatus { PY_LOCK_INTR } PyLockStatus; -PyAPI_FUNC(void) PyThread_init_thread(void); -PyAPI_FUNC(long) PyThread_start_new_thread(void (*)(void *), void *); -PyAPI_FUNC(void) PyThread_exit_thread(void); -PyAPI_FUNC(long) PyThread_get_thread_ident(void); +void PyThread_init_thread(void); +long PyThread_start_new_thread(void (*)(void *), void *); +void PyThread_exit_thread(void); +long PyThread_get_thread_ident(void); -PyAPI_FUNC(PyThread_type_lock) PyThread_allocate_lock(void); -PyAPI_FUNC(void) PyThread_free_lock(PyThread_type_lock); -PyAPI_FUNC(int) PyThread_acquire_lock(PyThread_type_lock, int); +PyThread_type_lock PyThread_allocate_lock(void); +void PyThread_free_lock(PyThread_type_lock); +int PyThread_acquire_lock(PyThread_type_lock, int); #define WAIT_LOCK 1 #define NOWAIT_LOCK 0 @@ -57,28 +58,28 @@ PyAPI_FUNC(int) PyThread_acquire_lock(PyThread_type_lock, int); call will return PY_LOCK_INTR. The caller may reattempt to acquire the lock. */ -PyAPI_FUNC(PyLockStatus) PyThread_acquire_lock_timed(PyThread_type_lock, +PyLockStatus PyThread_acquire_lock_timed(PyThread_type_lock, PY_TIMEOUT_T microseconds, int intr_flag); -PyAPI_FUNC(void) PyThread_release_lock(PyThread_type_lock); +void PyThread_release_lock(PyThread_type_lock); -PyAPI_FUNC(size_t) PyThread_get_stacksize(void); -PyAPI_FUNC(int) PyThread_set_stacksize(size_t); +size_t PyThread_get_stacksize(void); +int PyThread_set_stacksize(size_t); #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 -PyAPI_FUNC(PyObject*) PyThread_GetInfo(void); +PyObject* PyThread_GetInfo(void); #endif /* Thread Local Storage (TLS) API */ -PyAPI_FUNC(int) PyThread_create_key(void); -PyAPI_FUNC(void) PyThread_delete_key(int); -PyAPI_FUNC(int) PyThread_set_key_value(int, void *); -PyAPI_FUNC(void *) PyThread_get_key_value(int); -PyAPI_FUNC(void) PyThread_delete_key_value(int key); +int PyThread_create_key(void); +void PyThread_delete_key(int); +int PyThread_set_key_value(int, void *); +void * PyThread_get_key_value(int); +void PyThread_delete_key_value(int key); /* Cleanup after a fork */ -PyAPI_FUNC(void) PyThread_ReInitTLS(void); +void PyThread_ReInitTLS(void); COSMOPOLITAN_C_END_ #endif /* !Py_PYTHREAD_H */ diff --git a/third_party/python/Include/pytime.h b/third_party/python/Include/pytime.h index 4116d942c..db0b7eb28 100644 --- a/third_party/python/Include/pytime.h +++ b/third_party/python/Include/pytime.h @@ -1,205 +1,63 @@ #ifndef Py_LIMITED_API #ifndef Py_PYTIME_H #define Py_PYTIME_H +#include "libc/calls/struct/timespec.h" +#include "libc/calls/struct/timeval.h" +#include "libc/calls/weirdtypes.h" +#include "libc/time/struct/tm.h" #include "third_party/python/Include/object.h" #include "third_party/python/pyconfig.h" COSMOPOLITAN_C_START_ -/* clang-format off */ -/************************************************************************** -Symbols and macros to supply platform-independent interfaces to time related -functions and constants -**************************************************************************/ - -/* _PyTime_t: Python timestamp with subsecond precision. It can be used to - store a duration, and so indirectly a date (related to another date, like - UNIX epoch). */ typedef int64_t _PyTime_t; #define _PyTime_MIN PY_LLONG_MIN #define _PyTime_MAX PY_LLONG_MAX typedef enum { - /* Round towards minus infinity (-inf). - For example, used to read a clock. */ - _PyTime_ROUND_FLOOR=0, - /* Round towards infinity (+inf). - For example, used for timeout to wait "at least" N seconds. */ - _PyTime_ROUND_CEILING=1, - /* Round to nearest with ties going to nearest even integer. - For example, used to round from a Python float. */ - _PyTime_ROUND_HALF_EVEN=2, - /* Round away from zero - For example, used for timeout. _PyTime_ROUND_CEILING rounds - -1e-9 to 0 milliseconds which causes bpo-31786 issue. - _PyTime_ROUND_UP rounds -1e-9 to -1 millisecond which keeps - the timeout sign as expected. select.poll(timeout) must block - for negative values." */ - _PyTime_ROUND_UP=3, - /* _PyTime_ROUND_TIMEOUT (an alias for _PyTime_ROUND_UP) should be - used for timeouts. */ - _PyTime_ROUND_TIMEOUT = _PyTime_ROUND_UP + _PyTime_ROUND_FLOOR = 0, + _PyTime_ROUND_CEILING = 1, + _PyTime_ROUND_HALF_EVEN = 2, + _PyTime_ROUND_UP = 3, + _PyTime_ROUND_TIMEOUT = _PyTime_ROUND_UP } _PyTime_round_t; +PyObject *_PyLong_FromTime_t(time_t); +time_t _PyLong_AsTime_t(PyObject *); +int _PyTime_ObjectToTime_t(PyObject *, time_t *, _PyTime_round_t); +int _PyTime_ObjectToTimeval(PyObject *, time_t *, long *, _PyTime_round_t); +int _PyTime_ObjectToTimespec(PyObject *, time_t *, long *, _PyTime_round_t); -/* Convert a time_t to a PyLong. */ -PyAPI_FUNC(PyObject *) _PyLong_FromTime_t( - time_t sec); +_PyTime_t _PyTime_FromSeconds(int); -/* Convert a PyLong to a time_t. */ -PyAPI_FUNC(time_t) _PyLong_AsTime_t( - PyObject *obj); - -/* Convert a number of seconds, int or float, to time_t. */ -PyAPI_FUNC(int) _PyTime_ObjectToTime_t( - PyObject *obj, - time_t *sec, - _PyTime_round_t); - -/* Convert a number of seconds, int or float, to a timeval structure. - usec is in the range [0; 999999] and rounded towards zero. - For example, -1.2 is converted to (-2, 800000). */ -PyAPI_FUNC(int) _PyTime_ObjectToTimeval( - PyObject *obj, - time_t *sec, - long *usec, - _PyTime_round_t); - -/* Convert a number of seconds, int or float, to a timespec structure. - nsec is in the range [0; 999999999] and rounded towards zero. - For example, -1.2 is converted to (-2, 800000000). */ -PyAPI_FUNC(int) _PyTime_ObjectToTimespec( - PyObject *obj, - time_t *sec, - long *nsec, - _PyTime_round_t); - - -/* Create a timestamp from a number of seconds. */ -PyAPI_FUNC(_PyTime_t) _PyTime_FromSeconds(int seconds); - -/* Macro to create a timestamp from a number of seconds, no integer overflow. - Only use the macro for small values, prefer _PyTime_FromSeconds(). */ #define _PYTIME_FROMSECONDS(seconds) \ - ((_PyTime_t)(seconds) * (1000 * 1000 * 1000)) + ((_PyTime_t)(seconds) * (1000 * 1000 * 1000)) -/* Create a timestamp from a number of nanoseconds. */ -PyAPI_FUNC(_PyTime_t) _PyTime_FromNanoseconds(long long ns); +_PyTime_t _PyTime_FromNanoseconds(long long); +int _PyTime_FromSecondsObject(_PyTime_t *, PyObject *, _PyTime_round_t); +int _PyTime_FromMillisecondsObject(_PyTime_t *, PyObject *, _PyTime_round_t); +double _PyTime_AsSecondsDouble(_PyTime_t); +_PyTime_t _PyTime_AsMilliseconds(_PyTime_t, _PyTime_round_t); +_PyTime_t _PyTime_AsMicroseconds(_PyTime_t, _PyTime_round_t); +PyObject *_PyTime_AsNanosecondsObject(_PyTime_t); +int _PyTime_AsTimeval(_PyTime_t, struct timeval *, _PyTime_round_t); +int _PyTime_AsTimeval_noraise(_PyTime_t, struct timeval *, _PyTime_round_t); +int _PyTime_AsTimevalTime_t(_PyTime_t, time_t *, int *, _PyTime_round_t); +int _PyTime_AsTimespec(_PyTime_t, struct timespec *); +_PyTime_t _PyTime_GetSystemClock(void); +_PyTime_t _PyTime_GetMonotonicClock(void); -/* Convert a number of seconds (Python float or int) to a timetamp. - Raise an exception and return -1 on error, return 0 on success. */ -PyAPI_FUNC(int) _PyTime_FromSecondsObject(_PyTime_t *t, - PyObject *obj, - _PyTime_round_t round); - -/* Convert a number of milliseconds (Python float or int, 10^-3) to a timetamp. - Raise an exception and return -1 on error, return 0 on success. */ -PyAPI_FUNC(int) _PyTime_FromMillisecondsObject(_PyTime_t *t, - PyObject *obj, - _PyTime_round_t round); - -/* Convert a timestamp to a number of seconds as a C double. */ -PyAPI_FUNC(double) _PyTime_AsSecondsDouble(_PyTime_t t); - -/* Convert timestamp to a number of milliseconds (10^-3 seconds). */ -PyAPI_FUNC(_PyTime_t) _PyTime_AsMilliseconds(_PyTime_t t, - _PyTime_round_t round); - -/* Convert timestamp to a number of microseconds (10^-6 seconds). */ -PyAPI_FUNC(_PyTime_t) _PyTime_AsMicroseconds(_PyTime_t t, - _PyTime_round_t round); - -/* Convert timestamp to a number of nanoseconds (10^-9 seconds) as a Python int - object. */ -PyAPI_FUNC(PyObject *) _PyTime_AsNanosecondsObject(_PyTime_t t); - -/* Convert a timestamp to a timeval structure (microsecond resolution). - tv_usec is always positive. - Raise an exception and return -1 if the conversion overflowed, - return 0 on success. */ -PyAPI_FUNC(int) _PyTime_AsTimeval(_PyTime_t t, - struct timeval *tv, - _PyTime_round_t round); - -/* Similar to _PyTime_AsTimeval(), but don't raise an exception on error. */ -PyAPI_FUNC(int) _PyTime_AsTimeval_noraise(_PyTime_t t, - struct timeval *tv, - _PyTime_round_t round); - -/* Convert a timestamp to a number of seconds (secs) and microseconds (us). - us is always positive. This function is similar to _PyTime_AsTimeval() - except that secs is always a time_t type, whereas the timeval structure - uses a C long for tv_sec on Windows. - Raise an exception and return -1 if the conversion overflowed, - return 0 on success. */ -PyAPI_FUNC(int) _PyTime_AsTimevalTime_t( - _PyTime_t t, - time_t *secs, - int *us, - _PyTime_round_t round); - -#if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_KQUEUE) -/* Convert a timestamp to a timespec structure (nanosecond resolution). - tv_nsec is always positive. - Raise an exception and return -1 on error, return 0 on success. */ -PyAPI_FUNC(int) _PyTime_AsTimespec(_PyTime_t t, struct timespec *ts); -#endif - -/* Get the current time from the system clock. - - The function cannot fail. _PyTime_Init() ensures that the system clock - works. */ -PyAPI_FUNC(_PyTime_t) _PyTime_GetSystemClock(void); - -/* Get the time of a monotonic clock, i.e. a clock that cannot go backwards. - The clock is not affected by system clock updates. The reference point of - the returned value is undefined, so that only the difference between the - results of consecutive calls is valid. - - The function cannot fail. _PyTime_Init() ensures that a monotonic clock - is available and works. */ -PyAPI_FUNC(_PyTime_t) _PyTime_GetMonotonicClock(void); - - -/* Structure used by time.get_clock_info() */ typedef struct { - const char *implementation; - int monotonic; - int adjustable; - double resolution; + const char *implementation; + int monotonic; + int adjustable; + double resolution; } _Py_clock_info_t; -/* Get the current time from the system clock. - * Fill clock information if info is not NULL. - * Raise an exception and return -1 on error, return 0 on success. - */ -PyAPI_FUNC(int) _PyTime_GetSystemClockWithInfo( - _PyTime_t *t, - _Py_clock_info_t *info); - -/* Get the time of a monotonic clock, i.e. a clock that cannot go backwards. - The clock is not affected by system clock updates. The reference point of - the returned value is undefined, so that only the difference between the - results of consecutive calls is valid. - - Fill info (if set) with information of the function used to get the time. - - Return 0 on success, raise an exception and return -1 on error. */ -PyAPI_FUNC(int) _PyTime_GetMonotonicClockWithInfo( - _PyTime_t *t, - _Py_clock_info_t *info); - - -/* Initialize time. - Return 0 on success, raise an exception and return -1 on error. */ -PyAPI_FUNC(int) _PyTime_Init(void); - -/* Converts a timestamp to the Gregorian time, using the local time zone. - Return 0 on success, raise an exception and return -1 on error. */ -PyAPI_FUNC(int) _PyTime_localtime(time_t t, struct tm *tm); - -/* Converts a timestamp to the Gregorian time, assuming UTC. - Return 0 on success, raise an exception and return -1 on error. */ -PyAPI_FUNC(int) _PyTime_gmtime(time_t t, struct tm *tm); +int _PyTime_GetSystemClockWithInfo(_PyTime_t *, _Py_clock_info_t *); +int _PyTime_GetMonotonicClockWithInfo(_PyTime_t *, _Py_clock_info_t *); +int _PyTime_Init(void); +int _PyTime_localtime(time_t, struct tm *); +int _PyTime_gmtime(time_t, struct tm *); COSMOPOLITAN_C_END_ #endif /* Py_PYTIME_H */ diff --git a/third_party/python/Include/rangeobject.h b/third_party/python/Include/rangeobject.h index 9d3e462c7..6c219267a 100644 --- a/third_party/python/Include/rangeobject.h +++ b/third_party/python/Include/rangeobject.h @@ -1,5 +1,6 @@ #ifndef Py_RANGEOBJECT_H #define Py_RANGEOBJECT_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -11,9 +12,9 @@ Range objects behave like the corresponding tuple objects except that they are represented by a start, stop, and step datamembers. */ -PyAPI_DATA(PyTypeObject) PyRange_Type; -PyAPI_DATA(PyTypeObject) PyRangeIter_Type; -PyAPI_DATA(PyTypeObject) PyLongRangeIter_Type; +extern PyTypeObject PyRange_Type; +extern PyTypeObject PyRangeIter_Type; +extern PyTypeObject PyLongRangeIter_Type; #define PyRange_Check(op) (Py_TYPE(op) == &PyRange_Type) diff --git a/third_party/python/Include/setobject.h b/third_party/python/Include/setobject.h index c0225cede..895680e8c 100644 --- a/third_party/python/Include/setobject.h +++ b/third_party/python/Include/setobject.h @@ -1,5 +1,6 @@ #ifndef Py_SETOBJECT_H #define Py_SETOBJECT_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -63,27 +64,27 @@ typedef struct { #define PySet_GET_SIZE(so) (((PySetObject *)(so))->used) -PyAPI_DATA(PyObject *) _PySet_Dummy; +extern PyObject * _PySet_Dummy; -PyAPI_FUNC(int) _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash); -PyAPI_FUNC(int) _PySet_Update(PyObject *set, PyObject *iterable); -PyAPI_FUNC(int) PySet_ClearFreeList(void); +int _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash); +int _PySet_Update(PyObject *set, PyObject *iterable); +int PySet_ClearFreeList(void); #endif /* Section excluded by Py_LIMITED_API */ -PyAPI_DATA(PyTypeObject) PySet_Type; -PyAPI_DATA(PyTypeObject) PyFrozenSet_Type; -PyAPI_DATA(PyTypeObject) PySetIter_Type; +extern PyTypeObject PySet_Type; +extern PyTypeObject PyFrozenSet_Type; +extern PyTypeObject PySetIter_Type; -PyAPI_FUNC(PyObject *) PySet_New(PyObject *); -PyAPI_FUNC(PyObject *) PyFrozenSet_New(PyObject *); +PyObject * PySet_New(PyObject *); +PyObject * PyFrozenSet_New(PyObject *); -PyAPI_FUNC(int) PySet_Add(PyObject *set, PyObject *key); -PyAPI_FUNC(int) PySet_Clear(PyObject *set); -PyAPI_FUNC(int) PySet_Contains(PyObject *anyset, PyObject *key); -PyAPI_FUNC(int) PySet_Discard(PyObject *set, PyObject *key); -PyAPI_FUNC(PyObject *) PySet_Pop(PyObject *set); -PyAPI_FUNC(Py_ssize_t) PySet_Size(PyObject *anyset); +int PySet_Add(PyObject *set, PyObject *key); +int PySet_Clear(PyObject *set); +int PySet_Contains(PyObject *anyset, PyObject *key); +int PySet_Discard(PyObject *set, PyObject *key); +PyObject * PySet_Pop(PyObject *set); +Py_ssize_t PySet_Size(PyObject *anyset); #define PyFrozenSet_CheckExact(ob) (Py_TYPE(ob) == &PyFrozenSet_Type) #define PyAnySet_CheckExact(ob) \ diff --git a/third_party/python/Include/sliceobject.h b/third_party/python/Include/sliceobject.h index 9fe402473..f1c222b38 100644 --- a/third_party/python/Include/sliceobject.h +++ b/third_party/python/Include/sliceobject.h @@ -1,11 +1,12 @@ #ifndef Py_SLICEOBJECT_H #define Py_SLICEOBJECT_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ /* The unique ellipsis object "..." */ -PyAPI_DATA(PyObject) _Py_EllipsisObject; /* Don't use this directly */ +extern PyObject _Py_EllipsisObject; /* Don't use this directly */ #define Py_Ellipsis (&_Py_EllipsisObject) @@ -24,22 +25,22 @@ typedef struct { } PySliceObject; #endif -PyAPI_DATA(PyTypeObject) PySlice_Type; -PyAPI_DATA(PyTypeObject) PyEllipsis_Type; +extern PyTypeObject PySlice_Type; +extern PyTypeObject PyEllipsis_Type; #define PySlice_Check(op) (Py_TYPE(op) == &PySlice_Type) -PyAPI_FUNC(PyObject *) PySlice_New(PyObject* start, PyObject* stop, +PyObject * PySlice_New(PyObject* start, PyObject* stop, PyObject* step); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) _PySlice_FromIndices(Py_ssize_t start, Py_ssize_t stop); -PyAPI_FUNC(int) _PySlice_GetLongIndices(PySliceObject *self, PyObject *length, +PyObject * _PySlice_FromIndices(Py_ssize_t start, Py_ssize_t stop); +int _PySlice_GetLongIndices(PySliceObject *self, PyObject *length, PyObject **start_ptr, PyObject **stop_ptr, PyObject **step_ptr); #endif -PyAPI_FUNC(int) PySlice_GetIndices(PyObject *r, Py_ssize_t length, +int PySlice_GetIndices(PyObject *r, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step); -PyAPI_FUNC(int) PySlice_GetIndicesEx(PyObject *r, Py_ssize_t length, +int PySlice_GetIndicesEx(PyObject *r, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, Py_ssize_t *slicelength); @@ -51,9 +52,9 @@ PyAPI_FUNC(int) PySlice_GetIndicesEx(PyObject *r, Py_ssize_t length, ((*(slicelen) = PySlice_AdjustIndices((length), (start), (stop), *(step))), \ 0)) #endif -PyAPI_FUNC(int) PySlice_Unpack(PyObject *slice, +int PySlice_Unpack(PyObject *slice, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step); -PyAPI_FUNC(Py_ssize_t) PySlice_AdjustIndices(Py_ssize_t length, +Py_ssize_t PySlice_AdjustIndices(Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t step); #endif diff --git a/third_party/python/Include/structmember.h b/third_party/python/Include/structmember.h index 403d09b57..4fe7e0f07 100644 --- a/third_party/python/Include/structmember.h +++ b/third_party/python/Include/structmember.h @@ -1,5 +1,6 @@ #ifndef Py_STRUCTMEMBER_H #define Py_STRUCTMEMBER_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -59,8 +60,8 @@ typedef struct PyMemberDef { /* Current API, use this */ -PyAPI_FUNC(PyObject *) PyMember_GetOne(const char *, struct PyMemberDef *); -PyAPI_FUNC(int) PyMember_SetOne(char *, struct PyMemberDef *, PyObject *); +PyObject * PyMember_GetOne(const char *, struct PyMemberDef *); +int PyMember_SetOne(char *, struct PyMemberDef *, PyObject *); COSMOPOLITAN_C_END_ #endif /* !Py_STRUCTMEMBER_H */ diff --git a/third_party/python/Include/structseq.h b/third_party/python/Include/structseq.h index 92a316bfd..c53fde951 100644 --- a/third_party/python/Include/structseq.h +++ b/third_party/python/Include/structseq.h @@ -1,5 +1,7 @@ #ifndef Py_STRUCTSEQ_H #define Py_STRUCTSEQ_H +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/tupleobject.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -18,14 +20,14 @@ typedef struct PyStructSequence_Desc { extern char* PyStructSequence_UnnamedField; #ifndef Py_LIMITED_API -PyAPI_FUNC(void) PyStructSequence_InitType(PyTypeObject *type, +void PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc); -PyAPI_FUNC(int) PyStructSequence_InitType2(PyTypeObject *type, +int PyStructSequence_InitType2(PyTypeObject *type, PyStructSequence_Desc *desc); #endif -PyAPI_FUNC(PyTypeObject*) PyStructSequence_NewType(PyStructSequence_Desc *desc); +PyTypeObject* PyStructSequence_NewType(PyStructSequence_Desc *desc); -PyAPI_FUNC(PyObject *) PyStructSequence_New(PyTypeObject* type); +PyObject * PyStructSequence_New(PyTypeObject* type); #ifndef Py_LIMITED_API typedef PyTupleObject PyStructSequence; @@ -36,8 +38,8 @@ typedef PyTupleObject PyStructSequence; #define PyStructSequence_GET_ITEM(op, i) PyTuple_GET_ITEM(op, i) #endif -PyAPI_FUNC(void) PyStructSequence_SetItem(PyObject*, Py_ssize_t, PyObject*); -PyAPI_FUNC(PyObject*) PyStructSequence_GetItem(PyObject*, Py_ssize_t); +void PyStructSequence_SetItem(PyObject*, Py_ssize_t, PyObject*); +PyObject* PyStructSequence_GetItem(PyObject*, Py_ssize_t); COSMOPOLITAN_C_END_ #endif /* !Py_STRUCTSEQ_H */ diff --git a/third_party/python/Include/symtable.h b/third_party/python/Include/symtable.h index 68f49738f..d97cc2a2c 100644 --- a/third_party/python/Include/symtable.h +++ b/third_party/python/Include/symtable.h @@ -1,6 +1,9 @@ #ifndef Py_LIMITED_API #ifndef Py_SYMTABLE_H #define Py_SYMTABLE_H +#include "third_party/python/Include/Python-ast.h" +#include "third_party/python/Include/compile.h" +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -58,23 +61,23 @@ typedef struct _symtable_entry { struct symtable *ste_table; } PySTEntryObject; -PyAPI_DATA(PyTypeObject) PySTEntry_Type; +extern PyTypeObject PySTEntry_Type; #define PySTEntry_Check(op) (Py_TYPE(op) == &PySTEntry_Type) -PyAPI_FUNC(int) PyST_GetScope(PySTEntryObject *, PyObject *); +int PyST_GetScope(PySTEntryObject *, PyObject *); -PyAPI_FUNC(struct symtable *) PySymtable_Build( +struct symtable * PySymtable_Build( mod_ty mod, const char *filename, /* decoded from the filesystem encoding */ PyFutureFeatures *future); -PyAPI_FUNC(struct symtable *) PySymtable_BuildObject( +struct symtable * PySymtable_BuildObject( mod_ty mod, PyObject *filename, PyFutureFeatures *future); -PyAPI_FUNC(PySTEntryObject *) PySymtable_Lookup(struct symtable *, void *); +PySTEntryObject * PySymtable_Lookup(struct symtable *, void *); -PyAPI_FUNC(void) PySymtable_Free(struct symtable *); +void PySymtable_Free(struct symtable *); /* Flags for def-use information */ diff --git a/third_party/python/Include/sysmodule.h b/third_party/python/Include/sysmodule.h index 75acad2fa..e4f620d01 100644 --- a/third_party/python/Include/sysmodule.h +++ b/third_party/python/Include/sysmodule.h @@ -1,36 +1,31 @@ #ifndef Py_SYSMODULE_H #define Py_SYSMODULE_H +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyport.h" COSMOPOLITAN_C_START_ /* clang-format off */ -PyAPI_FUNC(PyObject *) PySys_GetObject(const char *); -PyAPI_FUNC(int) PySys_SetObject(const char *, PyObject *); +PyObject * PySys_GetObject(const char *); +int PySys_SetObject(const char *, PyObject *); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) _PySys_GetObjectId(_Py_Identifier *key); -PyAPI_FUNC(int) _PySys_SetObjectId(_Py_Identifier *key, PyObject *); +PyObject * _PySys_GetObjectId(_Py_Identifier *key); +int _PySys_SetObjectId(_Py_Identifier *key, PyObject *); #endif -PyAPI_FUNC(void) PySys_SetArgv(int, wchar_t **); -PyAPI_FUNC(void) PySys_SetArgvEx(int, wchar_t **, int); -PyAPI_FUNC(void) PySys_SetPath(const wchar_t *); - -PyAPI_FUNC(void) PySys_WriteStdout(const char *format, ...) - Py_GCC_ATTRIBUTE((format(printf, 1, 2))); -PyAPI_FUNC(void) PySys_WriteStderr(const char *format, ...) - Py_GCC_ATTRIBUTE((format(printf, 1, 2))); -PyAPI_FUNC(void) PySys_FormatStdout(const char *format, ...); -PyAPI_FUNC(void) PySys_FormatStderr(const char *format, ...); - -PyAPI_FUNC(void) PySys_ResetWarnOptions(void); -PyAPI_FUNC(void) PySys_AddWarnOption(const wchar_t *); -PyAPI_FUNC(void) PySys_AddWarnOptionUnicode(PyObject *); -PyAPI_FUNC(int) PySys_HasWarnOptions(void); - -PyAPI_FUNC(void) PySys_AddXOption(const wchar_t *); -PyAPI_FUNC(PyObject *) PySys_GetXOptions(void); +void PySys_SetArgv(int, wchar_t **); +void PySys_SetArgvEx(int, wchar_t **, int); +void PySys_SetPath(const wchar_t *); +void PySys_FormatStdout(const char *, ...); +void PySys_FormatStderr(const char *, ...); +void PySys_ResetWarnOptions(void); +void PySys_AddWarnOption(const wchar_t *); +void PySys_AddWarnOptionUnicode(PyObject *); +int PySys_HasWarnOptions(void); +void PySys_AddXOption(const wchar_t *); +PyObject * PySys_GetXOptions(void); #ifndef Py_LIMITED_API -PyAPI_FUNC(size_t) _PySys_GetSizeOf(PyObject *); +size_t _PySys_GetSizeOf(PyObject *); #endif COSMOPOLITAN_C_END_ diff --git a/third_party/python/Include/token.h b/third_party/python/Include/token.h index 0eef17b16..b66401a8b 100644 --- a/third_party/python/Include/token.h +++ b/third_party/python/Include/token.h @@ -75,10 +75,10 @@ COSMOPOLITAN_C_START_ #define ISEOF(x) ((x) == ENDMARKER) -PyAPI_DATA(const char *) _PyParser_TokenNames[]; /* Token names */ -PyAPI_FUNC(int) PyToken_OneChar(int); -PyAPI_FUNC(int) PyToken_TwoChars(int, int); -PyAPI_FUNC(int) PyToken_ThreeChars(int, int, int); +extern const char * _PyParser_TokenNames[]; /* Token names */ +int PyToken_OneChar(int); +int PyToken_TwoChars(int, int); +int PyToken_ThreeChars(int, int, int); COSMOPOLITAN_C_END_ #endif /* !Py_TOKEN_H */ diff --git a/third_party/python/Include/traceback.h b/third_party/python/Include/traceback.h index e1589307d..dc8a7c79d 100644 --- a/third_party/python/Include/traceback.h +++ b/third_party/python/Include/traceback.h @@ -1,5 +1,6 @@ #ifndef Py_TRACEBACK_H #define Py_TRACEBACK_H +#include "third_party/python/Include/object.h" #include "third_party/python/Include/pystate.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -17,15 +18,15 @@ typedef struct _traceback { } PyTracebackObject; #endif -PyAPI_FUNC(int) PyTraceBack_Here(struct _frame *); -PyAPI_FUNC(int) PyTraceBack_Print(PyObject *, PyObject *); +int PyTraceBack_Here(struct _frame *); +int PyTraceBack_Print(PyObject *, PyObject *); #ifndef Py_LIMITED_API -PyAPI_FUNC(int) _Py_DisplaySourceLine(PyObject *, PyObject *, int, int); -PyAPI_FUNC(void) _PyTraceback_Add(const char *, const char *, int); +int _Py_DisplaySourceLine(PyObject *, PyObject *, int, int); +void _PyTraceback_Add(const char *, const char *, int); #endif /* Reveal traceback type so we can typecheck traceback objects */ -PyAPI_DATA(PyTypeObject) PyTraceBack_Type; +extern PyTypeObject PyTraceBack_Type; #define PyTraceBack_Check(v) (Py_TYPE(v) == &PyTraceBack_Type) #ifndef Py_LIMITED_API @@ -46,7 +47,7 @@ PyAPI_DATA(PyTypeObject) PyTraceBack_Type; This function is signal safe. */ -PyAPI_FUNC(void) _Py_DumpTraceback( +void _Py_DumpTraceback( int fd, PyThreadState *tstate); @@ -73,7 +74,7 @@ PyAPI_FUNC(void) _Py_DumpTraceback( This function is signal safe. */ -PyAPI_FUNC(const char*) _Py_DumpTracebackThreads( +const char* _Py_DumpTracebackThreads( int fd, PyInterpreterState *interp, PyThreadState *current_tstate); @@ -88,12 +89,12 @@ PyAPI_FUNC(const char*) _Py_DumpTracebackThreads( string which is not ready (PyUnicode_WCHAR_KIND). This function is signal safe. */ -PyAPI_FUNC(void) _Py_DumpASCII(int fd, PyObject *text); +void _Py_DumpASCII(int fd, PyObject *text); /* Format an integer as decimal into the file descriptor fd. This function is signal safe. */ -PyAPI_FUNC(void) _Py_DumpDecimal( +void _Py_DumpDecimal( int fd, unsigned long value); @@ -103,7 +104,7 @@ PyAPI_FUNC(void) _Py_DumpDecimal( The maximum width is sizeof(unsigned long)*2 digits. This function is signal safe. */ -PyAPI_FUNC(void) _Py_DumpHexadecimal( +void _Py_DumpHexadecimal( int fd, unsigned long value, Py_ssize_t width); diff --git a/third_party/python/Include/tupleobject.h b/third_party/python/Include/tupleobject.h index 02bb1acae..998b81d89 100644 --- a/third_party/python/Include/tupleobject.h +++ b/third_party/python/Include/tupleobject.h @@ -1,5 +1,6 @@ #ifndef Py_TUPLEOBJECT_H #define Py_TUPLEOBJECT_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -29,24 +30,24 @@ typedef struct { } PyTupleObject; #endif -PyAPI_DATA(PyTypeObject) PyTuple_Type; -PyAPI_DATA(PyTypeObject) PyTupleIter_Type; +extern PyTypeObject PyTuple_Type; +extern PyTypeObject PyTupleIter_Type; #define PyTuple_Check(op) \ PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS) #define PyTuple_CheckExact(op) (Py_TYPE(op) == &PyTuple_Type) -PyAPI_FUNC(PyObject *) PyTuple_New(Py_ssize_t size); -PyAPI_FUNC(Py_ssize_t) PyTuple_Size(PyObject *); -PyAPI_FUNC(PyObject *) PyTuple_GetItem(PyObject *, Py_ssize_t); -PyAPI_FUNC(int) PyTuple_SetItem(PyObject *, Py_ssize_t, PyObject *); -PyAPI_FUNC(PyObject *) PyTuple_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t); +PyObject * PyTuple_New(Py_ssize_t size); +Py_ssize_t PyTuple_Size(PyObject *); +PyObject * PyTuple_GetItem(PyObject *, Py_ssize_t); +int PyTuple_SetItem(PyObject *, Py_ssize_t, PyObject *); +PyObject * PyTuple_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t); #ifndef Py_LIMITED_API -PyAPI_FUNC(int) _PyTuple_Resize(PyObject **, Py_ssize_t); +int _PyTuple_Resize(PyObject **, Py_ssize_t); #endif -PyAPI_FUNC(PyObject *) PyTuple_Pack(Py_ssize_t, ...); +PyObject * PyTuple_Pack(Py_ssize_t, ...); #ifndef Py_LIMITED_API -PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *); +void _PyTuple_MaybeUntrack(PyObject *); #endif /* Macro, trading safety for speed */ @@ -58,9 +59,9 @@ PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *); #define PyTuple_SET_ITEM(op, i, v) (((PyTupleObject *)(op))->ob_item[i] = v) #endif -PyAPI_FUNC(int) PyTuple_ClearFreeList(void); +int PyTuple_ClearFreeList(void); #ifndef Py_LIMITED_API -PyAPI_FUNC(void) _PyTuple_DebugMallocStats(FILE *out); +void _PyTuple_DebugMallocStats(FILE *out); #endif /* Py_LIMITED_API */ COSMOPOLITAN_C_END_ diff --git a/third_party/python/Include/ucnhash.h b/third_party/python/Include/ucnhash.h index ef689ee82..24933f1f6 100644 --- a/third_party/python/Include/ucnhash.h +++ b/third_party/python/Include/ucnhash.h @@ -1,6 +1,8 @@ -#ifndef Py_LIMITED_API #ifndef Py_UCNHASH_H #define Py_UCNHASH_H +#ifndef Py_LIMITED_API +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/unicodeobject.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -28,5 +30,5 @@ typedef struct { } _PyUnicode_Name_CAPI; COSMOPOLITAN_C_END_ -#endif /* !Py_UCNHASH_H */ #endif /* !Py_LIMITED_API */ +#endif /* !Py_UCNHASH_H */ diff --git a/third_party/python/Include/unicodeobject.h b/third_party/python/Include/unicodeobject.h index e4d31d827..6dcb621b1 100644 --- a/third_party/python/Include/unicodeobject.h +++ b/third_party/python/Include/unicodeobject.h @@ -1,64 +1,11 @@ #ifndef Py_UNICODEOBJECT_H #define Py_UNICODEOBJECT_H +#include "libc/assert.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/pyconfig.h" COSMOPOLITAN_C_START_ /* clang-format off */ -/* -Unicode implementation based on original code by Fredrik Lundh, -modified by Marc-Andre Lemburg (mal@lemburg.com) according to the -Unicode Integration Proposal. (See -http://www.egenix.com/files/python/unicode-proposal.txt). - -Copyright (c) Corporation for National Research Initiatives. - - - Original header: - -------------------------------------------------------------------- - - * Yet another Unicode string type for Python. This type supports the - * 16-bit Basic Multilingual Plane (BMP) only. - * - * Written by Fredrik Lundh, January 1999. - * - * Copyright (c) 1999 by Secret Labs AB. - * Copyright (c) 1999 by Fredrik Lundh. - * - * fredrik@pythonware.com - * http://www.pythonware.com - * - * -------------------------------------------------------------------- - * This Unicode String Type is - * - * Copyright (c) 1999 by Secret Labs AB - * Copyright (c) 1999 by Fredrik Lundh - * - * By obtaining, using, and/or copying this software and/or its - * associated documentation, you agree that you have read, understood, - * and will comply with the following terms and conditions: - * - * Permission to use, copy, modify, and distribute this software and its - * associated documentation for any purpose and without fee is hereby - * granted, provided that the above copyright notice appears in all - * copies, and that both that copyright notice and this permission notice - * appear in supporting documentation, and that the name of Secret Labs - * AB or the author not be used in advertising or publicity pertaining to - * distribution of the software without specific, written prior - * permission. - * - * SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO - * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT - * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * -------------------------------------------------------------------- */ - -/* === Internal API ======================================================= */ - -/* --- Internal Unicode Format -------------------------------------------- */ - -/* Python 3.x requires unicode */ #define Py_USING_UNICODE #ifndef SIZEOF_WCHAR_T @@ -184,79 +131,6 @@ typedef uint8_t Py_UCS1; immediately follow the structure. utf8_length and wstr_length can be found in the length field; the utf8 pointer is equal to the data pointer. */ typedef struct { - /* There are 4 forms of Unicode strings: - - - compact ascii: - - * structure = PyASCIIObject - * test: PyUnicode_IS_COMPACT_ASCII(op) - * kind = PyUnicode_1BYTE_KIND - * compact = 1 - * ascii = 1 - * ready = 1 - * (length is the length of the utf8 and wstr strings) - * (data starts just after the structure) - * (since ASCII is decoded from UTF-8, the utf8 string are the data) - - - compact: - - * structure = PyCompactUnicodeObject - * test: PyUnicode_IS_COMPACT(op) && !PyUnicode_IS_ASCII(op) - * kind = PyUnicode_1BYTE_KIND, PyUnicode_2BYTE_KIND or - PyUnicode_4BYTE_KIND - * compact = 1 - * ready = 1 - * ascii = 0 - * utf8 is not shared with data - * utf8_length = 0 if utf8 is NULL - * wstr is shared with data and wstr_length=length - if kind=PyUnicode_2BYTE_KIND and sizeof(wchar_t)=2 - or if kind=PyUnicode_4BYTE_KIND and sizeof(wchar_t)=4 - * wstr_length = 0 if wstr is NULL - * (data starts just after the structure) - - - legacy string, not ready: - - * structure = PyUnicodeObject - * test: kind == PyUnicode_WCHAR_KIND - * length = 0 (use wstr_length) - * hash = -1 - * kind = PyUnicode_WCHAR_KIND - * compact = 0 - * ascii = 0 - * ready = 0 - * interned = SSTATE_NOT_INTERNED - * wstr is not NULL - * data.any is NULL - * utf8 is NULL - * utf8_length = 0 - - - legacy string, ready: - - * structure = PyUnicodeObject structure - * test: !PyUnicode_IS_COMPACT(op) && kind != PyUnicode_WCHAR_KIND - * kind = PyUnicode_1BYTE_KIND, PyUnicode_2BYTE_KIND or - PyUnicode_4BYTE_KIND - * compact = 0 - * ready = 1 - * data.any is not NULL - * utf8 is shared and utf8_length = length with data.any if ascii = 1 - * utf8_length = 0 if utf8 is NULL - * wstr is shared with data.any and wstr_length = length - if kind=PyUnicode_2BYTE_KIND and sizeof(wchar_t)=2 - or if kind=PyUnicode_4BYTE_KIND and sizeof(wchar_4)=4 - * wstr_length = 0 if wstr is NULL - - Compact strings use only one memory block (structure + characters), - whereas legacy strings use one block for the structure and one block - for characters. - - Legacy strings are created by PyUnicode_FromUnicode() and - PyUnicode_FromStringAndSize(NULL, size) functions. They become ready - when PyUnicode_READY() is called. - - See also _PyUnicode_CheckConsistency(). - */ PyObject_HEAD Py_ssize_t length; /* Number of code points in the string */ Py_hash_t hash; /* Hash value; -1 if not set */ @@ -345,8 +219,8 @@ typedef struct { } PyUnicodeObject; #endif -PyAPI_DATA(PyTypeObject) PyUnicode_Type; -PyAPI_DATA(PyTypeObject) PyUnicodeIter_Type; +extern PyTypeObject PyUnicode_Type; +extern PyTypeObject PyUnicodeIter_Type; #define PyUnicode_Check(op) \ PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS) @@ -568,7 +442,7 @@ enum PyUnicode_Kind { This function will allocate the object and its buffer in a single memory block. Objects created using this function are not resizable. */ #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) PyUnicode_New( +PyObject* PyUnicode_New( Py_ssize_t size, /* Number of code points in the new string */ Py_UCS4 maxchar /* maximum code point value in the string */ ); @@ -582,14 +456,14 @@ PyAPI_FUNC(PyObject*) PyUnicode_New( Don't call this function directly, use the public PyUnicode_READY() macro instead. */ #ifndef Py_LIMITED_API -PyAPI_FUNC(int) _PyUnicode_Ready( +int _PyUnicode_Ready( PyObject *unicode /* Unicode object */ ); #endif /* Get a copy of a Unicode string. */ #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) _PyUnicode_Copy( +PyObject* _PyUnicode_Copy( PyObject *unicode ); #endif @@ -613,7 +487,7 @@ PyAPI_FUNC(PyObject*) _PyUnicode_Copy( Note: The function doesn't write a terminating null character. */ #ifndef Py_LIMITED_API -PyAPI_FUNC(Py_ssize_t) PyUnicode_CopyCharacters( +Py_ssize_t PyUnicode_CopyCharacters( PyObject *to, Py_ssize_t to_start, PyObject *from, @@ -624,7 +498,7 @@ PyAPI_FUNC(Py_ssize_t) PyUnicode_CopyCharacters( /* Unsafe version of PyUnicode_CopyCharacters(): don't check arguments and so may crash if parameters are invalid (e.g. if the output string is too short). */ -PyAPI_FUNC(void) _PyUnicode_FastCopyCharacters( +void _PyUnicode_FastCopyCharacters( PyObject *to, Py_ssize_t to_start, PyObject *from, @@ -642,7 +516,7 @@ PyAPI_FUNC(void) _PyUnicode_FastCopyCharacters( Return the number of written character, or return -1 and raise an exception on error. */ -PyAPI_FUNC(Py_ssize_t) PyUnicode_Fill( +Py_ssize_t PyUnicode_Fill( PyObject *unicode, Py_ssize_t start, Py_ssize_t length, @@ -651,7 +525,7 @@ PyAPI_FUNC(Py_ssize_t) PyUnicode_Fill( /* Unsafe version of PyUnicode_Fill(): don't check arguments and so may crash if parameters are invalid (e.g. if length is longer than the string). */ -PyAPI_FUNC(void) _PyUnicode_FastFill( +void _PyUnicode_FastFill( PyObject *unicode, Py_ssize_t start, Py_ssize_t length, @@ -670,41 +544,41 @@ PyAPI_FUNC(void) _PyUnicode_FastFill( The buffer is copied into the new object. */ #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode( +PyObject* PyUnicode_FromUnicode( const Py_UNICODE *u, /* Unicode buffer */ Py_ssize_t size /* size of buffer */ ); #endif /* Similar to PyUnicode_FromUnicode(), but u points to UTF-8 encoded bytes */ -PyAPI_FUNC(PyObject*) PyUnicode_FromStringAndSize( +PyObject* PyUnicode_FromStringAndSize( const char *u, /* UTF-8 encoded string */ Py_ssize_t size /* size of buffer */ ); /* Similar to PyUnicode_FromUnicode(), but u points to null-terminated UTF-8 encoded bytes. The size is determined with strlen(). */ -PyAPI_FUNC(PyObject*) PyUnicode_FromString( +PyObject* PyUnicode_FromString( const char *u /* UTF-8 encoded string */ ); #ifndef Py_LIMITED_API /* Create a new string from a buffer of Py_UCS1, Py_UCS2 or Py_UCS4 characters. Scan the string to find the maximum character. */ -PyAPI_FUNC(PyObject*) PyUnicode_FromKindAndData( +PyObject* PyUnicode_FromKindAndData( int kind, const void *buffer, Py_ssize_t size); /* Create a new string from a buffer of ASCII characters. WARNING: Don't check if the string contains any non-ASCII character. */ -PyAPI_FUNC(PyObject*) _PyUnicode_FromASCII( +PyObject* _PyUnicode_FromASCII( const char *buffer, Py_ssize_t size); #endif #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 -PyAPI_FUNC(PyObject*) PyUnicode_Substring( +PyObject* PyUnicode_Substring( PyObject *str, Py_ssize_t start, Py_ssize_t end); @@ -713,7 +587,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_Substring( #ifndef Py_LIMITED_API /* Compute the maximum character of the substring unicode[start:end]. Return 127 for an empty string. */ -PyAPI_FUNC(Py_UCS4) _PyUnicode_FindMaxChar ( +Py_UCS4 _PyUnicode_FindMaxChar ( PyObject *unicode, Py_ssize_t start, Py_ssize_t end); @@ -725,7 +599,7 @@ PyAPI_FUNC(Py_UCS4) _PyUnicode_FindMaxChar ( the buffer is smaller than the string. Return buffer on success. buflen is the length of the buffer in (Py_UCS4) characters. */ -PyAPI_FUNC(Py_UCS4*) PyUnicode_AsUCS4( +Py_UCS4* PyUnicode_AsUCS4( PyObject *unicode, Py_UCS4* buffer, Py_ssize_t buflen, @@ -734,7 +608,7 @@ PyAPI_FUNC(Py_UCS4*) PyUnicode_AsUCS4( /* Copy the string into a UCS4 buffer. A new buffer is allocated using * PyMem_Malloc; if this fails, NULL is returned with a memory error exception set. */ -PyAPI_FUNC(Py_UCS4*) PyUnicode_AsUCS4Copy(PyObject *unicode); +Py_UCS4* PyUnicode_AsUCS4Copy(PyObject *unicode); #endif #ifndef Py_LIMITED_API @@ -743,13 +617,13 @@ PyAPI_FUNC(Py_UCS4*) PyUnicode_AsUCS4Copy(PyObject *unicode); If the wchar_t/Py_UNICODE representation is not yet available, this function will calculate it. */ -PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicode( +Py_UNICODE * PyUnicode_AsUnicode( PyObject *unicode /* Unicode object */ ); /* Similar to PyUnicode_AsUnicode(), but raises a ValueError if the string contains null characters. */ -PyAPI_FUNC(const Py_UNICODE *) _PyUnicode_AsUnicode( +const Py_UNICODE * _PyUnicode_AsUnicode( PyObject *unicode /* Unicode object */ ); @@ -758,7 +632,7 @@ PyAPI_FUNC(const Py_UNICODE *) _PyUnicode_AsUnicode( If the wchar_t/Py_UNICODE representation is not yet available, this function will calculate it. */ -PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicodeAndSize( +Py_UNICODE * PyUnicode_AsUnicodeAndSize( PyObject *unicode, /* Unicode object */ Py_ssize_t *size /* location where to save the length */ ); @@ -767,7 +641,7 @@ PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicodeAndSize( #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 /* Get the length of the Unicode object. */ -PyAPI_FUNC(Py_ssize_t) PyUnicode_GetLength( +Py_ssize_t PyUnicode_GetLength( PyObject *unicode ); #endif @@ -775,14 +649,14 @@ PyAPI_FUNC(Py_ssize_t) PyUnicode_GetLength( /* Get the number of Py_UNICODE units in the string representation. */ -PyAPI_FUNC(Py_ssize_t) PyUnicode_GetSize( +Py_ssize_t PyUnicode_GetSize( PyObject *unicode /* Unicode object */ ); #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 /* Read a character from the string. */ -PyAPI_FUNC(Py_UCS4) PyUnicode_ReadChar( +Py_UCS4 PyUnicode_ReadChar( PyObject *unicode, Py_ssize_t index ); @@ -792,7 +666,7 @@ PyAPI_FUNC(Py_UCS4) PyUnicode_ReadChar( Return 0 on success, -1 on error. */ -PyAPI_FUNC(int) PyUnicode_WriteChar( +int PyUnicode_WriteChar( PyObject *unicode, Py_ssize_t index, Py_UCS4 character @@ -801,7 +675,7 @@ PyAPI_FUNC(int) PyUnicode_WriteChar( #ifndef Py_LIMITED_API /* Get the maximum ordinal for a Unicode character. */ -PyAPI_FUNC(Py_UNICODE) PyUnicode_GetMax(void); +Py_UNICODE PyUnicode_GetMax(void); #endif /* Resize a Unicode object. The length is the number of characters, except @@ -820,7 +694,7 @@ PyAPI_FUNC(Py_UNICODE) PyUnicode_GetMax(void); WARNING: The function doesn't check string content, the result may not be a string in canonical representation. */ -PyAPI_FUNC(int) PyUnicode_Resize( +int PyUnicode_Resize( PyObject **unicode, /* Pointer to the Unicode object */ Py_ssize_t length /* New length */ ); @@ -838,7 +712,7 @@ PyAPI_FUNC(int) PyUnicode_Resize( */ -PyAPI_FUNC(PyObject*) PyUnicode_FromEncodedObject( +PyObject* PyUnicode_FromEncodedObject( PyObject *obj, /* Object */ const char *encoding, /* encoding */ const char *errors /* error handling */ @@ -853,15 +727,15 @@ PyAPI_FUNC(PyObject*) PyUnicode_FromEncodedObject( */ -PyAPI_FUNC(PyObject*) PyUnicode_FromObject( +PyObject* PyUnicode_FromObject( PyObject *obj /* Object */ ); -PyAPI_FUNC(PyObject *) PyUnicode_FromFormatV( +PyObject * PyUnicode_FromFormatV( const char *format, /* ASCII-encoded string */ va_list vargs ); -PyAPI_FUNC(PyObject *) PyUnicode_FromFormat( +PyObject * PyUnicode_FromFormat( const char *format, /* ASCII-encoded string */ ... ); @@ -894,7 +768,7 @@ typedef struct { * By default, the minimum buffer size is 0 character and overallocation is * disabled. Set min_length, min_char and overallocate attributes to control * the allocation of the buffer. */ -PyAPI_FUNC(void) +void _PyUnicodeWriter_Init(_PyUnicodeWriter *writer); /* Prepare the buffer to write 'length' characters @@ -911,7 +785,7 @@ _PyUnicodeWriter_Init(_PyUnicodeWriter *writer); /* Don't call this function directly, use the _PyUnicodeWriter_Prepare() macro instead. */ -PyAPI_FUNC(int) +int _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer, Py_ssize_t length, Py_UCS4 maxchar); @@ -928,27 +802,27 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer, /* Don't call this function directly, use the _PyUnicodeWriter_PrepareKind() macro instead. */ -PyAPI_FUNC(int) +int _PyUnicodeWriter_PrepareKindInternal(_PyUnicodeWriter *writer, enum PyUnicode_Kind kind); /* Append a Unicode character. Return 0 on success, raise an exception and return -1 on error. */ -PyAPI_FUNC(int) +int _PyUnicodeWriter_WriteChar(_PyUnicodeWriter *writer, Py_UCS4 ch ); /* Append a Unicode string. Return 0 on success, raise an exception and return -1 on error. */ -PyAPI_FUNC(int) +int _PyUnicodeWriter_WriteStr(_PyUnicodeWriter *writer, PyObject *str /* Unicode string */ ); /* Append a substring of a Unicode string. Return 0 on success, raise an exception and return -1 on error. */ -PyAPI_FUNC(int) +int _PyUnicodeWriter_WriteSubstring(_PyUnicodeWriter *writer, PyObject *str, /* Unicode string */ Py_ssize_t start, @@ -957,7 +831,7 @@ _PyUnicodeWriter_WriteSubstring(_PyUnicodeWriter *writer, /* Append an ASCII-encoded byte string. Return 0 on success, raise an exception and return -1 on error. */ -PyAPI_FUNC(int) +int _PyUnicodeWriter_WriteASCIIString(_PyUnicodeWriter *writer, const char *str, /* ASCII-encoded byte string */ Py_ssize_t len /* number of bytes, or -1 if unknown */ @@ -965,7 +839,7 @@ _PyUnicodeWriter_WriteASCIIString(_PyUnicodeWriter *writer, /* Append a latin1-encoded byte string. Return 0 on success, raise an exception and return -1 on error. */ -PyAPI_FUNC(int) +int _PyUnicodeWriter_WriteLatin1String(_PyUnicodeWriter *writer, const char *str, /* latin1-encoded byte string */ Py_ssize_t len /* length in bytes */ @@ -974,18 +848,18 @@ _PyUnicodeWriter_WriteLatin1String(_PyUnicodeWriter *writer, /* Get the value of the writer as a Unicode string. Clear the buffer of the writer. Raise an exception and return NULL on error. */ -PyAPI_FUNC(PyObject *) +PyObject * _PyUnicodeWriter_Finish(_PyUnicodeWriter *writer); /* Deallocate memory of a writer (clear its internal buffer). */ -PyAPI_FUNC(void) +void _PyUnicodeWriter_Dealloc(_PyUnicodeWriter *writer); #endif #ifndef Py_LIMITED_API /* Format the object based on the format_spec, as defined in PEP 3101 (Advanced String Formatting). */ -PyAPI_FUNC(int) _PyUnicode_FormatAdvancedWriter( +int _PyUnicode_FormatAdvancedWriter( _PyUnicodeWriter *writer, PyObject *obj, PyObject *format_spec, @@ -993,13 +867,13 @@ PyAPI_FUNC(int) _PyUnicode_FormatAdvancedWriter( Py_ssize_t end); #endif -PyAPI_FUNC(void) PyUnicode_InternInPlace(PyObject **); -PyAPI_FUNC(void) PyUnicode_InternImmortal(PyObject **); -PyAPI_FUNC(PyObject *) PyUnicode_InternFromString( +void PyUnicode_InternInPlace(PyObject **); +void PyUnicode_InternImmortal(PyObject **); +PyObject * PyUnicode_InternFromString( const char *u /* UTF-8 encoded string */ ); #ifndef Py_LIMITED_API -PyAPI_FUNC(void) _Py_ReleaseInternedUnicodeStrings(void); +void _Py_ReleaseInternedUnicodeStrings(void); #endif /* Use only if you know it's a string */ @@ -1015,7 +889,7 @@ PyAPI_FUNC(void) _Py_ReleaseInternedUnicodeStrings(void); The buffer is copied into the new object. */ -PyAPI_FUNC(PyObject*) PyUnicode_FromWideChar( +PyObject* PyUnicode_FromWideChar( const wchar_t *w, /* wchar_t buffer */ Py_ssize_t size /* size of buffer */ ); @@ -1032,7 +906,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_FromWideChar( possibly trailing 0-termination character) or -1 in case of an error. */ -PyAPI_FUNC(Py_ssize_t) PyUnicode_AsWideChar( +Py_ssize_t PyUnicode_AsWideChar( PyObject *unicode, /* Unicode object */ wchar_t *w, /* wchar_t buffer */ Py_ssize_t size /* size of buffer */ @@ -1046,7 +920,7 @@ PyAPI_FUNC(Py_ssize_t) PyUnicode_AsWideChar( on success. On error, returns NULL, *size is undefined and raises a MemoryError. */ -PyAPI_FUNC(wchar_t*) PyUnicode_AsWideCharString( +wchar_t* PyUnicode_AsWideCharString( PyObject *unicode, /* Unicode object */ Py_ssize_t *size /* number of characters of the result */ ); @@ -1054,11 +928,11 @@ PyAPI_FUNC(wchar_t*) PyUnicode_AsWideCharString( #ifndef Py_LIMITED_API /* Similar to PyUnicode_AsWideCharString(unicode, NULL), but check if the string contains null characters. */ -PyAPI_FUNC(wchar_t*) _PyUnicode_AsWideCharString( +wchar_t* _PyUnicode_AsWideCharString( PyObject *unicode /* Unicode object */ ); -PyAPI_FUNC(void*) _PyUnicode_AsKind(PyObject *s, unsigned int kind); +void* _PyUnicode_AsKind(PyObject *s, unsigned int kind); #endif #endif @@ -1072,7 +946,7 @@ PyAPI_FUNC(void*) _PyUnicode_AsKind(PyObject *s, unsigned int kind); */ -PyAPI_FUNC(PyObject*) PyUnicode_FromOrdinal(int ordinal); +PyObject* PyUnicode_FromOrdinal(int ordinal); /* --- Free-list management ----------------------------------------------- */ @@ -1083,7 +957,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_FromOrdinal(int ordinal); */ -PyAPI_FUNC(int) PyUnicode_ClearFreeList(void); +int PyUnicode_ClearFreeList(void); /* === Builtin Codecs ===================================================== @@ -1126,7 +1000,7 @@ PyAPI_FUNC(int) PyUnicode_ClearFreeList(void); */ #ifndef Py_LIMITED_API -PyAPI_FUNC(char *) PyUnicode_AsUTF8AndSize( +char * PyUnicode_AsUTF8AndSize( PyObject *unicode, Py_ssize_t *size); #define _PyUnicode_AsStringAndSize PyUnicode_AsUTF8AndSize @@ -1153,20 +1027,20 @@ PyAPI_FUNC(char *) PyUnicode_AsUTF8AndSize( */ #ifndef Py_LIMITED_API -PyAPI_FUNC(char *) PyUnicode_AsUTF8(PyObject *unicode); +char * PyUnicode_AsUTF8(PyObject *unicode); #define _PyUnicode_AsString PyUnicode_AsUTF8 #endif /* Returns "utf-8". */ -PyAPI_FUNC(const char*) PyUnicode_GetDefaultEncoding(void); +const char* PyUnicode_GetDefaultEncoding(void); /* --- Generic Codecs ----------------------------------------------------- */ /* Create a Unicode object by decoding the encoded string s of the given size. */ -PyAPI_FUNC(PyObject*) PyUnicode_Decode( +PyObject* PyUnicode_Decode( const char *s, /* encoded string */ Py_ssize_t size, /* size of buffer */ const char *encoding, /* encoding */ @@ -1180,7 +1054,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_Decode( Use PyCodec_Decode() to decode with rot13 and non-standard codecs that decode from str. */ -PyAPI_FUNC(PyObject*) PyUnicode_AsDecodedObject( +PyObject* PyUnicode_AsDecodedObject( PyObject *unicode, /* Unicode object */ const char *encoding, /* encoding */ const char *errors /* error handling */ @@ -1193,17 +1067,17 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsDecodedObject( Use PyCodec_Decode() to decode with rot13 and non-standard codecs that decode from str to str. */ -PyAPI_FUNC(PyObject*) PyUnicode_AsDecodedUnicode( +PyObject* PyUnicode_AsDecodedUnicode( PyObject *unicode, /* Unicode object */ const char *encoding, /* encoding */ const char *errors /* error handling */ - ) Py_DEPRECATED(3.6); + ) Py_DEPRECATED(3.6); /* Encodes a Py_UNICODE buffer of the given size and returns a Python string object. */ #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) PyUnicode_Encode( +PyObject* PyUnicode_Encode( const Py_UNICODE *s, /* Unicode char buffer */ Py_ssize_t size, /* number of Py_UNICODE chars to encode */ const char *encoding, /* encoding */ @@ -1219,7 +1093,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_Encode( Use PyCodec_Encode() for encoding with rot13 and non-standard codecs that encode form str to non-bytes. */ -PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedObject( +PyObject* PyUnicode_AsEncodedObject( PyObject *unicode, /* Unicode object */ const char *encoding, /* encoding */ const char *errors /* error handling */ @@ -1228,7 +1102,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedObject( /* Encodes a Unicode object and returns the result as Python string object. */ -PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedString( +PyObject* PyUnicode_AsEncodedString( PyObject *unicode, /* Unicode object */ const char *encoding, /* encoding */ const char *errors /* error handling */ @@ -1241,7 +1115,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedString( Use PyCodec_Encode() to encode with rot13 and non-standard codecs that encode from str to str. */ -PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedUnicode( +PyObject* PyUnicode_AsEncodedUnicode( PyObject *unicode, /* Unicode object */ const char *encoding, /* encoding */ const char *errors /* error handling */ @@ -1249,19 +1123,19 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedUnicode( /* Build an encoding map. */ -PyAPI_FUNC(PyObject*) PyUnicode_BuildEncodingMap( +PyObject* PyUnicode_BuildEncodingMap( PyObject* string /* 256 character map */ ); /* --- UTF-7 Codecs ------------------------------------------------------- */ -PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF7( +PyObject* PyUnicode_DecodeUTF7( const char *string, /* UTF-7 encoded string */ Py_ssize_t length, /* size of string */ const char *errors /* error handling */ ); -PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF7Stateful( +PyObject* PyUnicode_DecodeUTF7Stateful( const char *string, /* UTF-7 encoded string */ Py_ssize_t length, /* size of string */ const char *errors, /* error handling */ @@ -1269,14 +1143,14 @@ PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF7Stateful( ); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF7( +PyObject* PyUnicode_EncodeUTF7( const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length, /* number of Py_UNICODE chars to encode */ int base64SetO, /* Encode RFC2152 Set O characters in base64 */ int base64WhiteSpace, /* Encode whitespace (sp, ht, nl, cr) in base64 */ const char *errors /* error handling */ ); -PyAPI_FUNC(PyObject*) _PyUnicode_EncodeUTF7( +PyObject* _PyUnicode_EncodeUTF7( PyObject *unicode, /* Unicode object */ int base64SetO, /* Encode RFC2152 Set O characters in base64 */ int base64WhiteSpace, /* Encode whitespace (sp, ht, nl, cr) in base64 */ @@ -1286,29 +1160,29 @@ PyAPI_FUNC(PyObject*) _PyUnicode_EncodeUTF7( /* --- UTF-8 Codecs ------------------------------------------------------- */ -PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF8( +PyObject* PyUnicode_DecodeUTF8( const char *string, /* UTF-8 encoded string */ Py_ssize_t length, /* size of string */ const char *errors /* error handling */ ); -PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF8Stateful( +PyObject* PyUnicode_DecodeUTF8Stateful( const char *string, /* UTF-8 encoded string */ Py_ssize_t length, /* size of string */ const char *errors, /* error handling */ Py_ssize_t *consumed /* bytes consumed */ ); -PyAPI_FUNC(PyObject*) PyUnicode_AsUTF8String( +PyObject* PyUnicode_AsUTF8String( PyObject *unicode /* Unicode object */ ); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) _PyUnicode_AsUTF8String( +PyObject* _PyUnicode_AsUTF8String( PyObject *unicode, const char *errors); -PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF8( +PyObject* PyUnicode_EncodeUTF8( const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length, /* number of Py_UNICODE chars to encode */ const char *errors /* error handling */ @@ -1340,7 +1214,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF8( */ -PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF32( +PyObject* PyUnicode_DecodeUTF32( const char *string, /* UTF-32 encoded string */ Py_ssize_t length, /* size of string */ const char *errors, /* error handling */ @@ -1349,7 +1223,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF32( exit */ ); -PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF32Stateful( +PyObject* PyUnicode_DecodeUTF32Stateful( const char *string, /* UTF-32 encoded string */ Py_ssize_t length, /* size of string */ const char *errors, /* error handling */ @@ -1362,7 +1236,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF32Stateful( /* Returns a Python string using the UTF-32 encoding in native byte order. The string always starts with a BOM mark. */ -PyAPI_FUNC(PyObject*) PyUnicode_AsUTF32String( +PyObject* PyUnicode_AsUTF32String( PyObject *unicode /* Unicode object */ ); @@ -1383,13 +1257,13 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsUTF32String( */ #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF32( +PyObject* PyUnicode_EncodeUTF32( const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length, /* number of Py_UNICODE chars to encode */ const char *errors, /* error handling */ int byteorder /* byteorder to use 0=BOM+native;-1=LE,1=BE */ ); -PyAPI_FUNC(PyObject*) _PyUnicode_EncodeUTF32( +PyObject* _PyUnicode_EncodeUTF32( PyObject *object, /* Unicode object */ const char *errors, /* error handling */ int byteorder /* byteorder to use 0=BOM+native;-1=LE,1=BE */ @@ -1421,7 +1295,7 @@ PyAPI_FUNC(PyObject*) _PyUnicode_EncodeUTF32( */ -PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF16( +PyObject* PyUnicode_DecodeUTF16( const char *string, /* UTF-16 encoded string */ Py_ssize_t length, /* size of string */ const char *errors, /* error handling */ @@ -1430,7 +1304,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF16( exit */ ); -PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF16Stateful( +PyObject* PyUnicode_DecodeUTF16Stateful( const char *string, /* UTF-16 encoded string */ Py_ssize_t length, /* size of string */ const char *errors, /* error handling */ @@ -1443,7 +1317,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF16Stateful( /* Returns a Python string using the UTF-16 encoding in native byte order. The string always starts with a BOM mark. */ -PyAPI_FUNC(PyObject*) PyUnicode_AsUTF16String( +PyObject* PyUnicode_AsUTF16String( PyObject *unicode /* Unicode object */ ); @@ -1468,13 +1342,13 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsUTF16String( */ #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF16( +PyObject* PyUnicode_EncodeUTF16( const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length, /* number of Py_UNICODE chars to encode */ const char *errors, /* error handling */ int byteorder /* byteorder to use 0=BOM+native;-1=LE,1=BE */ ); -PyAPI_FUNC(PyObject*) _PyUnicode_EncodeUTF16( +PyObject* _PyUnicode_EncodeUTF16( PyObject* unicode, /* Unicode object */ const char *errors, /* error handling */ int byteorder /* byteorder to use 0=BOM+native;-1=LE,1=BE */ @@ -1483,7 +1357,7 @@ PyAPI_FUNC(PyObject*) _PyUnicode_EncodeUTF16( /* --- Unicode-Escape Codecs ---------------------------------------------- */ -PyAPI_FUNC(PyObject*) PyUnicode_DecodeUnicodeEscape( +PyObject* PyUnicode_DecodeUnicodeEscape( const char *string, /* Unicode-Escape encoded string */ Py_ssize_t length, /* size of string */ const char *errors /* error handling */ @@ -1492,7 +1366,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_DecodeUnicodeEscape( #ifndef Py_LIMITED_API /* Helper for PyUnicode_DecodeUnicodeEscape that detects invalid escape chars. */ -PyAPI_FUNC(PyObject*) _PyUnicode_DecodeUnicodeEscape( +PyObject* _PyUnicode_DecodeUnicodeEscape( const char *string, /* Unicode-Escape encoded string */ Py_ssize_t length, /* size of string */ const char *errors, /* error handling */ @@ -1502,12 +1376,12 @@ PyAPI_FUNC(PyObject*) _PyUnicode_DecodeUnicodeEscape( ); #endif -PyAPI_FUNC(PyObject*) PyUnicode_AsUnicodeEscapeString( +PyObject* PyUnicode_AsUnicodeEscapeString( PyObject *unicode /* Unicode object */ ); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) PyUnicode_EncodeUnicodeEscape( +PyObject* PyUnicode_EncodeUnicodeEscape( const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length /* Number of Py_UNICODE chars to encode */ ); @@ -1515,18 +1389,18 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeUnicodeEscape( /* --- Raw-Unicode-Escape Codecs ------------------------------------------ */ -PyAPI_FUNC(PyObject*) PyUnicode_DecodeRawUnicodeEscape( +PyObject* PyUnicode_DecodeRawUnicodeEscape( const char *string, /* Raw-Unicode-Escape encoded string */ Py_ssize_t length, /* size of string */ const char *errors /* error handling */ ); -PyAPI_FUNC(PyObject*) PyUnicode_AsRawUnicodeEscapeString( +PyObject* PyUnicode_AsRawUnicodeEscapeString( PyObject *unicode /* Unicode object */ ); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) PyUnicode_EncodeRawUnicodeEscape( +PyObject* PyUnicode_EncodeRawUnicodeEscape( const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length /* Number of Py_UNICODE chars to encode */ ); @@ -1550,22 +1424,22 @@ PyObject *_PyUnicode_DecodeUnicodeInternal( */ -PyAPI_FUNC(PyObject*) PyUnicode_DecodeLatin1( +PyObject* PyUnicode_DecodeLatin1( const char *string, /* Latin-1 encoded string */ Py_ssize_t length, /* size of string */ const char *errors /* error handling */ ); -PyAPI_FUNC(PyObject*) PyUnicode_AsLatin1String( +PyObject* PyUnicode_AsLatin1String( PyObject *unicode /* Unicode object */ ); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) _PyUnicode_AsLatin1String( +PyObject* _PyUnicode_AsLatin1String( PyObject* unicode, const char* errors); -PyAPI_FUNC(PyObject*) PyUnicode_EncodeLatin1( +PyObject* PyUnicode_EncodeLatin1( const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */ const char *errors /* error handling */ @@ -1578,22 +1452,22 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeLatin1( */ -PyAPI_FUNC(PyObject*) PyUnicode_DecodeASCII( +PyObject* PyUnicode_DecodeASCII( const char *string, /* ASCII encoded string */ Py_ssize_t length, /* size of string */ const char *errors /* error handling */ ); -PyAPI_FUNC(PyObject*) PyUnicode_AsASCIIString( +PyObject* PyUnicode_AsASCIIString( PyObject *unicode /* Unicode object */ ); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) _PyUnicode_AsASCIIString( +PyObject* _PyUnicode_AsASCIIString( PyObject* unicode, const char* errors); -PyAPI_FUNC(PyObject*) PyUnicode_EncodeASCII( +PyObject* PyUnicode_EncodeASCII( const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */ const char *errors /* error handling */ @@ -1617,26 +1491,26 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeASCII( */ -PyAPI_FUNC(PyObject*) PyUnicode_DecodeCharmap( +PyObject* PyUnicode_DecodeCharmap( const char *string, /* Encoded string */ Py_ssize_t length, /* size of string */ PyObject *mapping, /* decoding mapping */ const char *errors /* error handling */ ); -PyAPI_FUNC(PyObject*) PyUnicode_AsCharmapString( +PyObject* PyUnicode_AsCharmapString( PyObject *unicode, /* Unicode object */ PyObject *mapping /* encoding mapping */ ); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) PyUnicode_EncodeCharmap( +PyObject* PyUnicode_EncodeCharmap( const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */ PyObject *mapping, /* encoding mapping */ const char *errors /* error handling */ ); -PyAPI_FUNC(PyObject*) _PyUnicode_EncodeCharmap( +PyObject* _PyUnicode_EncodeCharmap( PyObject *unicode, /* Unicode object */ PyObject *mapping, /* encoding mapping */ const char *errors /* error handling */ @@ -1657,7 +1531,7 @@ PyAPI_FUNC(PyObject*) _PyUnicode_EncodeCharmap( */ #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) PyUnicode_TranslateCharmap( +PyObject * PyUnicode_TranslateCharmap( const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */ PyObject *table, /* Translate table */ @@ -1669,13 +1543,13 @@ PyAPI_FUNC(PyObject *) PyUnicode_TranslateCharmap( /* --- MBCS codecs for Windows -------------------------------------------- */ -PyAPI_FUNC(PyObject*) PyUnicode_DecodeMBCS( +PyObject* PyUnicode_DecodeMBCS( const char *string, /* MBCS encoded string */ Py_ssize_t length, /* size of string */ const char *errors /* error handling */ ); -PyAPI_FUNC(PyObject*) PyUnicode_DecodeMBCSStateful( +PyObject* PyUnicode_DecodeMBCSStateful( const char *string, /* MBCS encoded string */ Py_ssize_t length, /* size of string */ const char *errors, /* error handling */ @@ -1683,7 +1557,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_DecodeMBCSStateful( ); #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 -PyAPI_FUNC(PyObject*) PyUnicode_DecodeCodePageStateful( +PyObject* PyUnicode_DecodeCodePageStateful( int code_page, /* code page number */ const char *string, /* encoded string */ Py_ssize_t length, /* size of string */ @@ -1692,12 +1566,12 @@ PyAPI_FUNC(PyObject*) PyUnicode_DecodeCodePageStateful( ); #endif -PyAPI_FUNC(PyObject*) PyUnicode_AsMBCSString( +PyObject* PyUnicode_AsMBCSString( PyObject *unicode /* Unicode object */ ); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) PyUnicode_EncodeMBCS( +PyObject* PyUnicode_EncodeMBCS( const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length, /* number of Py_UNICODE chars to encode */ const char *errors /* error handling */ @@ -1705,7 +1579,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeMBCS( #endif #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 -PyAPI_FUNC(PyObject*) PyUnicode_EncodeCodePage( +PyObject* PyUnicode_EncodeCodePage( int code_page, /* code page number */ PyObject *unicode, /* Unicode object */ const char *errors /* error handling */ @@ -1739,7 +1613,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeCodePage( */ #ifndef Py_LIMITED_API -PyAPI_FUNC(int) PyUnicode_EncodeDecimal( +int PyUnicode_EncodeDecimal( Py_UNICODE *s, /* Unicode buffer */ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */ char *output, /* Output buffer; must have size >= length */ @@ -1754,7 +1628,7 @@ PyAPI_FUNC(int) PyUnicode_EncodeDecimal( */ #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) PyUnicode_TransformDecimalToASCII( +PyObject* PyUnicode_TransformDecimalToASCII( Py_UNICODE *s, /* Unicode buffer */ Py_ssize_t length /* Number of Py_UNICODE chars to transform */ ); @@ -1766,7 +1640,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_TransformDecimalToASCII( floatobject, and complexobject did anyways. */ #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) _PyUnicode_TransformDecimalAndSpaceToASCII( +PyObject* _PyUnicode_TransformDecimalAndSpaceToASCII( PyObject *unicode /* Unicode object */ ); #endif @@ -1782,7 +1656,7 @@ PyAPI_FUNC(PyObject*) _PyUnicode_TransformDecimalAndSpaceToASCII( instead of being decoded. *str* must end with a null character but cannot contain embedded null characters. */ -PyAPI_FUNC(PyObject*) PyUnicode_DecodeLocaleAndSize( +PyObject* PyUnicode_DecodeLocaleAndSize( const char *str, Py_ssize_t len, const char *errors); @@ -1790,7 +1664,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_DecodeLocaleAndSize( /* Similar to PyUnicode_DecodeLocaleAndSize(), but compute the string length using strlen(). */ -PyAPI_FUNC(PyObject*) PyUnicode_DecodeLocale( +PyObject* PyUnicode_DecodeLocale( const char *str, const char *errors); @@ -1799,7 +1673,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_DecodeLocale( "surrogateescape" error handler is used. Return a bytes object. The string cannot contain embedded null characters. */ -PyAPI_FUNC(PyObject*) PyUnicode_EncodeLocale( +PyObject* PyUnicode_EncodeLocale( PyObject *unicode, const char *errors ); @@ -1810,12 +1684,12 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeLocale( /* ParseTuple converter: encode str objects to bytes using PyUnicode_EncodeFSDefault(); bytes objects are output as-is. */ -PyAPI_FUNC(int) PyUnicode_FSConverter(PyObject*, void*); +int PyUnicode_FSConverter(PyObject*, void*); /* ParseTuple converter: decode bytes objects to unicode using PyUnicode_DecodeFSDefaultAndSize(); str objects are output as-is. */ -PyAPI_FUNC(int) PyUnicode_FSDecoder(PyObject*, void*); +int PyUnicode_FSDecoder(PyObject*, void*); /* Decode a null-terminated string using Py_FileSystemDefaultEncoding and the "surrogateescape" error handler. @@ -1826,7 +1700,7 @@ PyAPI_FUNC(int) PyUnicode_FSDecoder(PyObject*, void*); Use PyUnicode_DecodeFSDefaultAndSize() if the string length is known. */ -PyAPI_FUNC(PyObject*) PyUnicode_DecodeFSDefault( +PyObject* PyUnicode_DecodeFSDefault( const char *s /* encoded string */ ); @@ -1837,7 +1711,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_DecodeFSDefault( encoding. */ -PyAPI_FUNC(PyObject*) PyUnicode_DecodeFSDefaultAndSize( +PyObject* PyUnicode_DecodeFSDefaultAndSize( const char *s, /* encoded string */ Py_ssize_t size /* size */ ); @@ -1849,7 +1723,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_DecodeFSDefaultAndSize( encoding. */ -PyAPI_FUNC(PyObject*) PyUnicode_EncodeFSDefault( +PyObject* PyUnicode_EncodeFSDefault( PyObject *unicode ); @@ -1861,7 +1735,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeFSDefault( /* Concat two strings giving a new Unicode string. */ -PyAPI_FUNC(PyObject*) PyUnicode_Concat( +PyObject* PyUnicode_Concat( PyObject *left, /* Left string */ PyObject *right /* Right string */ ); @@ -1869,7 +1743,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_Concat( /* Concat two strings and put the result in *pleft (sets *pleft to NULL on error) */ -PyAPI_FUNC(void) PyUnicode_Append( +void PyUnicode_Append( PyObject **pleft, /* Pointer to left string */ PyObject *right /* Right string */ ); @@ -1877,7 +1751,7 @@ PyAPI_FUNC(void) PyUnicode_Append( /* Concat two strings, put the result in *pleft and drop the right object (sets *pleft to NULL on error) */ -PyAPI_FUNC(void) PyUnicode_AppendAndDel( +void PyUnicode_AppendAndDel( PyObject **pleft, /* Pointer to left string */ PyObject *right /* Right string */ ); @@ -1893,7 +1767,7 @@ PyAPI_FUNC(void) PyUnicode_AppendAndDel( */ -PyAPI_FUNC(PyObject*) PyUnicode_Split( +PyObject* PyUnicode_Split( PyObject *s, /* String to split */ PyObject *sep, /* String separator */ Py_ssize_t maxsplit /* Maxsplit count */ @@ -1904,14 +1778,14 @@ PyAPI_FUNC(PyObject*) PyUnicode_Split( CRLF is considered to be one line break. Line breaks are not included in the resulting list. */ -PyAPI_FUNC(PyObject*) PyUnicode_Splitlines( +PyObject* PyUnicode_Splitlines( PyObject *s, /* String to split */ int keepends /* If true, line end markers are included */ ); /* Partition a string using a given separator. */ -PyAPI_FUNC(PyObject*) PyUnicode_Partition( +PyObject* PyUnicode_Partition( PyObject *s, /* String to partition */ PyObject *sep /* String separator */ ); @@ -1919,7 +1793,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_Partition( /* Partition a string using a given separator, searching from the end of the string. */ -PyAPI_FUNC(PyObject*) PyUnicode_RPartition( +PyObject* PyUnicode_RPartition( PyObject *s, /* String to partition */ PyObject *sep /* String separator */ ); @@ -1937,7 +1811,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_RPartition( */ -PyAPI_FUNC(PyObject*) PyUnicode_RSplit( +PyObject* PyUnicode_RSplit( PyObject *s, /* String to split */ PyObject *sep, /* String separator */ Py_ssize_t maxsplit /* Maxsplit count */ @@ -1955,7 +1829,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_RSplit( */ -PyAPI_FUNC(PyObject *) PyUnicode_Translate( +PyObject * PyUnicode_Translate( PyObject *str, /* String */ PyObject *table, /* Translate table */ const char *errors /* error handling */ @@ -1964,13 +1838,13 @@ PyAPI_FUNC(PyObject *) PyUnicode_Translate( /* Join a sequence of strings using the given separator and return the resulting Unicode string. */ -PyAPI_FUNC(PyObject*) PyUnicode_Join( +PyObject* PyUnicode_Join( PyObject *separator, /* Separator string */ PyObject *seq /* Sequence object */ ); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) _PyUnicode_JoinArray( +PyObject * _PyUnicode_JoinArray( PyObject *separator, PyObject **items, Py_ssize_t seqlen @@ -1980,7 +1854,7 @@ PyAPI_FUNC(PyObject *) _PyUnicode_JoinArray( /* Return 1 if substr matches str[start:end] at the given tail end, 0 otherwise. */ -PyAPI_FUNC(Py_ssize_t) PyUnicode_Tailmatch( +Py_ssize_t PyUnicode_Tailmatch( PyObject *str, /* String */ PyObject *substr, /* Prefix or Suffix string */ Py_ssize_t start, /* Start index */ @@ -1992,7 +1866,7 @@ PyAPI_FUNC(Py_ssize_t) PyUnicode_Tailmatch( given search direction or -1 if not found. -2 is returned in case an error occurred and an exception is set. */ -PyAPI_FUNC(Py_ssize_t) PyUnicode_Find( +Py_ssize_t PyUnicode_Find( PyObject *str, /* String */ PyObject *substr, /* Substring to find */ Py_ssize_t start, /* Start index */ @@ -2002,7 +1876,7 @@ PyAPI_FUNC(Py_ssize_t) PyUnicode_Find( #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 /* Like PyUnicode_Find, but search for single character only. */ -PyAPI_FUNC(Py_ssize_t) PyUnicode_FindChar( +Py_ssize_t PyUnicode_FindChar( PyObject *str, Py_UCS4 ch, Py_ssize_t start, @@ -2013,7 +1887,7 @@ PyAPI_FUNC(Py_ssize_t) PyUnicode_FindChar( /* Count the number of occurrences of substr in str[start:end]. */ -PyAPI_FUNC(Py_ssize_t) PyUnicode_Count( +Py_ssize_t PyUnicode_Count( PyObject *str, /* String */ PyObject *substr, /* Substring to count */ Py_ssize_t start, /* Start index */ @@ -2023,7 +1897,7 @@ PyAPI_FUNC(Py_ssize_t) PyUnicode_Count( /* Replace at most maxcount occurrences of substr in str with replstr and return the resulting Unicode object. */ -PyAPI_FUNC(PyObject *) PyUnicode_Replace( +PyObject * PyUnicode_Replace( PyObject *str, /* String */ PyObject *substr, /* Substring to find */ PyObject *replstr, /* Substring to replace */ @@ -2035,7 +1909,7 @@ PyAPI_FUNC(PyObject *) PyUnicode_Replace( greater than resp. Raise an exception and return -1 on error. */ -PyAPI_FUNC(int) PyUnicode_Compare( +int PyUnicode_Compare( PyObject *left, /* Left string */ PyObject *right /* Right string */ ); @@ -2045,7 +1919,7 @@ PyAPI_FUNC(int) PyUnicode_Compare( 0 otherwise. The right argument must be ASCII identifier. Any error occurs inside will be cleared before return. */ -PyAPI_FUNC(int) _PyUnicode_EqualToASCIIId( +int _PyUnicode_EqualToASCIIId( PyObject *left, /* Left string */ _Py_Identifier *right /* Right identifier */ ); @@ -2057,7 +1931,7 @@ PyAPI_FUNC(int) _PyUnicode_EqualToASCIIId( ISO-8859-1 if it contains non-ASCII characters. This function does not raise exceptions. */ -PyAPI_FUNC(int) PyUnicode_CompareWithASCIIString( +int PyUnicode_CompareWithASCIIString( PyObject *left, const char *right /* ASCII-encoded string */ ); @@ -2067,7 +1941,7 @@ PyAPI_FUNC(int) PyUnicode_CompareWithASCIIString( 0 otherwise. The right argument must be ASCII-encoded string. Any error occurs inside will be cleared before return. */ -PyAPI_FUNC(int) _PyUnicode_EqualToASCIIString( +int _PyUnicode_EqualToASCIIString( PyObject *left, const char *right /* ASCII-encoded string */ ); @@ -2085,7 +1959,7 @@ PyAPI_FUNC(int) _PyUnicode_EqualToASCIIString( */ -PyAPI_FUNC(PyObject *) PyUnicode_RichCompare( +PyObject * PyUnicode_RichCompare( PyObject *left, /* Left string */ PyObject *right, /* Right string */ int op /* Operation: Py_EQ, Py_NE, Py_GT, etc. */ @@ -2094,7 +1968,7 @@ PyAPI_FUNC(PyObject *) PyUnicode_RichCompare( /* Apply an argument tuple or dictionary to a format string and return the resulting Unicode string. */ -PyAPI_FUNC(PyObject *) PyUnicode_Format( +PyObject * PyUnicode_Format( PyObject *format, /* Format string */ PyObject *args /* Argument tuple or dictionary */ ); @@ -2105,18 +1979,18 @@ PyAPI_FUNC(PyObject *) PyUnicode_Format( element has to coerce to a one element Unicode string. -1 is returned in case of an error. */ -PyAPI_FUNC(int) PyUnicode_Contains( +int PyUnicode_Contains( PyObject *container, /* Container string */ PyObject *element /* Element string */ ); /* Checks whether argument is a valid identifier. */ -PyAPI_FUNC(int) PyUnicode_IsIdentifier(PyObject *s); +int PyUnicode_IsIdentifier(PyObject *s); #ifndef Py_LIMITED_API /* Externally visible for str.strip(unicode) */ -PyAPI_FUNC(PyObject *) _PyUnicode_XStrip( +PyObject * _PyUnicode_XStrip( PyObject *self, int striptype, PyObject *sepobj @@ -2127,7 +2001,7 @@ PyAPI_FUNC(PyObject *) _PyUnicode_XStrip( into the string pointed to by buffer. For the argument descriptions, see Objects/stringlib/localeutil.h */ #ifndef Py_LIMITED_API -PyAPI_FUNC(Py_ssize_t) _PyUnicode_InsertThousandsGrouping( +Py_ssize_t _PyUnicode_InsertThousandsGrouping( _PyUnicodeWriter *writer, Py_ssize_t n_buffer, PyObject *digits, @@ -2143,7 +2017,7 @@ PyAPI_FUNC(Py_ssize_t) _PyUnicode_InsertThousandsGrouping( /* Helper array used by Py_UNICODE_ISSPACE(). */ #ifndef Py_LIMITED_API -PyAPI_DATA(const unsigned char) _Py_ascii_whitespace[]; +extern const unsigned char _Py_ascii_whitespace[]; /* These should not be used directly. Use the Py_UNICODE_IS* and Py_UNICODE_TO* macros instead. @@ -2152,156 +2026,156 @@ PyAPI_DATA(const unsigned char) _Py_ascii_whitespace[]; */ -PyAPI_FUNC(int) _PyUnicode_IsLowercase( +int _PyUnicode_IsLowercase( Py_UCS4 ch /* Unicode character */ ); -PyAPI_FUNC(int) _PyUnicode_IsUppercase( +int _PyUnicode_IsUppercase( Py_UCS4 ch /* Unicode character */ ); -PyAPI_FUNC(int) _PyUnicode_IsTitlecase( +int _PyUnicode_IsTitlecase( Py_UCS4 ch /* Unicode character */ ); -PyAPI_FUNC(int) _PyUnicode_IsXidStart( +int _PyUnicode_IsXidStart( Py_UCS4 ch /* Unicode character */ ); -PyAPI_FUNC(int) _PyUnicode_IsXidContinue( +int _PyUnicode_IsXidContinue( Py_UCS4 ch /* Unicode character */ ); -PyAPI_FUNC(int) _PyUnicode_IsWhitespace( +int _PyUnicode_IsWhitespace( const Py_UCS4 ch /* Unicode character */ ); -PyAPI_FUNC(int) _PyUnicode_IsLinebreak( +int _PyUnicode_IsLinebreak( const Py_UCS4 ch /* Unicode character */ ); -PyAPI_FUNC(Py_UCS4) _PyUnicode_ToLowercase( +Py_UCS4 _PyUnicode_ToLowercase( Py_UCS4 ch /* Unicode character */ ); -PyAPI_FUNC(Py_UCS4) _PyUnicode_ToUppercase( +Py_UCS4 _PyUnicode_ToUppercase( Py_UCS4 ch /* Unicode character */ ); -PyAPI_FUNC(Py_UCS4) _PyUnicode_ToTitlecase( +Py_UCS4 _PyUnicode_ToTitlecase( Py_UCS4 ch /* Unicode character */ ); -PyAPI_FUNC(int) _PyUnicode_ToLowerFull( +int _PyUnicode_ToLowerFull( Py_UCS4 ch, /* Unicode character */ Py_UCS4 *res ); -PyAPI_FUNC(int) _PyUnicode_ToTitleFull( +int _PyUnicode_ToTitleFull( Py_UCS4 ch, /* Unicode character */ Py_UCS4 *res ); -PyAPI_FUNC(int) _PyUnicode_ToUpperFull( +int _PyUnicode_ToUpperFull( Py_UCS4 ch, /* Unicode character */ Py_UCS4 *res ); -PyAPI_FUNC(int) _PyUnicode_ToFoldedFull( +int _PyUnicode_ToFoldedFull( Py_UCS4 ch, /* Unicode character */ Py_UCS4 *res ); -PyAPI_FUNC(int) _PyUnicode_IsCaseIgnorable( +int _PyUnicode_IsCaseIgnorable( Py_UCS4 ch /* Unicode character */ ); -PyAPI_FUNC(int) _PyUnicode_IsCased( +int _PyUnicode_IsCased( Py_UCS4 ch /* Unicode character */ ); -PyAPI_FUNC(int) _PyUnicode_ToDecimalDigit( +int _PyUnicode_ToDecimalDigit( Py_UCS4 ch /* Unicode character */ ); -PyAPI_FUNC(int) _PyUnicode_ToDigit( +int _PyUnicode_ToDigit( Py_UCS4 ch /* Unicode character */ ); -PyAPI_FUNC(double) _PyUnicode_ToNumeric( +double _PyUnicode_ToNumeric( Py_UCS4 ch /* Unicode character */ ); -PyAPI_FUNC(int) _PyUnicode_IsDecimalDigit( +int _PyUnicode_IsDecimalDigit( Py_UCS4 ch /* Unicode character */ ); -PyAPI_FUNC(int) _PyUnicode_IsDigit( +int _PyUnicode_IsDigit( Py_UCS4 ch /* Unicode character */ ); -PyAPI_FUNC(int) _PyUnicode_IsNumeric( +int _PyUnicode_IsNumeric( Py_UCS4 ch /* Unicode character */ ); -PyAPI_FUNC(int) _PyUnicode_IsPrintable( +int _PyUnicode_IsPrintable( Py_UCS4 ch /* Unicode character */ ); -PyAPI_FUNC(int) _PyUnicode_IsAlpha( +int _PyUnicode_IsAlpha( Py_UCS4 ch /* Unicode character */ ); -PyAPI_FUNC(size_t) Py_UNICODE_strlen( +size_t Py_UNICODE_strlen( const Py_UNICODE *u ); -PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strcpy( +Py_UNICODE* Py_UNICODE_strcpy( Py_UNICODE *s1, const Py_UNICODE *s2); -PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strcat( +Py_UNICODE* Py_UNICODE_strcat( Py_UNICODE *s1, const Py_UNICODE *s2); -PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strncpy( +Py_UNICODE* Py_UNICODE_strncpy( Py_UNICODE *s1, const Py_UNICODE *s2, size_t n); -PyAPI_FUNC(int) Py_UNICODE_strcmp( +int Py_UNICODE_strcmp( const Py_UNICODE *s1, const Py_UNICODE *s2 ); -PyAPI_FUNC(int) Py_UNICODE_strncmp( +int Py_UNICODE_strncmp( const Py_UNICODE *s1, const Py_UNICODE *s2, size_t n ); -PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strchr( +Py_UNICODE* Py_UNICODE_strchr( const Py_UNICODE *s, Py_UNICODE c ); -PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strrchr( +Py_UNICODE* Py_UNICODE_strrchr( const Py_UNICODE *s, Py_UNICODE c ); -PyAPI_FUNC(PyObject*) _PyUnicode_FormatLong(PyObject *, int, int, int); +PyObject* _PyUnicode_FormatLong(PyObject *, int, int, int); /* Create a copy of a unicode string ending with a nul character. Return NULL and raise a MemoryError exception on memory allocation failure, otherwise return a new allocated buffer (use PyMem_Free() to free the buffer). */ -PyAPI_FUNC(Py_UNICODE*) PyUnicode_AsUnicodeCopy( +Py_UNICODE* PyUnicode_AsUnicodeCopy( PyObject *unicode ); #endif /* Py_LIMITED_API */ #if defined(Py_DEBUG) && !defined(Py_LIMITED_API) -PyAPI_FUNC(int) _PyUnicode_CheckConsistency( +int _PyUnicode_CheckConsistency( PyObject *op, int check_content); #elif !defined(NDEBUG) @@ -2312,13 +2186,13 @@ PyAPI_FUNC(int) _PyUnicode_CheckConsistency( #ifndef Py_LIMITED_API /* Return an interned Unicode object for an Identifier; may fail if there is no memory.*/ -PyAPI_FUNC(PyObject*) _PyUnicode_FromId(_Py_Identifier*); +PyObject* _PyUnicode_FromId(_Py_Identifier*); /* Clear all static strings. */ -PyAPI_FUNC(void) _PyUnicode_ClearStaticStrings(void); +void _PyUnicode_ClearStaticStrings(void); /* Fast equality check when the inputs are known to be exact unicode types and where the hash values are equal (i.e. a very probable match) */ -PyAPI_FUNC(int) _PyUnicode_EQ(PyObject *, PyObject *); +int _PyUnicode_EQ(PyObject *, PyObject *); #endif /* !Py_LIMITED_API */ COSMOPOLITAN_C_END_ diff --git a/third_party/python/Include/warnings.h b/third_party/python/Include/warnings.h index 7bada505f..d562e909e 100644 --- a/third_party/python/Include/warnings.h +++ b/third_party/python/Include/warnings.h @@ -1,60 +1,35 @@ #ifndef Py_WARNINGS_H #define Py_WARNINGS_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ -/* clang-format off */ #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject*) _PyWarnings_Init(void); +PyObject *_PyWarnings_Init(void); #endif -PyAPI_FUNC(int) PyErr_WarnEx( - PyObject *category, - const char *message, /* UTF-8 encoded string */ - Py_ssize_t stack_level); -PyAPI_FUNC(int) PyErr_WarnFormat( - PyObject *category, - Py_ssize_t stack_level, - const char *format, /* ASCII-encoded string */ - ...); +int PyErr_WarnEx(PyObject *, const char *, Py_ssize_t); +int PyErr_WarnFormat(PyObject *, Py_ssize_t, const char *, ...); -#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03060000 -/* Emit a ResourceWarning warning */ -PyAPI_FUNC(int) PyErr_ResourceWarning( - PyObject *source, - Py_ssize_t stack_level, - const char *format, /* ASCII-encoded string */ - ...); +#if !defined(Py_LIMITED_API) || Py_LIMITED_API + 0 >= 0x03060000 +int PyErr_ResourceWarning(PyObject *, Py_ssize_t, const char *, ...); #endif -#ifndef Py_LIMITED_API -PyAPI_FUNC(int) PyErr_WarnExplicitObject( - PyObject *category, - PyObject *message, - PyObject *filename, - int lineno, - PyObject *module, - PyObject *registry); -#endif -PyAPI_FUNC(int) PyErr_WarnExplicit( - PyObject *category, - const char *message, /* UTF-8 encoded string */ - const char *filename, /* decoded from the filesystem encoding */ - int lineno, - const char *module, /* UTF-8 encoded string */ - PyObject *registry); #ifndef Py_LIMITED_API -PyAPI_FUNC(int) -PyErr_WarnExplicitFormat(PyObject *category, - const char *filename, int lineno, - const char *module, PyObject *registry, - const char *format, ...); +int PyErr_WarnExplicitObject(PyObject *, PyObject *, PyObject *, int, + PyObject *, PyObject *); +#endif + +int PyErr_WarnExplicit(PyObject *, const char *, const char *, int, + const char *, PyObject *); + +#ifndef Py_LIMITED_API +int PyErr_WarnExplicitFormat(PyObject *, const char *, int, const char *, + PyObject *, const char *, ...); #endif -/* DEPRECATED: Use PyErr_WarnEx() instead. */ #ifndef Py_LIMITED_API #define PyErr_Warn(category, msg) PyErr_WarnEx(category, msg, 1) #endif COSMOPOLITAN_C_END_ #endif /* !Py_WARNINGS_H */ - diff --git a/third_party/python/Include/weakrefobject.h b/third_party/python/Include/weakrefobject.h index 61a448835..a03148eb5 100644 --- a/third_party/python/Include/weakrefobject.h +++ b/third_party/python/Include/weakrefobject.h @@ -1,5 +1,6 @@ #ifndef Py_WEAKREFOBJECT_H #define Py_WEAKREFOBJECT_H +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ @@ -36,9 +37,9 @@ struct _PyWeakReference { }; #endif -PyAPI_DATA(PyTypeObject) _PyWeakref_RefType; -PyAPI_DATA(PyTypeObject) _PyWeakref_ProxyType; -PyAPI_DATA(PyTypeObject) _PyWeakref_CallableProxyType; +extern PyTypeObject _PyWeakref_RefType; +extern PyTypeObject _PyWeakref_ProxyType; +extern PyTypeObject _PyWeakref_CallableProxyType; #define PyWeakref_CheckRef(op) PyObject_TypeCheck(op, &_PyWeakref_RefType) #define PyWeakref_CheckRefExact(op) \ @@ -51,16 +52,16 @@ PyAPI_DATA(PyTypeObject) _PyWeakref_CallableProxyType; (PyWeakref_CheckRef(op) || PyWeakref_CheckProxy(op)) -PyAPI_FUNC(PyObject *) PyWeakref_NewRef(PyObject *ob, +PyObject * PyWeakref_NewRef(PyObject *ob, PyObject *callback); -PyAPI_FUNC(PyObject *) PyWeakref_NewProxy(PyObject *ob, +PyObject * PyWeakref_NewProxy(PyObject *ob, PyObject *callback); -PyAPI_FUNC(PyObject *) PyWeakref_GetObject(PyObject *ref); +PyObject * PyWeakref_GetObject(PyObject *ref); #ifndef Py_LIMITED_API -PyAPI_FUNC(Py_ssize_t) _PyWeakref_GetWeakrefCount(PyWeakReference *head); +Py_ssize_t _PyWeakref_GetWeakrefCount(PyWeakReference *head); -PyAPI_FUNC(void) _PyWeakref_ClearRef(PyWeakReference *self); +void _PyWeakref_ClearRef(PyWeakReference *self); #endif /* Explanation for the Py_REFCNT() check: when a weakref's target is part diff --git a/third_party/python/Lib/_osx_support.py b/third_party/python/Lib/_osx_support.py index db6674ea2..e7d4e90e7 100644 --- a/third_party/python/Lib/_osx_support.py +++ b/third_party/python/Lib/_osx_support.py @@ -15,9 +15,9 @@ __all__ = [ # like "-arch" or "-isdkroot", that may need customization for # the user environment _UNIVERSAL_CONFIG_VARS = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS', 'BASECFLAGS', - 'BLDSHARED', 'LDSHARED', 'CC', 'CXX', - 'PY_CFLAGS', 'PY_LDFLAGS', 'PY_CPPFLAGS', - 'PY_CORE_CFLAGS', 'PY_CORE_LDFLAGS') + 'BLDSHARED', 'LDSHARED', 'CC', 'CXX', + 'PY_CFLAGS', 'PY_LDFLAGS', 'PY_CPPFLAGS', + 'PY_CORE_CFLAGS', 'PY_CORE_LDFLAGS') # configuration variables that may contain compiler calls _COMPILER_CONFIG_VARS = ('BLDSHARED', 'LDSHARED', 'CC', 'CXX') diff --git a/third_party/python/Lib/_sysconfigdata_m_cosmo_x86_64-cosmo.py b/third_party/python/Lib/_sysconfigdata_m_cosmo_x86_64-cosmo.py index c8aa99aef..f1628c56e 100644 --- a/third_party/python/Lib/_sysconfigdata_m_cosmo_x86_64-cosmo.py +++ b/third_party/python/Lib/_sysconfigdata_m_cosmo_x86_64-cosmo.py @@ -10,14 +10,13 @@ build_time_vars = {'ABIFLAGS': 'm', 'BASEMODLIBS': '', 'BINDIR': '/bin', 'BINLIBDEST': '/lib/python3.6', - 'BLAKE_SSE': "'BLAKE_USE_SSE=1'", 'BLDLIBRARY': 'libpython3.6m.a', 'BLDSHARED': 'gcc -shared -static -nostdlib -nostdinc -fno-pie ' '-mno-red-zone -include ' '/cpython36/libcosmo/cosmopolitan.h', 'BUILDEXE': '.com.dbg', 'BUILDPYTHON': 'python.com.dbg', - 'BUILD_GNU_TYPE': 'x86_64-pc-linux-gnu', + 'BUILD_GNU_TYPE': 'x86_64-pc-cosmo-gnu', 'BYTESTR_DEPS': '\\', 'CC': 'gcc', 'CCSHARED': '-fPIC', @@ -126,7 +125,7 @@ build_time_vars = {'ABIFLAGS': 'm', 'EXTRAMACHDEPPATH': '', 'EXTRATESTOPTS': '', 'EXTRA_CFLAGS': '', - 'EXT_SUFFIX': '.cpython-36m-x86_64-linux-gnu.so', + 'EXT_SUFFIX': '.cpython-36m-x86_64-cosmo-gnu.so', 'FILEMODE': 644, 'FLOCK_NEEDS_LIBBSD': 0, 'GETPGRP_HAVE_ARG': 0, @@ -207,8 +206,8 @@ build_time_vars = {'ABIFLAGS': 'm', 'HAVE_DUP3': 1, 'HAVE_DYNAMIC_LOADING': 1, 'HAVE_ENDIAN_H': 0, - 'HAVE_EPOLL': 1, - 'HAVE_EPOLL_CREATE1': 1, + 'HAVE_EPOLL': 0, + 'HAVE_EPOLL_CREATE1': 0, 'HAVE_ERF': 1, 'HAVE_ERFC': 1, 'HAVE_ERRNO_H': 1, @@ -309,13 +308,13 @@ build_time_vars = {'ABIFLAGS': 'm', 'HAVE_LIBUTIL_H': 0, 'HAVE_LINK': 1, 'HAVE_LINKAT': 1, - 'HAVE_LINUX_CAN_BCM_H': 0, - 'HAVE_LINUX_CAN_H': 0, - 'HAVE_LINUX_CAN_RAW_FD_FRAMES': 0, - 'HAVE_LINUX_CAN_RAW_H': 0, - 'HAVE_LINUX_NETLINK_H': 0, - 'HAVE_LINUX_RANDOM_H': 0, - 'HAVE_LINUX_TIPC_H': 0, + 'HAVE_COSMO_CAN_BCM_H': 0, + 'HAVE_COSMO_CAN_H': 0, + 'HAVE_COSMO_CAN_RAW_FD_FRAMES': 0, + 'HAVE_COSMO_CAN_RAW_H': 0, + 'HAVE_COSMO_NETLINK_H': 0, + 'HAVE_COSMO_RANDOM_H': 0, + 'HAVE_COSMO_TIPC_H': 0, 'HAVE_LOCKF': 0, 'HAVE_LOG1P': 1, 'HAVE_LOG2': 1, @@ -347,7 +346,6 @@ build_time_vars = {'ABIFLAGS': 'm', 'HAVE_PIPE2': 1, 'HAVE_PLOCK': 0, 'HAVE_POLL': 1, - 'HAVE_POLL_H': 1, 'HAVE_POSIX_FADVISE': 1, 'HAVE_POSIX_FALLOCATE': 0, 'HAVE_PREAD': 1, @@ -522,9 +520,9 @@ build_time_vars = {'ABIFLAGS': 'm', 'HAVE_WMEMCMP': 1, 'HAVE_WORKING_TZSET': 1, 'HAVE_WRITEV': 1, - 'HAVE_ZLIB_COPY': 0, + 'HAVE_ZLIB_COPY': 1, 'HAVE__GETPTY': 0, - 'HOST_GNU_TYPE': 'x86_64-pc-linux-gnu', + 'HOST_GNU_TYPE': 'x86_64-pc-cosmo-gnu', 'INCLDIRSTOMAKE': '/include /include /include/python3.6m /include/python3.6m', 'INCLUDEDIR': '/include', 'INCLUDEPY': '/include/python3.6m', @@ -556,7 +554,7 @@ build_time_vars = {'ABIFLAGS': 'm', 'LIBOBJDIR': 'Python/', 'LIBOBJS': '', 'LIBPC': '/lib/pkgconfig', - 'LIBPL': '/lib/python3.6/config-3.6m-x86_64-linux-gnu', + 'LIBPL': '/lib/python3.6/config-3.6m-x86_64-cosmo-gnu', 'LIBRARY': 'libpython3.6m.a', 'LIBRARY_OBJS': '\\', 'LIBRARY_OBJS_OMIT_FROZEN': '\\', @@ -577,7 +575,7 @@ build_time_vars = {'ABIFLAGS': 'm', 'LN': 'ln', 'LOCALMODLIBS': '', 'LOG1P_DROPS_ZERO_SIGN': 0, - 'MACHDEP': 'linux', + 'MACHDEP': 'cosmo', 'MACHDEPPATH': ':', 'MACHDEP_OBJS': '', 'MACHDESTLIB': '/lib/python3.6', @@ -595,7 +593,7 @@ build_time_vars = {'ABIFLAGS': 'm', '_tracemalloc _symtable array cmath math _struct _weakref ' '_testcapi _random _elementtree _pickle _datetime _bisect _heapq ' 'unicodedata fcntl grp select mmap _csv _socket resource ' - '_posixsubprocess _md5 _sha1 _sha256 _sha512 _sha3 _blake2 syslog ' + '_posixsubprocess _md5 _sha1 _sha256 _sha512 _sha3 syslog ' 'binascii parser fpectl zlib pyexpat _multibytecodec _codecs_cn ' '_codecs_hk _codecs_iso2022 _codecs_jp _codecs_kr _codecs_tw ' '_json _lsprof _opcode', @@ -626,8 +624,7 @@ build_time_vars = {'ABIFLAGS': 'm', 'Modules/resource.o Modules/_posixsubprocess.o ' 'Modules/md5module.o Modules/sha1module.o ' 'Modules/sha256module.o Modules/sha512module.o ' - 'Modules/sha3module.o Modules/blake2module.o ' - 'Modules/blake2b_impl.o Modules/blake2s_impl.o ' + 'Modules/_sha3.o ' 'Modules/syslogmodule.o Modules/binascii.o ' 'Modules/parsermodule.o Modules/fpectlmodule.o ' 'Modules/zlibmodule.o Modules/xmlparse.o Modules/xmlrole.o ' @@ -638,8 +635,8 @@ build_time_vars = {'ABIFLAGS': 'm', 'Modules/_json.o Modules/_lsprof.o Modules/rotatingtree.o ' 'Modules/_opcode.o', 'MODULE_OBJS': '\\', - 'MULTIARCH': 'x86_64-linux-gnu', - 'MULTIARCH_CPPFLAGS': '-DMULTIARCH=\\"x86_64-linux-gnu\\"', + 'MULTIARCH': 'x86_64-cosmo-gnu', + 'MULTIARCH_CPPFLAGS': '-DMULTIARCH=\\"x86_64-cosmo-gnu\\"', 'MVWDELCH_IS_EXPRESSION': 1, 'NO_AS_NEEDED': '-Wl,--no-as-needed', 'OBJECT_OBJS': '\\', @@ -762,7 +759,7 @@ build_time_vars = {'ABIFLAGS': 'm', 'SIZEOF_VOID_P': 8, 'SIZEOF_WCHAR_T': 4, 'SIZEOF__BOOL': 1, - 'SOABI': 'cpython-36m-x86_64-linux-gnu', + 'SOABI': 'cpython-36m-x86_64-cosmo', 'SRCDIRS': 'Parser Objects Python Modules Programs', 'SRC_GDB_HOOKS': './Tools/gdb/libpython.py', 'STDC_HEADERS': 1, diff --git a/third_party/python/Lib/hashlib.py b/third_party/python/Lib/hashlib.py index 98d2d7981..7e0a7dd09 100644 --- a/third_party/python/Lib/hashlib.py +++ b/third_party/python/Lib/hashlib.py @@ -11,7 +11,7 @@ new(name, data=b'', **kwargs) - returns a new hash object implementing the Named constructor functions are also available, these are faster than using new(name): -md5(), sha1(), sha224(), sha256(), sha384(), sha512(), blake2b(), blake2s(), +md5(), sha1(), sha224(), sha256(), sha384(), sha512(), sha3_224, sha3_256, sha3_384, sha3_512, shake_128, and shake_256. More algorithms may be available on your platform but the above are guaranteed @@ -56,7 +56,6 @@ More condensed: # This tuple and __get_builtin_constructor() must be modified if a new # always available algorithm is added. __always_supported = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512', - 'blake2b', 'blake2s', 'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512', 'shake_128', 'shake_256') @@ -90,10 +89,6 @@ def __get_builtin_constructor(name): import _sha512 cache['SHA384'] = cache['sha384'] = _sha512.sha384 cache['SHA512'] = cache['sha512'] = _sha512.sha512 - elif name in ('blake2b', 'blake2s'): - import _blake2 - cache['blake2b'] = _blake2.blake2b - cache['blake2s'] = _blake2.blake2s elif name in {'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512', 'shake_128', 'shake_256'}: import _sha3 @@ -114,9 +109,6 @@ def __get_builtin_constructor(name): def __get_openssl_constructor(name): - if name in {'blake2b', 'blake2s'}: - # Prefer our blake2 implementation. - return __get_builtin_constructor(name) try: f = getattr(_hashlib, 'openssl_' + name) # Allow the C module to raise ValueError. The function will be @@ -140,12 +132,6 @@ def __hash_new(name, data=b'', **kwargs): """new(name, data=b'') - Return a new hashing object using the named algorithm; optionally initialized with data (which must be a bytes-like object). """ - if name in {'blake2b', 'blake2s'}: - # Prefer our blake2 implementation. - # OpenSSL 1.1.0 comes with a limited implementation of blake2b/s. - # It does neither support keyed blake2 nor advanced features like - # salt, personal, tree hashing or SSE. - return __get_builtin_constructor(name)(data, **kwargs) try: return _hashlib.new(name, data) except ValueError: diff --git a/third_party/python/Lib/lib2to3/pgen2/conv.py b/third_party/python/Lib/lib2to3/pgen2/conv.py index ed0cac532..7184eff11 100644 --- a/third_party/python/Lib/lib2to3/pgen2/conv.py +++ b/third_party/python/Lib/lib2to3/pgen2/conv.py @@ -86,8 +86,8 @@ class Converter(grammar.Grammar): The file looks as follows. The first two lines are always this: - #include "pgenheaders.h" - #include "grammar.h" + #include "third_party/python/Include/pgenheaders.h" + #include "third_party/python/Include/grammar.h" After that come four blocks: diff --git a/third_party/python/Lib/test/libregrtest/refleak.py b/third_party/python/Lib/test/libregrtest/refleak.py index 18d5bd051..9e914feea 100644 --- a/third_party/python/Lib/test/libregrtest/refleak.py +++ b/third_party/python/Lib/test/libregrtest/refleak.py @@ -235,13 +235,6 @@ def clear_caches(): else: doctest.master = None - try: - ctypes = sys.modules['ctypes'] - except KeyError: - pass - else: - ctypes._reset_cache() - try: typing = sys.modules['typing'] except KeyError: diff --git a/third_party/python/Lib/test/test_hashlib.py b/third_party/python/Lib/test/test_hashlib.py index 5af2d5a2f..ebc33d683 100644 --- a/third_party/python/Lib/test/test_hashlib.py +++ b/third_party/python/Lib/test/test_hashlib.py @@ -30,13 +30,6 @@ COMPILED_WITH_PYDEBUG = hasattr(sys, 'gettotalrefcount') c_hashlib = import_fresh_module('hashlib', fresh=['_hashlib']) py_hashlib = import_fresh_module('hashlib', blocked=['_hashlib']) -try: - import _blake2 -except ImportError: - _blake2 = None - -requires_blake2 = unittest.skipUnless(_blake2, 'requires _blake2') - try: import _sha3 except ImportError: @@ -76,7 +69,6 @@ class HashLibTestCase(unittest.TestCase): supported_hash_names = ( 'md5', 'MD5', 'sha1', 'SHA1', 'sha224', 'SHA224', 'sha256', 'SHA256', 'sha384', 'SHA384', 'sha512', 'SHA512', - 'blake2b', 'blake2s', 'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512', 'shake_128', 'shake_256') @@ -99,10 +91,6 @@ class HashLibTestCase(unittest.TestCase): for algorithm in self.supported_hash_names: algorithms.add(algorithm.lower()) - _blake2 = self._conditional_import_module('_blake2') - if _blake2: - algorithms.update({'blake2b', 'blake2s'}) - self.constructors_to_test = {} for algorithm in algorithms: self.constructors_to_test[algorithm] = set() @@ -146,10 +134,6 @@ class HashLibTestCase(unittest.TestCase): if _sha512: add_builtin_constructor('sha384') add_builtin_constructor('sha512') - if _blake2: - add_builtin_constructor('blake2s') - add_builtin_constructor('blake2b') - _sha3 = self._conditional_import_module('_sha3') if _sha3: add_builtin_constructor('sha3_224') @@ -325,11 +309,6 @@ class HashLibTestCase(unittest.TestCase): self.check_no_unicode('sha384') self.check_no_unicode('sha512') - @requires_blake2 - def test_no_unicode_blake2(self): - self.check_no_unicode('blake2b') - self.check_no_unicode('blake2s') - @requires_sha3 def test_no_unicode_sha3(self): self.check_no_unicode('sha3_224') @@ -393,11 +372,6 @@ class HashLibTestCase(unittest.TestCase): self.check_sha3('shake_128', 256, 1344, b'\x1f') self.check_sha3('shake_256', 512, 1088, b'\x1f') - @requires_blake2 - def test_blocksize_name_blake2(self): - self.check_blocksize_name('blake2b', 128, 64) - self.check_blocksize_name('blake2s', 64, 32) - def test_case_md5_0(self): self.check('md5', b'', 'd41d8cd98f00b204e9800998ecf8427e') @@ -526,195 +500,6 @@ class HashLibTestCase(unittest.TestCase): "e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973eb"+ "de0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b") - def check_blake2(self, constructor, salt_size, person_size, key_size, - digest_size, max_offset): - self.assertEqual(constructor.SALT_SIZE, salt_size) - for i in range(salt_size + 1): - constructor(salt=b'a' * i) - salt = b'a' * (salt_size + 1) - self.assertRaises(ValueError, constructor, salt=salt) - - self.assertEqual(constructor.PERSON_SIZE, person_size) - for i in range(person_size+1): - constructor(person=b'a' * i) - person = b'a' * (person_size + 1) - self.assertRaises(ValueError, constructor, person=person) - - self.assertEqual(constructor.MAX_DIGEST_SIZE, digest_size) - for i in range(1, digest_size + 1): - constructor(digest_size=i) - self.assertRaises(ValueError, constructor, digest_size=-1) - self.assertRaises(ValueError, constructor, digest_size=0) - self.assertRaises(ValueError, constructor, digest_size=digest_size+1) - - self.assertEqual(constructor.MAX_KEY_SIZE, key_size) - for i in range(key_size+1): - constructor(key=b'a' * i) - key = b'a' * (key_size + 1) - self.assertRaises(ValueError, constructor, key=key) - self.assertEqual(constructor().hexdigest(), - constructor(key=b'').hexdigest()) - - for i in range(0, 256): - constructor(fanout=i) - self.assertRaises(ValueError, constructor, fanout=-1) - self.assertRaises(ValueError, constructor, fanout=256) - - for i in range(1, 256): - constructor(depth=i) - self.assertRaises(ValueError, constructor, depth=-1) - self.assertRaises(ValueError, constructor, depth=0) - self.assertRaises(ValueError, constructor, depth=256) - - for i in range(0, 256): - constructor(node_depth=i) - self.assertRaises(ValueError, constructor, node_depth=-1) - self.assertRaises(ValueError, constructor, node_depth=256) - - for i in range(0, digest_size + 1): - constructor(inner_size=i) - self.assertRaises(ValueError, constructor, inner_size=-1) - self.assertRaises(ValueError, constructor, inner_size=digest_size+1) - - constructor(leaf_size=0) - constructor(leaf_size=(1<<32)-1) - self.assertRaises(OverflowError, constructor, leaf_size=-1) - self.assertRaises(OverflowError, constructor, leaf_size=1<<32) - - constructor(node_offset=0) - constructor(node_offset=max_offset) - self.assertRaises(OverflowError, constructor, node_offset=-1) - self.assertRaises(OverflowError, constructor, node_offset=max_offset+1) - - self.assertRaises(TypeError, constructor, data=b'') - self.assertRaises(TypeError, constructor, string=b'') - self.assertRaises(TypeError, constructor, '') - - constructor( - b'', - key=b'', - salt=b'', - person=b'', - digest_size=17, - fanout=1, - depth=1, - leaf_size=256, - node_offset=512, - node_depth=1, - inner_size=7, - last_node=True - ) - - def blake2_rfc7693(self, constructor, md_len, in_len): - def selftest_seq(length, seed): - mask = (1<<32)-1 - a = (0xDEAD4BAD * seed) & mask - b = 1 - out = bytearray(length) - for i in range(length): - t = (a + b) & mask - a, b = b, t - out[i] = (t >> 24) & 0xFF - return out - outer = constructor(digest_size=32) - for outlen in md_len: - for inlen in in_len: - indata = selftest_seq(inlen, inlen) - key = selftest_seq(outlen, outlen) - unkeyed = constructor(indata, digest_size=outlen) - outer.update(unkeyed.digest()) - keyed = constructor(indata, key=key, digest_size=outlen) - outer.update(keyed.digest()) - return outer.hexdigest() - - @requires_blake2 - def test_blake2b(self): - self.check_blake2(hashlib.blake2b, 16, 16, 64, 64, (1<<64)-1) - b2b_md_len = [20, 32, 48, 64] - b2b_in_len = [0, 3, 128, 129, 255, 1024] - self.assertEqual( - self.blake2_rfc7693(hashlib.blake2b, b2b_md_len, b2b_in_len), - "c23a7800d98123bd10f506c61e29da5603d763b8bbad2e737f5e765a7bccd475") - - @requires_blake2 - def test_case_blake2b_0(self): - self.check('blake2b', b"", - "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419"+ - "d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce") - - @requires_blake2 - def test_case_blake2b_1(self): - self.check('blake2b', b"abc", - "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d1"+ - "7d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923") - - @requires_blake2 - def test_case_blake2b_all_parameters(self): - # This checks that all the parameters work in general, and also that - # parameter byte order doesn't get confused on big endian platforms. - self.check('blake2b', b"foo", - "920568b0c5873b2f0ab67bedb6cf1b2b", - digest_size=16, - key=b"bar", - salt=b"baz", - person=b"bing", - fanout=2, - depth=3, - leaf_size=4, - node_offset=5, - node_depth=6, - inner_size=7, - last_node=True) - - @requires_blake2 - def test_blake2b_vectors(self): - for msg, key, md in read_vectors('blake2b'): - key = bytes.fromhex(key) - self.check('blake2b', msg, md, key=key) - - @requires_blake2 - def test_blake2s(self): - self.check_blake2(hashlib.blake2s, 8, 8, 32, 32, (1<<48)-1) - b2s_md_len = [16, 20, 28, 32] - b2s_in_len = [0, 3, 64, 65, 255, 1024] - self.assertEqual( - self.blake2_rfc7693(hashlib.blake2s, b2s_md_len, b2s_in_len), - "6a411f08ce25adcdfb02aba641451cec53c598b24f4fc787fbdc88797f4c1dfe") - - @requires_blake2 - def test_case_blake2s_0(self): - self.check('blake2s', b"", - "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9") - - @requires_blake2 - def test_case_blake2s_1(self): - self.check('blake2s', b"abc", - "508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982") - - @requires_blake2 - def test_case_blake2s_all_parameters(self): - # This checks that all the parameters work in general, and also that - # parameter byte order doesn't get confused on big endian platforms. - self.check('blake2s', b"foo", - "bf2a8f7fe3c555012a6f8046e646bc75", - digest_size=16, - key=b"bar", - salt=b"baz", - person=b"bing", - fanout=2, - depth=3, - leaf_size=4, - node_offset=5, - node_depth=6, - inner_size=7, - last_node=True) - - @requires_blake2 - def test_blake2s_vectors(self): - for msg, key, md in read_vectors('blake2s'): - key = bytes.fromhex(key) - self.check('blake2s', msg, md, key=key) - @requires_sha3 def test_case_sha3_224_0(self): self.check('sha3_224', b"", diff --git a/third_party/python/Lib/test/test_threading.py b/third_party/python/Lib/test/test_threading.py index ad5427276..429e610f0 100644 --- a/third_party/python/Lib/test/test_threading.py +++ b/third_party/python/Lib/test/test_threading.py @@ -177,93 +177,6 @@ class ThreadTests(BaseTestCase): self.assertRegex(repr(threading._active[tid]), '_DummyThread') del threading._active[tid] - # PyThreadState_SetAsyncExc() is a CPython-only gimmick, not (currently) - # exposed at the Python level. This test relies on ctypes to get at it. - def test_PyThreadState_SetAsyncExc(self): - ctypes = import_module("ctypes") - - set_async_exc = ctypes.pythonapi.PyThreadState_SetAsyncExc - - class AsyncExc(Exception): - pass - - exception = ctypes.py_object(AsyncExc) - - # First check it works when setting the exception from the same thread. - tid = threading.get_ident() - - try: - result = set_async_exc(ctypes.c_long(tid), exception) - # The exception is async, so we might have to keep the VM busy until - # it notices. - while True: - pass - except AsyncExc: - pass - else: - # This code is unreachable but it reflects the intent. If we wanted - # to be smarter the above loop wouldn't be infinite. - self.fail("AsyncExc not raised") - try: - self.assertEqual(result, 1) # one thread state modified - except UnboundLocalError: - # The exception was raised too quickly for us to get the result. - pass - - # `worker_started` is set by the thread when it's inside a try/except - # block waiting to catch the asynchronously set AsyncExc exception. - # `worker_saw_exception` is set by the thread upon catching that - # exception. - worker_started = threading.Event() - worker_saw_exception = threading.Event() - - class Worker(threading.Thread): - def run(self): - self.id = threading.get_ident() - self.finished = False - - try: - while True: - worker_started.set() - time.sleep(0.1) - except AsyncExc: - self.finished = True - worker_saw_exception.set() - - t = Worker() - t.daemon = True # so if this fails, we don't hang Python at shutdown - t.start() - if verbose: - print(" started worker thread") - - # Try a thread id that doesn't make sense. - if verbose: - print(" trying nonsensical thread id") - result = set_async_exc(ctypes.c_long(-1), exception) - self.assertEqual(result, 0) # no thread states modified - - # Now raise an exception in the worker thread. - if verbose: - print(" waiting for worker thread to get started") - ret = worker_started.wait() - self.assertTrue(ret) - if verbose: - print(" verifying worker hasn't exited") - self.assertFalse(t.finished) - if verbose: - print(" attempting to raise asynch exception in worker") - result = set_async_exc(ctypes.c_long(t.id), exception) - self.assertEqual(result, 1) # one thread state modified - if verbose: - print(" waiting for worker to say it caught the exception") - worker_saw_exception.wait(timeout=10) - self.assertTrue(t.finished) - if verbose: - print(" all OK -- joining worker") - if t.finished: - t.join() - # else the thread is still running, and we have no way to kill it - def test_limbo_cleanup(self): # Issue 7481: Failure to start thread should cleanup the limbo map. def fail_new_thread(*args): diff --git a/third_party/python/Modules/_asynciomodule.c b/third_party/python/Modules/_asynciomodule.c index c86c5ff78..d2c02139c 100644 --- a/third_party/python/Modules/_asynciomodule.c +++ b/third_party/python/Modules/_asynciomodule.c @@ -1,7 +1,20 @@ +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/genobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/setobject.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/traceback.h" /* clang-format off */ -#include "Python.h" -#include "structmember.h" - /*[clinic input] module _asyncio diff --git a/third_party/python/Modules/_bisectmodule.c b/third_party/python/Modules/_bisectmodule.c index 3059844ae..e8e0650eb 100644 --- a/third_party/python/Modules/_bisectmodule.c +++ b/third_party/python/Modules/_bisectmodule.c @@ -1,12 +1,17 @@ +#define PY_SSIZE_T_CLEAN +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" /* clang-format off */ + /* Bisection algorithms. Drop in replacement for bisect.py Converted to C by Dmitry Vasiliev (dima at hlabs.spb.ru). */ -#define PY_SSIZE_T_CLEAN -#include "third_party/python/Include/Python.h" - _Py_IDENTIFIER(insert); static Py_ssize_t diff --git a/third_party/python/Modules/_blake2/blake2b2s.py b/third_party/python/Modules/_blake2/blake2b2s.py deleted file mode 100755 index 01cf26521..000000000 --- a/third_party/python/Modules/_blake2/blake2b2s.py +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/python3 - -import os -import re - -HERE = os.path.dirname(os.path.abspath(__file__)) -BLAKE2 = os.path.join(HERE, 'impl') - -PUBLIC_SEARCH = re.compile(r'\ int (blake2[bs]p?[a-z_]*)\(') - - -def getfiles(): - for name in os.listdir(BLAKE2): - name = os.path.join(BLAKE2, name) - if os.path.isfile(name): - yield name - - -def find_public(): - public_funcs = set() - for name in getfiles(): - with open(name) as f: - for line in f: - # find public functions - mo = PUBLIC_SEARCH.search(line) - if mo: - public_funcs.add(mo.group(1)) - - for f in sorted(public_funcs): - print('#define {0:<18} PyBlake2_{0}'.format(f)) - - return public_funcs - - -def main(): - lines = [] - with open(os.path.join(HERE, 'blake2b_impl.c')) as f: - for line in f: - line = line.replace('blake2b', 'blake2s') - line = line.replace('BLAKE2b', 'BLAKE2s') - line = line.replace('BLAKE2B', 'BLAKE2S') - lines.append(line) - with open(os.path.join(HERE, 'blake2s_impl.c'), 'w') as f: - f.write(''.join(lines)) - # find_public() - - -if __name__ == '__main__': - main() diff --git a/third_party/python/Modules/_blake2/blake2b_impl.c b/third_party/python/Modules/_blake2/blake2b_impl.c deleted file mode 100644 index de6dd396c..000000000 --- a/third_party/python/Modules/_blake2/blake2b_impl.c +++ /dev/null @@ -1,464 +0,0 @@ -/* clang-format off */ -/* - * Written in 2013 by Dmitry Chestnykh - * Modified for CPython by Christian Heimes - * - * To the extent possible under law, the author have dedicated all - * copyright and related and neighboring rights to this software to - * the public domain worldwide. This software is distributed without - * any warranty. http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* WARNING: autogenerated file! - * - * The blake2s_impl.c is autogenerated from blake2b_impl.c. - */ - -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/pystrhex.h" -#ifdef WITH_THREAD -#include "third_party/python/Include/pythread.h" -#endif - -#include "third_party/python/Modules/hashlib.h" -#include "third_party/python/Modules/_blake2/blake2ns.h" - -#define HAVE_BLAKE2B 1 -#define BLAKE2_LOCAL_INLINE(type) Py_LOCAL_INLINE(type) - -#include "impl/blake2.h" -#include "impl/blake2-impl.h" /* for secure_zero_memory() and store48() */ - -#ifdef BLAKE2_USE_SSE -#include "impl/blake2b.c" -#else -#include "impl/blake2b-ref.c" -#endif - - -extern PyTypeObject PyBlake2_BLAKE2bType; - -typedef struct { - PyObject_HEAD - blake2b_param param; - blake2b_state state; -#ifdef WITH_THREAD - PyThread_type_lock lock; -#endif -} BLAKE2bObject; - -#include "clinic/blake2b_impl.c.h" - -/*[clinic input] -module _blake2 -class _blake2.blake2b "BLAKE2bObject *" "&PyBlake2_BLAKE2bType" -[clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=d47b0527b39c673f]*/ - - -static BLAKE2bObject * -new_BLAKE2bObject(PyTypeObject *type) -{ - BLAKE2bObject *self; - self = (BLAKE2bObject *)type->tp_alloc(type, 0); -#ifdef WITH_THREAD - if (self != NULL) { - self->lock = NULL; - } -#endif - return self; -} - -/*[clinic input] -@classmethod -_blake2.blake2b.__new__ as py_blake2b_new - data: object(c_default="NULL") = b'' - / - * - digest_size: int(c_default="BLAKE2B_OUTBYTES") = _blake2.blake2b.MAX_DIGEST_SIZE - key: Py_buffer(c_default="NULL", py_default="b''") = None - salt: Py_buffer(c_default="NULL", py_default="b''") = None - person: Py_buffer(c_default="NULL", py_default="b''") = None - fanout: int = 1 - depth: int = 1 - leaf_size as leaf_size_obj: object(c_default="NULL") = 0 - node_offset as node_offset_obj: object(c_default="NULL") = 0 - node_depth: int = 0 - inner_size: int = 0 - last_node: bool = False - -Return a new BLAKE2b hash object. -[clinic start generated code]*/ - -static PyObject * -py_blake2b_new_impl(PyTypeObject *type, PyObject *data, int digest_size, - Py_buffer *key, Py_buffer *salt, Py_buffer *person, - int fanout, int depth, PyObject *leaf_size_obj, - PyObject *node_offset_obj, int node_depth, - int inner_size, int last_node) -/*[clinic end generated code: output=7506d8d890e5f13b input=aca35b33c5612b4b]*/ -{ - BLAKE2bObject *self = NULL; - Py_buffer buf; - - unsigned long leaf_size = 0; - unsigned long long node_offset = 0; - - self = new_BLAKE2bObject(type); - if (self == NULL) { - goto error; - } - - /* Zero parameter block. */ - memset(&self->param, 0, sizeof(self->param)); - - /* Set digest size. */ - if (digest_size <= 0 || digest_size > BLAKE2B_OUTBYTES) { - PyErr_Format(PyExc_ValueError, - "digest_size must be between 1 and %d bytes", - BLAKE2B_OUTBYTES); - goto error; - } - self->param.digest_length = digest_size; - - /* Set salt parameter. */ - if ((salt->obj != NULL) && salt->len) { - if (salt->len > BLAKE2B_SALTBYTES) { - PyErr_Format(PyExc_ValueError, - "maximum salt length is %d bytes", - BLAKE2B_SALTBYTES); - goto error; - } - memcpy(self->param.salt, salt->buf, salt->len); - } - - /* Set personalization parameter. */ - if ((person->obj != NULL) && person->len) { - if (person->len > BLAKE2B_PERSONALBYTES) { - PyErr_Format(PyExc_ValueError, - "maximum person length is %d bytes", - BLAKE2B_PERSONALBYTES); - goto error; - } - memcpy(self->param.personal, person->buf, person->len); - } - - /* Set tree parameters. */ - if (fanout < 0 || fanout > 255) { - PyErr_SetString(PyExc_ValueError, - "fanout must be between 0 and 255"); - goto error; - } - self->param.fanout = (uint8_t)fanout; - - if (depth <= 0 || depth > 255) { - PyErr_SetString(PyExc_ValueError, - "depth must be between 1 and 255"); - goto error; - } - self->param.depth = (uint8_t)depth; - - if (leaf_size_obj != NULL) { - leaf_size = PyLong_AsUnsignedLong(leaf_size_obj); - if (leaf_size == (unsigned long) -1 && PyErr_Occurred()) { - goto error; - } - if (leaf_size > 0xFFFFFFFFU) { - PyErr_SetString(PyExc_OverflowError, "leaf_size is too large"); - goto error; - } - } - // NB: Simple assignment here would be incorrect on big endian platforms. - store32(&(self->param.leaf_length), leaf_size); - - if (node_offset_obj != NULL) { - node_offset = PyLong_AsUnsignedLongLong(node_offset_obj); - if (node_offset == (unsigned long long) -1 && PyErr_Occurred()) { - goto error; - } - } -#ifdef HAVE_BLAKE2S - if (node_offset > 0xFFFFFFFFFFFFULL) { - /* maximum 2**48 - 1 */ - PyErr_SetString(PyExc_OverflowError, "node_offset is too large"); - goto error; - } - store48(&(self->param.node_offset), node_offset); -#else - // NB: Simple assignment here would be incorrect on big endian platforms. - store64(&(self->param.node_offset), node_offset); -#endif - - if (node_depth < 0 || node_depth > 255) { - PyErr_SetString(PyExc_ValueError, - "node_depth must be between 0 and 255"); - goto error; - } - self->param.node_depth = node_depth; - - if (inner_size < 0 || inner_size > BLAKE2B_OUTBYTES) { - PyErr_Format(PyExc_ValueError, - "inner_size must be between 0 and is %d", - BLAKE2B_OUTBYTES); - goto error; - } - self->param.inner_length = inner_size; - - /* Set key length. */ - if ((key->obj != NULL) && key->len) { - if (key->len > BLAKE2B_KEYBYTES) { - PyErr_Format(PyExc_ValueError, - "maximum key length is %d bytes", - BLAKE2B_KEYBYTES); - goto error; - } - self->param.key_length = (uint8_t)key->len; - } - - /* Initialize hash state. */ - if (blake2b_init_param(&self->state, &self->param) < 0) { - PyErr_SetString(PyExc_RuntimeError, - "error initializing hash state"); - goto error; - } - - /* Set last node flag (must come after initialization). */ - self->state.last_node = last_node; - - /* Process key block if any. */ - if (self->param.key_length) { - uint8_t block[BLAKE2B_BLOCKBYTES]; - memset(block, 0, sizeof(block)); - memcpy(block, key->buf, key->len); - blake2b_update(&self->state, block, sizeof(block)); - secure_zero_memory(block, sizeof(block)); - } - - /* Process initial data if any. */ - if (data != NULL) { - GET_BUFFER_VIEW_OR_ERROR(data, &buf, goto error); - - if (buf.len >= HASHLIB_GIL_MINSIZE) { - Py_BEGIN_ALLOW_THREADS - blake2b_update(&self->state, buf.buf, buf.len); - Py_END_ALLOW_THREADS - } else { - blake2b_update(&self->state, buf.buf, buf.len); - } - PyBuffer_Release(&buf); - } - - return (PyObject *)self; - - error: - if (self != NULL) { - Py_DECREF(self); - } - return NULL; -} - -/*[clinic input] -_blake2.blake2b.copy - -Return a copy of the hash object. -[clinic start generated code]*/ - -static PyObject * -_blake2_blake2b_copy_impl(BLAKE2bObject *self) -/*[clinic end generated code: output=ff6acee5f93656ae input=e383c2d199fd8a2e]*/ -{ - BLAKE2bObject *cpy; - - if ((cpy = new_BLAKE2bObject(Py_TYPE(self))) == NULL) - return NULL; - - ENTER_HASHLIB(self); - cpy->param = self->param; - cpy->state = self->state; - LEAVE_HASHLIB(self); - return (PyObject *)cpy; -} - -/*[clinic input] -_blake2.blake2b.update - - data: object - / - -Update this hash object's state with the provided bytes-like object. -[clinic start generated code]*/ - -static PyObject * -_blake2_blake2b_update(BLAKE2bObject *self, PyObject *data) -/*[clinic end generated code: output=010dfcbe22654359 input=ffc4aa6a6a225d31]*/ -{ - Py_buffer buf; - - GET_BUFFER_VIEW_OR_ERROUT(data, &buf); - -#ifdef WITH_THREAD - if (self->lock == NULL && buf.len >= HASHLIB_GIL_MINSIZE) - self->lock = PyThread_allocate_lock(); - - if (self->lock != NULL) { - Py_BEGIN_ALLOW_THREADS - PyThread_acquire_lock(self->lock, 1); - blake2b_update(&self->state, buf.buf, buf.len); - PyThread_release_lock(self->lock); - Py_END_ALLOW_THREADS - } else { - blake2b_update(&self->state, buf.buf, buf.len); - } -#else - blake2b_update(&self->state, buf.buf, buf.len); -#endif /* !WITH_THREAD */ - PyBuffer_Release(&buf); - - Py_INCREF(Py_None); - return Py_None; -} - -/*[clinic input] -_blake2.blake2b.digest - -Return the digest value as a bytes object. -[clinic start generated code]*/ - -static PyObject * -_blake2_blake2b_digest_impl(BLAKE2bObject *self) -/*[clinic end generated code: output=a5864660f4bfc61a input=7d21659e9c5fff02]*/ -{ - uint8_t digest[BLAKE2B_OUTBYTES]; - blake2b_state state_cpy; - - ENTER_HASHLIB(self); - state_cpy = self->state; - blake2b_final(&state_cpy, digest, self->param.digest_length); - LEAVE_HASHLIB(self); - return PyBytes_FromStringAndSize((const char *)digest, - self->param.digest_length); -} - -/*[clinic input] -_blake2.blake2b.hexdigest - -Return the digest value as a string of hexadecimal digits. -[clinic start generated code]*/ - -static PyObject * -_blake2_blake2b_hexdigest_impl(BLAKE2bObject *self) -/*[clinic end generated code: output=b5598a87d8794a60 input=76930f6946351f56]*/ -{ - uint8_t digest[BLAKE2B_OUTBYTES]; - blake2b_state state_cpy; - - ENTER_HASHLIB(self); - state_cpy = self->state; - blake2b_final(&state_cpy, digest, self->param.digest_length); - LEAVE_HASHLIB(self); - return _Py_strhex((const char *)digest, self->param.digest_length); -} - - -static PyMethodDef py_blake2b_methods[] = { - _BLAKE2_BLAKE2B_COPY_METHODDEF - _BLAKE2_BLAKE2B_DIGEST_METHODDEF - _BLAKE2_BLAKE2B_HEXDIGEST_METHODDEF - _BLAKE2_BLAKE2B_UPDATE_METHODDEF - {NULL, NULL} -}; - - - -static PyObject * -py_blake2b_get_name(BLAKE2bObject *self, void *closure) -{ - return PyUnicode_FromString("blake2b"); -} - - - -static PyObject * -py_blake2b_get_block_size(BLAKE2bObject *self, void *closure) -{ - return PyLong_FromLong(BLAKE2B_BLOCKBYTES); -} - - - -static PyObject * -py_blake2b_get_digest_size(BLAKE2bObject *self, void *closure) -{ - return PyLong_FromLong(self->param.digest_length); -} - - -static PyGetSetDef py_blake2b_getsetters[] = { - {"name", (getter)py_blake2b_get_name, - NULL, NULL, NULL}, - {"block_size", (getter)py_blake2b_get_block_size, - NULL, NULL, NULL}, - {"digest_size", (getter)py_blake2b_get_digest_size, - NULL, NULL, NULL}, - {NULL} -}; - - -static void -py_blake2b_dealloc(PyObject *self) -{ - BLAKE2bObject *obj = (BLAKE2bObject *)self; - - /* Try not to leave state in memory. */ - secure_zero_memory(&obj->param, sizeof(obj->param)); - secure_zero_memory(&obj->state, sizeof(obj->state)); -#ifdef WITH_THREAD - if (obj->lock) { - PyThread_free_lock(obj->lock); - obj->lock = NULL; - } -#endif - PyObject_Del(self); -} - - -PyTypeObject PyBlake2_BLAKE2bType = { - PyVarObject_HEAD_INIT(NULL, 0) - "_blake2.blake2b", /* tp_name */ - sizeof(BLAKE2bObject), /* tp_basicsize */ - 0, /* tp_itemsize */ - py_blake2b_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - py_blake2b_new__doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - py_blake2b_methods, /* tp_methods */ - 0, /* tp_members */ - py_blake2b_getsetters, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - py_blake2b_new, /* tp_new */ -}; diff --git a/third_party/python/Modules/_blake2/blake2module.c b/third_party/python/Modules/_blake2/blake2module.c deleted file mode 100644 index 7d473239a..000000000 --- a/third_party/python/Modules/_blake2/blake2module.c +++ /dev/null @@ -1,106 +0,0 @@ -/* clang-format off */ -/* - * Written in 2013 by Dmitry Chestnykh - * Modified for CPython by Christian Heimes - * - * To the extent possible under law, the author have dedicated all - * copyright and related and neighboring rights to this software to - * the public domain worldwide. This software is distributed without - * any warranty. http://creativecommons.org/publicdomain/zero/1.0/ - */ - -#include "third_party/python/Include/Python.h" - -#include "third_party/python/Modules/_blake2/impl/blake2.h" - -extern PyTypeObject PyBlake2_BLAKE2bType; -extern PyTypeObject PyBlake2_BLAKE2sType; - - -PyDoc_STRVAR(blake2mod__doc__, -"_blake2b provides BLAKE2b for hashlib\n" -); - - -static struct PyMethodDef blake2mod_functions[] = { - {NULL, NULL} -}; - -static struct PyModuleDef blake2_module = { - PyModuleDef_HEAD_INIT, - "_blake2", - blake2mod__doc__, - -1, - blake2mod_functions, - NULL, - NULL, - NULL, - NULL -}; - -#define ADD_INT(d, name, value) do { \ - PyObject *x = PyLong_FromLong(value); \ - if (!x) { \ - Py_DECREF(m); \ - return NULL; \ - } \ - if (PyDict_SetItemString(d, name, x) < 0) { \ - Py_DECREF(m); \ - return NULL; \ - } \ - Py_DECREF(x); \ -} while(0) - - -PyMODINIT_FUNC -PyInit__blake2(void) -{ - PyObject *m; - PyObject *d; - - m = PyModule_Create(&blake2_module); - if (m == NULL) - return NULL; - - /* BLAKE2b */ - Py_TYPE(&PyBlake2_BLAKE2bType) = &PyType_Type; - if (PyType_Ready(&PyBlake2_BLAKE2bType) < 0) { - return NULL; - } - - Py_INCREF(&PyBlake2_BLAKE2bType); - PyModule_AddObject(m, "blake2b", (PyObject *)&PyBlake2_BLAKE2bType); - - d = PyBlake2_BLAKE2bType.tp_dict; - ADD_INT(d, "SALT_SIZE", BLAKE2B_SALTBYTES); - ADD_INT(d, "PERSON_SIZE", BLAKE2B_PERSONALBYTES); - ADD_INT(d, "MAX_KEY_SIZE", BLAKE2B_KEYBYTES); - ADD_INT(d, "MAX_DIGEST_SIZE", BLAKE2B_OUTBYTES); - - PyModule_AddIntConstant(m, "BLAKE2B_SALT_SIZE", BLAKE2B_SALTBYTES); - PyModule_AddIntConstant(m, "BLAKE2B_PERSON_SIZE", BLAKE2B_PERSONALBYTES); - PyModule_AddIntConstant(m, "BLAKE2B_MAX_KEY_SIZE", BLAKE2B_KEYBYTES); - PyModule_AddIntConstant(m, "BLAKE2B_MAX_DIGEST_SIZE", BLAKE2B_OUTBYTES); - - /* BLAKE2s */ - Py_TYPE(&PyBlake2_BLAKE2sType) = &PyType_Type; - if (PyType_Ready(&PyBlake2_BLAKE2sType) < 0) { - return NULL; - } - - Py_INCREF(&PyBlake2_BLAKE2sType); - PyModule_AddObject(m, "blake2s", (PyObject *)&PyBlake2_BLAKE2sType); - - d = PyBlake2_BLAKE2sType.tp_dict; - ADD_INT(d, "SALT_SIZE", BLAKE2S_SALTBYTES); - ADD_INT(d, "PERSON_SIZE", BLAKE2S_PERSONALBYTES); - ADD_INT(d, "MAX_KEY_SIZE", BLAKE2S_KEYBYTES); - ADD_INT(d, "MAX_DIGEST_SIZE", BLAKE2S_OUTBYTES); - - PyModule_AddIntConstant(m, "BLAKE2S_SALT_SIZE", BLAKE2S_SALTBYTES); - PyModule_AddIntConstant(m, "BLAKE2S_PERSON_SIZE", BLAKE2S_PERSONALBYTES); - PyModule_AddIntConstant(m, "BLAKE2S_MAX_KEY_SIZE", BLAKE2S_KEYBYTES); - PyModule_AddIntConstant(m, "BLAKE2S_MAX_DIGEST_SIZE", BLAKE2S_OUTBYTES); - - return m; -} diff --git a/third_party/python/Modules/_blake2/blake2ns.h b/third_party/python/Modules/_blake2/blake2ns.h deleted file mode 100644 index ad7683377..000000000 --- a/third_party/python/Modules/_blake2/blake2ns.h +++ /dev/null @@ -1,33 +0,0 @@ -/* clang-format off */ -/* Prefix all public blake2 symbols with PyBlake2_ - */ - -#ifndef Py_BLAKE2_NS -#define Py_BLAKE2_NS - -#define blake2b PyBlake2_blake2b -#define blake2b_compress PyBlake2_blake2b_compress -#define blake2b_final PyBlake2_blake2b_final -#define blake2b_init PyBlake2_blake2b_init -#define blake2b_init_key PyBlake2_blake2b_init_key -#define blake2b_init_param PyBlake2_blake2b_init_param -#define blake2b_update PyBlake2_blake2b_update -#define blake2bp PyBlake2_blake2bp -#define blake2bp_final PyBlake2_blake2bp_final -#define blake2bp_init PyBlake2_blake2bp_init -#define blake2bp_init_key PyBlake2_blake2bp_init_key -#define blake2bp_update PyBlake2_blake2bp_update -#define blake2s PyBlake2_blake2s -#define blake2s_compress PyBlake2_blake2s_compress -#define blake2s_final PyBlake2_blake2s_final -#define blake2s_init PyBlake2_blake2s_init -#define blake2s_init_key PyBlake2_blake2s_init_key -#define blake2s_init_param PyBlake2_blake2s_init_param -#define blake2s_update PyBlake2_blake2s_update -#define blake2sp PyBlake2_blake2sp -#define blake2sp_final PyBlake2_blake2sp_final -#define blake2sp_init PyBlake2_blake2sp_init -#define blake2sp_init_key PyBlake2_blake2sp_init_key -#define blake2sp_update PyBlake2_blake2sp_update - -#endif /* Py_BLAKE2_NS */ diff --git a/third_party/python/Modules/_blake2/blake2s_impl.c b/third_party/python/Modules/_blake2/blake2s_impl.c deleted file mode 100644 index 6d5f0b3a7..000000000 --- a/third_party/python/Modules/_blake2/blake2s_impl.c +++ /dev/null @@ -1,464 +0,0 @@ -/* clang-format off */ -/* - * Written in 2013 by Dmitry Chestnykh - * Modified for CPython by Christian Heimes - * - * To the extent possible under law, the author have dedicated all - * copyright and related and neighboring rights to this software to - * the public domain worldwide. This software is distributed without - * any warranty. http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* WARNING: autogenerated file! - * - * The blake2s_impl.c is autogenerated from blake2s_impl.c. - */ - -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/pystrhex.h" -#ifdef WITH_THREAD -#include "third_party/python/Include/pythread.h" -#endif - -#include "third_party/python/Modules/hashlib.h" -#include "third_party/python/Modules/_blake2/blake2ns.h" - -#define HAVE_BLAKE2S 1 -#define BLAKE2_LOCAL_INLINE(type) Py_LOCAL_INLINE(type) - -#include "third_party/python/Modules/_blake2/impl/blake2.h" -#include "third_party/python/Modules/_blake2/impl/blake2-impl.h" /* for secure_zero_memory() and store48() */ - -#ifdef BLAKE2_USE_SSE -#include "third_party/python/Modules/_blake2/impl/blake2s.c" -#else -#include "third_party/python/Modules/_blake2/impl/blake2s-ref.c" -#endif - - -extern PyTypeObject PyBlake2_BLAKE2sType; - -typedef struct { - PyObject_HEAD - blake2s_param param; - blake2s_state state; -#ifdef WITH_THREAD - PyThread_type_lock lock; -#endif -} BLAKE2sObject; - -#include "third_party/python/Modules/_blake2/clinic/blake2s_impl.c.h" - -/*[clinic input] -module _blake2 -class _blake2.blake2s "BLAKE2sObject *" "&PyBlake2_BLAKE2sType" -[clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=4b79d7ffe07286ce]*/ - - -static BLAKE2sObject * -new_BLAKE2sObject(PyTypeObject *type) -{ - BLAKE2sObject *self; - self = (BLAKE2sObject *)type->tp_alloc(type, 0); -#ifdef WITH_THREAD - if (self != NULL) { - self->lock = NULL; - } -#endif - return self; -} - -/*[clinic input] -@classmethod -_blake2.blake2s.__new__ as py_blake2s_new - data: object(c_default="NULL") = b'' - / - * - digest_size: int(c_default="BLAKE2S_OUTBYTES") = _blake2.blake2s.MAX_DIGEST_SIZE - key: Py_buffer(c_default="NULL", py_default="b''") = None - salt: Py_buffer(c_default="NULL", py_default="b''") = None - person: Py_buffer(c_default="NULL", py_default="b''") = None - fanout: int = 1 - depth: int = 1 - leaf_size as leaf_size_obj: object(c_default="NULL") = 0 - node_offset as node_offset_obj: object(c_default="NULL") = 0 - node_depth: int = 0 - inner_size: int = 0 - last_node: bool = False - -Return a new BLAKE2s hash object. -[clinic start generated code]*/ - -static PyObject * -py_blake2s_new_impl(PyTypeObject *type, PyObject *data, int digest_size, - Py_buffer *key, Py_buffer *salt, Py_buffer *person, - int fanout, int depth, PyObject *leaf_size_obj, - PyObject *node_offset_obj, int node_depth, - int inner_size, int last_node) -/*[clinic end generated code: output=fe060b258a8cbfc6 input=3abfaabe7f5f62cc]*/ -{ - BLAKE2sObject *self = NULL; - Py_buffer buf; - - unsigned long leaf_size = 0; - unsigned long long node_offset = 0; - - self = new_BLAKE2sObject(type); - if (self == NULL) { - goto error; - } - - /* Zero parameter block. */ - memset(&self->param, 0, sizeof(self->param)); - - /* Set digest size. */ - if (digest_size <= 0 || digest_size > BLAKE2S_OUTBYTES) { - PyErr_Format(PyExc_ValueError, - "digest_size must be between 1 and %d bytes", - BLAKE2S_OUTBYTES); - goto error; - } - self->param.digest_length = digest_size; - - /* Set salt parameter. */ - if ((salt->obj != NULL) && salt->len) { - if (salt->len > BLAKE2S_SALTBYTES) { - PyErr_Format(PyExc_ValueError, - "maximum salt length is %d bytes", - BLAKE2S_SALTBYTES); - goto error; - } - memcpy(self->param.salt, salt->buf, salt->len); - } - - /* Set personalization parameter. */ - if ((person->obj != NULL) && person->len) { - if (person->len > BLAKE2S_PERSONALBYTES) { - PyErr_Format(PyExc_ValueError, - "maximum person length is %d bytes", - BLAKE2S_PERSONALBYTES); - goto error; - } - memcpy(self->param.personal, person->buf, person->len); - } - - /* Set tree parameters. */ - if (fanout < 0 || fanout > 255) { - PyErr_SetString(PyExc_ValueError, - "fanout must be between 0 and 255"); - goto error; - } - self->param.fanout = (uint8_t)fanout; - - if (depth <= 0 || depth > 255) { - PyErr_SetString(PyExc_ValueError, - "depth must be between 1 and 255"); - goto error; - } - self->param.depth = (uint8_t)depth; - - if (leaf_size_obj != NULL) { - leaf_size = PyLong_AsUnsignedLong(leaf_size_obj); - if (leaf_size == (unsigned long) -1 && PyErr_Occurred()) { - goto error; - } - if (leaf_size > 0xFFFFFFFFU) { - PyErr_SetString(PyExc_OverflowError, "leaf_size is too large"); - goto error; - } - } - // NB: Simple assignment here would be incorrect on big endian platforms. - store32(&(self->param.leaf_length), leaf_size); - - if (node_offset_obj != NULL) { - node_offset = PyLong_AsUnsignedLongLong(node_offset_obj); - if (node_offset == (unsigned long long) -1 && PyErr_Occurred()) { - goto error; - } - } -#ifdef HAVE_BLAKE2S - if (node_offset > 0xFFFFFFFFFFFFULL) { - /* maximum 2**48 - 1 */ - PyErr_SetString(PyExc_OverflowError, "node_offset is too large"); - goto error; - } - store48(&(self->param.node_offset), node_offset); -#else - // NB: Simple assignment here would be incorrect on big endian platforms. - store64(&(self->param.node_offset), node_offset); -#endif - - if (node_depth < 0 || node_depth > 255) { - PyErr_SetString(PyExc_ValueError, - "node_depth must be between 0 and 255"); - goto error; - } - self->param.node_depth = node_depth; - - if (inner_size < 0 || inner_size > BLAKE2S_OUTBYTES) { - PyErr_Format(PyExc_ValueError, - "inner_size must be between 0 and is %d", - BLAKE2S_OUTBYTES); - goto error; - } - self->param.inner_length = inner_size; - - /* Set key length. */ - if ((key->obj != NULL) && key->len) { - if (key->len > BLAKE2S_KEYBYTES) { - PyErr_Format(PyExc_ValueError, - "maximum key length is %d bytes", - BLAKE2S_KEYBYTES); - goto error; - } - self->param.key_length = (uint8_t)key->len; - } - - /* Initialize hash state. */ - if (blake2s_init_param(&self->state, &self->param) < 0) { - PyErr_SetString(PyExc_RuntimeError, - "error initializing hash state"); - goto error; - } - - /* Set last node flag (must come after initialization). */ - self->state.last_node = last_node; - - /* Process key block if any. */ - if (self->param.key_length) { - uint8_t block[BLAKE2S_BLOCKBYTES]; - memset(block, 0, sizeof(block)); - memcpy(block, key->buf, key->len); - blake2s_update(&self->state, block, sizeof(block)); - secure_zero_memory(block, sizeof(block)); - } - - /* Process initial data if any. */ - if (data != NULL) { - GET_BUFFER_VIEW_OR_ERROR(data, &buf, goto error); - - if (buf.len >= HASHLIB_GIL_MINSIZE) { - Py_BEGIN_ALLOW_THREADS - blake2s_update(&self->state, buf.buf, buf.len); - Py_END_ALLOW_THREADS - } else { - blake2s_update(&self->state, buf.buf, buf.len); - } - PyBuffer_Release(&buf); - } - - return (PyObject *)self; - - error: - if (self != NULL) { - Py_DECREF(self); - } - return NULL; -} - -/*[clinic input] -_blake2.blake2s.copy - -Return a copy of the hash object. -[clinic start generated code]*/ - -static PyObject * -_blake2_blake2s_copy_impl(BLAKE2sObject *self) -/*[clinic end generated code: output=5b90131c4eae275e input=0b9d44942f0fe4b2]*/ -{ - BLAKE2sObject *cpy; - - if ((cpy = new_BLAKE2sObject(Py_TYPE(self))) == NULL) - return NULL; - - ENTER_HASHLIB(self); - cpy->param = self->param; - cpy->state = self->state; - LEAVE_HASHLIB(self); - return (PyObject *)cpy; -} - -/*[clinic input] -_blake2.blake2s.update - - data: object - / - -Update this hash object's state with the provided bytes-like object. -[clinic start generated code]*/ - -static PyObject * -_blake2_blake2s_update(BLAKE2sObject *self, PyObject *data) -/*[clinic end generated code: output=757dc087fec37815 input=97500db2f9de4aaa]*/ -{ - Py_buffer buf; - - GET_BUFFER_VIEW_OR_ERROUT(data, &buf); - -#ifdef WITH_THREAD - if (self->lock == NULL && buf.len >= HASHLIB_GIL_MINSIZE) - self->lock = PyThread_allocate_lock(); - - if (self->lock != NULL) { - Py_BEGIN_ALLOW_THREADS - PyThread_acquire_lock(self->lock, 1); - blake2s_update(&self->state, buf.buf, buf.len); - PyThread_release_lock(self->lock); - Py_END_ALLOW_THREADS - } else { - blake2s_update(&self->state, buf.buf, buf.len); - } -#else - blake2s_update(&self->state, buf.buf, buf.len); -#endif /* !WITH_THREAD */ - PyBuffer_Release(&buf); - - Py_INCREF(Py_None); - return Py_None; -} - -/*[clinic input] -_blake2.blake2s.digest - -Return the digest value as a bytes object. -[clinic start generated code]*/ - -static PyObject * -_blake2_blake2s_digest_impl(BLAKE2sObject *self) -/*[clinic end generated code: output=40c566ca4bc6bc51 input=f41e0b8d6d937454]*/ -{ - uint8_t digest[BLAKE2S_OUTBYTES]; - blake2s_state state_cpy; - - ENTER_HASHLIB(self); - state_cpy = self->state; - blake2s_final(&state_cpy, digest, self->param.digest_length); - LEAVE_HASHLIB(self); - return PyBytes_FromStringAndSize((const char *)digest, - self->param.digest_length); -} - -/*[clinic input] -_blake2.blake2s.hexdigest - -Return the digest value as a string of hexadecimal digits. -[clinic start generated code]*/ - -static PyObject * -_blake2_blake2s_hexdigest_impl(BLAKE2sObject *self) -/*[clinic end generated code: output=15153eb5e59c52eb input=c77a1321567e8952]*/ -{ - uint8_t digest[BLAKE2S_OUTBYTES]; - blake2s_state state_cpy; - - ENTER_HASHLIB(self); - state_cpy = self->state; - blake2s_final(&state_cpy, digest, self->param.digest_length); - LEAVE_HASHLIB(self); - return _Py_strhex((const char *)digest, self->param.digest_length); -} - - -static PyMethodDef py_blake2s_methods[] = { - _BLAKE2_BLAKE2S_COPY_METHODDEF - _BLAKE2_BLAKE2S_DIGEST_METHODDEF - _BLAKE2_BLAKE2S_HEXDIGEST_METHODDEF - _BLAKE2_BLAKE2S_UPDATE_METHODDEF - {NULL, NULL} -}; - - - -static PyObject * -py_blake2s_get_name(BLAKE2sObject *self, void *closure) -{ - return PyUnicode_FromString("blake2s"); -} - - - -static PyObject * -py_blake2s_get_block_size(BLAKE2sObject *self, void *closure) -{ - return PyLong_FromLong(BLAKE2S_BLOCKBYTES); -} - - - -static PyObject * -py_blake2s_get_digest_size(BLAKE2sObject *self, void *closure) -{ - return PyLong_FromLong(self->param.digest_length); -} - - -static PyGetSetDef py_blake2s_getsetters[] = { - {"name", (getter)py_blake2s_get_name, - NULL, NULL, NULL}, - {"block_size", (getter)py_blake2s_get_block_size, - NULL, NULL, NULL}, - {"digest_size", (getter)py_blake2s_get_digest_size, - NULL, NULL, NULL}, - {NULL} -}; - - -static void -py_blake2s_dealloc(PyObject *self) -{ - BLAKE2sObject *obj = (BLAKE2sObject *)self; - - /* Try not to leave state in memory. */ - secure_zero_memory(&obj->param, sizeof(obj->param)); - secure_zero_memory(&obj->state, sizeof(obj->state)); -#ifdef WITH_THREAD - if (obj->lock) { - PyThread_free_lock(obj->lock); - obj->lock = NULL; - } -#endif - PyObject_Del(self); -} - - -PyTypeObject PyBlake2_BLAKE2sType = { - PyVarObject_HEAD_INIT(NULL, 0) - "_blake2.blake2s", /* tp_name */ - sizeof(BLAKE2sObject), /* tp_basicsize */ - 0, /* tp_itemsize */ - py_blake2s_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - py_blake2s_new__doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - py_blake2s_methods, /* tp_methods */ - 0, /* tp_members */ - py_blake2s_getsetters, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - py_blake2s_new, /* tp_new */ -}; diff --git a/third_party/python/Modules/_blake2/clinic/blake2b_impl.c.h b/third_party/python/Modules/_blake2/clinic/blake2b_impl.c.h deleted file mode 100644 index 9b2965eb6..000000000 --- a/third_party/python/Modules/_blake2/clinic/blake2b_impl.c.h +++ /dev/null @@ -1,124 +0,0 @@ -/*[clinic input] -preserve -[clinic start generated code]*/ - -PyDoc_STRVAR(py_blake2b_new__doc__, -"blake2b(data=b\'\', /, *, digest_size=_blake2.blake2b.MAX_DIGEST_SIZE,\n" -" key=b\'\', salt=b\'\', person=b\'\', fanout=1, depth=1, leaf_size=0,\n" -" node_offset=0, node_depth=0, inner_size=0, last_node=False)\n" -"--\n" -"\n" -"Return a new BLAKE2b hash object."); - -static PyObject * -py_blake2b_new_impl(PyTypeObject *type, PyObject *data, int digest_size, - Py_buffer *key, Py_buffer *salt, Py_buffer *person, - int fanout, int depth, PyObject *leaf_size_obj, - PyObject *node_offset_obj, int node_depth, - int inner_size, int last_node); - -static PyObject * -py_blake2b_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static const char * const _keywords[] = {"", "digest_size", "key", "salt", "person", "fanout", "depth", "leaf_size", "node_offset", "node_depth", "inner_size", "last_node", NULL}; - static _PyArg_Parser _parser = {"|O$iy*y*y*iiOOiip:blake2b", _keywords, 0}; - PyObject *data = NULL; - int digest_size = BLAKE2B_OUTBYTES; - Py_buffer key = {NULL, NULL}; - Py_buffer salt = {NULL, NULL}; - Py_buffer person = {NULL, NULL}; - int fanout = 1; - int depth = 1; - PyObject *leaf_size_obj = NULL; - PyObject *node_offset_obj = NULL; - int node_depth = 0; - int inner_size = 0; - int last_node = 0; - - if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser, - &data, &digest_size, &key, &salt, &person, &fanout, &depth, &leaf_size_obj, &node_offset_obj, &node_depth, &inner_size, &last_node)) { - goto exit; - } - return_value = py_blake2b_new_impl(type, data, digest_size, &key, &salt, &person, fanout, depth, leaf_size_obj, node_offset_obj, node_depth, inner_size, last_node); - -exit: - /* Cleanup for key */ - if (key.obj) { - PyBuffer_Release(&key); - } - /* Cleanup for salt */ - if (salt.obj) { - PyBuffer_Release(&salt); - } - /* Cleanup for person */ - if (person.obj) { - PyBuffer_Release(&person); - } - - return return_value; -} - -PyDoc_STRVAR(_blake2_blake2b_copy__doc__, -"copy($self, /)\n" -"--\n" -"\n" -"Return a copy of the hash object."); - -#define _BLAKE2_BLAKE2B_COPY_METHODDEF \ - {"copy", (PyCFunction)_blake2_blake2b_copy, METH_NOARGS, _blake2_blake2b_copy__doc__}, - -static PyObject * -_blake2_blake2b_copy_impl(BLAKE2bObject *self); - -static PyObject * -_blake2_blake2b_copy(BLAKE2bObject *self, PyObject *Py_UNUSED(ignored)) -{ - return _blake2_blake2b_copy_impl(self); -} - -PyDoc_STRVAR(_blake2_blake2b_update__doc__, -"update($self, data, /)\n" -"--\n" -"\n" -"Update this hash object\'s state with the provided bytes-like object."); - -#define _BLAKE2_BLAKE2B_UPDATE_METHODDEF \ - {"update", (PyCFunction)_blake2_blake2b_update, METH_O, _blake2_blake2b_update__doc__}, - -PyDoc_STRVAR(_blake2_blake2b_digest__doc__, -"digest($self, /)\n" -"--\n" -"\n" -"Return the digest value as a bytes object."); - -#define _BLAKE2_BLAKE2B_DIGEST_METHODDEF \ - {"digest", (PyCFunction)_blake2_blake2b_digest, METH_NOARGS, _blake2_blake2b_digest__doc__}, - -static PyObject * -_blake2_blake2b_digest_impl(BLAKE2bObject *self); - -static PyObject * -_blake2_blake2b_digest(BLAKE2bObject *self, PyObject *Py_UNUSED(ignored)) -{ - return _blake2_blake2b_digest_impl(self); -} - -PyDoc_STRVAR(_blake2_blake2b_hexdigest__doc__, -"hexdigest($self, /)\n" -"--\n" -"\n" -"Return the digest value as a string of hexadecimal digits."); - -#define _BLAKE2_BLAKE2B_HEXDIGEST_METHODDEF \ - {"hexdigest", (PyCFunction)_blake2_blake2b_hexdigest, METH_NOARGS, _blake2_blake2b_hexdigest__doc__}, - -static PyObject * -_blake2_blake2b_hexdigest_impl(BLAKE2bObject *self); - -static PyObject * -_blake2_blake2b_hexdigest(BLAKE2bObject *self, PyObject *Py_UNUSED(ignored)) -{ - return _blake2_blake2b_hexdigest_impl(self); -} -/*[clinic end generated code: output=0eb559f418fc0a21 input=a9049054013a1b77]*/ diff --git a/third_party/python/Modules/_blake2/clinic/blake2s_impl.c.h b/third_party/python/Modules/_blake2/clinic/blake2s_impl.c.h deleted file mode 100644 index 42b87b709..000000000 --- a/third_party/python/Modules/_blake2/clinic/blake2s_impl.c.h +++ /dev/null @@ -1,124 +0,0 @@ -/*[clinic input] -preserve -[clinic start generated code]*/ - -PyDoc_STRVAR(py_blake2s_new__doc__, -"blake2s(data=b\'\', /, *, digest_size=_blake2.blake2s.MAX_DIGEST_SIZE,\n" -" key=b\'\', salt=b\'\', person=b\'\', fanout=1, depth=1, leaf_size=0,\n" -" node_offset=0, node_depth=0, inner_size=0, last_node=False)\n" -"--\n" -"\n" -"Return a new BLAKE2s hash object."); - -static PyObject * -py_blake2s_new_impl(PyTypeObject *type, PyObject *data, int digest_size, - Py_buffer *key, Py_buffer *salt, Py_buffer *person, - int fanout, int depth, PyObject *leaf_size_obj, - PyObject *node_offset_obj, int node_depth, - int inner_size, int last_node); - -static PyObject * -py_blake2s_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static const char * const _keywords[] = {"", "digest_size", "key", "salt", "person", "fanout", "depth", "leaf_size", "node_offset", "node_depth", "inner_size", "last_node", NULL}; - static _PyArg_Parser _parser = {"|O$iy*y*y*iiOOiip:blake2s", _keywords, 0}; - PyObject *data = NULL; - int digest_size = BLAKE2S_OUTBYTES; - Py_buffer key = {NULL, NULL}; - Py_buffer salt = {NULL, NULL}; - Py_buffer person = {NULL, NULL}; - int fanout = 1; - int depth = 1; - PyObject *leaf_size_obj = NULL; - PyObject *node_offset_obj = NULL; - int node_depth = 0; - int inner_size = 0; - int last_node = 0; - - if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser, - &data, &digest_size, &key, &salt, &person, &fanout, &depth, &leaf_size_obj, &node_offset_obj, &node_depth, &inner_size, &last_node)) { - goto exit; - } - return_value = py_blake2s_new_impl(type, data, digest_size, &key, &salt, &person, fanout, depth, leaf_size_obj, node_offset_obj, node_depth, inner_size, last_node); - -exit: - /* Cleanup for key */ - if (key.obj) { - PyBuffer_Release(&key); - } - /* Cleanup for salt */ - if (salt.obj) { - PyBuffer_Release(&salt); - } - /* Cleanup for person */ - if (person.obj) { - PyBuffer_Release(&person); - } - - return return_value; -} - -PyDoc_STRVAR(_blake2_blake2s_copy__doc__, -"copy($self, /)\n" -"--\n" -"\n" -"Return a copy of the hash object."); - -#define _BLAKE2_BLAKE2S_COPY_METHODDEF \ - {"copy", (PyCFunction)_blake2_blake2s_copy, METH_NOARGS, _blake2_blake2s_copy__doc__}, - -static PyObject * -_blake2_blake2s_copy_impl(BLAKE2sObject *self); - -static PyObject * -_blake2_blake2s_copy(BLAKE2sObject *self, PyObject *Py_UNUSED(ignored)) -{ - return _blake2_blake2s_copy_impl(self); -} - -PyDoc_STRVAR(_blake2_blake2s_update__doc__, -"update($self, data, /)\n" -"--\n" -"\n" -"Update this hash object\'s state with the provided bytes-like object."); - -#define _BLAKE2_BLAKE2S_UPDATE_METHODDEF \ - {"update", (PyCFunction)_blake2_blake2s_update, METH_O, _blake2_blake2s_update__doc__}, - -PyDoc_STRVAR(_blake2_blake2s_digest__doc__, -"digest($self, /)\n" -"--\n" -"\n" -"Return the digest value as a bytes object."); - -#define _BLAKE2_BLAKE2S_DIGEST_METHODDEF \ - {"digest", (PyCFunction)_blake2_blake2s_digest, METH_NOARGS, _blake2_blake2s_digest__doc__}, - -static PyObject * -_blake2_blake2s_digest_impl(BLAKE2sObject *self); - -static PyObject * -_blake2_blake2s_digest(BLAKE2sObject *self, PyObject *Py_UNUSED(ignored)) -{ - return _blake2_blake2s_digest_impl(self); -} - -PyDoc_STRVAR(_blake2_blake2s_hexdigest__doc__, -"hexdigest($self, /)\n" -"--\n" -"\n" -"Return the digest value as a string of hexadecimal digits."); - -#define _BLAKE2_BLAKE2S_HEXDIGEST_METHODDEF \ - {"hexdigest", (PyCFunction)_blake2_blake2s_hexdigest, METH_NOARGS, _blake2_blake2s_hexdigest__doc__}, - -static PyObject * -_blake2_blake2s_hexdigest_impl(BLAKE2sObject *self); - -static PyObject * -_blake2_blake2s_hexdigest(BLAKE2sObject *self, PyObject *Py_UNUSED(ignored)) -{ - return _blake2_blake2s_hexdigest_impl(self); -} -/*[clinic end generated code: output=13d4b08ea9ee2d62 input=a9049054013a1b77]*/ diff --git a/third_party/python/Modules/_blake2/impl/blake2-config.h b/third_party/python/Modules/_blake2/impl/blake2-config.h deleted file mode 100644 index aea1f4d63..000000000 --- a/third_party/python/Modules/_blake2/impl/blake2-config.h +++ /dev/null @@ -1,75 +0,0 @@ -/* clang-format off */ -/* - BLAKE2 reference source code package - optimized C implementations - - Copyright 2012, Samuel Neves . You may use this under the - terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at - your option. The terms of these licenses can be found at: - - - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 - - OpenSSL license : https://www.openssl.org/source/license.html - - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 - - More information about the BLAKE2 hash function can be found at - https://blake2.net. -*/ -#pragma once -#ifndef __BLAKE2_CONFIG_H__ -#define __BLAKE2_CONFIG_H__ - -/* These don't work everywhere */ -#if defined(__SSE2__) || defined(__x86_64__) || defined(__amd64__) -#define HAVE_SSE2 -#endif - -#if defined(__SSSE3__) -#define HAVE_SSSE3 -#endif - -#if defined(__SSE4_1__) -#define HAVE_SSE41 -#endif - -#if defined(__AVX__) -#define HAVE_AVX -#endif - -#if defined(__XOP__) -#define HAVE_XOP -#endif - - -#ifdef HAVE_AVX2 -#ifndef HAVE_AVX -#define HAVE_AVX -#endif -#endif - -#ifdef HAVE_XOP -#ifndef HAVE_AVX -#define HAVE_AVX -#endif -#endif - -#ifdef HAVE_AVX -#ifndef HAVE_SSE41 -#define HAVE_SSE41 -#endif -#endif - -#ifdef HAVE_SSE41 -#ifndef HAVE_SSSE3 -#define HAVE_SSSE3 -#endif -#endif - -#ifdef HAVE_SSSE3 -#define HAVE_SSE2 -#endif - -#if !defined(HAVE_SSE2) -#error "This code requires at least SSE2." -#endif - -#endif - diff --git a/third_party/python/Modules/_blake2/impl/blake2-impl.h b/third_party/python/Modules/_blake2/impl/blake2-impl.h deleted file mode 100644 index 4367fd695..000000000 --- a/third_party/python/Modules/_blake2/impl/blake2-impl.h +++ /dev/null @@ -1,137 +0,0 @@ -/* clang-format off */ -/* - BLAKE2 reference source code package - optimized C implementations - - Copyright 2012, Samuel Neves . You may use this under the - terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at - your option. The terms of these licenses can be found at: - - - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 - - OpenSSL license : https://www.openssl.org/source/license.html - - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 - - More information about the BLAKE2 hash function can be found at - https://blake2.net. -*/ -#pragma once -#ifndef __BLAKE2_IMPL_H__ -#define __BLAKE2_IMPL_H__ - -BLAKE2_LOCAL_INLINE(uint32_t) load32( const void *src ) -{ -#if defined(NATIVE_LITTLE_ENDIAN) - uint32_t w; - memcpy(&w, src, sizeof w); - return w; -#else - const uint8_t *p = ( const uint8_t * )src; - uint32_t w = *p++; - w |= ( uint32_t )( *p++ ) << 8; - w |= ( uint32_t )( *p++ ) << 16; - w |= ( uint32_t )( *p++ ) << 24; - return w; -#endif -} - -BLAKE2_LOCAL_INLINE(uint64_t) load64( const void *src ) -{ -#if defined(NATIVE_LITTLE_ENDIAN) - uint64_t w; - memcpy(&w, src, sizeof w); - return w; -#else - const uint8_t *p = ( const uint8_t * )src; - uint64_t w = *p++; - w |= ( uint64_t )( *p++ ) << 8; - w |= ( uint64_t )( *p++ ) << 16; - w |= ( uint64_t )( *p++ ) << 24; - w |= ( uint64_t )( *p++ ) << 32; - w |= ( uint64_t )( *p++ ) << 40; - w |= ( uint64_t )( *p++ ) << 48; - w |= ( uint64_t )( *p++ ) << 56; - return w; -#endif -} - -BLAKE2_LOCAL_INLINE(void) store32( void *dst, uint32_t w ) -{ -#if defined(NATIVE_LITTLE_ENDIAN) - memcpy(dst, &w, sizeof w); -#else - uint8_t *p = ( uint8_t * )dst; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; -#endif -} - -BLAKE2_LOCAL_INLINE(void) store64( void *dst, uint64_t w ) -{ -#if defined(NATIVE_LITTLE_ENDIAN) - memcpy(dst, &w, sizeof w); -#else - uint8_t *p = ( uint8_t * )dst; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; -#endif -} - -BLAKE2_LOCAL_INLINE(uint64_t) load48( const void *src ) -{ - const uint8_t *p = ( const uint8_t * )src; - uint64_t w = *p++; - w |= ( uint64_t )( *p++ ) << 8; - w |= ( uint64_t )( *p++ ) << 16; - w |= ( uint64_t )( *p++ ) << 24; - w |= ( uint64_t )( *p++ ) << 32; - w |= ( uint64_t )( *p++ ) << 40; - return w; -} - -BLAKE2_LOCAL_INLINE(void) store48( void *dst, uint64_t w ) -{ - uint8_t *p = ( uint8_t * )dst; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; -} - -BLAKE2_LOCAL_INLINE(uint32_t) rotl32( const uint32_t w, const unsigned c ) -{ - return ( w << c ) | ( w >> ( 32 - c ) ); -} - -BLAKE2_LOCAL_INLINE(uint64_t) rotl64( const uint64_t w, const unsigned c ) -{ - return ( w << c ) | ( w >> ( 64 - c ) ); -} - -BLAKE2_LOCAL_INLINE(uint32_t) rotr32( const uint32_t w, const unsigned c ) -{ - return ( w >> c ) | ( w << ( 32 - c ) ); -} - -BLAKE2_LOCAL_INLINE(uint64_t) rotr64( const uint64_t w, const unsigned c ) -{ - return ( w >> c ) | ( w << ( 64 - c ) ); -} - -/* prevents compiler optimizing out memset() */ -BLAKE2_LOCAL_INLINE(void) secure_zero_memory(void *v, size_t n) -{ - static void *(*const volatile memset_v)(void *, int, size_t) = &memset; - memset_v(v, 0, n); -} - -#endif - diff --git a/third_party/python/Modules/_blake2/impl/blake2.h b/third_party/python/Modules/_blake2/impl/blake2.h deleted file mode 100644 index 5a6215fae..000000000 --- a/third_party/python/Modules/_blake2/impl/blake2.h +++ /dev/null @@ -1,159 +0,0 @@ -/* clang-format off */ -/* - BLAKE2 reference source code package - reference C implementations - - Copyright 2012, Samuel Neves . You may use this under the - terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at - your option. The terms of these licenses can be found at: - - - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 - - OpenSSL license : https://www.openssl.org/source/license.html - - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 - - More information about the BLAKE2 hash function can be found at - https://blake2.net. -*/ -#pragma once -#ifndef __BLAKE2_H__ -#define __BLAKE2_H__ - -#ifdef BLAKE2_NO_INLINE -#define BLAKE2_LOCAL_INLINE(type) static type -#endif - -#ifndef BLAKE2_LOCAL_INLINE -#define BLAKE2_LOCAL_INLINE(type) static inline type -#endif - -#if defined(__cplusplus) -extern "C" { -#endif - - enum blake2s_constant - { - BLAKE2S_BLOCKBYTES = 64, - BLAKE2S_OUTBYTES = 32, - BLAKE2S_KEYBYTES = 32, - BLAKE2S_SALTBYTES = 8, - BLAKE2S_PERSONALBYTES = 8 - }; - - enum blake2b_constant - { - BLAKE2B_BLOCKBYTES = 128, - BLAKE2B_OUTBYTES = 64, - BLAKE2B_KEYBYTES = 64, - BLAKE2B_SALTBYTES = 16, - BLAKE2B_PERSONALBYTES = 16 - }; - - typedef struct __blake2s_state - { - uint32_t h[8]; - uint32_t t[2]; - uint32_t f[2]; - uint8_t buf[2 * BLAKE2S_BLOCKBYTES]; - size_t buflen; - uint8_t last_node; - } blake2s_state; - - typedef struct __blake2b_state - { - uint64_t h[8]; - uint64_t t[2]; - uint64_t f[2]; - uint8_t buf[2 * BLAKE2B_BLOCKBYTES]; - size_t buflen; - uint8_t last_node; - } blake2b_state; - - typedef struct __blake2sp_state - { - blake2s_state S[8][1]; - blake2s_state R[1]; - uint8_t buf[8 * BLAKE2S_BLOCKBYTES]; - size_t buflen; - } blake2sp_state; - - typedef struct __blake2bp_state - { - blake2b_state S[4][1]; - blake2b_state R[1]; - uint8_t buf[4 * BLAKE2B_BLOCKBYTES]; - size_t buflen; - } blake2bp_state; - - -#pragma pack(push, 1) - typedef struct __blake2s_param - { - uint8_t digest_length; /* 1 */ - uint8_t key_length; /* 2 */ - uint8_t fanout; /* 3 */ - uint8_t depth; /* 4 */ - uint32_t leaf_length; /* 8 */ - uint8_t node_offset[6];// 14 - uint8_t node_depth; /* 15 */ - uint8_t inner_length; /* 16 */ - /* uint8_t reserved[0]; */ - uint8_t salt[BLAKE2S_SALTBYTES]; /* 24 */ - uint8_t personal[BLAKE2S_PERSONALBYTES]; /* 32 */ - } blake2s_param; - - typedef struct __blake2b_param - { - uint8_t digest_length; /* 1 */ - uint8_t key_length; /* 2 */ - uint8_t fanout; /* 3 */ - uint8_t depth; /* 4 */ - uint32_t leaf_length; /* 8 */ - uint64_t node_offset; /* 16 */ - uint8_t node_depth; /* 17 */ - uint8_t inner_length; /* 18 */ - uint8_t reserved[14]; /* 32 */ - uint8_t salt[BLAKE2B_SALTBYTES]; /* 48 */ - uint8_t personal[BLAKE2B_PERSONALBYTES]; /* 64 */ - } blake2b_param; -#pragma pack(pop) - - /* Streaming API */ - int blake2s_init( blake2s_state *S, const uint8_t outlen ); - int blake2s_init_key( blake2s_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); - int blake2s_init_param( blake2s_state *S, const blake2s_param *P ); - int blake2s_update( blake2s_state *S, const uint8_t *in, uint64_t inlen ); - int blake2s_final( blake2s_state *S, uint8_t *out, uint8_t outlen ); - - int blake2b_init( blake2b_state *S, const uint8_t outlen ); - int blake2b_init_key( blake2b_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); - int blake2b_init_param( blake2b_state *S, const blake2b_param *P ); - int blake2b_update( blake2b_state *S, const uint8_t *in, uint64_t inlen ); - int blake2b_final( blake2b_state *S, uint8_t *out, uint8_t outlen ); - - int blake2sp_init( blake2sp_state *S, const uint8_t outlen ); - int blake2sp_init_key( blake2sp_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); - int blake2sp_update( blake2sp_state *S, const uint8_t *in, uint64_t inlen ); - int blake2sp_final( blake2sp_state *S, uint8_t *out, uint8_t outlen ); - - int blake2bp_init( blake2bp_state *S, const uint8_t outlen ); - int blake2bp_init_key( blake2bp_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); - int blake2bp_update( blake2bp_state *S, const uint8_t *in, uint64_t inlen ); - int blake2bp_final( blake2bp_state *S, uint8_t *out, uint8_t outlen ); - - /* Simple API */ - int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); - int blake2b( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); - - int blake2sp( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); - int blake2bp( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); - - static inline int blake2( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ) - { - return blake2b( out, in, key, outlen, inlen, keylen ); - } - -#if defined(__cplusplus) -} -#endif - -#endif - diff --git a/third_party/python/Modules/_blake2/impl/blake2b-load-sse2.h b/third_party/python/Modules/_blake2/impl/blake2b-load-sse2.h deleted file mode 100644 index 3564775bb..000000000 --- a/third_party/python/Modules/_blake2/impl/blake2b-load-sse2.h +++ /dev/null @@ -1,71 +0,0 @@ -/* clang-format off */ -/* - BLAKE2 reference source code package - optimized C implementations - - Copyright 2012, Samuel Neves . You may use this under the - terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at - your option. The terms of these licenses can be found at: - - - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 - - OpenSSL license : https://www.openssl.org/source/license.html - - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 - - More information about the BLAKE2 hash function can be found at - https://blake2.net. -*/ -#pragma once -#ifndef __BLAKE2B_LOAD_SSE2_H__ -#define __BLAKE2B_LOAD_SSE2_H__ - -#define LOAD_MSG_0_1(b0, b1) b0 = _mm_set_epi64x(m2, m0); b1 = _mm_set_epi64x(m6, m4) -#define LOAD_MSG_0_2(b0, b1) b0 = _mm_set_epi64x(m3, m1); b1 = _mm_set_epi64x(m7, m5) -#define LOAD_MSG_0_3(b0, b1) b0 = _mm_set_epi64x(m10, m8); b1 = _mm_set_epi64x(m14, m12) -#define LOAD_MSG_0_4(b0, b1) b0 = _mm_set_epi64x(m11, m9); b1 = _mm_set_epi64x(m15, m13) -#define LOAD_MSG_1_1(b0, b1) b0 = _mm_set_epi64x(m4, m14); b1 = _mm_set_epi64x(m13, m9) -#define LOAD_MSG_1_2(b0, b1) b0 = _mm_set_epi64x(m8, m10); b1 = _mm_set_epi64x(m6, m15) -#define LOAD_MSG_1_3(b0, b1) b0 = _mm_set_epi64x(m0, m1); b1 = _mm_set_epi64x(m5, m11) -#define LOAD_MSG_1_4(b0, b1) b0 = _mm_set_epi64x(m2, m12); b1 = _mm_set_epi64x(m3, m7) -#define LOAD_MSG_2_1(b0, b1) b0 = _mm_set_epi64x(m12, m11); b1 = _mm_set_epi64x(m15, m5) -#define LOAD_MSG_2_2(b0, b1) b0 = _mm_set_epi64x(m0, m8); b1 = _mm_set_epi64x(m13, m2) -#define LOAD_MSG_2_3(b0, b1) b0 = _mm_set_epi64x(m3, m10); b1 = _mm_set_epi64x(m9, m7) -#define LOAD_MSG_2_4(b0, b1) b0 = _mm_set_epi64x(m6, m14); b1 = _mm_set_epi64x(m4, m1) -#define LOAD_MSG_3_1(b0, b1) b0 = _mm_set_epi64x(m3, m7); b1 = _mm_set_epi64x(m11, m13) -#define LOAD_MSG_3_2(b0, b1) b0 = _mm_set_epi64x(m1, m9); b1 = _mm_set_epi64x(m14, m12) -#define LOAD_MSG_3_3(b0, b1) b0 = _mm_set_epi64x(m5, m2); b1 = _mm_set_epi64x(m15, m4) -#define LOAD_MSG_3_4(b0, b1) b0 = _mm_set_epi64x(m10, m6); b1 = _mm_set_epi64x(m8, m0) -#define LOAD_MSG_4_1(b0, b1) b0 = _mm_set_epi64x(m5, m9); b1 = _mm_set_epi64x(m10, m2) -#define LOAD_MSG_4_2(b0, b1) b0 = _mm_set_epi64x(m7, m0); b1 = _mm_set_epi64x(m15, m4) -#define LOAD_MSG_4_3(b0, b1) b0 = _mm_set_epi64x(m11, m14); b1 = _mm_set_epi64x(m3, m6) -#define LOAD_MSG_4_4(b0, b1) b0 = _mm_set_epi64x(m12, m1); b1 = _mm_set_epi64x(m13, m8) -#define LOAD_MSG_5_1(b0, b1) b0 = _mm_set_epi64x(m6, m2); b1 = _mm_set_epi64x(m8, m0) -#define LOAD_MSG_5_2(b0, b1) b0 = _mm_set_epi64x(m10, m12); b1 = _mm_set_epi64x(m3, m11) -#define LOAD_MSG_5_3(b0, b1) b0 = _mm_set_epi64x(m7, m4); b1 = _mm_set_epi64x(m1, m15) -#define LOAD_MSG_5_4(b0, b1) b0 = _mm_set_epi64x(m5, m13); b1 = _mm_set_epi64x(m9, m14) -#define LOAD_MSG_6_1(b0, b1) b0 = _mm_set_epi64x(m1, m12); b1 = _mm_set_epi64x(m4, m14) -#define LOAD_MSG_6_2(b0, b1) b0 = _mm_set_epi64x(m15, m5); b1 = _mm_set_epi64x(m10, m13) -#define LOAD_MSG_6_3(b0, b1) b0 = _mm_set_epi64x(m6, m0); b1 = _mm_set_epi64x(m8, m9) -#define LOAD_MSG_6_4(b0, b1) b0 = _mm_set_epi64x(m3, m7); b1 = _mm_set_epi64x(m11, m2) -#define LOAD_MSG_7_1(b0, b1) b0 = _mm_set_epi64x(m7, m13); b1 = _mm_set_epi64x(m3, m12) -#define LOAD_MSG_7_2(b0, b1) b0 = _mm_set_epi64x(m14, m11); b1 = _mm_set_epi64x(m9, m1) -#define LOAD_MSG_7_3(b0, b1) b0 = _mm_set_epi64x(m15, m5); b1 = _mm_set_epi64x(m2, m8) -#define LOAD_MSG_7_4(b0, b1) b0 = _mm_set_epi64x(m4, m0); b1 = _mm_set_epi64x(m10, m6) -#define LOAD_MSG_8_1(b0, b1) b0 = _mm_set_epi64x(m14, m6); b1 = _mm_set_epi64x(m0, m11) -#define LOAD_MSG_8_2(b0, b1) b0 = _mm_set_epi64x(m9, m15); b1 = _mm_set_epi64x(m8, m3) -#define LOAD_MSG_8_3(b0, b1) b0 = _mm_set_epi64x(m13, m12); b1 = _mm_set_epi64x(m10, m1) -#define LOAD_MSG_8_4(b0, b1) b0 = _mm_set_epi64x(m7, m2); b1 = _mm_set_epi64x(m5, m4) -#define LOAD_MSG_9_1(b0, b1) b0 = _mm_set_epi64x(m8, m10); b1 = _mm_set_epi64x(m1, m7) -#define LOAD_MSG_9_2(b0, b1) b0 = _mm_set_epi64x(m4, m2); b1 = _mm_set_epi64x(m5, m6) -#define LOAD_MSG_9_3(b0, b1) b0 = _mm_set_epi64x(m9, m15); b1 = _mm_set_epi64x(m13, m3) -#define LOAD_MSG_9_4(b0, b1) b0 = _mm_set_epi64x(m14, m11); b1 = _mm_set_epi64x(m0, m12) -#define LOAD_MSG_10_1(b0, b1) b0 = _mm_set_epi64x(m2, m0); b1 = _mm_set_epi64x(m6, m4) -#define LOAD_MSG_10_2(b0, b1) b0 = _mm_set_epi64x(m3, m1); b1 = _mm_set_epi64x(m7, m5) -#define LOAD_MSG_10_3(b0, b1) b0 = _mm_set_epi64x(m10, m8); b1 = _mm_set_epi64x(m14, m12) -#define LOAD_MSG_10_4(b0, b1) b0 = _mm_set_epi64x(m11, m9); b1 = _mm_set_epi64x(m15, m13) -#define LOAD_MSG_11_1(b0, b1) b0 = _mm_set_epi64x(m4, m14); b1 = _mm_set_epi64x(m13, m9) -#define LOAD_MSG_11_2(b0, b1) b0 = _mm_set_epi64x(m8, m10); b1 = _mm_set_epi64x(m6, m15) -#define LOAD_MSG_11_3(b0, b1) b0 = _mm_set_epi64x(m0, m1); b1 = _mm_set_epi64x(m5, m11) -#define LOAD_MSG_11_4(b0, b1) b0 = _mm_set_epi64x(m2, m12); b1 = _mm_set_epi64x(m3, m7) - - -#endif - diff --git a/third_party/python/Modules/_blake2/impl/blake2b-load-sse41.h b/third_party/python/Modules/_blake2/impl/blake2b-load-sse41.h deleted file mode 100644 index b605afff6..000000000 --- a/third_party/python/Modules/_blake2/impl/blake2b-load-sse41.h +++ /dev/null @@ -1,405 +0,0 @@ -/* clang-format off */ -/* - BLAKE2 reference source code package - optimized C implementations - - Copyright 2012, Samuel Neves . You may use this under the - terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at - your option. The terms of these licenses can be found at: - - - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 - - OpenSSL license : https://www.openssl.org/source/license.html - - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 - - More information about the BLAKE2 hash function can be found at - https://blake2.net. -*/ -#pragma once -#ifndef __BLAKE2B_LOAD_SSE41_H__ -#define __BLAKE2B_LOAD_SSE41_H__ - -#define LOAD_MSG_0_1(b0, b1) \ -do \ -{ \ -b0 = _mm_unpacklo_epi64(m0, m1); \ -b1 = _mm_unpacklo_epi64(m2, m3); \ -} while(0) - - -#define LOAD_MSG_0_2(b0, b1) \ -do \ -{ \ -b0 = _mm_unpackhi_epi64(m0, m1); \ -b1 = _mm_unpackhi_epi64(m2, m3); \ -} while(0) - - -#define LOAD_MSG_0_3(b0, b1) \ -do \ -{ \ -b0 = _mm_unpacklo_epi64(m4, m5); \ -b1 = _mm_unpacklo_epi64(m6, m7); \ -} while(0) - - -#define LOAD_MSG_0_4(b0, b1) \ -do \ -{ \ -b0 = _mm_unpackhi_epi64(m4, m5); \ -b1 = _mm_unpackhi_epi64(m6, m7); \ -} while(0) - - -#define LOAD_MSG_1_1(b0, b1) \ -do \ -{ \ -b0 = _mm_unpacklo_epi64(m7, m2); \ -b1 = _mm_unpackhi_epi64(m4, m6); \ -} while(0) - - -#define LOAD_MSG_1_2(b0, b1) \ -do \ -{ \ -b0 = _mm_unpacklo_epi64(m5, m4); \ -b1 = _mm_alignr_epi8(m3, m7, 8); \ -} while(0) - - -#define LOAD_MSG_1_3(b0, b1) \ -do \ -{ \ -b0 = _mm_shuffle_epi32(m0, _MM_SHUFFLE(1,0,3,2)); \ -b1 = _mm_unpackhi_epi64(m5, m2); \ -} while(0) - - -#define LOAD_MSG_1_4(b0, b1) \ -do \ -{ \ -b0 = _mm_unpacklo_epi64(m6, m1); \ -b1 = _mm_unpackhi_epi64(m3, m1); \ -} while(0) - - -#define LOAD_MSG_2_1(b0, b1) \ -do \ -{ \ -b0 = _mm_alignr_epi8(m6, m5, 8); \ -b1 = _mm_unpackhi_epi64(m2, m7); \ -} while(0) - - -#define LOAD_MSG_2_2(b0, b1) \ -do \ -{ \ -b0 = _mm_unpacklo_epi64(m4, m0); \ -b1 = _mm_blend_epi16(m1, m6, 0xF0); \ -} while(0) - - -#define LOAD_MSG_2_3(b0, b1) \ -do \ -{ \ -b0 = _mm_blend_epi16(m5, m1, 0xF0); \ -b1 = _mm_unpackhi_epi64(m3, m4); \ -} while(0) - - -#define LOAD_MSG_2_4(b0, b1) \ -do \ -{ \ -b0 = _mm_unpacklo_epi64(m7, m3); \ -b1 = _mm_alignr_epi8(m2, m0, 8); \ -} while(0) - - -#define LOAD_MSG_3_1(b0, b1) \ -do \ -{ \ -b0 = _mm_unpackhi_epi64(m3, m1); \ -b1 = _mm_unpackhi_epi64(m6, m5); \ -} while(0) - - -#define LOAD_MSG_3_2(b0, b1) \ -do \ -{ \ -b0 = _mm_unpackhi_epi64(m4, m0); \ -b1 = _mm_unpacklo_epi64(m6, m7); \ -} while(0) - - -#define LOAD_MSG_3_3(b0, b1) \ -do \ -{ \ -b0 = _mm_blend_epi16(m1, m2, 0xF0); \ -b1 = _mm_blend_epi16(m2, m7, 0xF0); \ -} while(0) - - -#define LOAD_MSG_3_4(b0, b1) \ -do \ -{ \ -b0 = _mm_unpacklo_epi64(m3, m5); \ -b1 = _mm_unpacklo_epi64(m0, m4); \ -} while(0) - - -#define LOAD_MSG_4_1(b0, b1) \ -do \ -{ \ -b0 = _mm_unpackhi_epi64(m4, m2); \ -b1 = _mm_unpacklo_epi64(m1, m5); \ -} while(0) - - -#define LOAD_MSG_4_2(b0, b1) \ -do \ -{ \ -b0 = _mm_blend_epi16(m0, m3, 0xF0); \ -b1 = _mm_blend_epi16(m2, m7, 0xF0); \ -} while(0) - - -#define LOAD_MSG_4_3(b0, b1) \ -do \ -{ \ -b0 = _mm_blend_epi16(m7, m5, 0xF0); \ -b1 = _mm_blend_epi16(m3, m1, 0xF0); \ -} while(0) - - -#define LOAD_MSG_4_4(b0, b1) \ -do \ -{ \ -b0 = _mm_alignr_epi8(m6, m0, 8); \ -b1 = _mm_blend_epi16(m4, m6, 0xF0); \ -} while(0) - - -#define LOAD_MSG_5_1(b0, b1) \ -do \ -{ \ -b0 = _mm_unpacklo_epi64(m1, m3); \ -b1 = _mm_unpacklo_epi64(m0, m4); \ -} while(0) - - -#define LOAD_MSG_5_2(b0, b1) \ -do \ -{ \ -b0 = _mm_unpacklo_epi64(m6, m5); \ -b1 = _mm_unpackhi_epi64(m5, m1); \ -} while(0) - - -#define LOAD_MSG_5_3(b0, b1) \ -do \ -{ \ -b0 = _mm_blend_epi16(m2, m3, 0xF0); \ -b1 = _mm_unpackhi_epi64(m7, m0); \ -} while(0) - - -#define LOAD_MSG_5_4(b0, b1) \ -do \ -{ \ -b0 = _mm_unpackhi_epi64(m6, m2); \ -b1 = _mm_blend_epi16(m7, m4, 0xF0); \ -} while(0) - - -#define LOAD_MSG_6_1(b0, b1) \ -do \ -{ \ -b0 = _mm_blend_epi16(m6, m0, 0xF0); \ -b1 = _mm_unpacklo_epi64(m7, m2); \ -} while(0) - - -#define LOAD_MSG_6_2(b0, b1) \ -do \ -{ \ -b0 = _mm_unpackhi_epi64(m2, m7); \ -b1 = _mm_alignr_epi8(m5, m6, 8); \ -} while(0) - - -#define LOAD_MSG_6_3(b0, b1) \ -do \ -{ \ -b0 = _mm_unpacklo_epi64(m0, m3); \ -b1 = _mm_shuffle_epi32(m4, _MM_SHUFFLE(1,0,3,2)); \ -} while(0) - - -#define LOAD_MSG_6_4(b0, b1) \ -do \ -{ \ -b0 = _mm_unpackhi_epi64(m3, m1); \ -b1 = _mm_blend_epi16(m1, m5, 0xF0); \ -} while(0) - - -#define LOAD_MSG_7_1(b0, b1) \ -do \ -{ \ -b0 = _mm_unpackhi_epi64(m6, m3); \ -b1 = _mm_blend_epi16(m6, m1, 0xF0); \ -} while(0) - - -#define LOAD_MSG_7_2(b0, b1) \ -do \ -{ \ -b0 = _mm_alignr_epi8(m7, m5, 8); \ -b1 = _mm_unpackhi_epi64(m0, m4); \ -} while(0) - - -#define LOAD_MSG_7_3(b0, b1) \ -do \ -{ \ -b0 = _mm_unpackhi_epi64(m2, m7); \ -b1 = _mm_unpacklo_epi64(m4, m1); \ -} while(0) - - -#define LOAD_MSG_7_4(b0, b1) \ -do \ -{ \ -b0 = _mm_unpacklo_epi64(m0, m2); \ -b1 = _mm_unpacklo_epi64(m3, m5); \ -} while(0) - - -#define LOAD_MSG_8_1(b0, b1) \ -do \ -{ \ -b0 = _mm_unpacklo_epi64(m3, m7); \ -b1 = _mm_alignr_epi8(m0, m5, 8); \ -} while(0) - - -#define LOAD_MSG_8_2(b0, b1) \ -do \ -{ \ -b0 = _mm_unpackhi_epi64(m7, m4); \ -b1 = _mm_alignr_epi8(m4, m1, 8); \ -} while(0) - - -#define LOAD_MSG_8_3(b0, b1) \ -do \ -{ \ -b0 = m6; \ -b1 = _mm_alignr_epi8(m5, m0, 8); \ -} while(0) - - -#define LOAD_MSG_8_4(b0, b1) \ -do \ -{ \ -b0 = _mm_blend_epi16(m1, m3, 0xF0); \ -b1 = m2; \ -} while(0) - - -#define LOAD_MSG_9_1(b0, b1) \ -do \ -{ \ -b0 = _mm_unpacklo_epi64(m5, m4); \ -b1 = _mm_unpackhi_epi64(m3, m0); \ -} while(0) - - -#define LOAD_MSG_9_2(b0, b1) \ -do \ -{ \ -b0 = _mm_unpacklo_epi64(m1, m2); \ -b1 = _mm_blend_epi16(m3, m2, 0xF0); \ -} while(0) - - -#define LOAD_MSG_9_3(b0, b1) \ -do \ -{ \ -b0 = _mm_unpackhi_epi64(m7, m4); \ -b1 = _mm_unpackhi_epi64(m1, m6); \ -} while(0) - - -#define LOAD_MSG_9_4(b0, b1) \ -do \ -{ \ -b0 = _mm_alignr_epi8(m7, m5, 8); \ -b1 = _mm_unpacklo_epi64(m6, m0); \ -} while(0) - - -#define LOAD_MSG_10_1(b0, b1) \ -do \ -{ \ -b0 = _mm_unpacklo_epi64(m0, m1); \ -b1 = _mm_unpacklo_epi64(m2, m3); \ -} while(0) - - -#define LOAD_MSG_10_2(b0, b1) \ -do \ -{ \ -b0 = _mm_unpackhi_epi64(m0, m1); \ -b1 = _mm_unpackhi_epi64(m2, m3); \ -} while(0) - - -#define LOAD_MSG_10_3(b0, b1) \ -do \ -{ \ -b0 = _mm_unpacklo_epi64(m4, m5); \ -b1 = _mm_unpacklo_epi64(m6, m7); \ -} while(0) - - -#define LOAD_MSG_10_4(b0, b1) \ -do \ -{ \ -b0 = _mm_unpackhi_epi64(m4, m5); \ -b1 = _mm_unpackhi_epi64(m6, m7); \ -} while(0) - - -#define LOAD_MSG_11_1(b0, b1) \ -do \ -{ \ -b0 = _mm_unpacklo_epi64(m7, m2); \ -b1 = _mm_unpackhi_epi64(m4, m6); \ -} while(0) - - -#define LOAD_MSG_11_2(b0, b1) \ -do \ -{ \ -b0 = _mm_unpacklo_epi64(m5, m4); \ -b1 = _mm_alignr_epi8(m3, m7, 8); \ -} while(0) - - -#define LOAD_MSG_11_3(b0, b1) \ -do \ -{ \ -b0 = _mm_shuffle_epi32(m0, _MM_SHUFFLE(1,0,3,2)); \ -b1 = _mm_unpackhi_epi64(m5, m2); \ -} while(0) - - -#define LOAD_MSG_11_4(b0, b1) \ -do \ -{ \ -b0 = _mm_unpacklo_epi64(m6, m1); \ -b1 = _mm_unpackhi_epi64(m3, m1); \ -} while(0) - - -#endif - diff --git a/third_party/python/Modules/_blake2/impl/blake2b-ref.c b/third_party/python/Modules/_blake2/impl/blake2b-ref.c deleted file mode 100644 index 79d484579..000000000 --- a/third_party/python/Modules/_blake2/impl/blake2b-ref.c +++ /dev/null @@ -1,417 +0,0 @@ -/* clang-format off */ -/* - BLAKE2 reference source code package - reference C implementations - - Copyright 2012, Samuel Neves . You may use this under the - terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at - your option. The terms of these licenses can be found at: - - - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 - - OpenSSL license : https://www.openssl.org/source/license.html - - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 - - More information about the BLAKE2 hash function can be found at - https://blake2.net. -*/ - -#include "blake2.h" -#include "blake2-impl.h" - -static const uint64_t blake2b_IV[8] = -{ - 0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL, - 0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL, - 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL, - 0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL -}; - -static const uint8_t blake2b_sigma[12][16] = -{ - { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } , - { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } , - { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 } , - { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 } , - { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 } , - { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 } , - { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 } , - { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 } , - { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 } , - { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 } , - { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } , - { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } -}; - - -BLAKE2_LOCAL_INLINE(int) blake2b_set_lastnode( blake2b_state *S ) -{ - S->f[1] = -1; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_clear_lastnode( blake2b_state *S ) -{ - S->f[1] = 0; - return 0; -} - -/* Some helper functions, not necessarily useful */ -BLAKE2_LOCAL_INLINE(int) blake2b_is_lastblock( const blake2b_state *S ) -{ - return S->f[0] != 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_set_lastblock( blake2b_state *S ) -{ - if( S->last_node ) blake2b_set_lastnode( S ); - - S->f[0] = -1; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_clear_lastblock( blake2b_state *S ) -{ - if( S->last_node ) blake2b_clear_lastnode( S ); - - S->f[0] = 0; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_increment_counter( blake2b_state *S, const uint64_t inc ) -{ - S->t[0] += inc; - S->t[1] += ( S->t[0] < inc ); - return 0; -} - - - -/* Parameter-related functions */ -BLAKE2_LOCAL_INLINE(int) blake2b_param_set_digest_length( blake2b_param *P, const uint8_t digest_length ) -{ - P->digest_length = digest_length; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_param_set_fanout( blake2b_param *P, const uint8_t fanout ) -{ - P->fanout = fanout; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_param_set_max_depth( blake2b_param *P, const uint8_t depth ) -{ - P->depth = depth; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_param_set_leaf_length( blake2b_param *P, const uint32_t leaf_length ) -{ - store32( &P->leaf_length, leaf_length ); - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_param_set_node_offset( blake2b_param *P, const uint64_t node_offset ) -{ - store64( &P->node_offset, node_offset ); - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_param_set_node_depth( blake2b_param *P, const uint8_t node_depth ) -{ - P->node_depth = node_depth; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_param_set_inner_length( blake2b_param *P, const uint8_t inner_length ) -{ - P->inner_length = inner_length; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_param_set_salt( blake2b_param *P, const uint8_t salt[BLAKE2B_SALTBYTES] ) -{ - memcpy( P->salt, salt, BLAKE2B_SALTBYTES ); - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_param_set_personal( blake2b_param *P, const uint8_t personal[BLAKE2B_PERSONALBYTES] ) -{ - memcpy( P->personal, personal, BLAKE2B_PERSONALBYTES ); - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_init0( blake2b_state *S ) -{ - int i; - memset( S, 0, sizeof( blake2b_state ) ); - - for( i = 0; i < 8; ++i ) S->h[i] = blake2b_IV[i]; - - return 0; -} - -/* init xors IV with input parameter block */ -int blake2b_init_param( blake2b_state *S, const blake2b_param *P ) -{ - const uint8_t *p = ( const uint8_t * )( P ); - size_t i; - - blake2b_init0( S ); - - /* IV XOR ParamBlock */ - for( i = 0; i < 8; ++i ) - S->h[i] ^= load64( p + sizeof( S->h[i] ) * i ); - - return 0; -} - - - -int blake2b_init( blake2b_state *S, const uint8_t outlen ) -{ - blake2b_param P[1]; - - if ( ( !outlen ) || ( outlen > BLAKE2B_OUTBYTES ) ) return -1; - - P->digest_length = outlen; - P->key_length = 0; - P->fanout = 1; - P->depth = 1; - store32( &P->leaf_length, 0 ); - store64( &P->node_offset, 0 ); - P->node_depth = 0; - P->inner_length = 0; - memset( P->reserved, 0, sizeof( P->reserved ) ); - memset( P->salt, 0, sizeof( P->salt ) ); - memset( P->personal, 0, sizeof( P->personal ) ); - return blake2b_init_param( S, P ); -} - - -int blake2b_init_key( blake2b_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ) -{ - blake2b_param P[1]; - - if ( ( !outlen ) || ( outlen > BLAKE2B_OUTBYTES ) ) return -1; - - if ( !key || !keylen || keylen > BLAKE2B_KEYBYTES ) return -1; - - P->digest_length = outlen; - P->key_length = keylen; - P->fanout = 1; - P->depth = 1; - store32( &P->leaf_length, 0 ); - store64( &P->node_offset, 0 ); - P->node_depth = 0; - P->inner_length = 0; - memset( P->reserved, 0, sizeof( P->reserved ) ); - memset( P->salt, 0, sizeof( P->salt ) ); - memset( P->personal, 0, sizeof( P->personal ) ); - - if( blake2b_init_param( S, P ) < 0 ) return -1; - - { - uint8_t block[BLAKE2B_BLOCKBYTES]; - memset( block, 0, BLAKE2B_BLOCKBYTES ); - memcpy( block, key, keylen ); - blake2b_update( S, block, BLAKE2B_BLOCKBYTES ); - secure_zero_memory( block, BLAKE2B_BLOCKBYTES ); /* Burn the key from stack */ - } - return 0; -} - -static int blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] ) -{ - uint64_t m[16]; - uint64_t v[16]; - int i; - - for( i = 0; i < 16; ++i ) - m[i] = load64( block + i * sizeof( m[i] ) ); - - for( i = 0; i < 8; ++i ) - v[i] = S->h[i]; - - v[ 8] = blake2b_IV[0]; - v[ 9] = blake2b_IV[1]; - v[10] = blake2b_IV[2]; - v[11] = blake2b_IV[3]; - v[12] = S->t[0] ^ blake2b_IV[4]; - v[13] = S->t[1] ^ blake2b_IV[5]; - v[14] = S->f[0] ^ blake2b_IV[6]; - v[15] = S->f[1] ^ blake2b_IV[7]; -#define G(r,i,a,b,c,d) \ - do { \ - a = a + b + m[blake2b_sigma[r][2*i+0]]; \ - d = rotr64(d ^ a, 32); \ - c = c + d; \ - b = rotr64(b ^ c, 24); \ - a = a + b + m[blake2b_sigma[r][2*i+1]]; \ - d = rotr64(d ^ a, 16); \ - c = c + d; \ - b = rotr64(b ^ c, 63); \ - } while(0) -#define ROUND(r) \ - do { \ - G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \ - G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \ - G(r,2,v[ 2],v[ 6],v[10],v[14]); \ - G(r,3,v[ 3],v[ 7],v[11],v[15]); \ - G(r,4,v[ 0],v[ 5],v[10],v[15]); \ - G(r,5,v[ 1],v[ 6],v[11],v[12]); \ - G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \ - G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \ - } while(0) - ROUND( 0 ); - ROUND( 1 ); - ROUND( 2 ); - ROUND( 3 ); - ROUND( 4 ); - ROUND( 5 ); - ROUND( 6 ); - ROUND( 7 ); - ROUND( 8 ); - ROUND( 9 ); - ROUND( 10 ); - ROUND( 11 ); - - for( i = 0; i < 8; ++i ) - S->h[i] = S->h[i] ^ v[i] ^ v[i + 8]; - -#undef G -#undef ROUND - return 0; -} - -/* inlen now in bytes */ -int blake2b_update( blake2b_state *S, const uint8_t *in, uint64_t inlen ) -{ - while( inlen > 0 ) - { - size_t left = S->buflen; - size_t fill = 2 * BLAKE2B_BLOCKBYTES - left; - - if( inlen > fill ) - { - memcpy( S->buf + left, in, fill ); /* Fill buffer */ - S->buflen += fill; - blake2b_increment_counter( S, BLAKE2B_BLOCKBYTES ); - blake2b_compress( S, S->buf ); /* Compress */ - memcpy( S->buf, S->buf + BLAKE2B_BLOCKBYTES, BLAKE2B_BLOCKBYTES ); /* Shift buffer left */ - S->buflen -= BLAKE2B_BLOCKBYTES; - in += fill; - inlen -= fill; - } - else /* inlen <= fill */ - { - memcpy( S->buf + left, in, (size_t)inlen ); - S->buflen += (size_t)inlen; /* Be lazy, do not compress */ - in += inlen; - inlen -= inlen; - } - } - - return 0; -} - -/* Is this correct? */ -int blake2b_final( blake2b_state *S, uint8_t *out, uint8_t outlen ) -{ - uint8_t buffer[BLAKE2B_OUTBYTES] = {0}; - int i; - - if( out == NULL || outlen == 0 || outlen > BLAKE2B_OUTBYTES ) - return -1; - - if( blake2b_is_lastblock( S ) ) - return -1; - - if( S->buflen > BLAKE2B_BLOCKBYTES ) - { - blake2b_increment_counter( S, BLAKE2B_BLOCKBYTES ); - blake2b_compress( S, S->buf ); - S->buflen -= BLAKE2B_BLOCKBYTES; - memmove( S->buf, S->buf + BLAKE2B_BLOCKBYTES, S->buflen ); - } - - blake2b_increment_counter( S, S->buflen ); - blake2b_set_lastblock( S ); - memset( S->buf + S->buflen, 0, 2 * BLAKE2B_BLOCKBYTES - S->buflen ); /* Padding */ - blake2b_compress( S, S->buf ); - - for( i = 0; i < 8; ++i ) /* Output full hash to temp buffer */ - store64( buffer + sizeof( S->h[i] ) * i, S->h[i] ); - - memcpy( out, buffer, outlen ); - return 0; -} - -/* inlen, at least, should be uint64_t. Others can be size_t. */ -int blake2b( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ) -{ - blake2b_state S[1]; - - /* Verify parameters */ - if ( NULL == in && inlen > 0 ) return -1; - - if ( NULL == out ) return -1; - - if( NULL == key && keylen > 0 ) return -1; - - if( !outlen || outlen > BLAKE2B_OUTBYTES ) return -1; - - if( keylen > BLAKE2B_KEYBYTES ) return -1; - - if( keylen > 0 ) - { - if( blake2b_init_key( S, outlen, key, keylen ) < 0 ) return -1; - } - else - { - if( blake2b_init( S, outlen ) < 0 ) return -1; - } - - blake2b_update( S, ( const uint8_t * )in, inlen ); - blake2b_final( S, out, outlen ); - return 0; -} - -#if defined(SUPERCOP) -int crypto_hash( unsigned char *out, unsigned char *in, unsigned long long inlen ) -{ - return blake2b( out, in, NULL, BLAKE2B_OUTBYTES, inlen, 0 ); -} -#endif - -#if defined(BLAKE2B_SELFTEST) -#include -#include "blake2-kat.h" -int main( int argc, char **argv ) -{ - uint8_t key[BLAKE2B_KEYBYTES]; - uint8_t buf[KAT_LENGTH]; - size_t i; - - for( i = 0; i < BLAKE2B_KEYBYTES; ++i ) - key[i] = ( uint8_t )i; - - for( i = 0; i < KAT_LENGTH; ++i ) - buf[i] = ( uint8_t )i; - - for( i = 0; i < KAT_LENGTH; ++i ) - { - uint8_t hash[BLAKE2B_OUTBYTES]; - blake2b( hash, buf, key, BLAKE2B_OUTBYTES, i, BLAKE2B_KEYBYTES ); - - if( 0 != memcmp( hash, blake2b_keyed_kat[i], BLAKE2B_OUTBYTES ) ) - { - puts( "error" ); - return -1; - } - } - - puts( "ok" ); - return 0; -} -#endif - diff --git a/third_party/python/Modules/_blake2/impl/blake2b-round.h b/third_party/python/Modules/_blake2/impl/blake2b-round.h deleted file mode 100644 index c6a3230a5..000000000 --- a/third_party/python/Modules/_blake2/impl/blake2b-round.h +++ /dev/null @@ -1,160 +0,0 @@ -/* clang-format off */ -/* - BLAKE2 reference source code package - optimized C implementations - - Copyright 2012, Samuel Neves . You may use this under the - terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at - your option. The terms of these licenses can be found at: - - - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 - - OpenSSL license : https://www.openssl.org/source/license.html - - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 - - More information about the BLAKE2 hash function can be found at - https://blake2.net. -*/ -#pragma once -#ifndef __BLAKE2B_ROUND_H__ -#define __BLAKE2B_ROUND_H__ - -#define LOADU(p) _mm_loadu_si128( (const __m128i *)(p) ) -#define STOREU(p,r) _mm_storeu_si128((__m128i *)(p), r) - -#define TOF(reg) _mm_castsi128_ps((reg)) -#define TOI(reg) _mm_castps_si128((reg)) - -#define LIKELY(x) __builtin_expect((x),1) - - -/* Microarchitecture-specific macros */ -#ifndef HAVE_XOP -#ifdef HAVE_SSSE3 -#define _mm_roti_epi64(x, c) \ - (-(c) == 32) ? _mm_shuffle_epi32((x), _MM_SHUFFLE(2,3,0,1)) \ - : (-(c) == 24) ? _mm_shuffle_epi8((x), r24) \ - : (-(c) == 16) ? _mm_shuffle_epi8((x), r16) \ - : (-(c) == 63) ? _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_add_epi64((x), (x))) \ - : _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_slli_epi64((x), 64-(-(c)))) -#else -#define _mm_roti_epi64(r, c) _mm_xor_si128(_mm_srli_epi64( (r), -(c) ),_mm_slli_epi64( (r), 64-(-(c)) )) -#endif -#else -/* ... */ -#endif - - - -#define G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h,b0,b1) \ - row1l = _mm_add_epi64(_mm_add_epi64(row1l, b0), row2l); \ - row1h = _mm_add_epi64(_mm_add_epi64(row1h, b1), row2h); \ - \ - row4l = _mm_xor_si128(row4l, row1l); \ - row4h = _mm_xor_si128(row4h, row1h); \ - \ - row4l = _mm_roti_epi64(row4l, -32); \ - row4h = _mm_roti_epi64(row4h, -32); \ - \ - row3l = _mm_add_epi64(row3l, row4l); \ - row3h = _mm_add_epi64(row3h, row4h); \ - \ - row2l = _mm_xor_si128(row2l, row3l); \ - row2h = _mm_xor_si128(row2h, row3h); \ - \ - row2l = _mm_roti_epi64(row2l, -24); \ - row2h = _mm_roti_epi64(row2h, -24); \ - -#define G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h,b0,b1) \ - row1l = _mm_add_epi64(_mm_add_epi64(row1l, b0), row2l); \ - row1h = _mm_add_epi64(_mm_add_epi64(row1h, b1), row2h); \ - \ - row4l = _mm_xor_si128(row4l, row1l); \ - row4h = _mm_xor_si128(row4h, row1h); \ - \ - row4l = _mm_roti_epi64(row4l, -16); \ - row4h = _mm_roti_epi64(row4h, -16); \ - \ - row3l = _mm_add_epi64(row3l, row4l); \ - row3h = _mm_add_epi64(row3h, row4h); \ - \ - row2l = _mm_xor_si128(row2l, row3l); \ - row2h = _mm_xor_si128(row2h, row3h); \ - \ - row2l = _mm_roti_epi64(row2l, -63); \ - row2h = _mm_roti_epi64(row2h, -63); \ - -#if defined(HAVE_SSSE3) -#define DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ - t0 = _mm_alignr_epi8(row2h, row2l, 8); \ - t1 = _mm_alignr_epi8(row2l, row2h, 8); \ - row2l = t0; \ - row2h = t1; \ - \ - t0 = row3l; \ - row3l = row3h; \ - row3h = t0; \ - \ - t0 = _mm_alignr_epi8(row4h, row4l, 8); \ - t1 = _mm_alignr_epi8(row4l, row4h, 8); \ - row4l = t1; \ - row4h = t0; - -#define UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ - t0 = _mm_alignr_epi8(row2l, row2h, 8); \ - t1 = _mm_alignr_epi8(row2h, row2l, 8); \ - row2l = t0; \ - row2h = t1; \ - \ - t0 = row3l; \ - row3l = row3h; \ - row3h = t0; \ - \ - t0 = _mm_alignr_epi8(row4l, row4h, 8); \ - t1 = _mm_alignr_epi8(row4h, row4l, 8); \ - row4l = t1; \ - row4h = t0; -#else - -#define DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ - t0 = row4l;\ - t1 = row2l;\ - row4l = row3l;\ - row3l = row3h;\ - row3h = row4l;\ - row4l = _mm_unpackhi_epi64(row4h, _mm_unpacklo_epi64(t0, t0)); \ - row4h = _mm_unpackhi_epi64(t0, _mm_unpacklo_epi64(row4h, row4h)); \ - row2l = _mm_unpackhi_epi64(row2l, _mm_unpacklo_epi64(row2h, row2h)); \ - row2h = _mm_unpackhi_epi64(row2h, _mm_unpacklo_epi64(t1, t1)) - -#define UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ - t0 = row3l;\ - row3l = row3h;\ - row3h = t0;\ - t0 = row2l;\ - t1 = row4l;\ - row2l = _mm_unpackhi_epi64(row2h, _mm_unpacklo_epi64(row2l, row2l)); \ - row2h = _mm_unpackhi_epi64(t0, _mm_unpacklo_epi64(row2h, row2h)); \ - row4l = _mm_unpackhi_epi64(row4l, _mm_unpacklo_epi64(row4h, row4h)); \ - row4h = _mm_unpackhi_epi64(row4h, _mm_unpacklo_epi64(t1, t1)) - -#endif - -#if defined(HAVE_SSE41) -#include "blake2b-load-sse41.h" -#else -#include "blake2b-load-sse2.h" -#endif - -#define ROUND(r) \ - LOAD_MSG_ ##r ##_1(b0, b1); \ - G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h,b0,b1); \ - LOAD_MSG_ ##r ##_2(b0, b1); \ - G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h,b0,b1); \ - DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ - LOAD_MSG_ ##r ##_3(b0, b1); \ - G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h,b0,b1); \ - LOAD_MSG_ ##r ##_4(b0, b1); \ - G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h,b0,b1); \ - UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); - -#endif - diff --git a/third_party/python/Modules/_blake2/impl/blake2b.c b/third_party/python/Modules/_blake2/impl/blake2b.c deleted file mode 100644 index 9ca73f023..000000000 --- a/third_party/python/Modules/_blake2/impl/blake2b.c +++ /dev/null @@ -1,454 +0,0 @@ -/* clang-format off */ -/* - BLAKE2 reference source code package - optimized C implementations - - Copyright 2012, Samuel Neves . You may use this under the - terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at - your option. The terms of these licenses can be found at: - - - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 - - OpenSSL license : https://www.openssl.org/source/license.html - - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 - - More information about the BLAKE2 hash function can be found at - https://blake2.net. -*/ - -#include -#include -#include - -#include "blake2.h" -#include "blake2-impl.h" - -#include "blake2-config.h" - -#ifdef _MSC_VER -#include /* for _mm_set_epi64x */ -#endif -#include -#if defined(HAVE_SSSE3) -#include -#endif -#if defined(HAVE_SSE41) -#include -#endif -#if defined(HAVE_AVX) -#include -#endif -#if defined(HAVE_XOP) -#include -#endif - -#include "blake2b-round.h" - -static const uint64_t blake2b_IV[8] = -{ - 0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL, - 0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL, - 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL, - 0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL -}; - -static const uint8_t blake2b_sigma[12][16] = -{ - { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } , - { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } , - { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 } , - { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 } , - { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 } , - { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 } , - { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 } , - { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 } , - { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 } , - { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 } , - { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } , - { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } -}; - - -/* Some helper functions, not necessarily useful */ -BLAKE2_LOCAL_INLINE(int) blake2b_set_lastnode( blake2b_state *S ) -{ - S->f[1] = -1; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_clear_lastnode( blake2b_state *S ) -{ - S->f[1] = 0; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_is_lastblock( const blake2b_state *S ) -{ - return S->f[0] != 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_set_lastblock( blake2b_state *S ) -{ - if( S->last_node ) blake2b_set_lastnode( S ); - - S->f[0] = -1; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_clear_lastblock( blake2b_state *S ) -{ - if( S->last_node ) blake2b_clear_lastnode( S ); - - S->f[0] = 0; - return 0; -} - - -BLAKE2_LOCAL_INLINE(int) blake2b_increment_counter( blake2b_state *S, const uint64_t inc ) -{ -#if __x86_64__ - /* ADD/ADC chain */ - __uint128_t t = ( ( __uint128_t )S->t[1] << 64 ) | S->t[0]; - t += inc; - S->t[0] = ( uint64_t )( t >> 0 ); - S->t[1] = ( uint64_t )( t >> 64 ); -#else - S->t[0] += inc; - S->t[1] += ( S->t[0] < inc ); -#endif - return 0; -} - - -/* Parameter-related functions */ -BLAKE2_LOCAL_INLINE(int) blake2b_param_set_digest_length( blake2b_param *P, const uint8_t digest_length ) -{ - P->digest_length = digest_length; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_param_set_fanout( blake2b_param *P, const uint8_t fanout ) -{ - P->fanout = fanout; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_param_set_max_depth( blake2b_param *P, const uint8_t depth ) -{ - P->depth = depth; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_param_set_leaf_length( blake2b_param *P, const uint32_t leaf_length ) -{ - P->leaf_length = leaf_length; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_param_set_node_offset( blake2b_param *P, const uint64_t node_offset ) -{ - P->node_offset = node_offset; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_param_set_node_depth( blake2b_param *P, const uint8_t node_depth ) -{ - P->node_depth = node_depth; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_param_set_inner_length( blake2b_param *P, const uint8_t inner_length ) -{ - P->inner_length = inner_length; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_param_set_salt( blake2b_param *P, const uint8_t salt[BLAKE2B_SALTBYTES] ) -{ - memcpy( P->salt, salt, BLAKE2B_SALTBYTES ); - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_param_set_personal( blake2b_param *P, const uint8_t personal[BLAKE2B_PERSONALBYTES] ) -{ - memcpy( P->personal, personal, BLAKE2B_PERSONALBYTES ); - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_init0( blake2b_state *S ) -{ - int i; - memset( S, 0, sizeof( blake2b_state ) ); - - for( i = 0; i < 8; ++i ) S->h[i] = blake2b_IV[i]; - - return 0; -} - -/* init xors IV with input parameter block */ -int blake2b_init_param( blake2b_state *S, const blake2b_param *P ) -{ - /*blake2b_init0( S ); */ - const uint8_t * v = ( const uint8_t * )( blake2b_IV ); - const uint8_t * p = ( const uint8_t * )( P ); - uint8_t * h = ( uint8_t * )( S->h ); - int i; - /* IV XOR ParamBlock */ - memset( S, 0, sizeof( blake2b_state ) ); - - for( i = 0; i < BLAKE2B_OUTBYTES; ++i ) h[i] = v[i] ^ p[i]; - - return 0; -} - - -/* Some sort of default parameter block initialization, for sequential blake2b */ -int blake2b_init( blake2b_state *S, const uint8_t outlen ) -{ - const blake2b_param P = - { - outlen, - 0, - 1, - 1, - 0, - 0, - 0, - 0, - {0}, - {0}, - {0} - }; - - if ( ( !outlen ) || ( outlen > BLAKE2B_OUTBYTES ) ) return -1; - - return blake2b_init_param( S, &P ); -} - -int blake2b_init_key( blake2b_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ) -{ - const blake2b_param P = - { - outlen, - keylen, - 1, - 1, - 0, - 0, - 0, - 0, - {0}, - {0}, - {0} - }; - - if ( ( !outlen ) || ( outlen > BLAKE2B_OUTBYTES ) ) return -1; - - if ( ( !keylen ) || keylen > BLAKE2B_KEYBYTES ) return -1; - - if( blake2b_init_param( S, &P ) < 0 ) - return 0; - - { - uint8_t block[BLAKE2B_BLOCKBYTES]; - memset( block, 0, BLAKE2B_BLOCKBYTES ); - memcpy( block, key, keylen ); - blake2b_update( S, block, BLAKE2B_BLOCKBYTES ); - secure_zero_memory( block, BLAKE2B_BLOCKBYTES ); /* Burn the key from stack */ - } - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] ) -{ - __m128i row1l, row1h; - __m128i row2l, row2h; - __m128i row3l, row3h; - __m128i row4l, row4h; - __m128i b0, b1; - __m128i t0, t1; -#if defined(HAVE_SSSE3) && !defined(HAVE_XOP) - const __m128i r16 = _mm_setr_epi8( 2, 3, 4, 5, 6, 7, 0, 1, 10, 11, 12, 13, 14, 15, 8, 9 ); - const __m128i r24 = _mm_setr_epi8( 3, 4, 5, 6, 7, 0, 1, 2, 11, 12, 13, 14, 15, 8, 9, 10 ); -#endif -#if defined(HAVE_SSE41) - const __m128i m0 = LOADU( block + 00 ); - const __m128i m1 = LOADU( block + 16 ); - const __m128i m2 = LOADU( block + 32 ); - const __m128i m3 = LOADU( block + 48 ); - const __m128i m4 = LOADU( block + 64 ); - const __m128i m5 = LOADU( block + 80 ); - const __m128i m6 = LOADU( block + 96 ); - const __m128i m7 = LOADU( block + 112 ); -#else - const uint64_t m0 = ( ( uint64_t * )block )[ 0]; - const uint64_t m1 = ( ( uint64_t * )block )[ 1]; - const uint64_t m2 = ( ( uint64_t * )block )[ 2]; - const uint64_t m3 = ( ( uint64_t * )block )[ 3]; - const uint64_t m4 = ( ( uint64_t * )block )[ 4]; - const uint64_t m5 = ( ( uint64_t * )block )[ 5]; - const uint64_t m6 = ( ( uint64_t * )block )[ 6]; - const uint64_t m7 = ( ( uint64_t * )block )[ 7]; - const uint64_t m8 = ( ( uint64_t * )block )[ 8]; - const uint64_t m9 = ( ( uint64_t * )block )[ 9]; - const uint64_t m10 = ( ( uint64_t * )block )[10]; - const uint64_t m11 = ( ( uint64_t * )block )[11]; - const uint64_t m12 = ( ( uint64_t * )block )[12]; - const uint64_t m13 = ( ( uint64_t * )block )[13]; - const uint64_t m14 = ( ( uint64_t * )block )[14]; - const uint64_t m15 = ( ( uint64_t * )block )[15]; -#endif - row1l = LOADU( &S->h[0] ); - row1h = LOADU( &S->h[2] ); - row2l = LOADU( &S->h[4] ); - row2h = LOADU( &S->h[6] ); - row3l = LOADU( &blake2b_IV[0] ); - row3h = LOADU( &blake2b_IV[2] ); - row4l = _mm_xor_si128( LOADU( &blake2b_IV[4] ), LOADU( &S->t[0] ) ); - row4h = _mm_xor_si128( LOADU( &blake2b_IV[6] ), LOADU( &S->f[0] ) ); - ROUND( 0 ); - ROUND( 1 ); - ROUND( 2 ); - ROUND( 3 ); - ROUND( 4 ); - ROUND( 5 ); - ROUND( 6 ); - ROUND( 7 ); - ROUND( 8 ); - ROUND( 9 ); - ROUND( 10 ); - ROUND( 11 ); - row1l = _mm_xor_si128( row3l, row1l ); - row1h = _mm_xor_si128( row3h, row1h ); - STOREU( &S->h[0], _mm_xor_si128( LOADU( &S->h[0] ), row1l ) ); - STOREU( &S->h[2], _mm_xor_si128( LOADU( &S->h[2] ), row1h ) ); - row2l = _mm_xor_si128( row4l, row2l ); - row2h = _mm_xor_si128( row4h, row2h ); - STOREU( &S->h[4], _mm_xor_si128( LOADU( &S->h[4] ), row2l ) ); - STOREU( &S->h[6], _mm_xor_si128( LOADU( &S->h[6] ), row2h ) ); - return 0; -} - - -int blake2b_update( blake2b_state *S, const uint8_t *in, uint64_t inlen ) -{ - while( inlen > 0 ) - { - size_t left = S->buflen; - size_t fill = 2 * BLAKE2B_BLOCKBYTES - left; - - if( inlen > fill ) - { - memcpy( S->buf + left, in, fill ); /* Fill buffer */ - S->buflen += fill; - blake2b_increment_counter( S, BLAKE2B_BLOCKBYTES ); - blake2b_compress( S, S->buf ); /* Compress */ - memcpy( S->buf, S->buf + BLAKE2B_BLOCKBYTES, BLAKE2B_BLOCKBYTES ); /* Shift buffer left */ - S->buflen -= BLAKE2B_BLOCKBYTES; - in += fill; - inlen -= fill; - } - else /* inlen <= fill */ - { - memcpy( S->buf + left, in, inlen ); - S->buflen += inlen; /* Be lazy, do not compress */ - in += inlen; - inlen -= inlen; - } - } - - return 0; -} - - -int blake2b_final( blake2b_state *S, uint8_t *out, uint8_t outlen ) -{ - if( outlen > BLAKE2B_OUTBYTES ) - return -1; - - if( blake2b_is_lastblock( S ) ) - return -1; - - if( S->buflen > BLAKE2B_BLOCKBYTES ) - { - blake2b_increment_counter( S, BLAKE2B_BLOCKBYTES ); - blake2b_compress( S, S->buf ); - S->buflen -= BLAKE2B_BLOCKBYTES; - memmove( S->buf, S->buf + BLAKE2B_BLOCKBYTES, S->buflen ); - } - - blake2b_increment_counter( S, S->buflen ); - blake2b_set_lastblock( S ); - memset( S->buf + S->buflen, 0, 2 * BLAKE2B_BLOCKBYTES - S->buflen ); /* Padding */ - blake2b_compress( S, S->buf ); - memcpy( out, &S->h[0], outlen ); - return 0; -} - - -int blake2b( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ) -{ - blake2b_state S[1]; - - /* Verify parameters */ - if ( NULL == in && inlen > 0 ) return -1; - - if ( NULL == out ) return -1; - - if( NULL == key && keylen > 0 ) return -1; - - if( !outlen || outlen > BLAKE2B_OUTBYTES ) return -1; - - if( keylen > BLAKE2B_KEYBYTES ) return -1; - - if( keylen ) - { - if( blake2b_init_key( S, outlen, key, keylen ) < 0 ) return -1; - } - else - { - if( blake2b_init( S, outlen ) < 0 ) return -1; - } - - blake2b_update( S, ( const uint8_t * )in, inlen ); - blake2b_final( S, out, outlen ); - return 0; -} - -#if defined(SUPERCOP) -int crypto_hash( unsigned char *out, unsigned char *in, unsigned long long inlen ) -{ - return blake2b( out, in, NULL, BLAKE2B_OUTBYTES, inlen, 0 ); -} -#endif - -#if defined(BLAKE2B_SELFTEST) -#include -#include "blake2-kat.h" -int main( int argc, char **argv ) -{ - uint8_t key[BLAKE2B_KEYBYTES]; - uint8_t buf[KAT_LENGTH]; - size_t i; - - for( i = 0; i < BLAKE2B_KEYBYTES; ++i ) - key[i] = ( uint8_t )i; - - for( i = 0; i < KAT_LENGTH; ++i ) - buf[i] = ( uint8_t )i; - - for( i = 0; i < KAT_LENGTH; ++i ) - { - uint8_t hash[BLAKE2B_OUTBYTES]; - blake2b( hash, buf, key, BLAKE2B_OUTBYTES, i, BLAKE2B_KEYBYTES ); - - if( 0 != memcmp( hash, blake2b_keyed_kat[i], BLAKE2B_OUTBYTES ) ) - { - puts( "error" ); - return -1; - } - } - - puts( "ok" ); - return 0; -} -#endif - diff --git a/third_party/python/Modules/_blake2/impl/blake2s-load-sse2.h b/third_party/python/Modules/_blake2/impl/blake2s-load-sse2.h deleted file mode 100644 index 7f04ba1df..000000000 --- a/third_party/python/Modules/_blake2/impl/blake2s-load-sse2.h +++ /dev/null @@ -1,62 +0,0 @@ -/* clang-format off */ -/* - BLAKE2 reference source code package - optimized C implementations - - Copyright 2012, Samuel Neves . You may use this under the - terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at - your option. The terms of these licenses can be found at: - - - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 - - OpenSSL license : https://www.openssl.org/source/license.html - - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 - - More information about the BLAKE2 hash function can be found at - https://blake2.net. -*/ -#pragma once -#ifndef __BLAKE2S_LOAD_SSE2_H__ -#define __BLAKE2S_LOAD_SSE2_H__ - -#define LOAD_MSG_0_1(buf) buf = _mm_set_epi32(m6,m4,m2,m0) -#define LOAD_MSG_0_2(buf) buf = _mm_set_epi32(m7,m5,m3,m1) -#define LOAD_MSG_0_3(buf) buf = _mm_set_epi32(m14,m12,m10,m8) -#define LOAD_MSG_0_4(buf) buf = _mm_set_epi32(m15,m13,m11,m9) -#define LOAD_MSG_1_1(buf) buf = _mm_set_epi32(m13,m9,m4,m14) -#define LOAD_MSG_1_2(buf) buf = _mm_set_epi32(m6,m15,m8,m10) -#define LOAD_MSG_1_3(buf) buf = _mm_set_epi32(m5,m11,m0,m1) -#define LOAD_MSG_1_4(buf) buf = _mm_set_epi32(m3,m7,m2,m12) -#define LOAD_MSG_2_1(buf) buf = _mm_set_epi32(m15,m5,m12,m11) -#define LOAD_MSG_2_2(buf) buf = _mm_set_epi32(m13,m2,m0,m8) -#define LOAD_MSG_2_3(buf) buf = _mm_set_epi32(m9,m7,m3,m10) -#define LOAD_MSG_2_4(buf) buf = _mm_set_epi32(m4,m1,m6,m14) -#define LOAD_MSG_3_1(buf) buf = _mm_set_epi32(m11,m13,m3,m7) -#define LOAD_MSG_3_2(buf) buf = _mm_set_epi32(m14,m12,m1,m9) -#define LOAD_MSG_3_3(buf) buf = _mm_set_epi32(m15,m4,m5,m2) -#define LOAD_MSG_3_4(buf) buf = _mm_set_epi32(m8,m0,m10,m6) -#define LOAD_MSG_4_1(buf) buf = _mm_set_epi32(m10,m2,m5,m9) -#define LOAD_MSG_4_2(buf) buf = _mm_set_epi32(m15,m4,m7,m0) -#define LOAD_MSG_4_3(buf) buf = _mm_set_epi32(m3,m6,m11,m14) -#define LOAD_MSG_4_4(buf) buf = _mm_set_epi32(m13,m8,m12,m1) -#define LOAD_MSG_5_1(buf) buf = _mm_set_epi32(m8,m0,m6,m2) -#define LOAD_MSG_5_2(buf) buf = _mm_set_epi32(m3,m11,m10,m12) -#define LOAD_MSG_5_3(buf) buf = _mm_set_epi32(m1,m15,m7,m4) -#define LOAD_MSG_5_4(buf) buf = _mm_set_epi32(m9,m14,m5,m13) -#define LOAD_MSG_6_1(buf) buf = _mm_set_epi32(m4,m14,m1,m12) -#define LOAD_MSG_6_2(buf) buf = _mm_set_epi32(m10,m13,m15,m5) -#define LOAD_MSG_6_3(buf) buf = _mm_set_epi32(m8,m9,m6,m0) -#define LOAD_MSG_6_4(buf) buf = _mm_set_epi32(m11,m2,m3,m7) -#define LOAD_MSG_7_1(buf) buf = _mm_set_epi32(m3,m12,m7,m13) -#define LOAD_MSG_7_2(buf) buf = _mm_set_epi32(m9,m1,m14,m11) -#define LOAD_MSG_7_3(buf) buf = _mm_set_epi32(m2,m8,m15,m5) -#define LOAD_MSG_7_4(buf) buf = _mm_set_epi32(m10,m6,m4,m0) -#define LOAD_MSG_8_1(buf) buf = _mm_set_epi32(m0,m11,m14,m6) -#define LOAD_MSG_8_2(buf) buf = _mm_set_epi32(m8,m3,m9,m15) -#define LOAD_MSG_8_3(buf) buf = _mm_set_epi32(m10,m1,m13,m12) -#define LOAD_MSG_8_4(buf) buf = _mm_set_epi32(m5,m4,m7,m2) -#define LOAD_MSG_9_1(buf) buf = _mm_set_epi32(m1,m7,m8,m10) -#define LOAD_MSG_9_2(buf) buf = _mm_set_epi32(m5,m6,m4,m2) -#define LOAD_MSG_9_3(buf) buf = _mm_set_epi32(m13,m3,m9,m15) -#define LOAD_MSG_9_4(buf) buf = _mm_set_epi32(m0,m12,m14,m11) - - -#endif diff --git a/third_party/python/Modules/_blake2/impl/blake2s-load-sse41.h b/third_party/python/Modules/_blake2/impl/blake2s-load-sse41.h deleted file mode 100644 index d9156ad98..000000000 --- a/third_party/python/Modules/_blake2/impl/blake2s-load-sse41.h +++ /dev/null @@ -1,232 +0,0 @@ -/* clang-format off */ -/* - BLAKE2 reference source code package - optimized C implementations - - Copyright 2012, Samuel Neves . You may use this under the - terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at - your option. The terms of these licenses can be found at: - - - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 - - OpenSSL license : https://www.openssl.org/source/license.html - - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 - - More information about the BLAKE2 hash function can be found at - https://blake2.net. -*/ -#pragma once -#ifndef __BLAKE2S_LOAD_SSE41_H__ -#define __BLAKE2S_LOAD_SSE41_H__ - -#define LOAD_MSG_0_1(buf) \ -buf = TOI(_mm_shuffle_ps(TOF(m0), TOF(m1), _MM_SHUFFLE(2,0,2,0))); - -#define LOAD_MSG_0_2(buf) \ -buf = TOI(_mm_shuffle_ps(TOF(m0), TOF(m1), _MM_SHUFFLE(3,1,3,1))); - -#define LOAD_MSG_0_3(buf) \ -buf = TOI(_mm_shuffle_ps(TOF(m2), TOF(m3), _MM_SHUFFLE(2,0,2,0))); - -#define LOAD_MSG_0_4(buf) \ -buf = TOI(_mm_shuffle_ps(TOF(m2), TOF(m3), _MM_SHUFFLE(3,1,3,1))); - -#define LOAD_MSG_1_1(buf) \ -t0 = _mm_blend_epi16(m1, m2, 0x0C); \ -t1 = _mm_slli_si128(m3, 4); \ -t2 = _mm_blend_epi16(t0, t1, 0xF0); \ -buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(2,1,0,3)); - -#define LOAD_MSG_1_2(buf) \ -t0 = _mm_shuffle_epi32(m2,_MM_SHUFFLE(0,0,2,0)); \ -t1 = _mm_blend_epi16(m1,m3,0xC0); \ -t2 = _mm_blend_epi16(t0, t1, 0xF0); \ -buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(2,3,0,1)); - -#define LOAD_MSG_1_3(buf) \ -t0 = _mm_slli_si128(m1, 4); \ -t1 = _mm_blend_epi16(m2, t0, 0x30); \ -t2 = _mm_blend_epi16(m0, t1, 0xF0); \ -buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(2,3,0,1)); - -#define LOAD_MSG_1_4(buf) \ -t0 = _mm_unpackhi_epi32(m0,m1); \ -t1 = _mm_slli_si128(m3, 4); \ -t2 = _mm_blend_epi16(t0, t1, 0x0C); \ -buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(2,3,0,1)); - -#define LOAD_MSG_2_1(buf) \ -t0 = _mm_unpackhi_epi32(m2,m3); \ -t1 = _mm_blend_epi16(m3,m1,0x0C); \ -t2 = _mm_blend_epi16(t0, t1, 0x0F); \ -buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(3,1,0,2)); - -#define LOAD_MSG_2_2(buf) \ -t0 = _mm_unpacklo_epi32(m2,m0); \ -t1 = _mm_blend_epi16(t0, m0, 0xF0); \ -t2 = _mm_slli_si128(m3, 8); \ -buf = _mm_blend_epi16(t1, t2, 0xC0); - -#define LOAD_MSG_2_3(buf) \ -t0 = _mm_blend_epi16(m0, m2, 0x3C); \ -t1 = _mm_srli_si128(m1, 12); \ -t2 = _mm_blend_epi16(t0,t1,0x03); \ -buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(1,0,3,2)); - -#define LOAD_MSG_2_4(buf) \ -t0 = _mm_slli_si128(m3, 4); \ -t1 = _mm_blend_epi16(m0, m1, 0x33); \ -t2 = _mm_blend_epi16(t1, t0, 0xC0); \ -buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(0,1,2,3)); - -#define LOAD_MSG_3_1(buf) \ -t0 = _mm_unpackhi_epi32(m0,m1); \ -t1 = _mm_unpackhi_epi32(t0, m2); \ -t2 = _mm_blend_epi16(t1, m3, 0x0C); \ -buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(3,1,0,2)); - -#define LOAD_MSG_3_2(buf) \ -t0 = _mm_slli_si128(m2, 8); \ -t1 = _mm_blend_epi16(m3,m0,0x0C); \ -t2 = _mm_blend_epi16(t1, t0, 0xC0); \ -buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(2,0,1,3)); - -#define LOAD_MSG_3_3(buf) \ -t0 = _mm_blend_epi16(m0,m1,0x0F); \ -t1 = _mm_blend_epi16(t0, m3, 0xC0); \ -buf = _mm_shuffle_epi32(t1, _MM_SHUFFLE(3,0,1,2)); - -#define LOAD_MSG_3_4(buf) \ -t0 = _mm_unpacklo_epi32(m0,m2); \ -t1 = _mm_unpackhi_epi32(m1,m2); \ -buf = _mm_unpacklo_epi64(t1,t0); - -#define LOAD_MSG_4_1(buf) \ -t0 = _mm_unpacklo_epi64(m1,m2); \ -t1 = _mm_unpackhi_epi64(m0,m2); \ -t2 = _mm_blend_epi16(t0,t1,0x33); \ -buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(2,0,1,3)); - -#define LOAD_MSG_4_2(buf) \ -t0 = _mm_unpackhi_epi64(m1,m3); \ -t1 = _mm_unpacklo_epi64(m0,m1); \ -buf = _mm_blend_epi16(t0,t1,0x33); - -#define LOAD_MSG_4_3(buf) \ -t0 = _mm_unpackhi_epi64(m3,m1); \ -t1 = _mm_unpackhi_epi64(m2,m0); \ -buf = _mm_blend_epi16(t1,t0,0x33); - -#define LOAD_MSG_4_4(buf) \ -t0 = _mm_blend_epi16(m0,m2,0x03); \ -t1 = _mm_slli_si128(t0, 8); \ -t2 = _mm_blend_epi16(t1,m3,0x0F); \ -buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(1,2,0,3)); - -#define LOAD_MSG_5_1(buf) \ -t0 = _mm_unpackhi_epi32(m0,m1); \ -t1 = _mm_unpacklo_epi32(m0,m2); \ -buf = _mm_unpacklo_epi64(t0,t1); - -#define LOAD_MSG_5_2(buf) \ -t0 = _mm_srli_si128(m2, 4); \ -t1 = _mm_blend_epi16(m0,m3,0x03); \ -buf = _mm_blend_epi16(t1,t0,0x3C); - -#define LOAD_MSG_5_3(buf) \ -t0 = _mm_blend_epi16(m1,m0,0x0C); \ -t1 = _mm_srli_si128(m3, 4); \ -t2 = _mm_blend_epi16(t0,t1,0x30); \ -buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(1,2,3,0)); - -#define LOAD_MSG_5_4(buf) \ -t0 = _mm_unpacklo_epi64(m1,m2); \ -t1= _mm_shuffle_epi32(m3, _MM_SHUFFLE(0,2,0,1)); \ -buf = _mm_blend_epi16(t0,t1,0x33); - -#define LOAD_MSG_6_1(buf) \ -t0 = _mm_slli_si128(m1, 12); \ -t1 = _mm_blend_epi16(m0,m3,0x33); \ -buf = _mm_blend_epi16(t1,t0,0xC0); - -#define LOAD_MSG_6_2(buf) \ -t0 = _mm_blend_epi16(m3,m2,0x30); \ -t1 = _mm_srli_si128(m1, 4); \ -t2 = _mm_blend_epi16(t0,t1,0x03); \ -buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(2,1,3,0)); - -#define LOAD_MSG_6_3(buf) \ -t0 = _mm_unpacklo_epi64(m0,m2); \ -t1 = _mm_srli_si128(m1, 4); \ -buf = _mm_shuffle_epi32(_mm_blend_epi16(t0,t1,0x0C), _MM_SHUFFLE(2,3,1,0)); - -#define LOAD_MSG_6_4(buf) \ -t0 = _mm_unpackhi_epi32(m1,m2); \ -t1 = _mm_unpackhi_epi64(m0,t0); \ -buf = _mm_shuffle_epi32(t1, _MM_SHUFFLE(3,0,1,2)); - -#define LOAD_MSG_7_1(buf) \ -t0 = _mm_unpackhi_epi32(m0,m1); \ -t1 = _mm_blend_epi16(t0,m3,0x0F); \ -buf = _mm_shuffle_epi32(t1,_MM_SHUFFLE(2,0,3,1)); - -#define LOAD_MSG_7_2(buf) \ -t0 = _mm_blend_epi16(m2,m3,0x30); \ -t1 = _mm_srli_si128(m0,4); \ -t2 = _mm_blend_epi16(t0,t1,0x03); \ -buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(1,0,2,3)); - -#define LOAD_MSG_7_3(buf) \ -t0 = _mm_unpackhi_epi64(m0,m3); \ -t1 = _mm_unpacklo_epi64(m1,m2); \ -t2 = _mm_blend_epi16(t0,t1,0x3C); \ -buf = _mm_shuffle_epi32(t2,_MM_SHUFFLE(0,2,3,1)); - -#define LOAD_MSG_7_4(buf) \ -t0 = _mm_unpacklo_epi32(m0,m1); \ -t1 = _mm_unpackhi_epi32(m1,m2); \ -buf = _mm_unpacklo_epi64(t0,t1); - -#define LOAD_MSG_8_1(buf) \ -t0 = _mm_unpackhi_epi32(m1,m3); \ -t1 = _mm_unpacklo_epi64(t0,m0); \ -t2 = _mm_blend_epi16(t1,m2,0xC0); \ -buf = _mm_shufflehi_epi16(t2,_MM_SHUFFLE(1,0,3,2)); - -#define LOAD_MSG_8_2(buf) \ -t0 = _mm_unpackhi_epi32(m0,m3); \ -t1 = _mm_blend_epi16(m2,t0,0xF0); \ -buf = _mm_shuffle_epi32(t1,_MM_SHUFFLE(0,2,1,3)); - -#define LOAD_MSG_8_3(buf) \ -t0 = _mm_blend_epi16(m2,m0,0x0C); \ -t1 = _mm_slli_si128(t0,4); \ -buf = _mm_blend_epi16(t1,m3,0x0F); - -#define LOAD_MSG_8_4(buf) \ -t0 = _mm_blend_epi16(m1,m0,0x30); \ -buf = _mm_shuffle_epi32(t0,_MM_SHUFFLE(1,0,3,2)); - -#define LOAD_MSG_9_1(buf) \ -t0 = _mm_blend_epi16(m0,m2,0x03); \ -t1 = _mm_blend_epi16(m1,m2,0x30); \ -t2 = _mm_blend_epi16(t1,t0,0x0F); \ -buf = _mm_shuffle_epi32(t2,_MM_SHUFFLE(1,3,0,2)); - -#define LOAD_MSG_9_2(buf) \ -t0 = _mm_slli_si128(m0,4); \ -t1 = _mm_blend_epi16(m1,t0,0xC0); \ -buf = _mm_shuffle_epi32(t1,_MM_SHUFFLE(1,2,0,3)); - -#define LOAD_MSG_9_3(buf) \ -t0 = _mm_unpackhi_epi32(m0,m3); \ -t1 = _mm_unpacklo_epi32(m2,m3); \ -t2 = _mm_unpackhi_epi64(t0,t1); \ -buf = _mm_shuffle_epi32(t2,_MM_SHUFFLE(3,0,2,1)); - -#define LOAD_MSG_9_4(buf) \ -t0 = _mm_blend_epi16(m3,m2,0xC0); \ -t1 = _mm_unpacklo_epi32(m0,m3); \ -t2 = _mm_blend_epi16(t0,t1,0x0F); \ -buf = _mm_shuffle_epi32(t2,_MM_SHUFFLE(0,1,2,3)); - -#endif - diff --git a/third_party/python/Modules/_blake2/impl/blake2s-load-xop.h b/third_party/python/Modules/_blake2/impl/blake2s-load-xop.h deleted file mode 100644 index 5377fbc88..000000000 --- a/third_party/python/Modules/_blake2/impl/blake2s-load-xop.h +++ /dev/null @@ -1,194 +0,0 @@ -/* clang-format off */ -/* - BLAKE2 reference source code package - optimized C implementations - - Copyright 2012, Samuel Neves . You may use this under the - terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at - your option. The terms of these licenses can be found at: - - - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 - - OpenSSL license : https://www.openssl.org/source/license.html - - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 - - More information about the BLAKE2 hash function can be found at - https://blake2.net. -*/ -#pragma once -#ifndef __BLAKE2S_LOAD_XOP_H__ -#define __BLAKE2S_LOAD_XOP_H__ - -#define TOB(x) ((x)*4*0x01010101 + 0x03020100) /* ..or not TOB */ - -#if 0 -/* Basic VPPERM emulation, for testing purposes */ -static __m128i _mm_perm_epi8(const __m128i src1, const __m128i src2, const __m128i sel) -{ - const __m128i sixteen = _mm_set1_epi8(16); - const __m128i t0 = _mm_shuffle_epi8(src1, sel); - const __m128i s1 = _mm_shuffle_epi8(src2, _mm_sub_epi8(sel, sixteen)); - const __m128i mask = _mm_or_si128(_mm_cmpeq_epi8(sel, sixteen), - _mm_cmpgt_epi8(sel, sixteen)); /* (>=16) = 0xff : 00 */ - return _mm_blendv_epi8(t0, s1, mask); -} -#endif - -#define LOAD_MSG_0_1(buf) \ -buf = _mm_perm_epi8(m0, m1, _mm_set_epi32(TOB(6),TOB(4),TOB(2),TOB(0)) ); - -#define LOAD_MSG_0_2(buf) \ -buf = _mm_perm_epi8(m0, m1, _mm_set_epi32(TOB(7),TOB(5),TOB(3),TOB(1)) ); - -#define LOAD_MSG_0_3(buf) \ -buf = _mm_perm_epi8(m2, m3, _mm_set_epi32(TOB(6),TOB(4),TOB(2),TOB(0)) ); - -#define LOAD_MSG_0_4(buf) \ -buf = _mm_perm_epi8(m2, m3, _mm_set_epi32(TOB(7),TOB(5),TOB(3),TOB(1)) ); - -#define LOAD_MSG_1_1(buf) \ -t0 = _mm_perm_epi8(m1, m2, _mm_set_epi32(TOB(0),TOB(5),TOB(0),TOB(0)) ); \ -buf = _mm_perm_epi8(t0, m3, _mm_set_epi32(TOB(5),TOB(2),TOB(1),TOB(6)) ); - -#define LOAD_MSG_1_2(buf) \ -t1 = _mm_perm_epi8(m1, m2, _mm_set_epi32(TOB(2),TOB(0),TOB(4),TOB(6)) ); \ -buf = _mm_perm_epi8(t1, m3, _mm_set_epi32(TOB(3),TOB(7),TOB(1),TOB(0)) ); - -#define LOAD_MSG_1_3(buf) \ -t0 = _mm_perm_epi8(m0, m1, _mm_set_epi32(TOB(5),TOB(0),TOB(0),TOB(1)) ); \ -buf = _mm_perm_epi8(t0, m2, _mm_set_epi32(TOB(3),TOB(7),TOB(1),TOB(0)) ); - -#define LOAD_MSG_1_4(buf) \ -t1 = _mm_perm_epi8(m0, m1, _mm_set_epi32(TOB(3),TOB(7),TOB(2),TOB(0)) ); \ -buf = _mm_perm_epi8(t1, m3, _mm_set_epi32(TOB(3),TOB(2),TOB(1),TOB(4)) ); - -#define LOAD_MSG_2_1(buf) \ -t0 = _mm_perm_epi8(m1, m2, _mm_set_epi32(TOB(0),TOB(1),TOB(0),TOB(7)) ); \ -buf = _mm_perm_epi8(t0, m3, _mm_set_epi32(TOB(7),TOB(2),TOB(4),TOB(0)) ); - -#define LOAD_MSG_2_2(buf) \ -t1 = _mm_perm_epi8(m0, m2, _mm_set_epi32(TOB(0),TOB(2),TOB(0),TOB(4)) ); \ -buf = _mm_perm_epi8(t1, m3, _mm_set_epi32(TOB(5),TOB(2),TOB(1),TOB(0)) ); - -#define LOAD_MSG_2_3(buf) \ -t0 = _mm_perm_epi8(m0, m1, _mm_set_epi32(TOB(0),TOB(7),TOB(3),TOB(0)) ); \ -buf = _mm_perm_epi8(t0, m2, _mm_set_epi32(TOB(5),TOB(2),TOB(1),TOB(6)) ); - -#define LOAD_MSG_2_4(buf) \ -t1 = _mm_perm_epi8(m0, m1, _mm_set_epi32(TOB(4),TOB(1),TOB(6),TOB(0)) ); \ -buf = _mm_perm_epi8(t1, m3, _mm_set_epi32(TOB(3),TOB(2),TOB(1),TOB(6)) ); - -#define LOAD_MSG_3_1(buf) \ -t0 = _mm_perm_epi8(m0, m1, _mm_set_epi32(TOB(0),TOB(0),TOB(3),TOB(7)) ); \ -t0 = _mm_perm_epi8(t0, m2, _mm_set_epi32(TOB(7),TOB(2),TOB(1),TOB(0)) ); \ -buf = _mm_perm_epi8(t0, m3, _mm_set_epi32(TOB(3),TOB(5),TOB(1),TOB(0)) ); - -#define LOAD_MSG_3_2(buf) \ -t1 = _mm_perm_epi8(m0, m2, _mm_set_epi32(TOB(0),TOB(0),TOB(1),TOB(5)) ); \ -buf = _mm_perm_epi8(t1, m3, _mm_set_epi32(TOB(6),TOB(4),TOB(1),TOB(0)) ); - -#define LOAD_MSG_3_3(buf) \ -t0 = _mm_perm_epi8(m0, m1, _mm_set_epi32(TOB(0),TOB(4),TOB(5),TOB(2)) ); \ -buf = _mm_perm_epi8(t0, m3, _mm_set_epi32(TOB(7),TOB(2),TOB(1),TOB(0)) ); - -#define LOAD_MSG_3_4(buf) \ -t1 = _mm_perm_epi8(m0, m1, _mm_set_epi32(TOB(0),TOB(0),TOB(0),TOB(6)) ); \ -buf = _mm_perm_epi8(t1, m2, _mm_set_epi32(TOB(4),TOB(2),TOB(6),TOB(0)) ); - -#define LOAD_MSG_4_1(buf) \ -t0 = _mm_perm_epi8(m0, m1, _mm_set_epi32(TOB(0),TOB(2),TOB(5),TOB(0)) ); \ -buf = _mm_perm_epi8(t0, m2, _mm_set_epi32(TOB(6),TOB(2),TOB(1),TOB(5)) ); - -#define LOAD_MSG_4_2(buf) \ -t1 = _mm_perm_epi8(m0, m1, _mm_set_epi32(TOB(0),TOB(4),TOB(7),TOB(0)) ); \ -buf = _mm_perm_epi8(t1, m3, _mm_set_epi32(TOB(7),TOB(2),TOB(1),TOB(0)) ); - -#define LOAD_MSG_4_3(buf) \ -t0 = _mm_perm_epi8(m0, m1, _mm_set_epi32(TOB(3),TOB(6),TOB(0),TOB(0)) ); \ -t0 = _mm_perm_epi8(t0, m2, _mm_set_epi32(TOB(3),TOB(2),TOB(7),TOB(0)) ); \ -buf = _mm_perm_epi8(t0, m3, _mm_set_epi32(TOB(3),TOB(2),TOB(1),TOB(6)) ); - -#define LOAD_MSG_4_4(buf) \ -t1 = _mm_perm_epi8(m0, m2, _mm_set_epi32(TOB(0),TOB(4),TOB(0),TOB(1)) ); \ -buf = _mm_perm_epi8(t1, m3, _mm_set_epi32(TOB(5),TOB(2),TOB(4),TOB(0)) ); - -#define LOAD_MSG_5_1(buf) \ -t0 = _mm_perm_epi8(m0, m1, _mm_set_epi32(TOB(0),TOB(0),TOB(6),TOB(2)) ); \ -buf = _mm_perm_epi8(t0, m2, _mm_set_epi32(TOB(4),TOB(2),TOB(1),TOB(0)) ); - -#define LOAD_MSG_5_2(buf) \ -t1 = _mm_perm_epi8(m0, m2, _mm_set_epi32(TOB(3),TOB(7),TOB(6),TOB(0)) ); \ -buf = _mm_perm_epi8(t1, m3, _mm_set_epi32(TOB(3),TOB(2),TOB(1),TOB(4)) ); - -#define LOAD_MSG_5_3(buf) \ -t0 = _mm_perm_epi8(m0, m1, _mm_set_epi32(TOB(1),TOB(0),TOB(7),TOB(4)) ); \ -buf = _mm_perm_epi8(t0, m3, _mm_set_epi32(TOB(3),TOB(7),TOB(1),TOB(0)) ); - -#define LOAD_MSG_5_4(buf) \ -t1 = _mm_perm_epi8(m1, m2, _mm_set_epi32(TOB(5),TOB(0),TOB(1),TOB(0)) ); \ -buf = _mm_perm_epi8(t1, m3, _mm_set_epi32(TOB(3),TOB(6),TOB(1),TOB(5)) ); - -#define LOAD_MSG_6_1(buf) \ -t0 = _mm_perm_epi8(m0, m1, _mm_set_epi32(TOB(4),TOB(0),TOB(1),TOB(0)) ); \ -buf = _mm_perm_epi8(t0, m3, _mm_set_epi32(TOB(3),TOB(6),TOB(1),TOB(4)) ); - -#define LOAD_MSG_6_2(buf) \ -t1 = _mm_perm_epi8(m1, m2, _mm_set_epi32(TOB(6),TOB(0),TOB(0),TOB(1)) ); \ -buf = _mm_perm_epi8(t1, m3, _mm_set_epi32(TOB(3),TOB(5),TOB(7),TOB(0)) ); - -#define LOAD_MSG_6_3(buf) \ -t0 = _mm_perm_epi8(m0, m1, _mm_set_epi32(TOB(0),TOB(0),TOB(6),TOB(0)) ); \ -buf = _mm_perm_epi8(t0, m2, _mm_set_epi32(TOB(4),TOB(5),TOB(1),TOB(0)) ); - -#define LOAD_MSG_6_4(buf) \ -t1 = _mm_perm_epi8(m0, m1, _mm_set_epi32(TOB(0),TOB(2),TOB(3),TOB(7)) ); \ -buf = _mm_perm_epi8(t1, m2, _mm_set_epi32(TOB(7),TOB(2),TOB(1),TOB(0)) ); - -#define LOAD_MSG_7_1(buf) \ -t0 = _mm_perm_epi8(m0, m1, _mm_set_epi32(TOB(3),TOB(0),TOB(7),TOB(0)) ); \ -buf = _mm_perm_epi8(t0, m3, _mm_set_epi32(TOB(3),TOB(4),TOB(1),TOB(5)) ); - -#define LOAD_MSG_7_2(buf) \ -t1 = _mm_perm_epi8(m0, m2, _mm_set_epi32(TOB(5),TOB(1),TOB(0),TOB(7)) ); \ -buf = _mm_perm_epi8(t1, m3, _mm_set_epi32(TOB(3),TOB(2),TOB(6),TOB(0)) ); - -#define LOAD_MSG_7_3(buf) \ -t0 = _mm_perm_epi8(m0, m1, _mm_set_epi32(TOB(2),TOB(0),TOB(0),TOB(5)) ); \ -t0 = _mm_perm_epi8(t0, m2, _mm_set_epi32(TOB(3),TOB(4),TOB(1),TOB(0)) ); \ -buf = _mm_perm_epi8(t0, m3, _mm_set_epi32(TOB(3),TOB(2),TOB(7),TOB(0)) ); - -#define LOAD_MSG_7_4(buf) \ -t1 = _mm_perm_epi8(m0, m1, _mm_set_epi32(TOB(0),TOB(6),TOB(4),TOB(0)) ); \ -buf = _mm_perm_epi8(t1, m2, _mm_set_epi32(TOB(6),TOB(2),TOB(1),TOB(0)) ); - -#define LOAD_MSG_8_1(buf) \ -t0 = _mm_perm_epi8(m0, m1, _mm_set_epi32(TOB(0),TOB(0),TOB(0),TOB(6)) ); \ -t0 = _mm_perm_epi8(t0, m2, _mm_set_epi32(TOB(3),TOB(7),TOB(1),TOB(0)) ); \ -buf = _mm_perm_epi8(t0, m3, _mm_set_epi32(TOB(3),TOB(2),TOB(6),TOB(0)) ); - -#define LOAD_MSG_8_2(buf) \ -t1 = _mm_perm_epi8(m0, m2, _mm_set_epi32(TOB(4),TOB(3),TOB(5),TOB(0)) ); \ -buf = _mm_perm_epi8(t1, m3, _mm_set_epi32(TOB(3),TOB(2),TOB(1),TOB(7)) ); - -#define LOAD_MSG_8_3(buf) \ -t0 = _mm_perm_epi8(m0, m2, _mm_set_epi32(TOB(6),TOB(1),TOB(0),TOB(0)) ); \ -buf = _mm_perm_epi8(t0, m3, _mm_set_epi32(TOB(3),TOB(2),TOB(5),TOB(4)) ); \ - -#define LOAD_MSG_8_4(buf) \ -buf = _mm_perm_epi8(m0, m1, _mm_set_epi32(TOB(5),TOB(4),TOB(7),TOB(2)) ); - -#define LOAD_MSG_9_1(buf) \ -t0 = _mm_perm_epi8(m0, m1, _mm_set_epi32(TOB(1),TOB(7),TOB(0),TOB(0)) ); \ -buf = _mm_perm_epi8(t0, m2, _mm_set_epi32(TOB(3),TOB(2),TOB(4),TOB(6)) ); - -#define LOAD_MSG_9_2(buf) \ -buf = _mm_perm_epi8(m0, m1, _mm_set_epi32(TOB(5),TOB(6),TOB(4),TOB(2)) ); - -#define LOAD_MSG_9_3(buf) \ -t0 = _mm_perm_epi8(m0, m2, _mm_set_epi32(TOB(0),TOB(3),TOB(5),TOB(0)) ); \ -buf = _mm_perm_epi8(t0, m3, _mm_set_epi32(TOB(5),TOB(2),TOB(1),TOB(7)) ); - -#define LOAD_MSG_9_4(buf) \ -t1 = _mm_perm_epi8(m0, m2, _mm_set_epi32(TOB(0),TOB(0),TOB(0),TOB(7)) ); \ -buf = _mm_perm_epi8(t1, m3, _mm_set_epi32(TOB(3),TOB(4),TOB(6),TOB(0)) ); - -#endif - diff --git a/third_party/python/Modules/_blake2/impl/blake2s-ref.c b/third_party/python/Modules/_blake2/impl/blake2s-ref.c deleted file mode 100644 index d7c6a9901..000000000 --- a/third_party/python/Modules/_blake2/impl/blake2s-ref.c +++ /dev/null @@ -1,408 +0,0 @@ -/* clang-format off */ -/* - BLAKE2 reference source code package - reference C implementations - - Copyright 2012, Samuel Neves . You may use this under the - terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at - your option. The terms of these licenses can be found at: - - - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 - - OpenSSL license : https://www.openssl.org/source/license.html - - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 - - More information about the BLAKE2 hash function can be found at - https://blake2.net. -*/ - -#include "blake2.h" -#include "blake2-impl.h" - -static const uint32_t blake2s_IV[8] = -{ - 0x6A09E667UL, 0xBB67AE85UL, 0x3C6EF372UL, 0xA54FF53AUL, - 0x510E527FUL, 0x9B05688CUL, 0x1F83D9ABUL, 0x5BE0CD19UL -}; - -static const uint8_t blake2s_sigma[10][16] = -{ - { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } , - { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } , - { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 } , - { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 } , - { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 } , - { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 } , - { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 } , - { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 } , - { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 } , - { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 } , -}; - -BLAKE2_LOCAL_INLINE(int) blake2s_set_lastnode( blake2s_state *S ) -{ - S->f[1] = -1; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_clear_lastnode( blake2s_state *S ) -{ - S->f[1] = 0; - return 0; -} - -/* Some helper functions, not necessarily useful */ -BLAKE2_LOCAL_INLINE(int) blake2s_is_lastblock( const blake2s_state *S ) -{ - return S->f[0] != 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_set_lastblock( blake2s_state *S ) -{ - if( S->last_node ) blake2s_set_lastnode( S ); - - S->f[0] = -1; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_clear_lastblock( blake2s_state *S ) -{ - if( S->last_node ) blake2s_clear_lastnode( S ); - - S->f[0] = 0; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_increment_counter( blake2s_state *S, const uint32_t inc ) -{ - S->t[0] += inc; - S->t[1] += ( S->t[0] < inc ); - return 0; -} - -/* Parameter-related functions */ -BLAKE2_LOCAL_INLINE(int) blake2s_param_set_digest_length( blake2s_param *P, const uint8_t digest_length ) -{ - P->digest_length = digest_length; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_param_set_fanout( blake2s_param *P, const uint8_t fanout ) -{ - P->fanout = fanout; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_param_set_max_depth( blake2s_param *P, const uint8_t depth ) -{ - P->depth = depth; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_param_set_leaf_length( blake2s_param *P, const uint32_t leaf_length ) -{ - store32( &P->leaf_length, leaf_length ); - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_param_set_node_offset( blake2s_param *P, const uint64_t node_offset ) -{ - store48( P->node_offset, node_offset ); - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_param_set_node_depth( blake2s_param *P, const uint8_t node_depth ) -{ - P->node_depth = node_depth; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_param_set_inner_length( blake2s_param *P, const uint8_t inner_length ) -{ - P->inner_length = inner_length; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_param_set_salt( blake2s_param *P, const uint8_t salt[BLAKE2S_SALTBYTES] ) -{ - memcpy( P->salt, salt, BLAKE2S_SALTBYTES ); - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_param_set_personal( blake2s_param *P, const uint8_t personal[BLAKE2S_PERSONALBYTES] ) -{ - memcpy( P->personal, personal, BLAKE2S_PERSONALBYTES ); - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_init0( blake2s_state *S ) -{ - int i; - memset( S, 0, sizeof( blake2s_state ) ); - - for( i = 0; i < 8; ++i ) S->h[i] = blake2s_IV[i]; - - return 0; -} - -/* init2 xors IV with input parameter block */ -int blake2s_init_param( blake2s_state *S, const blake2s_param *P ) -{ - const uint32_t *p = ( const uint32_t * )( P ); - size_t i; - - blake2s_init0( S ); - - /* IV XOR ParamBlock */ - for( i = 0; i < 8; ++i ) - S->h[i] ^= load32( &p[i] ); - - return 0; -} - - -/* Sequential blake2s initialization */ -int blake2s_init( blake2s_state *S, const uint8_t outlen ) -{ - blake2s_param P[1]; - - /* Move interval verification here? */ - if ( ( !outlen ) || ( outlen > BLAKE2S_OUTBYTES ) ) return -1; - - P->digest_length = outlen; - P->key_length = 0; - P->fanout = 1; - P->depth = 1; - store32( &P->leaf_length, 0 ); - store48( &P->node_offset, 0 ); - P->node_depth = 0; - P->inner_length = 0; - /* memset(P->reserved, 0, sizeof(P->reserved) ); */ - memset( P->salt, 0, sizeof( P->salt ) ); - memset( P->personal, 0, sizeof( P->personal ) ); - return blake2s_init_param( S, P ); -} - -int blake2s_init_key( blake2s_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ) -{ - blake2s_param P[1]; - - if ( ( !outlen ) || ( outlen > BLAKE2S_OUTBYTES ) ) return -1; - - if ( !key || !keylen || keylen > BLAKE2S_KEYBYTES ) return -1; - - P->digest_length = outlen; - P->key_length = keylen; - P->fanout = 1; - P->depth = 1; - store32( &P->leaf_length, 0 ); - store48( &P->node_offset, 0 ); - P->node_depth = 0; - P->inner_length = 0; - /* memset(P->reserved, 0, sizeof(P->reserved) ); */ - memset( P->salt, 0, sizeof( P->salt ) ); - memset( P->personal, 0, sizeof( P->personal ) ); - - if( blake2s_init_param( S, P ) < 0 ) return -1; - - { - uint8_t block[BLAKE2S_BLOCKBYTES]; - memset( block, 0, BLAKE2S_BLOCKBYTES ); - memcpy( block, key, keylen ); - blake2s_update( S, block, BLAKE2S_BLOCKBYTES ); - secure_zero_memory( block, BLAKE2S_BLOCKBYTES ); /* Burn the key from stack */ - } - return 0; -} - -static int blake2s_compress( blake2s_state *S, const uint8_t block[BLAKE2S_BLOCKBYTES] ) -{ - uint32_t m[16]; - uint32_t v[16]; - size_t i; - - for( i = 0; i < 16; ++i ) - m[i] = load32( block + i * sizeof( m[i] ) ); - - for( i = 0; i < 8; ++i ) - v[i] = S->h[i]; - - v[ 8] = blake2s_IV[0]; - v[ 9] = blake2s_IV[1]; - v[10] = blake2s_IV[2]; - v[11] = blake2s_IV[3]; - v[12] = S->t[0] ^ blake2s_IV[4]; - v[13] = S->t[1] ^ blake2s_IV[5]; - v[14] = S->f[0] ^ blake2s_IV[6]; - v[15] = S->f[1] ^ blake2s_IV[7]; -#define G(r,i,a,b,c,d) \ - do { \ - a = a + b + m[blake2s_sigma[r][2*i+0]]; \ - d = rotr32(d ^ a, 16); \ - c = c + d; \ - b = rotr32(b ^ c, 12); \ - a = a + b + m[blake2s_sigma[r][2*i+1]]; \ - d = rotr32(d ^ a, 8); \ - c = c + d; \ - b = rotr32(b ^ c, 7); \ - } while(0) -#define ROUND(r) \ - do { \ - G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \ - G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \ - G(r,2,v[ 2],v[ 6],v[10],v[14]); \ - G(r,3,v[ 3],v[ 7],v[11],v[15]); \ - G(r,4,v[ 0],v[ 5],v[10],v[15]); \ - G(r,5,v[ 1],v[ 6],v[11],v[12]); \ - G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \ - G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \ - } while(0) - ROUND( 0 ); - ROUND( 1 ); - ROUND( 2 ); - ROUND( 3 ); - ROUND( 4 ); - ROUND( 5 ); - ROUND( 6 ); - ROUND( 7 ); - ROUND( 8 ); - ROUND( 9 ); - - for( i = 0; i < 8; ++i ) - S->h[i] = S->h[i] ^ v[i] ^ v[i + 8]; - -#undef G -#undef ROUND - return 0; -} - - -int blake2s_update( blake2s_state *S, const uint8_t *in, uint64_t inlen ) -{ - while( inlen > 0 ) - { - size_t left = S->buflen; - size_t fill = 2 * BLAKE2S_BLOCKBYTES - left; - - if( inlen > fill ) - { - memcpy( S->buf + left, in, fill ); /* Fill buffer */ - S->buflen += fill; - blake2s_increment_counter( S, BLAKE2S_BLOCKBYTES ); - blake2s_compress( S, S->buf ); /* Compress */ - memcpy( S->buf, S->buf + BLAKE2S_BLOCKBYTES, BLAKE2S_BLOCKBYTES ); /* Shift buffer left */ - S->buflen -= BLAKE2S_BLOCKBYTES; - in += fill; - inlen -= fill; - } - else /* inlen <= fill */ - { - memcpy( S->buf + left, in, (size_t)inlen ); - S->buflen += (size_t)inlen; /* Be lazy, do not compress */ - in += inlen; - inlen -= inlen; - } - } - - return 0; -} - -int blake2s_final( blake2s_state *S, uint8_t *out, uint8_t outlen ) -{ - uint8_t buffer[BLAKE2S_OUTBYTES] = {0}; - int i; - - if( out == NULL || outlen == 0 || outlen > BLAKE2S_OUTBYTES ) - return -1; - - if( blake2s_is_lastblock( S ) ) - return -1; - - - if( S->buflen > BLAKE2S_BLOCKBYTES ) - { - blake2s_increment_counter( S, BLAKE2S_BLOCKBYTES ); - blake2s_compress( S, S->buf ); - S->buflen -= BLAKE2S_BLOCKBYTES; - memmove( S->buf, S->buf + BLAKE2S_BLOCKBYTES, S->buflen ); - } - - blake2s_increment_counter( S, ( uint32_t )S->buflen ); - blake2s_set_lastblock( S ); - memset( S->buf + S->buflen, 0, 2 * BLAKE2S_BLOCKBYTES - S->buflen ); /* Padding */ - blake2s_compress( S, S->buf ); - - for( i = 0; i < 8; ++i ) /* Output full hash to temp buffer */ - store32( buffer + sizeof( S->h[i] ) * i, S->h[i] ); - - memcpy( out, buffer, outlen ); - return 0; -} - -int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ) -{ - blake2s_state S[1]; - - /* Verify parameters */ - if ( NULL == in && inlen > 0 ) return -1; - - if ( NULL == out ) return -1; - - if ( NULL == key && keylen > 0) return -1; - - if( !outlen || outlen > BLAKE2S_OUTBYTES ) return -1; - - if( keylen > BLAKE2S_KEYBYTES ) return -1; - - if( keylen > 0 ) - { - if( blake2s_init_key( S, outlen, key, keylen ) < 0 ) return -1; - } - else - { - if( blake2s_init( S, outlen ) < 0 ) return -1; - } - - blake2s_update( S, ( const uint8_t * )in, inlen ); - blake2s_final( S, out, outlen ); - return 0; -} - -#if defined(SUPERCOP) -int crypto_hash( unsigned char *out, unsigned char *in, unsigned long long inlen ) -{ - return blake2s( out, in, NULL, BLAKE2S_OUTBYTES, inlen, 0 ); -} -#endif - -#if defined(BLAKE2S_SELFTEST) -#include -#include "blake2-kat.h" -int main( int argc, char **argv ) -{ - uint8_t key[BLAKE2S_KEYBYTES]; - uint8_t buf[KAT_LENGTH]; - size_t i; - - for( i = 0; i < BLAKE2S_KEYBYTES; ++i ) - key[i] = ( uint8_t )i; - - for( i = 0; i < KAT_LENGTH; ++i ) - buf[i] = ( uint8_t )i; - - for( i = 0; i < KAT_LENGTH; ++i ) - { - uint8_t hash[BLAKE2S_OUTBYTES]; - blake2s( hash, buf, key, BLAKE2S_OUTBYTES, i, BLAKE2S_KEYBYTES ); - - if( 0 != memcmp( hash, blake2s_keyed_kat[i], BLAKE2S_OUTBYTES ) ) - { - puts( "error" ); - return -1; - } - } - - puts( "ok" ); - return 0; -} -#endif - - diff --git a/third_party/python/Modules/_blake2/impl/blake2s-round.h b/third_party/python/Modules/_blake2/impl/blake2s-round.h deleted file mode 100644 index b6a1f7694..000000000 --- a/third_party/python/Modules/_blake2/impl/blake2s-round.h +++ /dev/null @@ -1,91 +0,0 @@ -/* clang-format off */ -/* - BLAKE2 reference source code package - optimized C implementations - - Copyright 2012, Samuel Neves . You may use this under the - terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at - your option. The terms of these licenses can be found at: - - - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 - - OpenSSL license : https://www.openssl.org/source/license.html - - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 - - More information about the BLAKE2 hash function can be found at - https://blake2.net. -*/ -#pragma once -#ifndef __BLAKE2S_ROUND_H__ -#define __BLAKE2S_ROUND_H__ - -#define LOADU(p) _mm_loadu_si128( (const __m128i *)(p) ) -#define STOREU(p,r) _mm_storeu_si128((__m128i *)(p), r) - -#define TOF(reg) _mm_castsi128_ps((reg)) -#define TOI(reg) _mm_castps_si128((reg)) - -#define LIKELY(x) __builtin_expect((x),1) - - -/* Microarchitecture-specific macros */ -#ifndef HAVE_XOP -#ifdef HAVE_SSSE3 -#define _mm_roti_epi32(r, c) ( \ - (8==-(c)) ? _mm_shuffle_epi8(r,r8) \ - : (16==-(c)) ? _mm_shuffle_epi8(r,r16) \ - : _mm_xor_si128(_mm_srli_epi32( (r), -(c) ),_mm_slli_epi32( (r), 32-(-(c)) )) ) -#else -#define _mm_roti_epi32(r, c) _mm_xor_si128(_mm_srli_epi32( (r), -(c) ),_mm_slli_epi32( (r), 32-(-(c)) )) -#endif -#else -/* ... */ -#endif - - -#define G1(row1,row2,row3,row4,buf) \ - row1 = _mm_add_epi32( _mm_add_epi32( row1, buf), row2 ); \ - row4 = _mm_xor_si128( row4, row1 ); \ - row4 = _mm_roti_epi32(row4, -16); \ - row3 = _mm_add_epi32( row3, row4 ); \ - row2 = _mm_xor_si128( row2, row3 ); \ - row2 = _mm_roti_epi32(row2, -12); - -#define G2(row1,row2,row3,row4,buf) \ - row1 = _mm_add_epi32( _mm_add_epi32( row1, buf), row2 ); \ - row4 = _mm_xor_si128( row4, row1 ); \ - row4 = _mm_roti_epi32(row4, -8); \ - row3 = _mm_add_epi32( row3, row4 ); \ - row2 = _mm_xor_si128( row2, row3 ); \ - row2 = _mm_roti_epi32(row2, -7); - -#define DIAGONALIZE(row1,row2,row3,row4) \ - row4 = _mm_shuffle_epi32( row4, _MM_SHUFFLE(2,1,0,3) ); \ - row3 = _mm_shuffle_epi32( row3, _MM_SHUFFLE(1,0,3,2) ); \ - row2 = _mm_shuffle_epi32( row2, _MM_SHUFFLE(0,3,2,1) ); - -#define UNDIAGONALIZE(row1,row2,row3,row4) \ - row4 = _mm_shuffle_epi32( row4, _MM_SHUFFLE(0,3,2,1) ); \ - row3 = _mm_shuffle_epi32( row3, _MM_SHUFFLE(1,0,3,2) ); \ - row2 = _mm_shuffle_epi32( row2, _MM_SHUFFLE(2,1,0,3) ); - -#if defined(HAVE_XOP) -#include "blake2s-load-xop.h" -#elif defined(HAVE_SSE41) -#include "blake2s-load-sse41.h" -#else -#include "blake2s-load-sse2.h" -#endif - -#define ROUND(r) \ - LOAD_MSG_ ##r ##_1(buf1); \ - G1(row1,row2,row3,row4,buf1); \ - LOAD_MSG_ ##r ##_2(buf2); \ - G2(row1,row2,row3,row4,buf2); \ - DIAGONALIZE(row1,row2,row3,row4); \ - LOAD_MSG_ ##r ##_3(buf3); \ - G1(row1,row2,row3,row4,buf3); \ - LOAD_MSG_ ##r ##_4(buf4); \ - G2(row1,row2,row3,row4,buf4); \ - UNDIAGONALIZE(row1,row2,row3,row4); \ - -#endif - diff --git a/third_party/python/Modules/_blake2/impl/blake2s.c b/third_party/python/Modules/_blake2/impl/blake2s.c deleted file mode 100644 index e79aa5db3..000000000 --- a/third_party/python/Modules/_blake2/impl/blake2s.c +++ /dev/null @@ -1,436 +0,0 @@ -/* clang-format off */ -/* - BLAKE2 reference source code package - optimized C implementations - - Copyright 2012, Samuel Neves . You may use this under the - terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at - your option. The terms of these licenses can be found at: - - - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 - - OpenSSL license : https://www.openssl.org/source/license.html - - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 - - More information about the BLAKE2 hash function can be found at - https://blake2.net. -*/ - -#include -#include -#include - -#include "blake2.h" -#include "blake2-impl.h" - -#include "blake2-config.h" - - -#include -#if defined(HAVE_SSSE3) -#include -#endif -#if defined(HAVE_SSE41) -#include -#endif -#if defined(HAVE_AVX) -#include -#endif -#if defined(HAVE_XOP) -#include -#endif - -#include "blake2s-round.h" - -static const uint32_t blake2s_IV[8] = -{ - 0x6A09E667UL, 0xBB67AE85UL, 0x3C6EF372UL, 0xA54FF53AUL, - 0x510E527FUL, 0x9B05688CUL, 0x1F83D9ABUL, 0x5BE0CD19UL -}; - -static const uint8_t blake2s_sigma[10][16] = -{ - { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } , - { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } , - { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 } , - { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 } , - { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 } , - { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 } , - { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 } , - { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 } , - { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 } , - { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 } , -}; - - -/* Some helper functions, not necessarily useful */ -BLAKE2_LOCAL_INLINE(int) blake2s_set_lastnode( blake2s_state *S ) -{ - S->f[1] = -1; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_clear_lastnode( blake2s_state *S ) -{ - S->f[1] = 0; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_is_lastblock( const blake2s_state *S ) -{ - return S->f[0] != 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_set_lastblock( blake2s_state *S ) -{ - if( S->last_node ) blake2s_set_lastnode( S ); - - S->f[0] = -1; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_clear_lastblock( blake2s_state *S ) -{ - if( S->last_node ) blake2s_clear_lastnode( S ); - - S->f[0] = 0; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_increment_counter( blake2s_state *S, const uint32_t inc ) -{ - uint64_t t = ( ( uint64_t )S->t[1] << 32 ) | S->t[0]; - t += inc; - S->t[0] = ( uint32_t )( t >> 0 ); - S->t[1] = ( uint32_t )( t >> 32 ); - return 0; -} - - -/* Parameter-related functions */ -BLAKE2_LOCAL_INLINE(int) blake2s_param_set_digest_length( blake2s_param *P, const uint8_t digest_length ) -{ - P->digest_length = digest_length; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_param_set_fanout( blake2s_param *P, const uint8_t fanout ) -{ - P->fanout = fanout; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_param_set_max_depth( blake2s_param *P, const uint8_t depth ) -{ - P->depth = depth; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_param_set_leaf_length( blake2s_param *P, const uint32_t leaf_length ) -{ - P->leaf_length = leaf_length; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_param_set_node_offset( blake2s_param *P, const uint64_t node_offset ) -{ - store48( P->node_offset, node_offset ); - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_param_set_node_depth( blake2s_param *P, const uint8_t node_depth ) -{ - P->node_depth = node_depth; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_param_set_inner_length( blake2s_param *P, const uint8_t inner_length ) -{ - P->inner_length = inner_length; - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_param_set_salt( blake2s_param *P, const uint8_t salt[BLAKE2S_SALTBYTES] ) -{ - memcpy( P->salt, salt, BLAKE2S_SALTBYTES ); - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_param_set_personal( blake2s_param *P, const uint8_t personal[BLAKE2S_PERSONALBYTES] ) -{ - memcpy( P->personal, personal, BLAKE2S_PERSONALBYTES ); - return 0; -} - -BLAKE2_LOCAL_INLINE(int) blake2s_init0( blake2s_state *S ) -{ - int i; - memset( S, 0, sizeof( blake2s_state ) ); - - for( i = 0; i < 8; ++i ) S->h[i] = blake2s_IV[i]; - - return 0; -} - -/* init2 xors IV with input parameter block */ -int blake2s_init_param( blake2s_state *S, const blake2s_param *P ) -{ - /*blake2s_init0( S ); */ - const uint8_t * v = ( const uint8_t * )( blake2s_IV ); - const uint8_t * p = ( const uint8_t * )( P ); - uint8_t * h = ( uint8_t * )( S->h ); - int i; - /* IV XOR ParamBlock */ - memset( S, 0, sizeof( blake2s_state ) ); - - for( i = 0; i < BLAKE2S_OUTBYTES; ++i ) h[i] = v[i] ^ p[i]; - - return 0; -} - - -/* Some sort of default parameter block initialization, for sequential blake2s */ -int blake2s_init( blake2s_state *S, const uint8_t outlen ) -{ - const blake2s_param P = - { - outlen, - 0, - 1, - 1, - 0, - {0}, - 0, - 0, - {0}, - {0} - }; - /* Move interval verification here? */ - if ( ( !outlen ) || ( outlen > BLAKE2S_OUTBYTES ) ) return -1; - return blake2s_init_param( S, &P ); -} - - -int blake2s_init_key( blake2s_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ) -{ - const blake2s_param P = - { - outlen, - keylen, - 1, - 1, - 0, - {0}, - 0, - 0, - {0}, - {0} - }; - - /* Move interval verification here? */ - if ( ( !outlen ) || ( outlen > BLAKE2S_OUTBYTES ) ) return -1; - - if ( ( !key ) || ( !keylen ) || keylen > BLAKE2S_KEYBYTES ) return -1; - - if( blake2s_init_param( S, &P ) < 0 ) - return -1; - - { - uint8_t block[BLAKE2S_BLOCKBYTES]; - memset( block, 0, BLAKE2S_BLOCKBYTES ); - memcpy( block, key, keylen ); - blake2s_update( S, block, BLAKE2S_BLOCKBYTES ); - secure_zero_memory( block, BLAKE2S_BLOCKBYTES ); /* Burn the key from stack */ - } - return 0; -} - - -BLAKE2_LOCAL_INLINE(int) blake2s_compress( blake2s_state *S, const uint8_t block[BLAKE2S_BLOCKBYTES] ) -{ - __m128i row1, row2, row3, row4; - __m128i buf1, buf2, buf3, buf4; -#if defined(HAVE_SSE41) - __m128i t0, t1; -#if !defined(HAVE_XOP) - __m128i t2; -#endif -#endif - __m128i ff0, ff1; -#if defined(HAVE_SSSE3) && !defined(HAVE_XOP) - const __m128i r8 = _mm_set_epi8( 12, 15, 14, 13, 8, 11, 10, 9, 4, 7, 6, 5, 0, 3, 2, 1 ); - const __m128i r16 = _mm_set_epi8( 13, 12, 15, 14, 9, 8, 11, 10, 5, 4, 7, 6, 1, 0, 3, 2 ); -#endif -#if defined(HAVE_SSE41) - const __m128i m0 = LOADU( block + 00 ); - const __m128i m1 = LOADU( block + 16 ); - const __m128i m2 = LOADU( block + 32 ); - const __m128i m3 = LOADU( block + 48 ); -#else - const uint32_t m0 = ( ( uint32_t * )block )[ 0]; - const uint32_t m1 = ( ( uint32_t * )block )[ 1]; - const uint32_t m2 = ( ( uint32_t * )block )[ 2]; - const uint32_t m3 = ( ( uint32_t * )block )[ 3]; - const uint32_t m4 = ( ( uint32_t * )block )[ 4]; - const uint32_t m5 = ( ( uint32_t * )block )[ 5]; - const uint32_t m6 = ( ( uint32_t * )block )[ 6]; - const uint32_t m7 = ( ( uint32_t * )block )[ 7]; - const uint32_t m8 = ( ( uint32_t * )block )[ 8]; - const uint32_t m9 = ( ( uint32_t * )block )[ 9]; - const uint32_t m10 = ( ( uint32_t * )block )[10]; - const uint32_t m11 = ( ( uint32_t * )block )[11]; - const uint32_t m12 = ( ( uint32_t * )block )[12]; - const uint32_t m13 = ( ( uint32_t * )block )[13]; - const uint32_t m14 = ( ( uint32_t * )block )[14]; - const uint32_t m15 = ( ( uint32_t * )block )[15]; -#endif - row1 = ff0 = LOADU( &S->h[0] ); - row2 = ff1 = LOADU( &S->h[4] ); - row3 = _mm_setr_epi32( 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A ); - row4 = _mm_xor_si128( _mm_setr_epi32( 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19 ), LOADU( &S->t[0] ) ); - ROUND( 0 ); - ROUND( 1 ); - ROUND( 2 ); - ROUND( 3 ); - ROUND( 4 ); - ROUND( 5 ); - ROUND( 6 ); - ROUND( 7 ); - ROUND( 8 ); - ROUND( 9 ); - STOREU( &S->h[0], _mm_xor_si128( ff0, _mm_xor_si128( row1, row3 ) ) ); - STOREU( &S->h[4], _mm_xor_si128( ff1, _mm_xor_si128( row2, row4 ) ) ); - return 0; -} - -/* inlen now in bytes */ -int blake2s_update( blake2s_state *S, const uint8_t *in, uint64_t inlen ) -{ - while( inlen > 0 ) - { - size_t left = S->buflen; - size_t fill = 2 * BLAKE2S_BLOCKBYTES - left; - - if( inlen > fill ) - { - memcpy( S->buf + left, in, fill ); /* Fill buffer */ - S->buflen += fill; - blake2s_increment_counter( S, BLAKE2S_BLOCKBYTES ); - blake2s_compress( S, S->buf ); /* Compress */ - memcpy( S->buf, S->buf + BLAKE2S_BLOCKBYTES, BLAKE2S_BLOCKBYTES ); /* Shift buffer left */ - S->buflen -= BLAKE2S_BLOCKBYTES; - in += fill; - inlen -= fill; - } - else /* inlen <= fill */ - { - memcpy( S->buf + left, in, inlen ); - S->buflen += inlen; /* Be lazy, do not compress */ - in += inlen; - inlen -= inlen; - } - } - - return 0; -} - -/* Is this correct? */ -int blake2s_final( blake2s_state *S, uint8_t *out, uint8_t outlen ) -{ - uint8_t buffer[BLAKE2S_OUTBYTES] = {0}; - int i; - - if( outlen > BLAKE2S_OUTBYTES ) - return -1; - - if( blake2s_is_lastblock( S ) ) - return -1; - - if( S->buflen > BLAKE2S_BLOCKBYTES ) - { - blake2s_increment_counter( S, BLAKE2S_BLOCKBYTES ); - blake2s_compress( S, S->buf ); - S->buflen -= BLAKE2S_BLOCKBYTES; - memmove( S->buf, S->buf + BLAKE2S_BLOCKBYTES, S->buflen ); - } - - blake2s_increment_counter( S, ( uint32_t )S->buflen ); - blake2s_set_lastblock( S ); - memset( S->buf + S->buflen, 0, 2 * BLAKE2S_BLOCKBYTES - S->buflen ); /* Padding */ - blake2s_compress( S, S->buf ); - - for( i = 0; i < 8; ++i ) /* Output full hash to temp buffer */ - store32( buffer + sizeof( S->h[i] ) * i, S->h[i] ); - - memcpy( out, buffer, outlen ); - return 0; -} - -/* inlen, at least, should be uint64_t. Others can be size_t. */ -int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ) -{ - blake2s_state S[1]; - - /* Verify parameters */ - if ( NULL == in && inlen > 0 ) return -1; - - if ( NULL == out ) return -1; - - if ( NULL == key && keylen > 0) return -1; - - if( !outlen || outlen > BLAKE2S_OUTBYTES ) return -1; - - if( keylen > BLAKE2S_KEYBYTES ) return -1; - - if( keylen > 0 ) - { - if( blake2s_init_key( S, outlen, key, keylen ) < 0 ) return -1; - } - else - { - if( blake2s_init( S, outlen ) < 0 ) return -1; - } - - blake2s_update( S, ( const uint8_t * )in, inlen ); - blake2s_final( S, out, outlen ); - return 0; -} - -#if defined(SUPERCOP) -int crypto_hash( unsigned char *out, unsigned char *in, unsigned long long inlen ) -{ - return blake2s( out, in, NULL, BLAKE2S_OUTBYTES, inlen, 0 ); -} -#endif - -#if defined(BLAKE2S_SELFTEST) -#include -#include "blake2-kat.h" -int main( int argc, char **argv ) -{ - uint8_t key[BLAKE2S_KEYBYTES]; - uint8_t buf[KAT_LENGTH]; - size_t i; - - for( i = 0; i < BLAKE2S_KEYBYTES; ++i ) - key[i] = ( uint8_t )i; - - for( i = 0; i < KAT_LENGTH; ++i ) - buf[i] = ( uint8_t )i; - - for( i = 0; i < KAT_LENGTH; ++i ) - { - uint8_t hash[BLAKE2S_OUTBYTES]; - - if( blake2s( hash, buf, key, BLAKE2S_OUTBYTES, i, BLAKE2S_KEYBYTES ) < 0 || - 0 != memcmp( hash, blake2s_keyed_kat[i], BLAKE2S_OUTBYTES ) ) - { - puts( "error" ); - return -1; - } - } - - puts( "ok" ); - return 0; -} -#endif - - diff --git a/third_party/python/Modules/_codecsmodule.c b/third_party/python/Modules/_codecsmodule.c index cc492f3fe..00ca0570e 100644 --- a/third_party/python/Modules/_codecsmodule.c +++ b/third_party/python/Modules/_codecsmodule.c @@ -1,4 +1,15 @@ +#define PY_SSIZE_T_CLEAN +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/codecs.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/unicodeobject.h" +#include "third_party/python/Include/warnings.h" /* clang-format off */ + /* ------------------------------------------------------------------------ _codecs -- Provides access to the codec registry and the builtin @@ -32,9 +43,6 @@ Copyright (c) Corporation for National Research Initiatives. ------------------------------------------------------------------------ */ -#define PY_SSIZE_T_CLEAN -#include "third_party/python/Include/Python.h" - /*[clinic input] module _codecs [clinic start generated code]*/ diff --git a/third_party/python/Modules/_collectionsmodule.c b/third_party/python/Modules/_collectionsmodule.c index 4897d564b..48456f1ba 100644 --- a/third_party/python/Modules/_collectionsmodule.c +++ b/third_party/python/Modules/_collectionsmodule.c @@ -1,6 +1,19 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" +#include "libc/assert.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/odictobject.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" #include "third_party/python/Include/structmember.h" +/* clang-format off */ /* collections module implementation of a deque() datatype Written and maintained by Raymond D. Hettinger diff --git a/third_party/python/Modules/_cryptmodule.c b/third_party/python/Modules/_cryptmodule.c index 6f1b2f7a3..edfa461a2 100644 --- a/third_party/python/Modules/_cryptmodule.c +++ b/third_party/python/Modules/_cryptmodule.c @@ -1,13 +1,11 @@ +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pymacro.h" /* clang-format off */ + /* cryptmodule.c - by Steve Majewski */ -#include "Python.h" - -#include - -/* Module crypt */ - /*[clinic input] module crypt [clinic start generated code]*/ diff --git a/third_party/python/Modules/_csv.c b/third_party/python/Modules/_csv.c index 936f7787c..2eb56e8bd 100644 --- a/third_party/python/Modules/_csv.c +++ b/third_party/python/Modules/_csv.c @@ -1,3 +1,15 @@ +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/moduleobject.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pystate.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/unicodeobject.h" /* clang-format off */ /* csv module */ @@ -11,10 +23,6 @@ module instead. #define MODULE_VERSION "1.0" -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" - - typedef struct { PyObject *error_obj; /* CSV exception */ PyObject *dialects; /* Dialect registry */ diff --git a/third_party/python/Modules/_ctypes/_ctypes.c b/third_party/python/Modules/_ctypes/_ctypes.c deleted file mode 100644 index 2a44dae02..000000000 --- a/third_party/python/Modules/_ctypes/_ctypes.c +++ /dev/null @@ -1,5617 +0,0 @@ -/* clang-format off */ -/* - ToDo: - - Get rid of the checker (and also the converters) field in PyCFuncPtrObject and - StgDictObject, and replace them by slot functions in StgDictObject. - - think about a buffer-like object (memory? bytes?) - - Should POINTER(c_char) and POINTER(c_wchar) have a .value property? - What about c_char and c_wchar arrays then? - - Add from_mmap, from_file, from_string metaclass methods. - - Maybe we can get away with from_file (calls read) and with a from_buffer - method? - - And what about the to_mmap, to_file, to_str(?) methods? They would clobber - the namespace, probably. So, functions instead? And we already have memmove... -*/ - -/* - -Name methods, members, getsets -============================================================================== - -PyCStructType_Type __new__(), from_address(), __mul__(), from_param() -UnionType_Type __new__(), from_address(), __mul__(), from_param() -PyCPointerType_Type __new__(), from_address(), __mul__(), from_param(), set_type() -PyCArrayType_Type __new__(), from_address(), __mul__(), from_param() -PyCSimpleType_Type __new__(), from_address(), __mul__(), from_param() - -PyCData_Type - Struct_Type __new__(), __init__() - PyCPointer_Type __new__(), __init__(), _as_parameter_, contents - PyCArray_Type __new__(), __init__(), _as_parameter_, __get/setitem__(), __len__() - Simple_Type __new__(), __init__(), _as_parameter_ - -PyCField_Type -PyCStgDict_Type - -============================================================================== - -class methods -------------- - -It has some similarity to the byref() construct compared to pointer() -from_address(addr) - - construct an instance from a given memory block (sharing this memory block) - -from_param(obj) - - typecheck and convert a Python object into a C function call parameter - The result may be an instance of the type, or an integer or tuple - (typecode, value[, obj]) - -instance methods/properties ---------------------------- - -_as_parameter_ - - convert self into a C function call parameter - This is either an integer, or a 3-tuple (typecode, value, obj) - -functions ---------- - -sizeof(cdata) - - return the number of bytes the buffer contains - -sizeof(ctype) - - return the number of bytes the buffer of an instance would contain - -byref(cdata) - -addressof(cdata) - -pointer(cdata) - -POINTER(ctype) - -bytes(cdata) - - return the buffer contents as a sequence of bytes (which is currently a string) - -*/ - -/* - * PyCStgDict_Type - * PyCStructType_Type - * UnionType_Type - * PyCPointerType_Type - * PyCArrayType_Type - * PyCSimpleType_Type - * - * PyCData_Type - * Struct_Type - * Union_Type - * PyCArray_Type - * Simple_Type - * PyCPointer_Type - * PyCField_Type - * - */ - -#define PY_SSIZE_T_CLEAN - -#include "Python.h" -#include "structmember.h" - -#include -#ifdef MS_WIN32 -#include -#include -#ifndef IS_INTRESOURCE -#define IS_INTRESOURCE(x) (((size_t)(x) >> 16) == 0) -#endif -#else -#include "ctypes_dlfcn.h" -#endif -#include "ctypes.h" - -PyObject *PyExc_ArgError; - -/* This dict maps ctypes types to POINTER types */ -PyObject *_ctypes_ptrtype_cache; - -static PyTypeObject Simple_Type; - -/* a callable object used for unpickling */ -static PyObject *_unpickle; - - - -/****************************************************************/ - -typedef struct { - PyObject_HEAD - PyObject *key; - PyObject *dict; -} DictRemoverObject; - -static void -_DictRemover_dealloc(PyObject *myself) -{ - DictRemoverObject *self = (DictRemoverObject *)myself; - Py_XDECREF(self->key); - Py_XDECREF(self->dict); - Py_TYPE(self)->tp_free(myself); -} - -static PyObject * -_DictRemover_call(PyObject *myself, PyObject *args, PyObject *kw) -{ - DictRemoverObject *self = (DictRemoverObject *)myself; - if (self->key && self->dict) { - if (-1 == PyDict_DelItem(self->dict, self->key)) - /* XXX Error context */ - PyErr_WriteUnraisable(Py_None); - Py_CLEAR(self->key); - Py_CLEAR(self->dict); - } - Py_INCREF(Py_None); - return Py_None; -} - -static PyTypeObject DictRemover_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_ctypes.DictRemover", /* tp_name */ - sizeof(DictRemoverObject), /* tp_basicsize */ - 0, /* tp_itemsize */ - _DictRemover_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - _DictRemover_call, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ -/* XXX should participate in GC? */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - "deletes a key from a dictionary", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0, /* tp_free */ -}; - -int -PyDict_SetItemProxy(PyObject *dict, PyObject *key, PyObject *item) -{ - PyObject *obj; - DictRemoverObject *remover; - PyObject *proxy; - int result; - - obj = PyObject_CallObject((PyObject *)&DictRemover_Type, NULL); - if (obj == NULL) - return -1; - - remover = (DictRemoverObject *)obj; - assert(remover->key == NULL); - assert(remover->dict == NULL); - Py_INCREF(key); - remover->key = key; - Py_INCREF(dict); - remover->dict = dict; - - proxy = PyWeakref_NewProxy(item, obj); - Py_DECREF(obj); - if (proxy == NULL) - return -1; - - result = PyDict_SetItem(dict, key, proxy); - Py_DECREF(proxy); - return result; -} - -PyObject * -PyDict_GetItemProxy(PyObject *dict, PyObject *key) -{ - PyObject *result; - PyObject *item = PyDict_GetItem(dict, key); - - if (item == NULL) - return NULL; - if (!PyWeakref_CheckProxy(item)) - return item; - result = PyWeakref_GET_OBJECT(item); - if (result == Py_None) - return NULL; - return result; -} - -/******************************************************************/ - -/* - Allocate a memory block for a pep3118 format string, filled with - a suitable PEP 3118 type code corresponding to the given ctypes - type. Returns NULL on failure, with the error indicator set. - - This produces type codes in the standard size mode (cf. struct module), - since the endianness may need to be swapped to a non-native one - later on. - */ -static char * -_ctypes_alloc_format_string_for_type(char code, int big_endian) -{ - char *result; - char pep_code = '\0'; - - switch (code) { -#if SIZEOF_INT == 2 - case 'i': pep_code = 'h'; break; - case 'I': pep_code = 'H'; break; -#elif SIZEOF_INT == 4 - case 'i': pep_code = 'i'; break; - case 'I': pep_code = 'I'; break; -#elif SIZEOF_INT == 8 - case 'i': pep_code = 'q'; break; - case 'I': pep_code = 'Q'; break; -#else -# error SIZEOF_INT has an unexpected value -#endif /* SIZEOF_INT */ -#if SIZEOF_LONG == 4 - case 'l': pep_code = 'l'; break; - case 'L': pep_code = 'L'; break; -#elif SIZEOF_LONG == 8 - case 'l': pep_code = 'q'; break; - case 'L': pep_code = 'Q'; break; -#else -# error SIZEOF_LONG has an unexpected value -#endif /* SIZEOF_LONG */ -#if SIZEOF__BOOL == 1 - case '?': pep_code = '?'; break; -#elif SIZEOF__BOOL == 2 - case '?': pep_code = 'H'; break; -#elif SIZEOF__BOOL == 4 - case '?': pep_code = 'L'; break; -#elif SIZEOF__BOOL == 8 - case '?': pep_code = 'Q'; break; -#else -# error SIZEOF__BOOL has an unexpected value -#endif /* SIZEOF__BOOL */ - default: - /* The standard-size code is the same as the ctypes one */ - pep_code = code; - break; - } - - result = PyMem_Malloc(3); - if (result == NULL) { - PyErr_NoMemory(); - return NULL; - } - - result[0] = big_endian ? '>' : '<'; - result[1] = pep_code; - result[2] = '\0'; - return result; -} - -/* - Allocate a memory block for a pep3118 format string, copy prefix (if - non-null) and suffix into it. Returns NULL on failure, with the error - indicator set. If called with a suffix of NULL the error indicator must - already be set. - */ -char * -_ctypes_alloc_format_string(const char *prefix, const char *suffix) -{ - size_t len; - char *result; - - if (suffix == NULL) { - assert(PyErr_Occurred()); - return NULL; - } - len = strlen(suffix); - if (prefix) - len += strlen(prefix); - result = PyMem_Malloc(len + 1); - if (result == NULL) { - PyErr_NoMemory(); - return NULL; - } - if (prefix) - strcpy(result, prefix); - else - result[0] = '\0'; - strcat(result, suffix); - return result; -} - -/* - Allocate a memory block for a pep3118 format string, adding - the given prefix (if non-null), an additional shape prefix, and a suffix. - Returns NULL on failure, with the error indicator set. If called with - a suffix of NULL the error indicator must already be set. - */ -char * -_ctypes_alloc_format_string_with_shape(int ndim, const Py_ssize_t *shape, - const char *prefix, const char *suffix) -{ - char *new_prefix; - char *result; - char buf[32]; - Py_ssize_t prefix_len; - int k; - - prefix_len = 32 * ndim + 3; - if (prefix) - prefix_len += strlen(prefix); - new_prefix = PyMem_Malloc(prefix_len); - if (new_prefix == NULL) { - PyErr_NoMemory(); - return NULL; - } - new_prefix[0] = '\0'; - if (prefix) - strcpy(new_prefix, prefix); - if (ndim > 0) { - /* Add the prefix "(shape[0],shape[1],...,shape[ndim-1])" */ - strcat(new_prefix, "("); - for (k = 0; k < ndim; ++k) { - if (k < ndim-1) { - sprintf(buf, "%"PY_FORMAT_SIZE_T"d,", shape[k]); - } else { - sprintf(buf, "%"PY_FORMAT_SIZE_T"d)", shape[k]); - } - strcat(new_prefix, buf); - } - } - result = _ctypes_alloc_format_string(new_prefix, suffix); - PyMem_Free(new_prefix); - return result; -} - -/* - PyCStructType_Type - a meta type/class. Creating a new class using this one as - __metaclass__ will call the constructor StructUnionType_new. It replaces the - tp_dict member with a new instance of StgDict, and initializes the C - accessible fields somehow. -*/ - -static PyCArgObject * -StructUnionType_paramfunc(CDataObject *self) -{ - PyCArgObject *parg; - StgDictObject *stgdict; - - parg = PyCArgObject_new(); - if (parg == NULL) - return NULL; - - parg->tag = 'V'; - stgdict = PyObject_stgdict((PyObject *)self); - assert(stgdict); /* Cannot be NULL for structure/union instances */ - parg->pffi_type = &stgdict->ffi_type_pointer; - /* For structure parameters (by value), parg->value doesn't contain the structure - data itself, instead parg->value.p *points* to the structure's data - See also _ctypes.c, function _call_function_pointer(). - */ - parg->value.p = self->b_ptr; - parg->size = self->b_size; - Py_INCREF(self); - parg->obj = (PyObject *)self; - return parg; -} - -static PyObject * -StructUnionType_new(PyTypeObject *type, PyObject *args, PyObject *kwds, int isStruct) -{ - PyTypeObject *result; - PyObject *fields; - StgDictObject *dict; - - /* create the new instance (which is a class, - since we are a metatype!) */ - result = (PyTypeObject *)PyType_Type.tp_new(type, args, kwds); - if (!result) - return NULL; - - /* keep this for bw compatibility */ - if (PyDict_GetItemString(result->tp_dict, "_abstract_")) - return (PyObject *)result; - - dict = (StgDictObject *)PyObject_CallObject((PyObject *)&PyCStgDict_Type, NULL); - if (!dict) { - Py_DECREF(result); - return NULL; - } - /* replace the class dict by our updated stgdict, which holds info - about storage requirements of the instances */ - if (-1 == PyDict_Update((PyObject *)dict, result->tp_dict)) { - Py_DECREF(result); - Py_DECREF((PyObject *)dict); - return NULL; - } - Py_SETREF(result->tp_dict, (PyObject *)dict); - dict->format = _ctypes_alloc_format_string(NULL, "B"); - if (dict->format == NULL) { - Py_DECREF(result); - return NULL; - } - - dict->paramfunc = StructUnionType_paramfunc; - - fields = PyDict_GetItemString((PyObject *)dict, "_fields_"); - if (!fields) { - StgDictObject *basedict = PyType_stgdict((PyObject *)result->tp_base); - - if (basedict == NULL) - return (PyObject *)result; - /* copy base dict */ - if (-1 == PyCStgDict_clone(dict, basedict)) { - Py_DECREF(result); - return NULL; - } - dict->flags &= ~DICTFLAG_FINAL; /* clear the 'final' flag in the subclass dict */ - basedict->flags |= DICTFLAG_FINAL; /* set the 'final' flag in the baseclass dict */ - return (PyObject *)result; - } - - if (-1 == PyObject_SetAttrString((PyObject *)result, "_fields_", fields)) { - Py_DECREF(result); - return NULL; - } - return (PyObject *)result; -} - -static PyObject * -PyCStructType_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - return StructUnionType_new(type, args, kwds, 1); -} - -static PyObject * -UnionType_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - return StructUnionType_new(type, args, kwds, 0); -} - -static const char from_address_doc[] = -"C.from_address(integer) -> C instance\naccess a C instance at the specified address"; - -static PyObject * -CDataType_from_address(PyObject *type, PyObject *value) -{ - void *buf; - if (!PyLong_Check(value)) { - PyErr_SetString(PyExc_TypeError, - "integer expected"); - return NULL; - } - buf = (void *)PyLong_AsVoidPtr(value); - if (PyErr_Occurred()) - return NULL; - return PyCData_AtAddress(type, buf); -} - -static const char from_buffer_doc[] = -"C.from_buffer(object, offset=0) -> C instance\ncreate a C instance from a writeable buffer"; - -static int -KeepRef(CDataObject *target, Py_ssize_t index, PyObject *keep); - -static PyObject * -CDataType_from_buffer(PyObject *type, PyObject *args) -{ - PyObject *obj; - PyObject *mv; - PyObject *result; - Py_buffer *buffer; - Py_ssize_t offset = 0; - - StgDictObject *dict = PyType_stgdict(type); - if (!dict) { - PyErr_SetString(PyExc_TypeError, "abstract class"); - return NULL; - } - - if (!PyArg_ParseTuple(args, "O|n:from_buffer", &obj, &offset)) - return NULL; - - mv = PyMemoryView_FromObject(obj); - if (mv == NULL) - return NULL; - - buffer = PyMemoryView_GET_BUFFER(mv); - - if (buffer->readonly) { - PyErr_SetString(PyExc_TypeError, - "underlying buffer is not writable"); - Py_DECREF(mv); - return NULL; - } - - if (!PyBuffer_IsContiguous(buffer, 'C')) { - PyErr_SetString(PyExc_TypeError, - "underlying buffer is not C contiguous"); - Py_DECREF(mv); - return NULL; - } - - if (offset < 0) { - PyErr_SetString(PyExc_ValueError, - "offset cannot be negative"); - Py_DECREF(mv); - return NULL; - } - - if (dict->size > buffer->len - offset) { - PyErr_Format(PyExc_ValueError, - "Buffer size too small " - "(%zd instead of at least %zd bytes)", - buffer->len, dict->size + offset); - Py_DECREF(mv); - return NULL; - } - - result = PyCData_AtAddress(type, (char *)buffer->buf + offset); - if (result == NULL) { - Py_DECREF(mv); - return NULL; - } - - if (-1 == KeepRef((CDataObject *)result, -1, mv)) { - Py_DECREF(result); - return NULL; - } - - return result; -} - -static const char from_buffer_copy_doc[] = -"C.from_buffer_copy(object, offset=0) -> C instance\ncreate a C instance from a readable buffer"; - -static PyObject * -GenericPyCData_new(PyTypeObject *type, PyObject *args, PyObject *kwds); - -static PyObject * -CDataType_from_buffer_copy(PyObject *type, PyObject *args) -{ - Py_buffer buffer; - Py_ssize_t offset = 0; - PyObject *result; - StgDictObject *dict = PyType_stgdict(type); - if (!dict) { - PyErr_SetString(PyExc_TypeError, "abstract class"); - return NULL; - } - - if (!PyArg_ParseTuple(args, "y*|n:from_buffer_copy", &buffer, &offset)) - return NULL; - - if (offset < 0) { - PyErr_SetString(PyExc_ValueError, - "offset cannot be negative"); - PyBuffer_Release(&buffer); - return NULL; - } - - if (dict->size > buffer.len - offset) { - PyErr_Format(PyExc_ValueError, - "Buffer size too small (%zd instead of at least %zd bytes)", - buffer.len, dict->size + offset); - PyBuffer_Release(&buffer); - return NULL; - } - - result = GenericPyCData_new((PyTypeObject *)type, NULL, NULL); - if (result != NULL) { - memcpy(((CDataObject *)result)->b_ptr, - (char *)buffer.buf + offset, dict->size); - } - PyBuffer_Release(&buffer); - return result; -} - -static const char in_dll_doc[] = -"C.in_dll(dll, name) -> C instance\naccess a C instance in a dll"; - -static PyObject * -CDataType_in_dll(PyObject *type, PyObject *args) -{ - PyObject *dll; - char *name; - PyObject *obj; - void *handle; - void *address; - - if (!PyArg_ParseTuple(args, "Os:in_dll", &dll, &name)) - return NULL; - - obj = PyObject_GetAttrString(dll, "_handle"); - if (!obj) - return NULL; - if (!PyLong_Check(obj)) { - PyErr_SetString(PyExc_TypeError, - "the _handle attribute of the second argument must be an integer"); - Py_DECREF(obj); - return NULL; - } - handle = (void *)PyLong_AsVoidPtr(obj); - Py_DECREF(obj); - if (PyErr_Occurred()) { - PyErr_SetString(PyExc_ValueError, - "could not convert the _handle attribute to a pointer"); - return NULL; - } - -#ifdef MS_WIN32 - address = (void *)GetProcAddress(handle, name); - if (!address) { - PyErr_Format(PyExc_ValueError, - "symbol '%s' not found", - name); - return NULL; - } -#else - address = (void *)ctypes_dlsym(handle, name); - if (!address) { -#ifdef __CYGWIN__ -/* dlerror() isn't very helpful on cygwin */ - PyErr_Format(PyExc_ValueError, - "symbol '%s' not found", - name); -#else - PyErr_SetString(PyExc_ValueError, ctypes_dlerror()); -#endif - return NULL; - } -#endif - return PyCData_AtAddress(type, address); -} - -static const char from_param_doc[] = -"Convert a Python object into a function call parameter."; - -static PyObject * -CDataType_from_param(PyObject *type, PyObject *value) -{ - PyObject *as_parameter; - int res = PyObject_IsInstance(value, type); - if (res == -1) - return NULL; - if (res) { - Py_INCREF(value); - return value; - } - if (PyCArg_CheckExact(value)) { - PyCArgObject *p = (PyCArgObject *)value; - PyObject *ob = p->obj; - const char *ob_name; - StgDictObject *dict; - dict = PyType_stgdict(type); - - /* If we got a PyCArgObject, we must check if the object packed in it - is an instance of the type's dict->proto */ - if(dict && ob) { - res = PyObject_IsInstance(ob, dict->proto); - if (res == -1) - return NULL; - if (res) { - Py_INCREF(value); - return value; - } - } - ob_name = (ob) ? Py_TYPE(ob)->tp_name : "???"; - PyErr_Format(PyExc_TypeError, - "expected %s instance instead of pointer to %s", - ((PyTypeObject *)type)->tp_name, ob_name); - return NULL; - } - - as_parameter = PyObject_GetAttrString(value, "_as_parameter_"); - if (as_parameter) { - value = CDataType_from_param(type, as_parameter); - Py_DECREF(as_parameter); - return value; - } - PyErr_Format(PyExc_TypeError, - "expected %s instance instead of %s", - ((PyTypeObject *)type)->tp_name, - Py_TYPE(value)->tp_name); - return NULL; -} - -static PyMethodDef CDataType_methods[] = { - { "from_param", CDataType_from_param, METH_O, from_param_doc }, - { "from_address", CDataType_from_address, METH_O, from_address_doc }, - { "from_buffer", CDataType_from_buffer, METH_VARARGS, from_buffer_doc, }, - { "from_buffer_copy", CDataType_from_buffer_copy, METH_VARARGS, from_buffer_copy_doc, }, - { "in_dll", CDataType_in_dll, METH_VARARGS, in_dll_doc }, - { NULL, NULL }, -}; - -static PyObject * -CDataType_repeat(PyObject *self, Py_ssize_t length) -{ - if (length < 0) - return PyErr_Format(PyExc_ValueError, - "Array length must be >= 0, not %zd", - length); - return PyCArrayType_from_ctype(self, length); -} - -static PySequenceMethods CDataType_as_sequence = { - 0, /* inquiry sq_length; */ - 0, /* binaryfunc sq_concat; */ - CDataType_repeat, /* intargfunc sq_repeat; */ - 0, /* intargfunc sq_item; */ - 0, /* intintargfunc sq_slice; */ - 0, /* intobjargproc sq_ass_item; */ - 0, /* intintobjargproc sq_ass_slice; */ - 0, /* objobjproc sq_contains; */ - - 0, /* binaryfunc sq_inplace_concat; */ - 0, /* intargfunc sq_inplace_repeat; */ -}; - -static int -CDataType_clear(PyTypeObject *self) -{ - StgDictObject *dict = PyType_stgdict((PyObject *)self); - if (dict) - Py_CLEAR(dict->proto); - return PyType_Type.tp_clear((PyObject *)self); -} - -static int -CDataType_traverse(PyTypeObject *self, visitproc visit, void *arg) -{ - StgDictObject *dict = PyType_stgdict((PyObject *)self); - if (dict) - Py_VISIT(dict->proto); - return PyType_Type.tp_traverse((PyObject *)self, visit, arg); -} - -static int -PyCStructType_setattro(PyObject *self, PyObject *key, PyObject *value) -{ - /* XXX Should we disallow deleting _fields_? */ - if (-1 == PyType_Type.tp_setattro(self, key, value)) - return -1; - - if (value && PyUnicode_Check(key) && - _PyUnicode_EqualToASCIIString(key, "_fields_")) - return PyCStructUnionType_update_stgdict(self, value, 1); - return 0; -} - - -static int -UnionType_setattro(PyObject *self, PyObject *key, PyObject *value) -{ - /* XXX Should we disallow deleting _fields_? */ - if (-1 == PyObject_GenericSetAttr(self, key, value)) - return -1; - - if (PyUnicode_Check(key) && - _PyUnicode_EqualToASCIIString(key, "_fields_")) - return PyCStructUnionType_update_stgdict(self, value, 0); - return 0; -} - - -PyTypeObject PyCStructType_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_ctypes.PyCStructType", /* tp_name */ - 0, /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - &CDataType_as_sequence, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - PyCStructType_setattro, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ - "metatype for the CData Objects", /* tp_doc */ - (traverseproc)CDataType_traverse, /* tp_traverse */ - (inquiry)CDataType_clear, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - CDataType_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - PyCStructType_new, /* tp_new */ - 0, /* tp_free */ -}; - -static PyTypeObject UnionType_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_ctypes.UnionType", /* tp_name */ - 0, /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - &CDataType_as_sequence, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - UnionType_setattro, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ - "metatype for the CData Objects", /* tp_doc */ - (traverseproc)CDataType_traverse, /* tp_traverse */ - (inquiry)CDataType_clear, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - CDataType_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - UnionType_new, /* tp_new */ - 0, /* tp_free */ -}; - - -/******************************************************************/ - -/* - -The PyCPointerType_Type metaclass must ensure that the subclass of Pointer can be -created. It must check for a _type_ attribute in the class. Since are no -runtime created properties, a CField is probably *not* needed ? - -class IntPointer(Pointer): - _type_ = "i" - -The PyCPointer_Type provides the functionality: a contents method/property, a -size property/method, and the sequence protocol. - -*/ - -static int -PyCPointerType_SetProto(StgDictObject *stgdict, PyObject *proto) -{ - if (!proto || !PyType_Check(proto)) { - PyErr_SetString(PyExc_TypeError, - "_type_ must be a type"); - return -1; - } - if (!PyType_stgdict(proto)) { - PyErr_SetString(PyExc_TypeError, - "_type_ must have storage info"); - return -1; - } - Py_INCREF(proto); - Py_XSETREF(stgdict->proto, proto); - return 0; -} - -static PyCArgObject * -PyCPointerType_paramfunc(CDataObject *self) -{ - PyCArgObject *parg; - - parg = PyCArgObject_new(); - if (parg == NULL) - return NULL; - - parg->tag = 'P'; - parg->pffi_type = &ffi_type_pointer; - Py_INCREF(self); - parg->obj = (PyObject *)self; - parg->value.p = *(void **)self->b_ptr; - return parg; -} - -static PyObject * -PyCPointerType_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyTypeObject *result; - StgDictObject *stgdict; - PyObject *proto; - PyObject *typedict; - - typedict = PyTuple_GetItem(args, 2); - if (!typedict) - return NULL; -/* - stgdict items size, align, length contain info about pointers itself, - stgdict->proto has info about the pointed to type! -*/ - stgdict = (StgDictObject *)PyObject_CallObject( - (PyObject *)&PyCStgDict_Type, NULL); - if (!stgdict) - return NULL; - stgdict->size = sizeof(void *); - stgdict->align = _ctypes_get_fielddesc("P")->pffi_type->alignment; - stgdict->length = 1; - stgdict->ffi_type_pointer = ffi_type_pointer; - stgdict->paramfunc = PyCPointerType_paramfunc; - stgdict->flags |= TYPEFLAG_ISPOINTER; - - proto = PyDict_GetItemString(typedict, "_type_"); /* Borrowed ref */ - if (proto && -1 == PyCPointerType_SetProto(stgdict, proto)) { - Py_DECREF((PyObject *)stgdict); - return NULL; - } - - if (proto) { - StgDictObject *itemdict = PyType_stgdict(proto); - const char *current_format; - /* PyCPointerType_SetProto has verified proto has a stgdict. */ - assert(itemdict); - /* If itemdict->format is NULL, then this is a pointer to an - incomplete type. We create a generic format string - 'pointer to bytes' in this case. XXX Better would be to - fix the format string later... - */ - current_format = itemdict->format ? itemdict->format : "B"; - if (itemdict->shape != NULL) { - /* pointer to an array: the shape needs to be prefixed */ - stgdict->format = _ctypes_alloc_format_string_with_shape( - itemdict->ndim, itemdict->shape, "&", current_format); - } else { - stgdict->format = _ctypes_alloc_format_string("&", current_format); - } - if (stgdict->format == NULL) { - Py_DECREF((PyObject *)stgdict); - return NULL; - } - } - - /* create the new instance (which is a class, - since we are a metatype!) */ - result = (PyTypeObject *)PyType_Type.tp_new(type, args, kwds); - if (result == NULL) { - Py_DECREF((PyObject *)stgdict); - return NULL; - } - - /* replace the class dict by our updated spam dict */ - if (-1 == PyDict_Update((PyObject *)stgdict, result->tp_dict)) { - Py_DECREF(result); - Py_DECREF((PyObject *)stgdict); - return NULL; - } - Py_SETREF(result->tp_dict, (PyObject *)stgdict); - - return (PyObject *)result; -} - - -static PyObject * -PyCPointerType_set_type(PyTypeObject *self, PyObject *type) -{ - StgDictObject *dict; - - dict = PyType_stgdict((PyObject *)self); - if (!dict) { - PyErr_SetString(PyExc_TypeError, - "abstract class"); - return NULL; - } - - if (-1 == PyCPointerType_SetProto(dict, type)) - return NULL; - - if (-1 == PyDict_SetItemString((PyObject *)dict, "_type_", type)) - return NULL; - - Py_INCREF(Py_None); - return Py_None; -} - -static PyObject *_byref(PyObject *); - -static PyObject * -PyCPointerType_from_param(PyObject *type, PyObject *value) -{ - StgDictObject *typedict; - - if (value == Py_None) { - /* ConvParam will convert to a NULL pointer later */ - Py_INCREF(value); - return value; - } - - typedict = PyType_stgdict(type); - if (!typedict) { - PyErr_SetString(PyExc_TypeError, - "abstract class"); - return NULL; - } - - /* If we expect POINTER(), but receive a instance, accept - it by calling byref(). - */ - switch (PyObject_IsInstance(value, typedict->proto)) { - case 1: - Py_INCREF(value); /* _byref steals a refcount */ - return _byref(value); - case -1: - return NULL; - default: - break; - } - - if (PointerObject_Check(value) || ArrayObject_Check(value)) { - /* Array instances are also pointers when - the item types are the same. - */ - StgDictObject *v = PyObject_stgdict(value); - assert(v); /* Cannot be NULL for pointer or array objects */ - if (PyObject_IsSubclass(v->proto, typedict->proto)) { - Py_INCREF(value); - return value; - } - } - return CDataType_from_param(type, value); -} - -static PyMethodDef PyCPointerType_methods[] = { - { "from_address", CDataType_from_address, METH_O, from_address_doc }, - { "from_buffer", CDataType_from_buffer, METH_VARARGS, from_buffer_doc, }, - { "from_buffer_copy", CDataType_from_buffer_copy, METH_VARARGS, from_buffer_copy_doc, }, - { "in_dll", CDataType_in_dll, METH_VARARGS, in_dll_doc}, - { "from_param", (PyCFunction)PyCPointerType_from_param, METH_O, from_param_doc}, - { "set_type", (PyCFunction)PyCPointerType_set_type, METH_O }, - { NULL, NULL }, -}; - -PyTypeObject PyCPointerType_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_ctypes.PyCPointerType", /* tp_name */ - 0, /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - &CDataType_as_sequence, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ - "metatype for the Pointer Objects", /* tp_doc */ - (traverseproc)CDataType_traverse, /* tp_traverse */ - (inquiry)CDataType_clear, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - PyCPointerType_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - PyCPointerType_new, /* tp_new */ - 0, /* tp_free */ -}; - - -/******************************************************************/ -/* - PyCArrayType_Type -*/ -/* - PyCArrayType_new ensures that the new Array subclass created has a _length_ - attribute, and a _type_ attribute. -*/ - -static int -CharArray_set_raw(CDataObject *self, PyObject *value, void *Py_UNUSED(ignored)) -{ - char *ptr; - Py_ssize_t size; - Py_buffer view; - - if (PyObject_GetBuffer(value, &view, PyBUF_SIMPLE) < 0) - return -1; - size = view.len; - ptr = view.buf; - if (size > self->b_size) { - PyErr_SetString(PyExc_ValueError, - "byte string too long"); - goto fail; - } - - memcpy(self->b_ptr, ptr, size); - - PyBuffer_Release(&view); - return 0; - fail: - PyBuffer_Release(&view); - return -1; -} - -static PyObject * -CharArray_get_raw(CDataObject *self, void *Py_UNUSED(ignored)) -{ - return PyBytes_FromStringAndSize(self->b_ptr, self->b_size); -} - -static PyObject * -CharArray_get_value(CDataObject *self, void *Py_UNUSED(ignored)) -{ - Py_ssize_t i; - char *ptr = self->b_ptr; - for (i = 0; i < self->b_size; ++i) - if (*ptr++ == '\0') - break; - return PyBytes_FromStringAndSize(self->b_ptr, i); -} - -static int -CharArray_set_value(CDataObject *self, PyObject *value, void *Py_UNUSED(ignored)) -{ - char *ptr; - Py_ssize_t size; - - if (value == NULL) { - PyErr_SetString(PyExc_TypeError, - "can't delete attribute"); - return -1; - } - - if (!PyBytes_Check(value)) { - PyErr_Format(PyExc_TypeError, - "bytes expected instead of %s instance", - Py_TYPE(value)->tp_name); - return -1; - } else - Py_INCREF(value); - size = PyBytes_GET_SIZE(value); - if (size > self->b_size) { - PyErr_SetString(PyExc_ValueError, - "byte string too long"); - Py_DECREF(value); - return -1; - } - - ptr = PyBytes_AS_STRING(value); - memcpy(self->b_ptr, ptr, size); - if (size < self->b_size) - self->b_ptr[size] = '\0'; - Py_DECREF(value); - - return 0; -} - -static PyGetSetDef CharArray_getsets[] = { - { "raw", (getter)CharArray_get_raw, (setter)CharArray_set_raw, - "value", NULL }, - { "value", (getter)CharArray_get_value, (setter)CharArray_set_value, - "string value"}, - { NULL, NULL } -}; - -#ifdef CTYPES_UNICODE -static PyObject * -WCharArray_get_value(CDataObject *self, void *Py_UNUSED(ignored)) -{ - Py_ssize_t i; - wchar_t *ptr = (wchar_t *)self->b_ptr; - for (i = 0; i < self->b_size/(Py_ssize_t)sizeof(wchar_t); ++i) - if (*ptr++ == (wchar_t)0) - break; - return PyUnicode_FromWideChar((wchar_t *)self->b_ptr, i); -} - -static int -WCharArray_set_value(CDataObject *self, PyObject *value, void *Py_UNUSED(ignored)) -{ - Py_ssize_t result = 0; - Py_UNICODE *wstr; - Py_ssize_t len; - - if (value == NULL) { - PyErr_SetString(PyExc_TypeError, - "can't delete attribute"); - return -1; - } - if (!PyUnicode_Check(value)) { - PyErr_Format(PyExc_TypeError, - "unicode string expected instead of %s instance", - Py_TYPE(value)->tp_name); - return -1; - } else - Py_INCREF(value); - - wstr = PyUnicode_AsUnicodeAndSize(value, &len); - if (wstr == NULL) - return -1; - if ((size_t)len > self->b_size/sizeof(wchar_t)) { - PyErr_SetString(PyExc_ValueError, - "string too long"); - result = -1; - goto done; - } - result = PyUnicode_AsWideChar(value, - (wchar_t *)self->b_ptr, - self->b_size/sizeof(wchar_t)); - if (result >= 0 && (size_t)result < self->b_size/sizeof(wchar_t)) - ((wchar_t *)self->b_ptr)[result] = (wchar_t)0; - done: - Py_DECREF(value); - - return result >= 0 ? 0 : -1; -} - -static PyGetSetDef WCharArray_getsets[] = { - { "value", (getter)WCharArray_get_value, (setter)WCharArray_set_value, - "string value"}, - { NULL, NULL } -}; -#endif - -/* - The next three functions copied from Python's typeobject.c. - - They are used to attach methods, members, or getsets to a type *after* it - has been created: Arrays of characters have additional getsets to treat them - as strings. - */ -/* -static int -add_methods(PyTypeObject *type, PyMethodDef *meth) -{ - PyObject *dict = type->tp_dict; - for (; meth->ml_name != NULL; meth++) { - PyObject *descr; - descr = PyDescr_NewMethod(type, meth); - if (descr == NULL) - return -1; - if (PyDict_SetItemString(dict, meth->ml_name, descr) < 0) { - Py_DECREF(descr); - return -1; - } - Py_DECREF(descr); - } - return 0; -} - -static int -add_members(PyTypeObject *type, PyMemberDef *memb) -{ - PyObject *dict = type->tp_dict; - for (; memb->name != NULL; memb++) { - PyObject *descr; - descr = PyDescr_NewMember(type, memb); - if (descr == NULL) - return -1; - if (PyDict_SetItemString(dict, memb->name, descr) < 0) { - Py_DECREF(descr); - return -1; - } - Py_DECREF(descr); - } - return 0; -} -*/ - -static int -add_getset(PyTypeObject *type, PyGetSetDef *gsp) -{ - PyObject *dict = type->tp_dict; - for (; gsp->name != NULL; gsp++) { - PyObject *descr; - descr = PyDescr_NewGetSet(type, gsp); - if (descr == NULL) - return -1; - if (PyDict_SetItemString(dict, gsp->name, descr) < 0) { - Py_DECREF(descr); - return -1; - } - Py_DECREF(descr); - } - return 0; -} - -static PyCArgObject * -PyCArrayType_paramfunc(CDataObject *self) -{ - PyCArgObject *p = PyCArgObject_new(); - if (p == NULL) - return NULL; - p->tag = 'P'; - p->pffi_type = &ffi_type_pointer; - p->value.p = (char *)self->b_ptr; - Py_INCREF(self); - p->obj = (PyObject *)self; - return p; -} - -static PyObject * -PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyTypeObject *result; - StgDictObject *stgdict; - StgDictObject *itemdict; - PyObject *length_attr, *type_attr; - Py_ssize_t length; - Py_ssize_t itemsize, itemalign; - - /* create the new instance (which is a class, - since we are a metatype!) */ - result = (PyTypeObject *)PyType_Type.tp_new(type, args, kwds); - if (result == NULL) - return NULL; - - /* Initialize these variables to NULL so that we can simplify error - handling by using Py_XDECREF. */ - stgdict = NULL; - type_attr = NULL; - - length_attr = PyObject_GetAttrString((PyObject *)result, "_length_"); - if (!length_attr || !PyLong_Check(length_attr)) { - PyErr_SetString(PyExc_AttributeError, - "class must define a '_length_' attribute, " - "which must be a positive integer"); - Py_XDECREF(length_attr); - goto error; - } - length = PyLong_AsSsize_t(length_attr); - Py_DECREF(length_attr); - if (length == -1 && PyErr_Occurred()) { - if (PyErr_ExceptionMatches(PyExc_OverflowError)) { - PyErr_SetString(PyExc_OverflowError, - "The '_length_' attribute is too large"); - } - goto error; - } - - type_attr = PyObject_GetAttrString((PyObject *)result, "_type_"); - if (!type_attr) { - PyErr_SetString(PyExc_AttributeError, - "class must define a '_type_' attribute"); - goto error; - } - - stgdict = (StgDictObject *)PyObject_CallObject( - (PyObject *)&PyCStgDict_Type, NULL); - if (!stgdict) - goto error; - - itemdict = PyType_stgdict(type_attr); - if (!itemdict) { - PyErr_SetString(PyExc_TypeError, - "_type_ must have storage info"); - goto error; - } - - assert(itemdict->format); - stgdict->format = _ctypes_alloc_format_string(NULL, itemdict->format); - if (stgdict->format == NULL) - goto error; - stgdict->ndim = itemdict->ndim + 1; - stgdict->shape = PyMem_Malloc(sizeof(Py_ssize_t) * stgdict->ndim); - if (stgdict->shape == NULL) { - PyErr_NoMemory(); - goto error; - } - stgdict->shape[0] = length; - if (stgdict->ndim > 1) { - memmove(&stgdict->shape[1], itemdict->shape, - sizeof(Py_ssize_t) * (stgdict->ndim - 1)); - } - - itemsize = itemdict->size; - if (length * itemsize < 0) { - PyErr_SetString(PyExc_OverflowError, - "array too large"); - goto error; - } - - itemalign = itemdict->align; - - if (itemdict->flags & (TYPEFLAG_ISPOINTER | TYPEFLAG_HASPOINTER)) - stgdict->flags |= TYPEFLAG_HASPOINTER; - - stgdict->size = itemsize * length; - stgdict->align = itemalign; - stgdict->length = length; - stgdict->proto = type_attr; - - stgdict->paramfunc = &PyCArrayType_paramfunc; - - /* Arrays are passed as pointers to function calls. */ - stgdict->ffi_type_pointer = ffi_type_pointer; - - /* replace the class dict by our updated spam dict */ - if (-1 == PyDict_Update((PyObject *)stgdict, result->tp_dict)) - goto error; - Py_SETREF(result->tp_dict, (PyObject *)stgdict); /* steal the reference */ - stgdict = NULL; - - /* Special case for character arrays. - A permanent annoyance: char arrays are also strings! - */ - if (itemdict->getfunc == _ctypes_get_fielddesc("c")->getfunc) { - if (-1 == add_getset(result, CharArray_getsets)) - goto error; -#ifdef CTYPES_UNICODE - } else if (itemdict->getfunc == _ctypes_get_fielddesc("u")->getfunc) { - if (-1 == add_getset(result, WCharArray_getsets)) - goto error; -#endif - } - - return (PyObject *)result; -error: - Py_XDECREF((PyObject*)stgdict); - Py_XDECREF(type_attr); - Py_DECREF(result); - return NULL; -} - -PyTypeObject PyCArrayType_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_ctypes.PyCArrayType", /* tp_name */ - 0, /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - &CDataType_as_sequence, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - "metatype for the Array Objects", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - CDataType_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - PyCArrayType_new, /* tp_new */ - 0, /* tp_free */ -}; - - -/******************************************************************/ -/* - PyCSimpleType_Type -*/ -/* - -PyCSimpleType_new ensures that the new Simple_Type subclass created has a valid -_type_ attribute. - -*/ - -static const char SIMPLE_TYPE_CHARS[] = "cbBhHiIlLdfuzZqQPXOv?g"; - -static PyObject * -c_wchar_p_from_param(PyObject *type, PyObject *value) -{ - PyObject *as_parameter; - int res; - if (value == Py_None) { - Py_INCREF(Py_None); - return Py_None; - } - if (PyUnicode_Check(value)) { - PyCArgObject *parg; - struct fielddesc *fd = _ctypes_get_fielddesc("Z"); - - parg = PyCArgObject_new(); - if (parg == NULL) - return NULL; - parg->pffi_type = &ffi_type_pointer; - parg->tag = 'Z'; - parg->obj = fd->setfunc(&parg->value, value, 0); - if (parg->obj == NULL) { - Py_DECREF(parg); - return NULL; - } - return (PyObject *)parg; - } - res = PyObject_IsInstance(value, type); - if (res == -1) - return NULL; - if (res) { - Py_INCREF(value); - return value; - } - if (ArrayObject_Check(value) || PointerObject_Check(value)) { - /* c_wchar array instance or pointer(c_wchar(...)) */ - StgDictObject *dt = PyObject_stgdict(value); - StgDictObject *dict; - assert(dt); /* Cannot be NULL for pointer or array objects */ - dict = dt && dt->proto ? PyType_stgdict(dt->proto) : NULL; - if (dict && (dict->setfunc == _ctypes_get_fielddesc("u")->setfunc)) { - Py_INCREF(value); - return value; - } - } - if (PyCArg_CheckExact(value)) { - /* byref(c_char(...)) */ - PyCArgObject *a = (PyCArgObject *)value; - StgDictObject *dict = PyObject_stgdict(a->obj); - if (dict && (dict->setfunc == _ctypes_get_fielddesc("u")->setfunc)) { - Py_INCREF(value); - return value; - } - } - - as_parameter = PyObject_GetAttrString(value, "_as_parameter_"); - if (as_parameter) { - value = c_wchar_p_from_param(type, as_parameter); - Py_DECREF(as_parameter); - return value; - } - /* XXX better message */ - PyErr_SetString(PyExc_TypeError, - "wrong type"); - return NULL; -} - -static PyObject * -c_char_p_from_param(PyObject *type, PyObject *value) -{ - PyObject *as_parameter; - int res; - if (value == Py_None) { - Py_INCREF(Py_None); - return Py_None; - } - if (PyBytes_Check(value)) { - PyCArgObject *parg; - struct fielddesc *fd = _ctypes_get_fielddesc("z"); - - parg = PyCArgObject_new(); - if (parg == NULL) - return NULL; - parg->pffi_type = &ffi_type_pointer; - parg->tag = 'z'; - parg->obj = fd->setfunc(&parg->value, value, 0); - if (parg->obj == NULL) { - Py_DECREF(parg); - return NULL; - } - return (PyObject *)parg; - } - res = PyObject_IsInstance(value, type); - if (res == -1) - return NULL; - if (res) { - Py_INCREF(value); - return value; - } - if (ArrayObject_Check(value) || PointerObject_Check(value)) { - /* c_char array instance or pointer(c_char(...)) */ - StgDictObject *dt = PyObject_stgdict(value); - StgDictObject *dict; - assert(dt); /* Cannot be NULL for pointer or array objects */ - dict = dt && dt->proto ? PyType_stgdict(dt->proto) : NULL; - if (dict && (dict->setfunc == _ctypes_get_fielddesc("c")->setfunc)) { - Py_INCREF(value); - return value; - } - } - if (PyCArg_CheckExact(value)) { - /* byref(c_char(...)) */ - PyCArgObject *a = (PyCArgObject *)value; - StgDictObject *dict = PyObject_stgdict(a->obj); - if (dict && (dict->setfunc == _ctypes_get_fielddesc("c")->setfunc)) { - Py_INCREF(value); - return value; - } - } - - as_parameter = PyObject_GetAttrString(value, "_as_parameter_"); - if (as_parameter) { - value = c_char_p_from_param(type, as_parameter); - Py_DECREF(as_parameter); - return value; - } - /* XXX better message */ - PyErr_SetString(PyExc_TypeError, - "wrong type"); - return NULL; -} - -static PyObject * -c_void_p_from_param(PyObject *type, PyObject *value) -{ - StgDictObject *stgd; - PyObject *as_parameter; - int res; - -/* None */ - if (value == Py_None) { - Py_INCREF(Py_None); - return Py_None; - } - /* Should probably allow buffer interface as well */ -/* int, long */ - if (PyLong_Check(value)) { - PyCArgObject *parg; - struct fielddesc *fd = _ctypes_get_fielddesc("P"); - - parg = PyCArgObject_new(); - if (parg == NULL) - return NULL; - parg->pffi_type = &ffi_type_pointer; - parg->tag = 'P'; - parg->obj = fd->setfunc(&parg->value, value, 0); - if (parg->obj == NULL) { - Py_DECREF(parg); - return NULL; - } - return (PyObject *)parg; - } - /* XXX struni: remove later */ -/* bytes */ - if (PyBytes_Check(value)) { - PyCArgObject *parg; - struct fielddesc *fd = _ctypes_get_fielddesc("z"); - - parg = PyCArgObject_new(); - if (parg == NULL) - return NULL; - parg->pffi_type = &ffi_type_pointer; - parg->tag = 'z'; - parg->obj = fd->setfunc(&parg->value, value, 0); - if (parg->obj == NULL) { - Py_DECREF(parg); - return NULL; - } - return (PyObject *)parg; - } -/* unicode */ - if (PyUnicode_Check(value)) { - PyCArgObject *parg; - struct fielddesc *fd = _ctypes_get_fielddesc("Z"); - - parg = PyCArgObject_new(); - if (parg == NULL) - return NULL; - parg->pffi_type = &ffi_type_pointer; - parg->tag = 'Z'; - parg->obj = fd->setfunc(&parg->value, value, 0); - if (parg->obj == NULL) { - Py_DECREF(parg); - return NULL; - } - return (PyObject *)parg; - } -/* c_void_p instance (or subclass) */ - res = PyObject_IsInstance(value, type); - if (res == -1) - return NULL; - if (res) { - /* c_void_p instances */ - Py_INCREF(value); - return value; - } -/* ctypes array or pointer instance */ - if (ArrayObject_Check(value) || PointerObject_Check(value)) { - /* Any array or pointer is accepted */ - Py_INCREF(value); - return value; - } -/* byref(...) */ - if (PyCArg_CheckExact(value)) { - /* byref(c_xxx()) */ - PyCArgObject *a = (PyCArgObject *)value; - if (a->tag == 'P') { - Py_INCREF(value); - return value; - } - } -/* function pointer */ - if (PyCFuncPtrObject_Check(value)) { - PyCArgObject *parg; - PyCFuncPtrObject *func; - func = (PyCFuncPtrObject *)value; - parg = PyCArgObject_new(); - if (parg == NULL) - return NULL; - parg->pffi_type = &ffi_type_pointer; - parg->tag = 'P'; - Py_INCREF(value); - parg->value.p = *(void **)func->b_ptr; - parg->obj = value; - return (PyObject *)parg; - } -/* c_char_p, c_wchar_p */ - stgd = PyObject_stgdict(value); - if (stgd && CDataObject_Check(value) && stgd->proto && PyUnicode_Check(stgd->proto)) { - PyCArgObject *parg; - - switch (PyUnicode_AsUTF8(stgd->proto)[0]) { - case 'z': /* c_char_p */ - case 'Z': /* c_wchar_p */ - parg = PyCArgObject_new(); - if (parg == NULL) - return NULL; - parg->pffi_type = &ffi_type_pointer; - parg->tag = 'Z'; - Py_INCREF(value); - parg->obj = value; - /* Remember: b_ptr points to where the pointer is stored! */ - parg->value.p = *(void **)(((CDataObject *)value)->b_ptr); - return (PyObject *)parg; - } - } - - as_parameter = PyObject_GetAttrString(value, "_as_parameter_"); - if (as_parameter) { - value = c_void_p_from_param(type, as_parameter); - Py_DECREF(as_parameter); - return value; - } - /* XXX better message */ - PyErr_SetString(PyExc_TypeError, - "wrong type"); - return NULL; -} - -static PyMethodDef c_void_p_method = { "from_param", c_void_p_from_param, METH_O }; -static PyMethodDef c_char_p_method = { "from_param", c_char_p_from_param, METH_O }; -static PyMethodDef c_wchar_p_method = { "from_param", c_wchar_p_from_param, METH_O }; - -static PyObject *CreateSwappedType(PyTypeObject *type, PyObject *args, PyObject *kwds, - PyObject *proto, struct fielddesc *fmt) -{ - PyTypeObject *result; - StgDictObject *stgdict; - PyObject *name = PyTuple_GET_ITEM(args, 0); - PyObject *newname; - PyObject *swapped_args; - static PyObject *suffix; - Py_ssize_t i; - - swapped_args = PyTuple_New(PyTuple_GET_SIZE(args)); - if (!swapped_args) - return NULL; - - if (suffix == NULL) -#ifdef WORDS_BIGENDIAN - suffix = PyUnicode_InternFromString("_le"); -#else - suffix = PyUnicode_InternFromString("_be"); -#endif - if (suffix == NULL) { - Py_DECREF(swapped_args); - return NULL; - } - - newname = PyUnicode_Concat(name, suffix); - if (newname == NULL) { - Py_DECREF(swapped_args); - return NULL; - } - - PyTuple_SET_ITEM(swapped_args, 0, newname); - for (i=1; iffi_type_pointer = *fmt->pffi_type; - stgdict->align = fmt->pffi_type->alignment; - stgdict->length = 0; - stgdict->size = fmt->pffi_type->size; - stgdict->setfunc = fmt->setfunc_swapped; - stgdict->getfunc = fmt->getfunc_swapped; - - Py_INCREF(proto); - stgdict->proto = proto; - - /* replace the class dict by our updated spam dict */ - if (-1 == PyDict_Update((PyObject *)stgdict, result->tp_dict)) { - Py_DECREF(result); - Py_DECREF((PyObject *)stgdict); - return NULL; - } - Py_SETREF(result->tp_dict, (PyObject *)stgdict); - - return (PyObject *)result; -} - -static PyCArgObject * -PyCSimpleType_paramfunc(CDataObject *self) -{ - StgDictObject *dict; - char *fmt; - PyCArgObject *parg; - struct fielddesc *fd; - - dict = PyObject_stgdict((PyObject *)self); - assert(dict); /* Cannot be NULL for CDataObject instances */ - fmt = PyUnicode_AsUTF8(dict->proto); - assert(fmt); - - fd = _ctypes_get_fielddesc(fmt); - assert(fd); - - parg = PyCArgObject_new(); - if (parg == NULL) - return NULL; - - parg->tag = fmt[0]; - parg->pffi_type = fd->pffi_type; - Py_INCREF(self); - parg->obj = (PyObject *)self; - memcpy(&parg->value, self->b_ptr, self->b_size); - return parg; -} - -static PyObject * -PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyTypeObject *result; - StgDictObject *stgdict; - PyObject *proto; - const char *proto_str; - Py_ssize_t proto_len; - PyMethodDef *ml; - struct fielddesc *fmt; - - /* create the new instance (which is a class, - since we are a metatype!) */ - result = (PyTypeObject *)PyType_Type.tp_new(type, args, kwds); - if (result == NULL) - return NULL; - - proto = PyObject_GetAttrString((PyObject *)result, "_type_"); /* new ref */ - if (!proto) { - PyErr_SetString(PyExc_AttributeError, - "class must define a '_type_' attribute"); - error: - Py_XDECREF(proto); - Py_XDECREF(result); - return NULL; - } - if (PyUnicode_Check(proto)) { - proto_str = PyUnicode_AsUTF8AndSize(proto, &proto_len); - if (!proto_str) - goto error; - } else { - PyErr_SetString(PyExc_TypeError, - "class must define a '_type_' string attribute"); - goto error; - } - if (proto_len != 1) { - PyErr_SetString(PyExc_ValueError, - "class must define a '_type_' attribute " - "which must be a string of length 1"); - goto error; - } - if (!strchr(SIMPLE_TYPE_CHARS, *proto_str)) { - PyErr_Format(PyExc_AttributeError, - "class must define a '_type_' attribute which must be\n" - "a single character string containing one of '%s'.", - SIMPLE_TYPE_CHARS); - goto error; - } - fmt = _ctypes_get_fielddesc(proto_str); - if (fmt == NULL) { - PyErr_Format(PyExc_ValueError, - "_type_ '%s' not supported", proto_str); - goto error; - } - - stgdict = (StgDictObject *)PyObject_CallObject( - (PyObject *)&PyCStgDict_Type, NULL); - if (!stgdict) - goto error; - - stgdict->ffi_type_pointer = *fmt->pffi_type; - stgdict->align = fmt->pffi_type->alignment; - stgdict->length = 0; - stgdict->size = fmt->pffi_type->size; - stgdict->setfunc = fmt->setfunc; - stgdict->getfunc = fmt->getfunc; -#ifdef WORDS_BIGENDIAN - stgdict->format = _ctypes_alloc_format_string_for_type(proto_str[0], 1); -#else - stgdict->format = _ctypes_alloc_format_string_for_type(proto_str[0], 0); -#endif - if (stgdict->format == NULL) { - Py_DECREF(result); - Py_DECREF(proto); - Py_DECREF((PyObject *)stgdict); - return NULL; - } - - stgdict->paramfunc = PyCSimpleType_paramfunc; -/* - if (result->tp_base != &Simple_Type) { - stgdict->setfunc = NULL; - stgdict->getfunc = NULL; - } -*/ - - /* This consumes the refcount on proto which we have */ - stgdict->proto = proto; - - /* replace the class dict by our updated spam dict */ - if (-1 == PyDict_Update((PyObject *)stgdict, result->tp_dict)) { - Py_DECREF(result); - Py_DECREF((PyObject *)stgdict); - return NULL; - } - Py_SETREF(result->tp_dict, (PyObject *)stgdict); - - /* Install from_param class methods in ctypes base classes. - Overrides the PyCSimpleType_from_param generic method. - */ - if (result->tp_base == &Simple_Type) { - switch (*proto_str) { - case 'z': /* c_char_p */ - ml = &c_char_p_method; - stgdict->flags |= TYPEFLAG_ISPOINTER; - break; - case 'Z': /* c_wchar_p */ - ml = &c_wchar_p_method; - stgdict->flags |= TYPEFLAG_ISPOINTER; - break; - case 'P': /* c_void_p */ - ml = &c_void_p_method; - stgdict->flags |= TYPEFLAG_ISPOINTER; - break; - case 's': - case 'X': - case 'O': - ml = NULL; - stgdict->flags |= TYPEFLAG_ISPOINTER; - break; - default: - ml = NULL; - break; - } - - if (ml) { - PyObject *meth; - int x; - meth = PyDescr_NewClassMethod(result, ml); - if (!meth) { - Py_DECREF(result); - return NULL; - } - x = PyDict_SetItemString(result->tp_dict, - ml->ml_name, - meth); - Py_DECREF(meth); - if (x == -1) { - Py_DECREF(result); - return NULL; - } - } - } - - if (type == &PyCSimpleType_Type && fmt->setfunc_swapped && fmt->getfunc_swapped) { - PyObject *swapped = CreateSwappedType(type, args, kwds, - proto, fmt); - StgDictObject *sw_dict; - if (swapped == NULL) { - Py_DECREF(result); - return NULL; - } - sw_dict = PyType_stgdict(swapped); -#ifdef WORDS_BIGENDIAN - PyObject_SetAttrString((PyObject *)result, "__ctype_le__", swapped); - PyObject_SetAttrString((PyObject *)result, "__ctype_be__", (PyObject *)result); - PyObject_SetAttrString(swapped, "__ctype_be__", (PyObject *)result); - PyObject_SetAttrString(swapped, "__ctype_le__", swapped); - /* We are creating the type for the OTHER endian */ - sw_dict->format = _ctypes_alloc_format_string("<", stgdict->format+1); -#else - PyObject_SetAttrString((PyObject *)result, "__ctype_be__", swapped); - PyObject_SetAttrString((PyObject *)result, "__ctype_le__", (PyObject *)result); - PyObject_SetAttrString(swapped, "__ctype_le__", (PyObject *)result); - PyObject_SetAttrString(swapped, "__ctype_be__", swapped); - /* We are creating the type for the OTHER endian */ - sw_dict->format = _ctypes_alloc_format_string(">", stgdict->format+1); -#endif - Py_DECREF(swapped); - if (PyErr_Occurred()) { - Py_DECREF(result); - return NULL; - } - }; - - return (PyObject *)result; -} - -/* - * This is a *class method*. - * Convert a parameter into something that ConvParam can handle. - */ -static PyObject * -PyCSimpleType_from_param(PyObject *type, PyObject *value) -{ - StgDictObject *dict; - char *fmt; - PyCArgObject *parg; - struct fielddesc *fd; - PyObject *as_parameter; - int res; - - /* If the value is already an instance of the requested type, - we can use it as is */ - res = PyObject_IsInstance(value, type); - if (res == -1) - return NULL; - if (res) { - Py_INCREF(value); - return value; - } - - dict = PyType_stgdict(type); - if (!dict) { - PyErr_SetString(PyExc_TypeError, - "abstract class"); - return NULL; - } - - /* I think we can rely on this being a one-character string */ - fmt = PyUnicode_AsUTF8(dict->proto); - assert(fmt); - - fd = _ctypes_get_fielddesc(fmt); - assert(fd); - - parg = PyCArgObject_new(); - if (parg == NULL) - return NULL; - - parg->tag = fmt[0]; - parg->pffi_type = fd->pffi_type; - parg->obj = fd->setfunc(&parg->value, value, 0); - if (parg->obj) - return (PyObject *)parg; - PyErr_Clear(); - Py_DECREF(parg); - - as_parameter = PyObject_GetAttrString(value, "_as_parameter_"); - if (as_parameter) { - if (Py_EnterRecursiveCall("while processing _as_parameter_")) { - Py_DECREF(as_parameter); - return NULL; - } - value = PyCSimpleType_from_param(type, as_parameter); - Py_LeaveRecursiveCall(); - Py_DECREF(as_parameter); - return value; - } - PyErr_SetString(PyExc_TypeError, - "wrong type"); - return NULL; -} - -static PyMethodDef PyCSimpleType_methods[] = { - { "from_param", PyCSimpleType_from_param, METH_O, from_param_doc }, - { "from_address", CDataType_from_address, METH_O, from_address_doc }, - { "from_buffer", CDataType_from_buffer, METH_VARARGS, from_buffer_doc, }, - { "from_buffer_copy", CDataType_from_buffer_copy, METH_VARARGS, from_buffer_copy_doc, }, - { "in_dll", CDataType_in_dll, METH_VARARGS, in_dll_doc}, - { NULL, NULL }, -}; - -PyTypeObject PyCSimpleType_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_ctypes.PyCSimpleType", /* tp_name */ - 0, /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - &CDataType_as_sequence, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - "metatype for the PyCSimpleType Objects", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - PyCSimpleType_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - PyCSimpleType_new, /* tp_new */ - 0, /* tp_free */ -}; - -/******************************************************************/ -/* - PyCFuncPtrType_Type - */ - -static PyObject * -converters_from_argtypes(PyObject *ob) -{ - PyObject *converters; - Py_ssize_t i; - Py_ssize_t nArgs; - - ob = PySequence_Tuple(ob); /* new reference */ - if (!ob) { - PyErr_SetString(PyExc_TypeError, - "_argtypes_ must be a sequence of types"); - return NULL; - } - - nArgs = PyTuple_GET_SIZE(ob); - converters = PyTuple_New(nArgs); - if (!converters) { - Py_DECREF(ob); - return NULL; - } - - /* I have to check if this is correct. Using c_char, which has a size - of 1, will be assumed to be pushed as only one byte! - Aren't these promoted to integers by the C compiler and pushed as 4 bytes? - */ - - for (i = 0; i < nArgs; ++i) { - PyObject *tp = PyTuple_GET_ITEM(ob, i); - PyObject *cnv = PyObject_GetAttrString(tp, "from_param"); - if (!cnv) - goto argtypes_error_1; - PyTuple_SET_ITEM(converters, i, cnv); - } - Py_DECREF(ob); - return converters; - - argtypes_error_1: - Py_XDECREF(converters); - Py_DECREF(ob); - PyErr_Format(PyExc_TypeError, - "item %zd in _argtypes_ has no from_param method", - i+1); - return NULL; -} - -static int -make_funcptrtype_dict(StgDictObject *stgdict) -{ - PyObject *ob; - PyObject *converters = NULL; - - stgdict->align = _ctypes_get_fielddesc("P")->pffi_type->alignment; - stgdict->length = 1; - stgdict->size = sizeof(void *); - stgdict->setfunc = NULL; - stgdict->getfunc = NULL; - stgdict->ffi_type_pointer = ffi_type_pointer; - - ob = PyDict_GetItemString((PyObject *)stgdict, "_flags_"); - if (!ob || !PyLong_Check(ob)) { - PyErr_SetString(PyExc_TypeError, - "class must define _flags_ which must be an integer"); - return -1; - } - stgdict->flags = PyLong_AS_LONG(ob) | TYPEFLAG_ISPOINTER; - - /* _argtypes_ is optional... */ - ob = PyDict_GetItemString((PyObject *)stgdict, "_argtypes_"); - if (ob) { - converters = converters_from_argtypes(ob); - if (!converters) - goto error; - Py_INCREF(ob); - stgdict->argtypes = ob; - stgdict->converters = converters; - } - - ob = PyDict_GetItemString((PyObject *)stgdict, "_restype_"); - if (ob) { - if (ob != Py_None && !PyType_stgdict(ob) && !PyCallable_Check(ob)) { - PyErr_SetString(PyExc_TypeError, - "_restype_ must be a type, a callable, or None"); - return -1; - } - Py_INCREF(ob); - stgdict->restype = ob; - stgdict->checker = PyObject_GetAttrString(ob, "_check_retval_"); - if (stgdict->checker == NULL) - PyErr_Clear(); - } -/* XXX later, maybe. - ob = PyDict_GetItemString((PyObject *)stgdict, "_errcheck_"); - if (ob) { - if (!PyCallable_Check(ob)) { - PyErr_SetString(PyExc_TypeError, - "_errcheck_ must be callable"); - return -1; - } - Py_INCREF(ob); - stgdict->errcheck = ob; - } -*/ - return 0; - - error: - Py_XDECREF(converters); - return -1; - -} - -static PyCArgObject * -PyCFuncPtrType_paramfunc(CDataObject *self) -{ - PyCArgObject *parg; - - parg = PyCArgObject_new(); - if (parg == NULL) - return NULL; - - parg->tag = 'P'; - parg->pffi_type = &ffi_type_pointer; - Py_INCREF(self); - parg->obj = (PyObject *)self; - parg->value.p = *(void **)self->b_ptr; - return parg; -} - -static PyObject * -PyCFuncPtrType_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyTypeObject *result; - StgDictObject *stgdict; - - stgdict = (StgDictObject *)PyObject_CallObject( - (PyObject *)&PyCStgDict_Type, NULL); - if (!stgdict) - return NULL; - - stgdict->paramfunc = PyCFuncPtrType_paramfunc; - /* We do NOT expose the function signature in the format string. It - is impossible, generally, because the only requirement for the - argtypes items is that they have a .from_param method - we do not - know the types of the arguments (although, in practice, most - argtypes would be a ctypes type). - */ - stgdict->format = _ctypes_alloc_format_string(NULL, "X{}"); - if (stgdict->format == NULL) { - Py_DECREF((PyObject *)stgdict); - return NULL; - } - stgdict->flags |= TYPEFLAG_ISPOINTER; - - /* create the new instance (which is a class, - since we are a metatype!) */ - result = (PyTypeObject *)PyType_Type.tp_new(type, args, kwds); - if (result == NULL) { - Py_DECREF((PyObject *)stgdict); - return NULL; - } - - /* replace the class dict by our updated storage dict */ - if (-1 == PyDict_Update((PyObject *)stgdict, result->tp_dict)) { - Py_DECREF(result); - Py_DECREF((PyObject *)stgdict); - return NULL; - } - Py_SETREF(result->tp_dict, (PyObject *)stgdict); - - if (-1 == make_funcptrtype_dict(stgdict)) { - Py_DECREF(result); - return NULL; - } - - return (PyObject *)result; -} - -PyTypeObject PyCFuncPtrType_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_ctypes.PyCFuncPtrType", /* tp_name */ - 0, /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - &CDataType_as_sequence, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ - "metatype for C function pointers", /* tp_doc */ - (traverseproc)CDataType_traverse, /* tp_traverse */ - (inquiry)CDataType_clear, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - CDataType_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - PyCFuncPtrType_new, /* tp_new */ - 0, /* tp_free */ -}; - - -/***************************************************************** - * Code to keep needed objects alive - */ - -static CDataObject * -PyCData_GetContainer(CDataObject *self) -{ - while (self->b_base) - self = self->b_base; - if (self->b_objects == NULL) { - if (self->b_length) { - self->b_objects = PyDict_New(); - if (self->b_objects == NULL) - return NULL; - } else { - Py_INCREF(Py_None); - self->b_objects = Py_None; - } - } - return self; -} - -static PyObject * -GetKeepedObjects(CDataObject *target) -{ - CDataObject *container; - container = PyCData_GetContainer(target); - if (container == NULL) - return NULL; - return container->b_objects; -} - -static PyObject * -unique_key(CDataObject *target, Py_ssize_t index) -{ - char string[256]; - char *cp = string; - size_t bytes_left; - - Py_BUILD_ASSERT(sizeof(string) - 1 > sizeof(Py_ssize_t) * 2); - cp += sprintf(cp, "%x", Py_SAFE_DOWNCAST(index, Py_ssize_t, int)); - while (target->b_base) { - bytes_left = sizeof(string) - (cp - string) - 1; - /* Hex format needs 2 characters per byte */ - if (bytes_left < sizeof(Py_ssize_t) * 2) { - PyErr_SetString(PyExc_ValueError, - "ctypes object structure too deep"); - return NULL; - } - cp += sprintf(cp, ":%x", Py_SAFE_DOWNCAST(target->b_index, Py_ssize_t, int)); - target = target->b_base; - } - return PyUnicode_FromStringAndSize(string, cp-string); -} - -/* - * Keep a reference to 'keep' in the 'target', at index 'index'. - * - * If 'keep' is None, do nothing. - * - * Otherwise create a dictionary (if it does not yet exist) id the root - * objects 'b_objects' item, which will store the 'keep' object under a unique - * key. - * - * The unique_key helper travels the target's b_base pointer down to the root, - * building a string containing hex-formatted indexes found during traversal, - * separated by colons. - * - * The index tuple is used as a key into the root object's b_objects dict. - * - * Note: This function steals a refcount of the third argument, even if it - * fails! - */ -static int -KeepRef(CDataObject *target, Py_ssize_t index, PyObject *keep) -{ - int result; - CDataObject *ob; - PyObject *key; - -/* Optimization: no need to store None */ - if (keep == Py_None) { - Py_DECREF(Py_None); - return 0; - } - ob = PyCData_GetContainer(target); - if (ob == NULL) { - Py_DECREF(keep); - return -1; - } - if (ob->b_objects == NULL || !PyDict_CheckExact(ob->b_objects)) { - Py_XSETREF(ob->b_objects, keep); /* refcount consumed */ - return 0; - } - key = unique_key(target, index); - if (key == NULL) { - Py_DECREF(keep); - return -1; - } - result = PyDict_SetItem(ob->b_objects, key, keep); - Py_DECREF(key); - Py_DECREF(keep); - return result; -} - -/******************************************************************/ -/* - PyCData_Type - */ -static int -PyCData_traverse(CDataObject *self, visitproc visit, void *arg) -{ - Py_VISIT(self->b_objects); - Py_VISIT((PyObject *)self->b_base); - return 0; -} - -static int -PyCData_clear(CDataObject *self) -{ - Py_CLEAR(self->b_objects); - if ((self->b_needsfree) - && _CDataObject_HasExternalBuffer(self)) - PyMem_Free(self->b_ptr); - self->b_ptr = NULL; - Py_CLEAR(self->b_base); - return 0; -} - -static void -PyCData_dealloc(PyObject *self) -{ - PyCData_clear((CDataObject *)self); - Py_TYPE(self)->tp_free(self); -} - -static PyMemberDef PyCData_members[] = { - { "_b_base_", T_OBJECT, - offsetof(CDataObject, b_base), READONLY, - "the base object" }, - { "_b_needsfree_", T_INT, - offsetof(CDataObject, b_needsfree), READONLY, - "whether the object owns the memory or not" }, - { "_objects", T_OBJECT, - offsetof(CDataObject, b_objects), READONLY, - "internal objects tree (NEVER CHANGE THIS OBJECT!)"}, - { NULL }, -}; - -static int PyCData_NewGetBuffer(PyObject *myself, Py_buffer *view, int flags) -{ - CDataObject *self = (CDataObject *)myself; - StgDictObject *dict = PyObject_stgdict(myself); - Py_ssize_t i; - - if (view == NULL) return 0; - - view->buf = self->b_ptr; - view->obj = myself; - Py_INCREF(myself); - view->len = self->b_size; - view->readonly = 0; - /* use default format character if not set */ - view->format = dict->format ? dict->format : "B"; - view->ndim = dict->ndim; - view->shape = dict->shape; - view->itemsize = self->b_size; - if (view->itemsize) { - for (i = 0; i < view->ndim; ++i) { - view->itemsize /= dict->shape[i]; - } - } - view->strides = NULL; - view->suboffsets = NULL; - view->internal = NULL; - return 0; -} - -static PyBufferProcs PyCData_as_buffer = { - PyCData_NewGetBuffer, - NULL, -}; - -/* - * CData objects are mutable, so they cannot be hashable! - */ -static Py_hash_t -PyCData_nohash(PyObject *self) -{ - PyErr_SetString(PyExc_TypeError, "unhashable type"); - return -1; -} - -static PyObject * -PyCData_reduce(PyObject *myself, PyObject *args) -{ - CDataObject *self = (CDataObject *)myself; - - if (PyObject_stgdict(myself)->flags & (TYPEFLAG_ISPOINTER|TYPEFLAG_HASPOINTER)) { - PyErr_SetString(PyExc_ValueError, - "ctypes objects containing pointers cannot be pickled"); - return NULL; - } - return Py_BuildValue("O(O(NN))", - _unpickle, - Py_TYPE(myself), - PyObject_GetAttrString(myself, "__dict__"), - PyBytes_FromStringAndSize(self->b_ptr, self->b_size)); -} - -static PyObject * -PyCData_setstate(PyObject *myself, PyObject *args) -{ - void *data; - Py_ssize_t len; - int res; - PyObject *dict, *mydict; - CDataObject *self = (CDataObject *)myself; - if (!PyArg_ParseTuple(args, "Os#", &dict, &data, &len)) - return NULL; - if (len > self->b_size) - len = self->b_size; - memmove(self->b_ptr, data, len); - mydict = PyObject_GetAttrString(myself, "__dict__"); - if (mydict == NULL) { - return NULL; - } - if (!PyDict_Check(mydict)) { - PyErr_Format(PyExc_TypeError, - "%.200s.__dict__ must be a dictionary, not %.200s", - Py_TYPE(myself)->tp_name, Py_TYPE(mydict)->tp_name); - Py_DECREF(mydict); - return NULL; - } - res = PyDict_Update(mydict, dict); - Py_DECREF(mydict); - if (res == -1) - return NULL; - Py_INCREF(Py_None); - return Py_None; -} - -/* - * default __ctypes_from_outparam__ method returns self. - */ -static PyObject * -PyCData_from_outparam(PyObject *self, PyObject *args) -{ - Py_INCREF(self); - return self; -} - -static PyMethodDef PyCData_methods[] = { - { "__ctypes_from_outparam__", PyCData_from_outparam, METH_NOARGS, }, - { "__reduce__", PyCData_reduce, METH_NOARGS, }, - { "__setstate__", PyCData_setstate, METH_VARARGS, }, - { NULL, NULL }, -}; - -PyTypeObject PyCData_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_ctypes._CData", - sizeof(CDataObject), /* tp_basicsize */ - 0, /* tp_itemsize */ - PyCData_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - PyCData_nohash, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - &PyCData_as_buffer, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - "XXX to be provided", /* tp_doc */ - (traverseproc)PyCData_traverse, /* tp_traverse */ - (inquiry)PyCData_clear, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - PyCData_methods, /* tp_methods */ - PyCData_members, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0, /* tp_free */ -}; - -static int PyCData_MallocBuffer(CDataObject *obj, StgDictObject *dict) -{ - if ((size_t)dict->size <= sizeof(obj->b_value)) { - /* No need to call malloc, can use the default buffer */ - obj->b_ptr = (char *)&obj->b_value; - /* The b_needsfree flag does not mean that we actually did - call PyMem_Malloc to allocate the memory block; instead it - means we are the *owner* of the memory and are responsible - for freeing resources associated with the memory. This is - also the reason that b_needsfree is exposed to Python. - */ - obj->b_needsfree = 1; - } else { - /* In python 2.4, and ctypes 0.9.6, the malloc call took about - 33% of the creation time for c_int(). - */ - obj->b_ptr = (char *)PyMem_Malloc(dict->size); - if (obj->b_ptr == NULL) { - PyErr_NoMemory(); - return -1; - } - obj->b_needsfree = 1; - memset(obj->b_ptr, 0, dict->size); - } - obj->b_size = dict->size; - return 0; -} - -PyObject * -PyCData_FromBaseObj(PyObject *type, PyObject *base, Py_ssize_t index, char *adr) -{ - CDataObject *cmem; - StgDictObject *dict; - - assert(PyType_Check(type)); - dict = PyType_stgdict(type); - if (!dict) { - PyErr_SetString(PyExc_TypeError, - "abstract class"); - return NULL; - } - dict->flags |= DICTFLAG_FINAL; - cmem = (CDataObject *)((PyTypeObject *)type)->tp_alloc((PyTypeObject *)type, 0); - if (cmem == NULL) - return NULL; - assert(CDataObject_Check(cmem)); - - cmem->b_length = dict->length; - cmem->b_size = dict->size; - if (base) { /* use base's buffer */ - assert(CDataObject_Check(base)); - cmem->b_ptr = adr; - cmem->b_needsfree = 0; - Py_INCREF(base); - cmem->b_base = (CDataObject *)base; - cmem->b_index = index; - } else { /* copy contents of adr */ - if (-1 == PyCData_MallocBuffer(cmem, dict)) { - Py_DECREF(cmem); - return NULL; - } - memcpy(cmem->b_ptr, adr, dict->size); - cmem->b_index = index; - } - return (PyObject *)cmem; -} - -/* - Box a memory block into a CData instance. -*/ -PyObject * -PyCData_AtAddress(PyObject *type, void *buf) -{ - CDataObject *pd; - StgDictObject *dict; - - assert(PyType_Check(type)); - dict = PyType_stgdict(type); - if (!dict) { - PyErr_SetString(PyExc_TypeError, - "abstract class"); - return NULL; - } - dict->flags |= DICTFLAG_FINAL; - - pd = (CDataObject *)((PyTypeObject *)type)->tp_alloc((PyTypeObject *)type, 0); - if (!pd) - return NULL; - assert(CDataObject_Check(pd)); - pd->b_ptr = (char *)buf; - pd->b_length = dict->length; - pd->b_size = dict->size; - return (PyObject *)pd; -} - -/* - This function returns TRUE for c_int, c_void_p, and these kind of - classes. FALSE otherwise FALSE also for subclasses of c_int and - such. -*/ -int _ctypes_simple_instance(PyObject *obj) -{ - PyTypeObject *type = (PyTypeObject *)obj; - - if (PyCSimpleTypeObject_Check(type)) - return type->tp_base != &Simple_Type; - return 0; -} - -PyObject * -PyCData_get(PyObject *type, GETFUNC getfunc, PyObject *src, - Py_ssize_t index, Py_ssize_t size, char *adr) -{ - StgDictObject *dict; - if (getfunc) - return getfunc(adr, size); - assert(type); - dict = PyType_stgdict(type); - if (dict && dict->getfunc && !_ctypes_simple_instance(type)) - return dict->getfunc(adr, size); - return PyCData_FromBaseObj(type, src, index, adr); -} - -/* - Helper function for PyCData_set below. -*/ -static PyObject * -_PyCData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value, - Py_ssize_t size, char *ptr) -{ - CDataObject *src; - int err; - - if (setfunc) - return setfunc(ptr, value, size); - - if (!CDataObject_Check(value)) { - StgDictObject *dict = PyType_stgdict(type); - if (dict && dict->setfunc) - return dict->setfunc(ptr, value, size); - /* - If value is a tuple, we try to call the type with the tuple - and use the result! - */ - assert(PyType_Check(type)); - if (PyTuple_Check(value)) { - PyObject *ob; - PyObject *result; - ob = PyObject_CallObject(type, value); - if (ob == NULL) { - _ctypes_extend_error(PyExc_RuntimeError, "(%s) ", - ((PyTypeObject *)type)->tp_name); - return NULL; - } - result = _PyCData_set(dst, type, setfunc, ob, - size, ptr); - Py_DECREF(ob); - return result; - } else if (value == Py_None && PyCPointerTypeObject_Check(type)) { - *(void **)ptr = NULL; - Py_INCREF(Py_None); - return Py_None; - } else { - PyErr_Format(PyExc_TypeError, - "expected %s instance, got %s", - ((PyTypeObject *)type)->tp_name, - Py_TYPE(value)->tp_name); - return NULL; - } - } - src = (CDataObject *)value; - - err = PyObject_IsInstance(value, type); - if (err == -1) - return NULL; - if (err) { - memcpy(ptr, - src->b_ptr, - size); - - if (PyCPointerTypeObject_Check(type)) { - /* XXX */ - } - - value = GetKeepedObjects(src); - if (value == NULL) - return NULL; - - Py_INCREF(value); - return value; - } - - if (PyCPointerTypeObject_Check(type) - && ArrayObject_Check(value)) { - StgDictObject *p1, *p2; - PyObject *keep; - p1 = PyObject_stgdict(value); - assert(p1); /* Cannot be NULL for array instances */ - p2 = PyType_stgdict(type); - assert(p2); /* Cannot be NULL for pointer types */ - - if (p1->proto != p2->proto) { - PyErr_Format(PyExc_TypeError, - "incompatible types, %s instance instead of %s instance", - Py_TYPE(value)->tp_name, - ((PyTypeObject *)type)->tp_name); - return NULL; - } - *(void **)ptr = src->b_ptr; - - keep = GetKeepedObjects(src); - if (keep == NULL) - return NULL; - - /* - We are assigning an array object to a field which represents - a pointer. This has the same effect as converting an array - into a pointer. So, again, we have to keep the whole object - pointed to (which is the array in this case) alive, and not - only it's object list. So we create a tuple, containing - b_objects list PLUS the array itself, and return that! - */ - return PyTuple_Pack(2, keep, value); - } - PyErr_Format(PyExc_TypeError, - "incompatible types, %s instance instead of %s instance", - Py_TYPE(value)->tp_name, - ((PyTypeObject *)type)->tp_name); - return NULL; -} - -/* - * Set a slice in object 'dst', which has the type 'type', - * to the value 'value'. - */ -int -PyCData_set(PyObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value, - Py_ssize_t index, Py_ssize_t size, char *ptr) -{ - CDataObject *mem = (CDataObject *)dst; - PyObject *result; - - if (!CDataObject_Check(dst)) { - PyErr_SetString(PyExc_TypeError, - "not a ctype instance"); - return -1; - } - - result = _PyCData_set(mem, type, setfunc, value, - size, ptr); - if (result == NULL) - return -1; - - /* KeepRef steals a refcount from it's last argument */ - /* If KeepRef fails, we are stumped. The dst memory block has already - been changed */ - return KeepRef(mem, index, result); -} - - -/******************************************************************/ -static PyObject * -GenericPyCData_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - CDataObject *obj; - StgDictObject *dict; - - dict = PyType_stgdict((PyObject *)type); - if (!dict) { - PyErr_SetString(PyExc_TypeError, - "abstract class"); - return NULL; - } - dict->flags |= DICTFLAG_FINAL; - - obj = (CDataObject *)type->tp_alloc(type, 0); - if (!obj) - return NULL; - - obj->b_base = NULL; - obj->b_index = 0; - obj->b_objects = NULL; - obj->b_length = dict->length; - - if (-1 == PyCData_MallocBuffer(obj, dict)) { - Py_DECREF(obj); - return NULL; - } - return (PyObject *)obj; -} -/*****************************************************************/ -/* - PyCFuncPtr_Type -*/ - -static int -PyCFuncPtr_set_errcheck(PyCFuncPtrObject *self, PyObject *ob, void *Py_UNUSED(ignored)) -{ - if (ob && !PyCallable_Check(ob)) { - PyErr_SetString(PyExc_TypeError, - "the errcheck attribute must be callable"); - return -1; - } - Py_XINCREF(ob); - Py_XSETREF(self->errcheck, ob); - return 0; -} - -static PyObject * -PyCFuncPtr_get_errcheck(PyCFuncPtrObject *self, void *Py_UNUSED(ignored)) -{ - if (self->errcheck) { - Py_INCREF(self->errcheck); - return self->errcheck; - } - Py_INCREF(Py_None); - return Py_None; -} - -static int -PyCFuncPtr_set_restype(PyCFuncPtrObject *self, PyObject *ob, void *Py_UNUSED(ignored)) -{ - if (ob == NULL) { - Py_CLEAR(self->restype); - Py_CLEAR(self->checker); - return 0; - } - if (ob != Py_None && !PyType_stgdict(ob) && !PyCallable_Check(ob)) { - PyErr_SetString(PyExc_TypeError, - "restype must be a type, a callable, or None"); - return -1; - } - Py_INCREF(ob); - Py_XSETREF(self->restype, ob); - Py_XSETREF(self->checker, PyObject_GetAttrString(ob, "_check_retval_")); - if (self->checker == NULL) - PyErr_Clear(); - return 0; -} - -static PyObject * -PyCFuncPtr_get_restype(PyCFuncPtrObject *self, void *Py_UNUSED(ignored)) -{ - StgDictObject *dict; - if (self->restype) { - Py_INCREF(self->restype); - return self->restype; - } - dict = PyObject_stgdict((PyObject *)self); - assert(dict); /* Cannot be NULL for PyCFuncPtrObject instances */ - if (dict->restype) { - Py_INCREF(dict->restype); - return dict->restype; - } else { - Py_INCREF(Py_None); - return Py_None; - } -} - -static int -PyCFuncPtr_set_argtypes(PyCFuncPtrObject *self, PyObject *ob, void *Py_UNUSED(ignored)) -{ - PyObject *converters; - - if (ob == NULL || ob == Py_None) { - Py_CLEAR(self->converters); - Py_CLEAR(self->argtypes); - } else { - converters = converters_from_argtypes(ob); - if (!converters) - return -1; - Py_XSETREF(self->converters, converters); - Py_INCREF(ob); - Py_XSETREF(self->argtypes, ob); - } - return 0; -} - -static PyObject * -PyCFuncPtr_get_argtypes(PyCFuncPtrObject *self, void *Py_UNUSED(ignored)) -{ - StgDictObject *dict; - if (self->argtypes) { - Py_INCREF(self->argtypes); - return self->argtypes; - } - dict = PyObject_stgdict((PyObject *)self); - assert(dict); /* Cannot be NULL for PyCFuncPtrObject instances */ - if (dict->argtypes) { - Py_INCREF(dict->argtypes); - return dict->argtypes; - } else { - Py_INCREF(Py_None); - return Py_None; - } -} - -static PyGetSetDef PyCFuncPtr_getsets[] = { - { "errcheck", (getter)PyCFuncPtr_get_errcheck, (setter)PyCFuncPtr_set_errcheck, - "a function to check for errors", NULL }, - { "restype", (getter)PyCFuncPtr_get_restype, (setter)PyCFuncPtr_set_restype, - "specify the result type", NULL }, - { "argtypes", (getter)PyCFuncPtr_get_argtypes, - (setter)PyCFuncPtr_set_argtypes, - "specify the argument types", NULL }, - { NULL, NULL } -}; - -#ifdef MS_WIN32 -static PPROC FindAddress(void *handle, const char *name, PyObject *type) -{ -#ifdef MS_WIN64 - /* win64 has no stdcall calling conv, so it should - also not have the name mangling of it. - */ - return (PPROC)GetProcAddress(handle, name); -#else - PPROC address; - char *mangled_name; - int i; - StgDictObject *dict; - - address = (PPROC)GetProcAddress(handle, name); - if (address) - return address; - if (((size_t)name & ~0xFFFF) == 0) { - return NULL; - } - - dict = PyType_stgdict((PyObject *)type); - /* It should not happen that dict is NULL, but better be safe */ - if (dict==NULL || dict->flags & FUNCFLAG_CDECL) - return address; - - /* for stdcall, try mangled names: - funcname -> _funcname@ - where n is 0, 4, 8, 12, ..., 128 - */ - mangled_name = alloca(strlen(name) + 1 + 1 + 1 + 3); /* \0 _ @ %d */ - if (!mangled_name) - return NULL; - for (i = 0; i < 32; ++i) { - sprintf(mangled_name, "_%s@%d", name, i*4); - address = (PPROC)GetProcAddress(handle, mangled_name); - if (address) - return address; - } - return NULL; -#endif -} -#endif - -/* Return 1 if usable, 0 else and exception set. */ -static int -_check_outarg_type(PyObject *arg, Py_ssize_t index) -{ - StgDictObject *dict; - - if (PyCPointerTypeObject_Check(arg)) - return 1; - - if (PyCArrayTypeObject_Check(arg)) - return 1; - - dict = PyType_stgdict(arg); - if (dict - /* simple pointer types, c_void_p, c_wchar_p, BSTR, ... */ - && PyUnicode_Check(dict->proto) -/* We only allow c_void_p, c_char_p and c_wchar_p as a simple output parameter type */ - && (strchr("PzZ", PyUnicode_AsUTF8(dict->proto)[0]))) { - return 1; - } - - PyErr_Format(PyExc_TypeError, - "'out' parameter %d must be a pointer type, not %s", - Py_SAFE_DOWNCAST(index, Py_ssize_t, int), - PyType_Check(arg) ? - ((PyTypeObject *)arg)->tp_name : - Py_TYPE(arg)->tp_name); - return 0; -} - -/* Returns 1 on success, 0 on error */ -static int -_validate_paramflags(PyTypeObject *type, PyObject *paramflags) -{ - Py_ssize_t i, len; - StgDictObject *dict; - PyObject *argtypes; - - dict = PyType_stgdict((PyObject *)type); - if (!dict) { - PyErr_SetString(PyExc_TypeError, - "abstract class"); - return 0; - } - argtypes = dict->argtypes; - - if (paramflags == NULL || dict->argtypes == NULL) - return 1; - - if (!PyTuple_Check(paramflags)) { - PyErr_SetString(PyExc_TypeError, - "paramflags must be a tuple or None"); - return 0; - } - - len = PyTuple_GET_SIZE(paramflags); - if (len != PyTuple_GET_SIZE(dict->argtypes)) { - PyErr_SetString(PyExc_ValueError, - "paramflags must have the same length as argtypes"); - return 0; - } - - for (i = 0; i < len; ++i) { - PyObject *item = PyTuple_GET_ITEM(paramflags, i); - int flag; - char *name; - PyObject *defval; - PyObject *typ; - if (!PyArg_ParseTuple(item, "i|ZO", &flag, &name, &defval)) { - PyErr_SetString(PyExc_TypeError, - "paramflags must be a sequence of (int [,string [,value]]) tuples"); - return 0; - } - typ = PyTuple_GET_ITEM(argtypes, i); - switch (flag & (PARAMFLAG_FIN | PARAMFLAG_FOUT | PARAMFLAG_FLCID)) { - case 0: - case PARAMFLAG_FIN: - case PARAMFLAG_FIN | PARAMFLAG_FLCID: - case PARAMFLAG_FIN | PARAMFLAG_FOUT: - break; - case PARAMFLAG_FOUT: - if (!_check_outarg_type(typ, i+1)) - return 0; - break; - default: - PyErr_Format(PyExc_TypeError, - "paramflag value %d not supported", - flag); - return 0; - } - } - return 1; -} - -static int -_get_name(PyObject *obj, const char **pname) -{ -#ifdef MS_WIN32 - if (PyLong_Check(obj)) { - /* We have to use MAKEINTRESOURCEA for Windows CE. - Works on Windows as well, of course. - */ - *pname = MAKEINTRESOURCEA(PyLong_AsUnsignedLongMask(obj) & 0xFFFF); - return 1; - } -#endif - if (PyBytes_Check(obj)) { - *pname = PyBytes_AS_STRING(obj); - return *pname ? 1 : 0; - } - if (PyUnicode_Check(obj)) { - *pname = PyUnicode_AsUTF8(obj); - return *pname ? 1 : 0; - } - PyErr_SetString(PyExc_TypeError, - "function name must be string, bytes object or integer"); - return 0; -} - - -static PyObject * -PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - const char *name; - int (* address)(void); - PyObject *ftuple; - PyObject *dll; - PyObject *obj; - PyCFuncPtrObject *self; - void *handle; - PyObject *paramflags = NULL; - - if (!PyArg_ParseTuple(args, "O|O", &ftuple, ¶mflags)) - return NULL; - if (paramflags == Py_None) - paramflags = NULL; - - ftuple = PySequence_Tuple(ftuple); - if (!ftuple) - /* Here ftuple is a borrowed reference */ - return NULL; - - if (!PyArg_ParseTuple(ftuple, "O&O", _get_name, &name, &dll)) { - Py_DECREF(ftuple); - return NULL; - } - - obj = PyObject_GetAttrString(dll, "_handle"); - if (!obj) { - Py_DECREF(ftuple); - return NULL; - } - if (!PyLong_Check(obj)) { - PyErr_SetString(PyExc_TypeError, - "the _handle attribute of the second argument must be an integer"); - Py_DECREF(ftuple); - Py_DECREF(obj); - return NULL; - } - handle = (void *)PyLong_AsVoidPtr(obj); - Py_DECREF(obj); - if (PyErr_Occurred()) { - PyErr_SetString(PyExc_ValueError, - "could not convert the _handle attribute to a pointer"); - Py_DECREF(ftuple); - return NULL; - } - -#ifdef MS_WIN32 - address = FindAddress(handle, name, (PyObject *)type); - if (!address) { - if (!IS_INTRESOURCE(name)) - PyErr_Format(PyExc_AttributeError, - "function '%s' not found", - name); - else - PyErr_Format(PyExc_AttributeError, - "function ordinal %d not found", - (WORD)(size_t)name); - Py_DECREF(ftuple); - return NULL; - } -#else - address = (PPROC)ctypes_dlsym(handle, name); - if (!address) { -#ifdef __CYGWIN__ -/* dlerror() isn't very helpful on cygwin */ - PyErr_Format(PyExc_AttributeError, - "function '%s' not found", - name); -#else - PyErr_SetString(PyExc_AttributeError, ctypes_dlerror()); -#endif - Py_DECREF(ftuple); - return NULL; - } -#endif - Py_INCREF(dll); /* for KeepRef */ - Py_DECREF(ftuple); - if (!_validate_paramflags(type, paramflags)) - return NULL; - - self = (PyCFuncPtrObject *)GenericPyCData_new(type, args, kwds); - if (!self) - return NULL; - - Py_XINCREF(paramflags); - self->paramflags = paramflags; - - *(void **)self->b_ptr = address; - - if (-1 == KeepRef((CDataObject *)self, 0, dll)) { - Py_DECREF((PyObject *)self); - return NULL; - } - - Py_INCREF(self); - self->callable = (PyObject *)self; - return (PyObject *)self; -} - -#ifdef MS_WIN32 -static PyObject * -PyCFuncPtr_FromVtblIndex(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyCFuncPtrObject *self; - int index; - char *name = NULL; - PyObject *paramflags = NULL; - GUID *iid = NULL; - Py_ssize_t iid_len = 0; - - if (!PyArg_ParseTuple(args, "is|Oz#", &index, &name, ¶mflags, &iid, &iid_len)) - return NULL; - if (paramflags == Py_None) - paramflags = NULL; - - if (!_validate_paramflags(type, paramflags)) - return NULL; - - self = (PyCFuncPtrObject *)GenericPyCData_new(type, args, kwds); - self->index = index + 0x1000; - Py_XINCREF(paramflags); - self->paramflags = paramflags; - if (iid_len == sizeof(GUID)) - self->iid = iid; - return (PyObject *)self; -} -#endif - -/* - PyCFuncPtr_new accepts different argument lists in addition to the standard - _basespec_ keyword arg: - - one argument form - "i" - function address - "O" - must be a callable, creates a C callable function - - two or more argument forms (the third argument is a paramflags tuple) - "(sO)|..." - (function name, dll object (with an integer handle)), paramflags - "(iO)|..." - (function ordinal, dll object (with an integer handle)), paramflags - "is|..." - vtable index, method name, creates callable calling COM vtbl -*/ -static PyObject * -PyCFuncPtr_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyCFuncPtrObject *self; - PyObject *callable; - StgDictObject *dict; - CThunkObject *thunk; - - if (PyTuple_GET_SIZE(args) == 0) - return GenericPyCData_new(type, args, kwds); - - if (1 <= PyTuple_GET_SIZE(args) && PyTuple_Check(PyTuple_GET_ITEM(args, 0))) - return PyCFuncPtr_FromDll(type, args, kwds); - -#ifdef MS_WIN32 - if (2 <= PyTuple_GET_SIZE(args) && PyLong_Check(PyTuple_GET_ITEM(args, 0))) - return PyCFuncPtr_FromVtblIndex(type, args, kwds); -#endif - - if (1 == PyTuple_GET_SIZE(args) - && (PyLong_Check(PyTuple_GET_ITEM(args, 0)))) { - CDataObject *ob; - void *ptr = PyLong_AsVoidPtr(PyTuple_GET_ITEM(args, 0)); - if (ptr == NULL && PyErr_Occurred()) - return NULL; - ob = (CDataObject *)GenericPyCData_new(type, args, kwds); - if (ob == NULL) - return NULL; - *(void **)ob->b_ptr = ptr; - return (PyObject *)ob; - } - - if (!PyArg_ParseTuple(args, "O", &callable)) - return NULL; - if (!PyCallable_Check(callable)) { - PyErr_SetString(PyExc_TypeError, - "argument must be callable or integer function address"); - return NULL; - } - - /* XXX XXX This would allow passing additional options. For COM - method *implementations*, we would probably want different - behaviour than in 'normal' callback functions: return a HRESULT if - an exception occurs in the callback, and print the traceback not - only on the console, but also to OutputDebugString() or something - like that. - */ -/* - if (kwds && PyDict_GetItemString(kwds, "options")) { - ... - } -*/ - - dict = PyType_stgdict((PyObject *)type); - /* XXXX Fails if we do: 'PyCFuncPtr(lambda x: x)' */ - if (!dict || !dict->argtypes) { - PyErr_SetString(PyExc_TypeError, - "cannot construct instance of this class:" - " no argtypes"); - return NULL; - } - - thunk = _ctypes_alloc_callback(callable, - dict->argtypes, - dict->restype, - dict->flags); - if (!thunk) - return NULL; - - self = (PyCFuncPtrObject *)GenericPyCData_new(type, args, kwds); - if (self == NULL) { - Py_DECREF(thunk); - return NULL; - } - - Py_INCREF(callable); - self->callable = callable; - - self->thunk = thunk; - *(void **)self->b_ptr = (void *)thunk->pcl_exec; - - Py_INCREF((PyObject *)thunk); /* for KeepRef */ - if (-1 == KeepRef((CDataObject *)self, 0, (PyObject *)thunk)) { - Py_DECREF((PyObject *)self); - return NULL; - } - return (PyObject *)self; -} - - -/* - _byref consumes a refcount to its argument -*/ -static PyObject * -_byref(PyObject *obj) -{ - PyCArgObject *parg; - if (!CDataObject_Check(obj)) { - PyErr_SetString(PyExc_TypeError, - "expected CData instance"); - return NULL; - } - - parg = PyCArgObject_new(); - if (parg == NULL) { - Py_DECREF(obj); - return NULL; - } - - parg->tag = 'P'; - parg->pffi_type = &ffi_type_pointer; - parg->obj = obj; - parg->value.p = ((CDataObject *)obj)->b_ptr; - return (PyObject *)parg; -} - -static PyObject * -_get_arg(int *pindex, PyObject *name, PyObject *defval, PyObject *inargs, PyObject *kwds) -{ - PyObject *v; - - if (*pindex < PyTuple_GET_SIZE(inargs)) { - v = PyTuple_GET_ITEM(inargs, *pindex); - ++*pindex; - Py_INCREF(v); - return v; - } - if (kwds && name && (v = PyDict_GetItem(kwds, name))) { - ++*pindex; - Py_INCREF(v); - return v; - } - if (defval) { - Py_INCREF(defval); - return defval; - } - /* we can't currently emit a better error message */ - if (name) - PyErr_Format(PyExc_TypeError, - "required argument '%S' missing", name); - else - PyErr_Format(PyExc_TypeError, - "not enough arguments"); - return NULL; -} - -/* - This function implements higher level functionality plus the ability to call - functions with keyword arguments by looking at parameter flags. parameter - flags is a tuple of 1, 2 or 3-tuples. The first entry in each is an integer - specifying the direction of the data transfer for this parameter - 'in', - 'out' or 'inout' (zero means the same as 'in'). The second entry is the - parameter name, and the third is the default value if the parameter is - missing in the function call. - - This function builds and returns a new tuple 'callargs' which contains the - parameters to use in the call. Items on this tuple are copied from the - 'inargs' tuple for 'in' and 'in, out' parameters, and constructed from the - 'argtypes' tuple for 'out' parameters. It also calculates numretvals which - is the number of return values for the function, outmask/inoutmask are - bitmasks containing indexes into the callargs tuple specifying which - parameters have to be returned. _build_result builds the return value of the - function. -*/ -static PyObject * -_build_callargs(PyCFuncPtrObject *self, PyObject *argtypes, - PyObject *inargs, PyObject *kwds, - int *poutmask, int *pinoutmask, unsigned int *pnumretvals) -{ - PyObject *paramflags = self->paramflags; - PyObject *callargs; - StgDictObject *dict; - Py_ssize_t i, len; - int inargs_index = 0; - /* It's a little bit difficult to determine how many arguments the - function call requires/accepts. For simplicity, we count the consumed - args and compare this to the number of supplied args. */ - Py_ssize_t actual_args; - - *poutmask = 0; - *pinoutmask = 0; - *pnumretvals = 0; - - /* Trivial cases, where we either return inargs itself, or a slice of it. */ - if (argtypes == NULL || paramflags == NULL || PyTuple_GET_SIZE(argtypes) == 0) { -#ifdef MS_WIN32 - if (self->index) - return PyTuple_GetSlice(inargs, 1, PyTuple_GET_SIZE(inargs)); -#endif - Py_INCREF(inargs); - return inargs; - } - - len = PyTuple_GET_SIZE(argtypes); - callargs = PyTuple_New(len); /* the argument tuple we build */ - if (callargs == NULL) - return NULL; - -#ifdef MS_WIN32 - /* For a COM method, skip the first arg */ - if (self->index) { - inargs_index = 1; - } -#endif - for (i = 0; i < len; ++i) { - PyObject *item = PyTuple_GET_ITEM(paramflags, i); - PyObject *ob; - int flag; - PyObject *name = NULL; - PyObject *defval = NULL; - - /* This way seems to be ~2 us faster than the PyArg_ParseTuple - calls below. */ - /* We HAVE already checked that the tuple can be parsed with "i|ZO", so... */ - Py_ssize_t tsize = PyTuple_GET_SIZE(item); - flag = PyLong_AS_LONG(PyTuple_GET_ITEM(item, 0)); - name = tsize > 1 ? PyTuple_GET_ITEM(item, 1) : NULL; - defval = tsize > 2 ? PyTuple_GET_ITEM(item, 2) : NULL; - - switch (flag & (PARAMFLAG_FIN | PARAMFLAG_FOUT | PARAMFLAG_FLCID)) { - case PARAMFLAG_FIN | PARAMFLAG_FLCID: - /* ['in', 'lcid'] parameter. Always taken from defval, - if given, else the integer 0. */ - if (defval == NULL) { - defval = PyLong_FromLong(0); - if (defval == NULL) - goto error; - } else - Py_INCREF(defval); - PyTuple_SET_ITEM(callargs, i, defval); - break; - case (PARAMFLAG_FIN | PARAMFLAG_FOUT): - *pinoutmask |= (1 << i); /* mark as inout arg */ - (*pnumretvals)++; - /* fall through */ - case 0: - case PARAMFLAG_FIN: - /* 'in' parameter. Copy it from inargs. */ - ob =_get_arg(&inargs_index, name, defval, inargs, kwds); - if (ob == NULL) - goto error; - PyTuple_SET_ITEM(callargs, i, ob); - break; - case PARAMFLAG_FOUT: - /* XXX Refactor this code into a separate function. */ - /* 'out' parameter. - argtypes[i] must be a POINTER to a c type. - - Cannot by supplied in inargs, but a defval will be used - if available. XXX Should we support getting it from kwds? - */ - if (defval) { - /* XXX Using mutable objects as defval will - make the function non-threadsafe, unless we - copy the object in each invocation */ - Py_INCREF(defval); - PyTuple_SET_ITEM(callargs, i, defval); - *poutmask |= (1 << i); /* mark as out arg */ - (*pnumretvals)++; - break; - } - ob = PyTuple_GET_ITEM(argtypes, i); - dict = PyType_stgdict(ob); - if (dict == NULL) { - /* Cannot happen: _validate_paramflags() - would not accept such an object */ - PyErr_Format(PyExc_RuntimeError, - "NULL stgdict unexpected"); - goto error; - } - if (PyUnicode_Check(dict->proto)) { - PyErr_Format( - PyExc_TypeError, - "%s 'out' parameter must be passed as default value", - ((PyTypeObject *)ob)->tp_name); - goto error; - } - if (PyCArrayTypeObject_Check(ob)) - ob = PyObject_CallObject(ob, NULL); - else - /* Create an instance of the pointed-to type */ - ob = PyObject_CallObject(dict->proto, NULL); - /* - XXX Is the following correct any longer? - We must not pass a byref() to the array then but - the array instance itself. Then, we cannot retrive - the result from the PyCArgObject. - */ - if (ob == NULL) - goto error; - /* The .from_param call that will ocurr later will pass this - as a byref parameter. */ - PyTuple_SET_ITEM(callargs, i, ob); - *poutmask |= (1 << i); /* mark as out arg */ - (*pnumretvals)++; - break; - default: - PyErr_Format(PyExc_ValueError, - "paramflag %d not yet implemented", flag); - goto error; - break; - } - } - - /* We have counted the arguments we have consumed in 'inargs_index'. This - must be the same as len(inargs) + len(kwds), otherwise we have - either too much or not enough arguments. */ - - actual_args = PyTuple_GET_SIZE(inargs) + (kwds ? PyDict_Size(kwds) : 0); - if (actual_args != inargs_index) { - /* When we have default values or named parameters, this error - message is misleading. See unittests/test_paramflags.py - */ - PyErr_Format(PyExc_TypeError, - "call takes exactly %d arguments (%zd given)", - inargs_index, actual_args); - goto error; - } - - /* outmask is a bitmask containing indexes into callargs. Items at - these indexes contain values to return. - */ - return callargs; - error: - Py_DECREF(callargs); - return NULL; -} - -/* See also: - http://msdn.microsoft.com/library/en-us/com/html/769127a1-1a14-4ed4-9d38-7cf3e571b661.asp -*/ -/* - Build return value of a function. - - Consumes the refcount on result and callargs. -*/ -static PyObject * -_build_result(PyObject *result, PyObject *callargs, - int outmask, int inoutmask, unsigned int numretvals) -{ - unsigned int i, index; - int bit; - PyObject *tup = NULL; - - if (callargs == NULL) - return result; - if (result == NULL || numretvals == 0) { - Py_DECREF(callargs); - return result; - } - Py_DECREF(result); - - /* tup will not be allocated if numretvals == 1 */ - /* allocate tuple to hold the result */ - if (numretvals > 1) { - tup = PyTuple_New(numretvals); - if (tup == NULL) { - Py_DECREF(callargs); - return NULL; - } - } - - index = 0; - for (bit = 1, i = 0; i < 32; ++i, bit <<= 1) { - PyObject *v; - if (bit & inoutmask) { - v = PyTuple_GET_ITEM(callargs, i); - Py_INCREF(v); - if (numretvals == 1) { - Py_DECREF(callargs); - return v; - } - PyTuple_SET_ITEM(tup, index, v); - index++; - } else if (bit & outmask) { - _Py_IDENTIFIER(__ctypes_from_outparam__); - - v = PyTuple_GET_ITEM(callargs, i); - v = _PyObject_CallMethodId(v, &PyId___ctypes_from_outparam__, NULL); - if (v == NULL || numretvals == 1) { - Py_DECREF(callargs); - return v; - } - PyTuple_SET_ITEM(tup, index, v); - index++; - } - if (index == numretvals) - break; - } - - Py_DECREF(callargs); - return tup; -} - -static PyObject * -PyCFuncPtr_call(PyCFuncPtrObject *self, PyObject *inargs, PyObject *kwds) -{ - PyObject *restype; - PyObject *converters; - PyObject *checker; - PyObject *argtypes; - StgDictObject *dict = PyObject_stgdict((PyObject *)self); - PyObject *result; - PyObject *callargs; - PyObject *errcheck; -#ifdef MS_WIN32 - IUnknown *piunk = NULL; -#endif - void *pProc = NULL; - - int inoutmask; - int outmask; - unsigned int numretvals; - - assert(dict); /* Cannot be NULL for PyCFuncPtrObject instances */ - restype = self->restype ? self->restype : dict->restype; - converters = self->converters ? self->converters : dict->converters; - checker = self->checker ? self->checker : dict->checker; - argtypes = self->argtypes ? self->argtypes : dict->argtypes; -/* later, we probably want to have an errcheck field in stgdict */ - errcheck = self->errcheck /* ? self->errcheck : dict->errcheck */; - - - pProc = *(void **)self->b_ptr; -#ifdef MS_WIN32 - if (self->index) { - /* It's a COM method */ - CDataObject *this; - this = (CDataObject *)PyTuple_GetItem(inargs, 0); /* borrowed ref! */ - if (!this) { - PyErr_SetString(PyExc_ValueError, - "native com method call without 'this' parameter"); - return NULL; - } - if (!CDataObject_Check(this)) { - PyErr_SetString(PyExc_TypeError, - "Expected a COM this pointer as first argument"); - return NULL; - } - /* there should be more checks? No, in Python */ - /* First arg is a pointer to an interface instance */ - if (!this->b_ptr || *(void **)this->b_ptr == NULL) { - PyErr_SetString(PyExc_ValueError, - "NULL COM pointer access"); - return NULL; - } - piunk = *(IUnknown **)this->b_ptr; - if (NULL == piunk->lpVtbl) { - PyErr_SetString(PyExc_ValueError, - "COM method call without VTable"); - return NULL; - } - pProc = ((void **)piunk->lpVtbl)[self->index - 0x1000]; - } -#endif - callargs = _build_callargs(self, argtypes, - inargs, kwds, - &outmask, &inoutmask, &numretvals); - if (callargs == NULL) - return NULL; - - if (converters) { - int required = Py_SAFE_DOWNCAST(PyTuple_GET_SIZE(converters), - Py_ssize_t, int); - int actual = Py_SAFE_DOWNCAST(PyTuple_GET_SIZE(callargs), - Py_ssize_t, int); - - if ((dict->flags & FUNCFLAG_CDECL) == FUNCFLAG_CDECL) { - /* For cdecl functions, we allow more actual arguments - than the length of the argtypes tuple. - */ - if (required > actual) { - Py_DECREF(callargs); - PyErr_Format(PyExc_TypeError, - "this function takes at least %d argument%s (%d given)", - required, - required == 1 ? "" : "s", - actual); - return NULL; - } - } else if (required != actual) { - Py_DECREF(callargs); - PyErr_Format(PyExc_TypeError, - "this function takes %d argument%s (%d given)", - required, - required == 1 ? "" : "s", - actual); - return NULL; - } - } - - result = _ctypes_callproc(pProc, - callargs, -#ifdef MS_WIN32 - piunk, - self->iid, -#endif - dict->flags, - converters, - restype, - checker); -/* The 'errcheck' protocol */ - if (result != NULL && errcheck) { - PyObject *v = PyObject_CallFunctionObjArgs(errcheck, - result, - self, - callargs, - NULL); - /* If the errcheck function failed, return NULL. - If the errcheck function returned callargs unchanged, - continue normal processing. - If the errcheck function returned something else, - use that as result. - */ - if (v == NULL || v != callargs) { - Py_DECREF(result); - Py_DECREF(callargs); - return v; - } - Py_DECREF(v); - } - - return _build_result(result, callargs, - outmask, inoutmask, numretvals); -} - -static int -PyCFuncPtr_traverse(PyCFuncPtrObject *self, visitproc visit, void *arg) -{ - Py_VISIT(self->callable); - Py_VISIT(self->restype); - Py_VISIT(self->checker); - Py_VISIT(self->errcheck); - Py_VISIT(self->argtypes); - Py_VISIT(self->converters); - Py_VISIT(self->paramflags); - Py_VISIT(self->thunk); - return PyCData_traverse((CDataObject *)self, visit, arg); -} - -static int -PyCFuncPtr_clear(PyCFuncPtrObject *self) -{ - Py_CLEAR(self->callable); - Py_CLEAR(self->restype); - Py_CLEAR(self->checker); - Py_CLEAR(self->errcheck); - Py_CLEAR(self->argtypes); - Py_CLEAR(self->converters); - Py_CLEAR(self->paramflags); - Py_CLEAR(self->thunk); - return PyCData_clear((CDataObject *)self); -} - -static void -PyCFuncPtr_dealloc(PyCFuncPtrObject *self) -{ - PyCFuncPtr_clear(self); - Py_TYPE(self)->tp_free((PyObject *)self); -} - -static PyObject * -PyCFuncPtr_repr(PyCFuncPtrObject *self) -{ -#ifdef MS_WIN32 - if (self->index) - return PyUnicode_FromFormat("", - self->index - 0x1000, - Py_TYPE(self)->tp_name, - self); -#endif - return PyUnicode_FromFormat("<%s object at %p>", - Py_TYPE(self)->tp_name, - self); -} - -static int -PyCFuncPtr_bool(PyCFuncPtrObject *self) -{ - return ((*(void **)self->b_ptr != NULL) -#ifdef MS_WIN32 - || (self->index != 0) -#endif - ); -} - -static PyNumberMethods PyCFuncPtr_as_number = { - 0, /* nb_add */ - 0, /* nb_subtract */ - 0, /* nb_multiply */ - 0, /* nb_remainder */ - 0, /* nb_divmod */ - 0, /* nb_power */ - 0, /* nb_negative */ - 0, /* nb_positive */ - 0, /* nb_absolute */ - (inquiry)PyCFuncPtr_bool, /* nb_bool */ -}; - -PyTypeObject PyCFuncPtr_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_ctypes.PyCFuncPtr", - sizeof(PyCFuncPtrObject), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)PyCFuncPtr_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)PyCFuncPtr_repr, /* tp_repr */ - &PyCFuncPtr_as_number, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)PyCFuncPtr_call, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - &PyCData_as_buffer, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - "Function Pointer", /* tp_doc */ - (traverseproc)PyCFuncPtr_traverse, /* tp_traverse */ - (inquiry)PyCFuncPtr_clear, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - PyCFuncPtr_getsets, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - PyCFuncPtr_new, /* tp_new */ - 0, /* tp_free */ -}; - -/*****************************************************************/ -/* - Struct_Type -*/ -/* - This function is called to initialize a Structure or Union with positional - arguments. It calls itself recursively for all Structure or Union base - classes, then retrieves the _fields_ member to associate the argument - position with the correct field name. - - Returns -1 on error, or the index of next argument on success. - */ -static Py_ssize_t -_init_pos_args(PyObject *self, PyTypeObject *type, - PyObject *args, PyObject *kwds, - Py_ssize_t index) -{ - StgDictObject *dict; - PyObject *fields; - Py_ssize_t i; - - if (PyType_stgdict((PyObject *)type->tp_base)) { - index = _init_pos_args(self, type->tp_base, - args, kwds, - index); - if (index == -1) - return -1; - } - - dict = PyType_stgdict((PyObject *)type); - fields = PyDict_GetItemString((PyObject *)dict, "_fields_"); - if (fields == NULL) - return index; - - for (i = 0; - i < dict->length && (i+index) < PyTuple_GET_SIZE(args); - ++i) { - PyObject *pair = PySequence_GetItem(fields, i); - PyObject *name, *val; - int res; - if (!pair) - return -1; - name = PySequence_GetItem(pair, 0); - if (!name) { - Py_DECREF(pair); - return -1; - } - val = PyTuple_GET_ITEM(args, i + index); - if (kwds && PyDict_GetItem(kwds, name)) { - PyErr_Format(PyExc_TypeError, - "duplicate values for field %R", - name); - Py_DECREF(pair); - Py_DECREF(name); - return -1; - } - - res = PyObject_SetAttr(self, name, val); - Py_DECREF(pair); - Py_DECREF(name); - if (res == -1) - return -1; - } - return index + dict->length; -} - -static int -Struct_init(PyObject *self, PyObject *args, PyObject *kwds) -{ -/* Optimization possible: Store the attribute names _fields_[x][0] - * in C accessible fields somewhere ? - */ - if (!PyTuple_Check(args)) { - PyErr_SetString(PyExc_TypeError, - "args not a tuple?"); - return -1; - } - if (PyTuple_GET_SIZE(args)) { - Py_ssize_t res = _init_pos_args(self, Py_TYPE(self), - args, kwds, 0); - if (res == -1) - return -1; - if (res < PyTuple_GET_SIZE(args)) { - PyErr_SetString(PyExc_TypeError, - "too many initializers"); - return -1; - } - } - - if (kwds) { - PyObject *key, *value; - Py_ssize_t pos = 0; - while(PyDict_Next(kwds, &pos, &key, &value)) { - if (-1 == PyObject_SetAttr(self, key, value)) - return -1; - } - } - return 0; -} - -static PyTypeObject Struct_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_ctypes.Structure", - sizeof(CDataObject), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - &PyCData_as_buffer, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - "Structure base class", /* tp_doc */ - (traverseproc)PyCData_traverse, /* tp_traverse */ - (inquiry)PyCData_clear, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - Struct_init, /* tp_init */ - 0, /* tp_alloc */ - GenericPyCData_new, /* tp_new */ - 0, /* tp_free */ -}; - -static PyTypeObject Union_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_ctypes.Union", - sizeof(CDataObject), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - &PyCData_as_buffer, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - "Union base class", /* tp_doc */ - (traverseproc)PyCData_traverse, /* tp_traverse */ - (inquiry)PyCData_clear, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - Struct_init, /* tp_init */ - 0, /* tp_alloc */ - GenericPyCData_new, /* tp_new */ - 0, /* tp_free */ -}; - - -/******************************************************************/ -/* - PyCArray_Type -*/ -static int -Array_init(CDataObject *self, PyObject *args, PyObject *kw) -{ - Py_ssize_t i; - Py_ssize_t n; - - if (!PyTuple_Check(args)) { - PyErr_SetString(PyExc_TypeError, - "args not a tuple?"); - return -1; - } - n = PyTuple_GET_SIZE(args); - for (i = 0; i < n; ++i) { - PyObject *v; - v = PyTuple_GET_ITEM(args, i); - if (-1 == PySequence_SetItem((PyObject *)self, i, v)) - return -1; - } - return 0; -} - -static PyObject * -Array_item(PyObject *myself, Py_ssize_t index) -{ - CDataObject *self = (CDataObject *)myself; - Py_ssize_t offset, size; - StgDictObject *stgdict; - - - if (index < 0 || index >= self->b_length) { - PyErr_SetString(PyExc_IndexError, - "invalid index"); - return NULL; - } - - stgdict = PyObject_stgdict((PyObject *)self); - assert(stgdict); /* Cannot be NULL for array instances */ - /* Would it be clearer if we got the item size from - stgdict->proto's stgdict? - */ - size = stgdict->size / stgdict->length; - offset = index * size; - - return PyCData_get(stgdict->proto, stgdict->getfunc, (PyObject *)self, - index, size, self->b_ptr + offset); -} - -static PyObject * -Array_subscript(PyObject *myself, PyObject *item) -{ - CDataObject *self = (CDataObject *)myself; - - if (PyIndex_Check(item)) { - Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); - - if (i == -1 && PyErr_Occurred()) - return NULL; - if (i < 0) - i += self->b_length; - return Array_item(myself, i); - } - else if (PySlice_Check(item)) { - StgDictObject *stgdict, *itemdict; - PyObject *proto; - PyObject *np; - Py_ssize_t start, stop, step, slicelen, cur, i; - - if (PySlice_Unpack(item, &start, &stop, &step) < 0) { - return NULL; - } - slicelen = PySlice_AdjustIndices(self->b_length, &start, &stop, step); - - stgdict = PyObject_stgdict((PyObject *)self); - assert(stgdict); /* Cannot be NULL for array object instances */ - proto = stgdict->proto; - itemdict = PyType_stgdict(proto); - assert(itemdict); /* proto is the item type of the array, a - ctypes type, so this cannot be NULL */ - - if (itemdict->getfunc == _ctypes_get_fielddesc("c")->getfunc) { - char *ptr = (char *)self->b_ptr; - char *dest; - - if (slicelen <= 0) - return PyBytes_FromStringAndSize("", 0); - if (step == 1) { - return PyBytes_FromStringAndSize(ptr + start, - slicelen); - } - dest = (char *)PyMem_Malloc(slicelen); - - if (dest == NULL) - return PyErr_NoMemory(); - - for (cur = start, i = 0; i < slicelen; - cur += step, i++) { - dest[i] = ptr[cur]; - } - - np = PyBytes_FromStringAndSize(dest, slicelen); - PyMem_Free(dest); - return np; - } -#ifdef CTYPES_UNICODE - if (itemdict->getfunc == _ctypes_get_fielddesc("u")->getfunc) { - wchar_t *ptr = (wchar_t *)self->b_ptr; - wchar_t *dest; - - if (slicelen <= 0) - return PyUnicode_New(0, 0); - if (step == 1) { - return PyUnicode_FromWideChar(ptr + start, - slicelen); - } - - dest = PyMem_New(wchar_t, slicelen); - if (dest == NULL) { - PyErr_NoMemory(); - return NULL; - } - - for (cur = start, i = 0; i < slicelen; - cur += step, i++) { - dest[i] = ptr[cur]; - } - - np = PyUnicode_FromWideChar(dest, slicelen); - PyMem_Free(dest); - return np; - } -#endif - - np = PyList_New(slicelen); - if (np == NULL) - return NULL; - - for (cur = start, i = 0; i < slicelen; - cur += step, i++) { - PyObject *v = Array_item(myself, cur); - if (v == NULL) { - Py_DECREF(np); - return NULL; - } - PyList_SET_ITEM(np, i, v); - } - return np; - } - else { - PyErr_SetString(PyExc_TypeError, - "indices must be integers"); - return NULL; - } - -} - -static int -Array_ass_item(PyObject *myself, Py_ssize_t index, PyObject *value) -{ - CDataObject *self = (CDataObject *)myself; - Py_ssize_t size, offset; - StgDictObject *stgdict; - char *ptr; - - if (value == NULL) { - PyErr_SetString(PyExc_TypeError, - "Array does not support item deletion"); - return -1; - } - - stgdict = PyObject_stgdict((PyObject *)self); - assert(stgdict); /* Cannot be NULL for array object instances */ - if (index < 0 || index >= stgdict->length) { - PyErr_SetString(PyExc_IndexError, - "invalid index"); - return -1; - } - size = stgdict->size / stgdict->length; - offset = index * size; - ptr = self->b_ptr + offset; - - return PyCData_set((PyObject *)self, stgdict->proto, stgdict->setfunc, value, - index, size, ptr); -} - -static int -Array_ass_subscript(PyObject *myself, PyObject *item, PyObject *value) -{ - CDataObject *self = (CDataObject *)myself; - - if (value == NULL) { - PyErr_SetString(PyExc_TypeError, - "Array does not support item deletion"); - return -1; - } - - if (PyIndex_Check(item)) { - Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); - - if (i == -1 && PyErr_Occurred()) - return -1; - if (i < 0) - i += self->b_length; - return Array_ass_item(myself, i, value); - } - else if (PySlice_Check(item)) { - Py_ssize_t start, stop, step, slicelen, otherlen, i, cur; - - if (PySlice_Unpack(item, &start, &stop, &step) < 0) { - return -1; - } - slicelen = PySlice_AdjustIndices(self->b_length, &start, &stop, step); - if ((step < 0 && start < stop) || - (step > 0 && start > stop)) - stop = start; - - otherlen = PySequence_Length(value); - if (otherlen != slicelen) { - PyErr_SetString(PyExc_ValueError, - "Can only assign sequence of same size"); - return -1; - } - for (cur = start, i = 0; i < otherlen; cur += step, i++) { - PyObject *item = PySequence_GetItem(value, i); - int result; - if (item == NULL) - return -1; - result = Array_ass_item(myself, cur, item); - Py_DECREF(item); - if (result == -1) - return -1; - } - return 0; - } - else { - PyErr_SetString(PyExc_TypeError, - "indices must be integer"); - return -1; - } -} - -static Py_ssize_t -Array_length(PyObject *myself) -{ - CDataObject *self = (CDataObject *)myself; - return self->b_length; -} - -static PySequenceMethods Array_as_sequence = { - Array_length, /* sq_length; */ - 0, /* sq_concat; */ - 0, /* sq_repeat; */ - Array_item, /* sq_item; */ - 0, /* sq_slice; */ - Array_ass_item, /* sq_ass_item; */ - 0, /* sq_ass_slice; */ - 0, /* sq_contains; */ - - 0, /* sq_inplace_concat; */ - 0, /* sq_inplace_repeat; */ -}; - -static PyMappingMethods Array_as_mapping = { - Array_length, - Array_subscript, - Array_ass_subscript, -}; - -PyTypeObject PyCArray_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_ctypes.Array", - sizeof(CDataObject), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - &Array_as_sequence, /* tp_as_sequence */ - &Array_as_mapping, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - &PyCData_as_buffer, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - "XXX to be provided", /* tp_doc */ - (traverseproc)PyCData_traverse, /* tp_traverse */ - (inquiry)PyCData_clear, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)Array_init, /* tp_init */ - 0, /* tp_alloc */ - GenericPyCData_new, /* tp_new */ - 0, /* tp_free */ -}; - -PyObject * -PyCArrayType_from_ctype(PyObject *itemtype, Py_ssize_t length) -{ - static PyObject *cache; - PyObject *key; - PyObject *result; - char name[256]; - PyObject *len; - - if (cache == NULL) { - cache = PyDict_New(); - if (cache == NULL) - return NULL; - } - len = PyLong_FromSsize_t(length); - if (len == NULL) - return NULL; - key = PyTuple_Pack(2, itemtype, len); - Py_DECREF(len); - if (!key) - return NULL; - result = PyDict_GetItemProxy(cache, key); - if (result) { - Py_INCREF(result); - Py_DECREF(key); - return result; - } - - if (!PyType_Check(itemtype)) { - PyErr_SetString(PyExc_TypeError, - "Expected a type object"); - Py_DECREF(key); - return NULL; - } -#ifdef MS_WIN64 - sprintf(name, "%.200s_Array_%Id", - ((PyTypeObject *)itemtype)->tp_name, length); -#else - sprintf(name, "%.200s_Array_%ld", - ((PyTypeObject *)itemtype)->tp_name, (long)length); -#endif - - result = PyObject_CallFunction((PyObject *)&PyCArrayType_Type, - "s(O){s:n,s:O}", - name, - &PyCArray_Type, - "_length_", - length, - "_type_", - itemtype - ); - if (result == NULL) { - Py_DECREF(key); - return NULL; - } - if (-1 == PyDict_SetItemProxy(cache, key, result)) { - Py_DECREF(key); - Py_DECREF(result); - return NULL; - } - Py_DECREF(key); - return result; -} - - -/******************************************************************/ -/* - Simple_Type -*/ - -static int -Simple_set_value(CDataObject *self, PyObject *value, void *Py_UNUSED(ignored)) -{ - PyObject *result; - StgDictObject *dict = PyObject_stgdict((PyObject *)self); - - if (value == NULL) { - PyErr_SetString(PyExc_TypeError, - "can't delete attribute"); - return -1; - } - assert(dict); /* Cannot be NULL for CDataObject instances */ - assert(dict->setfunc); - result = dict->setfunc(self->b_ptr, value, dict->size); - if (!result) - return -1; - - /* consumes the refcount the setfunc returns */ - return KeepRef(self, 0, result); -} - -static int -Simple_init(CDataObject *self, PyObject *args, PyObject *kw) -{ - PyObject *value = NULL; - if (!PyArg_UnpackTuple(args, "__init__", 0, 1, &value)) - return -1; - if (value) - return Simple_set_value(self, value, NULL); - return 0; -} - -static PyObject * -Simple_get_value(CDataObject *self, void *Py_UNUSED(ignored)) -{ - StgDictObject *dict; - dict = PyObject_stgdict((PyObject *)self); - assert(dict); /* Cannot be NULL for CDataObject instances */ - assert(dict->getfunc); - return dict->getfunc(self->b_ptr, self->b_size); -} - -static PyGetSetDef Simple_getsets[] = { - { "value", (getter)Simple_get_value, (setter)Simple_set_value, - "current value", NULL }, - { NULL, NULL } -}; - -static PyObject * -Simple_from_outparm(PyObject *self, PyObject *args) -{ - if (_ctypes_simple_instance((PyObject *)Py_TYPE(self))) { - Py_INCREF(self); - return self; - } - /* call stgdict->getfunc */ - return Simple_get_value((CDataObject *)self, NULL); -} - -static PyMethodDef Simple_methods[] = { - { "__ctypes_from_outparam__", Simple_from_outparm, METH_NOARGS, }, - { NULL, NULL }, -}; - -static int Simple_bool(CDataObject *self) -{ - return memcmp(self->b_ptr, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", self->b_size); -} - -static PyNumberMethods Simple_as_number = { - 0, /* nb_add */ - 0, /* nb_subtract */ - 0, /* nb_multiply */ - 0, /* nb_remainder */ - 0, /* nb_divmod */ - 0, /* nb_power */ - 0, /* nb_negative */ - 0, /* nb_positive */ - 0, /* nb_absolute */ - (inquiry)Simple_bool, /* nb_bool */ -}; - -/* "%s(%s)" % (self.__class__.__name__, self.value) */ -static PyObject * -Simple_repr(CDataObject *self) -{ - PyObject *val, *result; - - if (Py_TYPE(self)->tp_base != &Simple_Type) { - return PyUnicode_FromFormat("<%s object at %p>", - Py_TYPE(self)->tp_name, self); - } - - val = Simple_get_value(self, NULL); - if (val == NULL) - return NULL; - - result = PyUnicode_FromFormat("%s(%R)", - Py_TYPE(self)->tp_name, val); - Py_DECREF(val); - return result; -} - -static PyTypeObject Simple_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_ctypes._SimpleCData", - sizeof(CDataObject), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)&Simple_repr, /* tp_repr */ - &Simple_as_number, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - &PyCData_as_buffer, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - "XXX to be provided", /* tp_doc */ - (traverseproc)PyCData_traverse, /* tp_traverse */ - (inquiry)PyCData_clear, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - Simple_methods, /* tp_methods */ - 0, /* tp_members */ - Simple_getsets, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)Simple_init, /* tp_init */ - 0, /* tp_alloc */ - GenericPyCData_new, /* tp_new */ - 0, /* tp_free */ -}; - -/******************************************************************/ -/* - PyCPointer_Type -*/ -static PyObject * -Pointer_item(PyObject *myself, Py_ssize_t index) -{ - CDataObject *self = (CDataObject *)myself; - Py_ssize_t size; - Py_ssize_t offset; - StgDictObject *stgdict, *itemdict; - PyObject *proto; - - if (*(void **)self->b_ptr == NULL) { - PyErr_SetString(PyExc_ValueError, - "NULL pointer access"); - return NULL; - } - - stgdict = PyObject_stgdict((PyObject *)self); - assert(stgdict); /* Cannot be NULL for pointer object instances */ - - proto = stgdict->proto; - assert(proto); - itemdict = PyType_stgdict(proto); - assert(itemdict); /* proto is the item type of the pointer, a ctypes - type, so this cannot be NULL */ - - size = itemdict->size; - offset = index * itemdict->size; - - return PyCData_get(proto, stgdict->getfunc, (PyObject *)self, - index, size, (*(char **)self->b_ptr) + offset); -} - -static int -Pointer_ass_item(PyObject *myself, Py_ssize_t index, PyObject *value) -{ - CDataObject *self = (CDataObject *)myself; - Py_ssize_t size; - Py_ssize_t offset; - StgDictObject *stgdict, *itemdict; - PyObject *proto; - - if (value == NULL) { - PyErr_SetString(PyExc_TypeError, - "Pointer does not support item deletion"); - return -1; - } - - if (*(void **)self->b_ptr == NULL) { - PyErr_SetString(PyExc_ValueError, - "NULL pointer access"); - return -1; - } - - stgdict = PyObject_stgdict((PyObject *)self); - assert(stgdict); /* Cannot be NULL for pointer instances */ - - proto = stgdict->proto; - assert(proto); - - itemdict = PyType_stgdict(proto); - assert(itemdict); /* Cannot be NULL because the itemtype of a pointer - is always a ctypes type */ - - size = itemdict->size; - offset = index * itemdict->size; - - return PyCData_set((PyObject *)self, proto, stgdict->setfunc, value, - index, size, (*(char **)self->b_ptr) + offset); -} - -static PyObject * -Pointer_get_contents(CDataObject *self, void *closure) -{ - StgDictObject *stgdict; - - if (*(void **)self->b_ptr == NULL) { - PyErr_SetString(PyExc_ValueError, - "NULL pointer access"); - return NULL; - } - - stgdict = PyObject_stgdict((PyObject *)self); - assert(stgdict); /* Cannot be NULL for pointer instances */ - return PyCData_FromBaseObj(stgdict->proto, - (PyObject *)self, 0, - *(void **)self->b_ptr); -} - -static int -Pointer_set_contents(CDataObject *self, PyObject *value, void *closure) -{ - StgDictObject *stgdict; - CDataObject *dst; - PyObject *keep; - - if (value == NULL) { - PyErr_SetString(PyExc_TypeError, - "Pointer does not support item deletion"); - return -1; - } - stgdict = PyObject_stgdict((PyObject *)self); - assert(stgdict); /* Cannot be NULL for pointer instances */ - assert(stgdict->proto); - if (!CDataObject_Check(value)) { - int res = PyObject_IsInstance(value, stgdict->proto); - if (res == -1) - return -1; - if (!res) { - PyErr_Format(PyExc_TypeError, - "expected %s instead of %s", - ((PyTypeObject *)(stgdict->proto))->tp_name, - Py_TYPE(value)->tp_name); - return -1; - } - } - - dst = (CDataObject *)value; - *(void **)self->b_ptr = dst->b_ptr; - - /* - A Pointer instance must keep the value it points to alive. So, a - pointer instance has b_length set to 2 instead of 1, and we set - 'value' itself as the second item of the b_objects list, additionally. - */ - Py_INCREF(value); - if (-1 == KeepRef(self, 1, value)) - return -1; - - keep = GetKeepedObjects(dst); - if (keep == NULL) - return -1; - - Py_INCREF(keep); - return KeepRef(self, 0, keep); -} - -static PyGetSetDef Pointer_getsets[] = { - { "contents", (getter)Pointer_get_contents, - (setter)Pointer_set_contents, - "the object this pointer points to (read-write)", NULL }, - { NULL, NULL } -}; - -static int -Pointer_init(CDataObject *self, PyObject *args, PyObject *kw) -{ - PyObject *value = NULL; - - if (!PyArg_UnpackTuple(args, "POINTER", 0, 1, &value)) - return -1; - if (value == NULL) - return 0; - return Pointer_set_contents(self, value, NULL); -} - -static PyObject * -Pointer_new(PyTypeObject *type, PyObject *args, PyObject *kw) -{ - StgDictObject *dict = PyType_stgdict((PyObject *)type); - if (!dict || !dict->proto) { - PyErr_SetString(PyExc_TypeError, - "Cannot create instance: has no _type_"); - return NULL; - } - return GenericPyCData_new(type, args, kw); -} - -static PyObject * -Pointer_subscript(PyObject *myself, PyObject *item) -{ - CDataObject *self = (CDataObject *)myself; - if (PyIndex_Check(item)) { - Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); - if (i == -1 && PyErr_Occurred()) - return NULL; - return Pointer_item(myself, i); - } - else if (PySlice_Check(item)) { - PySliceObject *slice = (PySliceObject *)item; - Py_ssize_t start, stop, step; - PyObject *np; - StgDictObject *stgdict, *itemdict; - PyObject *proto; - Py_ssize_t i, len, cur; - - /* Since pointers have no length, and we want to apply - different semantics to negative indices than normal - slicing, we have to dissect the slice object ourselves.*/ - if (slice->step == Py_None) { - step = 1; - } - else { - step = PyNumber_AsSsize_t(slice->step, - PyExc_ValueError); - if (step == -1 && PyErr_Occurred()) - return NULL; - if (step == 0) { - PyErr_SetString(PyExc_ValueError, - "slice step cannot be zero"); - return NULL; - } - } - if (slice->start == Py_None) { - if (step < 0) { - PyErr_SetString(PyExc_ValueError, - "slice start is required " - "for step < 0"); - return NULL; - } - start = 0; - } - else { - start = PyNumber_AsSsize_t(slice->start, - PyExc_ValueError); - if (start == -1 && PyErr_Occurred()) - return NULL; - } - if (slice->stop == Py_None) { - PyErr_SetString(PyExc_ValueError, - "slice stop is required"); - return NULL; - } - stop = PyNumber_AsSsize_t(slice->stop, - PyExc_ValueError); - if (stop == -1 && PyErr_Occurred()) - return NULL; - if ((step > 0 && start > stop) || - (step < 0 && start < stop)) - len = 0; - else if (step > 0) - len = (stop - start - 1) / step + 1; - else - len = (stop - start + 1) / step + 1; - - stgdict = PyObject_stgdict((PyObject *)self); - assert(stgdict); /* Cannot be NULL for pointer instances */ - proto = stgdict->proto; - assert(proto); - itemdict = PyType_stgdict(proto); - assert(itemdict); - if (itemdict->getfunc == _ctypes_get_fielddesc("c")->getfunc) { - char *ptr = *(char **)self->b_ptr; - char *dest; - - if (len <= 0) - return PyBytes_FromStringAndSize("", 0); - if (step == 1) { - return PyBytes_FromStringAndSize(ptr + start, - len); - } - dest = (char *)PyMem_Malloc(len); - if (dest == NULL) - return PyErr_NoMemory(); - for (cur = start, i = 0; i < len; cur += step, i++) { - dest[i] = ptr[cur]; - } - np = PyBytes_FromStringAndSize(dest, len); - PyMem_Free(dest); - return np; - } -#ifdef CTYPES_UNICODE - if (itemdict->getfunc == _ctypes_get_fielddesc("u")->getfunc) { - wchar_t *ptr = *(wchar_t **)self->b_ptr; - wchar_t *dest; - - if (len <= 0) - return PyUnicode_New(0, 0); - if (step == 1) { - return PyUnicode_FromWideChar(ptr + start, - len); - } - dest = PyMem_New(wchar_t, len); - if (dest == NULL) - return PyErr_NoMemory(); - for (cur = start, i = 0; i < len; cur += step, i++) { - dest[i] = ptr[cur]; - } - np = PyUnicode_FromWideChar(dest, len); - PyMem_Free(dest); - return np; - } -#endif - - np = PyList_New(len); - if (np == NULL) - return NULL; - - for (cur = start, i = 0; i < len; cur += step, i++) { - PyObject *v = Pointer_item(myself, cur); - PyList_SET_ITEM(np, i, v); - } - return np; - } - else { - PyErr_SetString(PyExc_TypeError, - "Pointer indices must be integer"); - return NULL; - } -} - -static PySequenceMethods Pointer_as_sequence = { - 0, /* inquiry sq_length; */ - 0, /* binaryfunc sq_concat; */ - 0, /* intargfunc sq_repeat; */ - Pointer_item, /* intargfunc sq_item; */ - 0, /* intintargfunc sq_slice; */ - Pointer_ass_item, /* intobjargproc sq_ass_item; */ - 0, /* intintobjargproc sq_ass_slice; */ - 0, /* objobjproc sq_contains; */ - /* Added in release 2.0 */ - 0, /* binaryfunc sq_inplace_concat; */ - 0, /* intargfunc sq_inplace_repeat; */ -}; - -static PyMappingMethods Pointer_as_mapping = { - 0, - Pointer_subscript, -}; - -static int -Pointer_bool(CDataObject *self) -{ - return (*(void **)self->b_ptr != NULL); -} - -static PyNumberMethods Pointer_as_number = { - 0, /* nb_add */ - 0, /* nb_subtract */ - 0, /* nb_multiply */ - 0, /* nb_remainder */ - 0, /* nb_divmod */ - 0, /* nb_power */ - 0, /* nb_negative */ - 0, /* nb_positive */ - 0, /* nb_absolute */ - (inquiry)Pointer_bool, /* nb_bool */ -}; - -PyTypeObject PyCPointer_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_ctypes._Pointer", - sizeof(CDataObject), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - &Pointer_as_number, /* tp_as_number */ - &Pointer_as_sequence, /* tp_as_sequence */ - &Pointer_as_mapping, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - &PyCData_as_buffer, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - "XXX to be provided", /* tp_doc */ - (traverseproc)PyCData_traverse, /* tp_traverse */ - (inquiry)PyCData_clear, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - Pointer_getsets, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)Pointer_init, /* tp_init */ - 0, /* tp_alloc */ - Pointer_new, /* tp_new */ - 0, /* tp_free */ -}; - - -/******************************************************************/ -/* - * Module initialization. - */ - -static const char module_docs[] = -"Create and manipulate C compatible data types in Python."; - -#ifdef MS_WIN32 - -static const char comerror_doc[] = "Raised when a COM method call failed."; - -int -comerror_init(PyObject *self, PyObject *args, PyObject *kwds) -{ - PyObject *hresult, *text, *details; - PyObject *a; - int status; - - if (!_PyArg_NoKeywords(Py_TYPE(self)->tp_name, kwds)) - return -1; - - if (!PyArg_ParseTuple(args, "OOO:COMError", &hresult, &text, &details)) - return -1; - - a = PySequence_GetSlice(args, 1, PySequence_Size(args)); - if (!a) - return -1; - status = PyObject_SetAttrString(self, "args", a); - Py_DECREF(a); - if (status < 0) - return -1; - - if (PyObject_SetAttrString(self, "hresult", hresult) < 0) - return -1; - - if (PyObject_SetAttrString(self, "text", text) < 0) - return -1; - - if (PyObject_SetAttrString(self, "details", details) < 0) - return -1; - - Py_INCREF(args); - Py_SETREF(((PyBaseExceptionObject *)self)->args, args); - - return 0; -} - -static PyTypeObject PyComError_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_ctypes.COMError", /* tp_name */ - sizeof(PyBaseExceptionObject), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - PyDoc_STR(comerror_doc), /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)comerror_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ -}; - - -static int -create_comerror(void) -{ - PyComError_Type.tp_base = (PyTypeObject*)PyExc_Exception; - if (PyType_Ready(&PyComError_Type) < 0) - return -1; - Py_INCREF(&PyComError_Type); - ComError = (PyObject*)&PyComError_Type; - return 0; -} - -#endif - -static PyObject * -string_at(const char *ptr, int size) -{ - if (size == -1) - return PyBytes_FromStringAndSize(ptr, strlen(ptr)); - return PyBytes_FromStringAndSize(ptr, size); -} - -static int -cast_check_pointertype(PyObject *arg) -{ - StgDictObject *dict; - - if (PyCPointerTypeObject_Check(arg)) - return 1; - if (PyCFuncPtrTypeObject_Check(arg)) - return 1; - dict = PyType_stgdict(arg); - if (dict != NULL && dict->proto != NULL) { - if (PyUnicode_Check(dict->proto) - && (strchr("sPzUZXO", PyUnicode_AsUTF8(dict->proto)[0]))) { - /* simple pointer types, c_void_p, c_wchar_p, BSTR, ... */ - return 1; - } - } - PyErr_Format(PyExc_TypeError, - "cast() argument 2 must be a pointer type, not %s", - PyType_Check(arg) - ? ((PyTypeObject *)arg)->tp_name - : Py_TYPE(arg)->tp_name); - return 0; -} - -static PyObject * -cast(void *ptr, PyObject *src, PyObject *ctype) -{ - CDataObject *result; - if (0 == cast_check_pointertype(ctype)) - return NULL; - result = (CDataObject *)PyObject_CallFunctionObjArgs(ctype, NULL); - if (result == NULL) - return NULL; - - /* - The casted objects '_objects' member: - - It must certainly contain the source objects one. - It must contain the source object itself. - */ - if (CDataObject_Check(src)) { - CDataObject *obj = (CDataObject *)src; - CDataObject *container; - - /* PyCData_GetContainer will initialize src.b_objects, we need - this so it can be shared */ - container = PyCData_GetContainer(obj); - if (container == NULL) - goto failed; - - /* But we need a dictionary! */ - if (obj->b_objects == Py_None) { - Py_DECREF(Py_None); - obj->b_objects = PyDict_New(); - if (obj->b_objects == NULL) - goto failed; - } - Py_XINCREF(obj->b_objects); - result->b_objects = obj->b_objects; - if (result->b_objects && PyDict_CheckExact(result->b_objects)) { - PyObject *index; - int rc; - index = PyLong_FromVoidPtr((void *)src); - if (index == NULL) - goto failed; - rc = PyDict_SetItem(result->b_objects, index, src); - Py_DECREF(index); - if (rc == -1) - goto failed; - } - } - /* Should we assert that result is a pointer type? */ - memcpy(result->b_ptr, &ptr, sizeof(void *)); - return (PyObject *)result; - - failed: - Py_DECREF(result); - return NULL; -} - -#ifdef CTYPES_UNICODE -static PyObject * -wstring_at(const wchar_t *ptr, int size) -{ - Py_ssize_t ssize = size; - if (ssize == -1) - ssize = wcslen(ptr); - return PyUnicode_FromWideChar(ptr, ssize); -} -#endif - - -static struct PyModuleDef _ctypesmodule = { - PyModuleDef_HEAD_INIT, - "_ctypes", - module_docs, - -1, - _ctypes_module_methods, - NULL, - NULL, - NULL, - NULL -}; - -PyMODINIT_FUNC -PyInit__ctypes(void) -{ - PyObject *m; - -/* Note: - ob_type is the metatype (the 'type'), defaults to PyType_Type, - tp_base is the base type, defaults to 'object' aka PyBaseObject_Type. -*/ -#ifdef WITH_THREAD - PyEval_InitThreads(); -#endif - m = PyModule_Create(&_ctypesmodule); - if (!m) - return NULL; - - _ctypes_ptrtype_cache = PyDict_New(); - if (_ctypes_ptrtype_cache == NULL) - return NULL; - - PyModule_AddObject(m, "_pointer_type_cache", (PyObject *)_ctypes_ptrtype_cache); - - _unpickle = PyObject_GetAttrString(m, "_unpickle"); - if (_unpickle == NULL) - return NULL; - - if (PyType_Ready(&PyCArg_Type) < 0) - return NULL; - - if (PyType_Ready(&PyCThunk_Type) < 0) - return NULL; - - /* StgDict is derived from PyDict_Type */ - PyCStgDict_Type.tp_base = &PyDict_Type; - if (PyType_Ready(&PyCStgDict_Type) < 0) - return NULL; - - /************************************************* - * - * Metaclasses - */ - - PyCStructType_Type.tp_base = &PyType_Type; - if (PyType_Ready(&PyCStructType_Type) < 0) - return NULL; - - UnionType_Type.tp_base = &PyType_Type; - if (PyType_Ready(&UnionType_Type) < 0) - return NULL; - - PyCPointerType_Type.tp_base = &PyType_Type; - if (PyType_Ready(&PyCPointerType_Type) < 0) - return NULL; - - PyCArrayType_Type.tp_base = &PyType_Type; - if (PyType_Ready(&PyCArrayType_Type) < 0) - return NULL; - - PyCSimpleType_Type.tp_base = &PyType_Type; - if (PyType_Ready(&PyCSimpleType_Type) < 0) - return NULL; - - PyCFuncPtrType_Type.tp_base = &PyType_Type; - if (PyType_Ready(&PyCFuncPtrType_Type) < 0) - return NULL; - - /************************************************* - * - * Classes using a custom metaclass - */ - - if (PyType_Ready(&PyCData_Type) < 0) - return NULL; - - Py_TYPE(&Struct_Type) = &PyCStructType_Type; - Struct_Type.tp_base = &PyCData_Type; - if (PyType_Ready(&Struct_Type) < 0) - return NULL; - Py_INCREF(&Struct_Type); - PyModule_AddObject(m, "Structure", (PyObject *)&Struct_Type); - - Py_TYPE(&Union_Type) = &UnionType_Type; - Union_Type.tp_base = &PyCData_Type; - if (PyType_Ready(&Union_Type) < 0) - return NULL; - Py_INCREF(&Union_Type); - PyModule_AddObject(m, "Union", (PyObject *)&Union_Type); - - Py_TYPE(&PyCPointer_Type) = &PyCPointerType_Type; - PyCPointer_Type.tp_base = &PyCData_Type; - if (PyType_Ready(&PyCPointer_Type) < 0) - return NULL; - Py_INCREF(&PyCPointer_Type); - PyModule_AddObject(m, "_Pointer", (PyObject *)&PyCPointer_Type); - - Py_TYPE(&PyCArray_Type) = &PyCArrayType_Type; - PyCArray_Type.tp_base = &PyCData_Type; - if (PyType_Ready(&PyCArray_Type) < 0) - return NULL; - Py_INCREF(&PyCArray_Type); - PyModule_AddObject(m, "Array", (PyObject *)&PyCArray_Type); - - Py_TYPE(&Simple_Type) = &PyCSimpleType_Type; - Simple_Type.tp_base = &PyCData_Type; - if (PyType_Ready(&Simple_Type) < 0) - return NULL; - Py_INCREF(&Simple_Type); - PyModule_AddObject(m, "_SimpleCData", (PyObject *)&Simple_Type); - - Py_TYPE(&PyCFuncPtr_Type) = &PyCFuncPtrType_Type; - PyCFuncPtr_Type.tp_base = &PyCData_Type; - if (PyType_Ready(&PyCFuncPtr_Type) < 0) - return NULL; - Py_INCREF(&PyCFuncPtr_Type); - PyModule_AddObject(m, "CFuncPtr", (PyObject *)&PyCFuncPtr_Type); - - /************************************************* - * - * Simple classes - */ - - /* PyCField_Type is derived from PyBaseObject_Type */ - if (PyType_Ready(&PyCField_Type) < 0) - return NULL; - - /************************************************* - * - * Other stuff - */ - - DictRemover_Type.tp_new = PyType_GenericNew; - if (PyType_Ready(&DictRemover_Type) < 0) - return NULL; - -#ifdef MS_WIN32 - if (create_comerror() < 0) - return NULL; - PyModule_AddObject(m, "COMError", ComError); - - PyModule_AddObject(m, "FUNCFLAG_HRESULT", PyLong_FromLong(FUNCFLAG_HRESULT)); - PyModule_AddObject(m, "FUNCFLAG_STDCALL", PyLong_FromLong(FUNCFLAG_STDCALL)); -#endif - PyModule_AddObject(m, "FUNCFLAG_CDECL", PyLong_FromLong(FUNCFLAG_CDECL)); - PyModule_AddObject(m, "FUNCFLAG_USE_ERRNO", PyLong_FromLong(FUNCFLAG_USE_ERRNO)); - PyModule_AddObject(m, "FUNCFLAG_USE_LASTERROR", PyLong_FromLong(FUNCFLAG_USE_LASTERROR)); - PyModule_AddObject(m, "FUNCFLAG_PYTHONAPI", PyLong_FromLong(FUNCFLAG_PYTHONAPI)); - PyModule_AddStringConstant(m, "__version__", "1.1.0"); - - PyModule_AddObject(m, "_memmove_addr", PyLong_FromVoidPtr(memmove)); - PyModule_AddObject(m, "_memset_addr", PyLong_FromVoidPtr(memset)); - PyModule_AddObject(m, "_string_at_addr", PyLong_FromVoidPtr(string_at)); - PyModule_AddObject(m, "_cast_addr", PyLong_FromVoidPtr(cast)); -#ifdef CTYPES_UNICODE - PyModule_AddObject(m, "_wstring_at_addr", PyLong_FromVoidPtr(wstring_at)); -#endif - -/* If RTLD_LOCAL is not defined (Windows!), set it to zero. */ -#if !HAVE_DECL_RTLD_LOCAL -#define RTLD_LOCAL 0 -#endif - -/* If RTLD_GLOBAL is not defined (cygwin), set it to the same value as - RTLD_LOCAL. -*/ -#if !HAVE_DECL_RTLD_GLOBAL -#define RTLD_GLOBAL RTLD_LOCAL -#endif - - PyModule_AddObject(m, "RTLD_LOCAL", PyLong_FromLong(RTLD_LOCAL)); - PyModule_AddObject(m, "RTLD_GLOBAL", PyLong_FromLong(RTLD_GLOBAL)); - - PyExc_ArgError = PyErr_NewException("ctypes.ArgumentError", NULL, NULL); - if (PyExc_ArgError) { - Py_INCREF(PyExc_ArgError); - PyModule_AddObject(m, "ArgumentError", PyExc_ArgError); - } - return m; -} - -/* - Local Variables: - compile-command: "cd .. && python setup.py -q build -g && python setup.py -q build install --home ~" - End: -*/ diff --git a/third_party/python/Modules/_ctypes/_ctypes_test.c b/third_party/python/Modules/_ctypes/_ctypes_test.c deleted file mode 100644 index 0094c6ff3..000000000 --- a/third_party/python/Modules/_ctypes/_ctypes_test.c +++ /dev/null @@ -1,900 +0,0 @@ -/* clang-format off */ -#include - -#ifdef MS_WIN32 -#include -#endif - -#if defined(MS_WIN32) || defined(__CYGWIN__) -#define EXPORT(x) __declspec(dllexport) x -#else -#define EXPORT(x) x -#endif - -/* some functions handy for testing */ - -EXPORT(int) -_testfunc_cbk_reg_int(int a, int b, int c, int d, int e, - int (*func)(int, int, int, int, int)) -{ - return func(a*a, b*b, c*c, d*d, e*e); -} - -EXPORT(double) -_testfunc_cbk_reg_double(double a, double b, double c, double d, double e, - double (*func)(double, double, double, double, double)) -{ - return func(a*a, b*b, c*c, d*d, e*e); -} - -/* - * This structure should be the same as in test_callbacks.py and the - * method test_callback_large_struct. See issues 17310 and 20160: the - * structure must be larger than 8 bytes long. - */ - -typedef struct { - unsigned long first; - unsigned long second; - unsigned long third; -} Test; - -EXPORT(void) -_testfunc_cbk_large_struct(Test in, void (*func)(Test)) -{ - func(in); -} - -/* - * See issue 29565. Update a structure passed by value; - * the caller should not see any change. - */ - -EXPORT(void) -_testfunc_large_struct_update_value(Test in) -{ - ((volatile Test *)&in)->first = 0x0badf00d; - ((volatile Test *)&in)->second = 0x0badf00d; - ((volatile Test *)&in)->third = 0x0badf00d; -} - -typedef struct { - unsigned int first; - unsigned int second; -} TestReg; - - -EXPORT(TestReg) last_tfrsuv_arg; - - -EXPORT(void) -_testfunc_reg_struct_update_value(TestReg in) -{ - last_tfrsuv_arg = in; - ((volatile TestReg *)&in)->first = 0x0badf00d; - ((volatile TestReg *)&in)->second = 0x0badf00d; -} - - -EXPORT(void)testfunc_array(int values[4]) -{ - printf("testfunc_array %d %d %d %d\n", - values[0], - values[1], - values[2], - values[3]); -} - -EXPORT(long double)testfunc_Ddd(double a, double b) -{ - long double result = (long double)(a * b); - printf("testfunc_Ddd(%p, %p)\n", &a, &b); - printf("testfunc_Ddd(%g, %g)\n", a, b); - return result; -} - -EXPORT(long double)testfunc_DDD(long double a, long double b) -{ - long double result = a * b; - printf("testfunc_DDD(%p, %p)\n", &a, &b); - printf("testfunc_DDD(%Lg, %Lg)\n", a, b); - return result; -} - -EXPORT(int)testfunc_iii(int a, int b) -{ - int result = a * b; - printf("testfunc_iii(%p, %p)\n", &a, &b); - return result; -} - -EXPORT(int)myprintf(char *fmt, ...) -{ - int result; - va_list argptr; - va_start(argptr, fmt); - result = vprintf(fmt, argptr); - va_end(argptr); - return result; -} - -EXPORT(char *)my_strtok(char *token, const char *delim) -{ - return strtok(token, delim); -} - -EXPORT(char *)my_strchr(const char *s, int c) -{ - return strchr(s, c); -} - - -EXPORT(double) my_sqrt(double a) -{ - return sqrt(a); -} - -EXPORT(void) my_qsort(void *base, size_t num, size_t width, int(*compare)(const void*, const void*)) -{ - qsort(base, num, width, compare); -} - -EXPORT(int *) _testfunc_ai8(int a[8]) -{ - return a; -} - -EXPORT(void) _testfunc_v(int a, int b, int *presult) -{ - *presult = a + b; -} - -EXPORT(int) _testfunc_i_bhilfd(signed char b, short h, int i, long l, float f, double d) -{ -/* printf("_testfunc_i_bhilfd got %d %d %d %ld %f %f\n", - b, h, i, l, f, d); -*/ - return (int)(b + h + i + l + f + d); -} - -EXPORT(float) _testfunc_f_bhilfd(signed char b, short h, int i, long l, float f, double d) -{ -/* printf("_testfunc_f_bhilfd got %d %d %d %ld %f %f\n", - b, h, i, l, f, d); -*/ - return (float)(b + h + i + l + f + d); -} - -EXPORT(double) _testfunc_d_bhilfd(signed char b, short h, int i, long l, float f, double d) -{ -/* printf("_testfunc_d_bhilfd got %d %d %d %ld %f %f\n", - b, h, i, l, f, d); -*/ - return (double)(b + h + i + l + f + d); -} - -EXPORT(long double) _testfunc_D_bhilfD(signed char b, short h, int i, long l, float f, long double d) -{ -/* printf("_testfunc_d_bhilfd got %d %d %d %ld %f %f\n", - b, h, i, l, f, d); -*/ - return (long double)(b + h + i + l + f + d); -} - -EXPORT(char *) _testfunc_p_p(void *s) -{ - return (char *)s; -} - -EXPORT(void *) _testfunc_c_p_p(int *argcp, char **argv) -{ - return argv[(*argcp)-1]; -} - -EXPORT(void *) get_strchr(void) -{ - return (void *)strchr; -} - -EXPORT(char *) my_strdup(char *src) -{ - char *dst = (char *)malloc(strlen(src)+1); - if (!dst) - return NULL; - strcpy(dst, src); - return dst; -} - -EXPORT(void)my_free(void *ptr) -{ - free(ptr); -} - -#ifdef HAVE_WCHAR_H -EXPORT(wchar_t *) my_wcsdup(wchar_t *src) -{ - size_t len = wcslen(src); - wchar_t *ptr = (wchar_t *)malloc((len + 1) * sizeof(wchar_t)); - if (ptr == NULL) - return NULL; - memcpy(ptr, src, (len+1) * sizeof(wchar_t)); - return ptr; -} - -EXPORT(size_t) my_wcslen(wchar_t *src) -{ - return wcslen(src); -} -#endif - -#ifndef MS_WIN32 -# ifndef __stdcall -# define __stdcall /* */ -# endif -#endif - -typedef struct { - int (*c)(int, int); - int (__stdcall *s)(int, int); -} FUNCS; - -EXPORT(int) _testfunc_callfuncp(FUNCS *fp) -{ - fp->c(1, 2); - fp->s(3, 4); - return 0; -} - -EXPORT(int) _testfunc_deref_pointer(int *pi) -{ - return *pi; -} - -#ifdef MS_WIN32 -EXPORT(int) _testfunc_piunk(IUnknown FAR *piunk) -{ - piunk->lpVtbl->AddRef(piunk); - return piunk->lpVtbl->Release(piunk); -} -#endif - -EXPORT(int) _testfunc_callback_with_pointer(int (*func)(int *)) -{ - int table[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - - return (*func)(table); -} - -EXPORT(long long) _testfunc_q_bhilfdq(signed char b, short h, int i, long l, float f, - double d, long long q) -{ - return (long long)(b + h + i + l + f + d + q); -} - -EXPORT(long long) _testfunc_q_bhilfd(signed char b, short h, int i, long l, float f, double d) -{ - return (long long)(b + h + i + l + f + d); -} - -EXPORT(int) _testfunc_callback_i_if(int value, int (*func)(int)) -{ - int sum = 0; - while (value != 0) { - sum += func(value); - value /= 2; - } - return sum; -} - -EXPORT(long long) _testfunc_callback_q_qf(long long value, - long long (*func)(long long)) -{ - long long sum = 0; - - while (value != 0) { - sum += func(value); - value /= 2; - } - return sum; -} - -typedef struct { - char *name; - char *value; -} SPAM; - -typedef struct { - char *name; - int num_spams; - SPAM *spams; -} EGG; - -SPAM my_spams[2] = { - { "name1", "value1" }, - { "name2", "value2" }, -}; - -EGG my_eggs[1] = { - { "first egg", 1, my_spams } -}; - -EXPORT(int) getSPAMANDEGGS(EGG **eggs) -{ - *eggs = my_eggs; - return 1; -} - -typedef struct tagpoint { - int x; - int y; -} point; - -EXPORT(int) _testfunc_byval(point in, point *pout) -{ - if (pout) { - pout->x = in.x; - pout->y = in.y; - } - return in.x + in.y; -} - -EXPORT (int) an_integer = 42; - -EXPORT(int) get_an_integer(void) -{ - return an_integer; -} - -EXPORT(double) -integrate(double a, double b, double (*f)(double), long nstep) -{ - double x, sum=0.0, dx=(b-a)/(double)nstep; - for(x=a+0.5*dx; (b-x)*(x-a)>0.0; x+=dx) - sum += f(x); - return sum/(double)nstep; -} - -typedef struct { - void (*initialize)(void *(*)(int), void(*)(void *)); -} xxx_library; - -static void _xxx_init(void *(*Xalloc)(int), void (*Xfree)(void *)) -{ - void *ptr; - - printf("_xxx_init got %p %p\n", Xalloc, Xfree); - printf("calling\n"); - ptr = Xalloc(32); - Xfree(ptr); - printf("calls done, ptr was %p\n", ptr); -} - -xxx_library _xxx_lib = { - _xxx_init -}; - -EXPORT(xxx_library) *library_get(void) -{ - return &_xxx_lib; -} - -#ifdef MS_WIN32 -/* See Don Box (german), pp 79ff. */ -EXPORT(void) GetString(BSTR *pbstr) -{ - *pbstr = SysAllocString(L"Goodbye!"); -} -#endif - -/* - * Some do-nothing functions, for speed tests - */ -PyObject *py_func_si(PyObject *self, PyObject *args) -{ - char *name; - int i; - if (!PyArg_ParseTuple(args, "si", &name, &i)) - return NULL; - Py_INCREF(Py_None); - return Py_None; -} - -EXPORT(void) _py_func_si(char *s, int i) -{ -} - -PyObject *py_func(PyObject *self, PyObject *args) -{ - Py_INCREF(Py_None); - return Py_None; -} - -EXPORT(void) _py_func(void) -{ -} - -EXPORT(long long) last_tf_arg_s; -EXPORT(unsigned long long) last_tf_arg_u; - -struct BITS { - int A: 1, B:2, C:3, D:4, E: 5, F: 6, G: 7, H: 8, I: 9; - short M: 1, N: 2, O: 3, P: 4, Q: 5, R: 6, S: 7; -}; - -EXPORT(void) set_bitfields(struct BITS *bits, char name, int value) -{ - switch (name) { - case 'A': bits->A = value; break; - case 'B': bits->B = value; break; - case 'C': bits->C = value; break; - case 'D': bits->D = value; break; - case 'E': bits->E = value; break; - case 'F': bits->F = value; break; - case 'G': bits->G = value; break; - case 'H': bits->H = value; break; - case 'I': bits->I = value; break; - - case 'M': bits->M = value; break; - case 'N': bits->N = value; break; - case 'O': bits->O = value; break; - case 'P': bits->P = value; break; - case 'Q': bits->Q = value; break; - case 'R': bits->R = value; break; - case 'S': bits->S = value; break; - } -} - -EXPORT(int) unpack_bitfields(struct BITS *bits, char name) -{ - switch (name) { - case 'A': return bits->A; - case 'B': return bits->B; - case 'C': return bits->C; - case 'D': return bits->D; - case 'E': return bits->E; - case 'F': return bits->F; - case 'G': return bits->G; - case 'H': return bits->H; - case 'I': return bits->I; - - case 'M': return bits->M; - case 'N': return bits->N; - case 'O': return bits->O; - case 'P': return bits->P; - case 'Q': return bits->Q; - case 'R': return bits->R; - case 'S': return bits->S; - } - return 0; -} - -static PyMethodDef module_methods[] = { -/* {"get_last_tf_arg_s", get_last_tf_arg_s, METH_NOARGS}, - {"get_last_tf_arg_u", get_last_tf_arg_u, METH_NOARGS}, -*/ - {"func_si", py_func_si, METH_VARARGS}, - {"func", py_func, METH_NOARGS}, - { NULL, NULL, 0, NULL}, -}; - -#define S last_tf_arg_s = (long long)c -#define U last_tf_arg_u = (unsigned long long)c - -EXPORT(signed char) tf_b(signed char c) { S; return c/3; } -EXPORT(unsigned char) tf_B(unsigned char c) { U; return c/3; } -EXPORT(short) tf_h(short c) { S; return c/3; } -EXPORT(unsigned short) tf_H(unsigned short c) { U; return c/3; } -EXPORT(int) tf_i(int c) { S; return c/3; } -EXPORT(unsigned int) tf_I(unsigned int c) { U; return c/3; } -EXPORT(long) tf_l(long c) { S; return c/3; } -EXPORT(unsigned long) tf_L(unsigned long c) { U; return c/3; } -EXPORT(long long) tf_q(long long c) { S; return c/3; } -EXPORT(unsigned long long) tf_Q(unsigned long long c) { U; return c/3; } -EXPORT(float) tf_f(float c) { S; return c/3; } -EXPORT(double) tf_d(double c) { S; return c/3; } -EXPORT(long double) tf_D(long double c) { S; return c/3; } - -#ifdef MS_WIN32 -EXPORT(signed char) __stdcall s_tf_b(signed char c) { S; return c/3; } -EXPORT(unsigned char) __stdcall s_tf_B(unsigned char c) { U; return c/3; } -EXPORT(short) __stdcall s_tf_h(short c) { S; return c/3; } -EXPORT(unsigned short) __stdcall s_tf_H(unsigned short c) { U; return c/3; } -EXPORT(int) __stdcall s_tf_i(int c) { S; return c/3; } -EXPORT(unsigned int) __stdcall s_tf_I(unsigned int c) { U; return c/3; } -EXPORT(long) __stdcall s_tf_l(long c) { S; return c/3; } -EXPORT(unsigned long) __stdcall s_tf_L(unsigned long c) { U; return c/3; } -EXPORT(long long) __stdcall s_tf_q(long long c) { S; return c/3; } -EXPORT(unsigned long long) __stdcall s_tf_Q(unsigned long long c) { U; return c/3; } -EXPORT(float) __stdcall s_tf_f(float c) { S; return c/3; } -EXPORT(double) __stdcall s_tf_d(double c) { S; return c/3; } -EXPORT(long double) __stdcall s_tf_D(long double c) { S; return c/3; } -#endif -/*******/ - -EXPORT(signed char) tf_bb(signed char x, signed char c) { S; return c/3; } -EXPORT(unsigned char) tf_bB(signed char x, unsigned char c) { U; return c/3; } -EXPORT(short) tf_bh(signed char x, short c) { S; return c/3; } -EXPORT(unsigned short) tf_bH(signed char x, unsigned short c) { U; return c/3; } -EXPORT(int) tf_bi(signed char x, int c) { S; return c/3; } -EXPORT(unsigned int) tf_bI(signed char x, unsigned int c) { U; return c/3; } -EXPORT(long) tf_bl(signed char x, long c) { S; return c/3; } -EXPORT(unsigned long) tf_bL(signed char x, unsigned long c) { U; return c/3; } -EXPORT(long long) tf_bq(signed char x, long long c) { S; return c/3; } -EXPORT(unsigned long long) tf_bQ(signed char x, unsigned long long c) { U; return c/3; } -EXPORT(float) tf_bf(signed char x, float c) { S; return c/3; } -EXPORT(double) tf_bd(signed char x, double c) { S; return c/3; } -EXPORT(long double) tf_bD(signed char x, long double c) { S; return c/3; } -EXPORT(void) tv_i(int c) { S; return; } - -#ifdef MS_WIN32 -EXPORT(signed char) __stdcall s_tf_bb(signed char x, signed char c) { S; return c/3; } -EXPORT(unsigned char) __stdcall s_tf_bB(signed char x, unsigned char c) { U; return c/3; } -EXPORT(short) __stdcall s_tf_bh(signed char x, short c) { S; return c/3; } -EXPORT(unsigned short) __stdcall s_tf_bH(signed char x, unsigned short c) { U; return c/3; } -EXPORT(int) __stdcall s_tf_bi(signed char x, int c) { S; return c/3; } -EXPORT(unsigned int) __stdcall s_tf_bI(signed char x, unsigned int c) { U; return c/3; } -EXPORT(long) __stdcall s_tf_bl(signed char x, long c) { S; return c/3; } -EXPORT(unsigned long) __stdcall s_tf_bL(signed char x, unsigned long c) { U; return c/3; } -EXPORT(long long) __stdcall s_tf_bq(signed char x, long long c) { S; return c/3; } -EXPORT(unsigned long long) __stdcall s_tf_bQ(signed char x, unsigned long long c) { U; return c/3; } -EXPORT(float) __stdcall s_tf_bf(signed char x, float c) { S; return c/3; } -EXPORT(double) __stdcall s_tf_bd(signed char x, double c) { S; return c/3; } -EXPORT(long double) __stdcall s_tf_bD(signed char x, long double c) { S; return c/3; } -EXPORT(void) __stdcall s_tv_i(int c) { S; return; } -#endif - -/********/ - -#ifndef MS_WIN32 - -typedef struct { - long x; - long y; -} POINT; - -typedef struct { - long left; - long top; - long right; - long bottom; -} RECT; - -#endif - -EXPORT(int) PointInRect(RECT *prc, POINT pt) -{ - if (pt.x < prc->left) - return 0; - if (pt.x > prc->right) - return 0; - if (pt.y < prc->top) - return 0; - if (pt.y > prc->bottom) - return 0; - return 1; -} - -EXPORT(long left = 10); -EXPORT(long top = 20); -EXPORT(long right = 30); -EXPORT(long bottom = 40); - -EXPORT(RECT) ReturnRect(int i, RECT ar, RECT* br, POINT cp, RECT dr, - RECT *er, POINT fp, RECT gr) -{ - /*Check input */ - if (ar.left + br->left + dr.left + er->left + gr.left != left * 5) - { - ar.left = 100; - return ar; - } - if (ar.right + br->right + dr.right + er->right + gr.right != right * 5) - { - ar.right = 100; - return ar; - } - if (cp.x != fp.x) - { - ar.left = -100; - } - if (cp.y != fp.y) - { - ar.left = -200; - } - switch(i) - { - case 0: - return ar; - break; - case 1: - return dr; - break; - case 2: - return gr; - break; - - } - return ar; -} - -typedef struct { - short x; - short y; -} S2H; - -EXPORT(S2H) ret_2h_func(S2H inp) -{ - inp.x *= 2; - inp.y *= 3; - return inp; -} - -typedef struct { - int a, b, c, d, e, f, g, h; -} S8I; - -EXPORT(S8I) ret_8i_func(S8I inp) -{ - inp.a *= 2; - inp.b *= 3; - inp.c *= 4; - inp.d *= 5; - inp.e *= 6; - inp.f *= 7; - inp.g *= 8; - inp.h *= 9; - return inp; -} - -EXPORT(int) GetRectangle(int flag, RECT *prect) -{ - if (flag == 0) - return 0; - prect->left = (int)flag; - prect->top = (int)flag + 1; - prect->right = (int)flag + 2; - prect->bottom = (int)flag + 3; - return 1; -} - -EXPORT(void) TwoOutArgs(int a, int *pi, int b, int *pj) -{ - *pi += a; - *pj += b; -} - -#ifdef MS_WIN32 - -typedef struct { - char f1; -} Size1; - -typedef struct { - char f1; - char f2; -} Size2; - -typedef struct { - char f1; - char f2; - char f3; -} Size3; - -typedef struct { - char f1; - char f2; - char f3; - char f4; -} Size4; - -typedef struct { - char f1; - char f2; - char f3; - char f4; - char f5; -} Size5; - -typedef struct { - char f1; - char f2; - char f3; - char f4; - char f5; - char f6; -} Size6; - -typedef struct { - char f1; - char f2; - char f3; - char f4; - char f5; - char f6; - char f7; -} Size7; - -typedef struct { - char f1; - char f2; - char f3; - char f4; - char f5; - char f6; - char f7; - char f8; -} Size8; - -typedef struct { - char f1; - char f2; - char f3; - char f4; - char f5; - char f6; - char f7; - char f8; - char f9; -} Size9; - -typedef struct { - char f1; - char f2; - char f3; - char f4; - char f5; - char f6; - char f7; - char f8; - char f9; - char f10; -} Size10; - -EXPORT(Size1) TestSize1() { - Size1 f; - f.f1 = 'a'; - return f; -} - -EXPORT(Size2) TestSize2() { - Size2 f; - f.f1 = 'a'; - f.f2 = 'b'; - return f; -} - -EXPORT(Size3) TestSize3() { - Size3 f; - f.f1 = 'a'; - f.f2 = 'b'; - f.f3 = 'c'; - return f; -} - -EXPORT(Size4) TestSize4() { - Size4 f; - f.f1 = 'a'; - f.f2 = 'b'; - f.f3 = 'c'; - f.f4 = 'd'; - return f; -} - -EXPORT(Size5) TestSize5() { - Size5 f; - f.f1 = 'a'; - f.f2 = 'b'; - f.f3 = 'c'; - f.f4 = 'd'; - f.f5 = 'e'; - return f; -} - -EXPORT(Size6) TestSize6() { - Size6 f; - f.f1 = 'a'; - f.f2 = 'b'; - f.f3 = 'c'; - f.f4 = 'd'; - f.f5 = 'e'; - f.f6 = 'f'; - return f; -} - -EXPORT(Size7) TestSize7() { - Size7 f; - f.f1 = 'a'; - f.f2 = 'b'; - f.f3 = 'c'; - f.f4 = 'd'; - f.f5 = 'e'; - f.f6 = 'f'; - f.f7 = 'g'; - return f; -} - -EXPORT(Size8) TestSize8() { - Size8 f; - f.f1 = 'a'; - f.f2 = 'b'; - f.f3 = 'c'; - f.f4 = 'd'; - f.f5 = 'e'; - f.f6 = 'f'; - f.f7 = 'g'; - f.f8 = 'h'; - return f; -} - -EXPORT(Size9) TestSize9() { - Size9 f; - f.f1 = 'a'; - f.f2 = 'b'; - f.f3 = 'c'; - f.f4 = 'd'; - f.f5 = 'e'; - f.f6 = 'f'; - f.f7 = 'g'; - f.f8 = 'h'; - f.f9 = 'i'; - return f; -} - -EXPORT(Size10) TestSize10() { - Size10 f; - f.f1 = 'a'; - f.f2 = 'b'; - f.f3 = 'c'; - f.f4 = 'd'; - f.f5 = 'e'; - f.f6 = 'f'; - f.f7 = 'g'; - f.f8 = 'h'; - f.f9 = 'i'; - f.f10 = 'j'; - return f; -} - -#endif - -#ifdef MS_WIN32 -EXPORT(S2H) __stdcall s_ret_2h_func(S2H inp) { return ret_2h_func(inp); } -EXPORT(S8I) __stdcall s_ret_8i_func(S8I inp) { return ret_8i_func(inp); } -#endif - -#ifdef MS_WIN32 -/* Should port this */ -#include -#include - -EXPORT (HRESULT) KeepObject(IUnknown *punk) -{ - static IUnknown *pobj; - if (punk) - punk->lpVtbl->AddRef(punk); - if (pobj) - pobj->lpVtbl->Release(pobj); - pobj = punk; - return S_OK; -} - -#endif - - -static struct PyModuleDef _ctypes_testmodule = { - PyModuleDef_HEAD_INIT, - "_ctypes_test", - NULL, - -1, - module_methods, - NULL, - NULL, - NULL, - NULL -}; - -PyMODINIT_FUNC -PyInit__ctypes_test(void) -{ - return PyModule_Create(&_ctypes_testmodule); -} diff --git a/third_party/python/Modules/_ctypes/_ctypes_test.h b/third_party/python/Modules/_ctypes/_ctypes_test.h deleted file mode 100644 index dfcf2d6a6..000000000 --- a/third_party/python/Modules/_ctypes/_ctypes_test.h +++ /dev/null @@ -1,2 +0,0 @@ -/* clang-format off */ -extern int _testfunc_i_bhilfd(char b, short h, int i, long l, float f, double d); diff --git a/third_party/python/Modules/_ctypes/callbacks.c b/third_party/python/Modules/_ctypes/callbacks.c deleted file mode 100644 index 87dd8055d..000000000 --- a/third_party/python/Modules/_ctypes/callbacks.c +++ /dev/null @@ -1,589 +0,0 @@ -/* clang-format off */ -#include "Python.h" -#include "frameobject.h" - -#include -#ifdef MS_WIN32 -#include -#endif -#include "ctypes.h" - -/**************************************************************/ - -static void -CThunkObject_dealloc(PyObject *myself) -{ - CThunkObject *self = (CThunkObject *)myself; - PyObject_GC_UnTrack(self); - Py_XDECREF(self->converters); - Py_XDECREF(self->callable); - Py_XDECREF(self->restype); - if (self->pcl_write) - ffi_closure_free(self->pcl_write); - PyObject_GC_Del(self); -} - -static int -CThunkObject_traverse(PyObject *myself, visitproc visit, void *arg) -{ - CThunkObject *self = (CThunkObject *)myself; - Py_VISIT(self->converters); - Py_VISIT(self->callable); - Py_VISIT(self->restype); - return 0; -} - -static int -CThunkObject_clear(PyObject *myself) -{ - CThunkObject *self = (CThunkObject *)myself; - Py_CLEAR(self->converters); - Py_CLEAR(self->callable); - Py_CLEAR(self->restype); - return 0; -} - -PyTypeObject PyCThunk_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_ctypes.CThunkObject", - sizeof(CThunkObject), /* tp_basicsize */ - sizeof(ffi_type), /* tp_itemsize */ - CThunkObject_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ - "CThunkObject", /* tp_doc */ - CThunkObject_traverse, /* tp_traverse */ - CThunkObject_clear, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ -}; - -/**************************************************************/ - -static void -PrintError(const char *msg, ...) -{ - char buf[512]; - PyObject *f = PySys_GetObject("stderr"); - va_list marker; - - va_start(marker, msg); - vsnprintf(buf, sizeof(buf), msg, marker); - va_end(marker); - if (f != NULL && f != Py_None) - PyFile_WriteString(buf, f); - PyErr_Print(); -} - - -#ifdef MS_WIN32 -/* - * We must call AddRef() on non-NULL COM pointers we receive as arguments - * to callback functions - these functions are COM method implementations. - * The Python instances we create have a __del__ method which calls Release(). - * - * The presence of a class attribute named '_needs_com_addref_' triggers this - * behaviour. It would also be possible to call the AddRef() Python method, - * after checking for PyObject_IsTrue(), but this would probably be somewhat - * slower. - */ -static void -TryAddRef(StgDictObject *dict, CDataObject *obj) -{ - IUnknown *punk; - - if (NULL == PyDict_GetItemString((PyObject *)dict, "_needs_com_addref_")) - return; - - punk = *(IUnknown **)obj->b_ptr; - if (punk) - punk->lpVtbl->AddRef(punk); - return; -} -#endif - -/****************************************************************************** - * - * Call the python object with all arguments - * - */ -static void _CallPythonObject(void *mem, - ffi_type *restype, - SETFUNC setfunc, - PyObject *callable, - PyObject *converters, - int flags, - void **pArgs) -{ - Py_ssize_t i; - PyObject *result; - PyObject *arglist = NULL; - Py_ssize_t nArgs; - PyObject *error_object = NULL; - int *space; -#ifdef WITH_THREAD - PyGILState_STATE state = PyGILState_Ensure(); -#endif - - nArgs = PySequence_Length(converters); - /* Hm. What to return in case of error? - For COM, 0xFFFFFFFF seems better than 0. - */ - if (nArgs < 0) { - PrintError("BUG: PySequence_Length"); - goto Done; - } - - arglist = PyTuple_New(nArgs); - if (!arglist) { - PrintError("PyTuple_New()"); - goto Done; - } - for (i = 0; i < nArgs; ++i) { - /* Note: new reference! */ - PyObject *cnv = PySequence_GetItem(converters, i); - StgDictObject *dict; - if (cnv) - dict = PyType_stgdict(cnv); - else { - PrintError("Getting argument converter %d\n", i); - goto Done; - } - - if (dict && dict->getfunc && !_ctypes_simple_instance(cnv)) { - PyObject *v = dict->getfunc(*pArgs, dict->size); - if (!v) { - PrintError("create argument %d:\n", i); - Py_DECREF(cnv); - goto Done; - } - PyTuple_SET_ITEM(arglist, i, v); - /* XXX XXX XX - We have the problem that c_byte or c_short have dict->size of - 1 resp. 4, but these parameters are pushed as sizeof(int) bytes. - BTW, the same problem occurs when they are pushed as parameters - */ - } else if (dict) { - /* Hm, shouldn't we use PyCData_AtAddress() or something like that instead? */ - CDataObject *obj = (CDataObject *)PyObject_CallFunctionObjArgs(cnv, NULL); - if (!obj) { - PrintError("create argument %d:\n", i); - Py_DECREF(cnv); - goto Done; - } - if (!CDataObject_Check(obj)) { - Py_DECREF(obj); - Py_DECREF(cnv); - PrintError("unexpected result of create argument %d:\n", i); - goto Done; - } - memcpy(obj->b_ptr, *pArgs, dict->size); - PyTuple_SET_ITEM(arglist, i, (PyObject *)obj); -#ifdef MS_WIN32 - TryAddRef(dict, obj); -#endif - } else { - PyErr_SetString(PyExc_TypeError, - "cannot build parameter"); - PrintError("Parsing argument %d\n", i); - Py_DECREF(cnv); - goto Done; - } - Py_DECREF(cnv); - /* XXX error handling! */ - pArgs++; - } - -#define CHECK(what, x) \ -if (x == NULL) _PyTraceback_Add(what, "_ctypes/callbacks.c", __LINE__ - 1), PyErr_Print() - - if (flags & (FUNCFLAG_USE_ERRNO | FUNCFLAG_USE_LASTERROR)) { - error_object = _ctypes_get_errobj(&space); - if (error_object == NULL) - goto Done; - if (flags & FUNCFLAG_USE_ERRNO) { - int temp = space[0]; - space[0] = errno; - errno = temp; - } -#ifdef MS_WIN32 - if (flags & FUNCFLAG_USE_LASTERROR) { - int temp = space[1]; - space[1] = GetLastError(); - SetLastError(temp); - } -#endif - } - - result = PyObject_CallObject(callable, arglist); - CHECK("'calling callback function'", result); - -#ifdef MS_WIN32 - if (flags & FUNCFLAG_USE_LASTERROR) { - int temp = space[1]; - space[1] = GetLastError(); - SetLastError(temp); - } -#endif - if (flags & FUNCFLAG_USE_ERRNO) { - int temp = space[0]; - space[0] = errno; - errno = temp; - } - Py_XDECREF(error_object); - - if ((restype != &ffi_type_void) && result) { - PyObject *keep; - assert(setfunc); -#ifdef WORDS_BIGENDIAN - /* See the corresponding code in callproc.c, around line 961 */ - if (restype->type != FFI_TYPE_FLOAT && restype->size < sizeof(ffi_arg)) - mem = (char *)mem + sizeof(ffi_arg) - restype->size; -#endif - keep = setfunc(mem, result, 0); - CHECK("'converting callback result'", keep); - /* keep is an object we have to keep alive so that the result - stays valid. If there is no such object, the setfunc will - have returned Py_None. - - If there is such an object, we have no choice than to keep - it alive forever - but a refcount and/or memory leak will - be the result. EXCEPT when restype is py_object - Python - itself knows how to manage the refcount of these objects. - */ - if (keep == NULL) /* Could not convert callback result. */ - PyErr_WriteUnraisable(callable); - else if (keep == Py_None) /* Nothing to keep */ - Py_DECREF(keep); - else if (setfunc != _ctypes_get_fielddesc("O")->setfunc) { - if (-1 == PyErr_WarnEx(PyExc_RuntimeWarning, - "memory leak in callback function.", - 1)) - PyErr_WriteUnraisable(callable); - } - } - Py_XDECREF(result); - Done: - Py_XDECREF(arglist); -#ifdef WITH_THREAD - PyGILState_Release(state); -#endif -} - -static void closure_fcn(ffi_cif *cif, - void *resp, - void **args, - void *userdata) -{ - CThunkObject *p = (CThunkObject *)userdata; - - _CallPythonObject(resp, - p->ffi_restype, - p->setfunc, - p->callable, - p->converters, - p->flags, - args); -} - -static CThunkObject* CThunkObject_new(Py_ssize_t nArgs) -{ - CThunkObject *p; - Py_ssize_t i; - - p = PyObject_GC_NewVar(CThunkObject, &PyCThunk_Type, nArgs); - if (p == NULL) { - return NULL; - } - - p->pcl_write = NULL; - p->pcl_exec = NULL; - memset(&p->cif, 0, sizeof(p->cif)); - p->flags = 0; - p->converters = NULL; - p->callable = NULL; - p->restype = NULL; - p->setfunc = NULL; - p->ffi_restype = NULL; - - for (i = 0; i < nArgs + 1; ++i) - p->atypes[i] = NULL; - PyObject_GC_Track((PyObject *)p); - return p; -} - -CThunkObject *_ctypes_alloc_callback(PyObject *callable, - PyObject *converters, - PyObject *restype, - int flags) -{ - int result; - CThunkObject *p; - Py_ssize_t nArgs, i; - ffi_abi cc; - - nArgs = PySequence_Size(converters); - p = CThunkObject_new(nArgs); - if (p == NULL) - return NULL; - - assert(CThunk_CheckExact((PyObject *)p)); - - p->pcl_write = ffi_closure_alloc(sizeof(ffi_closure), - &p->pcl_exec); - if (p->pcl_write == NULL) { - PyErr_NoMemory(); - goto error; - } - - p->flags = flags; - for (i = 0; i < nArgs; ++i) { - PyObject *cnv = PySequence_GetItem(converters, i); - if (cnv == NULL) - goto error; - p->atypes[i] = _ctypes_get_ffi_type(cnv); - Py_DECREF(cnv); - } - p->atypes[i] = NULL; - - Py_INCREF(restype); - p->restype = restype; - if (restype == Py_None) { - p->setfunc = NULL; - p->ffi_restype = &ffi_type_void; - } else { - StgDictObject *dict = PyType_stgdict(restype); - if (dict == NULL || dict->setfunc == NULL) { - PyErr_SetString(PyExc_TypeError, - "invalid result type for callback function"); - goto error; - } - p->setfunc = dict->setfunc; - p->ffi_restype = &dict->ffi_type_pointer; - } - - cc = FFI_DEFAULT_ABI; -#if defined(MS_WIN32) && !defined(_WIN32_WCE) && !defined(MS_WIN64) - if ((flags & FUNCFLAG_CDECL) == 0) - cc = FFI_STDCALL; -#endif - result = ffi_prep_cif(&p->cif, cc, - Py_SAFE_DOWNCAST(nArgs, Py_ssize_t, int), - _ctypes_get_ffi_type(restype), - &p->atypes[0]); - if (result != FFI_OK) { - PyErr_Format(PyExc_RuntimeError, - "ffi_prep_cif failed with %d", result); - goto error; - } -#if defined(X86_DARWIN) || defined(POWERPC_DARWIN) - result = ffi_prep_closure(p->pcl_write, &p->cif, closure_fcn, p); -#else - result = ffi_prep_closure_loc(p->pcl_write, &p->cif, closure_fcn, - p, - p->pcl_exec); -#endif - if (result != FFI_OK) { - PyErr_Format(PyExc_RuntimeError, - "ffi_prep_closure failed with %d", result); - goto error; - } - - Py_INCREF(converters); - p->converters = converters; - Py_INCREF(callable); - p->callable = callable; - return p; - - error: - Py_XDECREF(p); - return NULL; -} - -#ifdef MS_WIN32 - -static void LoadPython(void) -{ - if (!Py_IsInitialized()) { -#ifdef WITH_THREAD - PyEval_InitThreads(); -#endif - Py_Initialize(); - } -} - -/******************************************************************/ - -long Call_GetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv) -{ - PyObject *mod, *func, *result; - long retval; - static PyObject *context; - - if (context == NULL) - context = PyUnicode_InternFromString("_ctypes.DllGetClassObject"); - - mod = PyImport_ImportModuleNoBlock("ctypes"); - if (!mod) { - PyErr_WriteUnraisable(context ? context : Py_None); - /* There has been a warning before about this already */ - return E_FAIL; - } - - func = PyObject_GetAttrString(mod, "DllGetClassObject"); - Py_DECREF(mod); - if (!func) { - PyErr_WriteUnraisable(context ? context : Py_None); - return E_FAIL; - } - - { - PyObject *py_rclsid = PyLong_FromVoidPtr((void *)rclsid); - PyObject *py_riid = PyLong_FromVoidPtr((void *)riid); - PyObject *py_ppv = PyLong_FromVoidPtr(ppv); - if (!py_rclsid || !py_riid || !py_ppv) { - Py_XDECREF(py_rclsid); - Py_XDECREF(py_riid); - Py_XDECREF(py_ppv); - Py_DECREF(func); - PyErr_WriteUnraisable(context ? context : Py_None); - return E_FAIL; - } - result = PyObject_CallFunctionObjArgs(func, - py_rclsid, - py_riid, - py_ppv, - NULL); - Py_DECREF(py_rclsid); - Py_DECREF(py_riid); - Py_DECREF(py_ppv); - } - Py_DECREF(func); - if (!result) { - PyErr_WriteUnraisable(context ? context : Py_None); - return E_FAIL; - } - - retval = PyLong_AsLong(result); - if (PyErr_Occurred()) { - PyErr_WriteUnraisable(context ? context : Py_None); - retval = E_FAIL; - } - Py_DECREF(result); - return retval; -} - -STDAPI DllGetClassObject(REFCLSID rclsid, - REFIID riid, - LPVOID *ppv) -{ - long result; -#ifdef WITH_THREAD - PyGILState_STATE state; -#endif - - LoadPython(); -#ifdef WITH_THREAD - state = PyGILState_Ensure(); -#endif - result = Call_GetClassObject(rclsid, riid, ppv); -#ifdef WITH_THREAD - PyGILState_Release(state); -#endif - return result; -} - -long Call_CanUnloadNow(void) -{ - PyObject *mod, *func, *result; - long retval; - static PyObject *context; - - if (context == NULL) - context = PyUnicode_InternFromString("_ctypes.DllCanUnloadNow"); - - mod = PyImport_ImportModuleNoBlock("ctypes"); - if (!mod) { -/* OutputDebugString("Could not import ctypes"); */ - /* We assume that this error can only occur when shutting - down, so we silently ignore it */ - PyErr_Clear(); - return E_FAIL; - } - /* Other errors cannot be raised, but are printed to stderr */ - func = PyObject_GetAttrString(mod, "DllCanUnloadNow"); - Py_DECREF(mod); - if (!func) { - PyErr_WriteUnraisable(context ? context : Py_None); - return E_FAIL; - } - - result = PyObject_CallFunction(func, NULL); - Py_DECREF(func); - if (!result) { - PyErr_WriteUnraisable(context ? context : Py_None); - return E_FAIL; - } - - retval = PyLong_AsLong(result); - if (PyErr_Occurred()) { - PyErr_WriteUnraisable(context ? context : Py_None); - retval = E_FAIL; - } - Py_DECREF(result); - return retval; -} - -/* - DllRegisterServer and DllUnregisterServer still missing -*/ - -STDAPI DllCanUnloadNow(void) -{ - long result; -#ifdef WITH_THREAD - PyGILState_STATE state = PyGILState_Ensure(); -#endif - result = Call_CanUnloadNow(); -#ifdef WITH_THREAD - PyGILState_Release(state); -#endif - return result; -} - -#ifndef Py_NO_ENABLE_SHARED -BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvRes) -{ - switch(fdwReason) { - case DLL_PROCESS_ATTACH: - DisableThreadLibraryCalls(hinstDLL); - break; - } - return TRUE; -} -#endif - -#endif - -/* - Local Variables: - compile-command: "cd .. && python setup.py -q build_ext" - End: -*/ diff --git a/third_party/python/Modules/_ctypes/callproc.c b/third_party/python/Modules/_ctypes/callproc.c deleted file mode 100644 index 5832a0ac9..000000000 --- a/third_party/python/Modules/_ctypes/callproc.c +++ /dev/null @@ -1,1836 +0,0 @@ -/* clang-format off */ -/* - * History: First version dated from 3/97, derived from my SCMLIB version - * for win16. - */ -/* - * Related Work: - * - calldll http://www.nightmare.com/software.html - * - libffi http://sourceware.cygnus.com/libffi/ - * - ffcall http://clisp.cons.org/~haible/packages-ffcall.html - * and, of course, Don Beaudry's MESS package, but this is more ctypes - * related. - */ - - -/* - How are functions called, and how are parameters converted to C ? - - 1. _ctypes.c::PyCFuncPtr_call receives an argument tuple 'inargs' and a - keyword dictionary 'kwds'. - - 2. After several checks, _build_callargs() is called which returns another - tuple 'callargs'. This may be the same tuple as 'inargs', a slice of - 'inargs', or a completely fresh tuple, depending on several things (is it a - COM method?, are 'paramflags' available?). - - 3. _build_callargs also calculates bitarrays containing indexes into - the callargs tuple, specifying how to build the return value(s) of - the function. - - 4. _ctypes_callproc is then called with the 'callargs' tuple. _ctypes_callproc first - allocates two arrays. The first is an array of 'struct argument' items, the - second array has 'void *' entries. - - 5. If 'converters' are present (converters is a sequence of argtypes' - from_param methods), for each item in 'callargs' converter is called and the - result passed to ConvParam. If 'converters' are not present, each argument - is directly passed to ConvParm. - - 6. For each arg, ConvParam stores the contained C data (or a pointer to it, - for structures) into the 'struct argument' array. - - 7. Finally, a loop fills the 'void *' array so that each item points to the - data contained in or pointed to by the 'struct argument' array. - - 8. The 'void *' argument array is what _call_function_pointer - expects. _call_function_pointer then has very little to do - only some - libffi specific stuff, then it calls ffi_call. - - So, there are 4 data structures holding processed arguments: - - the inargs tuple (in PyCFuncPtr_call) - - the callargs tuple (in PyCFuncPtr_call) - - the 'struct arguments' array - - the 'void *' array - - */ - -#include "Python.h" -#include "structmember.h" - -#ifdef MS_WIN32 -#include -#include -#else -#include "ctypes_dlfcn.h" -#endif - -#ifdef MS_WIN32 -#include -#endif - -#include -#include "ctypes.h" -#ifdef HAVE_ALLOCA_H -/* AIX needs alloca.h for alloca() */ -#include -#endif - -#ifdef _Py_MEMORY_SANITIZER -#include -#endif - -#if defined(_DEBUG) || defined(__MINGW32__) -/* Don't use structured exception handling on Windows if this is defined. - MingW, AFAIK, doesn't support it. -*/ -#define DONT_USE_SEH -#endif - -#define CTYPES_CAPSULE_NAME_PYMEM "_ctypes pymem" - -static void pymem_destructor(PyObject *ptr) -{ - void *p = PyCapsule_GetPointer(ptr, CTYPES_CAPSULE_NAME_PYMEM); - if (p) { - PyMem_Free(p); - } -} - -/* - ctypes maintains thread-local storage that has space for two error numbers: - private copies of the system 'errno' value and, on Windows, the system error code - accessed by the GetLastError() and SetLastError() api functions. - - Foreign functions created with CDLL(..., use_errno=True), when called, swap - the system 'errno' value with the private copy just before the actual - function call, and swapped again immediately afterwards. The 'use_errno' - parameter defaults to False, in this case 'ctypes_errno' is not touched. - - On Windows, foreign functions created with CDLL(..., use_last_error=True) or - WinDLL(..., use_last_error=True) swap the system LastError value with the - ctypes private copy. - - The values are also swapped immeditately before and after ctypes callback - functions are called, if the callbacks are constructed using the new - optional use_errno parameter set to True: CFUNCTYPE(..., use_errno=TRUE) or - WINFUNCTYPE(..., use_errno=True). - - New ctypes functions are provided to access the ctypes private copies from - Python: - - - ctypes.set_errno(value) and ctypes.set_last_error(value) store 'value' in - the private copy and returns the previous value. - - - ctypes.get_errno() and ctypes.get_last_error() returns the current ctypes - private copies value. -*/ - -/* - This function creates and returns a thread-local Python object that has - space to store two integer error numbers; once created the Python object is - kept alive in the thread state dictionary as long as the thread itself. -*/ -PyObject * -_ctypes_get_errobj(int **pspace) -{ - PyObject *dict = PyThreadState_GetDict(); - PyObject *errobj; - static PyObject *error_object_name; - if (dict == 0) { - PyErr_SetString(PyExc_RuntimeError, - "cannot get thread state"); - return NULL; - } - if (error_object_name == NULL) { - error_object_name = PyUnicode_InternFromString("ctypes.error_object"); - if (error_object_name == NULL) - return NULL; - } - errobj = PyDict_GetItem(dict, error_object_name); - if (errobj) { - if (!PyCapsule_IsValid(errobj, CTYPES_CAPSULE_NAME_PYMEM)) { - PyErr_SetString(PyExc_RuntimeError, - "ctypes.error_object is an invalid capsule"); - return NULL; - } - Py_INCREF(errobj); - } - else { - void *space = PyMem_Malloc(sizeof(int) * 2); - if (space == NULL) - return NULL; - memset(space, 0, sizeof(int) * 2); - errobj = PyCapsule_New(space, CTYPES_CAPSULE_NAME_PYMEM, pymem_destructor); - if (errobj == NULL) { - PyMem_Free(space); - return NULL; - } - if (-1 == PyDict_SetItem(dict, error_object_name, - errobj)) { - Py_DECREF(errobj); - return NULL; - } - } - *pspace = (int *)PyCapsule_GetPointer(errobj, CTYPES_CAPSULE_NAME_PYMEM); - return errobj; -} - -static PyObject * -get_error_internal(PyObject *self, PyObject *args, int index) -{ - int *space; - PyObject *errobj = _ctypes_get_errobj(&space); - PyObject *result; - - if (errobj == NULL) - return NULL; - result = PyLong_FromLong(space[index]); - Py_DECREF(errobj); - return result; -} - -static PyObject * -set_error_internal(PyObject *self, PyObject *args, int index) -{ - int new_errno, old_errno; - PyObject *errobj; - int *space; - - if (!PyArg_ParseTuple(args, "i", &new_errno)) - return NULL; - errobj = _ctypes_get_errobj(&space); - if (errobj == NULL) - return NULL; - old_errno = space[index]; - space[index] = new_errno; - Py_DECREF(errobj); - return PyLong_FromLong(old_errno); -} - -static PyObject * -get_errno(PyObject *self, PyObject *args) -{ - return get_error_internal(self, args, 0); -} - -static PyObject * -set_errno(PyObject *self, PyObject *args) -{ - return set_error_internal(self, args, 0); -} - -#ifdef MS_WIN32 - -static PyObject * -get_last_error(PyObject *self, PyObject *args) -{ - return get_error_internal(self, args, 1); -} - -static PyObject * -set_last_error(PyObject *self, PyObject *args) -{ - return set_error_internal(self, args, 1); -} - -PyObject *ComError; - -static WCHAR *FormatError(DWORD code) -{ - WCHAR *lpMsgBuf; - DWORD n; - n = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - code, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */ - (LPWSTR) &lpMsgBuf, - 0, - NULL); - if (n) { - while (iswspace(lpMsgBuf[n-1])) - --n; - lpMsgBuf[n] = L'\0'; /* rstrip() */ - } - return lpMsgBuf; -} - -#ifndef DONT_USE_SEH -static void SetException(DWORD code, EXCEPTION_RECORD *pr) -{ - /* The 'code' is a normal win32 error code so it could be handled by - PyErr_SetFromWindowsErr(). However, for some errors, we have additional - information not included in the error code. We handle those here and - delegate all others to the generic function. */ - switch (code) { - case EXCEPTION_ACCESS_VIOLATION: - /* The thread attempted to read from or write - to a virtual address for which it does not - have the appropriate access. */ - if (pr->ExceptionInformation[0] == 0) - PyErr_Format(PyExc_OSError, - "exception: access violation reading %p", - pr->ExceptionInformation[1]); - else - PyErr_Format(PyExc_OSError, - "exception: access violation writing %p", - pr->ExceptionInformation[1]); - break; - - case EXCEPTION_BREAKPOINT: - /* A breakpoint was encountered. */ - PyErr_SetString(PyExc_OSError, - "exception: breakpoint encountered"); - break; - - case EXCEPTION_DATATYPE_MISALIGNMENT: - /* The thread attempted to read or write data that is - misaligned on hardware that does not provide - alignment. For example, 16-bit values must be - aligned on 2-byte boundaries, 32-bit values on - 4-byte boundaries, and so on. */ - PyErr_SetString(PyExc_OSError, - "exception: datatype misalignment"); - break; - - case EXCEPTION_SINGLE_STEP: - /* A trace trap or other single-instruction mechanism - signaled that one instruction has been executed. */ - PyErr_SetString(PyExc_OSError, - "exception: single step"); - break; - - case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: - /* The thread attempted to access an array element - that is out of bounds, and the underlying hardware - supports bounds checking. */ - PyErr_SetString(PyExc_OSError, - "exception: array bounds exceeded"); - break; - - case EXCEPTION_FLT_DENORMAL_OPERAND: - /* One of the operands in a floating-point operation - is denormal. A denormal value is one that is too - small to represent as a standard floating-point - value. */ - PyErr_SetString(PyExc_OSError, - "exception: floating-point operand denormal"); - break; - - case EXCEPTION_FLT_DIVIDE_BY_ZERO: - /* The thread attempted to divide a floating-point - value by a floating-point divisor of zero. */ - PyErr_SetString(PyExc_OSError, - "exception: float divide by zero"); - break; - - case EXCEPTION_FLT_INEXACT_RESULT: - /* The result of a floating-point operation cannot be - represented exactly as a decimal fraction. */ - PyErr_SetString(PyExc_OSError, - "exception: float inexact"); - break; - - case EXCEPTION_FLT_INVALID_OPERATION: - /* This exception represents any floating-point - exception not included in this list. */ - PyErr_SetString(PyExc_OSError, - "exception: float invalid operation"); - break; - - case EXCEPTION_FLT_OVERFLOW: - /* The exponent of a floating-point operation is - greater than the magnitude allowed by the - corresponding type. */ - PyErr_SetString(PyExc_OSError, - "exception: float overflow"); - break; - - case EXCEPTION_FLT_STACK_CHECK: - /* The stack overflowed or underflowed as the result - of a floating-point operation. */ - PyErr_SetString(PyExc_OSError, - "exception: stack over/underflow"); - break; - - case EXCEPTION_STACK_OVERFLOW: - /* The stack overflowed or underflowed as the result - of a floating-point operation. */ - PyErr_SetString(PyExc_OSError, - "exception: stack overflow"); - break; - - case EXCEPTION_FLT_UNDERFLOW: - /* The exponent of a floating-point operation is less - than the magnitude allowed by the corresponding - type. */ - PyErr_SetString(PyExc_OSError, - "exception: float underflow"); - break; - - case EXCEPTION_INT_DIVIDE_BY_ZERO: - /* The thread attempted to divide an integer value by - an integer divisor of zero. */ - PyErr_SetString(PyExc_OSError, - "exception: integer divide by zero"); - break; - - case EXCEPTION_INT_OVERFLOW: - /* The result of an integer operation caused a carry - out of the most significant bit of the result. */ - PyErr_SetString(PyExc_OSError, - "exception: integer overflow"); - break; - - case EXCEPTION_PRIV_INSTRUCTION: - /* The thread attempted to execute an instruction - whose operation is not allowed in the current - machine mode. */ - PyErr_SetString(PyExc_OSError, - "exception: privileged instruction"); - break; - - case EXCEPTION_NONCONTINUABLE_EXCEPTION: - /* The thread attempted to continue execution after a - noncontinuable exception occurred. */ - PyErr_SetString(PyExc_OSError, - "exception: nocontinuable"); - break; - - default: - PyErr_SetFromWindowsErr(code); - break; - } -} - -static DWORD HandleException(EXCEPTION_POINTERS *ptrs, - DWORD *pdw, EXCEPTION_RECORD *record) -{ - *pdw = ptrs->ExceptionRecord->ExceptionCode; - *record = *ptrs->ExceptionRecord; - /* We don't want to catch breakpoint exceptions, they are used to attach - * a debugger to the process. - */ - if (*pdw == EXCEPTION_BREAKPOINT) - return EXCEPTION_CONTINUE_SEARCH; - return EXCEPTION_EXECUTE_HANDLER; -} -#endif - -static PyObject * -check_hresult(PyObject *self, PyObject *args) -{ - HRESULT hr; - if (!PyArg_ParseTuple(args, "i", &hr)) - return NULL; - if (FAILED(hr)) - return PyErr_SetFromWindowsErr(hr); - return PyLong_FromLong(hr); -} - -#endif - -/**************************************************************/ - -PyCArgObject * -PyCArgObject_new(void) -{ - PyCArgObject *p; - p = PyObject_New(PyCArgObject, &PyCArg_Type); - if (p == NULL) - return NULL; - p->pffi_type = NULL; - p->tag = '\0'; - p->obj = NULL; - memset(&p->value, 0, sizeof(p->value)); - return p; -} - -static void -PyCArg_dealloc(PyCArgObject *self) -{ - Py_XDECREF(self->obj); - PyObject_Del(self); -} - -static int -is_literal_char(unsigned char c) -{ - return c < 128 && _PyUnicode_IsPrintable(c) && c != '\\' && c != '\''; -} - -static PyObject * -PyCArg_repr(PyCArgObject *self) -{ - switch(self->tag) { - case 'b': - case 'B': - return PyUnicode_FromFormat("", - self->tag, self->value.b); - case 'h': - case 'H': - return PyUnicode_FromFormat("", - self->tag, self->value.h); - case 'i': - case 'I': - return PyUnicode_FromFormat("", - self->tag, self->value.i); - case 'l': - case 'L': - return PyUnicode_FromFormat("", - self->tag, self->value.l); - - case 'q': - case 'Q': - return PyUnicode_FromFormat("", - self->tag, self->value.q); - case 'd': - case 'f': { - PyObject *f = PyFloat_FromDouble((self->tag == 'f') ? self->value.f : self->value.d); - if (f == NULL) { - return NULL; - } - PyObject *result = PyUnicode_FromFormat("", self->tag, f); - Py_DECREF(f); - return result; - } - case 'c': - if (is_literal_char((unsigned char)self->value.c)) { - return PyUnicode_FromFormat("", - self->tag, self->value.c); - } - else { - return PyUnicode_FromFormat("", - self->tag, (unsigned char)self->value.c); - } - -/* Hm, are these 'z' and 'Z' codes useful at all? - Shouldn't they be replaced by the functionality of c_string - and c_wstring ? -*/ - case 'z': - case 'Z': - case 'P': - return PyUnicode_FromFormat("", - self->tag, self->value.p); - break; - - default: - if (is_literal_char((unsigned char)self->tag)) { - return PyUnicode_FromFormat("", - (unsigned char)self->tag, (void *)self); - } - else { - return PyUnicode_FromFormat("", - (unsigned char)self->tag, (void *)self); - } - } -} - -static PyMemberDef PyCArgType_members[] = { - { "_obj", T_OBJECT, - offsetof(PyCArgObject, obj), READONLY, - "the wrapped object" }, - { NULL }, -}; - -PyTypeObject PyCArg_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "CArgObject", - sizeof(PyCArgObject), - 0, - (destructor)PyCArg_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)PyCArg_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - 0, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - PyCArgType_members, /* tp_members */ -}; - -/****************************************************************/ -/* - * Convert a PyObject * into a parameter suitable to pass to an - * C function call. - * - * 1. Python integers are converted to C int and passed by value. - * Py_None is converted to a C NULL pointer. - * - * 2. 3-tuples are expected to have a format character in the first - * item, which must be 'i', 'f', 'd', 'q', or 'P'. - * The second item will have to be an integer, float, double, long long - * or integer (denoting an address void *), will be converted to the - * corresponding C data type and passed by value. - * - * 3. Other Python objects are tested for an '_as_parameter_' attribute. - * The value of this attribute must be an integer which will be passed - * by value, or a 2-tuple or 3-tuple which will be used according - * to point 2 above. The third item (if any), is ignored. It is normally - * used to keep the object alive where this parameter refers to. - * XXX This convention is dangerous - you can construct arbitrary tuples - * in Python and pass them. Would it be safer to use a custom container - * datatype instead of a tuple? - * - * 4. Other Python objects cannot be passed as parameters - an exception is raised. - * - * 5. ConvParam will store the converted result in a struct containing format - * and value. - */ - -union result { - char c; - char b; - short h; - int i; - long l; - long long q; - long double D; - double d; - float f; - void *p; -}; - -struct argument { - ffi_type *ffi_type; - PyObject *keep; - union result value; -}; - -/* - * Convert a single Python object into a PyCArgObject and return it. - */ -static int ConvParam(PyObject *obj, Py_ssize_t index, struct argument *pa) -{ - StgDictObject *dict; - pa->keep = NULL; /* so we cannot forget it later */ - - dict = PyObject_stgdict(obj); - if (dict) { - PyCArgObject *carg; - assert(dict->paramfunc); - /* If it has an stgdict, it is a CDataObject */ - carg = dict->paramfunc((CDataObject *)obj); - if (carg == NULL) - return -1; - pa->ffi_type = carg->pffi_type; - memcpy(&pa->value, &carg->value, sizeof(pa->value)); - pa->keep = (PyObject *)carg; - return 0; - } - - if (PyCArg_CheckExact(obj)) { - PyCArgObject *carg = (PyCArgObject *)obj; - pa->ffi_type = carg->pffi_type; - Py_INCREF(obj); - pa->keep = obj; - memcpy(&pa->value, &carg->value, sizeof(pa->value)); - return 0; - } - - /* check for None, integer, string or unicode and use directly if successful */ - if (obj == Py_None) { - pa->ffi_type = &ffi_type_pointer; - pa->value.p = NULL; - return 0; - } - - if (PyLong_Check(obj)) { - pa->ffi_type = &ffi_type_sint; - pa->value.i = (long)PyLong_AsUnsignedLong(obj); - if (pa->value.i == -1 && PyErr_Occurred()) { - PyErr_Clear(); - pa->value.i = PyLong_AsLong(obj); - if (pa->value.i == -1 && PyErr_Occurred()) { - PyErr_SetString(PyExc_OverflowError, - "int too long to convert"); - return -1; - } - } - return 0; - } - - if (PyBytes_Check(obj)) { - pa->ffi_type = &ffi_type_pointer; - pa->value.p = PyBytes_AsString(obj); - Py_INCREF(obj); - pa->keep = obj; - return 0; - } - -#ifdef CTYPES_UNICODE - if (PyUnicode_Check(obj)) { - pa->ffi_type = &ffi_type_pointer; - pa->value.p = _PyUnicode_AsWideCharString(obj); - if (pa->value.p == NULL) - return -1; - pa->keep = PyCapsule_New(pa->value.p, CTYPES_CAPSULE_NAME_PYMEM, pymem_destructor); - if (!pa->keep) { - PyMem_Free(pa->value.p); - return -1; - } - return 0; - } -#endif - - { - PyObject *arg; - arg = PyObject_GetAttrString(obj, "_as_parameter_"); - /* Which types should we exactly allow here? - integers are required for using Python classes - as parameters (they have to expose the '_as_parameter_' - attribute) - */ - if (arg) { - int result; - result = ConvParam(arg, index, pa); - Py_DECREF(arg); - return result; - } - PyErr_Format(PyExc_TypeError, - "Don't know how to convert parameter %d", - Py_SAFE_DOWNCAST(index, Py_ssize_t, int)); - return -1; - } -} - - -ffi_type *_ctypes_get_ffi_type(PyObject *obj) -{ - StgDictObject *dict; - if (obj == NULL) - return &ffi_type_sint; - dict = PyType_stgdict(obj); - if (dict == NULL) - return &ffi_type_sint; -#if defined(MS_WIN32) && !defined(_WIN32_WCE) - /* This little trick works correctly with MSVC. - It returns small structures in registers - */ - if (dict->ffi_type_pointer.type == FFI_TYPE_STRUCT) { - if (can_return_struct_as_int(dict->ffi_type_pointer.size)) - return &ffi_type_sint32; - else if (can_return_struct_as_sint64 (dict->ffi_type_pointer.size)) - return &ffi_type_sint64; - } -#endif - return &dict->ffi_type_pointer; -} - - -/* - * libffi uses: - * - * ffi_status ffi_prep_cif(ffi_cif *cif, ffi_abi abi, - * unsigned int nargs, - * ffi_type *rtype, - * ffi_type **atypes); - * - * and then - * - * void ffi_call(ffi_cif *cif, void *fn, void *rvalue, void **avalues); - */ -static int _call_function_pointer(int flags, - PPROC pProc, - void **avalues, - ffi_type **atypes, - ffi_type *restype, - void *resmem, - int argcount) -{ -#ifdef WITH_THREAD - PyThreadState *_save = NULL; /* For Py_BLOCK_THREADS and Py_UNBLOCK_THREADS */ -#endif - PyObject *error_object = NULL; - int *space; - ffi_cif cif; - int cc; -#ifdef MS_WIN32 - int delta; -#ifndef DONT_USE_SEH - DWORD dwExceptionCode = 0; - EXCEPTION_RECORD record; -#endif -#endif - /* XXX check before here */ - if (restype == NULL) { - PyErr_SetString(PyExc_RuntimeError, - "No ffi_type for result"); - return -1; - } - - cc = FFI_DEFAULT_ABI; -#if defined(MS_WIN32) && !defined(MS_WIN64) && !defined(_WIN32_WCE) - if ((flags & FUNCFLAG_CDECL) == 0) - cc = FFI_STDCALL; -#endif - if (FFI_OK != ffi_prep_cif(&cif, - cc, - argcount, - restype, - atypes)) { - PyErr_SetString(PyExc_RuntimeError, - "ffi_prep_cif failed"); - return -1; - } - - if (flags & (FUNCFLAG_USE_ERRNO | FUNCFLAG_USE_LASTERROR)) { - error_object = _ctypes_get_errobj(&space); - if (error_object == NULL) - return -1; - } -#ifdef WITH_THREAD - if ((flags & FUNCFLAG_PYTHONAPI) == 0) - Py_UNBLOCK_THREADS -#endif - if (flags & FUNCFLAG_USE_ERRNO) { - int temp = space[0]; - space[0] = errno; - errno = temp; - } -#ifdef MS_WIN32 - if (flags & FUNCFLAG_USE_LASTERROR) { - int temp = space[1]; - space[1] = GetLastError(); - SetLastError(temp); - } -#ifndef DONT_USE_SEH - __try { -#endif - delta = -#endif - ffi_call(&cif, (void *)pProc, resmem, avalues); -#ifdef MS_WIN32 -#ifndef DONT_USE_SEH - } - __except (HandleException(GetExceptionInformation(), - &dwExceptionCode, &record)) { - ; - } -#endif - if (flags & FUNCFLAG_USE_LASTERROR) { - int temp = space[1]; - space[1] = GetLastError(); - SetLastError(temp); - } -#endif - if (flags & FUNCFLAG_USE_ERRNO) { - int temp = space[0]; - space[0] = errno; - errno = temp; - } -#ifdef WITH_THREAD - if ((flags & FUNCFLAG_PYTHONAPI) == 0) - Py_BLOCK_THREADS -#endif - Py_XDECREF(error_object); -#ifdef MS_WIN32 -#ifndef DONT_USE_SEH - if (dwExceptionCode) { - SetException(dwExceptionCode, &record); - return -1; - } -#endif -#ifdef MS_WIN64 - if (delta != 0) { - PyErr_Format(PyExc_RuntimeError, - "ffi_call failed with code %d", - delta); - return -1; - } -#else - if (delta < 0) { - if (flags & FUNCFLAG_CDECL) - PyErr_Format(PyExc_ValueError, - "Procedure called with not enough " - "arguments (%d bytes missing) " - "or wrong calling convention", - -delta); - else - PyErr_Format(PyExc_ValueError, - "Procedure probably called with not enough " - "arguments (%d bytes missing)", - -delta); - return -1; - } else if (delta > 0) { - PyErr_Format(PyExc_ValueError, - "Procedure probably called with too many " - "arguments (%d bytes in excess)", - delta); - return -1; - } -#endif -#endif - if ((flags & FUNCFLAG_PYTHONAPI) && PyErr_Occurred()) - return -1; - return 0; -} - -/* - * Convert the C value in result into a Python object, depending on restype. - * - * - If restype is NULL, return a Python integer. - * - If restype is None, return None. - * - If restype is a simple ctypes type (c_int, c_void_p), call the type's getfunc, - * pass the result to checker and return the result. - * - If restype is another ctypes type, return an instance of that. - * - Otherwise, call restype and return the result. - */ -static PyObject *GetResult(PyObject *restype, void *result, PyObject *checker) -{ - StgDictObject *dict; - PyObject *retval, *v; - - if (restype == NULL) - return PyLong_FromLong(*(int *)result); - - if (restype == Py_None) { - Py_INCREF(Py_None); - return Py_None; - } - - dict = PyType_stgdict(restype); - if (dict == NULL) - return PyObject_CallFunction(restype, "i", *(int *)result); - - if (dict->getfunc && !_ctypes_simple_instance(restype)) { - retval = dict->getfunc(result, dict->size); - /* If restype is py_object (detected by comparing getfunc with - O_get), we have to call Py_DECREF because O_get has already - called Py_INCREF. - */ - if (dict->getfunc == _ctypes_get_fielddesc("O")->getfunc) { - Py_DECREF(retval); - } - } else - retval = PyCData_FromBaseObj(restype, NULL, 0, result); - - if (!checker || !retval) - return retval; - - v = PyObject_CallFunctionObjArgs(checker, retval, NULL); - if (v == NULL) - _PyTraceback_Add("GetResult", "_ctypes/callproc.c", __LINE__-2); - Py_DECREF(retval); - return v; -} - -/* - * Raise a new exception 'exc_class', adding additional text to the original - * exception string. - */ -void _ctypes_extend_error(PyObject *exc_class, const char *fmt, ...) -{ - va_list vargs; - PyObject *tp, *v, *tb, *s, *cls_str, *msg_str; - - va_start(vargs, fmt); - s = PyUnicode_FromFormatV(fmt, vargs); - va_end(vargs); - if (!s) - return; - - PyErr_Fetch(&tp, &v, &tb); - PyErr_NormalizeException(&tp, &v, &tb); - cls_str = PyObject_Str(tp); - if (cls_str) { - PyUnicode_AppendAndDel(&s, cls_str); - PyUnicode_AppendAndDel(&s, PyUnicode_FromString(": ")); - if (s == NULL) - goto error; - } else - PyErr_Clear(); - msg_str = PyObject_Str(v); - if (msg_str) - PyUnicode_AppendAndDel(&s, msg_str); - else { - PyErr_Clear(); - PyUnicode_AppendAndDel(&s, PyUnicode_FromString("???")); - } - if (s == NULL) - goto error; - PyErr_SetObject(exc_class, s); -error: - Py_XDECREF(tp); - Py_XDECREF(v); - Py_XDECREF(tb); - Py_XDECREF(s); -} - - -#ifdef MS_WIN32 - -static PyObject * -GetComError(HRESULT errcode, GUID *riid, IUnknown *pIunk) -{ - HRESULT hr; - ISupportErrorInfo *psei = NULL; - IErrorInfo *pei = NULL; - BSTR descr=NULL, helpfile=NULL, source=NULL; - GUID guid; - DWORD helpcontext=0; - LPOLESTR progid; - PyObject *obj; - LPOLESTR text; - - /* We absolutely have to release the GIL during COM method calls, - otherwise we may get a deadlock! - */ -#ifdef WITH_THREAD - Py_BEGIN_ALLOW_THREADS -#endif - - hr = pIunk->lpVtbl->QueryInterface(pIunk, &IID_ISupportErrorInfo, (void **)&psei); - if (FAILED(hr)) - goto failed; - - hr = psei->lpVtbl->InterfaceSupportsErrorInfo(psei, riid); - psei->lpVtbl->Release(psei); - if (FAILED(hr)) - goto failed; - - hr = GetErrorInfo(0, &pei); - if (hr != S_OK) - goto failed; - - pei->lpVtbl->GetDescription(pei, &descr); - pei->lpVtbl->GetGUID(pei, &guid); - pei->lpVtbl->GetHelpContext(pei, &helpcontext); - pei->lpVtbl->GetHelpFile(pei, &helpfile); - pei->lpVtbl->GetSource(pei, &source); - - pei->lpVtbl->Release(pei); - - failed: -#ifdef WITH_THREAD - Py_END_ALLOW_THREADS -#endif - - progid = NULL; - ProgIDFromCLSID(&guid, &progid); - - text = FormatError(errcode); - obj = Py_BuildValue( - "iu(uuuiu)", - errcode, - text, - descr, source, helpfile, helpcontext, - progid); - if (obj) { - PyErr_SetObject(ComError, obj); - Py_DECREF(obj); - } - LocalFree(text); - - if (descr) - SysFreeString(descr); - if (helpfile) - SysFreeString(helpfile); - if (source) - SysFreeString(source); - - return NULL; -} -#endif - -#if (defined(__x86_64__) && (defined(__MINGW64__) || defined(__CYGWIN__))) || \ - defined(__aarch64__) -#define CTYPES_PASS_BY_REF_HACK -#define POW2(x) (((x & ~(x - 1)) == x) ? x : 0) -#define IS_PASS_BY_REF(x) (x > 8 || !POW2(x)) -#endif - -/* - * Requirements, must be ensured by the caller: - * - argtuple is tuple of arguments - * - argtypes is either NULL, or a tuple of the same size as argtuple - * - * - XXX various requirements for restype, not yet collected - */ -PyObject *_ctypes_callproc(PPROC pProc, - PyObject *argtuple, -#ifdef MS_WIN32 - IUnknown *pIunk, - GUID *iid, -#endif - int flags, - PyObject *argtypes, /* misleading name: This is a tuple of - methods, not types: the .from_param - class methods of the types */ - PyObject *restype, - PyObject *checker) -{ - Py_ssize_t i, n, argcount, argtype_count; - void *resbuf; - struct argument *args, *pa; - ffi_type **atypes; - ffi_type *rtype; - void **avalues; - PyObject *retval = NULL; - - n = argcount = PyTuple_GET_SIZE(argtuple); -#ifdef MS_WIN32 - /* an optional COM object this pointer */ - if (pIunk) - ++argcount; -#endif - - args = (struct argument *)alloca(sizeof(struct argument) * argcount); - if (!args) { - PyErr_NoMemory(); - return NULL; - } - memset(args, 0, sizeof(struct argument) * argcount); - argtype_count = argtypes ? PyTuple_GET_SIZE(argtypes) : 0; -#ifdef MS_WIN32 - if (pIunk) { - args[0].ffi_type = &ffi_type_pointer; - args[0].value.p = pIunk; - pa = &args[1]; - } else -#endif - pa = &args[0]; - - /* Convert the arguments */ - for (i = 0; i < n; ++i, ++pa) { - PyObject *converter; - PyObject *arg; - int err; - - arg = PyTuple_GET_ITEM(argtuple, i); /* borrowed ref */ - /* For cdecl functions, we allow more actual arguments - than the length of the argtypes tuple. - This is checked in _ctypes::PyCFuncPtr_Call - */ - if (argtypes && argtype_count > i) { - PyObject *v; - converter = PyTuple_GET_ITEM(argtypes, i); - v = PyObject_CallFunctionObjArgs(converter, arg, NULL); - if (v == NULL) { - _ctypes_extend_error(PyExc_ArgError, "argument %d: ", i+1); - goto cleanup; - } - - err = ConvParam(v, i+1, pa); - Py_DECREF(v); - if (-1 == err) { - _ctypes_extend_error(PyExc_ArgError, "argument %d: ", i+1); - goto cleanup; - } - } else { - err = ConvParam(arg, i+1, pa); - if (-1 == err) { - _ctypes_extend_error(PyExc_ArgError, "argument %d: ", i+1); - goto cleanup; /* leaking ? */ - } - } - } - - rtype = _ctypes_get_ffi_type(restype); - resbuf = alloca(max(rtype->size, sizeof(ffi_arg))); - -#ifdef _Py_MEMORY_SANITIZER - /* ffi_call actually initializes resbuf, but from asm, which - * MemorySanitizer can't detect. Avoid false positives from MSan. */ - if (resbuf != NULL) { - __msan_unpoison(resbuf, max(rtype->size, sizeof(ffi_arg))); - } -#endif - avalues = (void **)alloca(sizeof(void *) * argcount); - atypes = (ffi_type **)alloca(sizeof(ffi_type *) * argcount); - if (!resbuf || !avalues || !atypes) { - PyErr_NoMemory(); - goto cleanup; - } - for (i = 0; i < argcount; ++i) { - atypes[i] = args[i].ffi_type; -#ifdef CTYPES_PASS_BY_REF_HACK - size_t size = atypes[i]->size; - if (IS_PASS_BY_REF(size)) { - void *tmp = alloca(size); - if (atypes[i]->type == FFI_TYPE_STRUCT) - memcpy(tmp, args[i].value.p, size); - else - memcpy(tmp, (void*)&args[i].value, size); - - avalues[i] = tmp; - } - else -#endif - if (atypes[i]->type == FFI_TYPE_STRUCT) - avalues[i] = (void *)args[i].value.p; - else - avalues[i] = (void *)&args[i].value; - } - - if (-1 == _call_function_pointer(flags, pProc, avalues, atypes, - rtype, resbuf, - Py_SAFE_DOWNCAST(argcount, - Py_ssize_t, - int))) - goto cleanup; - -#ifdef WORDS_BIGENDIAN - /* libffi returns the result in a buffer with sizeof(ffi_arg). This - causes problems on big endian machines, since the result buffer - address cannot simply be used as result pointer, instead we must - adjust the pointer value: - */ - /* - XXX I should find out and clarify why this is needed at all, - especially why adjusting for ffi_type_float must be avoided on - 64-bit platforms. - */ - if (rtype->type != FFI_TYPE_FLOAT - && rtype->type != FFI_TYPE_STRUCT - && rtype->size < sizeof(ffi_arg)) - resbuf = (char *)resbuf + sizeof(ffi_arg) - rtype->size; -#endif - -#ifdef MS_WIN32 - if (iid && pIunk) { - if (*(int *)resbuf & 0x80000000) - retval = GetComError(*(HRESULT *)resbuf, iid, pIunk); - else - retval = PyLong_FromLong(*(int *)resbuf); - } else if (flags & FUNCFLAG_HRESULT) { - if (*(int *)resbuf & 0x80000000) - retval = PyErr_SetFromWindowsErr(*(int *)resbuf); - else - retval = PyLong_FromLong(*(int *)resbuf); - } else -#endif - retval = GetResult(restype, resbuf, checker); - cleanup: - for (i = 0; i < argcount; ++i) - Py_XDECREF(args[i].keep); - return retval; -} - -static int -_parse_voidp(PyObject *obj, void **address) -{ - *address = PyLong_AsVoidPtr(obj); - if (*address == NULL) - return 0; - return 1; -} - -#ifdef MS_WIN32 - -static const char format_error_doc[] = -"FormatError([integer]) -> string\n\ -\n\ -Convert a win32 error code into a string. If the error code is not\n\ -given, the return value of a call to GetLastError() is used.\n"; -static PyObject *format_error(PyObject *self, PyObject *args) -{ - PyObject *result; - wchar_t *lpMsgBuf; - DWORD code = 0; - if (!PyArg_ParseTuple(args, "|i:FormatError", &code)) - return NULL; - if (code == 0) - code = GetLastError(); - lpMsgBuf = FormatError(code); - if (lpMsgBuf) { - result = PyUnicode_FromWideChar(lpMsgBuf, wcslen(lpMsgBuf)); - LocalFree(lpMsgBuf); - } else { - result = PyUnicode_FromString(""); - } - return result; -} - -static const char load_library_doc[] = -"LoadLibrary(name) -> handle\n\ -\n\ -Load an executable (usually a DLL), and return a handle to it.\n\ -The handle may be used to locate exported functions in this\n\ -module.\n"; -static PyObject *load_library(PyObject *self, PyObject *args) -{ - const WCHAR *name; - PyObject *nameobj; - PyObject *ignored; - HMODULE hMod; - - if (!PyArg_ParseTuple(args, "U|O:LoadLibrary", &nameobj, &ignored)) - return NULL; - - name = _PyUnicode_AsUnicode(nameobj); - if (!name) - return NULL; - - hMod = LoadLibraryW(name); - if (!hMod) - return PyErr_SetFromWindowsErr(GetLastError()); -#ifdef _WIN64 - return PyLong_FromVoidPtr(hMod); -#else - return Py_BuildValue("i", hMod); -#endif -} - -static const char free_library_doc[] = -"FreeLibrary(handle) -> void\n\ -\n\ -Free the handle of an executable previously loaded by LoadLibrary.\n"; -static PyObject *free_library(PyObject *self, PyObject *args) -{ - void *hMod; - if (!PyArg_ParseTuple(args, "O&:FreeLibrary", &_parse_voidp, &hMod)) - return NULL; - if (!FreeLibrary((HMODULE)hMod)) - return PyErr_SetFromWindowsErr(GetLastError()); - Py_INCREF(Py_None); - return Py_None; -} - -static const char copy_com_pointer_doc[] = -"CopyComPointer(src, dst) -> HRESULT value\n"; - -static PyObject * -copy_com_pointer(PyObject *self, PyObject *args) -{ - PyObject *p1, *p2, *r = NULL; - struct argument a, b; - IUnknown *src, **pdst; - if (!PyArg_ParseTuple(args, "OO:CopyComPointer", &p1, &p2)) - return NULL; - a.keep = b.keep = NULL; - - if (-1 == ConvParam(p1, 0, &a) || -1 == ConvParam(p2, 1, &b)) - goto done; - src = (IUnknown *)a.value.p; - pdst = (IUnknown **)b.value.p; - - if (pdst == NULL) - r = PyLong_FromLong(E_POINTER); - else { - if (src) - src->lpVtbl->AddRef(src); - *pdst = src; - r = PyLong_FromLong(S_OK); - } - done: - Py_XDECREF(a.keep); - Py_XDECREF(b.keep); - return r; -} -#else - -static PyObject *py_dl_open(PyObject *self, PyObject *args) -{ - PyObject *name, *name2; - char *name_str; - void * handle; -#if HAVE_DECL_RTLD_LOCAL - int mode = RTLD_NOW | RTLD_LOCAL; -#else - /* cygwin doesn't define RTLD_LOCAL */ - int mode = RTLD_NOW; -#endif - if (!PyArg_ParseTuple(args, "O|i:dlopen", &name, &mode)) - return NULL; - mode |= RTLD_NOW; - if (name != Py_None) { - if (PyUnicode_FSConverter(name, &name2) == 0) - return NULL; - if (PyBytes_Check(name2)) - name_str = PyBytes_AS_STRING(name2); - else - name_str = PyByteArray_AS_STRING(name2); - } else { - name_str = NULL; - name2 = NULL; - } - handle = ctypes_dlopen(name_str, mode); - Py_XDECREF(name2); - if (!handle) { - char *errmsg = ctypes_dlerror(); - if (!errmsg) - errmsg = "dlopen() error"; - PyErr_SetString(PyExc_OSError, - errmsg); - return NULL; - } - return PyLong_FromVoidPtr(handle); -} - -static PyObject *py_dl_close(PyObject *self, PyObject *args) -{ - void *handle; - - if (!PyArg_ParseTuple(args, "O&:dlclose", &_parse_voidp, &handle)) - return NULL; - if (dlclose(handle)) { - PyErr_SetString(PyExc_OSError, - ctypes_dlerror()); - return NULL; - } - Py_INCREF(Py_None); - return Py_None; -} - -static PyObject *py_dl_sym(PyObject *self, PyObject *args) -{ - char *name; - void *handle; - void *ptr; - - if (!PyArg_ParseTuple(args, "O&s:dlsym", - &_parse_voidp, &handle, &name)) - return NULL; - ptr = ctypes_dlsym((void*)handle, name); - if (!ptr) { - PyErr_SetString(PyExc_OSError, - ctypes_dlerror()); - return NULL; - } - return PyLong_FromVoidPtr(ptr); -} -#endif - -/* - * Only for debugging so far: So that we can call CFunction instances - * - * XXX Needs to accept more arguments: flags, argtypes, restype - */ -static PyObject * -call_function(PyObject *self, PyObject *args) -{ - void *func; - PyObject *arguments; - PyObject *result; - - if (!PyArg_ParseTuple(args, - "O&O!", - &_parse_voidp, &func, - &PyTuple_Type, &arguments)) - return NULL; - - result = _ctypes_callproc((PPROC)func, - arguments, -#ifdef MS_WIN32 - NULL, - NULL, -#endif - 0, /* flags */ - NULL, /* self->argtypes */ - NULL, /* self->restype */ - NULL); /* checker */ - return result; -} - -/* - * Only for debugging so far: So that we can call CFunction instances - * - * XXX Needs to accept more arguments: flags, argtypes, restype - */ -static PyObject * -call_cdeclfunction(PyObject *self, PyObject *args) -{ - void *func; - PyObject *arguments; - PyObject *result; - - if (!PyArg_ParseTuple(args, - "O&O!", - &_parse_voidp, &func, - &PyTuple_Type, &arguments)) - return NULL; - - result = _ctypes_callproc((PPROC)func, - arguments, -#ifdef MS_WIN32 - NULL, - NULL, -#endif - FUNCFLAG_CDECL, /* flags */ - NULL, /* self->argtypes */ - NULL, /* self->restype */ - NULL); /* checker */ - return result; -} - -/***************************************************************** - * functions - */ -static const char sizeof_doc[] = -"sizeof(C type) -> integer\n" -"sizeof(C instance) -> integer\n" -"Return the size in bytes of a C instance"; - -static PyObject * -sizeof_func(PyObject *self, PyObject *obj) -{ - StgDictObject *dict; - - dict = PyType_stgdict(obj); - if (dict) - return PyLong_FromSsize_t(dict->size); - - if (CDataObject_Check(obj)) - return PyLong_FromSsize_t(((CDataObject *)obj)->b_size); - PyErr_SetString(PyExc_TypeError, - "this type has no size"); - return NULL; -} - -static const char alignment_doc[] = -"alignment(C type) -> integer\n" -"alignment(C instance) -> integer\n" -"Return the alignment requirements of a C instance"; - -static PyObject * -align_func(PyObject *self, PyObject *obj) -{ - StgDictObject *dict; - - dict = PyType_stgdict(obj); - if (dict) - return PyLong_FromSsize_t(dict->align); - - dict = PyObject_stgdict(obj); - if (dict) - return PyLong_FromSsize_t(dict->align); - - PyErr_SetString(PyExc_TypeError, - "no alignment info"); - return NULL; -} - -static const char byref_doc[] = -"byref(C instance[, offset=0]) -> byref-object\n" -"Return a pointer lookalike to a C instance, only usable\n" -"as function argument"; - -/* - * We must return something which can be converted to a parameter, - * but still has a reference to self. - */ -static PyObject * -byref(PyObject *self, PyObject *args) -{ - PyCArgObject *parg; - PyObject *obj; - PyObject *pyoffset = NULL; - Py_ssize_t offset = 0; - - if (!PyArg_UnpackTuple(args, "byref", 1, 2, - &obj, &pyoffset)) - return NULL; - if (pyoffset) { - offset = PyNumber_AsSsize_t(pyoffset, NULL); - if (offset == -1 && PyErr_Occurred()) - return NULL; - } - if (!CDataObject_Check(obj)) { - PyErr_Format(PyExc_TypeError, - "byref() argument must be a ctypes instance, not '%s'", - Py_TYPE(obj)->tp_name); - return NULL; - } - - parg = PyCArgObject_new(); - if (parg == NULL) - return NULL; - - parg->tag = 'P'; - parg->pffi_type = &ffi_type_pointer; - Py_INCREF(obj); - parg->obj = obj; - parg->value.p = (char *)((CDataObject *)obj)->b_ptr + offset; - return (PyObject *)parg; -} - -static const char addressof_doc[] = -"addressof(C instance) -> integer\n" -"Return the address of the C instance internal buffer"; - -static PyObject * -addressof(PyObject *self, PyObject *obj) -{ - if (CDataObject_Check(obj)) - return PyLong_FromVoidPtr(((CDataObject *)obj)->b_ptr); - PyErr_SetString(PyExc_TypeError, - "invalid type"); - return NULL; -} - -static int -converter(PyObject *obj, void **address) -{ - *address = PyLong_AsVoidPtr(obj); - return *address != NULL; -} - -static PyObject * -My_PyObj_FromPtr(PyObject *self, PyObject *args) -{ - PyObject *ob; - if (!PyArg_ParseTuple(args, "O&:PyObj_FromPtr", converter, &ob)) - return NULL; - Py_INCREF(ob); - return ob; -} - -static PyObject * -My_Py_INCREF(PyObject *self, PyObject *arg) -{ - Py_INCREF(arg); /* that's what this function is for */ - Py_INCREF(arg); /* that for returning it */ - return arg; -} - -static PyObject * -My_Py_DECREF(PyObject *self, PyObject *arg) -{ - Py_DECREF(arg); /* that's what this function is for */ - Py_INCREF(arg); /* that's for returning it */ - return arg; -} - -static PyObject * -resize(PyObject *self, PyObject *args) -{ - CDataObject *obj; - StgDictObject *dict; - Py_ssize_t size; - - if (!PyArg_ParseTuple(args, - "On:resize", - &obj, &size)) - return NULL; - - dict = PyObject_stgdict((PyObject *)obj); - if (dict == NULL) { - PyErr_SetString(PyExc_TypeError, - "excepted ctypes instance"); - return NULL; - } - if (size < dict->size) { - PyErr_Format(PyExc_ValueError, - "minimum size is %zd", - dict->size); - return NULL; - } - if (obj->b_needsfree == 0) { - PyErr_Format(PyExc_ValueError, - "Memory cannot be resized because this object doesn't own it"); - return NULL; - } - if ((size_t)size <= sizeof(obj->b_value)) { - /* internal default buffer is large enough */ - obj->b_size = size; - goto done; - } - if (!_CDataObject_HasExternalBuffer(obj)) { - /* We are currently using the objects default buffer, but it - isn't large enough any more. */ - void *ptr = PyMem_Malloc(size); - if (ptr == NULL) - return PyErr_NoMemory(); - memset(ptr, 0, size); - memmove(ptr, obj->b_ptr, obj->b_size); - obj->b_ptr = ptr; - obj->b_size = size; - } else { - void * ptr = PyMem_Realloc(obj->b_ptr, size); - if (ptr == NULL) - return PyErr_NoMemory(); - obj->b_ptr = ptr; - obj->b_size = size; - } - done: - Py_INCREF(Py_None); - return Py_None; -} - -static PyObject * -unpickle(PyObject *self, PyObject *args) -{ - PyObject *typ; - PyObject *state; - PyObject *result; - PyObject *tmp; - _Py_IDENTIFIER(__new__); - _Py_IDENTIFIER(__setstate__); - - if (!PyArg_ParseTuple(args, "OO", &typ, &state)) - return NULL; - result = _PyObject_CallMethodId(typ, &PyId___new__, "O", typ); - if (result == NULL) - return NULL; - tmp = _PyObject_CallMethodId(result, &PyId___setstate__, "O", state); - if (tmp == NULL) { - Py_DECREF(result); - return NULL; - } - Py_DECREF(tmp); - return result; -} - -static PyObject * -POINTER(PyObject *self, PyObject *cls) -{ - PyObject *result; - PyTypeObject *typ; - PyObject *key; - char *buf; - - result = PyDict_GetItem(_ctypes_ptrtype_cache, cls); - if (result) { - Py_INCREF(result); - return result; - } - if (PyUnicode_CheckExact(cls)) { - const char *name = PyUnicode_AsUTF8(cls); - if (name == NULL) - return NULL; - buf = PyMem_Malloc(strlen(name) + 3 + 1); - if (buf == NULL) - return PyErr_NoMemory(); - sprintf(buf, "LP_%s", name); - result = PyObject_CallFunction((PyObject *)Py_TYPE(&PyCPointer_Type), - "s(O){}", - buf, - &PyCPointer_Type); - PyMem_Free(buf); - if (result == NULL) - return result; - key = PyLong_FromVoidPtr(result); - if (key == NULL) { - Py_DECREF(result); - return NULL; - } - } else if (PyType_Check(cls)) { - typ = (PyTypeObject *)cls; - buf = PyMem_Malloc(strlen(typ->tp_name) + 3 + 1); - if (buf == NULL) - return PyErr_NoMemory(); - sprintf(buf, "LP_%s", typ->tp_name); - result = PyObject_CallFunction((PyObject *)Py_TYPE(&PyCPointer_Type), - "s(O){sO}", - buf, - &PyCPointer_Type, - "_type_", cls); - PyMem_Free(buf); - if (result == NULL) - return result; - Py_INCREF(cls); - key = cls; - } else { - PyErr_SetString(PyExc_TypeError, "must be a ctypes type"); - return NULL; - } - if (-1 == PyDict_SetItem(_ctypes_ptrtype_cache, key, result)) { - Py_DECREF(result); - Py_DECREF(key); - return NULL; - } - Py_DECREF(key); - return result; -} - -static PyObject * -pointer(PyObject *self, PyObject *arg) -{ - PyObject *result; - PyObject *typ; - - typ = PyDict_GetItem(_ctypes_ptrtype_cache, (PyObject *)Py_TYPE(arg)); - if (typ) - return PyObject_CallFunctionObjArgs(typ, arg, NULL); - typ = POINTER(NULL, (PyObject *)Py_TYPE(arg)); - if (typ == NULL) - return NULL; - result = PyObject_CallFunctionObjArgs(typ, arg, NULL); - Py_DECREF(typ); - return result; -} - -static PyObject * -buffer_info(PyObject *self, PyObject *arg) -{ - StgDictObject *dict = PyType_stgdict(arg); - PyObject *shape; - Py_ssize_t i; - - if (dict == NULL) - dict = PyObject_stgdict(arg); - if (dict == NULL) { - PyErr_SetString(PyExc_TypeError, - "not a ctypes type or object"); - return NULL; - } - shape = PyTuple_New(dict->ndim); - if (shape == NULL) - return NULL; - for (i = 0; i < (int)dict->ndim; ++i) - PyTuple_SET_ITEM(shape, i, PyLong_FromSsize_t(dict->shape[i])); - - if (PyErr_Occurred()) { - Py_DECREF(shape); - return NULL; - } - return Py_BuildValue("siN", dict->format, dict->ndim, shape); -} - -PyMethodDef _ctypes_module_methods[] = { - {"get_errno", get_errno, METH_NOARGS}, - {"set_errno", set_errno, METH_VARARGS}, - {"POINTER", POINTER, METH_O }, - {"pointer", pointer, METH_O }, - {"_unpickle", unpickle, METH_VARARGS }, - {"buffer_info", buffer_info, METH_O, "Return buffer interface information"}, - {"resize", resize, METH_VARARGS, "Resize the memory buffer of a ctypes instance"}, -#ifdef MS_WIN32 - {"get_last_error", get_last_error, METH_NOARGS}, - {"set_last_error", set_last_error, METH_VARARGS}, - {"CopyComPointer", copy_com_pointer, METH_VARARGS, copy_com_pointer_doc}, - {"FormatError", format_error, METH_VARARGS, format_error_doc}, - {"LoadLibrary", load_library, METH_VARARGS, load_library_doc}, - {"FreeLibrary", free_library, METH_VARARGS, free_library_doc}, - {"_check_HRESULT", check_hresult, METH_VARARGS}, -#else - {"dlopen", py_dl_open, METH_VARARGS, - "dlopen(name, flag={RTLD_GLOBAL|RTLD_LOCAL}) open a shared library"}, - {"dlclose", py_dl_close, METH_VARARGS, "dlclose a library"}, - {"dlsym", py_dl_sym, METH_VARARGS, "find symbol in shared library"}, -#endif - {"alignment", align_func, METH_O, alignment_doc}, - {"sizeof", sizeof_func, METH_O, sizeof_doc}, - {"byref", byref, METH_VARARGS, byref_doc}, - {"addressof", addressof, METH_O, addressof_doc}, - {"call_function", call_function, METH_VARARGS }, - {"call_cdeclfunction", call_cdeclfunction, METH_VARARGS }, - {"PyObj_FromPtr", My_PyObj_FromPtr, METH_VARARGS }, - {"Py_INCREF", My_Py_INCREF, METH_O }, - {"Py_DECREF", My_Py_DECREF, METH_O }, - {NULL, NULL} /* Sentinel */ -}; - -/* - Local Variables: - compile-command: "cd .. && python setup.py -q build -g && python setup.py -q build install --home ~" - End: -*/ diff --git a/third_party/python/Modules/_ctypes/cfield.c b/third_party/python/Modules/_ctypes/cfield.c deleted file mode 100644 index 3c1cefb57..000000000 --- a/third_party/python/Modules/_ctypes/cfield.c +++ /dev/null @@ -1,1669 +0,0 @@ -/* clang-format off */ -#include "Python.h" - -#include -#ifdef MS_WIN32 -#include -#endif -#include "ctypes.h" - - -#define CTYPES_CFIELD_CAPSULE_NAME_PYMEM "_ctypes/cfield.c pymem" - -static void pymem_destructor(PyObject *ptr) -{ - void *p = PyCapsule_GetPointer(ptr, CTYPES_CFIELD_CAPSULE_NAME_PYMEM); - if (p) { - PyMem_Free(p); - } -} - - -/******************************************************************/ -/* - PyCField_Type -*/ -static PyObject * -PyCField_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - CFieldObject *obj; - obj = (CFieldObject *)type->tp_alloc(type, 0); - return (PyObject *)obj; -} - -/* - * Expects the size, index and offset for the current field in *psize and - * *poffset, stores the total size so far in *psize, the offset for the next - * field in *poffset, the alignment requirements for the current field in - * *palign, and returns a field desriptor for this field. - */ -/* - * bitfields extension: - * bitsize != 0: this is a bit field. - * pbitofs points to the current bit offset, this will be updated. - * prev_desc points to the type of the previous bitfield, if any. - */ -PyObject * -PyCField_FromDesc(PyObject *desc, Py_ssize_t index, - Py_ssize_t *pfield_size, int bitsize, int *pbitofs, - Py_ssize_t *psize, Py_ssize_t *poffset, Py_ssize_t *palign, - int pack, int big_endian) -{ - CFieldObject *self; - PyObject *proto; - Py_ssize_t size, align; - SETFUNC setfunc = NULL; - GETFUNC getfunc = NULL; - StgDictObject *dict; - int fieldtype; -#define NO_BITFIELD 0 -#define NEW_BITFIELD 1 -#define CONT_BITFIELD 2 -#define EXPAND_BITFIELD 3 - - self = (CFieldObject *)PyObject_CallObject((PyObject *)&PyCField_Type, - NULL); - if (self == NULL) - return NULL; - dict = PyType_stgdict(desc); - if (!dict) { - PyErr_SetString(PyExc_TypeError, - "has no _stginfo_"); - Py_DECREF(self); - return NULL; - } - if (bitsize /* this is a bitfield request */ - && *pfield_size /* we have a bitfield open */ -#ifdef MS_WIN32 - /* MSVC, GCC with -mms-bitfields */ - && dict->size * 8 == *pfield_size -#else - /* GCC */ - && dict->size * 8 <= *pfield_size -#endif - && (*pbitofs + bitsize) <= *pfield_size) { - /* continue bit field */ - fieldtype = CONT_BITFIELD; -#ifndef MS_WIN32 - } else if (bitsize /* this is a bitfield request */ - && *pfield_size /* we have a bitfield open */ - && dict->size * 8 >= *pfield_size - && (*pbitofs + bitsize) <= dict->size * 8) { - /* expand bit field */ - fieldtype = EXPAND_BITFIELD; -#endif - } else if (bitsize) { - /* start new bitfield */ - fieldtype = NEW_BITFIELD; - *pbitofs = 0; - *pfield_size = dict->size * 8; - } else { - /* not a bit field */ - fieldtype = NO_BITFIELD; - *pbitofs = 0; - *pfield_size = 0; - } - - size = dict->size; - proto = desc; - - /* Field descriptors for 'c_char * n' are be scpecial cased to - return a Python string instead of an Array object instance... - */ - if (PyCArrayTypeObject_Check(proto)) { - StgDictObject *adict = PyType_stgdict(proto); - StgDictObject *idict; - if (adict && adict->proto) { - idict = PyType_stgdict(adict->proto); - if (!idict) { - PyErr_SetString(PyExc_TypeError, - "has no _stginfo_"); - Py_DECREF(self); - return NULL; - } - if (idict->getfunc == _ctypes_get_fielddesc("c")->getfunc) { - struct fielddesc *fd = _ctypes_get_fielddesc("s"); - getfunc = fd->getfunc; - setfunc = fd->setfunc; - } -#ifdef CTYPES_UNICODE - if (idict->getfunc == _ctypes_get_fielddesc("u")->getfunc) { - struct fielddesc *fd = _ctypes_get_fielddesc("U"); - getfunc = fd->getfunc; - setfunc = fd->setfunc; - } -#endif - } - } - - self->setfunc = setfunc; - self->getfunc = getfunc; - self->index = index; - - Py_INCREF(proto); - self->proto = proto; - - switch (fieldtype) { - case NEW_BITFIELD: - if (big_endian) - self->size = (bitsize << 16) + *pfield_size - *pbitofs - bitsize; - else - self->size = (bitsize << 16) + *pbitofs; - *pbitofs = bitsize; - /* fall through */ - case NO_BITFIELD: - if (pack) - align = min(pack, dict->align); - else - align = dict->align; - if (align && *poffset % align) { - Py_ssize_t delta = align - (*poffset % align); - *psize += delta; - *poffset += delta; - } - - if (bitsize == 0) - self->size = size; - *psize += size; - - self->offset = *poffset; - *poffset += size; - - *palign = align; - break; - - case EXPAND_BITFIELD: - *poffset += dict->size - *pfield_size/8; - *psize += dict->size - *pfield_size/8; - - *pfield_size = dict->size * 8; - - if (big_endian) - self->size = (bitsize << 16) + *pfield_size - *pbitofs - bitsize; - else - self->size = (bitsize << 16) + *pbitofs; - - self->offset = *poffset - size; /* poffset is already updated for the NEXT field */ - *pbitofs += bitsize; - break; - - case CONT_BITFIELD: - if (big_endian) - self->size = (bitsize << 16) + *pfield_size - *pbitofs - bitsize; - else - self->size = (bitsize << 16) + *pbitofs; - - self->offset = *poffset - size; /* poffset is already updated for the NEXT field */ - *pbitofs += bitsize; - break; - } - - return (PyObject *)self; -} - -static int -PyCField_set(CFieldObject *self, PyObject *inst, PyObject *value) -{ - CDataObject *dst; - char *ptr; - if (!CDataObject_Check(inst)) { - PyErr_SetString(PyExc_TypeError, - "not a ctype instance"); - return -1; - } - dst = (CDataObject *)inst; - ptr = dst->b_ptr + self->offset; - if (value == NULL) { - PyErr_SetString(PyExc_TypeError, - "can't delete attribute"); - return -1; - } - return PyCData_set(inst, self->proto, self->setfunc, value, - self->index, self->size, ptr); -} - -static PyObject * -PyCField_get(CFieldObject *self, PyObject *inst, PyTypeObject *type) -{ - CDataObject *src; - if (inst == NULL) { - Py_INCREF(self); - return (PyObject *)self; - } - if (!CDataObject_Check(inst)) { - PyErr_SetString(PyExc_TypeError, - "not a ctype instance"); - return NULL; - } - src = (CDataObject *)inst; - return PyCData_get(self->proto, self->getfunc, inst, - self->index, self->size, src->b_ptr + self->offset); -} - -static PyObject * -PyCField_get_offset(PyObject *self, void *data) -{ - return PyLong_FromSsize_t(((CFieldObject *)self)->offset); -} - -static PyObject * -PyCField_get_size(PyObject *self, void *data) -{ - return PyLong_FromSsize_t(((CFieldObject *)self)->size); -} - -static PyGetSetDef PyCField_getset[] = { - { "offset", PyCField_get_offset, NULL, "offset in bytes of this field" }, - { "size", PyCField_get_size, NULL, "size in bytes of this field" }, - { NULL, NULL, NULL, NULL }, -}; - -static int -PyCField_traverse(CFieldObject *self, visitproc visit, void *arg) -{ - Py_VISIT(self->proto); - return 0; -} - -static int -PyCField_clear(CFieldObject *self) -{ - Py_CLEAR(self->proto); - return 0; -} - -static void -PyCField_dealloc(PyObject *self) -{ - PyCField_clear((CFieldObject *)self); - self->ob_type->tp_free((PyObject *)self); -} - -static PyObject * -PyCField_repr(CFieldObject *self) -{ - PyObject *result; - Py_ssize_t bits = self->size >> 16; - Py_ssize_t size = self->size & 0xFFFF; - const char *name; - - name = ((PyTypeObject *)self->proto)->tp_name; - - if (bits) - result = PyUnicode_FromFormat( - "", - name, self->offset, size, bits); - else - result = PyUnicode_FromFormat( - "", - name, self->offset, size); - return result; -} - -PyTypeObject PyCField_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_ctypes.CField", /* tp_name */ - sizeof(CFieldObject), /* tp_basicsize */ - 0, /* tp_itemsize */ - PyCField_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)PyCField_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ - "Structure/Union member", /* tp_doc */ - (traverseproc)PyCField_traverse, /* tp_traverse */ - (inquiry)PyCField_clear, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - PyCField_getset, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - (descrgetfunc)PyCField_get, /* tp_descr_get */ - (descrsetfunc)PyCField_set, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - PyCField_new, /* tp_new */ - 0, /* tp_free */ -}; - - -/******************************************************************/ -/* - Accessor functions -*/ - -/* Derived from Modules/structmodule.c: - Helper routine to get a Python integer and raise the appropriate error - if it isn't one */ - -static int -get_long(PyObject *v, long *p) -{ - long x; - - if (PyFloat_Check(v)) { - PyErr_SetString(PyExc_TypeError, - "int expected instead of float"); - return -1; - } - x = PyLong_AsUnsignedLongMask(v); - if (x == -1 && PyErr_Occurred()) - return -1; - *p = x; - return 0; -} - -/* Same, but handling unsigned long */ - -static int -get_ulong(PyObject *v, unsigned long *p) -{ - unsigned long x; - - if (PyFloat_Check(v)) { - PyErr_SetString(PyExc_TypeError, - "int expected instead of float"); - return -1; - } - x = PyLong_AsUnsignedLongMask(v); - if (x == (unsigned long)-1 && PyErr_Occurred()) - return -1; - *p = x; - return 0; -} - -/* Same, but handling native long long. */ - -static int -get_longlong(PyObject *v, long long *p) -{ - long long x; - if (PyFloat_Check(v)) { - PyErr_SetString(PyExc_TypeError, - "int expected instead of float"); - return -1; - } - x = PyLong_AsUnsignedLongLongMask(v); - if (x == -1 && PyErr_Occurred()) - return -1; - *p = x; - return 0; -} - -/* Same, but handling native unsigned long long. */ - -static int -get_ulonglong(PyObject *v, unsigned long long *p) -{ - unsigned long long x; - if (PyFloat_Check(v)) { - PyErr_SetString(PyExc_TypeError, - "int expected instead of float"); - return -1; - } - x = PyLong_AsUnsignedLongLongMask(v); - if (x == (unsigned long long)-1 && PyErr_Occurred()) - return -1; - *p = x; - return 0; -} - -/***************************************************************** - * Integer fields, with bitfield support - */ - -/* how to decode the size field, for integer get/set functions */ -#define LOW_BIT(x) ((x) & 0xFFFF) -#define NUM_BITS(x) ((x) >> 16) - -/* Doesn't work if NUM_BITS(size) == 0, but it never happens in SET() call. */ -#define BIT_MASK(type, size) (((((type)1 << (NUM_BITS(size) - 1)) - 1) << 1) + 1) - -/* This macro CHANGES the first parameter IN PLACE. For proper sign handling, - we must first shift left, then right. -*/ -#define GET_BITFIELD(v, size) \ - if (NUM_BITS(size)) { \ - v <<= (sizeof(v)*8 - LOW_BIT(size) - NUM_BITS(size)); \ - v >>= (sizeof(v)*8 - NUM_BITS(size)); \ - } - -/* This macro RETURNS the first parameter with the bit field CHANGED. */ -#define SET(type, x, v, size) \ - (NUM_BITS(size) ? \ - ( ( (type)x & ~(BIT_MASK(type, size) << LOW_BIT(size)) ) | ( ((type)v & BIT_MASK(type, size)) << LOW_BIT(size) ) ) \ - : (type)v) - -/* byte swapping macros */ -#define SWAP_2(v) \ - ( ( (v >> 8) & 0x00FF) | \ - ( (v << 8) & 0xFF00) ) - -#define SWAP_4(v) \ - ( ( (v & 0x000000FF) << 24 ) | \ - ( (v & 0x0000FF00) << 8 ) | \ - ( (v & 0x00FF0000) >> 8 ) | \ - ( ((v >> 24) & 0xFF)) ) - -#ifdef _MSC_VER -#define SWAP_8(v) \ - ( ( (v & 0x00000000000000FFL) << 56 ) | \ - ( (v & 0x000000000000FF00L) << 40 ) | \ - ( (v & 0x0000000000FF0000L) << 24 ) | \ - ( (v & 0x00000000FF000000L) << 8 ) | \ - ( (v & 0x000000FF00000000L) >> 8 ) | \ - ( (v & 0x0000FF0000000000L) >> 24 ) | \ - ( (v & 0x00FF000000000000L) >> 40 ) | \ - ( ((v >> 56) & 0xFF)) ) -#else -#define SWAP_8(v) \ - ( ( (v & 0x00000000000000FFLL) << 56 ) | \ - ( (v & 0x000000000000FF00LL) << 40 ) | \ - ( (v & 0x0000000000FF0000LL) << 24 ) | \ - ( (v & 0x00000000FF000000LL) << 8 ) | \ - ( (v & 0x000000FF00000000LL) >> 8 ) | \ - ( (v & 0x0000FF0000000000LL) >> 24 ) | \ - ( (v & 0x00FF000000000000LL) >> 40 ) | \ - ( ((v >> 56) & 0xFF)) ) -#endif - -#define SWAP_INT SWAP_4 - -#if SIZEOF_LONG == 4 -# define SWAP_LONG SWAP_4 -#elif SIZEOF_LONG == 8 -# define SWAP_LONG SWAP_8 -#endif -/***************************************************************** - * The setter methods return an object which must be kept alive, to keep the - * data valid which has been stored in the memory block. The ctypes object - * instance inserts this object into its 'b_objects' list. - * - * For simple Python types like integers or characters, there is nothing that - * has to been kept alive, so Py_None is returned in these cases. But this - * makes inspecting the 'b_objects' list, which is accessible from Python for - * debugging, less useful. - * - * So, defining the _CTYPES_DEBUG_KEEP symbol returns the original value - * instead of Py_None. - */ - -#ifdef _CTYPES_DEBUG_KEEP -#define _RET(x) Py_INCREF(x); return x -#else -#define _RET(X) Py_INCREF(Py_None); return Py_None -#endif - -/***************************************************************** - * integer accessor methods, supporting bit fields - */ - -static PyObject * -b_set(void *ptr, PyObject *value, Py_ssize_t size) -{ - long val; - if (get_long(value, &val) < 0) - return NULL; - *(signed char *)ptr = SET(signed char, *(signed char *)ptr, val, size); - _RET(value); -} - - -static PyObject * -b_get(void *ptr, Py_ssize_t size) -{ - signed char val = *(signed char *)ptr; - GET_BITFIELD(val, size); - return PyLong_FromLong(val); -} - -static PyObject * -B_set(void *ptr, PyObject *value, Py_ssize_t size) -{ - unsigned long val; - if (get_ulong(value, &val) < 0) - return NULL; - *(unsigned char *)ptr = SET(unsigned char, *(unsigned char*)ptr, val, size); - _RET(value); -} - - -static PyObject * -B_get(void *ptr, Py_ssize_t size) -{ - unsigned char val = *(unsigned char *)ptr; - GET_BITFIELD(val, size); - return PyLong_FromLong(val); -} - -static PyObject * -h_set(void *ptr, PyObject *value, Py_ssize_t size) -{ - long val; - short x; - if (get_long(value, &val) < 0) - return NULL; - memcpy(&x, ptr, sizeof(x)); - x = SET(short, x, val, size); - memcpy(ptr, &x, sizeof(x)); - _RET(value); -} - - -static PyObject * -h_set_sw(void *ptr, PyObject *value, Py_ssize_t size) -{ - long val; - short field; - if (get_long(value, &val) < 0) - return NULL; - memcpy(&field, ptr, sizeof(field)); - field = SWAP_2(field); - field = SET(short, field, val, size); - field = SWAP_2(field); - memcpy(ptr, &field, sizeof(field)); - _RET(value); -} - -static PyObject * -h_get(void *ptr, Py_ssize_t size) -{ - short val; - memcpy(&val, ptr, sizeof(val)); - GET_BITFIELD(val, size); - return PyLong_FromLong((long)val); -} - -static PyObject * -h_get_sw(void *ptr, Py_ssize_t size) -{ - short val; - memcpy(&val, ptr, sizeof(val)); - val = SWAP_2(val); - GET_BITFIELD(val, size); - return PyLong_FromLong(val); -} - -static PyObject * -H_set(void *ptr, PyObject *value, Py_ssize_t size) -{ - unsigned long val; - unsigned short x; - if (get_ulong(value, &val) < 0) - return NULL; - memcpy(&x, ptr, sizeof(x)); - x = SET(unsigned short, x, val, size); - memcpy(ptr, &x, sizeof(x)); - _RET(value); -} - -static PyObject * -H_set_sw(void *ptr, PyObject *value, Py_ssize_t size) -{ - unsigned long val; - unsigned short field; - if (get_ulong(value, &val) < 0) - return NULL; - memcpy(&field, ptr, sizeof(field)); - field = SWAP_2(field); - field = SET(unsigned short, field, val, size); - field = SWAP_2(field); - memcpy(ptr, &field, sizeof(field)); - _RET(value); -} - - -static PyObject * -H_get(void *ptr, Py_ssize_t size) -{ - unsigned short val; - memcpy(&val, ptr, sizeof(val)); - GET_BITFIELD(val, size); - return PyLong_FromLong(val); -} - -static PyObject * -H_get_sw(void *ptr, Py_ssize_t size) -{ - unsigned short val; - memcpy(&val, ptr, sizeof(val)); - val = SWAP_2(val); - GET_BITFIELD(val, size); - return PyLong_FromLong(val); -} - -static PyObject * -i_set(void *ptr, PyObject *value, Py_ssize_t size) -{ - long val; - int x; - if (get_long(value, &val) < 0) - return NULL; - memcpy(&x, ptr, sizeof(x)); - x = SET(int, x, val, size); - memcpy(ptr, &x, sizeof(x)); - _RET(value); -} - -static PyObject * -i_set_sw(void *ptr, PyObject *value, Py_ssize_t size) -{ - long val; - int field; - if (get_long(value, &val) < 0) - return NULL; - memcpy(&field, ptr, sizeof(field)); - field = SWAP_INT(field); - field = SET(int, field, val, size); - field = SWAP_INT(field); - memcpy(ptr, &field, sizeof(field)); - _RET(value); -} - - -static PyObject * -i_get(void *ptr, Py_ssize_t size) -{ - int val; - memcpy(&val, ptr, sizeof(val)); - GET_BITFIELD(val, size); - return PyLong_FromLong(val); -} - -static PyObject * -i_get_sw(void *ptr, Py_ssize_t size) -{ - int val; - memcpy(&val, ptr, sizeof(val)); - val = SWAP_INT(val); - GET_BITFIELD(val, size); - return PyLong_FromLong(val); -} - -#ifdef MS_WIN32 -/* short BOOL - VARIANT_BOOL */ -static PyObject * -vBOOL_set(void *ptr, PyObject *value, Py_ssize_t size) -{ - switch (PyObject_IsTrue(value)) { - case -1: - return NULL; - case 0: - *(short int *)ptr = VARIANT_FALSE; - _RET(value); - default: - *(short int *)ptr = VARIANT_TRUE; - _RET(value); - } -} - -static PyObject * -vBOOL_get(void *ptr, Py_ssize_t size) -{ - return PyBool_FromLong((long)*(short int *)ptr); -} -#endif - -static PyObject * -bool_set(void *ptr, PyObject *value, Py_ssize_t size) -{ - switch (PyObject_IsTrue(value)) { - case -1: - return NULL; - case 0: - *(_Bool *)ptr = 0; - _RET(value); - default: - *(_Bool *)ptr = 1; - _RET(value); - } -} - -static PyObject * -bool_get(void *ptr, Py_ssize_t size) -{ - return PyBool_FromLong((long)*(_Bool *)ptr); -} - -static PyObject * -I_set(void *ptr, PyObject *value, Py_ssize_t size) -{ - unsigned long val; - unsigned int x; - if (get_ulong(value, &val) < 0) - return NULL; - memcpy(&x, ptr, sizeof(x)); - x = SET(unsigned int, x, val, size); - memcpy(ptr, &x, sizeof(x)); - _RET(value); -} - -static PyObject * -I_set_sw(void *ptr, PyObject *value, Py_ssize_t size) -{ - unsigned long val; - unsigned int field; - if (get_ulong(value, &val) < 0) - return NULL; - memcpy(&field, ptr, sizeof(field)); - field = SWAP_INT(field); - field = SET(unsigned int, field, (unsigned int)val, size); - field = SWAP_INT(field); - memcpy(ptr, &field, sizeof(field)); - _RET(value); -} - - -static PyObject * -I_get(void *ptr, Py_ssize_t size) -{ - unsigned int val; - memcpy(&val, ptr, sizeof(val)); - GET_BITFIELD(val, size); - return PyLong_FromUnsignedLong(val); -} - -static PyObject * -I_get_sw(void *ptr, Py_ssize_t size) -{ - unsigned int val; - memcpy(&val, ptr, sizeof(val)); - val = SWAP_INT(val); - GET_BITFIELD(val, size); - return PyLong_FromUnsignedLong(val); -} - -static PyObject * -l_set(void *ptr, PyObject *value, Py_ssize_t size) -{ - long val; - long x; - if (get_long(value, &val) < 0) - return NULL; - memcpy(&x, ptr, sizeof(x)); - x = SET(long, x, val, size); - memcpy(ptr, &x, sizeof(x)); - _RET(value); -} - -static PyObject * -l_set_sw(void *ptr, PyObject *value, Py_ssize_t size) -{ - long val; - long field; - if (get_long(value, &val) < 0) - return NULL; - memcpy(&field, ptr, sizeof(field)); - field = SWAP_LONG(field); - field = SET(long, field, val, size); - field = SWAP_LONG(field); - memcpy(ptr, &field, sizeof(field)); - _RET(value); -} - - -static PyObject * -l_get(void *ptr, Py_ssize_t size) -{ - long val; - memcpy(&val, ptr, sizeof(val)); - GET_BITFIELD(val, size); - return PyLong_FromLong(val); -} - -static PyObject * -l_get_sw(void *ptr, Py_ssize_t size) -{ - long val; - memcpy(&val, ptr, sizeof(val)); - val = SWAP_LONG(val); - GET_BITFIELD(val, size); - return PyLong_FromLong(val); -} - -static PyObject * -L_set(void *ptr, PyObject *value, Py_ssize_t size) -{ - unsigned long val; - unsigned long x; - if (get_ulong(value, &val) < 0) - return NULL; - memcpy(&x, ptr, sizeof(x)); - x = SET(unsigned long, x, val, size); - memcpy(ptr, &x, sizeof(x)); - _RET(value); -} - -static PyObject * -L_set_sw(void *ptr, PyObject *value, Py_ssize_t size) -{ - unsigned long val; - unsigned long field; - if (get_ulong(value, &val) < 0) - return NULL; - memcpy(&field, ptr, sizeof(field)); - field = SWAP_LONG(field); - field = SET(unsigned long, field, val, size); - field = SWAP_LONG(field); - memcpy(ptr, &field, sizeof(field)); - _RET(value); -} - - -static PyObject * -L_get(void *ptr, Py_ssize_t size) -{ - unsigned long val; - memcpy(&val, ptr, sizeof(val)); - GET_BITFIELD(val, size); - return PyLong_FromUnsignedLong(val); -} - -static PyObject * -L_get_sw(void *ptr, Py_ssize_t size) -{ - unsigned long val; - memcpy(&val, ptr, sizeof(val)); - val = SWAP_LONG(val); - GET_BITFIELD(val, size); - return PyLong_FromUnsignedLong(val); -} - -static PyObject * -q_set(void *ptr, PyObject *value, Py_ssize_t size) -{ - long long val; - long long x; - if (get_longlong(value, &val) < 0) - return NULL; - memcpy(&x, ptr, sizeof(x)); - x = SET(long long, x, val, size); - memcpy(ptr, &x, sizeof(x)); - _RET(value); -} - -static PyObject * -q_set_sw(void *ptr, PyObject *value, Py_ssize_t size) -{ - long long val; - long long field; - if (get_longlong(value, &val) < 0) - return NULL; - memcpy(&field, ptr, sizeof(field)); - field = SWAP_8(field); - field = SET(long long, field, val, size); - field = SWAP_8(field); - memcpy(ptr, &field, sizeof(field)); - _RET(value); -} - -static PyObject * -q_get(void *ptr, Py_ssize_t size) -{ - long long val; - memcpy(&val, ptr, sizeof(val)); - GET_BITFIELD(val, size); - return PyLong_FromLongLong(val); -} - -static PyObject * -q_get_sw(void *ptr, Py_ssize_t size) -{ - long long val; - memcpy(&val, ptr, sizeof(val)); - val = SWAP_8(val); - GET_BITFIELD(val, size); - return PyLong_FromLongLong(val); -} - -static PyObject * -Q_set(void *ptr, PyObject *value, Py_ssize_t size) -{ - unsigned long long val; - unsigned long long x; - if (get_ulonglong(value, &val) < 0) - return NULL; - memcpy(&x, ptr, sizeof(x)); - x = SET(long long, x, val, size); - memcpy(ptr, &x, sizeof(x)); - _RET(value); -} - -static PyObject * -Q_set_sw(void *ptr, PyObject *value, Py_ssize_t size) -{ - unsigned long long val; - unsigned long long field; - if (get_ulonglong(value, &val) < 0) - return NULL; - memcpy(&field, ptr, sizeof(field)); - field = SWAP_8(field); - field = SET(unsigned long long, field, val, size); - field = SWAP_8(field); - memcpy(ptr, &field, sizeof(field)); - _RET(value); -} - -static PyObject * -Q_get(void *ptr, Py_ssize_t size) -{ - unsigned long long val; - memcpy(&val, ptr, sizeof(val)); - GET_BITFIELD(val, size); - return PyLong_FromUnsignedLongLong(val); -} - -static PyObject * -Q_get_sw(void *ptr, Py_ssize_t size) -{ - unsigned long long val; - memcpy(&val, ptr, sizeof(val)); - val = SWAP_8(val); - GET_BITFIELD(val, size); - return PyLong_FromUnsignedLongLong(val); -} - -/***************************************************************** - * non-integer accessor methods, not supporting bit fields - */ - - -static PyObject * -g_set(void *ptr, PyObject *value, Py_ssize_t size) -{ - long double x; - - x = PyFloat_AsDouble(value); - if (x == -1 && PyErr_Occurred()) - return NULL; - memcpy(ptr, &x, sizeof(long double)); - _RET(value); -} - -static PyObject * -g_get(void *ptr, Py_ssize_t size) -{ - long double val; - memcpy(&val, ptr, sizeof(long double)); - return PyFloat_FromDouble(val); -} - -static PyObject * -d_set(void *ptr, PyObject *value, Py_ssize_t size) -{ - double x; - - x = PyFloat_AsDouble(value); - if (x == -1 && PyErr_Occurred()) - return NULL; - memcpy(ptr, &x, sizeof(double)); - _RET(value); -} - -static PyObject * -d_get(void *ptr, Py_ssize_t size) -{ - double val; - memcpy(&val, ptr, sizeof(val)); - return PyFloat_FromDouble(val); -} - -static PyObject * -d_set_sw(void *ptr, PyObject *value, Py_ssize_t size) -{ - double x; - - x = PyFloat_AsDouble(value); - if (x == -1 && PyErr_Occurred()) - return NULL; -#ifdef WORDS_BIGENDIAN - if (_PyFloat_Pack8(x, (unsigned char *)ptr, 1)) - return NULL; -#else - if (_PyFloat_Pack8(x, (unsigned char *)ptr, 0)) - return NULL; -#endif - _RET(value); -} - -static PyObject * -d_get_sw(void *ptr, Py_ssize_t size) -{ -#ifdef WORDS_BIGENDIAN - return PyFloat_FromDouble(_PyFloat_Unpack8(ptr, 1)); -#else - return PyFloat_FromDouble(_PyFloat_Unpack8(ptr, 0)); -#endif -} - -static PyObject * -f_set(void *ptr, PyObject *value, Py_ssize_t size) -{ - float x; - - x = (float)PyFloat_AsDouble(value); - if (x == -1 && PyErr_Occurred()) - return NULL; - memcpy(ptr, &x, sizeof(x)); - _RET(value); -} - -static PyObject * -f_get(void *ptr, Py_ssize_t size) -{ - float val; - memcpy(&val, ptr, sizeof(val)); - return PyFloat_FromDouble(val); -} - -static PyObject * -f_set_sw(void *ptr, PyObject *value, Py_ssize_t size) -{ - float x; - - x = (float)PyFloat_AsDouble(value); - if (x == -1 && PyErr_Occurred()) - return NULL; -#ifdef WORDS_BIGENDIAN - if (_PyFloat_Pack4(x, (unsigned char *)ptr, 1)) - return NULL; -#else - if (_PyFloat_Pack4(x, (unsigned char *)ptr, 0)) - return NULL; -#endif - _RET(value); -} - -static PyObject * -f_get_sw(void *ptr, Py_ssize_t size) -{ -#ifdef WORDS_BIGENDIAN - return PyFloat_FromDouble(_PyFloat_Unpack4(ptr, 1)); -#else - return PyFloat_FromDouble(_PyFloat_Unpack4(ptr, 0)); -#endif -} - -/* - py_object refcounts: - - 1. If we have a py_object instance, O_get must Py_INCREF the returned - object, of course. If O_get is called from a function result, no py_object - instance is created - so callproc.c::GetResult has to call Py_DECREF. - - 2. The memory block in py_object owns a refcount. So, py_object must call - Py_DECREF on destruction. Maybe only when b_needsfree is non-zero. -*/ -static PyObject * -O_get(void *ptr, Py_ssize_t size) -{ - PyObject *ob = *(PyObject **)ptr; - if (ob == NULL) { - if (!PyErr_Occurred()) - /* Set an error if not yet set */ - PyErr_SetString(PyExc_ValueError, - "PyObject is NULL"); - return NULL; - } - Py_INCREF(ob); - return ob; -} - -static PyObject * -O_set(void *ptr, PyObject *value, Py_ssize_t size) -{ - /* Hm, does the memory block need it's own refcount or not? */ - *(PyObject **)ptr = value; - Py_INCREF(value); - return value; -} - - -static PyObject * -c_set(void *ptr, PyObject *value, Py_ssize_t size) -{ - if (PyBytes_Check(value) && PyBytes_GET_SIZE(value) == 1) { - *(char *)ptr = PyBytes_AS_STRING(value)[0]; - _RET(value); - } - if (PyByteArray_Check(value) && PyByteArray_GET_SIZE(value) == 1) { - *(char *)ptr = PyByteArray_AS_STRING(value)[0]; - _RET(value); - } - if (PyLong_Check(value)) - { - long longval = PyLong_AS_LONG(value); - if (longval < 0 || longval >= 256) - goto error; - *(char *)ptr = (char)longval; - _RET(value); - } - error: - PyErr_Format(PyExc_TypeError, - "one character bytes, bytearray or integer expected"); - return NULL; -} - - -static PyObject * -c_get(void *ptr, Py_ssize_t size) -{ - return PyBytes_FromStringAndSize((char *)ptr, 1); -} - -#ifdef CTYPES_UNICODE -/* u - a single wchar_t character */ -static PyObject * -u_set(void *ptr, PyObject *value, Py_ssize_t size) -{ - Py_ssize_t len; - wchar_t chars[2]; - if (!PyUnicode_Check(value)) { - PyErr_Format(PyExc_TypeError, - "unicode string expected instead of %s instance", - value->ob_type->tp_name); - return NULL; - } else - Py_INCREF(value); - - len = PyUnicode_AsWideChar(value, chars, 2); - if (len != 1) { - Py_DECREF(value); - PyErr_SetString(PyExc_TypeError, - "one character unicode string expected"); - return NULL; - } - - *(wchar_t *)ptr = chars[0]; - Py_DECREF(value); - - _RET(value); -} - - -static PyObject * -u_get(void *ptr, Py_ssize_t size) -{ - return PyUnicode_FromWideChar((wchar_t *)ptr, 1); -} - -/* U - a unicode string */ -static PyObject * -U_get(void *ptr, Py_ssize_t size) -{ - Py_ssize_t len; - wchar_t *p; - - size /= sizeof(wchar_t); /* we count character units here, not bytes */ - - /* We need 'result' to be able to count the characters with wcslen, - since ptr may not be NUL terminated. If the length is smaller (if - it was actually NUL terminated, we construct a new one and throw - away the result. - */ - /* chop off at the first NUL character, if any. */ - p = (wchar_t*)ptr; - for (len = 0; len < size; ++len) { - if (!p[len]) - break; - } - - return PyUnicode_FromWideChar((wchar_t *)ptr, len); -} - -static PyObject * -U_set(void *ptr, PyObject *value, Py_ssize_t length) -{ - Py_UNICODE *wstr; - Py_ssize_t size; - - /* It's easier to calculate in characters than in bytes */ - length /= sizeof(wchar_t); - - if (!PyUnicode_Check(value)) { - PyErr_Format(PyExc_TypeError, - "unicode string expected instead of %s instance", - value->ob_type->tp_name); - return NULL; - } - - wstr = PyUnicode_AsUnicodeAndSize(value, &size); - if (wstr == NULL) - return NULL; - if (size > length) { - PyErr_Format(PyExc_ValueError, - "string too long (%zd, maximum length %zd)", - size, length); - return NULL; - } else if (size < length-1) - /* copy terminating NUL character if there is space */ - size += 1; - - if (PyUnicode_AsWideChar(value, (wchar_t *)ptr, size) == -1) { - return NULL; - } - - Py_INCREF(value); - return value; -} - -#endif - -static PyObject * -s_get(void *ptr, Py_ssize_t size) -{ - Py_ssize_t i; - char *p; - - p = (char *)ptr; - for (i = 0; i < size; ++i) { - if (*p++ == '\0') - break; - } - - return PyBytes_FromStringAndSize((char *)ptr, (Py_ssize_t)i); -} - -static PyObject * -s_set(void *ptr, PyObject *value, Py_ssize_t length) -{ - char *data; - Py_ssize_t size; - - if(!PyBytes_Check(value)) { - PyErr_Format(PyExc_TypeError, - "expected bytes, %s found", - value->ob_type->tp_name); - return NULL; - } - - data = PyBytes_AS_STRING(value); - size = strlen(data); /* XXX Why not Py_SIZE(value)? */ - if (size < length) { - /* This will copy the terminating NUL character - * if there is space for it. - */ - ++size; - } else if (size > length) { - PyErr_Format(PyExc_ValueError, - "bytes too long (%zd, maximum length %zd)", - size, length); - return NULL; - } - /* Also copy the terminating NUL character if there is space */ - memcpy((char *)ptr, data, size); - - _RET(value); -} - -static PyObject * -z_set(void *ptr, PyObject *value, Py_ssize_t size) -{ - if (value == Py_None) { - *(char **)ptr = NULL; - Py_INCREF(value); - return value; - } - if (PyBytes_Check(value)) { - *(char **)ptr = PyBytes_AsString(value); - Py_INCREF(value); - return value; - } else if (PyLong_Check(value)) { -#if SIZEOF_VOID_P == SIZEOF_LONG_LONG - *(char **)ptr = (char *)PyLong_AsUnsignedLongLongMask(value); -#else - *(char **)ptr = (char *)PyLong_AsUnsignedLongMask(value); -#endif - _RET(value); - } - PyErr_Format(PyExc_TypeError, - "bytes or integer address expected instead of %s instance", - value->ob_type->tp_name); - return NULL; -} - -static PyObject * -z_get(void *ptr, Py_ssize_t size) -{ - /* XXX What about invalid pointers ??? */ - if (*(void **)ptr) { - return PyBytes_FromStringAndSize(*(char **)ptr, - strlen(*(char **)ptr)); - } else { - Py_INCREF(Py_None); - return Py_None; - } -} - -#ifdef CTYPES_UNICODE -static PyObject * -Z_set(void *ptr, PyObject *value, Py_ssize_t size) -{ - PyObject *keep; - wchar_t *buffer; - - if (value == Py_None) { - *(wchar_t **)ptr = NULL; - Py_INCREF(value); - return value; - } - if (PyLong_Check(value)) { -#if SIZEOF_VOID_P == SIZEOF_LONG_LONG - *(wchar_t **)ptr = (wchar_t *)PyLong_AsUnsignedLongLongMask(value); -#else - *(wchar_t **)ptr = (wchar_t *)PyLong_AsUnsignedLongMask(value); -#endif - Py_INCREF(Py_None); - return Py_None; - } - if (!PyUnicode_Check(value)) { - PyErr_Format(PyExc_TypeError, - "unicode string or integer address expected instead of %s instance", - value->ob_type->tp_name); - return NULL; - } - - /* We must create a wchar_t* buffer from the unicode object, - and keep it alive */ - buffer = _PyUnicode_AsWideCharString(value); - if (!buffer) - return NULL; - keep = PyCapsule_New(buffer, CTYPES_CFIELD_CAPSULE_NAME_PYMEM, pymem_destructor); - if (!keep) { - PyMem_Free(buffer); - return NULL; - } - *(wchar_t **)ptr = buffer; - return keep; -} - -static PyObject * -Z_get(void *ptr, Py_ssize_t size) -{ - wchar_t *p; - p = *(wchar_t **)ptr; - if (p) { - return PyUnicode_FromWideChar(p, wcslen(p)); - } else { - Py_INCREF(Py_None); - return Py_None; - } -} -#endif - -#ifdef MS_WIN32 -static PyObject * -BSTR_set(void *ptr, PyObject *value, Py_ssize_t size) -{ - BSTR bstr; - - /* convert value into a PyUnicodeObject or NULL */ - if (Py_None == value) { - value = NULL; - } else if (!PyUnicode_Check(value)) { - PyErr_Format(PyExc_TypeError, - "unicode string expected instead of %s instance", - value->ob_type->tp_name); - return NULL; - } - - /* create a BSTR from value */ - if (value) { - wchar_t* wvalue; - Py_ssize_t wsize; - wvalue = PyUnicode_AsUnicodeAndSize(value, &wsize); - if (wvalue == NULL) - return NULL; - if ((unsigned) wsize != wsize) { - PyErr_SetString(PyExc_ValueError, "String too long for BSTR"); - return NULL; - } - bstr = SysAllocStringLen(wvalue, (unsigned)wsize); - } else - bstr = NULL; - - /* free the previous contents, if any */ - if (*(BSTR *)ptr) - SysFreeString(*(BSTR *)ptr); - - /* and store it */ - *(BSTR *)ptr = bstr; - - /* We don't need to keep any other object */ - _RET(value); -} - - -static PyObject * -BSTR_get(void *ptr, Py_ssize_t size) -{ - BSTR p; - p = *(BSTR *)ptr; - if (p) - return PyUnicode_FromWideChar(p, SysStringLen(p)); - else { - /* Hm, it seems NULL pointer and zero length string are the - same in BSTR, see Don Box, p 81 - */ - Py_INCREF(Py_None); - return Py_None; - } -} -#endif - -static PyObject * -P_set(void *ptr, PyObject *value, Py_ssize_t size) -{ - void *v; - if (value == Py_None) { - *(void **)ptr = NULL; - _RET(value); - } - - if (!PyLong_Check(value)) { - PyErr_SetString(PyExc_TypeError, - "cannot be converted to pointer"); - return NULL; - } - -#if SIZEOF_VOID_P <= SIZEOF_LONG - v = (void *)PyLong_AsUnsignedLongMask(value); -#else -#if SIZEOF_LONG_LONG < SIZEOF_VOID_P -# error "PyLong_AsVoidPtr: sizeof(long long) < sizeof(void*)" -#endif - v = (void *)PyLong_AsUnsignedLongLongMask(value); -#endif - - if (PyErr_Occurred()) - return NULL; - - *(void **)ptr = v; - _RET(value); -} - -static PyObject * -P_get(void *ptr, Py_ssize_t size) -{ - if (*(void **)ptr == NULL) { - Py_INCREF(Py_None); - return Py_None; - } - return PyLong_FromVoidPtr(*(void **)ptr); -} - -static struct fielddesc formattable[] = { - { 's', s_set, s_get, &ffi_type_pointer}, - { 'b', b_set, b_get, &ffi_type_schar}, - { 'B', B_set, B_get, &ffi_type_uchar}, - { 'c', c_set, c_get, &ffi_type_schar}, - { 'd', d_set, d_get, &ffi_type_double, d_set_sw, d_get_sw}, - { 'g', g_set, g_get, &ffi_type_longdouble}, - { 'f', f_set, f_get, &ffi_type_float, f_set_sw, f_get_sw}, - { 'h', h_set, h_get, &ffi_type_sshort, h_set_sw, h_get_sw}, - { 'H', H_set, H_get, &ffi_type_ushort, H_set_sw, H_get_sw}, - { 'i', i_set, i_get, &ffi_type_sint, i_set_sw, i_get_sw}, - { 'I', I_set, I_get, &ffi_type_uint, I_set_sw, I_get_sw}, -/* XXX Hm, sizeof(int) == sizeof(long) doesn't hold on every platform */ -/* As soon as we can get rid of the type codes, this is no longer a problem */ -#if SIZEOF_LONG == 4 - { 'l', l_set, l_get, &ffi_type_sint32, l_set_sw, l_get_sw}, - { 'L', L_set, L_get, &ffi_type_uint32, L_set_sw, L_get_sw}, -#elif SIZEOF_LONG == 8 - { 'l', l_set, l_get, &ffi_type_sint64, l_set_sw, l_get_sw}, - { 'L', L_set, L_get, &ffi_type_uint64, L_set_sw, L_get_sw}, -#else -# error -#endif -#if SIZEOF_LONG_LONG == 8 - { 'q', q_set, q_get, &ffi_type_sint64, q_set_sw, q_get_sw}, - { 'Q', Q_set, Q_get, &ffi_type_uint64, Q_set_sw, Q_get_sw}, -#else -# error -#endif - { 'P', P_set, P_get, &ffi_type_pointer}, - { 'z', z_set, z_get, &ffi_type_pointer}, -#ifdef CTYPES_UNICODE - { 'u', u_set, u_get, NULL}, /* ffi_type set later */ - { 'U', U_set, U_get, &ffi_type_pointer}, - { 'Z', Z_set, Z_get, &ffi_type_pointer}, -#endif -#ifdef MS_WIN32 - { 'X', BSTR_set, BSTR_get, &ffi_type_pointer}, - { 'v', vBOOL_set, vBOOL_get, &ffi_type_sshort}, -#endif -#if SIZEOF__BOOL == 1 - { '?', bool_set, bool_get, &ffi_type_uchar}, /* Also fallback for no native _Bool support */ -#elif SIZEOF__BOOL == SIZEOF_SHORT - { '?', bool_set, bool_get, &ffi_type_ushort}, -#elif SIZEOF__BOOL == SIZEOF_INT - { '?', bool_set, bool_get, &ffi_type_uint, I_set_sw, I_get_sw}, -#elif SIZEOF__BOOL == SIZEOF_LONG - { '?', bool_set, bool_get, &ffi_type_ulong, L_set_sw, L_get_sw}, -#elif SIZEOF__BOOL == SIZEOF_LONG_LONG - { '?', bool_set, bool_get, &ffi_type_ulong, Q_set_sw, Q_get_sw}, -#endif /* SIZEOF__BOOL */ - { 'O', O_set, O_get, &ffi_type_pointer}, - { 0, NULL, NULL, NULL}, -}; - -/* - Ideas: Implement VARIANT in this table, using 'V' code. - Use '?' as code for BOOL. -*/ - -struct fielddesc * -_ctypes_get_fielddesc(const char *fmt) -{ - static int initialized = 0; - struct fielddesc *table = formattable; - - if (!initialized) { - initialized = 1; -#ifdef CTYPES_UNICODE - if (sizeof(wchar_t) == sizeof(short)) - _ctypes_get_fielddesc("u")->pffi_type = &ffi_type_sshort; - else if (sizeof(wchar_t) == sizeof(int)) - _ctypes_get_fielddesc("u")->pffi_type = &ffi_type_sint; - else if (sizeof(wchar_t) == sizeof(long)) - _ctypes_get_fielddesc("u")->pffi_type = &ffi_type_slong; -#endif - } - - for (; table->code; ++table) { - if (table->code == fmt[0]) - return table; - } - return NULL; -} - -typedef struct { char c; char x; } s_char; -typedef struct { char c; short x; } s_short; -typedef struct { char c; int x; } s_int; -typedef struct { char c; long x; } s_long; -typedef struct { char c; float x; } s_float; -typedef struct { char c; double x; } s_double; -typedef struct { char c; long double x; } s_long_double; -typedef struct { char c; char *x; } s_char_p; -typedef struct { char c; void *x; } s_void_p; - -/* -#define CHAR_ALIGN (sizeof(s_char) - sizeof(char)) -#define SHORT_ALIGN (sizeof(s_short) - sizeof(short)) -#define LONG_ALIGN (sizeof(s_long) - sizeof(long)) -*/ -#define INT_ALIGN (sizeof(s_int) - sizeof(int)) -#define FLOAT_ALIGN (sizeof(s_float) - sizeof(float)) -#define DOUBLE_ALIGN (sizeof(s_double) - sizeof(double)) -#define LONGDOUBLE_ALIGN (sizeof(s_long_double) - sizeof(long double)) - -/* #define CHAR_P_ALIGN (sizeof(s_char_p) - sizeof(char*)) */ -#define VOID_P_ALIGN (sizeof(s_void_p) - sizeof(void*)) - -/* -#ifdef HAVE_USABLE_WCHAR_T -typedef struct { char c; wchar_t x; } s_wchar; -typedef struct { char c; wchar_t *x; } s_wchar_p; - -#define WCHAR_ALIGN (sizeof(s_wchar) - sizeof(wchar_t)) -#define WCHAR_P_ALIGN (sizeof(s_wchar_p) - sizeof(wchar_t*)) -#endif -*/ - -typedef struct { char c; long long x; } s_long_long; -#define LONG_LONG_ALIGN (sizeof(s_long_long) - sizeof(long long)) - -/* from ffi.h: -typedef struct _ffi_type -{ - size_t size; - unsigned short alignment; - unsigned short type; - struct _ffi_type **elements; -} ffi_type; -*/ - -/* align and size are bogus for void, but they must not be zero */ -ffi_type ffi_type_void = { 1, 1, FFI_TYPE_VOID }; - -ffi_type ffi_type_uint8 = { 1, 1, FFI_TYPE_UINT8 }; -ffi_type ffi_type_sint8 = { 1, 1, FFI_TYPE_SINT8 }; - -ffi_type ffi_type_uint16 = { 2, 2, FFI_TYPE_UINT16 }; -ffi_type ffi_type_sint16 = { 2, 2, FFI_TYPE_SINT16 }; - -ffi_type ffi_type_uint32 = { 4, INT_ALIGN, FFI_TYPE_UINT32 }; -ffi_type ffi_type_sint32 = { 4, INT_ALIGN, FFI_TYPE_SINT32 }; - -ffi_type ffi_type_uint64 = { 8, LONG_LONG_ALIGN, FFI_TYPE_UINT64 }; -ffi_type ffi_type_sint64 = { 8, LONG_LONG_ALIGN, FFI_TYPE_SINT64 }; - -ffi_type ffi_type_float = { sizeof(float), FLOAT_ALIGN, FFI_TYPE_FLOAT }; -ffi_type ffi_type_double = { sizeof(double), DOUBLE_ALIGN, FFI_TYPE_DOUBLE }; - -#ifdef ffi_type_longdouble -#undef ffi_type_longdouble -#endif - /* This is already defined on OSX */ -ffi_type ffi_type_longdouble = { sizeof(long double), LONGDOUBLE_ALIGN, - FFI_TYPE_LONGDOUBLE }; - -ffi_type ffi_type_pointer = { sizeof(void *), VOID_P_ALIGN, FFI_TYPE_POINTER }; - -/*---------------- EOF ----------------*/ diff --git a/third_party/python/Modules/_ctypes/ctypes.h b/third_party/python/Modules/_ctypes/ctypes.h deleted file mode 100644 index 83ae89ccd..000000000 --- a/third_party/python/Modules/_ctypes/ctypes.h +++ /dev/null @@ -1,372 +0,0 @@ -/* clang-format off */ -#if defined (__SVR4) && defined (__sun) -# include -#endif - -#ifndef MS_WIN32 -#define max(a, b) ((a) > (b) ? (a) : (b)) -#define min(a, b) ((a) < (b) ? (a) : (b)) - -#define PARAMFLAG_FIN 0x1 -#define PARAMFLAG_FOUT 0x2 -#define PARAMFLAG_FLCID 0x4 -#endif - -typedef struct tagPyCArgObject PyCArgObject; -typedef struct tagCDataObject CDataObject; -typedef PyObject *(* GETFUNC)(void *, Py_ssize_t size); -typedef PyObject *(* SETFUNC)(void *, PyObject *value, Py_ssize_t size); -typedef PyCArgObject *(* PARAMFUNC)(CDataObject *obj); - -/* A default buffer in CDataObject, which can be used for small C types. If -this buffer is too small, PyMem_Malloc will be called to create a larger one, -and this one is not used. - -Making CDataObject a variable size object would be a better solution, but more -difficult in the presence of PyCFuncPtrObject. Maybe later. -*/ -union value { - char c[16]; - short s; - int i; - long l; - float f; - double d; - long long ll; - long double D; -}; - -/* - Hm. Are there CDataObject's which do not need the b_objects member? In - this case we probably should introduce b_flags to mark it as present... If - b_objects is not present/unused b_length is unneeded as well. -*/ - -struct tagCDataObject { - PyObject_HEAD - char *b_ptr; /* pointer to memory block */ - int b_needsfree; /* need _we_ free the memory? */ - CDataObject *b_base; /* pointer to base object or NULL */ - Py_ssize_t b_size; /* size of memory block in bytes */ - Py_ssize_t b_length; /* number of references we need */ - Py_ssize_t b_index; /* index of this object into base's - b_object list */ - PyObject *b_objects; /* dictionary of references we need to keep, or Py_None */ - union value b_value; -}; - -typedef struct { - PyObject_VAR_HEAD - ffi_closure *pcl_write; /* the C callable, writeable */ - void *pcl_exec; /* the C callable, executable */ - ffi_cif cif; - int flags; - PyObject *converters; - PyObject *callable; - PyObject *restype; - SETFUNC setfunc; - ffi_type *ffi_restype; - ffi_type *atypes[1]; -} CThunkObject; -extern PyTypeObject PyCThunk_Type; -#define CThunk_CheckExact(v) ((v)->ob_type == &PyCThunk_Type) - -typedef struct { - /* First part identical to tagCDataObject */ - PyObject_HEAD - char *b_ptr; /* pointer to memory block */ - int b_needsfree; /* need _we_ free the memory? */ - CDataObject *b_base; /* pointer to base object or NULL */ - Py_ssize_t b_size; /* size of memory block in bytes */ - Py_ssize_t b_length; /* number of references we need */ - Py_ssize_t b_index; /* index of this object into base's - b_object list */ - PyObject *b_objects; /* list of references we need to keep */ - union value b_value; - /* end of tagCDataObject, additional fields follow */ - - CThunkObject *thunk; - PyObject *callable; - - /* These two fields will override the ones in the type's stgdict if - they are set */ - PyObject *converters; - PyObject *argtypes; - PyObject *restype; - PyObject *checker; - PyObject *errcheck; -#ifdef MS_WIN32 - int index; - GUID *iid; -#endif - PyObject *paramflags; -} PyCFuncPtrObject; - -extern PyTypeObject PyCStgDict_Type; -#define PyCStgDict_CheckExact(v) ((v)->ob_type == &PyCStgDict_Type) -#define PyCStgDict_Check(v) PyObject_TypeCheck(v, &PyCStgDict_Type) - -extern int PyCStructUnionType_update_stgdict(PyObject *fields, PyObject *type, int isStruct); -extern int PyType_stginfo(PyTypeObject *self, Py_ssize_t *psize, Py_ssize_t *palign, Py_ssize_t *plength); -extern int PyObject_stginfo(PyObject *self, Py_ssize_t *psize, Py_ssize_t *palign, Py_ssize_t *plength); - - - -extern PyTypeObject PyCData_Type; -#define CDataObject_CheckExact(v) ((v)->ob_type == &PyCData_Type) -#define CDataObject_Check(v) PyObject_TypeCheck(v, &PyCData_Type) -#define _CDataObject_HasExternalBuffer(v) ((v)->b_ptr != (char *)&(v)->b_value) - -extern PyTypeObject PyCSimpleType_Type; -#define PyCSimpleTypeObject_CheckExact(v) ((v)->ob_type == &PyCSimpleType_Type) -#define PyCSimpleTypeObject_Check(v) PyObject_TypeCheck(v, &PyCSimpleType_Type) - -extern PyTypeObject PyCField_Type; -extern struct fielddesc *_ctypes_get_fielddesc(const char *fmt); - - -extern PyObject * -PyCField_FromDesc(PyObject *desc, Py_ssize_t index, - Py_ssize_t *pfield_size, int bitsize, int *pbitofs, - Py_ssize_t *psize, Py_ssize_t *poffset, Py_ssize_t *palign, - int pack, int is_big_endian); - -extern PyObject *PyCData_AtAddress(PyObject *type, void *buf); -extern PyObject *PyCData_FromBytes(PyObject *type, char *data, Py_ssize_t length); - -extern PyTypeObject PyCArrayType_Type; -extern PyTypeObject PyCArray_Type; -extern PyTypeObject PyCPointerType_Type; -extern PyTypeObject PyCPointer_Type; -extern PyTypeObject PyCFuncPtr_Type; -extern PyTypeObject PyCFuncPtrType_Type; -extern PyTypeObject PyCStructType_Type; - -#define PyCArrayTypeObject_Check(v) PyObject_TypeCheck(v, &PyCArrayType_Type) -#define ArrayObject_Check(v) PyObject_TypeCheck(v, &PyCArray_Type) -#define PointerObject_Check(v) PyObject_TypeCheck(v, &PyCPointer_Type) -#define PyCPointerTypeObject_Check(v) PyObject_TypeCheck(v, &PyCPointerType_Type) -#define PyCFuncPtrObject_Check(v) PyObject_TypeCheck(v, &PyCFuncPtr_Type) -#define PyCFuncPtrTypeObject_Check(v) PyObject_TypeCheck(v, &PyCFuncPtrType_Type) -#define PyCStructTypeObject_Check(v) PyObject_TypeCheck(v, &PyCStructType_Type) - -extern PyObject * -PyCArrayType_from_ctype(PyObject *itemtype, Py_ssize_t length); - -extern PyMethodDef _ctypes_module_methods[]; - -extern CThunkObject *_ctypes_alloc_callback(PyObject *callable, - PyObject *converters, - PyObject *restype, - int flags); -/* a table entry describing a predefined ctypes type */ -struct fielddesc { - char code; - SETFUNC setfunc; - GETFUNC getfunc; - ffi_type *pffi_type; /* always statically allocated */ - SETFUNC setfunc_swapped; - GETFUNC getfunc_swapped; -}; - -typedef struct { - PyObject_HEAD - Py_ssize_t offset; - Py_ssize_t size; - Py_ssize_t index; /* Index into CDataObject's - object array */ - PyObject *proto; /* a type or NULL */ - GETFUNC getfunc; /* getter function if proto is NULL */ - SETFUNC setfunc; /* setter function if proto is NULL */ - int anonymous; -} CFieldObject; - -/* A subclass of PyDictObject, used as the instance dictionary of ctypes - metatypes */ -typedef struct { - PyDictObject dict; /* first part identical to PyDictObject */ -/* The size and align fields are unneeded, they are in ffi_type as well. As - an experiment shows, it's trivial to get rid of them, the only thing to - remember is that in PyCArrayType_new the ffi_type fields must be filled in - - so far it was unneeded because libffi doesn't support arrays at all - (because they are passed as pointers to function calls anyway). But it's - too much risk to change that now, and there are other fields which doesn't - belong into this structure anyway. Maybe in ctypes 2.0... (ctypes 2000?) -*/ - Py_ssize_t size; /* number of bytes */ - Py_ssize_t align; /* alignment requirements */ - Py_ssize_t length; /* number of fields */ - ffi_type ffi_type_pointer; - PyObject *proto; /* Only for Pointer/ArrayObject */ - SETFUNC setfunc; /* Only for simple objects */ - GETFUNC getfunc; /* Only for simple objects */ - PARAMFUNC paramfunc; - - /* Following fields only used by PyCFuncPtrType_Type instances */ - PyObject *argtypes; /* tuple of CDataObjects */ - PyObject *converters; /* tuple([t.from_param for t in argtypes]) */ - PyObject *restype; /* CDataObject or NULL */ - PyObject *checker; - int flags; /* calling convention and such */ - - /* pep3118 fields, pointers neeed PyMem_Free */ - char *format; - int ndim; - Py_ssize_t *shape; -/* Py_ssize_t *strides; */ /* unused in ctypes */ -/* Py_ssize_t *suboffsets; */ /* unused in ctypes */ - -} StgDictObject; - -/**************************************************************** - StgDictObject fields - - setfunc and getfunc is only set for simple data types, it is copied from the - corresponding fielddesc entry. These are functions to set and get the value - in a memory block. - They should probably by used by other types as well. - - proto is only used for Pointer and Array types - it points to the item type - object. - - Probably all the magic ctypes methods (like from_param) should have C - callable wrappers in the StgDictObject. For simple data type, for example, - the fielddesc table could have entries for C codec from_param functions or - other methods as well, if a subtype overrides this method in Python at - construction time, or assigns to it later, tp_setattro should update the - StgDictObject function to a generic one. - - Currently, PyCFuncPtr types have 'converters' and 'checker' entries in their - type dict. They are only used to cache attributes from other entries, which - is wrong. - - One use case is the .value attribute that all simple types have. But some - complex structures, like VARIANT, represent a single value also, and should - have this attribute. - - Another use case is a _check_retval_ function, which is called when a ctypes - type is used as return type of a function to validate and compute the return - value. - - Common ctypes protocol: - - - setfunc: store a python value in a memory block - - getfunc: convert data from a memory block into a python value - - - checkfunc: validate and convert a return value from a function call - - toparamfunc: convert a python value into a function argument - -*****************************************************************/ - -/* May return NULL, but does not set an exception! */ -extern StgDictObject *PyType_stgdict(PyObject *obj); - -/* May return NULL, but does not set an exception! */ -extern StgDictObject *PyObject_stgdict(PyObject *self); - -extern int PyCStgDict_clone(StgDictObject *src, StgDictObject *dst); - -typedef int(* PPROC)(void); - -PyObject *_ctypes_callproc(PPROC pProc, - PyObject *arguments, -#ifdef MS_WIN32 - IUnknown *pIUnk, - GUID *iid, -#endif - int flags, - PyObject *argtypes, - PyObject *restype, - PyObject *checker); - - -#define FUNCFLAG_STDCALL 0x0 -#define FUNCFLAG_CDECL 0x1 -#define FUNCFLAG_HRESULT 0x2 -#define FUNCFLAG_PYTHONAPI 0x4 -#define FUNCFLAG_USE_ERRNO 0x8 -#define FUNCFLAG_USE_LASTERROR 0x10 - -#define TYPEFLAG_ISPOINTER 0x100 -#define TYPEFLAG_HASPOINTER 0x200 - -#define DICTFLAG_FINAL 0x1000 - -struct tagPyCArgObject { - PyObject_HEAD - ffi_type *pffi_type; - char tag; - union { - char c; - char b; - short h; - int i; - long l; - long long q; - long double D; - double d; - float f; - void *p; - } value; - PyObject *obj; - Py_ssize_t size; /* for the 'V' tag */ -}; - -extern PyTypeObject PyCArg_Type; -#define PyCArg_CheckExact(v) ((v)->ob_type == &PyCArg_Type) -extern PyCArgObject *PyCArgObject_new(void); - -extern PyObject * -PyCData_get(PyObject *type, GETFUNC getfunc, PyObject *src, - Py_ssize_t index, Py_ssize_t size, char *ptr); - -extern int -PyCData_set(PyObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value, - Py_ssize_t index, Py_ssize_t size, char *ptr); - -extern void _ctypes_extend_error(PyObject *exc_class, const char *fmt, ...); - -struct basespec { - CDataObject *base; - Py_ssize_t index; - char *adr; -}; - -extern char basespec_string[]; - -extern ffi_type *_ctypes_get_ffi_type(PyObject *obj); - -/* exception classes */ -extern PyObject *PyExc_ArgError; - -extern char *_ctypes_conversion_encoding; -extern char *_ctypes_conversion_errors; - -#if defined(HAVE_WCHAR_H) -# define CTYPES_UNICODE -#endif - - -extern void _ctypes_free_closure(void *); -extern void *_ctypes_alloc_closure(void); - -extern PyObject *PyCData_FromBaseObj(PyObject *type, PyObject *base, Py_ssize_t index, char *adr); -extern char *_ctypes_alloc_format_string(const char *prefix, const char *suffix); -extern char *_ctypes_alloc_format_string_with_shape(int ndim, - const Py_ssize_t *shape, - const char *prefix, const char *suffix); - -extern int _ctypes_simple_instance(PyObject *obj); - -extern PyObject *_ctypes_ptrtype_cache; -PyObject *_ctypes_get_errobj(int **pspace); - -#ifdef MS_WIN32 -extern PyObject *ComError; -#endif - -/* - Local Variables: - compile-command: "python setup.py -q build install --home ~" - End: -*/ diff --git a/third_party/python/Modules/_ctypes/ctypes_dlfcn.h b/third_party/python/Modules/_ctypes/ctypes_dlfcn.h deleted file mode 100644 index 4ebb820c5..000000000 --- a/third_party/python/Modules/_ctypes/ctypes_dlfcn.h +++ /dev/null @@ -1,28 +0,0 @@ -/* clang-format off */ -#ifndef _CTYPES_DLFCN_H_ -#define _CTYPES_DLFCN_H_ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifndef MS_WIN32 - -#include - -#ifndef CTYPES_DARWIN_DLFCN - -#define ctypes_dlsym dlsym -#define ctypes_dlerror dlerror -#define ctypes_dlopen dlopen -#define ctypes_dlclose dlclose -#define ctypes_dladdr dladdr - -#endif /* !CTYPES_DARWIN_DLFCN */ - -#endif /* !MS_WIN32 */ - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* _CTYPES_DLFCN_H_ */ diff --git a/third_party/python/Modules/_ctypes/libffi.diff b/third_party/python/Modules/_ctypes/libffi.diff deleted file mode 100644 index ffa7bafe0..000000000 --- a/third_party/python/Modules/_ctypes/libffi.diff +++ /dev/null @@ -1,209 +0,0 @@ -diff -urN libffi-3.1/configure libffi/configure ---- libffi-3.1/configure 2014-05-19 15:44:03.000000000 +0200 -+++ libffi/configure 2014-08-09 21:51:07.877871443 +0200 -@@ -17236,6 +17236,10 @@ - fi - ;; - -+ i*86-*-nto-qnx*) -+ TARGET=X86; TARGETDIR=x86 -+ ;; -+ - x86_64-*-darwin*) - TARGET=X86_DARWIN; TARGETDIR=x86 - ;; -@@ -17298,12 +17302,12 @@ - ;; - - mips-sgi-irix5.* | mips-sgi-irix6.* | mips*-*-rtems*) -- TARGET=MIPS; TARGETDIR=mips -+ TARGET=MIPS_IRIX; TARGETDIR=mips - ;; - mips*-*linux* | mips*-*-openbsd*) - # Support 128-bit long double for NewABI. - HAVE_LONG_DOUBLE='defined(__mips64)' -- TARGET=MIPS; TARGETDIR=mips -+ TARGET=MIPS_LINUX; TARGETDIR=mips - ;; - - nios2*-linux*) -@@ -17373,7 +17377,7 @@ - as_fn_error $? "\"libffi has not been ported to $host.\"" "$LINENO" 5 - fi - -- if test x$TARGET = xMIPS; then -+ if expr x$TARGET : 'xMIPS' > /dev/null; then - MIPS_TRUE= - MIPS_FALSE='#' - else -@@ -18814,6 +18818,12 @@ - ac_config_files="$ac_config_files include/Makefile include/ffi.h Makefile testsuite/Makefile man/Makefile libffi.pc" - - -+ac_config_links="$ac_config_links include/ffi_common.h:include/ffi_common.h" -+ -+ -+ac_config_files="$ac_config_files fficonfig.py" -+ -+ - cat >confcache <<\_ACEOF - # This file is a shell script that caches the results of configure - # tests run on this system so they can be shared between configure -@@ -20126,6 +20136,8 @@ - "testsuite/Makefile") CONFIG_FILES="$CONFIG_FILES testsuite/Makefile" ;; - "man/Makefile") CONFIG_FILES="$CONFIG_FILES man/Makefile" ;; - "libffi.pc") CONFIG_FILES="$CONFIG_FILES libffi.pc" ;; -+ "include/ffi_common.h") CONFIG_LINKS="$CONFIG_LINKS include/ffi_common.h:include/ffi_common.h" ;; -+ "fficonfig.py") CONFIG_FILES="$CONFIG_FILES fficonfig.py" ;; - - *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; - esac -diff -urN libffi-3.1/configure.ac libffi/configure.ac ---- libffi-3.1/configure.ac 2014-05-11 15:57:49.000000000 +0200 -+++ libffi/configure.ac 2014-08-09 21:51:07.877871443 +0200 -@@ -1,4 +1,7 @@ - dnl Process this with autoconf to create configure -+# -+# file from libffi - slightly patched for Python's ctypes -+# - - AC_PREREQ(2.68) - -@@ -144,6 +147,9 @@ - AM_LTLDFLAGS='-no-undefined -bindir "$(bindir)"'; - fi - ;; -+ i*86-*-nto-qnx*) -+ TARGET=X86; TARGETDIR=x86 -+ ;; - i?86-*-darwin*) - TARGET=X86_DARWIN; TARGETDIR=x86 - ;; -@@ -218,12 +224,12 @@ - ;; - - mips-sgi-irix5.* | mips-sgi-irix6.* | mips*-*-rtems*) -- TARGET=MIPS; TARGETDIR=mips -+ TARGET=MIPS_IRIX; TARGETDIR=mips - ;; - mips*-*linux* | mips*-*-openbsd*) - # Support 128-bit long double for NewABI. - HAVE_LONG_DOUBLE='defined(__mips64)' -- TARGET=MIPS; TARGETDIR=mips -+ TARGET=MIPS_LINUX; TARGETDIR=mips - ;; - - nios2*-linux*) -@@ -293,7 +299,7 @@ - AC_MSG_ERROR(["libffi has not been ported to $host."]) - fi - --AM_CONDITIONAL(MIPS, test x$TARGET = xMIPS) -+AM_CONDITIONAL(MIPS,[expr x$TARGET : 'xMIPS' > /dev/null]) - AM_CONDITIONAL(BFIN, test x$TARGET = xBFIN) - AM_CONDITIONAL(SPARC, test x$TARGET = xSPARC) - AM_CONDITIONAL(X86, test x$TARGET = xX86) -@@ -617,4 +623,8 @@ - - AC_CONFIG_FILES(include/Makefile include/ffi.h Makefile testsuite/Makefile man/Makefile libffi.pc) - -+AC_CONFIG_LINKS(include/ffi_common.h:include/ffi_common.h) -+ -+AC_CONFIG_FILES(fficonfig.py) -+ - AC_OUTPUT -diff -urN libffi-3.1/fficonfig.py.in libffi/fficonfig.py.in ---- libffi-3.1/fficonfig.py.in 1970-01-01 01:00:00.000000000 +0100 -+++ libffi/fficonfig.py.in 2014-08-09 21:43:25.229871827 +0200 -@@ -0,0 +1,35 @@ -+ffi_sources = """ -+src/prep_cif.c -+src/closures.c -+""".split() -+ -+ffi_platforms = { -+ 'MIPS_IRIX': ['src/mips/ffi.c', 'src/mips/o32.S', 'src/mips/n32.S'], -+ 'MIPS_LINUX': ['src/mips/ffi.c', 'src/mips/o32.S'], -+ 'X86': ['src/x86/ffi.c', 'src/x86/sysv.S', 'src/x86/win32.S'], -+ 'X86_FREEBSD': ['src/x86/ffi.c', 'src/x86/freebsd.S'], -+ 'X86_WIN32': ['src/x86/ffi.c', 'src/x86/win32.S'], -+ 'SPARC': ['src/sparc/ffi.c', 'src/sparc/v8.S', 'src/sparc/v9.S'], -+ 'ALPHA': ['src/alpha/ffi.c', 'src/alpha/osf.S'], -+ 'IA64': ['src/ia64/ffi.c', 'src/ia64/unix.S'], -+ 'M32R': ['src/m32r/sysv.S', 'src/m32r/ffi.c'], -+ 'M68K': ['src/m68k/ffi.c', 'src/m68k/sysv.S'], -+ 'POWERPC': ['src/powerpc/ffi.c', 'src/powerpc/ffi_sysv.c', 'src/powerpc/ffi_linux64.c', 'src/powerpc/sysv.S', 'src/powerpc/ppc_closure.S', 'src/powerpc/linux64.S', 'src/powerpc/linux64_closure.S'], -+ 'POWERPC_AIX': ['src/powerpc/ffi_darwin.c', 'src/powerpc/aix.S', 'src/powerpc/aix_closure.S'], -+ 'POWERPC_FREEBSD': ['src/powerpc/ffi.c', 'src/powerpc/sysv.S', 'src/powerpc/ppc_closure.S'], -+ 'AARCH64': ['src/aarch64/sysv.S', 'src/aarch64/ffi.c'], -+ 'ARM': ['src/arm/sysv.S', 'src/arm/ffi.c'], -+ 'LIBFFI_CRIS': ['src/cris/sysv.S', 'src/cris/ffi.c'], -+ 'FRV': ['src/frv/eabi.S', 'src/frv/ffi.c'], -+ 'S390': ['src/s390/sysv.S', 'src/s390/ffi.c'], -+ 'X86_64': ['src/x86/ffi64.c', 'src/x86/unix64.S', 'src/x86/ffi.c', 'src/x86/sysv.S'], -+ 'SH': ['src/sh/sysv.S', 'src/sh/ffi.c'], -+ 'SH64': ['src/sh64/sysv.S', 'src/sh64/ffi.c'], -+ 'PA': ['src/pa/linux.S', 'src/pa/ffi.c'], -+ 'PA_LINUX': ['src/pa/linux.S', 'src/pa/ffi.c'], -+ 'PA_HPUX': ['src/pa/hpux32.S', 'src/pa/ffi.c'], -+} -+ -+ffi_sources += ffi_platforms['@TARGET@'] -+ -+ffi_cflags = '@CFLAGS@' -diff -urN libffi-3.1/src/dlmalloc.c libffi/src/dlmalloc.c ---- libffi-3.1/src/dlmalloc.c 2014-04-25 19:45:13.000000000 +0200 -+++ libffi/src/dlmalloc.c 2014-08-09 21:51:07.881871443 +0200 -@@ -457,6 +457,11 @@ - #define LACKS_ERRNO_H - #define MALLOC_FAILURE_ACTION - #define MMAP_CLEARS 0 /* WINCE and some others apparently don't clear */ -+#elif !defined _GNU_SOURCE -+/* mremap() on Linux requires this via sys/mman.h -+ * See roundup issue 10309 -+ */ -+#define _GNU_SOURCE 1 - #endif /* WIN32 */ - - #ifdef __OS2__ -@@ -4497,7 +4502,7 @@ - char* tbase = (char*)(CALL_MMAP(tsize)); - if (tbase != CMFAIL) { - m = init_user_mstate(tbase, tsize); -- set_segment_flags(&m->seg, IS_MMAPPED_BIT); -+ (void)set_segment_flags(&m->seg, IS_MMAPPED_BIT); - set_lock(m, locked); - } - } -@@ -4512,7 +4517,7 @@ - if (capacity > msize + TOP_FOOT_SIZE && - capacity < (size_t) -(msize + TOP_FOOT_SIZE + mparams.page_size)) { - m = init_user_mstate((char*)base, capacity); -- set_segment_flags(&m->seg, EXTERN_BIT); -+ (void)set_segment_flags(&m->seg, EXTERN_BIT); - set_lock(m, locked); - } - return (mspace)m; -diff -urN libffi-3.1/src/arm/ffi.c libffi/src/arm/ffi.c ---- libffi-3.1/src/arm/ffi.c Sat Aug 09 23:52:34 2014 +0200 -+++ libffi/src/arm/ffi.c Sat Aug 09 23:58:38 2014 +0200 -@@ -154,9 +154,6 @@ - - int ffi_prep_args_VFP(char *stack, extended_cif *ecif, float *vfp_space) - { -- // make sure we are using FFI_VFP -- FFI_ASSERT(ecif->cif->abi == FFI_VFP); -- - register unsigned int i, vi = 0; - register void **p_argv; - register char *argp, *regp, *eo_regp; -@@ -165,6 +162,9 @@ - char done_with_regs = 0; - char is_vfp_type; - -+ // make sure we are using FFI_VFP -+ FFI_ASSERT(ecif->cif->abi == FFI_VFP); -+ - /* the first 4 words on the stack are used for values passed in core - * registers. */ - regp = stack; diff --git a/third_party/python/Modules/_ctypes/malloc_closure.c b/third_party/python/Modules/_ctypes/malloc_closure.c deleted file mode 100644 index bb75e2024..000000000 --- a/third_party/python/Modules/_ctypes/malloc_closure.c +++ /dev/null @@ -1,112 +0,0 @@ -/* clang-format off */ -#include -#include -#ifdef MS_WIN32 -#include -#else -#include -#include -# if !defined(MAP_ANONYMOUS) && defined(MAP_ANON) -# define MAP_ANONYMOUS MAP_ANON -# endif -#endif -#include "ctypes.h" - -/* BLOCKSIZE can be adjusted. Larger blocksize will take a larger memory - overhead, but allocate less blocks from the system. It may be that some - systems have a limit of how many mmap'd blocks can be open. -*/ - -#define BLOCKSIZE _pagesize - -/* #define MALLOC_CLOSURE_DEBUG */ /* enable for some debugging output */ - -/******************************************************************/ - -typedef union _tagITEM { - ffi_closure closure; - union _tagITEM *next; -} ITEM; - -static ITEM *free_list; -static int _pagesize; - -static void more_core(void) -{ - ITEM *item; - int count, i; - -/* determine the pagesize */ -#ifdef MS_WIN32 - if (!_pagesize) { - SYSTEM_INFO systeminfo; - GetSystemInfo(&systeminfo); - _pagesize = systeminfo.dwPageSize; - } -#else - if (!_pagesize) { -#ifdef _SC_PAGESIZE - _pagesize = sysconf(_SC_PAGESIZE); -#else - _pagesize = getpagesize(); -#endif - } -#endif - - /* calculate the number of nodes to allocate */ - count = BLOCKSIZE / sizeof(ITEM); - - /* allocate a memory block */ -#ifdef MS_WIN32 - item = (ITEM *)VirtualAlloc(NULL, - count * sizeof(ITEM), - MEM_COMMIT, - PAGE_EXECUTE_READWRITE); - if (item == NULL) - return; -#else - item = (ITEM *)mmap(NULL, - count * sizeof(ITEM), - PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_PRIVATE | MAP_ANONYMOUS, - -1, - 0); - if (item == (void *)MAP_FAILED) - return; -#endif - -#ifdef MALLOC_CLOSURE_DEBUG - printf("block at %p allocated (%d bytes), %d ITEMs\n", - item, count * sizeof(ITEM), count); -#endif - /* put them into the free list */ - for (i = 0; i < count; ++i) { - item->next = free_list; - free_list = item; - ++item; - } -} - -/******************************************************************/ - -/* put the item back into the free list */ -void ffi_closure_free(void *p) -{ - ITEM *item = (ITEM *)p; - item->next = free_list; - free_list = item; -} - -/* return one item from the free list, allocating more if needed */ -void *ffi_closure_alloc(size_t ignored, void** codeloc) -{ - ITEM *item; - if (!free_list) - more_core(); - if (!free_list) - return NULL; - item = free_list; - free_list = item->next; - *codeloc = (void *)item; - return (void *)item; -} diff --git a/third_party/python/Modules/_ctypes/stgdict.c b/third_party/python/Modules/_ctypes/stgdict.c deleted file mode 100644 index 6f64606a7..000000000 --- a/third_party/python/Modules/_ctypes/stgdict.c +++ /dev/null @@ -1,602 +0,0 @@ -/* clang-format off */ -#include "Python.h" -#include -#ifdef MS_WIN32 -#include -#include -#endif -#include "ctypes.h" - -/******************************************************************/ -/* - StdDict - a dictionary subclass, containing additional C accessible fields - - XXX blabla more -*/ - -/* Seems we need this, otherwise we get problems when calling - * PyDict_SetItem() (ma_lookup is NULL) - */ -static int -PyCStgDict_init(StgDictObject *self, PyObject *args, PyObject *kwds) -{ - if (PyDict_Type.tp_init((PyObject *)self, args, kwds) < 0) - return -1; - self->format = NULL; - self->ndim = 0; - self->shape = NULL; - return 0; -} - -static int -PyCStgDict_clear(StgDictObject *self) -{ - Py_CLEAR(self->proto); - Py_CLEAR(self->argtypes); - Py_CLEAR(self->converters); - Py_CLEAR(self->restype); - Py_CLEAR(self->checker); - return 0; -} - -static void -PyCStgDict_dealloc(StgDictObject *self) -{ - PyCStgDict_clear(self); - PyMem_Free(self->format); - PyMem_Free(self->shape); - PyMem_Free(self->ffi_type_pointer.elements); - PyDict_Type.tp_dealloc((PyObject *)self); -} - -int -PyCStgDict_clone(StgDictObject *dst, StgDictObject *src) -{ - char *d, *s; - Py_ssize_t size; - - PyCStgDict_clear(dst); - PyMem_Free(dst->ffi_type_pointer.elements); - PyMem_Free(dst->format); - dst->format = NULL; - PyMem_Free(dst->shape); - dst->shape = NULL; - dst->ffi_type_pointer.elements = NULL; - - d = (char *)dst; - s = (char *)src; - memcpy(d + sizeof(PyDictObject), - s + sizeof(PyDictObject), - sizeof(StgDictObject) - sizeof(PyDictObject)); - - Py_XINCREF(dst->proto); - Py_XINCREF(dst->argtypes); - Py_XINCREF(dst->converters); - Py_XINCREF(dst->restype); - Py_XINCREF(dst->checker); - - if (src->format) { - dst->format = PyMem_Malloc(strlen(src->format) + 1); - if (dst->format == NULL) { - PyErr_NoMemory(); - return -1; - } - strcpy(dst->format, src->format); - } - if (src->shape) { - dst->shape = PyMem_Malloc(sizeof(Py_ssize_t) * src->ndim); - if (dst->shape == NULL) { - PyErr_NoMemory(); - return -1; - } - memcpy(dst->shape, src->shape, - sizeof(Py_ssize_t) * src->ndim); - } - - if (src->ffi_type_pointer.elements == NULL) - return 0; - size = sizeof(ffi_type *) * (src->length + 1); - dst->ffi_type_pointer.elements = PyMem_Malloc(size); - if (dst->ffi_type_pointer.elements == NULL) { - PyErr_NoMemory(); - return -1; - } - memcpy(dst->ffi_type_pointer.elements, - src->ffi_type_pointer.elements, - size); - return 0; -} - -PyTypeObject PyCStgDict_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "StgDict", - sizeof(StgDictObject), - 0, - (destructor)PyCStgDict_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - 0, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)PyCStgDict_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0, /* tp_free */ -}; - -/* May return NULL, but does not set an exception! */ -StgDictObject * -PyType_stgdict(PyObject *obj) -{ - PyTypeObject *type; - - if (!PyType_Check(obj)) - return NULL; - type = (PyTypeObject *)obj; - if (!type->tp_dict || !PyCStgDict_CheckExact(type->tp_dict)) - return NULL; - return (StgDictObject *)type->tp_dict; -} - -/* May return NULL, but does not set an exception! */ -/* - This function should be as fast as possible, so we don't call PyType_stgdict - above but inline the code, and avoid the PyType_Check(). -*/ -StgDictObject * -PyObject_stgdict(PyObject *self) -{ - PyTypeObject *type = self->ob_type; - if (!type->tp_dict || !PyCStgDict_CheckExact(type->tp_dict)) - return NULL; - return (StgDictObject *)type->tp_dict; -} - -/* descr is the descriptor for a field marked as anonymous. Get all the - _fields_ descriptors from descr->proto, create new descriptors with offset - and index adjusted, and stuff them into type. - */ -static int -MakeFields(PyObject *type, CFieldObject *descr, - Py_ssize_t index, Py_ssize_t offset) -{ - Py_ssize_t i; - PyObject *fields; - PyObject *fieldlist; - - fields = PyObject_GetAttrString(descr->proto, "_fields_"); - if (fields == NULL) - return -1; - fieldlist = PySequence_Fast(fields, "_fields_ must be a sequence"); - Py_DECREF(fields); - if (fieldlist == NULL) - return -1; - - for (i = 0; i < PySequence_Fast_GET_SIZE(fieldlist); ++i) { - PyObject *pair = PySequence_Fast_GET_ITEM(fieldlist, i); /* borrowed */ - PyObject *fname, *ftype, *bits; - CFieldObject *fdescr; - CFieldObject *new_descr; - /* Convert to PyArg_UnpackTuple... */ - if (!PyArg_ParseTuple(pair, "OO|O", &fname, &ftype, &bits)) { - Py_DECREF(fieldlist); - return -1; - } - fdescr = (CFieldObject *)PyObject_GetAttr(descr->proto, fname); - if (fdescr == NULL) { - Py_DECREF(fieldlist); - return -1; - } - if (Py_TYPE(fdescr) != &PyCField_Type) { - PyErr_SetString(PyExc_TypeError, "unexpected type"); - Py_DECREF(fdescr); - Py_DECREF(fieldlist); - return -1; - } - if (fdescr->anonymous) { - int rc = MakeFields(type, fdescr, - index + fdescr->index, - offset + fdescr->offset); - Py_DECREF(fdescr); - if (rc == -1) { - Py_DECREF(fieldlist); - return -1; - } - continue; - } - new_descr = (CFieldObject *)PyObject_CallObject((PyObject *)&PyCField_Type, NULL); - if (new_descr == NULL) { - Py_DECREF(fdescr); - Py_DECREF(fieldlist); - return -1; - } - assert(Py_TYPE(new_descr) == &PyCField_Type); - new_descr->size = fdescr->size; - new_descr->offset = fdescr->offset + offset; - new_descr->index = fdescr->index + index; - new_descr->proto = fdescr->proto; - Py_XINCREF(new_descr->proto); - new_descr->getfunc = fdescr->getfunc; - new_descr->setfunc = fdescr->setfunc; - - Py_DECREF(fdescr); - - if (-1 == PyObject_SetAttr(type, fname, (PyObject *)new_descr)) { - Py_DECREF(fieldlist); - Py_DECREF(new_descr); - return -1; - } - Py_DECREF(new_descr); - } - Py_DECREF(fieldlist); - return 0; -} - -/* Iterate over the names in the type's _anonymous_ attribute, if present, - */ -static int -MakeAnonFields(PyObject *type) -{ - PyObject *anon; - PyObject *anon_names; - Py_ssize_t i; - - anon = PyObject_GetAttrString(type, "_anonymous_"); - if (anon == NULL) { - PyErr_Clear(); - return 0; - } - anon_names = PySequence_Fast(anon, "_anonymous_ must be a sequence"); - Py_DECREF(anon); - if (anon_names == NULL) - return -1; - - for (i = 0; i < PySequence_Fast_GET_SIZE(anon_names); ++i) { - PyObject *fname = PySequence_Fast_GET_ITEM(anon_names, i); /* borrowed */ - CFieldObject *descr = (CFieldObject *)PyObject_GetAttr(type, fname); - if (descr == NULL) { - Py_DECREF(anon_names); - return -1; - } - if (Py_TYPE(descr) != &PyCField_Type) { - PyErr_Format(PyExc_AttributeError, - "'%U' is specified in _anonymous_ but not in " - "_fields_", - fname); - Py_DECREF(anon_names); - Py_DECREF(descr); - return -1; - } - descr->anonymous = 1; - - /* descr is in the field descriptor. */ - if (-1 == MakeFields(type, (CFieldObject *)descr, - ((CFieldObject *)descr)->index, - ((CFieldObject *)descr)->offset)) { - Py_DECREF(descr); - Py_DECREF(anon_names); - return -1; - } - Py_DECREF(descr); - } - - Py_DECREF(anon_names); - return 0; -} - -/* - Retrive the (optional) _pack_ attribute from a type, the _fields_ attribute, - and create an StgDictObject. Used for Structure and Union subclasses. -*/ -int -PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct) -{ - StgDictObject *stgdict, *basedict; - Py_ssize_t len, offset, size, align, i; - Py_ssize_t union_size, total_align; - Py_ssize_t field_size = 0; - int bitofs; - PyObject *isPacked; - int pack = 0; - Py_ssize_t ffi_ofs; - int big_endian; - - /* HACK Alert: I cannot be bothered to fix ctypes.com, so there has to - be a way to use the old, broken sematics: _fields_ are not extended - but replaced in subclasses. - - XXX Remove this in ctypes 1.0! - */ - int use_broken_old_ctypes_semantics; - - if (fields == NULL) - return 0; - -#ifdef WORDS_BIGENDIAN - big_endian = PyObject_HasAttrString(type, "_swappedbytes_") ? 0 : 1; -#else - big_endian = PyObject_HasAttrString(type, "_swappedbytes_") ? 1 : 0; -#endif - - use_broken_old_ctypes_semantics = \ - PyObject_HasAttrString(type, "_use_broken_old_ctypes_structure_semantics_"); - - isPacked = PyObject_GetAttrString(type, "_pack_"); - if (isPacked) { - pack = _PyLong_AsInt(isPacked); - if (pack < 0 || PyErr_Occurred()) { - Py_XDECREF(isPacked); - PyErr_SetString(PyExc_ValueError, - "_pack_ must be a non-negative integer"); - return -1; - } - Py_DECREF(isPacked); - } else - PyErr_Clear(); - - len = PySequence_Length(fields); - if (len == -1) { - PyErr_SetString(PyExc_TypeError, - "'_fields_' must be a sequence of pairs"); - return -1; - } - - stgdict = PyType_stgdict(type); - if (!stgdict) - return -1; - /* If this structure/union is already marked final we cannot assign - _fields_ anymore. */ - - if (stgdict->flags & DICTFLAG_FINAL) {/* is final ? */ - PyErr_SetString(PyExc_AttributeError, - "_fields_ is final"); - return -1; - } - - if (stgdict->format) { - PyMem_Free(stgdict->format); - stgdict->format = NULL; - } - - if (stgdict->ffi_type_pointer.elements) - PyMem_Free(stgdict->ffi_type_pointer.elements); - - basedict = PyType_stgdict((PyObject *)((PyTypeObject *)type)->tp_base); - if (basedict && !use_broken_old_ctypes_semantics) { - size = offset = basedict->size; - align = basedict->align; - union_size = 0; - total_align = align ? align : 1; - stgdict->ffi_type_pointer.type = FFI_TYPE_STRUCT; - stgdict->ffi_type_pointer.elements = PyMem_New(ffi_type *, basedict->length + len + 1); - if (stgdict->ffi_type_pointer.elements == NULL) { - PyErr_NoMemory(); - return -1; - } - memset(stgdict->ffi_type_pointer.elements, 0, - sizeof(ffi_type *) * (basedict->length + len + 1)); - if (basedict->length > 0) { - memcpy(stgdict->ffi_type_pointer.elements, - basedict->ffi_type_pointer.elements, - sizeof(ffi_type *) * (basedict->length)); - } - ffi_ofs = basedict->length; - } else { - offset = 0; - size = 0; - align = 0; - union_size = 0; - total_align = 1; - stgdict->ffi_type_pointer.type = FFI_TYPE_STRUCT; - stgdict->ffi_type_pointer.elements = PyMem_New(ffi_type *, len + 1); - if (stgdict->ffi_type_pointer.elements == NULL) { - PyErr_NoMemory(); - return -1; - } - memset(stgdict->ffi_type_pointer.elements, 0, - sizeof(ffi_type *) * (len + 1)); - ffi_ofs = 0; - } - - assert(stgdict->format == NULL); - if (isStruct && !isPacked) { - stgdict->format = _ctypes_alloc_format_string(NULL, "T{"); - } else { - /* PEP3118 doesn't support union, or packed structures (well, - only standard packing, but we dont support the pep for - that). Use 'B' for bytes. */ - stgdict->format = _ctypes_alloc_format_string(NULL, "B"); - } - if (stgdict->format == NULL) - return -1; - -#define realdict ((PyObject *)&stgdict->dict) - for (i = 0; i < len; ++i) { - PyObject *name = NULL, *desc = NULL; - PyObject *pair = PySequence_GetItem(fields, i); - PyObject *prop; - StgDictObject *dict; - int bitsize = 0; - - if (!pair || !PyArg_ParseTuple(pair, "UO|i", &name, &desc, &bitsize)) { - PyErr_SetString(PyExc_TypeError, - "'_fields_' must be a sequence of (name, C type) pairs"); - Py_XDECREF(pair); - return -1; - } - dict = PyType_stgdict(desc); - if (dict == NULL) { - Py_DECREF(pair); - PyErr_Format(PyExc_TypeError, - "second item in _fields_ tuple (index %zd) must be a C type", - i); - return -1; - } - stgdict->ffi_type_pointer.elements[ffi_ofs + i] = &dict->ffi_type_pointer; - if (dict->flags & (TYPEFLAG_ISPOINTER | TYPEFLAG_HASPOINTER)) - stgdict->flags |= TYPEFLAG_HASPOINTER; - dict->flags |= DICTFLAG_FINAL; /* mark field type final */ - if (PyTuple_Size(pair) == 3) { /* bits specified */ - switch(dict->ffi_type_pointer.type) { - case FFI_TYPE_UINT8: - case FFI_TYPE_UINT16: - case FFI_TYPE_UINT32: - case FFI_TYPE_SINT64: - case FFI_TYPE_UINT64: - break; - - case FFI_TYPE_SINT8: - case FFI_TYPE_SINT16: - case FFI_TYPE_SINT32: - if (dict->getfunc != _ctypes_get_fielddesc("c")->getfunc -#ifdef CTYPES_UNICODE - && dict->getfunc != _ctypes_get_fielddesc("u")->getfunc -#endif - ) - break; - /* else fall through */ - default: - PyErr_Format(PyExc_TypeError, - "bit fields not allowed for type %s", - ((PyTypeObject *)desc)->tp_name); - Py_DECREF(pair); - return -1; - } - if (bitsize <= 0 || bitsize > dict->size * 8) { - PyErr_SetString(PyExc_ValueError, - "number of bits invalid for bit field"); - Py_DECREF(pair); - return -1; - } - } else - bitsize = 0; - - if (isStruct && !isPacked) { - char *fieldfmt = dict->format ? dict->format : "B"; - char *fieldname = PyUnicode_AsUTF8(name); - char *ptr; - Py_ssize_t len; - char *buf; - - if (fieldname == NULL) - { - Py_DECREF(pair); - return -1; - } - - len = strlen(fieldname) + strlen(fieldfmt); - - buf = PyMem_Malloc(len + 2 + 1); - if (buf == NULL) { - Py_DECREF(pair); - PyErr_NoMemory(); - return -1; - } - sprintf(buf, "%s:%s:", fieldfmt, fieldname); - - ptr = stgdict->format; - if (dict->shape != NULL) { - stgdict->format = _ctypes_alloc_format_string_with_shape( - dict->ndim, dict->shape, stgdict->format, buf); - } else { - stgdict->format = _ctypes_alloc_format_string(stgdict->format, buf); - } - PyMem_Free(ptr); - PyMem_Free(buf); - - if (stgdict->format == NULL) { - Py_DECREF(pair); - return -1; - } - } - - if (isStruct) { - prop = PyCField_FromDesc(desc, i, - &field_size, bitsize, &bitofs, - &size, &offset, &align, - pack, big_endian); - } else /* union */ { - size = 0; - offset = 0; - align = 0; - prop = PyCField_FromDesc(desc, i, - &field_size, bitsize, &bitofs, - &size, &offset, &align, - pack, big_endian); - union_size = max(size, union_size); - } - total_align = max(align, total_align); - - if (!prop) { - Py_DECREF(pair); - return -1; - } - if (-1 == PyObject_SetAttr(type, name, prop)) { - Py_DECREF(prop); - Py_DECREF(pair); - return -1; - } - Py_DECREF(pair); - Py_DECREF(prop); - } -#undef realdict - - if (isStruct && !isPacked) { - char *ptr = stgdict->format; - stgdict->format = _ctypes_alloc_format_string(stgdict->format, "}"); - PyMem_Free(ptr); - if (stgdict->format == NULL) - return -1; - } - - if (!isStruct) - size = union_size; - - /* Adjust the size according to the alignment requirements */ - size = ((size + total_align - 1) / total_align) * total_align; - - stgdict->ffi_type_pointer.alignment = Py_SAFE_DOWNCAST(total_align, - Py_ssize_t, - unsigned short); - stgdict->ffi_type_pointer.size = size; - - stgdict->size = size; - stgdict->align = total_align; - stgdict->length = len; /* ADD ffi_ofs? */ - - /* We did check that this flag was NOT set above, it must not - have been set until now. */ - if (stgdict->flags & DICTFLAG_FINAL) { - PyErr_SetString(PyExc_AttributeError, - "Structure or union cannot contain itself"); - return -1; - } - stgdict->flags |= DICTFLAG_FINAL; - - return MakeAnonFields(type); -} diff --git a/third_party/python/Modules/_curses_panel.c b/third_party/python/Modules/_curses_panel.c index 7ccbf80f6..6b8ef4fd4 100644 --- a/third_party/python/Modules/_curses_panel.c +++ b/third_party/python/Modules/_curses_panel.c @@ -11,11 +11,9 @@ static const char PyCursesVersion[] = "2.1"; /* Includes */ -#include "Python.h" +#include "third_party/python/Include/Python.h" -#include "py_curses.h" - -#include +#include "third_party/python/Include/py_curses.h" typedef struct { PyObject *PyCursesError; diff --git a/third_party/python/Modules/_cursesmodule.c b/third_party/python/Modules/_cursesmodule.c index c0485b7a0..e868beceb 100644 --- a/third_party/python/Modules/_cursesmodule.c +++ b/third_party/python/Modules/_cursesmodule.c @@ -103,7 +103,7 @@ char *PyCursesVersion = "2.2"; #define PY_SSIZE_T_CLEAN -#include "Python.h" +#include "third_party/python/Include/Python.h" #ifdef __hpux @@ -111,7 +111,7 @@ char *PyCursesVersion = "2.2"; #endif #define CURSES_MODULE -#include "py_curses.h" +#include "third_party/python/Include/py_curses.h" #if defined(HAVE_TERM_H) || defined(__sgi) /* For termname, longname, putp, tigetflag, tigetnum, tigetstr, tparm @@ -122,10 +122,6 @@ char *PyCursesVersion = "2.2"; #undef columns #endif -#ifdef HAVE_LANGINFO_H -#include -#endif - #if !defined(HAVE_NCURSES_H) && (defined(sgi) || defined(__sun) || defined(SCO5)) #define STRICT_SYSV_CURSES /* Don't use ncurses extensions */ typedef chtype attr_t; /* No attr_t type is available */ diff --git a/third_party/python/Modules/_datetimemodule.c b/third_party/python/Modules/_datetimemodule.c index e1949d0a7..c3bd82242 100644 --- a/third_party/python/Modules/_datetimemodule.c +++ b/third_party/python/Modules/_datetimemodule.c @@ -1,12 +1,30 @@ +#include "libc/assert.h" +#include "libc/calls/weirdtypes.h" +#include "libc/fmt/fmt.h" +#include "libc/math.h" +#include "libc/time/struct/tm.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pycapsule.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pyhash.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pytime.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/tupleobject.h" /* clang-format off */ + /* C implementation for the date/time type documented at * http://www.zope.org/Members/fdrake/DateTimeWiki/FrontPage */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" -#include "libc/time/struct/tm.h" - /* Differentiate between building the core module and building extension * modules. */ diff --git a/third_party/python/Modules/_dbmmodule.c b/third_party/python/Modules/_dbmmodule.c index 079cab26c..6d971d97e 100644 --- a/third_party/python/Modules/_dbmmodule.c +++ b/third_party/python/Modules/_dbmmodule.c @@ -1,15 +1,8 @@ +#define PY_SSIZE_T_CLEAN /* clang-format off */ /* DBM module using dictionary interface */ - -#define PY_SSIZE_T_CLEAN -#include "Python.h" - -#include -#include -#include - /* Some Linux systems install gdbm/ndbm.h, but not ndbm.h. This supports * whichever configure was able to locate. */ diff --git a/third_party/python/Modules/_decimal/_decimal.c b/third_party/python/Modules/_decimal/_decimal.c index ddb07868a..0273e1a89 100644 --- a/third_party/python/Modules/_decimal/_decimal.c +++ b/third_party/python/Modules/_decimal/_decimal.c @@ -1,47 +1,61 @@ -/* clang-format off */ -/* - * Copyright (c) 2008-2012 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright (c) 2008-2016 Stefan Krah. All rights reserved. │ +│ │ +│ Redistribution and use in source and binary forms, with or without │ +│ modification, are permitted provided that the following conditions │ +│ are met: │ +│ │ +│ 1. Redistributions of source code must retain the above copyright │ +│ notice, this list of conditions and the following disclaimer. │ +│ │ +│ 2. Redistributions in binary form must reproduce the above copyright │ +│ notice, this list of conditions and the following disclaimer in │ +│ the documentation and/or other materials provided with the │ +│ distribution. │ +│ │ +│ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND │ +│ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE │ +│ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR │ +│ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS │ +│ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, │ +│ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT │ +│ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR │ +│ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, │ +│ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE │ +│ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, │ +│ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ -#include "docstrings.h" +#include "libc/fmt/fmt.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/complexobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/listobject.h" #include "third_party/python/Include/longintrepr.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pyhash.h" +#include "third_party/python/Include/pystate.h" +#include "third_party/python/Include/pythread.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/tupleobject.h" +#include "third_party/python/Modules/_decimal/docstrings.h" #include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" -#include "third_party/python/Include/pythread.h" -#include "third_party/python/Include/structmember.h" -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/complexobject.h" +/* clang-format off */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/longintrepr.h" -#include "third_party/python/Include/pythread.h" -#include "third_party/python/Include/structmember.h" -#include "third_party/python/Include/complexobject.h" - -#include "docstrings.h" +asm(".ident\t\"\\n\\n\ +libmpdec (BSD-2)\\n\ +Copyright 2008-2016 Stefan Krah\""); +asm(".include \"libc/disclaimer.inc\""); +#define CONFIG_64 #if !defined(MPD_VERSION_HEX) || MPD_VERSION_HEX < 0x02040100 #error "libmpdec version >= 2.4.1 required" diff --git a/third_party/python/Modules/_decimal/libmpdec/basearith.c b/third_party/python/Modules/_decimal/libmpdec/basearith.c index f5a66a582..43d3e7fb2 100644 --- a/third_party/python/Modules/_decimal/libmpdec/basearith.c +++ b/third_party/python/Modules/_decimal/libmpdec/basearith.c @@ -1,37 +1,42 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright (c) 2008-2016 Stefan Krah. All rights reserved. │ +│ │ +│ Redistribution and use in source and binary forms, with or without │ +│ modification, are permitted provided that the following conditions │ +│ are met: │ +│ │ +│ 1. Redistributions of source code must retain the above copyright │ +│ notice, this list of conditions and the following disclaimer. │ +│ │ +│ 2. Redistributions in binary form must reproduce the above copyright │ +│ notice, this list of conditions and the following disclaimer in │ +│ the documentation and/or other materials provided with the │ +│ distribution. │ +│ │ +│ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND │ +│ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE │ +│ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR │ +│ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS │ +│ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, │ +│ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT │ +│ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR │ +│ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, │ +│ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE │ +│ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, │ +│ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/python/Modules/_decimal/libmpdec/basearith.h" +#include "third_party/python/Modules/_decimal/libmpdec/constants.h" +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +#include "third_party/python/Modules/_decimal/libmpdec/typearith.h" /* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - -#include "mpdecimal.h" -#include "constants.h" -#include "typearith.h" -#include "basearith.h" +asm(".ident\t\"\\n\\n\ +libmpdec (BSD-2)\\n\ +Copyright 2008-2016 Stefan Krah\""); +asm(".include \"libc/disclaimer.inc\""); /*********************************************************************/ /* Calculations in base MPD_RADIX */ diff --git a/third_party/python/Modules/_decimal/libmpdec/basearith.h b/third_party/python/Modules/_decimal/libmpdec/basearith.h index 1e718b54c..94c768dd8 100644 --- a/third_party/python/Modules/_decimal/libmpdec/basearith.h +++ b/third_party/python/Modules/_decimal/libmpdec/basearith.h @@ -1,44 +1,12 @@ -/* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - #ifndef BASEARITH_H #define BASEARITH_H - - -#include "mpdecimal.h" -#include "typearith.h" - +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +#include "third_party/python/Modules/_decimal/libmpdec/typearith.h" +/* clang-format off */ /* Internal header file: all symbols have local scope in the DSO */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) - mpd_uint_t _mpd_baseadd(mpd_uint_t *w, const mpd_uint_t *u, const mpd_uint_t *v, mpd_size_t m, mpd_size_t n); void _mpd_baseaddto(mpd_uint_t *w, const mpd_uint_t *u, mpd_size_t n); @@ -68,8 +36,6 @@ void _mpd_baseshiftl(mpd_uint_t *dest, mpd_uint_t *src, mpd_size_t n, mpd_uint_t _mpd_baseshiftr(mpd_uint_t *dest, mpd_uint_t *src, mpd_size_t slen, mpd_size_t shift); - - #ifdef CONFIG_64 extern const mpd_uint_t mprime_rdx; @@ -212,11 +178,6 @@ _mpd_isallnine(const mpd_uint_t *data, mpd_ssize_t len) return 1; } - MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ - #endif /* BASEARITH_H */ - - - diff --git a/third_party/python/Modules/_decimal/libmpdec/bits.h b/third_party/python/Modules/_decimal/libmpdec/bits.h index da48fbef9..d8e2d6bdc 100644 --- a/third_party/python/Modules/_decimal/libmpdec/bits.h +++ b/third_party/python/Modules/_decimal/libmpdec/bits.h @@ -1,38 +1,7 @@ -/* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - #ifndef BITS_H #define BITS_H - - -#include "mpdecimal.h" - +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +/* clang-format off */ /* Check if n is a power of 2. */ static inline int @@ -42,6 +11,7 @@ ispower2(mpd_size_t n) } #if defined(ANSI) +#error oh no /* * Return the most significant bit position of n from 0 to 31 (63). * Assumptions: n != 0. @@ -129,7 +99,6 @@ static inline int mpd_bsf(mpd_size_t a) { mpd_size_t retval; - __asm__ ( #ifdef CONFIG_64 "bsfq %1, %0\n\t" @@ -140,7 +109,6 @@ mpd_bsf(mpd_size_t a) :"r" (a) :"cc" ); - return (int)retval; } /* END ASM */ diff --git a/third_party/python/Modules/_decimal/libmpdec/constants.c b/third_party/python/Modules/_decimal/libmpdec/constants.c index d831d3bd4..52a7f79b4 100644 --- a/third_party/python/Modules/_decimal/libmpdec/constants.c +++ b/third_party/python/Modules/_decimal/libmpdec/constants.c @@ -1,35 +1,40 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright (c) 2008-2016 Stefan Krah. All rights reserved. │ +│ │ +│ Redistribution and use in source and binary forms, with or without │ +│ modification, are permitted provided that the following conditions │ +│ are met: │ +│ │ +│ 1. Redistributions of source code must retain the above copyright │ +│ notice, this list of conditions and the following disclaimer. │ +│ │ +│ 2. Redistributions in binary form must reproduce the above copyright │ +│ notice, this list of conditions and the following disclaimer in │ +│ the documentation and/or other materials provided with the │ +│ distribution. │ +│ │ +│ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND │ +│ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE │ +│ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR │ +│ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS │ +│ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, │ +│ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT │ +│ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR │ +│ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, │ +│ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE │ +│ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, │ +│ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/python/Modules/_decimal/libmpdec/constants.h" +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" /* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - -#include "mpdecimal.h" -#include "constants.h" +asm(".ident\t\"\\n\\n\ +libmpdec (BSD-2)\\n\ +Copyright 2008-2016 Stefan Krah\""); +asm(".include \"libc/disclaimer.inc\""); #if defined(CONFIG_64) diff --git a/third_party/python/Modules/_decimal/libmpdec/constants.h b/third_party/python/Modules/_decimal/libmpdec/constants.h index f558530ad..27e912f02 100644 --- a/third_party/python/Modules/_decimal/libmpdec/constants.h +++ b/third_party/python/Modules/_decimal/libmpdec/constants.h @@ -1,43 +1,11 @@ -/* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - #ifndef CONSTANTS_H #define CONSTANTS_H - - -#include "mpdecimal.h" - +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +/* clang-format off */ /* Internal header file: all symbols have local scope in the DSO */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) - /* choice of optimized functions */ #if defined(CONFIG_64) /* x64 */ diff --git a/third_party/python/Modules/_decimal/libmpdec/context.c b/third_party/python/Modules/_decimal/libmpdec/context.c index 18042db1e..edf09c9df 100644 --- a/third_party/python/Modules/_decimal/libmpdec/context.c +++ b/third_party/python/Modules/_decimal/libmpdec/context.c @@ -1,36 +1,41 @@ -/* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright (c) 2008-2016 Stefan Krah. All rights reserved. │ +│ │ +│ Redistribution and use in source and binary forms, with or without │ +│ modification, are permitted provided that the following conditions │ +│ are met: │ +│ │ +│ 1. Redistributions of source code must retain the above copyright │ +│ notice, this list of conditions and the following disclaimer. │ +│ │ +│ 2. Redistributions in binary form must reproduce the above copyright │ +│ notice, this list of conditions and the following disclaimer in │ +│ the documentation and/or other materials provided with the │ +│ distribution. │ +│ │ +│ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND │ +│ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE │ +│ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR │ +│ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS │ +│ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, │ +│ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT │ +│ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR │ +│ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, │ +│ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE │ +│ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, │ +│ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/sysv/consts/sig.h" -#include "mpdecimal.h" +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +/* clang-format off */ +asm(".ident\t\"\\n\\n\ +libmpdec (BSD-2)\\n\ +Copyright 2008-2016 Stefan Krah\""); +asm(".include \"libc/disclaimer.inc\""); void mpd_dflt_traphandler(mpd_context_t *ctx UNUSED) diff --git a/third_party/python/Modules/_decimal/libmpdec/convolute.c b/third_party/python/Modules/_decimal/libmpdec/convolute.c index ac1430246..e501c3508 100644 --- a/third_party/python/Modules/_decimal/libmpdec/convolute.c +++ b/third_party/python/Modules/_decimal/libmpdec/convolute.c @@ -1,41 +1,47 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright (c) 2008-2016 Stefan Krah. All rights reserved. │ +│ │ +│ Redistribution and use in source and binary forms, with or without │ +│ modification, are permitted provided that the following conditions │ +│ are met: │ +│ │ +│ 1. Redistributions of source code must retain the above copyright │ +│ notice, this list of conditions and the following disclaimer. │ +│ │ +│ 2. Redistributions in binary form must reproduce the above copyright │ +│ notice, this list of conditions and the following disclaimer in │ +│ the documentation and/or other materials provided with the │ +│ distribution. │ +│ │ +│ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND │ +│ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE │ +│ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR │ +│ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS │ +│ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, │ +│ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT │ +│ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR │ +│ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, │ +│ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE │ +│ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, │ +│ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/python/Modules/_decimal/libmpdec/bits.h" +#include "third_party/python/Modules/_decimal/libmpdec/constants.h" +#include "third_party/python/Modules/_decimal/libmpdec/convolute.h" +#include "third_party/python/Modules/_decimal/libmpdec/fnt.h" +#include "third_party/python/Modules/_decimal/libmpdec/fourstep.h" +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +#include "third_party/python/Modules/_decimal/libmpdec/numbertheory.h" +#include "third_party/python/Modules/_decimal/libmpdec/sixstep.h" +#include "third_party/python/Modules/_decimal/libmpdec/umodarith.h" /* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "mpdecimal.h" -#include "bits.h" -#include "constants.h" -#include "fnt.h" -#include "fourstep.h" -#include "numbertheory.h" -#include "sixstep.h" -#include "umodarith.h" -#include "convolute.h" +asm(".ident\t\"\\n\\n\ +libmpdec (BSD-2)\\n\ +Copyright 2008-2016 Stefan Krah\""); +asm(".include \"libc/disclaimer.inc\""); /* Bignum: Fast convolution using the Number Theoretic Transform. Used for diff --git a/third_party/python/Modules/_decimal/libmpdec/convolute.h b/third_party/python/Modules/_decimal/libmpdec/convolute.h index ed2f885a2..7d27e66e4 100644 --- a/third_party/python/Modules/_decimal/libmpdec/convolute.h +++ b/third_party/python/Modules/_decimal/libmpdec/convolute.h @@ -1,50 +1,16 @@ -/* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - #ifndef CONVOLUTE_H #define CONVOLUTE_H - - -#include "mpdecimal.h" - +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +/* clang-format off */ /* Internal header file: all symbols have local scope in the DSO */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) - #define SIX_STEP_THRESHOLD 4096 int fnt_convolute(mpd_uint_t *c1, mpd_uint_t *c2, mpd_size_t n, int modnum); int fnt_autoconvolute(mpd_uint_t *c1, mpd_size_t n, int modnum); - MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ - #endif diff --git a/third_party/python/Modules/_decimal/libmpdec/crt.c b/third_party/python/Modules/_decimal/libmpdec/crt.c index dd1fe6f0a..02261b4a5 100644 --- a/third_party/python/Modules/_decimal/libmpdec/crt.c +++ b/third_party/python/Modules/_decimal/libmpdec/crt.c @@ -1,36 +1,42 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright (c) 2008-2016 Stefan Krah. All rights reserved. │ +│ │ +│ Redistribution and use in source and binary forms, with or without │ +│ modification, are permitted provided that the following conditions │ +│ are met: │ +│ │ +│ 1. Redistributions of source code must retain the above copyright │ +│ notice, this list of conditions and the following disclaimer. │ +│ │ +│ 2. Redistributions in binary form must reproduce the above copyright │ +│ notice, this list of conditions and the following disclaimer in │ +│ the documentation and/or other materials provided with the │ +│ distribution. │ +│ │ +│ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND │ +│ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE │ +│ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR │ +│ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS │ +│ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, │ +│ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT │ +│ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR │ +│ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, │ +│ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE │ +│ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, │ +│ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/python/Modules/_decimal/libmpdec/crt.h" +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +#include "third_party/python/Modules/_decimal/libmpdec/numbertheory.h" +#include "third_party/python/Modules/_decimal/libmpdec/umodarith.h" /* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "mpdecimal.h" -#include "numbertheory.h" -#include "umodarith.h" -#include "crt.h" +asm(".ident\t\"\\n\\n\ +libmpdec (BSD-2)\\n\ +Copyright 2008-2016 Stefan Krah\""); +asm(".include \"libc/disclaimer.inc\""); /* Bignum: Chinese Remainder Theorem, extends the maximum transform length. */ @@ -174,5 +180,3 @@ crt3(mpd_uint_t *x1, mpd_uint_t *x2, mpd_uint_t *x3, mpd_size_t rsize) assert(carry[0] == 0 && carry[1] == 0 && carry[2] == 0); } - - diff --git a/third_party/python/Modules/_decimal/libmpdec/crt.h b/third_party/python/Modules/_decimal/libmpdec/crt.h index f94e20bcd..33902a3b5 100644 --- a/third_party/python/Modules/_decimal/libmpdec/crt.h +++ b/third_party/python/Modules/_decimal/libmpdec/crt.h @@ -1,47 +1,13 @@ -/* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - #ifndef CRT_H #define CRT_H - - -#include "mpdecimal.h" - +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +/* clang-format off */ /* Internal header file: all symbols have local scope in the DSO */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) - void crt3(mpd_uint_t *x1, mpd_uint_t *x2, mpd_uint_t *x3, mpd_size_t nmemb); - MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ - #endif diff --git a/third_party/python/Modules/_decimal/libmpdec/difradix2.c b/third_party/python/Modules/_decimal/libmpdec/difradix2.c index 71a4af1b9..27cf79557 100644 --- a/third_party/python/Modules/_decimal/libmpdec/difradix2.c +++ b/third_party/python/Modules/_decimal/libmpdec/difradix2.c @@ -1,37 +1,43 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright (c) 2008-2016 Stefan Krah. All rights reserved. │ +│ │ +│ Redistribution and use in source and binary forms, with or without │ +│ modification, are permitted provided that the following conditions │ +│ are met: │ +│ │ +│ 1. Redistributions of source code must retain the above copyright │ +│ notice, this list of conditions and the following disclaimer. │ +│ │ +│ 2. Redistributions in binary form must reproduce the above copyright │ +│ notice, this list of conditions and the following disclaimer in │ +│ the documentation and/or other materials provided with the │ +│ distribution. │ +│ │ +│ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND │ +│ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE │ +│ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR │ +│ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS │ +│ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, │ +│ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT │ +│ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR │ +│ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, │ +│ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE │ +│ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, │ +│ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/python/Modules/_decimal/libmpdec/bits.h" +#include "third_party/python/Modules/_decimal/libmpdec/difradix2.h" +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +#include "third_party/python/Modules/_decimal/libmpdec/numbertheory.h" +#include "third_party/python/Modules/_decimal/libmpdec/umodarith.h" /* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "mpdecimal.h" -#include "bits.h" -#include "numbertheory.h" -#include "umodarith.h" -#include "difradix2.h" +asm(".ident\t\"\\n\\n\ +libmpdec (BSD-2)\\n\ +Copyright 2008-2016 Stefan Krah\""); +asm(".include \"libc/disclaimer.inc\""); /* Bignum: The actual transform routine (decimation in frequency). */ diff --git a/third_party/python/Modules/_decimal/libmpdec/difradix2.h b/third_party/python/Modules/_decimal/libmpdec/difradix2.h index 52150f130..e9306b7f0 100644 --- a/third_party/python/Modules/_decimal/libmpdec/difradix2.h +++ b/third_party/python/Modules/_decimal/libmpdec/difradix2.h @@ -1,48 +1,14 @@ -/* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - #ifndef DIF_RADIX2_H #define DIF_RADIX2_H - - -#include "mpdecimal.h" -#include "numbertheory.h" - +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +#include "third_party/python/Modules/_decimal/libmpdec/numbertheory.h" +/* clang-format off */ /* Internal header file: all symbols have local scope in the DSO */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) - void fnt_dif2(mpd_uint_t a[], mpd_size_t n, struct fnt_params *tparams); - MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ - #endif diff --git a/third_party/python/Modules/_decimal/libmpdec/fnt.c b/third_party/python/Modules/_decimal/libmpdec/fnt.c index e9c2efb39..5e319e7cb 100644 --- a/third_party/python/Modules/_decimal/libmpdec/fnt.c +++ b/third_party/python/Modules/_decimal/libmpdec/fnt.c @@ -1,38 +1,44 @@ -/* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - -#include "mpdecimal.h" -#include "bits.h" -#include "difradix2.h" -#include "numbertheory.h" +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright (c) 2008-2016 Stefan Krah. All rights reserved. │ +│ │ +│ Redistribution and use in source and binary forms, with or without │ +│ modification, are permitted provided that the following conditions │ +│ are met: │ +│ │ +│ 1. Redistributions of source code must retain the above copyright │ +│ notice, this list of conditions and the following disclaimer. │ +│ │ +│ 2. Redistributions in binary form must reproduce the above copyright │ +│ notice, this list of conditions and the following disclaimer in │ +│ the documentation and/or other materials provided with the │ +│ distribution. │ +│ │ +│ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND │ +│ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE │ +│ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR │ +│ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS │ +│ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, │ +│ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT │ +│ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR │ +│ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, │ +│ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE │ +│ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, │ +│ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "fnt.h" +#include "third_party/python/Modules/_decimal/libmpdec/bits.h" +#include "third_party/python/Modules/_decimal/libmpdec/difradix2.h" +#include "third_party/python/Modules/_decimal/libmpdec/fnt.h" +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +#include "third_party/python/Modules/_decimal/libmpdec/numbertheory.h" +/* clang-format off */ + +asm(".ident\t\"\\n\\n\ +libmpdec (BSD-2)\\n\ +Copyright 2008-2016 Stefan Krah\""); +asm(".include \"libc/disclaimer.inc\""); /* Bignum: Fast transform for medium-sized coefficients. */ diff --git a/third_party/python/Modules/_decimal/libmpdec/fnt.h b/third_party/python/Modules/_decimal/libmpdec/fnt.h index 1ce5c982d..eb382abf7 100644 --- a/third_party/python/Modules/_decimal/libmpdec/fnt.h +++ b/third_party/python/Modules/_decimal/libmpdec/fnt.h @@ -1,49 +1,14 @@ -/* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - #ifndef FNT_H #define FNT_H - - -#include "mpdecimal.h" - +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +/* clang-format off */ /* Internal header file: all symbols have local scope in the DSO */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) - int std_fnt(mpd_uint_t a[], mpd_size_t n, int modnum); int std_inv_fnt(mpd_uint_t a[], mpd_size_t n, int modnum); - MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ - #endif - diff --git a/third_party/python/Modules/_decimal/libmpdec/fourstep.c b/third_party/python/Modules/_decimal/libmpdec/fourstep.c index 09660515b..af99282b5 100644 --- a/third_party/python/Modules/_decimal/libmpdec/fourstep.c +++ b/third_party/python/Modules/_decimal/libmpdec/fourstep.c @@ -1,38 +1,44 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright (c) 2008-2016 Stefan Krah. All rights reserved. │ +│ │ +│ Redistribution and use in source and binary forms, with or without │ +│ modification, are permitted provided that the following conditions │ +│ are met: │ +│ │ +│ 1. Redistributions of source code must retain the above copyright │ +│ notice, this list of conditions and the following disclaimer. │ +│ │ +│ 2. Redistributions in binary form must reproduce the above copyright │ +│ notice, this list of conditions and the following disclaimer in │ +│ the documentation and/or other materials provided with the │ +│ distribution. │ +│ │ +│ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND │ +│ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE │ +│ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR │ +│ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS │ +│ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, │ +│ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT │ +│ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR │ +│ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, │ +│ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE │ +│ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, │ +│ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/python/Modules/_decimal/libmpdec/fourstep.h" +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +#include "third_party/python/Modules/_decimal/libmpdec/numbertheory.h" +#include "third_party/python/Modules/_decimal/libmpdec/sixstep.h" +#include "third_party/python/Modules/_decimal/libmpdec/transpose.h" +#include "third_party/python/Modules/_decimal/libmpdec/umodarith.h" /* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "mpdecimal.h" -#include "numbertheory.h" -#include "sixstep.h" -#include "transpose.h" -#include "umodarith.h" -#include "fourstep.h" +asm(".ident\t\"\\n\\n\ +libmpdec (BSD-2)\\n\ +Copyright 2008-2016 Stefan Krah\""); +asm(".include \"libc/disclaimer.inc\""); /* Bignum: Cache efficient Matrix Fourier Transform for arrays of the diff --git a/third_party/python/Modules/_decimal/libmpdec/fourstep.h b/third_party/python/Modules/_decimal/libmpdec/fourstep.h index dc069e741..b30dfbabe 100644 --- a/third_party/python/Modules/_decimal/libmpdec/fourstep.h +++ b/third_party/python/Modules/_decimal/libmpdec/fourstep.h @@ -1,48 +1,14 @@ -/* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - #ifndef FOUR_STEP_H #define FOUR_STEP_H - - -#include "mpdecimal.h" - +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +/* clang-format off */ /* Internal header file: all symbols have local scope in the DSO */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) - int four_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum); int inv_four_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum); - MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ - #endif diff --git a/third_party/python/Modules/_decimal/libmpdec/io.c b/third_party/python/Modules/_decimal/libmpdec/io.c index 26ec0e274..18835260c 100644 --- a/third_party/python/Modules/_decimal/libmpdec/io.c +++ b/third_party/python/Modules/_decimal/libmpdec/io.c @@ -1,40 +1,46 @@ -/* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - -#include "mpdecimal.h" -#include "libc/unicode/locale.h" -#include "bits.h" -#include "constants.h" -#include "typearith.h" +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright (c) 2008-2016 Stefan Krah. All rights reserved. │ +│ │ +│ Redistribution and use in source and binary forms, with or without │ +│ modification, are permitted provided that the following conditions │ +│ are met: │ +│ │ +│ 1. Redistributions of source code must retain the above copyright │ +│ notice, this list of conditions and the following disclaimer. │ +│ │ +│ 2. Redistributions in binary form must reproduce the above copyright │ +│ notice, this list of conditions and the following disclaimer in │ +│ the documentation and/or other materials provided with the │ +│ distribution. │ +│ │ +│ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND │ +│ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE │ +│ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR │ +│ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS │ +│ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, │ +│ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT │ +│ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR │ +│ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, │ +│ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE │ +│ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, │ +│ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/errno.h" #include "libc/fmt/fmt.h" -#include "io.h" +#include "libc/unicode/locale.h" +#include "third_party/python/Modules/_decimal/libmpdec/bits.h" +#include "third_party/python/Modules/_decimal/libmpdec/constants.h" +#include "third_party/python/Modules/_decimal/libmpdec/io.h" +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +#include "third_party/python/Modules/_decimal/libmpdec/typearith.h" +/* clang-format off */ + +asm(".ident\t\"\\n\\n\ +libmpdec (BSD-2)\\n\ +Copyright 2008-2016 Stefan Krah\""); +asm(".include \"libc/disclaimer.inc\""); /* This file contains functions for decimal <-> string conversions, including diff --git a/third_party/python/Modules/_decimal/libmpdec/io.h b/third_party/python/Modules/_decimal/libmpdec/io.h index 374b0296c..77c1af9c4 100644 --- a/third_party/python/Modules/_decimal/libmpdec/io.h +++ b/third_party/python/Modules/_decimal/libmpdec/io.h @@ -1,6 +1,6 @@ #ifndef IO_H #define IO_H -#include "mpdecimal.h" +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" /* clang-format off */ #if SIZE_MAX == MPD_SIZE_MAX diff --git a/third_party/python/Modules/_decimal/libmpdec/memory.c b/third_party/python/Modules/_decimal/libmpdec/memory.c index 51a083105..0fa6f16c3 100644 --- a/third_party/python/Modules/_decimal/libmpdec/memory.c +++ b/third_party/python/Modules/_decimal/libmpdec/memory.c @@ -1,41 +1,41 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright (c) 2008-2016 Stefan Krah. All rights reserved. │ +│ │ +│ Redistribution and use in source and binary forms, with or without │ +│ modification, are permitted provided that the following conditions │ +│ are met: │ +│ │ +│ 1. Redistributions of source code must retain the above copyright │ +│ notice, this list of conditions and the following disclaimer. │ +│ │ +│ 2. Redistributions in binary form must reproduce the above copyright │ +│ notice, this list of conditions and the following disclaimer in │ +│ the documentation and/or other materials provided with the │ +│ distribution. │ +│ │ +│ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND │ +│ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE │ +│ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR │ +│ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS │ +│ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, │ +│ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT │ +│ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR │ +│ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, │ +│ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE │ +│ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, │ +│ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/python/Modules/_decimal/libmpdec/mpalloc.h" +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +#include "third_party/python/Modules/_decimal/libmpdec/typearith.h" /* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - -#include "mpdecimal.h" -#include "typearith.h" -#include "mpalloc.h" - - -#if defined(_MSC_VER) - #pragma warning(disable : 4232) -#endif +asm(".ident\t\"\\n\\n\ +libmpdec (BSD-2)\\n\ +Copyright 2008-2016 Stefan Krah\""); +asm(".include \"libc/disclaimer.inc\""); /* Guaranteed minimum allocation for a coefficient. May be changed once at program start using mpd_setminalloc(). */ @@ -74,7 +74,7 @@ mpd_callocfunc_em(size_t nmemb, size_t size) return NULL; } /* used on uint32_t or uint64_t */ - memset(ptr, 0, req); + bzero(ptr, req); return ptr; } diff --git a/third_party/python/Modules/_decimal/libmpdec/mpalloc.h b/third_party/python/Modules/_decimal/libmpdec/mpalloc.h index 3c15e6ad0..03276d7cd 100644 --- a/third_party/python/Modules/_decimal/libmpdec/mpalloc.h +++ b/third_party/python/Modules/_decimal/libmpdec/mpalloc.h @@ -1,52 +1,15 @@ -/* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - #ifndef MPALLOC_H #define MPALLOC_H - - -#include "mpdecimal.h" - +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +/* clang-format off */ /* Internal header file: all symbols have local scope in the DSO */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) - int mpd_switch_to_dyn(mpd_t *result, mpd_ssize_t size, uint32_t *status); int mpd_switch_to_dyn_zero(mpd_t *result, mpd_ssize_t size, uint32_t *status); int mpd_realloc_dyn(mpd_t *result, mpd_ssize_t size, uint32_t *status); - MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ - #endif - - - diff --git a/third_party/python/Modules/_decimal/libmpdec/mpdecimal.c b/third_party/python/Modules/_decimal/libmpdec/mpdecimal.c index df6711b81..b52e6655d 100644 --- a/third_party/python/Modules/_decimal/libmpdec/mpdecimal.c +++ b/third_party/python/Modules/_decimal/libmpdec/mpdecimal.c @@ -1,67 +1,63 @@ -/* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - -#include "mpdecimal.h" -#include "basearith.h" -#include "bits.h" -#include "convolute.h" -#include "crt.h" -#include "mpalloc.h" -#include "typearith.h" +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright (c) 2008-2016 Stefan Krah. All rights reserved. │ +│ │ +│ Redistribution and use in source and binary forms, with or without │ +│ modification, are permitted provided that the following conditions │ +│ are met: │ +│ │ +│ 1. Redistributions of source code must retain the above copyright │ +│ notice, this list of conditions and the following disclaimer. │ +│ │ +│ 2. Redistributions in binary form must reproduce the above copyright │ +│ notice, this list of conditions and the following disclaimer in │ +│ the documentation and/or other materials provided with the │ +│ distribution. │ +│ │ +│ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND │ +│ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE │ +│ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR │ +│ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS │ +│ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, │ +│ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT │ +│ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR │ +│ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, │ +│ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE │ +│ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, │ +│ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "umodarith.h" +#include "third_party/python/Modules/_decimal/libmpdec/basearith.h" +#include "third_party/python/Modules/_decimal/libmpdec/bits.h" +#include "third_party/python/Modules/_decimal/libmpdec/convolute.h" +#include "third_party/python/Modules/_decimal/libmpdec/crt.h" +#include "third_party/python/Modules/_decimal/libmpdec/mpalloc.h" +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +#include "third_party/python/Modules/_decimal/libmpdec/typearith.h" +#include "third_party/python/Modules/_decimal/libmpdec/umodarith.h" +/* clang-format off */ + +asm(".ident\t\"\\n\\n\ +libmpdec (BSD-2)\\n\ +Copyright 2008-2016 Stefan Krah\""); +asm(".include \"libc/disclaimer.inc\""); #ifdef PPRO #if defined(_MSC_VER) - #include #pragma float_control(precise, on) #pragma fenv_access(on) #elif !defined(__OpenBSD__) && !defined(__NetBSD__) /* C99 */ - #include #pragma STDC FENV_ACCESS ON #endif #endif -#if defined(_MSC_VER) - #define ALWAYS_INLINE __forceinline -#elif defined(LEGACY_COMPILER) - #define ALWAYS_INLINE - #undef inline - #define inline +#ifdef TEST_COVERAGE +#define ALWAYS_INLINE #else - #ifdef TEST_COVERAGE - #define ALWAYS_INLINE - #else - #define ALWAYS_INLINE inline __attribute__ ((always_inline)) - #endif +#define ALWAYS_INLINE __inline __attribute__((__always_inline__)) #endif diff --git a/third_party/python/Modules/_decimal/libmpdec/mpdecimal.h b/third_party/python/Modules/_decimal/libmpdec/mpdecimal.h index 0c3aca70b..b868148f9 100644 --- a/third_party/python/Modules/_decimal/libmpdec/mpdecimal.h +++ b/third_party/python/Modules/_decimal/libmpdec/mpdecimal.h @@ -61,25 +61,23 @@ const char *mpd_version(void); /* Configuration */ /******************************************************************************/ -#if defined(UNIVERSAL) - #if defined(CONFIG_64) || defined(CONFIG_32) - #error "cannot use CONFIG_64 or CONFIG_32 with UNIVERSAL." - #endif - #if defined(__ppc__) - #define CONFIG_32 - #define ANSI - #elif defined(__ppc64__) - #define CONFIG_64 - #define ANSI - #elif defined(__i386__) - #define CONFIG_32 - #define ANSI - #elif defined(__x86_64__) - #define CONFIG_64 - #define ASM - #else - #error "unknown architecture for universal build." - #endif +#if defined(CONFIG_64) || defined(CONFIG_32) +#error "cannot use CONFIG_64 or CONFIG_32 with UNIVERSAL." +#endif +#if defined(__ppc__) +#define CONFIG_32 +#define ANSI +#elif defined(__ppc64__) +#define CONFIG_64 +#define ANSI +#elif defined(__i386__) +#define CONFIG_32 +#define ANSI +#elif defined(__x86_64__) +#define CONFIG_64 +#define ASM +#else +#error "unknown architecture for universal build." #endif diff --git a/third_party/python/Modules/_decimal/libmpdec/numbertheory.c b/third_party/python/Modules/_decimal/libmpdec/numbertheory.c index 5053c55c0..1681b546a 100644 --- a/third_party/python/Modules/_decimal/libmpdec/numbertheory.c +++ b/third_party/python/Modules/_decimal/libmpdec/numbertheory.c @@ -1,36 +1,42 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright (c) 2008-2016 Stefan Krah. All rights reserved. │ +│ │ +│ Redistribution and use in source and binary forms, with or without │ +│ modification, are permitted provided that the following conditions │ +│ are met: │ +│ │ +│ 1. Redistributions of source code must retain the above copyright │ +│ notice, this list of conditions and the following disclaimer. │ +│ │ +│ 2. Redistributions in binary form must reproduce the above copyright │ +│ notice, this list of conditions and the following disclaimer in │ +│ the documentation and/or other materials provided with the │ +│ distribution. │ +│ │ +│ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND │ +│ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE │ +│ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR │ +│ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS │ +│ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, │ +│ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT │ +│ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR │ +│ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, │ +│ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE │ +│ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, │ +│ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/python/Modules/_decimal/libmpdec/bits.h" +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +#include "third_party/python/Modules/_decimal/libmpdec/numbertheory.h" +#include "third_party/python/Modules/_decimal/libmpdec/umodarith.h" /* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "mpdecimal.h" -#include "bits.h" -#include "umodarith.h" -#include "numbertheory.h" +asm(".ident\t\"\\n\\n\ +libmpdec (BSD-2)\\n\ +Copyright 2008-2016 Stefan Krah\""); +asm(".include \"libc/disclaimer.inc\""); /* Bignum: Initialize the Number Theoretic Transform. */ diff --git a/third_party/python/Modules/_decimal/libmpdec/numbertheory.h b/third_party/python/Modules/_decimal/libmpdec/numbertheory.h index 3e6ee9824..b06078996 100644 --- a/third_party/python/Modules/_decimal/libmpdec/numbertheory.h +++ b/third_party/python/Modules/_decimal/libmpdec/numbertheory.h @@ -1,44 +1,12 @@ -/* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - #ifndef NUMBER_THEORY_H #define NUMBER_THEORY_H - - -#include "constants.h" -#include "mpdecimal.h" - +#include "third_party/python/Modules/_decimal/libmpdec/constants.h" +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +/* clang-format off */ /* Internal header file: all symbols have local scope in the DSO */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) - /* transform parameters */ struct fnt_params { int modnum; @@ -47,12 +15,10 @@ struct fnt_params { mpd_uint_t wtable[]; }; - mpd_uint_t _mpd_getkernel(mpd_uint_t n, int sign, int modnum); struct fnt_params *_mpd_init_fnt_params(mpd_size_t n, int sign, int modnum); void _mpd_init_w3table(mpd_uint_t w3table[3], int sign, int modnum); - #ifdef PPRO static inline void ppro_setmodulus(int modnum, mpd_uint_t *umod, double *dmod, uint32_t dinvmod[3]) @@ -70,10 +36,6 @@ std_setmodulus(int modnum, mpd_uint_t *umod) } #endif - MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ - #endif - - diff --git a/third_party/python/Modules/_decimal/libmpdec/sixstep.c b/third_party/python/Modules/_decimal/libmpdec/sixstep.c index 416801df6..65abc1053 100644 --- a/third_party/python/Modules/_decimal/libmpdec/sixstep.c +++ b/third_party/python/Modules/_decimal/libmpdec/sixstep.c @@ -1,39 +1,45 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright (c) 2008-2016 Stefan Krah. All rights reserved. │ +│ │ +│ Redistribution and use in source and binary forms, with or without │ +│ modification, are permitted provided that the following conditions │ +│ are met: │ +│ │ +│ 1. Redistributions of source code must retain the above copyright │ +│ notice, this list of conditions and the following disclaimer. │ +│ │ +│ 2. Redistributions in binary form must reproduce the above copyright │ +│ notice, this list of conditions and the following disclaimer in │ +│ the documentation and/or other materials provided with the │ +│ distribution. │ +│ │ +│ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND │ +│ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE │ +│ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR │ +│ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS │ +│ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, │ +│ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT │ +│ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR │ +│ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, │ +│ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE │ +│ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, │ +│ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/python/Modules/_decimal/libmpdec/bits.h" +#include "third_party/python/Modules/_decimal/libmpdec/difradix2.h" +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +#include "third_party/python/Modules/_decimal/libmpdec/numbertheory.h" +#include "third_party/python/Modules/_decimal/libmpdec/sixstep.h" +#include "third_party/python/Modules/_decimal/libmpdec/transpose.h" +#include "third_party/python/Modules/_decimal/libmpdec/umodarith.h" /* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "mpdecimal.h" -#include "bits.h" -#include "difradix2.h" -#include "numbertheory.h" -#include "transpose.h" -#include "umodarith.h" -#include "sixstep.h" +asm(".ident\t\"\\n\\n\ +libmpdec (BSD-2)\\n\ +Copyright 2008-2016 Stefan Krah\""); +asm(".include \"libc/disclaimer.inc\""); /* Bignum: Cache efficient Matrix Fourier Transform for arrays of the diff --git a/third_party/python/Modules/_decimal/libmpdec/sixstep.h b/third_party/python/Modules/_decimal/libmpdec/sixstep.h index 31ee9b12b..625e401a1 100644 --- a/third_party/python/Modules/_decimal/libmpdec/sixstep.h +++ b/third_party/python/Modules/_decimal/libmpdec/sixstep.h @@ -1,48 +1,14 @@ -/* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - #ifndef SIX_STEP_H #define SIX_STEP_H - - -#include "mpdecimal.h" - +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +/* clang-format off */ /* Internal header file: all symbols have local scope in the DSO */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) - int six_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum); int inv_six_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum); - MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ - #endif diff --git a/third_party/python/Modules/_decimal/libmpdec/transpose.c b/third_party/python/Modules/_decimal/libmpdec/transpose.c index 4e88f4b8b..19a81e410 100644 --- a/third_party/python/Modules/_decimal/libmpdec/transpose.c +++ b/third_party/python/Modules/_decimal/libmpdec/transpose.c @@ -1,37 +1,43 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright (c) 2008-2016 Stefan Krah. All rights reserved. │ +│ │ +│ Redistribution and use in source and binary forms, with or without │ +│ modification, are permitted provided that the following conditions │ +│ are met: │ +│ │ +│ 1. Redistributions of source code must retain the above copyright │ +│ notice, this list of conditions and the following disclaimer. │ +│ │ +│ 2. Redistributions in binary form must reproduce the above copyright │ +│ notice, this list of conditions and the following disclaimer in │ +│ the documentation and/or other materials provided with the │ +│ distribution. │ +│ │ +│ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND │ +│ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE │ +│ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR │ +│ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS │ +│ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, │ +│ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT │ +│ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR │ +│ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, │ +│ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE │ +│ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, │ +│ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/python/Modules/_decimal/libmpdec/bits.h" +#include "third_party/python/Modules/_decimal/libmpdec/constants.h" +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +#include "third_party/python/Modules/_decimal/libmpdec/transpose.h" +#include "third_party/python/Modules/_decimal/libmpdec/typearith.h" /* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "mpdecimal.h" -#include "bits.h" -#include "constants.h" -#include "typearith.h" -#include "transpose.h" +asm(".ident\t\"\\n\\n\ +libmpdec (BSD-2)\\n\ +Copyright 2008-2016 Stefan Krah\""); +asm(".include \"libc/disclaimer.inc\""); #define BUFSIZE 4096 diff --git a/third_party/python/Modules/_decimal/libmpdec/transpose.h b/third_party/python/Modules/_decimal/libmpdec/transpose.h index 3817b958c..ca8b7c8d4 100644 --- a/third_party/python/Modules/_decimal/libmpdec/transpose.h +++ b/third_party/python/Modules/_decimal/libmpdec/transpose.h @@ -1,31 +1,25 @@ #ifndef TRANSPOSE_H #define TRANSPOSE_H -#include "mpdecimal.h" +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" /* clang-format off */ /* Internal header file: all symbols have local scope in the DSO */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) - enum {FORWARD_CYCLE, BACKWARD_CYCLE}; - void std_trans(mpd_uint_t dest[], mpd_uint_t src[], mpd_size_t rows, mpd_size_t cols); int transpose_pow2(mpd_uint_t *matrix, mpd_size_t rows, mpd_size_t cols); void transpose_3xpow2(mpd_uint_t *matrix, mpd_size_t rows, mpd_size_t cols); - static inline void pointerswap(mpd_uint_t **a, mpd_uint_t **b) { mpd_uint_t *tmp; - tmp = *b; *b = *a; *a = tmp; } - MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ - #endif diff --git a/third_party/python/Modules/_decimal/libmpdec/typearith.h b/third_party/python/Modules/_decimal/libmpdec/typearith.h index b1cea626f..95e640bd0 100644 --- a/third_party/python/Modules/_decimal/libmpdec/typearith.h +++ b/third_party/python/Modules/_decimal/libmpdec/typearith.h @@ -1,38 +1,8 @@ -/* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - #ifndef TYPEARITH_H #define TYPEARITH_H - - #include "libc/assert.h" -#include "mpdecimal.h" +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +/* clang-format off */ /*****************************************************************************/ @@ -235,20 +205,6 @@ _mpd_div_words(mpd_uint_t *q, mpd_uint_t *r, mpd_uint_t hi, mpd_uint_t lo, *r = rr; } /* END GCC ASM */ -#elif defined(MASM) -#include -#pragma intrinsic(_umul128) - -static inline void -_mpd_mul_words(mpd_uint_t *hi, mpd_uint_t *lo, mpd_uint_t a, mpd_uint_t b) -{ - *lo = _umul128(a, b, hi); -} - -void _mpd_div_words(mpd_uint_t *q, mpd_uint_t *r, mpd_uint_t hi, mpd_uint_t lo, - mpd_uint_t d); - -/* END MASM (_MSC_VER) */ #else #error "need platform specific 128 bit multiplication and division" #endif @@ -492,41 +448,6 @@ _mpd_div_words(mpd_uint_t *q, mpd_uint_t *r, mpd_uint_t hi, mpd_uint_t lo, *r = rr; } /* END GCC ASM */ -#elif defined(MASM) -static inline void __cdecl -_mpd_mul_words(mpd_uint_t *hi, mpd_uint_t *lo, mpd_uint_t a, mpd_uint_t b) -{ - mpd_uint_t h, l; - - __asm { - mov eax, a - mul b - mov h, edx - mov l, eax - } - - *hi = h; - *lo = l; -} - -static inline void __cdecl -_mpd_div_words(mpd_uint_t *q, mpd_uint_t *r, mpd_uint_t hi, mpd_uint_t lo, - mpd_uint_t d) -{ - mpd_uint_t qq, rr; - - __asm { - mov eax, lo - mov edx, hi - div d - mov qq, eax - mov rr, edx - } - - *q = qq; - *r = rr; -} -/* END MASM (_MSC_VER) */ #else #error "need platform specific 64 bit multiplication and division" #endif diff --git a/third_party/python/Modules/_decimal/libmpdec/umodarith.h b/third_party/python/Modules/_decimal/libmpdec/umodarith.h index 5df665cc2..7d10b30d5 100644 --- a/third_party/python/Modules/_decimal/libmpdec/umodarith.h +++ b/third_party/python/Modules/_decimal/libmpdec/umodarith.h @@ -1,39 +1,9 @@ -/* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - #ifndef UMODARITH_H #define UMODARITH_H - - -#include "constants.h" -#include "mpdecimal.h" -#include "typearith.h" +#include "third_party/python/Modules/_decimal/libmpdec/constants.h" +#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" +#include "third_party/python/Modules/_decimal/libmpdec/typearith.h" +/* clang-format off */ /* Bignum: Low level routines for unsigned modular arithmetic. These are diff --git a/third_party/python/Modules/_decimal/libmpdec/vccompat.h b/third_party/python/Modules/_decimal/libmpdec/vccompat.h deleted file mode 100644 index 2653b5a68..000000000 --- a/third_party/python/Modules/_decimal/libmpdec/vccompat.h +++ /dev/null @@ -1,58 +0,0 @@ -/* clang-format off */ -/* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - -#ifndef VCCOMPAT_H -#define VCCOMPAT_H - - -/* Visual C fixes: no stdint.h, no snprintf ... */ -#ifdef _MSC_VER - #undef inline - #define inline __inline - #undef random - #define random rand - #undef srandom - #define srandom srand - #undef snprintf - #define snprintf sprintf_s - #define HAVE_SNPRINTF - #undef strncasecmp - #define strncasecmp _strnicmp - #undef strcasecmp - #define strcasecmp _stricmp - #undef strtoll - #define strtoll _strtoi64 - #define strdup _strdup -#endif - - -#endif /* VCCOMPAT_H */ - - - diff --git a/third_party/python/Modules/_decimal/libmpdec/vcdiv64.asm b/third_party/python/Modules/_decimal/libmpdec/vcdiv64.asm deleted file mode 100644 index 6b6645673..000000000 --- a/third_party/python/Modules/_decimal/libmpdec/vcdiv64.asm +++ /dev/null @@ -1,48 +0,0 @@ -; -; Copyright (c) 2008-2016 Stefan Krah. All rights reserved. -; -; Redistribution and use in source and binary forms, with or without -; modification, are permitted provided that the following conditions -; are met: -; -; 1. Redistributions of source code must retain the above copyright -; notice, this list of conditions and the following disclaimer. -; -; 2. Redistributions in binary form must reproduce the above copyright -; notice, this list of conditions and the following disclaimer in the -; documentation and/or other materials provided with the distribution. -; -; THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND -; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -; SUCH DAMAGE. -; - - -PUBLIC _mpd_div_words -_TEXT SEGMENT -q$ = 8 -r$ = 16 -hi$ = 24 -lo$ = 32 -d$ = 40 -_mpd_div_words PROC - mov r10, rdx - mov rdx, r8 - mov rax, r9 - div QWORD PTR d$[rsp] - mov QWORD PTR [r10], rdx - mov QWORD PTR [rcx], rax - ret 0 -_mpd_div_words ENDP -_TEXT ENDS -END - - diff --git a/third_party/python/Modules/_decimal/libmpdec/vcstdint.h b/third_party/python/Modules/_decimal/libmpdec/vcstdint.h deleted file mode 100644 index a7e8d9295..000000000 --- a/third_party/python/Modules/_decimal/libmpdec/vcstdint.h +++ /dev/null @@ -1,233 +0,0 @@ -/* clang-format off */ -// ISO C9x compliant stdint.h for Microsoft Visual Studio -// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 -// -// Copyright (c) 2006-2008 Alexander Chemeris -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// 3. The name of the author may be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED -// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO -// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef _MSC_VER // [ -#error "Use this header only with Microsoft Visual C++ compilers!" -#endif // _MSC_VER ] - -#ifndef _MSC_STDINT_H_ // [ -#define _MSC_STDINT_H_ - -#if _MSC_VER > 1000 -#pragma once -#endif - -#include - -// For Visual Studio 6 in C++ mode wrap include with 'extern "C++" {}' -// or compiler give many errors like this: -// error C2733: second C linkage of overloaded function 'wmemchr' not allowed -#if (_MSC_VER < 1300) && defined(__cplusplus) - extern "C++" { -#endif -# include -#if (_MSC_VER < 1300) && defined(__cplusplus) - } -#endif - -// Define _W64 macros to mark types changing their size, like intptr_t. -#ifndef _W64 -# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300 -# define _W64 __w64 -# else -# define _W64 -# endif -#endif - - -// 7.18.1 Integer types - -// 7.18.1.1 Exact-width integer types -typedef __int8 int8_t; -typedef __int16 int16_t; -typedef __int32 int32_t; -typedef __int64 int64_t; -typedef unsigned __int8 uint8_t; -typedef unsigned __int16 uint16_t; -typedef unsigned __int32 uint32_t; -typedef unsigned __int64 uint64_t; - -// 7.18.1.2 Minimum-width integer types -typedef int8_t int_least8_t; -typedef int16_t int_least16_t; -typedef int32_t int_least32_t; -typedef int64_t int_least64_t; -typedef uint8_t uint_least8_t; -typedef uint16_t uint_least16_t; -typedef uint32_t uint_least32_t; -typedef uint64_t uint_least64_t; - -// 7.18.1.3 Fastest minimum-width integer types -typedef int8_t int_fast8_t; -typedef int16_t int_fast16_t; -typedef int32_t int_fast32_t; -typedef int64_t int_fast64_t; -typedef uint8_t uint_fast8_t; -typedef uint16_t uint_fast16_t; -typedef uint32_t uint_fast32_t; -typedef uint64_t uint_fast64_t; - -// 7.18.1.4 Integer types capable of holding object pointers -#ifdef _WIN64 // [ - typedef __int64 intptr_t; - typedef unsigned __int64 uintptr_t; -#else // _WIN64 ][ - typedef _W64 int intptr_t; - typedef _W64 unsigned int uintptr_t; -#endif // _WIN64 ] - -// 7.18.1.5 Greatest-width integer types -typedef int64_t intmax_t; -typedef uint64_t uintmax_t; - - -// 7.18.2 Limits of specified-width integer types - -#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259 - -// 7.18.2.1 Limits of exact-width integer types -#define INT8_MIN ((int8_t)_I8_MIN) -#define INT8_MAX _I8_MAX -#define INT16_MIN ((int16_t)_I16_MIN) -#define INT16_MAX _I16_MAX -#define INT32_MIN ((int32_t)_I32_MIN) -#define INT32_MAX _I32_MAX -#define INT64_MIN ((int64_t)_I64_MIN) -#define INT64_MAX _I64_MAX -#define UINT8_MAX _UI8_MAX -#define UINT16_MAX _UI16_MAX -#define UINT32_MAX _UI32_MAX -#define UINT64_MAX _UI64_MAX - -// 7.18.2.2 Limits of minimum-width integer types -#define INT_LEAST8_MIN INT8_MIN -#define INT_LEAST8_MAX INT8_MAX -#define INT_LEAST16_MIN INT16_MIN -#define INT_LEAST16_MAX INT16_MAX -#define INT_LEAST32_MIN INT32_MIN -#define INT_LEAST32_MAX INT32_MAX -#define INT_LEAST64_MIN INT64_MIN -#define INT_LEAST64_MAX INT64_MAX -#define UINT_LEAST8_MAX UINT8_MAX -#define UINT_LEAST16_MAX UINT16_MAX -#define UINT_LEAST32_MAX UINT32_MAX -#define UINT_LEAST64_MAX UINT64_MAX - -// 7.18.2.3 Limits of fastest minimum-width integer types -#define INT_FAST8_MIN INT8_MIN -#define INT_FAST8_MAX INT8_MAX -#define INT_FAST16_MIN INT16_MIN -#define INT_FAST16_MAX INT16_MAX -#define INT_FAST32_MIN INT32_MIN -#define INT_FAST32_MAX INT32_MAX -#define INT_FAST64_MIN INT64_MIN -#define INT_FAST64_MAX INT64_MAX -#define UINT_FAST8_MAX UINT8_MAX -#define UINT_FAST16_MAX UINT16_MAX -#define UINT_FAST32_MAX UINT32_MAX -#define UINT_FAST64_MAX UINT64_MAX - -// 7.18.2.4 Limits of integer types capable of holding object pointers -#ifdef _WIN64 // [ -# define INTPTR_MIN INT64_MIN -# define INTPTR_MAX INT64_MAX -# define UINTPTR_MAX UINT64_MAX -#else // _WIN64 ][ -# define INTPTR_MIN INT32_MIN -# define INTPTR_MAX INT32_MAX -# define UINTPTR_MAX UINT32_MAX -#endif // _WIN64 ] - -// 7.18.2.5 Limits of greatest-width integer types -#define INTMAX_MIN INT64_MIN -#define INTMAX_MAX INT64_MAX -#define UINTMAX_MAX UINT64_MAX - -// 7.18.3 Limits of other integer types - -#ifdef _WIN64 // [ -# define PTRDIFF_MIN _I64_MIN -# define PTRDIFF_MAX _I64_MAX -#else // _WIN64 ][ -# define PTRDIFF_MIN _I32_MIN -# define PTRDIFF_MAX _I32_MAX -#endif // _WIN64 ] - -#define SIG_ATOMIC_MIN INT_MIN -#define SIG_ATOMIC_MAX INT_MAX - -#ifndef SIZE_MAX // [ -# ifdef _WIN64 // [ -# define SIZE_MAX _UI64_MAX -# else // _WIN64 ][ -# define SIZE_MAX _UI32_MAX -# endif // _WIN64 ] -#endif // SIZE_MAX ] - -// WCHAR_MIN and WCHAR_MAX are also defined in -#ifndef WCHAR_MIN // [ -# define WCHAR_MIN 0 -#endif // WCHAR_MIN ] -#ifndef WCHAR_MAX // [ -# define WCHAR_MAX _UI16_MAX -#endif // WCHAR_MAX ] - -#define WINT_MIN 0 -#define WINT_MAX _UI16_MAX - -#endif // __STDC_LIMIT_MACROS ] - - -// 7.18.4 Limits of other integer types - -#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260 - -// 7.18.4.1 Macros for minimum-width integer constants - -#define INT8_C(val) val##i8 -#define INT16_C(val) val##i16 -#define INT32_C(val) val##i32 -#define INT64_C(val) val##i64 - -#define UINT8_C(val) val##ui8 -#define UINT16_C(val) val##ui16 -#define UINT32_C(val) val##ui32 -#define UINT64_C(val) val##ui64 - -// 7.18.4.2 Macros for greatest-width integer constants -#define INTMAX_C INT64_C -#define UINTMAX_C UINT64_C - -#endif // __STDC_CONSTANT_MACROS ] - - -#endif // _MSC_STDINT_H_ ] diff --git a/third_party/python/Modules/_elementtree.c b/third_party/python/Modules/_elementtree.c index f38eafa64..1be08c352 100644 --- a/third_party/python/Modules/_elementtree.c +++ b/third_party/python/Modules/_elementtree.c @@ -1,3 +1,21 @@ +#define PY_SSIZE_T_CLEAN +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/moduleobject.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pycapsule.h" +#include "third_party/python/Include/pyhash.h" +#include "third_party/python/Include/pystate.h" +#include "third_party/python/Include/sliceobject.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/warnings.h" /* clang-format off */ /*-------------------------------------------------------------------- * Licensed to PSF under a Contributor Agreement. @@ -12,11 +30,6 @@ *-------------------------------------------------------------------- */ -#define PY_SSIZE_T_CLEAN - -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" - /* -------------------------------------------------------------------- */ /* configuration */ diff --git a/third_party/python/Modules/_functoolsmodule.c b/third_party/python/Modules/_functoolsmodule.c index 64a7d678a..e7e65a829 100644 --- a/third_party/python/Modules/_functoolsmodule.c +++ b/third_party/python/Modules/_functoolsmodule.c @@ -1,7 +1,17 @@ -/* clang-format off */ - -#include "third_party/python/Include/Python.h" +#include "libc/assert.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/classobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" #include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/tupleobject.h" +/* clang-format off */ /* _functools module written and maintained by Hye-Shik Chang diff --git a/third_party/python/Modules/_gdbmmodule.c b/third_party/python/Modules/_gdbmmodule.c index f1611794c..cf504a572 100644 --- a/third_party/python/Modules/_gdbmmodule.c +++ b/third_party/python/Modules/_gdbmmodule.c @@ -4,16 +4,10 @@ /* Author: Anthony Baxter, after dbmmodule.c */ /* Doc strings: Mitch Chapman */ - -#include "Python.h" - -#include -#include -#include #include "gdbm.h" #if defined(WIN32) && !defined(__CYGWIN__) -#include "gdbmerrno.h" +#include "third_party/python/Include/gdbmerrno.h" extern const char * gdbm_strerror(gdbm_error); #endif diff --git a/third_party/python/Modules/_hashopenssl.c b/third_party/python/Modules/_hashopenssl.c index b31a9d243..db7e6115e 100644 --- a/third_party/python/Modules/_hashopenssl.c +++ b/third_party/python/Modules/_hashopenssl.c @@ -14,10 +14,10 @@ #define PY_SSIZE_T_CLEAN -#include "Python.h" -#include "structmember.h" -#include "hashlib.h" -#include "pystrhex.h" +#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/hashlib.h" +#include "third_party/python/Include/pystrhex.h" /* EVP is the preferred interface to hashing in OpenSSL */ diff --git a/third_party/python/Modules/_heapqmodule.c b/third_party/python/Modules/_heapqmodule.c index a3695c525..1d15f0565 100644 --- a/third_party/python/Modules/_heapqmodule.c +++ b/third_party/python/Modules/_heapqmodule.c @@ -1,4 +1,10 @@ +#include "libc/assert.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" /* clang-format off */ + /* Drop in replacement for heapq.py C implementation derived directly from heapq.py in Py2.3 @@ -7,7 +13,6 @@ annotated by François Pinard, and converted to C by Raymond Hettinger. */ -#include "third_party/python/Include/Python.h" static int siftdown(PyListObject *heap, Py_ssize_t startpos, Py_ssize_t pos) diff --git a/third_party/python/Modules/_io/_iomodule.c b/third_party/python/Modules/_io/_iomodule.c index 78b0a4bef..a5f760b53 100644 --- a/third_party/python/Modules/_io/_iomodule.c +++ b/third_party/python/Modules/_io/_iomodule.c @@ -1,3 +1,25 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Python 3 │ +│ https://docs.python.org/3/license.html │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#define PY_SSIZE_T_CLEAN +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/osmodule.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pystate.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/unicodeobject.h" +#include "third_party/python/Include/warnings.h" +#include "third_party/python/Include/weakrefobject.h" +#include "third_party/python/Modules/_io/_iomodule.h" /* clang-format off */ /* An implementation of the new I/O lib as defined by PEP 3116 - "New I/O" @@ -8,11 +30,6 @@ Mostly written by Amaury Forgeot d'Arc */ -#define PY_SSIZE_T_CLEAN -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" -#include "third_party/python/Modules/_io/_iomodule.h" - /* Various interned strings */ PyObject *_PyIO_str_close; diff --git a/third_party/python/Modules/_io/_iomodule.h b/third_party/python/Modules/_io/_iomodule.h index a81de0a6d..802a07b00 100644 --- a/third_party/python/Modules/_io/_iomodule.h +++ b/third_party/python/Modules/_io/_iomodule.h @@ -1,7 +1,11 @@ +#ifndef COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES__IO__IOMODULE_H_ +#define COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES__IO__IOMODULE_H_ +#include "libc/calls/weirdtypes.h" +#include "third_party/python/Include/moduleobject.h" +#include "third_party/python/Include/object.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ /* clang-format off */ -/* - * Declarations shared between the different parts of the io module - */ /* ABCs */ extern PyTypeObject PyIOBase_Type; @@ -23,7 +27,7 @@ extern PyTypeObject PyIncrementalNewlineDecoder_Type; #ifndef Py_LIMITED_API #ifdef MS_WINDOWS extern PyTypeObject PyWindowsConsoleIO_Type; -PyAPI_DATA(PyObject *) _PyWindowsConsoleIO_Type; +extern PyObject * _PyWindowsConsoleIO_Type; #define PyWindowsConsoleIO_Check(op) (PyObject_TypeCheck((op), (PyTypeObject*)_PyWindowsConsoleIO_Type)) #endif /* MS_WINDOWS */ #endif /* Py_LIMITED_API */ @@ -34,10 +38,10 @@ extern int _PyIO_ConvertSsize_t(PyObject *, void *); * with args=NULL, and return a new reference. * BUT when args=Py_True is passed, they return a borrowed reference. */ -extern PyObject* _PyIOBase_check_readable(PyObject *self, PyObject *args); -extern PyObject* _PyIOBase_check_writable(PyObject *self, PyObject *args); -extern PyObject* _PyIOBase_check_seekable(PyObject *self, PyObject *args); -extern PyObject* _PyIOBase_check_closed(PyObject *self, PyObject *args); +PyObject* _PyIOBase_check_readable(PyObject *, PyObject *); +PyObject* _PyIOBase_check_writable(PyObject *, PyObject *); +PyObject* _PyIOBase_check_seekable(PyObject *, PyObject *); +PyObject* _PyIOBase_check_closed(PyObject *, PyObject *); /* Helper for finalization. This function will revive an object ready to be deallocated and try to @@ -187,3 +191,7 @@ extern PyObject *_PyIO_empty_bytes; extern PyObject *_PyIO_zero; extern PyTypeObject _PyBytesIOBuffer_Type; + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES__IO__IOMODULE_H_ */ diff --git a/third_party/python/Modules/_io/bufferedio.c b/third_party/python/Modules/_io/bufferedio.c index d918630a8..a466c5567 100644 --- a/third_party/python/Modules/_io/bufferedio.c +++ b/third_party/python/Modules/_io/bufferedio.c @@ -1,4 +1,22 @@ +#define PY_SSIZE_T_CLEAN +#include "libc/errno.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/memoryobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pythread.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Modules/_io/_iomodule.h" /* clang-format off */ + /* An implementation of Buffered I/O as defined by PEP 3116 - "New I/O" @@ -8,12 +26,6 @@ Written by Amaury Forgeot d'Arc and Antoine Pitrou */ -#define PY_SSIZE_T_CLEAN -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" -#include "third_party/python/Include/pythread.h" -#include "third_party/python/Modules/_io/_iomodule.h" - /*[clinic input] module _io class _io._BufferedIOBase "PyObject *" "&PyBufferedIOBase_Type" diff --git a/third_party/python/Modules/_io/bytesio.c b/third_party/python/Modules/_io/bytesio.c index c48fd06ca..ff72ad6fe 100644 --- a/third_party/python/Modules/_io/bytesio.c +++ b/third_party/python/Modules/_io/bytesio.c @@ -1,7 +1,23 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" +#include "libc/assert.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/memoryobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pythonrun.h" #include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/sysmodule.h" +#include "third_party/python/Include/tupleobject.h" #include "third_party/python/Modules/_io/_iomodule.h" +/* clang-format off */ /*[clinic input] module _io diff --git a/third_party/python/Modules/_io/clinic/_iomodule.inc b/third_party/python/Modules/_io/clinic/_iomodule.inc index f2e91a9fe..686893cf7 100644 --- a/third_party/python/Modules/_io/clinic/_iomodule.inc +++ b/third_party/python/Modules/_io/clinic/_iomodule.inc @@ -1,3 +1,4 @@ +/* clang-format off */ /*[clinic input] preserve [clinic start generated code]*/ @@ -129,11 +130,6 @@ PyDoc_STRVAR(_io_open__doc__, #define _IO_OPEN_METHODDEF \ {"open", (PyCFunction)_io_open, METH_FASTCALL, _io_open__doc__}, -static PyObject * -_io_open_impl(PyObject *module, PyObject *file, const char *mode, - int buffering, const char *encoding, const char *errors, - const char *newline, int closefd, PyObject *opener); - static PyObject * _io_open(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) { diff --git a/third_party/python/Modules/_io/clinic/bufferedio.inc b/third_party/python/Modules/_io/clinic/bufferedio.inc index 58144a401..d2c05e508 100644 --- a/third_party/python/Modules/_io/clinic/bufferedio.inc +++ b/third_party/python/Modules/_io/clinic/bufferedio.inc @@ -1,3 +1,4 @@ +/* clang-format off */ /*[clinic input] preserve [clinic start generated code]*/ @@ -10,8 +11,6 @@ PyDoc_STRVAR(_io__BufferedIOBase_readinto__doc__, #define _IO__BUFFEREDIOBASE_READINTO_METHODDEF \ {"readinto", (PyCFunction)_io__BufferedIOBase_readinto, METH_O, _io__BufferedIOBase_readinto__doc__}, -static PyObject * -_io__BufferedIOBase_readinto_impl(PyObject *self, Py_buffer *buffer); static PyObject * _io__BufferedIOBase_readinto(PyObject *self, PyObject *arg) diff --git a/third_party/python/Modules/_io/clinic/bytesio.inc b/third_party/python/Modules/_io/clinic/bytesio.inc index c64ce5c77..202e2b7a3 100644 --- a/third_party/python/Modules/_io/clinic/bytesio.inc +++ b/third_party/python/Modules/_io/clinic/bytesio.inc @@ -1,3 +1,4 @@ +/* clang-format off */ /*[clinic input] preserve [clinic start generated code]*/ diff --git a/third_party/python/Modules/_io/clinic/fileio.inc b/third_party/python/Modules/_io/clinic/fileio.inc index 908fe0f8c..1f4346b6f 100644 --- a/third_party/python/Modules/_io/clinic/fileio.inc +++ b/third_party/python/Modules/_io/clinic/fileio.inc @@ -1,3 +1,4 @@ +/* clang-format off */ /*[clinic input] preserve [clinic start generated code]*/ @@ -14,9 +15,6 @@ PyDoc_STRVAR(_io_FileIO_close__doc__, #define _IO_FILEIO_CLOSE_METHODDEF \ {"close", (PyCFunction)_io_FileIO_close, METH_NOARGS, _io_FileIO_close__doc__}, -static PyObject * -_io_FileIO_close_impl(fileio *self); - static PyObject * _io_FileIO_close(fileio *self, PyObject *Py_UNUSED(ignored)) { @@ -41,10 +39,6 @@ PyDoc_STRVAR(_io_FileIO___init____doc__, "*opener* must return an open file descriptor (passing os.open as *opener*\n" "results in functionality similar to passing None)."); -static int -_io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode, - int closefd, PyObject *opener); - static int _io_FileIO___init__(PyObject *self, PyObject *args, PyObject *kwargs) { diff --git a/third_party/python/Modules/_io/clinic/iobase.inc b/third_party/python/Modules/_io/clinic/iobase.inc index edbf73a40..1123041aa 100644 --- a/third_party/python/Modules/_io/clinic/iobase.inc +++ b/third_party/python/Modules/_io/clinic/iobase.inc @@ -1,3 +1,4 @@ +/* clang-format off */ /*[clinic input] preserve [clinic start generated code]*/ @@ -11,9 +12,6 @@ PyDoc_STRVAR(_io__IOBase_tell__doc__, #define _IO__IOBASE_TELL_METHODDEF \ {"tell", (PyCFunction)_io__IOBase_tell, METH_NOARGS, _io__IOBase_tell__doc__}, -static PyObject * -_io__IOBase_tell_impl(PyObject *self); - static PyObject * _io__IOBase_tell(PyObject *self, PyObject *Py_UNUSED(ignored)) { @@ -31,9 +29,6 @@ PyDoc_STRVAR(_io__IOBase_flush__doc__, #define _IO__IOBASE_FLUSH_METHODDEF \ {"flush", (PyCFunction)_io__IOBase_flush, METH_NOARGS, _io__IOBase_flush__doc__}, -static PyObject * -_io__IOBase_flush_impl(PyObject *self); - static PyObject * _io__IOBase_flush(PyObject *self, PyObject *Py_UNUSED(ignored)) { @@ -51,9 +46,6 @@ PyDoc_STRVAR(_io__IOBase_close__doc__, #define _IO__IOBASE_CLOSE_METHODDEF \ {"close", (PyCFunction)_io__IOBase_close, METH_NOARGS, _io__IOBase_close__doc__}, -static PyObject * -_io__IOBase_close_impl(PyObject *self); - static PyObject * _io__IOBase_close(PyObject *self, PyObject *Py_UNUSED(ignored)) { @@ -72,9 +64,6 @@ PyDoc_STRVAR(_io__IOBase_seekable__doc__, #define _IO__IOBASE_SEEKABLE_METHODDEF \ {"seekable", (PyCFunction)_io__IOBase_seekable, METH_NOARGS, _io__IOBase_seekable__doc__}, -static PyObject * -_io__IOBase_seekable_impl(PyObject *self); - static PyObject * _io__IOBase_seekable(PyObject *self, PyObject *Py_UNUSED(ignored)) { @@ -92,9 +81,6 @@ PyDoc_STRVAR(_io__IOBase_readable__doc__, #define _IO__IOBASE_READABLE_METHODDEF \ {"readable", (PyCFunction)_io__IOBase_readable, METH_NOARGS, _io__IOBase_readable__doc__}, -static PyObject * -_io__IOBase_readable_impl(PyObject *self); - static PyObject * _io__IOBase_readable(PyObject *self, PyObject *Py_UNUSED(ignored)) { @@ -112,9 +98,6 @@ PyDoc_STRVAR(_io__IOBase_writable__doc__, #define _IO__IOBASE_WRITABLE_METHODDEF \ {"writable", (PyCFunction)_io__IOBase_writable, METH_NOARGS, _io__IOBase_writable__doc__}, -static PyObject * -_io__IOBase_writable_impl(PyObject *self); - static PyObject * _io__IOBase_writable(PyObject *self, PyObject *Py_UNUSED(ignored)) { @@ -132,9 +115,6 @@ PyDoc_STRVAR(_io__IOBase_fileno__doc__, #define _IO__IOBASE_FILENO_METHODDEF \ {"fileno", (PyCFunction)_io__IOBase_fileno, METH_NOARGS, _io__IOBase_fileno__doc__}, -static PyObject * -_io__IOBase_fileno_impl(PyObject *self); - static PyObject * _io__IOBase_fileno(PyObject *self, PyObject *Py_UNUSED(ignored)) { @@ -152,9 +132,6 @@ PyDoc_STRVAR(_io__IOBase_isatty__doc__, #define _IO__IOBASE_ISATTY_METHODDEF \ {"isatty", (PyCFunction)_io__IOBase_isatty, METH_NOARGS, _io__IOBase_isatty__doc__}, -static PyObject * -_io__IOBase_isatty_impl(PyObject *self); - static PyObject * _io__IOBase_isatty(PyObject *self, PyObject *Py_UNUSED(ignored)) { @@ -176,9 +153,6 @@ PyDoc_STRVAR(_io__IOBase_readline__doc__, #define _IO__IOBASE_READLINE_METHODDEF \ {"readline", (PyCFunction)_io__IOBase_readline, METH_VARARGS, _io__IOBase_readline__doc__}, -static PyObject * -_io__IOBase_readline_impl(PyObject *self, Py_ssize_t limit); - static PyObject * _io__IOBase_readline(PyObject *self, PyObject *args) { @@ -208,9 +182,6 @@ PyDoc_STRVAR(_io__IOBase_readlines__doc__, #define _IO__IOBASE_READLINES_METHODDEF \ {"readlines", (PyCFunction)_io__IOBase_readlines, METH_VARARGS, _io__IOBase_readlines__doc__}, -static PyObject * -_io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint); - static PyObject * _io__IOBase_readlines(PyObject *self, PyObject *args) { diff --git a/third_party/python/Modules/_io/clinic/stringio.inc b/third_party/python/Modules/_io/clinic/stringio.inc index d2c05d7cb..54d623638 100644 --- a/third_party/python/Modules/_io/clinic/stringio.inc +++ b/third_party/python/Modules/_io/clinic/stringio.inc @@ -1,3 +1,4 @@ +/* clang-format off */ /*[clinic input] preserve [clinic start generated code]*/ @@ -11,9 +12,6 @@ PyDoc_STRVAR(_io_StringIO_getvalue__doc__, #define _IO_STRINGIO_GETVALUE_METHODDEF \ {"getvalue", (PyCFunction)_io_StringIO_getvalue, METH_NOARGS, _io_StringIO_getvalue__doc__}, -static PyObject * -_io_StringIO_getvalue_impl(stringio *self); - static PyObject * _io_StringIO_getvalue(stringio *self, PyObject *Py_UNUSED(ignored)) { diff --git a/third_party/python/Modules/_io/clinic/textio.inc b/third_party/python/Modules/_io/clinic/textio.inc index f39c35581..d847d8987 100644 --- a/third_party/python/Modules/_io/clinic/textio.inc +++ b/third_party/python/Modules/_io/clinic/textio.inc @@ -1,3 +1,10 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Python 3 │ +│ https://docs.python.org/3/license.html │ +╚─────────────────────────────────────────────────────────────────────────────*/ +/* clang-format off */ /*[clinic input] preserve [clinic start generated code]*/ diff --git a/third_party/python/Modules/_io/clinic/winconsoleio.inc b/third_party/python/Modules/_io/clinic/winconsoleio.inc index e44fcbb7a..842ee272c 100644 --- a/third_party/python/Modules/_io/clinic/winconsoleio.inc +++ b/third_party/python/Modules/_io/clinic/winconsoleio.inc @@ -1,3 +1,4 @@ +/* clang-format off */ /*[clinic input] preserve [clinic start generated code]*/ diff --git a/third_party/python/Modules/_io/fileio.c b/third_party/python/Modules/_io/fileio.c index fa069681a..af980368b 100644 --- a/third_party/python/Modules/_io/fileio.c +++ b/third_party/python/Modules/_io/fileio.c @@ -1,12 +1,27 @@ -/* clang-format off */ -/* Author: Daniel Stutzbach */ - #define PY_SSIZE_T_CLEAN -#include "third_party/python/Include/Python.h" +#include "libc/calls/calls.h" +#include "libc/errno.h" +#include "libc/sysv/consts/o.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" #include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/warnings.h" #include "third_party/python/Modules/_io/_iomodule.h" +/* clang-format off */ /* + * Author: Daniel Stutzbach + * * Known likely problems: * * - Files larger then 2**32-1 @@ -96,8 +111,6 @@ fileio_dealloc_warn(fileio *self, PyObject *source) static PyObject * portable_lseek(int fd, PyObject *posobj, int whence); -static PyObject *portable_lseek(int fd, PyObject *posobj, int whence); - /* Returns 0 on success, -1 with exception set on failure. */ static int internal_close(fileio *self) diff --git a/third_party/python/Modules/_io/iobase.c b/third_party/python/Modules/_io/iobase.c index 08dfb2890..9e3a45251 100644 --- a/third_party/python/Modules/_io/iobase.c +++ b/third_party/python/Modules/_io/iobase.c @@ -1,4 +1,19 @@ +#define PY_SSIZE_T_CLEAN +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/bytearrayobject.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Modules/_io/_iomodule.h" /* clang-format off */ + /* An implementation of the I/O abstract base classes hierarchy as defined by PEP 3116 - "New I/O" @@ -8,12 +23,6 @@ Written by Amaury Forgeot d'Arc and Antoine Pitrou */ - -#define PY_SSIZE_T_CLEAN -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" -#include "third_party/python/Modules/_io/_iomodule.h" - /*[clinic input] module _io class _io._IOBase "PyObject *" "&PyIOBase_Type" diff --git a/third_party/python/Modules/_io/stringio.c b/third_party/python/Modules/_io/stringio.c index 3e8d65ee3..780774ea0 100644 --- a/third_party/python/Modules/_io/stringio.c +++ b/third_party/python/Modules/_io/stringio.c @@ -1,9 +1,19 @@ -/* clang-format off */ #define PY_SSIZE_T_CLEAN -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/abstract.h" #include "third_party/python/Include/accu.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/unicodeobject.h" #include "third_party/python/Modules/_io/_iomodule.h" +/* clang-format off */ /* Implementation note: the buffer is always at least one character longer than the enclosed string, for proper functioning of _PyIO_find_line_ending. diff --git a/third_party/python/Modules/_io/textio.c b/third_party/python/Modules/_io/textio.c index 44579c672..eff6490a9 100644 --- a/third_party/python/Modules/_io/textio.c +++ b/third_party/python/Modules/_io/textio.c @@ -1,4 +1,22 @@ +#define PY_SSIZE_T_CLEAN +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/codecs.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/tupleobject.h" +#include "third_party/python/Modules/_io/_iomodule.h" /* clang-format off */ + /* An implementation of Text I/O as defined by PEP 3116 - "New I/O" @@ -7,11 +25,6 @@ Written by Amaury Forgeot d'Arc and Antoine Pitrou */ -#define PY_SSIZE_T_CLEAN -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" -#include "third_party/python/Modules/_io/_iomodule.h" - /*[clinic input] module _io class _io.IncrementalNewlineDecoder "nldecoder_object *" "&PyIncrementalNewlineDecoder_Type" diff --git a/third_party/python/Modules/_io/winconsoleio.c b/third_party/python/Modules/_io/winconsoleio.c index 9c044d79b..84dd7423f 100644 --- a/third_party/python/Modules/_io/winconsoleio.c +++ b/third_party/python/Modules/_io/winconsoleio.c @@ -1,4 +1,7 @@ +#define PY_SSIZE_T_CLEAN +#include "third_party/python/Modules/_io/_iomodule.h" /* clang-format off */ + /* An implementation of Windows console I/O @@ -7,10 +10,6 @@ Written by Steve Dower */ -#define PY_SSIZE_T_CLEAN -#include "Python.h" -#include "third_party/python/Modules/_io/_iomodule.h" - /* BUFSIZ determines how many characters can be typed at the console before it starts blocking. */ #if BUFSIZ < (16*1024) @@ -399,7 +398,7 @@ _io__WindowsConsoleIO___init___impl(winconsoleio *self, PyObject *nameobj, } self->blksize = DEFAULT_BUFFER_SIZE; - memset(self->buf, 0, 4); + bzero(self->buf, 4); if (_PyObject_SetAttrId((PyObject *)self, &PyId_name, nameobj) < 0) goto error; @@ -1072,7 +1071,7 @@ winconsoleio_getstate(winconsoleio *self) return NULL; } -#include "clinic/winconsoleio.c.h" +#include "third_party/python/Modules/_io/clinic/winconsoleio.inc" static PyMethodDef winconsoleio_methods[] = { _IO__WINDOWSCONSOLEIO_READ_METHODDEF diff --git a/third_party/python/Modules/_json.c b/third_party/python/Modules/_json.c index 328d5140c..e5500ed72 100644 --- a/third_party/python/Modules/_json.c +++ b/third_party/python/Modules/_json.c @@ -1,7 +1,23 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/abstract.h" #include "third_party/python/Include/accu.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/codecs.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/methodobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymath.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/tupleobject.h" +#include "third_party/python/Include/unicodeobject.h" +/* clang-format off */ #ifdef __GNUC__ #define UNUSED __attribute__((__unused__)) diff --git a/third_party/python/Modules/_localemodule.c b/third_party/python/Modules/_localemodule.c index 6a3812768..960387dd4 100644 --- a/third_party/python/Modules/_localemodule.c +++ b/third_party/python/Modules/_localemodule.c @@ -1,4 +1,17 @@ +#define PY_SSIZE_T_CLEAN +#include "libc/unicode/locale.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/unicodeobject.h" /* clang-format off */ + /*********************************************************** Copyright (C) 1997, 2002, 2003, 2007, 2008 Martin von Loewis @@ -10,10 +23,6 @@ This software comes with no warranty. Use at your own risk. ******************************************************************/ -#define PY_SSIZE_T_CLEAN -#include "third_party/python/Include/Python.h" -#include "libc/unicode/locale.h" - PyDoc_STRVAR(locale__doc__, "Support for POSIX locales."); static PyObject *Error; diff --git a/third_party/python/Modules/_lsprof.c b/third_party/python/Modules/_lsprof.c index 09fa16ec5..c9651c660 100644 --- a/third_party/python/Modules/_lsprof.c +++ b/third_party/python/Modules/_lsprof.c @@ -1,10 +1,20 @@ #include "libc/time/struct/tm.h" #include "libc/time/time.h" -/* clang-format off */ - -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/floatobject.h" #include "third_party/python/Include/frameobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/structseq.h" +#include "third_party/python/Include/unicodeobject.h" #include "third_party/python/Modules/rotatingtree.h" +/* clang-format off */ /*** Selection of a high-precision timer ***/ diff --git a/third_party/python/Modules/_lzmamodule.c b/third_party/python/Modules/_lzmamodule.c index 8d56c6421..b18aa95d6 100644 --- a/third_party/python/Modules/_lzmamodule.c +++ b/third_party/python/Modules/_lzmamodule.c @@ -1,4 +1,7 @@ +#define PY_SSIZE_T_CLEAN +#include "third_party/python/Include/structmember.h" /* clang-format off */ + /* _lzma - Low-level Python interface to liblzma. Initial implementation by Per Øyvind Karlsen. @@ -6,19 +9,10 @@ */ -#define PY_SSIZE_T_CLEAN - -#include "Python.h" -#include "structmember.h" #ifdef WITH_THREAD -#include "pythread.h" +#include "third_party/python/Include/pythread.h" #endif -#include -#include - -#include - #ifdef WITH_THREAD #define ACQUIRE_LOCK(obj) do { \ if (!PyThread_acquire_lock((obj)->lock, 0)) { \ @@ -227,7 +221,7 @@ parse_filter_spec_lzma(PyObject *spec) options = (lzma_options_lzma *)PyMem_Malloc(sizeof *options); if (options == NULL) return PyErr_NoMemory(); - memset(options, 0, sizeof *options); + bzero(options, sizeof *options); if (lzma_lzma_preset(options, preset)) { PyMem_Free(options); @@ -272,7 +266,7 @@ parse_filter_spec_delta(PyObject *spec) options = (lzma_options_delta *)PyMem_Malloc(sizeof *options); if (options == NULL) return PyErr_NoMemory(); - memset(options, 0, sizeof *options); + bzero(options, sizeof *options); options->type = LZMA_DELTA_TYPE_BYTE; options->dist = dist; return options; @@ -296,7 +290,7 @@ parse_filter_spec_bcj(PyObject *spec) options = (lzma_options_bcj *)PyMem_Malloc(sizeof *options); if (options == NULL) return PyErr_NoMemory(); - memset(options, 0, sizeof *options); + bzero(options, sizeof *options); options->start_offset = start_offset; return options; } diff --git a/third_party/python/Modules/_math.c b/third_party/python/Modules/_math.c index c318c61fe..81443c0da 100644 --- a/third_party/python/Modules/_math.c +++ b/third_party/python/Modules/_math.c @@ -1,10 +1,12 @@ +#include "libc/errno.h" +#include "third_party/python/Include/pymath.h" +#include "third_party/python/Modules/_math.h" +#include "third_party/python/pyconfig.h" /* clang-format off */ + /* Definitions of some C99 math library functions, for those platforms that don't implement these functions already. */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Modules/_math.h" - /* The following copyright notice applies to the original implementations of acosh, asinh and atanh. */ diff --git a/third_party/python/Modules/_math.h b/third_party/python/Modules/_math.h index 58f3b6520..679bbd789 100644 --- a/third_party/python/Modules/_math.h +++ b/third_party/python/Modules/_math.h @@ -3,11 +3,11 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -double _Py_acosh(double x); -double _Py_asinh(double x); -double _Py_atanh(double x); -double _Py_expm1(double x); -double _Py_log1p(double x); +double _Py_acosh(double); +double _Py_asinh(double); +double _Py_atanh(double); +double _Py_expm1(double); +double _Py_log1p(double); #ifdef HAVE_ACOSH #define m_acosh acosh diff --git a/third_party/python/Modules/_multiprocessing/multiprocessing.c b/third_party/python/Modules/_multiprocessing/multiprocessing.c index 90b8e8c3f..104654202 100644 --- a/third_party/python/Modules/_multiprocessing/multiprocessing.c +++ b/third_party/python/Modules/_multiprocessing/multiprocessing.c @@ -1,3 +1,4 @@ +#include "third_party/python/Modules/_multiprocessing/multiprocessing.h" /* clang-format off */ /* * Extension module used by multiprocessing package @@ -8,9 +9,6 @@ * Licensed to PSF under a Contributor Agreement. */ -#include "multiprocessing.h" - - /* * Function which raises exceptions based on error codes */ diff --git a/third_party/python/Modules/_multiprocessing/multiprocessing.h b/third_party/python/Modules/_multiprocessing/multiprocessing.h index 407005985..ee480445c 100644 --- a/third_party/python/Modules/_multiprocessing/multiprocessing.h +++ b/third_party/python/Modules/_multiprocessing/multiprocessing.h @@ -1,42 +1,25 @@ #ifndef MULTIPROCESSING_H #define MULTIPROCESSING_H -/* clang-format off */ - #define PY_SSIZE_T_CLEAN - -#include "Python.h" -#include "structmember.h" -#include "pythread.h" +#include "third_party/python/Include/pythread.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/pyconfig.h" +/* clang-format off */ /* * Platform includes and definitions */ - -#ifdef MS_WINDOWS -# define WIN32_LEAN_AND_MEAN -# include -# include -# include /* getpid() */ -# ifdef Py_DEBUG -# include -# endif -# define SEM_HANDLE HANDLE -# define SEM_VALUE_MAX LONG_MAX -#else -# include /* O_CREAT and O_EXCL */ -# if defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED) -# include - typedef sem_t *SEM_HANDLE; -# endif -# define HANDLE int -# define SOCKET int -# define BOOL int -# define UINT32 uint32_t -# define INT32 int32_t -# define TRUE 1 -# define FALSE 0 -# define INVALID_HANDLE_VALUE (-1) +#if defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED) +typedef sem_t *SEM_HANDLE; #endif +#define HANDLE int +#define SOCKET int +#define BOOL int +#define UINT32 uint32_t +#define INT32 int32_t +#define TRUE 1 +#define FALSE 0 +#define INVALID_HANDLE_VALUE (-1) /* * Issue 3110 - Solaris does not define SEM_VALUE_MAX diff --git a/third_party/python/Modules/_multiprocessing/semaphore.c b/third_party/python/Modules/_multiprocessing/semaphore.c index 4ff454f98..5414088d0 100644 --- a/third_party/python/Modules/_multiprocessing/semaphore.c +++ b/third_party/python/Modules/_multiprocessing/semaphore.c @@ -1,3 +1,5 @@ +#include "third_party/python/Modules/_multiprocessing/multiprocessing.h" +/* clang-format off */ /* * A type which wraps a semaphore * @@ -7,8 +9,6 @@ * Licensed to PSF under a Contributor Agreement. */ -#include "multiprocessing.h" - enum { RECURSIVE_MUTEX, SEMAPHORE }; typedef struct { diff --git a/third_party/python/Modules/_opcode.c b/third_party/python/Modules/_opcode.c index cf153f13e..8788d3370 100644 --- a/third_party/python/Modules/_opcode.c +++ b/third_party/python/Modules/_opcode.c @@ -1,6 +1,11 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/compile.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" #include "third_party/python/Include/opcode.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +/* clang-format off */ /*[clinic input] module _opcode diff --git a/third_party/python/Modules/_operator.c b/third_party/python/Modules/_operator.c index 3207175a2..59f932247 100644 --- a/third_party/python/Modules/_operator.c +++ b/third_party/python/Modules/_operator.c @@ -1,7 +1,15 @@ +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" /* clang-format off */ -#include "third_party/python/Include/Python.h" - PyDoc_STRVAR(operator_doc, "Operator interface.\n\ \n\ diff --git a/third_party/python/Modules/_pickle.c b/third_party/python/Modules/_pickle.c index 0daa343fc..793142c3f 100644 --- a/third_party/python/Modules/_pickle.c +++ b/third_party/python/Modules/_pickle.c @@ -1,6 +1,30 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" +#include "libc/errno.h" +#include "libc/fmt/conv.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/classobject.h" +#include "third_party/python/Include/codecs.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/funcobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/moduleobject.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pystate.h" +#include "third_party/python/Include/pystrtod.h" +#include "third_party/python/Include/setobject.h" +#include "third_party/python/Include/sliceobject.h" #include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/sysmodule.h" +#include "third_party/quickjs/internal.h" +/* clang-format off */ PyDoc_STRVAR(pickle_module_doc, "Optimized C implementation for the Python pickle module."); @@ -720,7 +744,7 @@ PyMemoTable_New(void) PyErr_NoMemory(); return NULL; } - memset(memo->mt_table, 0, MT_MINSIZE * sizeof(PyMemoEntry)); + bzero(memo->mt_table, MT_MINSIZE * sizeof(PyMemoEntry)); return memo; } @@ -768,7 +792,7 @@ PyMemoTable_Clear(PyMemoTable *self) Py_XDECREF(self->mt_table[i].me_key); } self->mt_used = 0; - memset(self->mt_table, 0, self->mt_allocated * sizeof(PyMemoEntry)); + bzero(self->mt_table, self->mt_allocated * sizeof(PyMemoEntry)); return 0; } @@ -843,7 +867,7 @@ _PyMemoTable_ResizeTable(PyMemoTable *self, size_t min_size) } self->mt_allocated = new_size; self->mt_mask = new_size - 1; - memset(self->mt_table, 0, sizeof(PyMemoEntry) * new_size); + bzero(self->mt_table, sizeof(PyMemoEntry) * new_size); /* Copy entries from the old table. */ to_process = self->mt_used; @@ -1413,7 +1437,7 @@ _Unpickler_NewMemo(Py_ssize_t new_size) PyErr_NoMemory(); return NULL; } - memset(memo, 0, new_size * sizeof(PyObject *)); + bzero(memo, new_size * sizeof(PyObject *)); return memo; } @@ -1459,7 +1483,7 @@ _Unpickler_New(void) self->marks_size = 0; self->proto = 0; self->fix_imports = 0; - memset(&self->buffer, 0, sizeof(Py_buffer)); + bzero(&self->buffer, sizeof(Py_buffer)); self->memo_size = 32; self->memo_len = 0; self->memo = _Unpickler_NewMemo(self->memo_size); diff --git a/third_party/python/Modules/_posixsubprocess.c b/third_party/python/Modules/_posixsubprocess.c index 2763f61c9..19af5b68b 100644 --- a/third_party/python/Modules/_posixsubprocess.c +++ b/third_party/python/Modules/_posixsubprocess.c @@ -1,7 +1,23 @@ -/* clang-format off */ -/* Authors: Gregory P. Smith & Jeffrey Yasskin */ +#include "libc/calls/calls.h" +#include "libc/calls/weirdtypes.h" #include "libc/dce.h" -#include "third_party/python/Include/Python.h" +#include "libc/errno.h" +#include "libc/sysv/consts/o.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/codecs.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/intrcheck.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.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/pymacro.h" +#include "third_party/python/Include/tupleobject.h" +/* clang-format off */ + +/* Authors: Gregory P. Smith & Jeffrey Yasskin */ # define FD_DIR (IsBsd() ? "/dev/fd" : "/proc/self/fd") diff --git a/third_party/python/Modules/_randommodule.c b/third_party/python/Modules/_randommodule.c index 71f0605b9..aa43c87a2 100644 --- a/third_party/python/Modules/_randommodule.c +++ b/third_party/python/Modules/_randommodule.c @@ -1,5 +1,15 @@ +#include "libc/calls/calls.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pylifecycle.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pytime.h" +#include "third_party/python/Include/tupleobject.h" /* clang-format off */ -/* Random objects */ /* ------------------------------------------------------------------ The code in this module was based on a download from: @@ -67,8 +77,6 @@ /* ---------------------------------------------------------------*/ -#include "third_party/python/Include/Python.h" - /* Period parameters -- These are all magic. Don't change. */ #define N 624 #define M 397 diff --git a/third_party/python/Modules/_sha3.c b/third_party/python/Modules/_sha3.c new file mode 100644 index 000000000..d8cac112e --- /dev/null +++ b/third_party/python/Modules/_sha3.c @@ -0,0 +1,7970 @@ +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pystrhex.h" + +/* +Ran preprocessor on working build, because spaghetti structure of +upstream Python 3.6 source code was unnaceptably incomprehensible +TODO(jart): Find SHA3 that isn't written in a laugh out loud way! +*/ + +typedef enum { SUCCESS = 0, FAIL = 1, BAD_HASHLEN = 2 } HashReturn; + +typedef struct KeccakWidth1600_SpongeInstanceStruct { + unsigned char state[200] forcealign(8); + unsigned int rate; + unsigned int byteIOIndex; + int squeezing; +} KeccakWidth1600_SpongeInstance; + +typedef struct { + KeccakWidth1600_SpongeInstance sponge; + unsigned int fixedOutputLength; + unsigned char delimitedSuffix; +} Keccak_HashInstance; + +static const uint64_t KeccakF1600RoundConstants[24] = { + 0x0000000000000001ULL, 0x0000000000008082ULL, 0x800000000000808aULL, + 0x8000000080008000ULL, 0x000000000000808bULL, 0x0000000080000001ULL, + 0x8000000080008081ULL, 0x8000000000008009ULL, 0x000000000000008aULL, + 0x0000000000000088ULL, 0x0000000080008009ULL, 0x000000008000000aULL, + 0x000000008000808bULL, 0x800000000000008bULL, 0x8000000000008089ULL, + 0x8000000000008003ULL, 0x8000000000008002ULL, 0x8000000000000080ULL, + 0x000000000000800aULL, 0x800000008000000aULL, 0x8000000080008081ULL, + 0x8000000000008080ULL, 0x0000000080000001ULL, 0x8000000080008008ULL, +}; + +static void _PySHA3_KeccakP1600_Initialize(void *state) { + bzero(state, 200); + ((uint64_t *)state)[1] = ~(uint64_t)0; + ((uint64_t *)state)[2] = ~(uint64_t)0; + ((uint64_t *)state)[8] = ~(uint64_t)0; + ((uint64_t *)state)[12] = ~(uint64_t)0; + ((uint64_t *)state)[17] = ~(uint64_t)0; + ((uint64_t *)state)[20] = ~(uint64_t)0; +} + +static void _PySHA3_KeccakP1600_AddBytesInLane(void *state, + unsigned int lanePosition, + const unsigned char *data, + unsigned int offset, + unsigned int length) { + uint64_t lane; + if (length == 0) return; + if (length == 1) + lane = data[0]; + else { + lane = 0; + memcpy(&lane, data, length); + } + lane <<= offset * 8; + ((uint64_t *)state)[lanePosition] ^= lane; +} + +static void _PySHA3_KeccakP1600_AddLanes(void *state, const unsigned char *data, + unsigned int laneCount) { + unsigned int i = 0; + for (; (i + 8) <= laneCount; i += 8) { + ((uint64_t *)state)[i + 0] ^= ((uint64_t *)data)[i + 0]; + ((uint64_t *)state)[i + 1] ^= ((uint64_t *)data)[i + 1]; + ((uint64_t *)state)[i + 2] ^= ((uint64_t *)data)[i + 2]; + ((uint64_t *)state)[i + 3] ^= ((uint64_t *)data)[i + 3]; + ((uint64_t *)state)[i + 4] ^= ((uint64_t *)data)[i + 4]; + ((uint64_t *)state)[i + 5] ^= ((uint64_t *)data)[i + 5]; + ((uint64_t *)state)[i + 6] ^= ((uint64_t *)data)[i + 6]; + ((uint64_t *)state)[i + 7] ^= ((uint64_t *)data)[i + 7]; + } + for (; (i + 4) <= laneCount; i += 4) { + ((uint64_t *)state)[i + 0] ^= ((uint64_t *)data)[i + 0]; + ((uint64_t *)state)[i + 1] ^= ((uint64_t *)data)[i + 1]; + ((uint64_t *)state)[i + 2] ^= ((uint64_t *)data)[i + 2]; + ((uint64_t *)state)[i + 3] ^= ((uint64_t *)data)[i + 3]; + } + for (; (i + 2) <= laneCount; i += 2) { + ((uint64_t *)state)[i + 0] ^= ((uint64_t *)data)[i + 0]; + ((uint64_t *)state)[i + 1] ^= ((uint64_t *)data)[i + 1]; + } + if (i < laneCount) { + ((uint64_t *)state)[i + 0] ^= ((uint64_t *)data)[i + 0]; + } +} + +static void _PySHA3_KeccakP1600_AddBytes(void *state, const unsigned char *data, + unsigned int offset, + unsigned int length) { + if ((offset) == 0) { + _PySHA3_KeccakP1600_AddLanes(state, data, (length) / 8); + _PySHA3_KeccakP1600_AddBytesInLane( + state, (length) / 8, (data) + ((length) / 8) * 8, 0, (length) % 8); + } else { + unsigned int _sizeLeft = (length); + unsigned int _lanePosition = (offset) / 8; + unsigned int _offsetInLane = (offset) % 8; + const unsigned char *_curData = (data); + while (_sizeLeft > 0) { + unsigned int _bytesInLane = 8 - _offsetInLane; + if (_bytesInLane > _sizeLeft) _bytesInLane = _sizeLeft; + _PySHA3_KeccakP1600_AddBytesInLane(state, _lanePosition, _curData, + _offsetInLane, _bytesInLane); + _sizeLeft -= _bytesInLane; + _lanePosition++; + _offsetInLane = 0; + _curData += _bytesInLane; + } + } +} + +static void _PySHA3_KeccakP1600_OverwriteBytesInLane(void *state, + unsigned int lanePosition, + const unsigned char *data, + unsigned int offset, + unsigned int length) { + if ((lanePosition == 1) || (lanePosition == 2) || (lanePosition == 8) || + (lanePosition == 12) || (lanePosition == 17) || (lanePosition == 20)) { + unsigned int i; + for (i = 0; i < length; i++) + ((unsigned char *)state)[lanePosition * 8 + offset + i] = ~data[i]; + } else { + memcpy((unsigned char *)state + lanePosition * 8 + offset, data, length); + } +} + +static void _PySHA3_KeccakP1600_OverwriteLanes(void *state, + const unsigned char *data, + unsigned int laneCount) { + unsigned int lanePosition; + for (lanePosition = 0; lanePosition < laneCount; lanePosition++) + if ((lanePosition == 1) || (lanePosition == 2) || (lanePosition == 8) || + (lanePosition == 12) || (lanePosition == 17) || (lanePosition == 20)) + ((uint64_t *)state)[lanePosition] = + ~((const uint64_t *)data)[lanePosition]; + else + ((uint64_t *)state)[lanePosition] = + ((const uint64_t *)data)[lanePosition]; +} + +static void _PySHA3_KeccakP1600_OverwriteBytes(void *state, + const unsigned char *data, + unsigned int offset, + unsigned int length) { + { + if ((offset) == 0) { + _PySHA3_KeccakP1600_OverwriteLanes(state, data, (length) / 8); + _PySHA3_KeccakP1600_OverwriteBytesInLane( + state, (length) / 8, (data) + ((length) / 8) * 8, 0, (length) % 8); + } else { + unsigned int _sizeLeft = (length); + unsigned int _lanePosition = (offset) / 8; + unsigned int _offsetInLane = (offset) % 8; + const unsigned char *_curData = (data); + while (_sizeLeft > 0) { + unsigned int _bytesInLane = 8 - _offsetInLane; + if (_bytesInLane > _sizeLeft) _bytesInLane = _sizeLeft; + _PySHA3_KeccakP1600_OverwriteBytesInLane(state, _lanePosition, _curData, + _offsetInLane, _bytesInLane); + _sizeLeft -= _bytesInLane; + _lanePosition++; + _offsetInLane = 0; + _curData += _bytesInLane; + } + } + }; +} + +static void _PySHA3_KeccakP1600_OverwriteWithZeroes(void *state, + unsigned int byteCount) { + unsigned int lanePosition; + for (lanePosition = 0; lanePosition < byteCount / 8; lanePosition++) + if ((lanePosition == 1) || (lanePosition == 2) || (lanePosition == 8) || + (lanePosition == 12) || (lanePosition == 17) || (lanePosition == 20)) + ((uint64_t *)state)[lanePosition] = ~0; + else + ((uint64_t *)state)[lanePosition] = 0; + if (byteCount % 8 != 0) { + lanePosition = byteCount / 8; + if ((lanePosition == 1) || (lanePosition == 2) || (lanePosition == 8) || + (lanePosition == 12) || (lanePosition == 17) || (lanePosition == 20)) + memset((unsigned char *)state + lanePosition * 8, 0xFF, byteCount % 8); + else + bzero((unsigned char *)state + lanePosition * 8, byteCount % 8); + } +} + +static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { + uint64_t Aba, Abe, Abi, Abo, Abu; + uint64_t Aga, Age, Agi, Ago, Agu; + uint64_t Aka, Ake, Aki, Ako, Aku; + uint64_t Ama, Ame, Ami, Amo, Amu; + uint64_t Asa, Ase, Asi, Aso, Asu; + uint64_t Bba, Bbe, Bbi, Bbo, Bbu; + uint64_t Bga, Bge, Bgi, Bgo, Bgu; + uint64_t Bka, Bke, Bki, Bko, Bku; + uint64_t Bma, Bme, Bmi, Bmo, Bmu; + uint64_t Bsa, Bse, Bsi, Bso, Bsu; + uint64_t Ca, Ce, Ci, Co, Cu; + uint64_t Da, De, Di, Do, Du; + uint64_t Eba, Ebe, Ebi, Ebo, Ebu; + uint64_t Ega, Ege, Egi, Ego, Egu; + uint64_t Eka, Eke, Eki, Eko, Eku; + uint64_t Ema, Eme, Emi, Emo, Emu; + uint64_t Esa, Ese, Esi, Eso, Esu; + uint64_t *stateAsLanes = (uint64_t *)state; + Aba = stateAsLanes[0]; + Abe = stateAsLanes[1]; + Abi = stateAsLanes[2]; + Abo = stateAsLanes[3]; + Abu = stateAsLanes[4]; + Aga = stateAsLanes[5]; + Age = stateAsLanes[6]; + Agi = stateAsLanes[7]; + Ago = stateAsLanes[8]; + Agu = stateAsLanes[9]; + Aka = stateAsLanes[10]; + Ake = stateAsLanes[11]; + Aki = stateAsLanes[12]; + Ako = stateAsLanes[13]; + Aku = stateAsLanes[14]; + Ama = stateAsLanes[15]; + Ame = stateAsLanes[16]; + Ami = stateAsLanes[17]; + Amo = stateAsLanes[18]; + Amu = stateAsLanes[19]; + Asa = stateAsLanes[20]; + Ase = stateAsLanes[21]; + Asi = stateAsLanes[22]; + Aso = stateAsLanes[23]; + Asu = stateAsLanes[24]; + Ca = Aba ^ Aga ^ Aka ^ Ama ^ Asa; + Ce = Abe ^ Age ^ Ake ^ Ame ^ Ase; + Ci = Abi ^ Agi ^ Aki ^ Ami ^ Asi; + Co = Abo ^ Ago ^ Ako ^ Amo ^ Aso; + Cu = Abu ^ Agu ^ Aku ^ Amu ^ Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[0]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[1]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[2]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[3]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[4]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[5]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[6]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[7]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[8]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[9]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[10]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[11]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[12]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[13]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[14]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[15]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[16]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[17]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[18]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[19]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[20]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[21]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[22]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[23]; + Abe = Bbe ^ ((~Bbi) | Bbo); + Abi = Bbi ^ (Bbo & Bbu); + Abo = Bbo ^ (Bbu | Bba); + Abu = Bbu ^ (Bba & Bbe); + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Age = Bge ^ (Bgi & Bgo); + Agi = Bgi ^ (Bgo | (~Bgu)); + Ago = Bgo ^ (Bgu | Bga); + Agu = Bgu ^ (Bga & Bge); + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ake = Bke ^ (Bki & Bko); + Aki = Bki ^ ((~Bko) & Bku); + Ako = (~Bko) ^ (Bku | Bka); + Aku = Bku ^ (Bka & Bke); + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ame = Bme ^ (Bmi | Bmo); + Ami = Bmi ^ ((~Bmo) | Bmu); + Amo = (~Bmo) ^ (Bmu & Bma); + Amu = Bmu ^ (Bma | Bme); + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ase = (~Bse) ^ (Bsi | Bso); + Asi = Bsi ^ (Bso & Bsu); + Aso = Bso ^ (Bsu | Bsa); + Asu = Bsu ^ (Bsa & Bse); + stateAsLanes[0] = Aba; + stateAsLanes[1] = Abe; + stateAsLanes[2] = Abi; + stateAsLanes[3] = Abo; + stateAsLanes[4] = Abu; + stateAsLanes[5] = Aga; + stateAsLanes[6] = Age; + stateAsLanes[7] = Agi; + stateAsLanes[8] = Ago; + stateAsLanes[9] = Agu; + stateAsLanes[10] = Aka; + stateAsLanes[11] = Ake; + stateAsLanes[12] = Aki; + stateAsLanes[13] = Ako; + stateAsLanes[14] = Aku; + stateAsLanes[15] = Ama; + stateAsLanes[16] = Ame; + stateAsLanes[17] = Ami; + stateAsLanes[18] = Amo; + stateAsLanes[19] = Amu; + stateAsLanes[20] = Asa; + stateAsLanes[21] = Ase; + stateAsLanes[22] = Asi; + stateAsLanes[23] = Aso; + stateAsLanes[24] = Asu; +} + +static void _PySHA3_KeccakP1600_Permute_12rounds(void *state) { + uint64_t Aba, Abe, Abi, Abo, Abu; + uint64_t Aga, Age, Agi, Ago, Agu; + uint64_t Aka, Ake, Aki, Ako, Aku; + uint64_t Ama, Ame, Ami, Amo, Amu; + uint64_t Asa, Ase, Asi, Aso, Asu; + uint64_t Bba, Bbe, Bbi, Bbo, Bbu; + uint64_t Bga, Bge, Bgi, Bgo, Bgu; + uint64_t Bka, Bke, Bki, Bko, Bku; + uint64_t Bma, Bme, Bmi, Bmo, Bmu; + uint64_t Bsa, Bse, Bsi, Bso, Bsu; + uint64_t Ca, Ce, Ci, Co, Cu; + uint64_t Da, De, Di, Do, Du; + uint64_t Eba, Ebe, Ebi, Ebo, Ebu; + uint64_t Ega, Ege, Egi, Ego, Egu; + uint64_t Eka, Eke, Eki, Eko, Eku; + uint64_t Ema, Eme, Emi, Emo, Emu; + uint64_t Esa, Ese, Esi, Eso, Esu; + uint64_t *stateAsLanes = (uint64_t *)state; + Aba = stateAsLanes[0]; + Abe = stateAsLanes[1]; + Abi = stateAsLanes[2]; + Abo = stateAsLanes[3]; + Abu = stateAsLanes[4]; + Aga = stateAsLanes[5]; + Age = stateAsLanes[6]; + Agi = stateAsLanes[7]; + Ago = stateAsLanes[8]; + Agu = stateAsLanes[9]; + Aka = stateAsLanes[10]; + Ake = stateAsLanes[11]; + Aki = stateAsLanes[12]; + Ako = stateAsLanes[13]; + Aku = stateAsLanes[14]; + Ama = stateAsLanes[15]; + Ame = stateAsLanes[16]; + Ami = stateAsLanes[17]; + Amo = stateAsLanes[18]; + Amu = stateAsLanes[19]; + Asa = stateAsLanes[20]; + Ase = stateAsLanes[21]; + Asi = stateAsLanes[22]; + Aso = stateAsLanes[23]; + Asu = stateAsLanes[24]; + Ca = Aba ^ Aga ^ Aka ^ Ama ^ Asa; + Ce = Abe ^ Age ^ Ake ^ Ame ^ Ase; + Ci = Abi ^ Agi ^ Aki ^ Ami ^ Asi; + Co = Abo ^ Ago ^ Ako ^ Amo ^ Aso; + Cu = Abu ^ Agu ^ Aku ^ Amu ^ Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[12]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[13]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[14]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[15]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[16]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[17]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[18]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[19]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[20]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[21]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[22]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[23]; + Abe = Bbe ^ ((~Bbi) | Bbo); + Abi = Bbi ^ (Bbo & Bbu); + Abo = Bbo ^ (Bbu | Bba); + Abu = Bbu ^ (Bba & Bbe); + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Age = Bge ^ (Bgi & Bgo); + Agi = Bgi ^ (Bgo | (~Bgu)); + Ago = Bgo ^ (Bgu | Bga); + Agu = Bgu ^ (Bga & Bge); + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ake = Bke ^ (Bki & Bko); + Aki = Bki ^ ((~Bko) & Bku); + Ako = (~Bko) ^ (Bku | Bka); + Aku = Bku ^ (Bka & Bke); + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ame = Bme ^ (Bmi | Bmo); + Ami = Bmi ^ ((~Bmo) | Bmu); + Amo = (~Bmo) ^ (Bmu & Bma); + Amu = Bmu ^ (Bma | Bme); + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ase = (~Bse) ^ (Bsi | Bso); + Asi = Bsi ^ (Bso & Bsu); + Aso = Bso ^ (Bsu | Bsa); + Asu = Bsu ^ (Bsa & Bse); + stateAsLanes[0] = Aba; + stateAsLanes[1] = Abe; + stateAsLanes[2] = Abi; + stateAsLanes[3] = Abo; + stateAsLanes[4] = Abu; + stateAsLanes[5] = Aga; + stateAsLanes[6] = Age; + stateAsLanes[7] = Agi; + stateAsLanes[8] = Ago; + stateAsLanes[9] = Agu; + stateAsLanes[10] = Aka; + stateAsLanes[11] = Ake; + stateAsLanes[12] = Aki; + stateAsLanes[13] = Ako; + stateAsLanes[14] = Aku; + stateAsLanes[15] = Ama; + stateAsLanes[16] = Ame; + stateAsLanes[17] = Ami; + stateAsLanes[18] = Amo; + stateAsLanes[19] = Amu; + stateAsLanes[20] = Asa; + stateAsLanes[21] = Ase; + stateAsLanes[22] = Asi; + stateAsLanes[23] = Aso; + stateAsLanes[24] = Asu; +} + +static void _PySHA3_KeccakP1600_ExtractBytesInLane(const void *state, + unsigned int lanePosition, + unsigned char *data, + unsigned int offset, + unsigned int length) { + uint64_t lane = ((uint64_t *)state)[lanePosition]; + if ((lanePosition == 1) || (lanePosition == 2) || (lanePosition == 8) || + (lanePosition == 12) || (lanePosition == 17) || (lanePosition == 20)) + lane = ~lane; + { + uint64_t lane1[1]; + lane1[0] = lane; + memcpy(data, (uint8_t *)lane1 + offset, length); + } +} + +static void _PySHA3_KeccakP1600_ExtractLanes(const void *state, + unsigned char *data, + unsigned int laneCount) { + memcpy(data, state, laneCount * 8); + if (laneCount > 1) { + ((uint64_t *)data)[1] = ~((uint64_t *)data)[1]; + if (laneCount > 2) { + ((uint64_t *)data)[2] = ~((uint64_t *)data)[2]; + if (laneCount > 8) { + ((uint64_t *)data)[8] = ~((uint64_t *)data)[8]; + if (laneCount > 12) { + ((uint64_t *)data)[12] = ~((uint64_t *)data)[12]; + if (laneCount > 17) { + ((uint64_t *)data)[17] = ~((uint64_t *)data)[17]; + if (laneCount > 20) { + ((uint64_t *)data)[20] = ~((uint64_t *)data)[20]; + } + } + } + } + } + } +} + +static void _PySHA3_KeccakP1600_ExtractBytes(const void *state, + unsigned char *data, + unsigned int offset, + unsigned int length) { + if ((offset) == 0) { + _PySHA3_KeccakP1600_ExtractLanes(state, data, (length) / 8); + _PySHA3_KeccakP1600_ExtractBytesInLane( + state, (length) / 8, (data) + ((length) / 8) * 8, 0, (length) % 8); + } else { + unsigned int _sizeLeft = (length); + unsigned int _lanePosition = (offset) / 8; + unsigned int _offsetInLane = (offset) % 8; + unsigned char *_curData = (data); + while (_sizeLeft > 0) { + unsigned int _bytesInLane = 8 - _offsetInLane; + if (_bytesInLane > _sizeLeft) _bytesInLane = _sizeLeft; + _PySHA3_KeccakP1600_ExtractBytesInLane(state, _lanePosition, _curData, + _offsetInLane, _bytesInLane); + _sizeLeft -= _bytesInLane; + _lanePosition++; + _offsetInLane = 0; + _curData += _bytesInLane; + } + } +} + +static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state, + unsigned int laneCount, + const unsigned char *data, + size_t dataByteLen) { + size_t originalDataByteLen = dataByteLen; + uint64_t Aba, Abe, Abi, Abo, Abu; + uint64_t Aga, Age, Agi, Ago, Agu; + uint64_t Aka, Ake, Aki, Ako, Aku; + uint64_t Ama, Ame, Ami, Amo, Amu; + uint64_t Asa, Ase, Asi, Aso, Asu; + uint64_t Bba, Bbe, Bbi, Bbo, Bbu; + uint64_t Bga, Bge, Bgi, Bgo, Bgu; + uint64_t Bka, Bke, Bki, Bko, Bku; + uint64_t Bma, Bme, Bmi, Bmo, Bmu; + uint64_t Bsa, Bse, Bsi, Bso, Bsu; + uint64_t Ca, Ce, Ci, Co, Cu; + uint64_t Da, De, Di, Do, Du; + uint64_t Eba, Ebe, Ebi, Ebo, Ebu; + uint64_t Ega, Ege, Egi, Ego, Egu; + uint64_t Eka, Eke, Eki, Eko, Eku; + uint64_t Ema, Eme, Emi, Emo, Emu; + uint64_t Esa, Ese, Esi, Eso, Esu; + uint64_t *stateAsLanes = (uint64_t *)state; + uint64_t *inDataAsLanes = (uint64_t *)data; + Aba = stateAsLanes[0]; + Abe = stateAsLanes[1]; + Abi = stateAsLanes[2]; + Abo = stateAsLanes[3]; + Abu = stateAsLanes[4]; + Aga = stateAsLanes[5]; + Age = stateAsLanes[6]; + Agi = stateAsLanes[7]; + Ago = stateAsLanes[8]; + Agu = stateAsLanes[9]; + Aka = stateAsLanes[10]; + Ake = stateAsLanes[11]; + Aki = stateAsLanes[12]; + Ako = stateAsLanes[13]; + Aku = stateAsLanes[14]; + Ama = stateAsLanes[15]; + Ame = stateAsLanes[16]; + Ami = stateAsLanes[17]; + Amo = stateAsLanes[18]; + Amu = stateAsLanes[19]; + Asa = stateAsLanes[20]; + Ase = stateAsLanes[21]; + Asi = stateAsLanes[22]; + Aso = stateAsLanes[23]; + Asu = stateAsLanes[24]; + while (dataByteLen >= laneCount * 8) { + if (laneCount == 21) { + Aba ^= inDataAsLanes[0]; + Abe ^= inDataAsLanes[1]; + Abi ^= inDataAsLanes[2]; + Abo ^= inDataAsLanes[3]; + Abu ^= inDataAsLanes[4]; + Aga ^= inDataAsLanes[5]; + Age ^= inDataAsLanes[6]; + Agi ^= inDataAsLanes[7]; + Ago ^= inDataAsLanes[8]; + Agu ^= inDataAsLanes[9]; + Aka ^= inDataAsLanes[10]; + Ake ^= inDataAsLanes[11]; + Aki ^= inDataAsLanes[12]; + Ako ^= inDataAsLanes[13]; + Aku ^= inDataAsLanes[14]; + Ama ^= inDataAsLanes[15]; + Ame ^= inDataAsLanes[16]; + Ami ^= inDataAsLanes[17]; + Amo ^= inDataAsLanes[18]; + Amu ^= inDataAsLanes[19]; + Asa ^= inDataAsLanes[20]; + } else if (laneCount < 16) { + if (laneCount < 8) { + if (laneCount < 4) { + if (laneCount < 2) { + if (laneCount < 1) { + } else { + Aba ^= inDataAsLanes[0]; + } + } else { + Aba ^= inDataAsLanes[0]; + Abe ^= inDataAsLanes[1]; + if (laneCount < 3) { + } else { + Abi ^= inDataAsLanes[2]; + } + } + } else { + Aba ^= inDataAsLanes[0]; + Abe ^= inDataAsLanes[1]; + Abi ^= inDataAsLanes[2]; + Abo ^= inDataAsLanes[3]; + if (laneCount < 6) { + if (laneCount < 5) { + } else { + Abu ^= inDataAsLanes[4]; + } + } else { + Abu ^= inDataAsLanes[4]; + Aga ^= inDataAsLanes[5]; + if (laneCount < 7) { + } else { + Age ^= inDataAsLanes[6]; + } + } + } + } else { + Aba ^= inDataAsLanes[0]; + Abe ^= inDataAsLanes[1]; + Abi ^= inDataAsLanes[2]; + Abo ^= inDataAsLanes[3]; + Abu ^= inDataAsLanes[4]; + Aga ^= inDataAsLanes[5]; + Age ^= inDataAsLanes[6]; + Agi ^= inDataAsLanes[7]; + if (laneCount < 12) { + if (laneCount < 10) { + if (laneCount < 9) { + } else { + Ago ^= inDataAsLanes[8]; + } + } else { + Ago ^= inDataAsLanes[8]; + Agu ^= inDataAsLanes[9]; + if (laneCount < 11) { + } else { + Aka ^= inDataAsLanes[10]; + } + } + } else { + Ago ^= inDataAsLanes[8]; + Agu ^= inDataAsLanes[9]; + Aka ^= inDataAsLanes[10]; + Ake ^= inDataAsLanes[11]; + if (laneCount < 14) { + if (laneCount < 13) { + } else { + Aki ^= inDataAsLanes[12]; + } + } else { + Aki ^= inDataAsLanes[12]; + Ako ^= inDataAsLanes[13]; + if (laneCount < 15) { + } else { + Aku ^= inDataAsLanes[14]; + } + } + } + } + } else { + Aba ^= inDataAsLanes[0]; + Abe ^= inDataAsLanes[1]; + Abi ^= inDataAsLanes[2]; + Abo ^= inDataAsLanes[3]; + Abu ^= inDataAsLanes[4]; + Aga ^= inDataAsLanes[5]; + Age ^= inDataAsLanes[6]; + Agi ^= inDataAsLanes[7]; + Ago ^= inDataAsLanes[8]; + Agu ^= inDataAsLanes[9]; + Aka ^= inDataAsLanes[10]; + Ake ^= inDataAsLanes[11]; + Aki ^= inDataAsLanes[12]; + Ako ^= inDataAsLanes[13]; + Aku ^= inDataAsLanes[14]; + Ama ^= inDataAsLanes[15]; + if (laneCount < 24) { + if (laneCount < 20) { + if (laneCount < 18) { + if (laneCount < 17) { + } else { + Ame ^= inDataAsLanes[16]; + } + } else { + Ame ^= inDataAsLanes[16]; + Ami ^= inDataAsLanes[17]; + if (laneCount < 19) { + } else { + Amo ^= inDataAsLanes[18]; + } + } + } else { + Ame ^= inDataAsLanes[16]; + Ami ^= inDataAsLanes[17]; + Amo ^= inDataAsLanes[18]; + Amu ^= inDataAsLanes[19]; + if (laneCount < 22) { + if (laneCount < 21) { + } else { + Asa ^= inDataAsLanes[20]; + } + } else { + Asa ^= inDataAsLanes[20]; + Ase ^= inDataAsLanes[21]; + if (laneCount < 23) { + } else { + Asi ^= inDataAsLanes[22]; + } + } + } + } else { + Ame ^= inDataAsLanes[16]; + Ami ^= inDataAsLanes[17]; + Amo ^= inDataAsLanes[18]; + Amu ^= inDataAsLanes[19]; + Asa ^= inDataAsLanes[20]; + Ase ^= inDataAsLanes[21]; + Asi ^= inDataAsLanes[22]; + Aso ^= inDataAsLanes[23]; + if (laneCount < 25) { + } else { + Asu ^= inDataAsLanes[24]; + } + } + } + Ca = Aba ^ Aga ^ Aka ^ Ama ^ Asa; + Ce = Abe ^ Age ^ Ake ^ Ame ^ Ase; + Ci = Abi ^ Agi ^ Aki ^ Ami ^ Asi; + Co = Abo ^ Ago ^ Ako ^ Amo ^ Aso; + Cu = Abu ^ Agu ^ Aku ^ Amu ^ Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[0]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[1]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[2]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[3]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[4]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[5]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[6]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[7]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[8]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[9]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[10]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[11]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[12]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[13]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[14]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[15]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[16]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[17]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[18]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[19]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[20]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[21]; + Ca = Aba; + Abe = Bbe ^ ((~Bbi) | Bbo); + Ce = Abe; + Abi = Bbi ^ (Bbo & Bbu); + Ci = Abi; + Abo = Bbo ^ (Bbu | Bba); + Co = Abo; + Abu = Bbu ^ (Bba & Bbe); + Cu = Abu; + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Ca ^= Aga; + Age = Bge ^ (Bgi & Bgo); + Ce ^= Age; + Agi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Agi; + Ago = Bgo ^ (Bgu | Bga); + Co ^= Ago; + Agu = Bgu ^ (Bga & Bge); + Cu ^= Agu; + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ca ^= Aka; + Ake = Bke ^ (Bki & Bko); + Ce ^= Ake; + Aki = Bki ^ ((~Bko) & Bku); + Ci ^= Aki; + Ako = (~Bko) ^ (Bku | Bka); + Co ^= Ako; + Aku = Bku ^ (Bka & Bke); + Cu ^= Aku; + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ca ^= Ama; + Ame = Bme ^ (Bmi | Bmo); + Ce ^= Ame; + Ami = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Ami; + Amo = (~Bmo) ^ (Bmu & Bma); + Co ^= Amo; + Amu = Bmu ^ (Bma | Bme); + Cu ^= Amu; + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Asa; + Ase = (~Bse) ^ (Bsi | Bso); + Ce ^= Ase; + Asi = Bsi ^ (Bso & Bsu); + Ci ^= Asi; + Aso = Bso ^ (Bsu | Bsa); + Co ^= Aso; + Asu = Bsu ^ (Bsa & Bse); + Cu ^= Asu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Aba ^= Da; + Bba = Aba; + Age ^= De; + Bbe = ((((uint64_t)Age) << 44) ^ (((uint64_t)Age) >> (64 - 44))); + Aki ^= Di; + Bbi = ((((uint64_t)Aki) << 43) ^ (((uint64_t)Aki) >> (64 - 43))); + Amo ^= Do; + Bbo = ((((uint64_t)Amo) << 21) ^ (((uint64_t)Amo) >> (64 - 21))); + Asu ^= Du; + Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); + Eba = Bba ^ (Bbe | Bbi); + Eba ^= KeccakF1600RoundConstants[22]; + Ca = Eba; + Ebe = Bbe ^ ((~Bbi) | Bbo); + Ce = Ebe; + Ebi = Bbi ^ (Bbo & Bbu); + Ci = Ebi; + Ebo = Bbo ^ (Bbu | Bba); + Co = Ebo; + Ebu = Bbu ^ (Bba & Bbe); + Cu = Ebu; + Abo ^= Do; + Bga = ((((uint64_t)Abo) << 28) ^ (((uint64_t)Abo) >> (64 - 28))); + Agu ^= Du; + Bge = ((((uint64_t)Agu) << 20) ^ (((uint64_t)Agu) >> (64 - 20))); + Aka ^= Da; + Bgi = ((((uint64_t)Aka) << 3) ^ (((uint64_t)Aka) >> (64 - 3))); + Ame ^= De; + Bgo = ((((uint64_t)Ame) << 45) ^ (((uint64_t)Ame) >> (64 - 45))); + Asi ^= Di; + Bgu = ((((uint64_t)Asi) << 61) ^ (((uint64_t)Asi) >> (64 - 61))); + Ega = Bga ^ (Bge | Bgi); + Ca ^= Ega; + Ege = Bge ^ (Bgi & Bgo); + Ce ^= Ege; + Egi = Bgi ^ (Bgo | (~Bgu)); + Ci ^= Egi; + Ego = Bgo ^ (Bgu | Bga); + Co ^= Ego; + Egu = Bgu ^ (Bga & Bge); + Cu ^= Egu; + Abe ^= De; + Bka = ((((uint64_t)Abe) << 1) ^ (((uint64_t)Abe) >> (64 - 1))); + Agi ^= Di; + Bke = ((((uint64_t)Agi) << 6) ^ (((uint64_t)Agi) >> (64 - 6))); + Ako ^= Do; + Bki = ((((uint64_t)Ako) << 25) ^ (((uint64_t)Ako) >> (64 - 25))); + Amu ^= Du; + Bko = ((((uint64_t)Amu) << 8) ^ (((uint64_t)Amu) >> (64 - 8))); + Asa ^= Da; + Bku = ((((uint64_t)Asa) << 18) ^ (((uint64_t)Asa) >> (64 - 18))); + Eka = Bka ^ (Bke | Bki); + Ca ^= Eka; + Eke = Bke ^ (Bki & Bko); + Ce ^= Eke; + Eki = Bki ^ ((~Bko) & Bku); + Ci ^= Eki; + Eko = (~Bko) ^ (Bku | Bka); + Co ^= Eko; + Eku = Bku ^ (Bka & Bke); + Cu ^= Eku; + Abu ^= Du; + Bma = ((((uint64_t)Abu) << 27) ^ (((uint64_t)Abu) >> (64 - 27))); + Aga ^= Da; + Bme = ((((uint64_t)Aga) << 36) ^ (((uint64_t)Aga) >> (64 - 36))); + Ake ^= De; + Bmi = ((((uint64_t)Ake) << 10) ^ (((uint64_t)Ake) >> (64 - 10))); + Ami ^= Di; + Bmo = ((((uint64_t)Ami) << 15) ^ (((uint64_t)Ami) >> (64 - 15))); + Aso ^= Do; + Bmu = ((((uint64_t)Aso) << 56) ^ (((uint64_t)Aso) >> (64 - 56))); + Ema = Bma ^ (Bme & Bmi); + Ca ^= Ema; + Eme = Bme ^ (Bmi | Bmo); + Ce ^= Eme; + Emi = Bmi ^ ((~Bmo) | Bmu); + Ci ^= Emi; + Emo = (~Bmo) ^ (Bmu & Bma); + Co ^= Emo; + Emu = Bmu ^ (Bma | Bme); + Cu ^= Emu; + Abi ^= Di; + Bsa = ((((uint64_t)Abi) << 62) ^ (((uint64_t)Abi) >> (64 - 62))); + Ago ^= Do; + Bse = ((((uint64_t)Ago) << 55) ^ (((uint64_t)Ago) >> (64 - 55))); + Aku ^= Du; + Bsi = ((((uint64_t)Aku) << 39) ^ (((uint64_t)Aku) >> (64 - 39))); + Ama ^= Da; + Bso = ((((uint64_t)Ama) << 41) ^ (((uint64_t)Ama) >> (64 - 41))); + Ase ^= De; + Bsu = ((((uint64_t)Ase) << 2) ^ (((uint64_t)Ase) >> (64 - 2))); + Esa = Bsa ^ ((~Bse) & Bsi); + Ca ^= Esa; + Ese = (~Bse) ^ (Bsi | Bso); + Ce ^= Ese; + Esi = Bsi ^ (Bso & Bsu); + Ci ^= Esi; + Eso = Bso ^ (Bsu | Bsa); + Co ^= Eso; + Esu = Bsu ^ (Bsa & Bse); + Cu ^= Esu; + Da = Cu ^ ((((uint64_t)Ce) << 1) ^ (((uint64_t)Ce) >> (64 - 1))); + De = Ca ^ ((((uint64_t)Ci) << 1) ^ (((uint64_t)Ci) >> (64 - 1))); + Di = Ce ^ ((((uint64_t)Co) << 1) ^ (((uint64_t)Co) >> (64 - 1))); + Do = Ci ^ ((((uint64_t)Cu) << 1) ^ (((uint64_t)Cu) >> (64 - 1))); + Du = Co ^ ((((uint64_t)Ca) << 1) ^ (((uint64_t)Ca) >> (64 - 1))); + Eba ^= Da; + Bba = Eba; + Ege ^= De; + Bbe = ((((uint64_t)Ege) << 44) ^ (((uint64_t)Ege) >> (64 - 44))); + Eki ^= Di; + Bbi = ((((uint64_t)Eki) << 43) ^ (((uint64_t)Eki) >> (64 - 43))); + Emo ^= Do; + Bbo = ((((uint64_t)Emo) << 21) ^ (((uint64_t)Emo) >> (64 - 21))); + Esu ^= Du; + Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); + Aba = Bba ^ (Bbe | Bbi); + Aba ^= KeccakF1600RoundConstants[23]; + Abe = Bbe ^ ((~Bbi) | Bbo); + Abi = Bbi ^ (Bbo & Bbu); + Abo = Bbo ^ (Bbu | Bba); + Abu = Bbu ^ (Bba & Bbe); + Ebo ^= Do; + Bga = ((((uint64_t)Ebo) << 28) ^ (((uint64_t)Ebo) >> (64 - 28))); + Egu ^= Du; + Bge = ((((uint64_t)Egu) << 20) ^ (((uint64_t)Egu) >> (64 - 20))); + Eka ^= Da; + Bgi = ((((uint64_t)Eka) << 3) ^ (((uint64_t)Eka) >> (64 - 3))); + Eme ^= De; + Bgo = ((((uint64_t)Eme) << 45) ^ (((uint64_t)Eme) >> (64 - 45))); + Esi ^= Di; + Bgu = ((((uint64_t)Esi) << 61) ^ (((uint64_t)Esi) >> (64 - 61))); + Aga = Bga ^ (Bge | Bgi); + Age = Bge ^ (Bgi & Bgo); + Agi = Bgi ^ (Bgo | (~Bgu)); + Ago = Bgo ^ (Bgu | Bga); + Agu = Bgu ^ (Bga & Bge); + Ebe ^= De; + Bka = ((((uint64_t)Ebe) << 1) ^ (((uint64_t)Ebe) >> (64 - 1))); + Egi ^= Di; + Bke = ((((uint64_t)Egi) << 6) ^ (((uint64_t)Egi) >> (64 - 6))); + Eko ^= Do; + Bki = ((((uint64_t)Eko) << 25) ^ (((uint64_t)Eko) >> (64 - 25))); + Emu ^= Du; + Bko = ((((uint64_t)Emu) << 8) ^ (((uint64_t)Emu) >> (64 - 8))); + Esa ^= Da; + Bku = ((((uint64_t)Esa) << 18) ^ (((uint64_t)Esa) >> (64 - 18))); + Aka = Bka ^ (Bke | Bki); + Ake = Bke ^ (Bki & Bko); + Aki = Bki ^ ((~Bko) & Bku); + Ako = (~Bko) ^ (Bku | Bka); + Aku = Bku ^ (Bka & Bke); + Ebu ^= Du; + Bma = ((((uint64_t)Ebu) << 27) ^ (((uint64_t)Ebu) >> (64 - 27))); + Ega ^= Da; + Bme = ((((uint64_t)Ega) << 36) ^ (((uint64_t)Ega) >> (64 - 36))); + Eke ^= De; + Bmi = ((((uint64_t)Eke) << 10) ^ (((uint64_t)Eke) >> (64 - 10))); + Emi ^= Di; + Bmo = ((((uint64_t)Emi) << 15) ^ (((uint64_t)Emi) >> (64 - 15))); + Eso ^= Do; + Bmu = ((((uint64_t)Eso) << 56) ^ (((uint64_t)Eso) >> (64 - 56))); + Ama = Bma ^ (Bme & Bmi); + Ame = Bme ^ (Bmi | Bmo); + Ami = Bmi ^ ((~Bmo) | Bmu); + Amo = (~Bmo) ^ (Bmu & Bma); + Amu = Bmu ^ (Bma | Bme); + Ebi ^= Di; + Bsa = ((((uint64_t)Ebi) << 62) ^ (((uint64_t)Ebi) >> (64 - 62))); + Ego ^= Do; + Bse = ((((uint64_t)Ego) << 55) ^ (((uint64_t)Ego) >> (64 - 55))); + Eku ^= Du; + Bsi = ((((uint64_t)Eku) << 39) ^ (((uint64_t)Eku) >> (64 - 39))); + Ema ^= Da; + Bso = ((((uint64_t)Ema) << 41) ^ (((uint64_t)Ema) >> (64 - 41))); + Ese ^= De; + Bsu = ((((uint64_t)Ese) << 2) ^ (((uint64_t)Ese) >> (64 - 2))); + Asa = Bsa ^ ((~Bse) & Bsi); + Ase = (~Bse) ^ (Bsi | Bso); + Asi = Bsi ^ (Bso & Bsu); + Aso = Bso ^ (Bsu | Bsa); + Asu = Bsu ^ (Bsa & Bse); + inDataAsLanes += laneCount; + dataByteLen -= laneCount * 8; + } + stateAsLanes[0] = Aba; + stateAsLanes[1] = Abe; + stateAsLanes[2] = Abi; + stateAsLanes[3] = Abo; + stateAsLanes[4] = Abu; + stateAsLanes[5] = Aga; + stateAsLanes[6] = Age; + stateAsLanes[7] = Agi; + stateAsLanes[8] = Ago; + stateAsLanes[9] = Agu; + stateAsLanes[10] = Aka; + stateAsLanes[11] = Ake; + stateAsLanes[12] = Aki; + stateAsLanes[13] = Ako; + stateAsLanes[14] = Aku; + stateAsLanes[15] = Ama; + stateAsLanes[16] = Ame; + stateAsLanes[17] = Ami; + stateAsLanes[18] = Amo; + stateAsLanes[19] = Amu; + stateAsLanes[20] = Asa; + stateAsLanes[21] = Ase; + stateAsLanes[22] = Asi; + stateAsLanes[23] = Aso; + stateAsLanes[24] = Asu; + return originalDataByteLen - dataByteLen; +} + +static int _PySHA3_KeccakWidth1600_Sponge( + unsigned int rate, unsigned int capacity, const unsigned char *input, + size_t inputByteLen, unsigned char suffix, unsigned char *output, + size_t outputByteLen) { + forcealign(8) unsigned char state[200]; + unsigned int partialBlock; + const unsigned char *curInput = input; + unsigned char *curOutput = output; + unsigned int rateInBytes = rate / 8; + if (rate + capacity != 1600) return 1; + if ((rate <= 0) || (rate > 1600) || ((rate % 8) != 0)) return 1; + if (suffix == 0) return 1; + _PySHA3_KeccakP1600_Initialize(state); + if (((rateInBytes % (1600 / 200)) == 0) && (inputByteLen >= rateInBytes)) { + size_t j; + j = _PySHA3_KeccakF1600_FastLoop_Absorb(state, rateInBytes / (1600 / 200), + curInput, inputByteLen); + curInput += j; + inputByteLen -= j; + } + while (inputByteLen >= (size_t)rateInBytes) { + _PySHA3_KeccakP1600_AddBytes(state, curInput, 0, rateInBytes); + _PySHA3_KeccakP1600_Permute_24rounds(state); + curInput += rateInBytes; + inputByteLen -= rateInBytes; + } + partialBlock = (unsigned int)inputByteLen; + _PySHA3_KeccakP1600_AddBytes(state, curInput, 0, partialBlock); + ((unsigned char *)(state))[(partialBlock)] ^= (suffix); + if ((suffix >= 0x80) && (partialBlock == (rateInBytes - 1))) + _PySHA3_KeccakP1600_Permute_24rounds(state); + ((unsigned char *)(state))[(rateInBytes - 1)] ^= (0x80); + _PySHA3_KeccakP1600_Permute_24rounds(state); + while (outputByteLen > (size_t)rateInBytes) { + _PySHA3_KeccakP1600_ExtractBytes(state, curOutput, 0, rateInBytes); + _PySHA3_KeccakP1600_Permute_24rounds(state); + curOutput += rateInBytes; + outputByteLen -= rateInBytes; + } + partialBlock = (unsigned int)outputByteLen; + _PySHA3_KeccakP1600_ExtractBytes(state, curOutput, 0, partialBlock); + return 0; +} + +static int _PySHA3_KeccakWidth1600_SpongeAbsorb( + KeccakWidth1600_SpongeInstance *instance, const unsigned char *data, + size_t dataByteLen) { + size_t i, j; + unsigned int partialBlock; + const unsigned char *curData; + unsigned int rateInBytes = instance->rate / 8; + if (instance->squeezing) return 1; + i = 0; + curData = data; + while (i < dataByteLen) { + if ((instance->byteIOIndex == 0) && (dataByteLen >= (i + rateInBytes))) { + if ((rateInBytes % (1600 / 200)) == 0) { + j = _PySHA3_KeccakF1600_FastLoop_Absorb(instance->state, + rateInBytes / (1600 / 200), + curData, dataByteLen - i); + i += j; + curData += j; + } else { + for (j = dataByteLen - i; j >= rateInBytes; j -= rateInBytes) { + _PySHA3_KeccakP1600_AddBytes(instance->state, curData, 0, + rateInBytes); + _PySHA3_KeccakP1600_Permute_24rounds(instance->state); + curData += rateInBytes; + } + i = dataByteLen - j; + } + } else { + partialBlock = (unsigned int)(dataByteLen - i); + if (partialBlock + instance->byteIOIndex > rateInBytes) + partialBlock = rateInBytes - instance->byteIOIndex; + i += partialBlock; + _PySHA3_KeccakP1600_AddBytes(instance->state, curData, + instance->byteIOIndex, partialBlock); + curData += partialBlock; + instance->byteIOIndex += partialBlock; + if (instance->byteIOIndex == rateInBytes) { + _PySHA3_KeccakP1600_Permute_24rounds(instance->state); + instance->byteIOIndex = 0; + } + } + } + return 0; +} + +static int _PySHA3_KeccakWidth1600_SpongeAbsorbLastFewBits( + KeccakWidth1600_SpongeInstance *instance, unsigned char delimitedData) { + unsigned int rateInBytes = instance->rate / 8; + if (delimitedData == 0) return 1; + if (instance->squeezing) return 1; + ((unsigned char *)(instance->state))[(instance->byteIOIndex)] ^= + (delimitedData); + if ((delimitedData >= 0x80) && (instance->byteIOIndex == (rateInBytes - 1))) + _PySHA3_KeccakP1600_Permute_24rounds(instance->state); + ((unsigned char *)(instance->state))[(rateInBytes - 1)] ^= (0x80); + _PySHA3_KeccakP1600_Permute_24rounds(instance->state); + instance->byteIOIndex = 0; + instance->squeezing = 1; + return 0; +} + +static int _PySHA3_KeccakWidth1600_SpongeSqueeze( + KeccakWidth1600_SpongeInstance *instance, unsigned char *data, + size_t dataByteLen) { + size_t i, j; + unsigned int partialBlock; + unsigned int rateInBytes = instance->rate / 8; + unsigned char *curData; + if (!instance->squeezing) + _PySHA3_KeccakWidth1600_SpongeAbsorbLastFewBits(instance, 0x01); + i = 0; + curData = data; + while (i < dataByteLen) { + if ((instance->byteIOIndex == rateInBytes) && + (dataByteLen >= (i + rateInBytes))) { + for (j = dataByteLen - i; j >= rateInBytes; j -= rateInBytes) { + _PySHA3_KeccakP1600_Permute_24rounds(instance->state); + _PySHA3_KeccakP1600_ExtractBytes(instance->state, curData, 0, + rateInBytes); + curData += rateInBytes; + } + i = dataByteLen - j; + } else { + if (instance->byteIOIndex == rateInBytes) { + _PySHA3_KeccakP1600_Permute_24rounds(instance->state); + instance->byteIOIndex = 0; + } + partialBlock = (unsigned int)(dataByteLen - i); + if (partialBlock + instance->byteIOIndex > rateInBytes) + partialBlock = rateInBytes - instance->byteIOIndex; + i += partialBlock; + _PySHA3_KeccakP1600_ExtractBytes(instance->state, curData, + instance->byteIOIndex, partialBlock); + curData += partialBlock; + instance->byteIOIndex += partialBlock; + } + } + return 0; +} + +static int _PySHA3_KeccakWidth1600_SpongeInitialize( + KeccakWidth1600_SpongeInstance *instance, unsigned int rate, + unsigned int capacity) { + if (rate + capacity != 1600) return 1; + if ((rate <= 0) || (rate > 1600) || ((rate % 8) != 0)) return 1; + _PySHA3_KeccakP1600_Initialize(instance->state); + instance->rate = rate; + instance->byteIOIndex = 0; + instance->squeezing = 0; + return 0; +} + +static HashReturn _PySHA3_Keccak_HashInitialize(Keccak_HashInstance *instance, + unsigned int rate, + unsigned int capacity, + unsigned int hashbitlen, + unsigned char delimitedSuffix) { + HashReturn result; + if (delimitedSuffix == 0) return FAIL; + result = (HashReturn)_PySHA3_KeccakWidth1600_SpongeInitialize( + &instance->sponge, rate, capacity); + if (result != SUCCESS) return result; + instance->fixedOutputLength = hashbitlen; + instance->delimitedSuffix = delimitedSuffix; + return SUCCESS; +} + +static HashReturn _PySHA3_Keccak_HashUpdate(Keccak_HashInstance *instance, + const unsigned char *data, + size_t databitlen) { + if ((databitlen % 8) == 0) + return (HashReturn)_PySHA3_KeccakWidth1600_SpongeAbsorb( + &instance->sponge, data, databitlen / 8); + else { + HashReturn ret = (HashReturn)_PySHA3_KeccakWidth1600_SpongeAbsorb( + &instance->sponge, data, databitlen / 8); + if (ret == SUCCESS) { + unsigned char lastByte = data[databitlen / 8]; + unsigned short delimitedLastBytes = + (unsigned short)((unsigned short)lastByte | + ((unsigned short)instance->delimitedSuffix + << (databitlen % 8))); + if ((delimitedLastBytes & 0xFF00) == 0x0000) { + instance->delimitedSuffix = delimitedLastBytes & 0xFF; + } else { + unsigned char oneByte[1]; + oneByte[0] = delimitedLastBytes & 0xFF; + ret = (HashReturn)_PySHA3_KeccakWidth1600_SpongeAbsorb( + &instance->sponge, oneByte, 1); + instance->delimitedSuffix = (delimitedLastBytes >> 8) & 0xFF; + } + } + return ret; + } +} + +static HashReturn _PySHA3_Keccak_HashFinal(Keccak_HashInstance *instance, + unsigned char *hashval) { + HashReturn ret = (HashReturn)_PySHA3_KeccakWidth1600_SpongeAbsorbLastFewBits( + &instance->sponge, instance->delimitedSuffix); + if (ret == SUCCESS) + return (HashReturn)_PySHA3_KeccakWidth1600_SpongeSqueeze( + &instance->sponge, hashval, instance->fixedOutputLength / 8); + else + return ret; +} + +static HashReturn _PySHA3_Keccak_HashSqueeze(Keccak_HashInstance *instance, + unsigned char *data, + size_t databitlen) { + if ((databitlen % 8) != 0) return FAIL; + return (HashReturn)_PySHA3_KeccakWidth1600_SpongeSqueeze( + &instance->sponge, data, databitlen / 8); +} + +static void _PySHA3_KeccakP1600_ExtractAndAddBytesInLane( + const void *state, unsigned int lanePosition, const unsigned char *input, + unsigned char *output, unsigned int offset, unsigned int length) { + uint64_t lane = ((uint64_t *)state)[lanePosition]; + if ((lanePosition == 1) || (lanePosition == 2) || (lanePosition == 8) || + (lanePosition == 12) || (lanePosition == 17) || (lanePosition == 20)) + lane = ~lane; + { + unsigned int i; + uint64_t lane1[1]; + lane1[0] = lane; + for (i = 0; i < length; i++) + output[i] = input[i] ^ ((uint8_t *)lane1)[offset + i]; + } +} + +static void _PySHA3_KeccakP1600_ExtractAndAddLanes(const void *state, + const unsigned char *input, + unsigned char *output, + unsigned int laneCount) { + unsigned int i; + for (i = 0; i < laneCount; i++) { + ((uint64_t *)output)[i] = + ((uint64_t *)input)[i] ^ ((const uint64_t *)state)[i]; + } + if (laneCount > 1) { + ((uint64_t *)output)[1] = ~((uint64_t *)output)[1]; + if (laneCount > 2) { + ((uint64_t *)output)[2] = ~((uint64_t *)output)[2]; + if (laneCount > 8) { + ((uint64_t *)output)[8] = ~((uint64_t *)output)[8]; + if (laneCount > 12) { + ((uint64_t *)output)[12] = ~((uint64_t *)output)[12]; + if (laneCount > 17) { + ((uint64_t *)output)[17] = ~((uint64_t *)output)[17]; + if (laneCount > 20) { + ((uint64_t *)output)[20] = ~((uint64_t *)output)[20]; + } + } + } + } + } + } +} + +static void _PySHA3_KeccakP1600_ExtractAndAddBytes(const void *state, + const unsigned char *input, + unsigned char *output, + unsigned int offset, + unsigned int length) { + if ((offset) == 0) { + _PySHA3_KeccakP1600_ExtractAndAddLanes(state, input, output, (length) / 8); + _PySHA3_KeccakP1600_ExtractAndAddBytesInLane( + state, (length) / 8, (input) + ((length) / 8) * 8, + (output) + ((length) / 8) * 8, 0, (length) % 8); + } else { + unsigned int _sizeLeft = (length); + unsigned int _lanePosition = (offset) / 8; + unsigned int _offsetInLane = (offset) % 8; + const unsigned char *_curInput = (input); + unsigned char *_curOutput = (output); + while (_sizeLeft > 0) { + unsigned int _bytesInLane = 8 - _offsetInLane; + if (_bytesInLane > _sizeLeft) _bytesInLane = _sizeLeft; + _PySHA3_KeccakP1600_ExtractAndAddBytesInLane(state, _lanePosition, + _curInput, _curOutput, + _offsetInLane, _bytesInLane); + _sizeLeft -= _bytesInLane; + _lanePosition++; + _offsetInLane = 0; + _curInput += _bytesInLane; + _curOutput += _bytesInLane; + } + } +} + +typedef struct { + PyObject ob_base; + Keccak_HashInstance hash_state; +} SHA3object; + +static PyTypeObject SHA3_224type; +static PyTypeObject SHA3_256type; +static PyTypeObject SHA3_384type; +static PyTypeObject SHA3_512type; +static PyTypeObject SHAKE128type; +static PyTypeObject SHAKE256type; + +static char _sha3_sha3_224_copy__doc__[] = "copy($self, /)\n" + "--\n" + "\n" + "Return a copy of the hash object."; + +static PyObject *_sha3_sha3_224_copy_impl(SHA3object *); + +static PyObject *_sha3_sha3_224_copy(SHA3object *self, PyObject *_unused_ignored + __attribute__((unused))) { + return _sha3_sha3_224_copy_impl(self); +} + +static char _sha3_sha3_224_digest__doc__[] = + "digest($self, /)\n" + "--\n" + "\n" + "Return the digest value as a bytes object."; + +static PyObject *_sha3_sha3_224_digest_impl(SHA3object *); + +static PyObject *_sha3_sha3_224_digest(SHA3object *self, + PyObject *_unused_ignored + __attribute__((unused))) { + return _sha3_sha3_224_digest_impl(self); +} + +static char _sha3_sha3_224_hexdigest__doc__[] = + "hexdigest($self, /)\n" + "--\n" + "\n" + "Return the digest value as a string of hexadecimal digits."; + +static PyObject *_sha3_sha3_224_hexdigest_impl(SHA3object *); + +static PyObject *_sha3_sha3_224_hexdigest(SHA3object *self, + PyObject *_unused_ignored + __attribute__((unused))) { + return _sha3_sha3_224_hexdigest_impl(self); +} + +static char _sha3_sha3_224_update__doc__[] = + "update($self, data, /)\n" + "--\n" + "\n" + "Update this hash object\'s state with the provided bytes-like object."; + +static char _sha3_shake_128_digest__doc__[] = + "digest($self, length, /)\n" + "--\n" + "\n" + "Return the digest value as a bytes object."; + +static char _sha3_shake_128_hexdigest__doc__[] = + "hexdigest($self, length, /)\n" + "--\n" + "\n" + "Return the digest value as a string of hexadecimal digits."; + +static SHA3object *newSHA3object(PyTypeObject *type) { + SHA3object *newobj; + newobj = PyObject_New(SHA3object, type); + if (!newobj) return 0; + return newobj; +} + +static PyObject *py_sha3_new(PyTypeObject *type, PyObject *args, + PyObject *kwargs) { + SHA3object *self = 0; + Py_buffer buf = {0, 0}; + HashReturn res; + PyObject *data = 0; + if (!_PyArg_NoKeywords(type->tp_name, kwargs)) { + return 0; + } + if (!PyArg_UnpackTuple(args, type->tp_name, 0, 1, &data)) { + return 0; + } + self = newSHA3object(type); + if (self == 0) { + goto error; + } + if (type == &SHA3_224type) { + res = + _PySHA3_Keccak_HashInitialize(&self->hash_state, 1152, 448, 224, 0x06); + } else if (type == &SHA3_256type) { + res = + _PySHA3_Keccak_HashInitialize(&self->hash_state, 1088, 512, 256, 0x06); + } else if (type == &SHA3_384type) { + res = _PySHA3_Keccak_HashInitialize(&self->hash_state, 832, 768, 384, 0x06); + } else if (type == &SHA3_512type) { + res = + _PySHA3_Keccak_HashInitialize(&self->hash_state, 576, 1024, 512, 0x06); + } else if (type == &SHAKE128type) { + res = _PySHA3_Keccak_HashInitialize(&self->hash_state, 1344, 256, 0, 0x1F); + } else if (type == &SHAKE256type) { + res = _PySHA3_Keccak_HashInitialize(&self->hash_state, 1088, 512, 0, 0x1F); + } else { + PyErr_BadInternalCall(); + goto error; + } + if (data) { + do { + if (((((((PyObject *)((data)))->ob_type))->tp_flags & ((1UL << 28))) != + 0)) { + PyErr_SetString(PyExc_TypeError, + "Unicode-objects must be encoded before hashing"); + goto error; + } + if (!((((data))->ob_type->tp_as_buffer != 0) && + (((data))->ob_type->tp_as_buffer->bf_getbuffer != 0))) { + PyErr_SetString(PyExc_TypeError, + "object supporting the buffer API required"); + goto error; + } + if (PyObject_GetBuffer((data), (&buf), 0) == -1) { + goto error; + } + if ((&buf)->ndim > 1) { + PyErr_SetString(PyExc_BufferError, "Buffer must be single dimension"); + PyBuffer_Release((&buf)); + goto error; + } + } while (0); + res = _PySHA3_Keccak_HashUpdate(&self->hash_state, buf.buf, buf.len * 8); + if (res != SUCCESS) { + PyErr_SetString(PyExc_RuntimeError, "internal error in SHA3 Update()"); + goto error; + } + PyBuffer_Release(&buf); + } + return (PyObject *)self; +error: + if (self) { + do { + PyObject *_py_decref_tmp = (PyObject *)(self); + if (--(_py_decref_tmp)->ob_refcnt != 0) + ; + else + ((*(((PyObject *)(_py_decref_tmp))->ob_type)->tp_dealloc)( + (PyObject *)(_py_decref_tmp))); + } while (0); + } + if (data && buf.obj) { + PyBuffer_Release(&buf); + } + return 0; +} + +static void SHA3_dealloc(SHA3object *self) { + PyObject_Free(self); +} + +static PyObject *_sha3_sha3_224_copy_impl(SHA3object *self) { + SHA3object *newobj; + if ((newobj = newSHA3object((((PyObject *)(self))->ob_type))) == 0) { + return 0; + } + memcpy(&(newobj->hash_state), &(self->hash_state), + sizeof(Keccak_HashInstance)); + return (PyObject *)newobj; +} + +static PyObject *_sha3_sha3_224_digest_impl(SHA3object *self) { + unsigned char digest[64 + (20 * 8)]; + Keccak_HashInstance temp; + HashReturn res; + memcpy(&(temp), &(self->hash_state), sizeof(Keccak_HashInstance)); + res = _PySHA3_Keccak_HashFinal(&temp, digest); + if (res != SUCCESS) { + PyErr_SetString(PyExc_RuntimeError, "internal error in SHA3 Final()"); + return 0; + } + return PyBytes_FromStringAndSize((const char *)digest, + self->hash_state.fixedOutputLength / 8); +} + +static PyObject *_sha3_sha3_224_hexdigest_impl(SHA3object *self) { + unsigned char digest[64 + (20 * 8)]; + Keccak_HashInstance temp; + HashReturn res; + memcpy(&(temp), &(self->hash_state), sizeof(Keccak_HashInstance)); + res = _PySHA3_Keccak_HashFinal(&temp, digest); + if (res != SUCCESS) { + PyErr_SetString(PyExc_RuntimeError, "internal error in SHA3 Final()"); + return 0; + } + return _Py_strhex((const char *)digest, + self->hash_state.fixedOutputLength / 8); +} + +static PyObject *_sha3_sha3_224_update(SHA3object *self, PyObject *data) { + Py_buffer buf; + HashReturn res; + do { + if (((((((PyObject *)((data)))->ob_type))->tp_flags & ((1UL << 28))) != + 0)) { + PyErr_SetString(PyExc_TypeError, + "Unicode-objects must be encoded before hashing"); + return 0; + } + if (!((((data))->ob_type->tp_as_buffer != 0) && + (((data))->ob_type->tp_as_buffer->bf_getbuffer != 0))) { + PyErr_SetString(PyExc_TypeError, + "object supporting the buffer API required"); + return 0; + } + if (PyObject_GetBuffer((data), (&buf), 0) == -1) { + return 0; + } + if ((&buf)->ndim > 1) { + PyErr_SetString(PyExc_BufferError, "Buffer must be single dimension"); + PyBuffer_Release((&buf)); + return 0; + } + } while (0); + res = _PySHA3_Keccak_HashUpdate(&self->hash_state, buf.buf, buf.len * 8); + if (res != SUCCESS) { + PyBuffer_Release(&buf); + PyErr_SetString(PyExc_RuntimeError, "internal error in SHA3 Update()"); + return 0; + } + PyBuffer_Release(&buf); + (((PyObject *)((&_Py_NoneStruct)))->ob_refcnt++); + return (&_Py_NoneStruct); +} + +static PyMethodDef SHA3_methods[] = { + {"copy", (PyCFunction)_sha3_sha3_224_copy, 0x0004, + _sha3_sha3_224_copy__doc__}, + {"digest", (PyCFunction)_sha3_sha3_224_digest, 0x0004, + _sha3_sha3_224_digest__doc__}, + {"hexdigest", (PyCFunction)_sha3_sha3_224_hexdigest, 0x0004, + _sha3_sha3_224_hexdigest__doc__}, + {"update", (PyCFunction)_sha3_sha3_224_update, 0x0008, + _sha3_sha3_224_update__doc__}, + {0}, +}; + +static PyObject *SHA3_get_block_size(SHA3object *self, void *closure) { + int rate = self->hash_state.sponge.rate; + return PyLong_FromLong(rate / 8); +} + +static PyObject *SHA3_get_name(SHA3object *self, void *closure) { + PyTypeObject *type = (((PyObject *)(self))->ob_type); + if (type == &SHA3_224type) { + return PyUnicode_FromString("sha3_224"); + } else if (type == &SHA3_256type) { + return PyUnicode_FromString("sha3_256"); + } else if (type == &SHA3_384type) { + return PyUnicode_FromString("sha3_384"); + } else if (type == &SHA3_512type) { + return PyUnicode_FromString("sha3_512"); + } else if (type == &SHAKE128type) { + return PyUnicode_FromString("shake_128"); + } else if (type == &SHAKE256type) { + return PyUnicode_FromString("shake_256"); + } else { + PyErr_BadInternalCall(); + return 0; + } +} + +static PyObject *SHA3_get_digest_size(SHA3object *self, void *closure) { + return PyLong_FromLong(self->hash_state.fixedOutputLength / 8); +} + +static PyObject *SHA3_get_capacity_bits(SHA3object *self, void *closure) { + int capacity = 1600 - self->hash_state.sponge.rate; + return PyLong_FromLong(capacity); +} + +static PyObject *SHA3_get_rate_bits(SHA3object *self, void *closure) { + unsigned int rate = self->hash_state.sponge.rate; + return PyLong_FromLong(rate); +} + +static PyObject *SHA3_get_suffix(SHA3object *self, void *closure) { + unsigned char suffix[2]; + suffix[0] = self->hash_state.delimitedSuffix; + suffix[1] = 0; + return PyBytes_FromStringAndSize((const char *)suffix, 1); +} + +static PyGetSetDef SHA3_getseters[] = { + {"block_size", (getter)SHA3_get_block_size}, + {"name", (getter)SHA3_get_name}, + {"digest_size", (getter)SHA3_get_digest_size}, + {"_capacity_bits", (getter)SHA3_get_capacity_bits}, + {"_rate_bits", (getter)SHA3_get_rate_bits}, + {"_suffix", (getter)SHA3_get_suffix}, + {0}, +}; + +static char sha3_224__doc__[] = + "sha3_224([data]) -> SHA3 object\n\nReturn a new SHA3 hash object with a " + "hashbit length of 28 bytes."; + +static char sha3_256__doc__[] = + "sha3_256([data]) -> SHA3 object\n\nReturn a new SHA3 hash object with a " + "hashbit length of 32 bytes."; + +static char sha3_384__doc__[] = + "sha3_384([data]) -> SHA3 object\n\nReturn a new SHA3 hash object with a " + "hashbit length of 48 bytes."; + +static char sha3_512__doc__[] = + "sha3_512([data]) -> SHA3 object\n\nReturn a new SHA3 hash object with a " + "hashbit length of 64 bytes."; + +static PyTypeObject SHA3_224type = { + {{1, 0}, 0}, + "_sha3.sha3_224", + sizeof(SHA3object), + 0, + (destructor)SHA3_dealloc, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + (0 | (1UL << 18) | 0), + sha3_224__doc__, + 0, + 0, + 0, + 0, + 0, + 0, + SHA3_methods, + 0, + SHA3_getseters, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + py_sha3_new, +}; + +static PyTypeObject SHA3_256type = { + {{1, 0}, 0}, + "_sha3.sha3_256", + sizeof(SHA3object), + 0, + (destructor)SHA3_dealloc, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + (0 | (1UL << 18) | 0), + sha3_256__doc__, + 0, + 0, + 0, + 0, + 0, + 0, + SHA3_methods, + 0, + SHA3_getseters, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + py_sha3_new, +}; + +static PyTypeObject SHA3_384type = { + {{1, 0}, 0}, + "_sha3.sha3_384", + sizeof(SHA3object), + 0, + (destructor)SHA3_dealloc, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + (0 | (1UL << 18) | 0), + sha3_384__doc__, + 0, + 0, + 0, + 0, + 0, + 0, + SHA3_methods, + 0, + SHA3_getseters, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + py_sha3_new, +}; + +static PyTypeObject SHA3_512type = { + {{1, 0}, 0}, + "_sha3.sha3_512", + sizeof(SHA3object), + 0, + (destructor)SHA3_dealloc, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + (0 | (1UL << 18) | 0), + sha3_512__doc__, + 0, + 0, + 0, + 0, + 0, + 0, + SHA3_methods, + 0, + SHA3_getseters, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + py_sha3_new, +}; + +static PyObject *_SHAKE_digest(SHA3object *self, PyObject *digestlen_obj, + int hex) { + unsigned long digestlen; + unsigned char *digest = 0; + Keccak_HashInstance temp; + int res; + PyObject *result = 0; + digestlen = PyLong_AsUnsignedLong(digestlen_obj); + if (digestlen == (unsigned long)-1 && PyErr_Occurred()) { + return 0; + } + if (digestlen >= (1 << 29)) { + PyErr_SetString(PyExc_ValueError, "length is too large"); + return 0; + } + digest = (unsigned char *)PyMem_Malloc(digestlen + (20 * 8)); + if (digest == 0) { + return PyErr_NoMemory(); + } + memcpy(&(temp), &(self->hash_state), sizeof(Keccak_HashInstance)); + res = _PySHA3_Keccak_HashFinal(&temp, 0); + if (res != SUCCESS) { + PyErr_SetString(PyExc_RuntimeError, "internal error in SHA3 done()"); + goto error; + } + res = _PySHA3_Keccak_HashSqueeze(&temp, digest, digestlen * 8); + if (res != SUCCESS) { + PyErr_SetString(PyExc_RuntimeError, "internal error in SHA3 Squeeze()"); + return 0; + } + if (hex) { + result = _Py_strhex((const char *)digest, digestlen); + } else { + result = PyBytes_FromStringAndSize((const char *)digest, digestlen); + } +error: + if (digest != 0) { + PyMem_Free(digest); + } + return result; +} + +static PyObject *_sha3_shake_128_digest(SHA3object *self, PyObject *length) { + return _SHAKE_digest(self, length, 0); +} + +static PyObject *_sha3_shake_128_hexdigest(SHA3object *self, PyObject *length) { + return _SHAKE_digest(self, length, 1); +} + +static PyMethodDef SHAKE_methods[] = { + {"copy", (PyCFunction)_sha3_sha3_224_copy, 0x0004, + _sha3_sha3_224_copy__doc__}, + {"digest", (PyCFunction)_sha3_shake_128_digest, 0x0008, + _sha3_shake_128_digest__doc__}, + {"hexdigest", (PyCFunction)_sha3_shake_128_hexdigest, 0x0008, + _sha3_shake_128_hexdigest__doc__}, + {"update", (PyCFunction)_sha3_sha3_224_update, 0x0008, + _sha3_sha3_224_update__doc__}, + {0, 0}}; + +static char shake_128__doc__[] = + "shake_128([data]) -> SHAKE object\n\nReturn a new SHAKE hash object."; + +static char shake_256__doc__[] = + "shake_256([data]) -> SHAKE object\n\nReturn a new SHAKE hash object."; + +static PyTypeObject SHAKE128type = { + {{1, 0}, 0}, + "_sha3.shake_128", + sizeof(SHA3object), + 0, + (destructor)SHA3_dealloc, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + (0 | (1UL << 18) | 0), + shake_128__doc__, + 0, + 0, + 0, + 0, + 0, + 0, + SHAKE_methods, + 0, + SHA3_getseters, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + py_sha3_new, +}; +static PyTypeObject SHAKE256type = { + {{1, 0}, 0}, + "_sha3.shake_256", + sizeof(SHA3object), + 0, + (destructor)SHA3_dealloc, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + (0 | (1UL << 18) | 0), + shake_256__doc__, + 0, + 0, + 0, + 0, + 0, + 0, + SHAKE_methods, + 0, + SHA3_getseters, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + py_sha3_new, +}; + +static struct PyModuleDef _SHA3module = {{{1, 0}, 0, 0, 0}, "_sha3", 0, -1}; + +PyObject *PyInit__sha3(void) { + PyObject *m = 0; + if ((m = PyModule_Create2(&_SHA3module, 1013)) == 0) { + return 0; + } + do { + (((PyObject *)(&SHA3_224type))->ob_type) = &PyType_Type; + if (PyType_Ready(&SHA3_224type) < 0) { + goto error; + } + (((PyObject *)((PyObject *)&SHA3_224type))->ob_refcnt++); + if (PyModule_AddObject(m, "sha3_224", (PyObject *)&SHA3_224type) < 0) { + goto error; + } + } while (0); + do { + (((PyObject *)(&SHA3_256type))->ob_type) = &PyType_Type; + if (PyType_Ready(&SHA3_256type) < 0) { + goto error; + } + (((PyObject *)((PyObject *)&SHA3_256type))->ob_refcnt++); + if (PyModule_AddObject(m, "sha3_256", (PyObject *)&SHA3_256type) < 0) { + goto error; + } + } while (0); + do { + (((PyObject *)(&SHA3_384type))->ob_type) = &PyType_Type; + if (PyType_Ready(&SHA3_384type) < 0) { + goto error; + } + (((PyObject *)((PyObject *)&SHA3_384type))->ob_refcnt++); + if (PyModule_AddObject(m, "sha3_384", (PyObject *)&SHA3_384type) < 0) { + goto error; + } + } while (0); + do { + (((PyObject *)(&SHA3_512type))->ob_type) = &PyType_Type; + if (PyType_Ready(&SHA3_512type) < 0) { + goto error; + } + (((PyObject *)((PyObject *)&SHA3_512type))->ob_refcnt++); + if (PyModule_AddObject(m, "sha3_512", (PyObject *)&SHA3_512type) < 0) { + goto error; + } + } while (0); + do { + (((PyObject *)(&SHAKE128type))->ob_type) = &PyType_Type; + if (PyType_Ready(&SHAKE128type) < 0) { + goto error; + } + (((PyObject *)((PyObject *)&SHAKE128type))->ob_refcnt++); + if (PyModule_AddObject(m, "shake_128", (PyObject *)&SHAKE128type) < 0) { + goto error; + } + } while (0); + do { + (((PyObject *)(&SHAKE256type))->ob_type) = &PyType_Type; + if (PyType_Ready(&SHAKE256type) < 0) { + goto error; + } + (((PyObject *)((PyObject *)&SHAKE256type))->ob_refcnt++); + if (PyModule_AddObject(m, "shake_256", (PyObject *)&SHAKE256type) < 0) { + goto error; + } + } while (0); + if (PyModule_AddIntConstant(m, "keccakopt", 64) < 0) { + goto error; + } + if (PyModule_AddStringConstant(m, "implementation", + "generic 64-bit optimized implementation (" + "lane complementing, all rounds unrolled" + ")") < 0) { + goto error; + } + return m; +error: + do { + PyObject *_py_decref_tmp = (PyObject *)(m); + if (--(_py_decref_tmp)->ob_refcnt != 0) + ; + else + ((*(((PyObject *)(_py_decref_tmp))->ob_type)->tp_dealloc)( + (PyObject *)(_py_decref_tmp))); + } while (0); + return 0; +} diff --git a/third_party/python/Modules/_sha3/README.txt b/third_party/python/Modules/_sha3/README.txt deleted file mode 100644 index e34b1d12f..000000000 --- a/third_party/python/Modules/_sha3/README.txt +++ /dev/null @@ -1,11 +0,0 @@ -Keccak Code Package -=================== - -The files in kcp are taken from the Keccak Code Package. They have been -slightly to be C89 compatible. The architecture specific header file -KeccakP-1600-SnP.h ha been renamed to KeccakP-1600-SnP-opt32.h or -KeccakP-1600-SnP-opt64.h. - -The 64bit files were generated with generic64lc/libkeccak.a.pack target, the -32bit files with generic32lc/libkeccak.a.pack. - diff --git a/third_party/python/Modules/_sha3/cleanup.py b/third_party/python/Modules/_sha3/cleanup.py deleted file mode 100755 index 4f53681b4..000000000 --- a/third_party/python/Modules/_sha3/cleanup.py +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Christian Heimes (christian@python.org) -# Licensed to PSF under a Contributor Agreement. -# -# cleanup Keccak sources - -import os -import re - -CPP1 = re.compile("^//(.*)") -CPP2 = re.compile(r"\ //(.*)") - -STATICS = ("void ", "int ", "HashReturn ", - "const UINT64 ", "UINT16 ", " int prefix##") - -HERE = os.path.dirname(os.path.abspath(__file__)) -KECCAK = os.path.join(HERE, "kcp") - -def getfiles(): - for name in os.listdir(KECCAK): - name = os.path.join(KECCAK, name) - if os.path.isfile(name): - yield name - -def cleanup(f): - buf = [] - for line in f: - # mark all functions and global data as static - #if line.startswith(STATICS): - # buf.append("static " + line) - # continue - # remove UINT64 typedef, we have our own - if line.startswith("typedef unsigned long long int"): - buf.append("/* %s */\n" % line.strip()) - continue - ## remove #include "brg_endian.h" - if "brg_endian.h" in line: - buf.append("/* %s */\n" % line.strip()) - continue - # transform C++ comments into ANSI C comments - line = CPP1.sub(r"/*\1 */\n", line) - line = CPP2.sub(r" /*\1 */\n", line) - buf.append(line) - return "".join(buf) - -for name in getfiles(): - with open(name) as f: - res = cleanup(f) - with open(name, "w") as f: - f.write(res) diff --git a/third_party/python/Modules/_sha3/clinic/sha3module.c.h b/third_party/python/Modules/_sha3/clinic/sha3module.c.h deleted file mode 100644 index 935f2e284..000000000 --- a/third_party/python/Modules/_sha3/clinic/sha3module.c.h +++ /dev/null @@ -1,86 +0,0 @@ -/* clang-format off */ -/*[clinic input] -preserve -[clinic start generated code]*/ - -PyDoc_STRVAR(_sha3_sha3_224_copy__doc__, -"copy($self, /)\n" -"--\n" -"\n" -"Return a copy of the hash object."); - -#define _SHA3_SHA3_224_COPY_METHODDEF \ - {"copy", (PyCFunction)_sha3_sha3_224_copy, METH_NOARGS, _sha3_sha3_224_copy__doc__}, - -static PyObject * -_sha3_sha3_224_copy_impl(SHA3object *self); - -static PyObject * -_sha3_sha3_224_copy(SHA3object *self, PyObject *Py_UNUSED(ignored)) -{ - return _sha3_sha3_224_copy_impl(self); -} - -PyDoc_STRVAR(_sha3_sha3_224_digest__doc__, -"digest($self, /)\n" -"--\n" -"\n" -"Return the digest value as a bytes object."); - -#define _SHA3_SHA3_224_DIGEST_METHODDEF \ - {"digest", (PyCFunction)_sha3_sha3_224_digest, METH_NOARGS, _sha3_sha3_224_digest__doc__}, - -static PyObject * -_sha3_sha3_224_digest_impl(SHA3object *self); - -static PyObject * -_sha3_sha3_224_digest(SHA3object *self, PyObject *Py_UNUSED(ignored)) -{ - return _sha3_sha3_224_digest_impl(self); -} - -PyDoc_STRVAR(_sha3_sha3_224_hexdigest__doc__, -"hexdigest($self, /)\n" -"--\n" -"\n" -"Return the digest value as a string of hexadecimal digits."); - -#define _SHA3_SHA3_224_HEXDIGEST_METHODDEF \ - {"hexdigest", (PyCFunction)_sha3_sha3_224_hexdigest, METH_NOARGS, _sha3_sha3_224_hexdigest__doc__}, - -static PyObject * -_sha3_sha3_224_hexdigest_impl(SHA3object *self); - -static PyObject * -_sha3_sha3_224_hexdigest(SHA3object *self, PyObject *Py_UNUSED(ignored)) -{ - return _sha3_sha3_224_hexdigest_impl(self); -} - -PyDoc_STRVAR(_sha3_sha3_224_update__doc__, -"update($self, data, /)\n" -"--\n" -"\n" -"Update this hash object\'s state with the provided bytes-like object."); - -#define _SHA3_SHA3_224_UPDATE_METHODDEF \ - {"update", (PyCFunction)_sha3_sha3_224_update, METH_O, _sha3_sha3_224_update__doc__}, - -PyDoc_STRVAR(_sha3_shake_128_digest__doc__, -"digest($self, length, /)\n" -"--\n" -"\n" -"Return the digest value as a bytes object."); - -#define _SHA3_SHAKE_128_DIGEST_METHODDEF \ - {"digest", (PyCFunction)_sha3_shake_128_digest, METH_O, _sha3_shake_128_digest__doc__}, - -PyDoc_STRVAR(_sha3_shake_128_hexdigest__doc__, -"hexdigest($self, length, /)\n" -"--\n" -"\n" -"Return the digest value as a string of hexadecimal digits."); - -#define _SHA3_SHAKE_128_HEXDIGEST_METHODDEF \ - {"hexdigest", (PyCFunction)_sha3_shake_128_hexdigest, METH_O, _sha3_shake_128_hexdigest__doc__}, -/*[clinic end generated code: output=826b6b5a7c3406eb input=a9049054013a1b77]*/ diff --git a/third_party/python/Modules/_sha3/kcp/KeccakHash.c b/third_party/python/Modules/_sha3/kcp/KeccakHash.c deleted file mode 100644 index 40419ab98..000000000 --- a/third_party/python/Modules/_sha3/kcp/KeccakHash.c +++ /dev/null @@ -1,82 +0,0 @@ -/* clang-format off */ -/* -Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni, -Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby -denoted as "the implementer". - -For more information, feedback or questions, please refer to our websites: -http://keccak.noekeon.org/ -http://keyak.noekeon.org/ -http://ketje.noekeon.org/ - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#include "KeccakHash.h" - -/* ---------------------------------------------------------------- */ - -HashReturn Keccak_HashInitialize(Keccak_HashInstance *instance, unsigned int rate, unsigned int capacity, unsigned int hashbitlen, unsigned char delimitedSuffix) -{ - HashReturn result; - - if (delimitedSuffix == 0) - return FAIL; - result = (HashReturn)KeccakWidth1600_SpongeInitialize(&instance->sponge, rate, capacity); - if (result != SUCCESS) - return result; - instance->fixedOutputLength = hashbitlen; - instance->delimitedSuffix = delimitedSuffix; - return SUCCESS; -} - -/* ---------------------------------------------------------------- */ - -HashReturn Keccak_HashUpdate(Keccak_HashInstance *instance, const BitSequence *data, DataLength databitlen) -{ - if ((databitlen % 8) == 0) - return (HashReturn)KeccakWidth1600_SpongeAbsorb(&instance->sponge, data, databitlen/8); - else { - HashReturn ret = (HashReturn)KeccakWidth1600_SpongeAbsorb(&instance->sponge, data, databitlen/8); - if (ret == SUCCESS) { - /* The last partial byte is assumed to be aligned on the least significant bits */ - - unsigned char lastByte = data[databitlen/8]; - /* Concatenate the last few bits provided here with those of the suffix */ - - unsigned short delimitedLastBytes = (unsigned short)((unsigned short)lastByte | ((unsigned short)instance->delimitedSuffix << (databitlen % 8))); - if ((delimitedLastBytes & 0xFF00) == 0x0000) { - instance->delimitedSuffix = delimitedLastBytes & 0xFF; - } - else { - unsigned char oneByte[1]; - oneByte[0] = delimitedLastBytes & 0xFF; - ret = (HashReturn)KeccakWidth1600_SpongeAbsorb(&instance->sponge, oneByte, 1); - instance->delimitedSuffix = (delimitedLastBytes >> 8) & 0xFF; - } - } - return ret; - } -} - -/* ---------------------------------------------------------------- */ - -HashReturn Keccak_HashFinal(Keccak_HashInstance *instance, BitSequence *hashval) -{ - HashReturn ret = (HashReturn)KeccakWidth1600_SpongeAbsorbLastFewBits(&instance->sponge, instance->delimitedSuffix); - if (ret == SUCCESS) - return (HashReturn)KeccakWidth1600_SpongeSqueeze(&instance->sponge, hashval, instance->fixedOutputLength/8); - else - return ret; -} - -/* ---------------------------------------------------------------- */ - -HashReturn Keccak_HashSqueeze(Keccak_HashInstance *instance, BitSequence *data, DataLength databitlen) -{ - if ((databitlen % 8) != 0) - return FAIL; - return (HashReturn)KeccakWidth1600_SpongeSqueeze(&instance->sponge, data, databitlen/8); -} diff --git a/third_party/python/Modules/_sha3/kcp/KeccakHash.h b/third_party/python/Modules/_sha3/kcp/KeccakHash.h deleted file mode 100644 index c03504abf..000000000 --- a/third_party/python/Modules/_sha3/kcp/KeccakHash.h +++ /dev/null @@ -1,114 +0,0 @@ -/* clang-format off */ -/* -Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni, -Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby -denoted as "the implementer". - -For more information, feedback or questions, please refer to our websites: -http://keccak.noekeon.org/ -http://keyak.noekeon.org/ -http://ketje.noekeon.org/ - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#ifndef _KeccakHashInterface_h_ -#define _KeccakHashInterface_h_ - -#ifndef KeccakP1600_excluded - -#include "KeccakSponge.h" - -typedef unsigned char BitSequence; -typedef size_t DataLength; -typedef enum { SUCCESS = 0, FAIL = 1, BAD_HASHLEN = 2 } HashReturn; - -typedef struct { - KeccakWidth1600_SpongeInstance sponge; - unsigned int fixedOutputLength; - unsigned char delimitedSuffix; -} Keccak_HashInstance; - -/** - * Function to initialize the Keccak[r, c] sponge function instance used in sequential hashing mode. - * @param hashInstance Pointer to the hash instance to be initialized. - * @param rate The value of the rate r. - * @param capacity The value of the capacity c. - * @param hashbitlen The desired number of output bits, - * or 0 for an arbitrarily-long output. - * @param delimitedSuffix Bits that will be automatically appended to the end - * of the input message, as in domain separation. - * This is a byte containing from 0 to 7 bits - * formatted like the @a delimitedData parameter of - * the Keccak_SpongeAbsorbLastFewBits() function. - * @pre One must have r+c=1600 and the rate a multiple of 8 bits in this implementation. - * @return SUCCESS if successful, FAIL otherwise. - */ -HashReturn Keccak_HashInitialize(Keccak_HashInstance *hashInstance, unsigned int rate, unsigned int capacity, unsigned int hashbitlen, unsigned char delimitedSuffix); - -/** Macro to initialize a SHAKE128 instance as specified in the FIPS 202 standard. - */ -#define Keccak_HashInitialize_SHAKE128(hashInstance) Keccak_HashInitialize(hashInstance, 1344, 256, 0, 0x1F) - -/** Macro to initialize a SHAKE256 instance as specified in the FIPS 202 standard. - */ -#define Keccak_HashInitialize_SHAKE256(hashInstance) Keccak_HashInitialize(hashInstance, 1088, 512, 0, 0x1F) - -/** Macro to initialize a SHA3-224 instance as specified in the FIPS 202 standard. - */ -#define Keccak_HashInitialize_SHA3_224(hashInstance) Keccak_HashInitialize(hashInstance, 1152, 448, 224, 0x06) - -/** Macro to initialize a SHA3-256 instance as specified in the FIPS 202 standard. - */ -#define Keccak_HashInitialize_SHA3_256(hashInstance) Keccak_HashInitialize(hashInstance, 1088, 512, 256, 0x06) - -/** Macro to initialize a SHA3-384 instance as specified in the FIPS 202 standard. - */ -#define Keccak_HashInitialize_SHA3_384(hashInstance) Keccak_HashInitialize(hashInstance, 832, 768, 384, 0x06) - -/** Macro to initialize a SHA3-512 instance as specified in the FIPS 202 standard. - */ -#define Keccak_HashInitialize_SHA3_512(hashInstance) Keccak_HashInitialize(hashInstance, 576, 1024, 512, 0x06) - -/** - * Function to give input data to be absorbed. - * @param hashInstance Pointer to the hash instance initialized by Keccak_HashInitialize(). - * @param data Pointer to the input data. - * When @a databitLen is not a multiple of 8, the last bits of data must be - * in the least significant bits of the last byte (little-endian convention). - * @param databitLen The number of input bits provided in the input data. - * @pre In the previous call to Keccak_HashUpdate(), databitlen was a multiple of 8. - * @return SUCCESS if successful, FAIL otherwise. - */ -HashReturn Keccak_HashUpdate(Keccak_HashInstance *hashInstance, const BitSequence *data, DataLength databitlen); - -/** - * Function to call after all input blocks have been input and to get - * output bits if the length was specified when calling Keccak_HashInitialize(). - * @param hashInstance Pointer to the hash instance initialized by Keccak_HashInitialize(). - * If @a hashbitlen was not 0 in the call to Keccak_HashInitialize(), the number of - * output bits is equal to @a hashbitlen. - * If @a hashbitlen was 0 in the call to Keccak_HashInitialize(), the output bits - * must be extracted using the Keccak_HashSqueeze() function. - * @param state Pointer to the state of the sponge function initialized by Init(). - * @param hashval Pointer to the buffer where to store the output data. - * @return SUCCESS if successful, FAIL otherwise. - */ -HashReturn Keccak_HashFinal(Keccak_HashInstance *hashInstance, BitSequence *hashval); - - /** - * Function to squeeze output data. - * @param hashInstance Pointer to the hash instance initialized by Keccak_HashInitialize(). - * @param data Pointer to the buffer where to store the output data. - * @param databitlen The number of output bits desired (must be a multiple of 8). - * @pre Keccak_HashFinal() must have been already called. - * @pre @a databitlen is a multiple of 8. - * @return SUCCESS if successful, FAIL otherwise. - */ -HashReturn Keccak_HashSqueeze(Keccak_HashInstance *hashInstance, BitSequence *data, DataLength databitlen); - -#endif - -#endif diff --git a/third_party/python/Modules/_sha3/kcp/KeccakP-1600-64.macros b/third_party/python/Modules/_sha3/kcp/KeccakP-1600-64.macros deleted file mode 100644 index 1f11fe3e7..000000000 --- a/third_party/python/Modules/_sha3/kcp/KeccakP-1600-64.macros +++ /dev/null @@ -1,2208 +0,0 @@ -/* -Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni, -Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby -denoted as "the implementer". - -For more information, feedback or questions, please refer to our websites: -http://keccak.noekeon.org/ -http://keyak.noekeon.org/ -http://ketje.noekeon.org/ - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#define declareABCDE \ - UINT64 Aba, Abe, Abi, Abo, Abu; \ - UINT64 Aga, Age, Agi, Ago, Agu; \ - UINT64 Aka, Ake, Aki, Ako, Aku; \ - UINT64 Ama, Ame, Ami, Amo, Amu; \ - UINT64 Asa, Ase, Asi, Aso, Asu; \ - UINT64 Bba, Bbe, Bbi, Bbo, Bbu; \ - UINT64 Bga, Bge, Bgi, Bgo, Bgu; \ - UINT64 Bka, Bke, Bki, Bko, Bku; \ - UINT64 Bma, Bme, Bmi, Bmo, Bmu; \ - UINT64 Bsa, Bse, Bsi, Bso, Bsu; \ - UINT64 Ca, Ce, Ci, Co, Cu; \ - UINT64 Da, De, Di, Do, Du; \ - UINT64 Eba, Ebe, Ebi, Ebo, Ebu; \ - UINT64 Ega, Ege, Egi, Ego, Egu; \ - UINT64 Eka, Eke, Eki, Eko, Eku; \ - UINT64 Ema, Eme, Emi, Emo, Emu; \ - UINT64 Esa, Ese, Esi, Eso, Esu; \ - -#define prepareTheta \ - Ca = Aba^Aga^Aka^Ama^Asa; \ - Ce = Abe^Age^Ake^Ame^Ase; \ - Ci = Abi^Agi^Aki^Ami^Asi; \ - Co = Abo^Ago^Ako^Amo^Aso; \ - Cu = Abu^Agu^Aku^Amu^Asu; \ - -#ifdef UseBebigokimisa -/* --- Code for round, with prepare-theta (lane complementing pattern 'bebigokimisa') */ - -/* --- 64-bit lanes mapped to 64-bit words */ - -#define thetaRhoPiChiIotaPrepareTheta(i, A, E) \ - Da = Cu^ROL64(Ce, 1); \ - De = Ca^ROL64(Ci, 1); \ - Di = Ce^ROL64(Co, 1); \ - Do = Ci^ROL64(Cu, 1); \ - Du = Co^ROL64(Ca, 1); \ -\ - A##ba ^= Da; \ - Bba = A##ba; \ - A##ge ^= De; \ - Bbe = ROL64(A##ge, 44); \ - A##ki ^= Di; \ - Bbi = ROL64(A##ki, 43); \ - A##mo ^= Do; \ - Bbo = ROL64(A##mo, 21); \ - A##su ^= Du; \ - Bbu = ROL64(A##su, 14); \ - E##ba = Bba ^( Bbe | Bbi ); \ - E##ba ^= KeccakF1600RoundConstants[i]; \ - Ca = E##ba; \ - E##be = Bbe ^((~Bbi)| Bbo ); \ - Ce = E##be; \ - E##bi = Bbi ^( Bbo & Bbu ); \ - Ci = E##bi; \ - E##bo = Bbo ^( Bbu | Bba ); \ - Co = E##bo; \ - E##bu = Bbu ^( Bba & Bbe ); \ - Cu = E##bu; \ -\ - A##bo ^= Do; \ - Bga = ROL64(A##bo, 28); \ - A##gu ^= Du; \ - Bge = ROL64(A##gu, 20); \ - A##ka ^= Da; \ - Bgi = ROL64(A##ka, 3); \ - A##me ^= De; \ - Bgo = ROL64(A##me, 45); \ - A##si ^= Di; \ - Bgu = ROL64(A##si, 61); \ - E##ga = Bga ^( Bge | Bgi ); \ - Ca ^= E##ga; \ - E##ge = Bge ^( Bgi & Bgo ); \ - Ce ^= E##ge; \ - E##gi = Bgi ^( Bgo |(~Bgu)); \ - Ci ^= E##gi; \ - E##go = Bgo ^( Bgu | Bga ); \ - Co ^= E##go; \ - E##gu = Bgu ^( Bga & Bge ); \ - Cu ^= E##gu; \ -\ - A##be ^= De; \ - Bka = ROL64(A##be, 1); \ - A##gi ^= Di; \ - Bke = ROL64(A##gi, 6); \ - A##ko ^= Do; \ - Bki = ROL64(A##ko, 25); \ - A##mu ^= Du; \ - Bko = ROL64(A##mu, 8); \ - A##sa ^= Da; \ - Bku = ROL64(A##sa, 18); \ - E##ka = Bka ^( Bke | Bki ); \ - Ca ^= E##ka; \ - E##ke = Bke ^( Bki & Bko ); \ - Ce ^= E##ke; \ - E##ki = Bki ^((~Bko)& Bku ); \ - Ci ^= E##ki; \ - E##ko = (~Bko)^( Bku | Bka ); \ - Co ^= E##ko; \ - E##ku = Bku ^( Bka & Bke ); \ - Cu ^= E##ku; \ -\ - A##bu ^= Du; \ - Bma = ROL64(A##bu, 27); \ - A##ga ^= Da; \ - Bme = ROL64(A##ga, 36); \ - A##ke ^= De; \ - Bmi = ROL64(A##ke, 10); \ - A##mi ^= Di; \ - Bmo = ROL64(A##mi, 15); \ - A##so ^= Do; \ - Bmu = ROL64(A##so, 56); \ - E##ma = Bma ^( Bme & Bmi ); \ - Ca ^= E##ma; \ - E##me = Bme ^( Bmi | Bmo ); \ - Ce ^= E##me; \ - E##mi = Bmi ^((~Bmo)| Bmu ); \ - Ci ^= E##mi; \ - E##mo = (~Bmo)^( Bmu & Bma ); \ - Co ^= E##mo; \ - E##mu = Bmu ^( Bma | Bme ); \ - Cu ^= E##mu; \ -\ - A##bi ^= Di; \ - Bsa = ROL64(A##bi, 62); \ - A##go ^= Do; \ - Bse = ROL64(A##go, 55); \ - A##ku ^= Du; \ - Bsi = ROL64(A##ku, 39); \ - A##ma ^= Da; \ - Bso = ROL64(A##ma, 41); \ - A##se ^= De; \ - Bsu = ROL64(A##se, 2); \ - E##sa = Bsa ^((~Bse)& Bsi ); \ - Ca ^= E##sa; \ - E##se = (~Bse)^( Bsi | Bso ); \ - Ce ^= E##se; \ - E##si = Bsi ^( Bso & Bsu ); \ - Ci ^= E##si; \ - E##so = Bso ^( Bsu | Bsa ); \ - Co ^= E##so; \ - E##su = Bsu ^( Bsa & Bse ); \ - Cu ^= E##su; \ -\ - -/* --- Code for round (lane complementing pattern 'bebigokimisa') */ - -/* --- 64-bit lanes mapped to 64-bit words */ - -#define thetaRhoPiChiIota(i, A, E) \ - Da = Cu^ROL64(Ce, 1); \ - De = Ca^ROL64(Ci, 1); \ - Di = Ce^ROL64(Co, 1); \ - Do = Ci^ROL64(Cu, 1); \ - Du = Co^ROL64(Ca, 1); \ -\ - A##ba ^= Da; \ - Bba = A##ba; \ - A##ge ^= De; \ - Bbe = ROL64(A##ge, 44); \ - A##ki ^= Di; \ - Bbi = ROL64(A##ki, 43); \ - A##mo ^= Do; \ - Bbo = ROL64(A##mo, 21); \ - A##su ^= Du; \ - Bbu = ROL64(A##su, 14); \ - E##ba = Bba ^( Bbe | Bbi ); \ - E##ba ^= KeccakF1600RoundConstants[i]; \ - E##be = Bbe ^((~Bbi)| Bbo ); \ - E##bi = Bbi ^( Bbo & Bbu ); \ - E##bo = Bbo ^( Bbu | Bba ); \ - E##bu = Bbu ^( Bba & Bbe ); \ -\ - A##bo ^= Do; \ - Bga = ROL64(A##bo, 28); \ - A##gu ^= Du; \ - Bge = ROL64(A##gu, 20); \ - A##ka ^= Da; \ - Bgi = ROL64(A##ka, 3); \ - A##me ^= De; \ - Bgo = ROL64(A##me, 45); \ - A##si ^= Di; \ - Bgu = ROL64(A##si, 61); \ - E##ga = Bga ^( Bge | Bgi ); \ - E##ge = Bge ^( Bgi & Bgo ); \ - E##gi = Bgi ^( Bgo |(~Bgu)); \ - E##go = Bgo ^( Bgu | Bga ); \ - E##gu = Bgu ^( Bga & Bge ); \ -\ - A##be ^= De; \ - Bka = ROL64(A##be, 1); \ - A##gi ^= Di; \ - Bke = ROL64(A##gi, 6); \ - A##ko ^= Do; \ - Bki = ROL64(A##ko, 25); \ - A##mu ^= Du; \ - Bko = ROL64(A##mu, 8); \ - A##sa ^= Da; \ - Bku = ROL64(A##sa, 18); \ - E##ka = Bka ^( Bke | Bki ); \ - E##ke = Bke ^( Bki & Bko ); \ - E##ki = Bki ^((~Bko)& Bku ); \ - E##ko = (~Bko)^( Bku | Bka ); \ - E##ku = Bku ^( Bka & Bke ); \ -\ - A##bu ^= Du; \ - Bma = ROL64(A##bu, 27); \ - A##ga ^= Da; \ - Bme = ROL64(A##ga, 36); \ - A##ke ^= De; \ - Bmi = ROL64(A##ke, 10); \ - A##mi ^= Di; \ - Bmo = ROL64(A##mi, 15); \ - A##so ^= Do; \ - Bmu = ROL64(A##so, 56); \ - E##ma = Bma ^( Bme & Bmi ); \ - E##me = Bme ^( Bmi | Bmo ); \ - E##mi = Bmi ^((~Bmo)| Bmu ); \ - E##mo = (~Bmo)^( Bmu & Bma ); \ - E##mu = Bmu ^( Bma | Bme ); \ -\ - A##bi ^= Di; \ - Bsa = ROL64(A##bi, 62); \ - A##go ^= Do; \ - Bse = ROL64(A##go, 55); \ - A##ku ^= Du; \ - Bsi = ROL64(A##ku, 39); \ - A##ma ^= Da; \ - Bso = ROL64(A##ma, 41); \ - A##se ^= De; \ - Bsu = ROL64(A##se, 2); \ - E##sa = Bsa ^((~Bse)& Bsi ); \ - E##se = (~Bse)^( Bsi | Bso ); \ - E##si = Bsi ^( Bso & Bsu ); \ - E##so = Bso ^( Bsu | Bsa ); \ - E##su = Bsu ^( Bsa & Bse ); \ -\ - -#else /* UseBebigokimisa */ - -/* --- Code for round, with prepare-theta */ - -/* --- 64-bit lanes mapped to 64-bit words */ - -#define thetaRhoPiChiIotaPrepareTheta(i, A, E) \ - Da = Cu^ROL64(Ce, 1); \ - De = Ca^ROL64(Ci, 1); \ - Di = Ce^ROL64(Co, 1); \ - Do = Ci^ROL64(Cu, 1); \ - Du = Co^ROL64(Ca, 1); \ -\ - A##ba ^= Da; \ - Bba = A##ba; \ - A##ge ^= De; \ - Bbe = ROL64(A##ge, 44); \ - A##ki ^= Di; \ - Bbi = ROL64(A##ki, 43); \ - A##mo ^= Do; \ - Bbo = ROL64(A##mo, 21); \ - A##su ^= Du; \ - Bbu = ROL64(A##su, 14); \ - E##ba = Bba ^((~Bbe)& Bbi ); \ - E##ba ^= KeccakF1600RoundConstants[i]; \ - Ca = E##ba; \ - E##be = Bbe ^((~Bbi)& Bbo ); \ - Ce = E##be; \ - E##bi = Bbi ^((~Bbo)& Bbu ); \ - Ci = E##bi; \ - E##bo = Bbo ^((~Bbu)& Bba ); \ - Co = E##bo; \ - E##bu = Bbu ^((~Bba)& Bbe ); \ - Cu = E##bu; \ -\ - A##bo ^= Do; \ - Bga = ROL64(A##bo, 28); \ - A##gu ^= Du; \ - Bge = ROL64(A##gu, 20); \ - A##ka ^= Da; \ - Bgi = ROL64(A##ka, 3); \ - A##me ^= De; \ - Bgo = ROL64(A##me, 45); \ - A##si ^= Di; \ - Bgu = ROL64(A##si, 61); \ - E##ga = Bga ^((~Bge)& Bgi ); \ - Ca ^= E##ga; \ - E##ge = Bge ^((~Bgi)& Bgo ); \ - Ce ^= E##ge; \ - E##gi = Bgi ^((~Bgo)& Bgu ); \ - Ci ^= E##gi; \ - E##go = Bgo ^((~Bgu)& Bga ); \ - Co ^= E##go; \ - E##gu = Bgu ^((~Bga)& Bge ); \ - Cu ^= E##gu; \ -\ - A##be ^= De; \ - Bka = ROL64(A##be, 1); \ - A##gi ^= Di; \ - Bke = ROL64(A##gi, 6); \ - A##ko ^= Do; \ - Bki = ROL64(A##ko, 25); \ - A##mu ^= Du; \ - Bko = ROL64(A##mu, 8); \ - A##sa ^= Da; \ - Bku = ROL64(A##sa, 18); \ - E##ka = Bka ^((~Bke)& Bki ); \ - Ca ^= E##ka; \ - E##ke = Bke ^((~Bki)& Bko ); \ - Ce ^= E##ke; \ - E##ki = Bki ^((~Bko)& Bku ); \ - Ci ^= E##ki; \ - E##ko = Bko ^((~Bku)& Bka ); \ - Co ^= E##ko; \ - E##ku = Bku ^((~Bka)& Bke ); \ - Cu ^= E##ku; \ -\ - A##bu ^= Du; \ - Bma = ROL64(A##bu, 27); \ - A##ga ^= Da; \ - Bme = ROL64(A##ga, 36); \ - A##ke ^= De; \ - Bmi = ROL64(A##ke, 10); \ - A##mi ^= Di; \ - Bmo = ROL64(A##mi, 15); \ - A##so ^= Do; \ - Bmu = ROL64(A##so, 56); \ - E##ma = Bma ^((~Bme)& Bmi ); \ - Ca ^= E##ma; \ - E##me = Bme ^((~Bmi)& Bmo ); \ - Ce ^= E##me; \ - E##mi = Bmi ^((~Bmo)& Bmu ); \ - Ci ^= E##mi; \ - E##mo = Bmo ^((~Bmu)& Bma ); \ - Co ^= E##mo; \ - E##mu = Bmu ^((~Bma)& Bme ); \ - Cu ^= E##mu; \ -\ - A##bi ^= Di; \ - Bsa = ROL64(A##bi, 62); \ - A##go ^= Do; \ - Bse = ROL64(A##go, 55); \ - A##ku ^= Du; \ - Bsi = ROL64(A##ku, 39); \ - A##ma ^= Da; \ - Bso = ROL64(A##ma, 41); \ - A##se ^= De; \ - Bsu = ROL64(A##se, 2); \ - E##sa = Bsa ^((~Bse)& Bsi ); \ - Ca ^= E##sa; \ - E##se = Bse ^((~Bsi)& Bso ); \ - Ce ^= E##se; \ - E##si = Bsi ^((~Bso)& Bsu ); \ - Ci ^= E##si; \ - E##so = Bso ^((~Bsu)& Bsa ); \ - Co ^= E##so; \ - E##su = Bsu ^((~Bsa)& Bse ); \ - Cu ^= E##su; \ -\ - -/* --- Code for round */ - -/* --- 64-bit lanes mapped to 64-bit words */ - -#define thetaRhoPiChiIota(i, A, E) \ - Da = Cu^ROL64(Ce, 1); \ - De = Ca^ROL64(Ci, 1); \ - Di = Ce^ROL64(Co, 1); \ - Do = Ci^ROL64(Cu, 1); \ - Du = Co^ROL64(Ca, 1); \ -\ - A##ba ^= Da; \ - Bba = A##ba; \ - A##ge ^= De; \ - Bbe = ROL64(A##ge, 44); \ - A##ki ^= Di; \ - Bbi = ROL64(A##ki, 43); \ - A##mo ^= Do; \ - Bbo = ROL64(A##mo, 21); \ - A##su ^= Du; \ - Bbu = ROL64(A##su, 14); \ - E##ba = Bba ^((~Bbe)& Bbi ); \ - E##ba ^= KeccakF1600RoundConstants[i]; \ - E##be = Bbe ^((~Bbi)& Bbo ); \ - E##bi = Bbi ^((~Bbo)& Bbu ); \ - E##bo = Bbo ^((~Bbu)& Bba ); \ - E##bu = Bbu ^((~Bba)& Bbe ); \ -\ - A##bo ^= Do; \ - Bga = ROL64(A##bo, 28); \ - A##gu ^= Du; \ - Bge = ROL64(A##gu, 20); \ - A##ka ^= Da; \ - Bgi = ROL64(A##ka, 3); \ - A##me ^= De; \ - Bgo = ROL64(A##me, 45); \ - A##si ^= Di; \ - Bgu = ROL64(A##si, 61); \ - E##ga = Bga ^((~Bge)& Bgi ); \ - E##ge = Bge ^((~Bgi)& Bgo ); \ - E##gi = Bgi ^((~Bgo)& Bgu ); \ - E##go = Bgo ^((~Bgu)& Bga ); \ - E##gu = Bgu ^((~Bga)& Bge ); \ -\ - A##be ^= De; \ - Bka = ROL64(A##be, 1); \ - A##gi ^= Di; \ - Bke = ROL64(A##gi, 6); \ - A##ko ^= Do; \ - Bki = ROL64(A##ko, 25); \ - A##mu ^= Du; \ - Bko = ROL64(A##mu, 8); \ - A##sa ^= Da; \ - Bku = ROL64(A##sa, 18); \ - E##ka = Bka ^((~Bke)& Bki ); \ - E##ke = Bke ^((~Bki)& Bko ); \ - E##ki = Bki ^((~Bko)& Bku ); \ - E##ko = Bko ^((~Bku)& Bka ); \ - E##ku = Bku ^((~Bka)& Bke ); \ -\ - A##bu ^= Du; \ - Bma = ROL64(A##bu, 27); \ - A##ga ^= Da; \ - Bme = ROL64(A##ga, 36); \ - A##ke ^= De; \ - Bmi = ROL64(A##ke, 10); \ - A##mi ^= Di; \ - Bmo = ROL64(A##mi, 15); \ - A##so ^= Do; \ - Bmu = ROL64(A##so, 56); \ - E##ma = Bma ^((~Bme)& Bmi ); \ - E##me = Bme ^((~Bmi)& Bmo ); \ - E##mi = Bmi ^((~Bmo)& Bmu ); \ - E##mo = Bmo ^((~Bmu)& Bma ); \ - E##mu = Bmu ^((~Bma)& Bme ); \ -\ - A##bi ^= Di; \ - Bsa = ROL64(A##bi, 62); \ - A##go ^= Do; \ - Bse = ROL64(A##go, 55); \ - A##ku ^= Du; \ - Bsi = ROL64(A##ku, 39); \ - A##ma ^= Da; \ - Bso = ROL64(A##ma, 41); \ - A##se ^= De; \ - Bsu = ROL64(A##se, 2); \ - E##sa = Bsa ^((~Bse)& Bsi ); \ - E##se = Bse ^((~Bsi)& Bso ); \ - E##si = Bsi ^((~Bso)& Bsu ); \ - E##so = Bso ^((~Bsu)& Bsa ); \ - E##su = Bsu ^((~Bsa)& Bse ); \ -\ - -#endif /* UseBebigokimisa */ - - -#define copyFromState(X, state) \ - X##ba = state[ 0]; \ - X##be = state[ 1]; \ - X##bi = state[ 2]; \ - X##bo = state[ 3]; \ - X##bu = state[ 4]; \ - X##ga = state[ 5]; \ - X##ge = state[ 6]; \ - X##gi = state[ 7]; \ - X##go = state[ 8]; \ - X##gu = state[ 9]; \ - X##ka = state[10]; \ - X##ke = state[11]; \ - X##ki = state[12]; \ - X##ko = state[13]; \ - X##ku = state[14]; \ - X##ma = state[15]; \ - X##me = state[16]; \ - X##mi = state[17]; \ - X##mo = state[18]; \ - X##mu = state[19]; \ - X##sa = state[20]; \ - X##se = state[21]; \ - X##si = state[22]; \ - X##so = state[23]; \ - X##su = state[24]; \ - -#define copyToState(state, X) \ - state[ 0] = X##ba; \ - state[ 1] = X##be; \ - state[ 2] = X##bi; \ - state[ 3] = X##bo; \ - state[ 4] = X##bu; \ - state[ 5] = X##ga; \ - state[ 6] = X##ge; \ - state[ 7] = X##gi; \ - state[ 8] = X##go; \ - state[ 9] = X##gu; \ - state[10] = X##ka; \ - state[11] = X##ke; \ - state[12] = X##ki; \ - state[13] = X##ko; \ - state[14] = X##ku; \ - state[15] = X##ma; \ - state[16] = X##me; \ - state[17] = X##mi; \ - state[18] = X##mo; \ - state[19] = X##mu; \ - state[20] = X##sa; \ - state[21] = X##se; \ - state[22] = X##si; \ - state[23] = X##so; \ - state[24] = X##su; \ - -#define copyStateVariables(X, Y) \ - X##ba = Y##ba; \ - X##be = Y##be; \ - X##bi = Y##bi; \ - X##bo = Y##bo; \ - X##bu = Y##bu; \ - X##ga = Y##ga; \ - X##ge = Y##ge; \ - X##gi = Y##gi; \ - X##go = Y##go; \ - X##gu = Y##gu; \ - X##ka = Y##ka; \ - X##ke = Y##ke; \ - X##ki = Y##ki; \ - X##ko = Y##ko; \ - X##ku = Y##ku; \ - X##ma = Y##ma; \ - X##me = Y##me; \ - X##mi = Y##mi; \ - X##mo = Y##mo; \ - X##mu = Y##mu; \ - X##sa = Y##sa; \ - X##se = Y##se; \ - X##si = Y##si; \ - X##so = Y##so; \ - X##su = Y##su; \ - -#define copyFromStateAndAdd(X, state, input, laneCount) \ - if (laneCount < 16) { \ - if (laneCount < 8) { \ - if (laneCount < 4) { \ - if (laneCount < 2) { \ - if (laneCount < 1) { \ - X##ba = state[ 0]; \ - } \ - else { \ - X##ba = state[ 0]^input[ 0]; \ - } \ - X##be = state[ 1]; \ - X##bi = state[ 2]; \ - } \ - else { \ - X##ba = state[ 0]^input[ 0]; \ - X##be = state[ 1]^input[ 1]; \ - if (laneCount < 3) { \ - X##bi = state[ 2]; \ - } \ - else { \ - X##bi = state[ 2]^input[ 2]; \ - } \ - } \ - X##bo = state[ 3]; \ - X##bu = state[ 4]; \ - X##ga = state[ 5]; \ - X##ge = state[ 6]; \ - } \ - else { \ - X##ba = state[ 0]^input[ 0]; \ - X##be = state[ 1]^input[ 1]; \ - X##bi = state[ 2]^input[ 2]; \ - X##bo = state[ 3]^input[ 3]; \ - if (laneCount < 6) { \ - if (laneCount < 5) { \ - X##bu = state[ 4]; \ - } \ - else { \ - X##bu = state[ 4]^input[ 4]; \ - } \ - X##ga = state[ 5]; \ - X##ge = state[ 6]; \ - } \ - else { \ - X##bu = state[ 4]^input[ 4]; \ - X##ga = state[ 5]^input[ 5]; \ - if (laneCount < 7) { \ - X##ge = state[ 6]; \ - } \ - else { \ - X##ge = state[ 6]^input[ 6]; \ - } \ - } \ - } \ - X##gi = state[ 7]; \ - X##go = state[ 8]; \ - X##gu = state[ 9]; \ - X##ka = state[10]; \ - X##ke = state[11]; \ - X##ki = state[12]; \ - X##ko = state[13]; \ - X##ku = state[14]; \ - } \ - else { \ - X##ba = state[ 0]^input[ 0]; \ - X##be = state[ 1]^input[ 1]; \ - X##bi = state[ 2]^input[ 2]; \ - X##bo = state[ 3]^input[ 3]; \ - X##bu = state[ 4]^input[ 4]; \ - X##ga = state[ 5]^input[ 5]; \ - X##ge = state[ 6]^input[ 6]; \ - X##gi = state[ 7]^input[ 7]; \ - if (laneCount < 12) { \ - if (laneCount < 10) { \ - if (laneCount < 9) { \ - X##go = state[ 8]; \ - } \ - else { \ - X##go = state[ 8]^input[ 8]; \ - } \ - X##gu = state[ 9]; \ - X##ka = state[10]; \ - } \ - else { \ - X##go = state[ 8]^input[ 8]; \ - X##gu = state[ 9]^input[ 9]; \ - if (laneCount < 11) { \ - X##ka = state[10]; \ - } \ - else { \ - X##ka = state[10]^input[10]; \ - } \ - } \ - X##ke = state[11]; \ - X##ki = state[12]; \ - X##ko = state[13]; \ - X##ku = state[14]; \ - } \ - else { \ - X##go = state[ 8]^input[ 8]; \ - X##gu = state[ 9]^input[ 9]; \ - X##ka = state[10]^input[10]; \ - X##ke = state[11]^input[11]; \ - if (laneCount < 14) { \ - if (laneCount < 13) { \ - X##ki = state[12]; \ - } \ - else { \ - X##ki = state[12]^input[12]; \ - } \ - X##ko = state[13]; \ - X##ku = state[14]; \ - } \ - else { \ - X##ki = state[12]^input[12]; \ - X##ko = state[13]^input[13]; \ - if (laneCount < 15) { \ - X##ku = state[14]; \ - } \ - else { \ - X##ku = state[14]^input[14]; \ - } \ - } \ - } \ - } \ - X##ma = state[15]; \ - X##me = state[16]; \ - X##mi = state[17]; \ - X##mo = state[18]; \ - X##mu = state[19]; \ - X##sa = state[20]; \ - X##se = state[21]; \ - X##si = state[22]; \ - X##so = state[23]; \ - X##su = state[24]; \ - } \ - else { \ - X##ba = state[ 0]^input[ 0]; \ - X##be = state[ 1]^input[ 1]; \ - X##bi = state[ 2]^input[ 2]; \ - X##bo = state[ 3]^input[ 3]; \ - X##bu = state[ 4]^input[ 4]; \ - X##ga = state[ 5]^input[ 5]; \ - X##ge = state[ 6]^input[ 6]; \ - X##gi = state[ 7]^input[ 7]; \ - X##go = state[ 8]^input[ 8]; \ - X##gu = state[ 9]^input[ 9]; \ - X##ka = state[10]^input[10]; \ - X##ke = state[11]^input[11]; \ - X##ki = state[12]^input[12]; \ - X##ko = state[13]^input[13]; \ - X##ku = state[14]^input[14]; \ - X##ma = state[15]^input[15]; \ - if (laneCount < 24) { \ - if (laneCount < 20) { \ - if (laneCount < 18) { \ - if (laneCount < 17) { \ - X##me = state[16]; \ - } \ - else { \ - X##me = state[16]^input[16]; \ - } \ - X##mi = state[17]; \ - X##mo = state[18]; \ - } \ - else { \ - X##me = state[16]^input[16]; \ - X##mi = state[17]^input[17]; \ - if (laneCount < 19) { \ - X##mo = state[18]; \ - } \ - else { \ - X##mo = state[18]^input[18]; \ - } \ - } \ - X##mu = state[19]; \ - X##sa = state[20]; \ - X##se = state[21]; \ - X##si = state[22]; \ - } \ - else { \ - X##me = state[16]^input[16]; \ - X##mi = state[17]^input[17]; \ - X##mo = state[18]^input[18]; \ - X##mu = state[19]^input[19]; \ - if (laneCount < 22) { \ - if (laneCount < 21) { \ - X##sa = state[20]; \ - } \ - else { \ - X##sa = state[20]^input[20]; \ - } \ - X##se = state[21]; \ - X##si = state[22]; \ - } \ - else { \ - X##sa = state[20]^input[20]; \ - X##se = state[21]^input[21]; \ - if (laneCount < 23) { \ - X##si = state[22]; \ - } \ - else { \ - X##si = state[22]^input[22]; \ - } \ - } \ - } \ - X##so = state[23]; \ - X##su = state[24]; \ - } \ - else { \ - X##me = state[16]^input[16]; \ - X##mi = state[17]^input[17]; \ - X##mo = state[18]^input[18]; \ - X##mu = state[19]^input[19]; \ - X##sa = state[20]^input[20]; \ - X##se = state[21]^input[21]; \ - X##si = state[22]^input[22]; \ - X##so = state[23]^input[23]; \ - if (laneCount < 25) { \ - X##su = state[24]; \ - } \ - else { \ - X##su = state[24]^input[24]; \ - } \ - } \ - } - -#define addInput(X, input, laneCount) \ - if (laneCount == 21) { \ - X##ba ^= input[ 0]; \ - X##be ^= input[ 1]; \ - X##bi ^= input[ 2]; \ - X##bo ^= input[ 3]; \ - X##bu ^= input[ 4]; \ - X##ga ^= input[ 5]; \ - X##ge ^= input[ 6]; \ - X##gi ^= input[ 7]; \ - X##go ^= input[ 8]; \ - X##gu ^= input[ 9]; \ - X##ka ^= input[10]; \ - X##ke ^= input[11]; \ - X##ki ^= input[12]; \ - X##ko ^= input[13]; \ - X##ku ^= input[14]; \ - X##ma ^= input[15]; \ - X##me ^= input[16]; \ - X##mi ^= input[17]; \ - X##mo ^= input[18]; \ - X##mu ^= input[19]; \ - X##sa ^= input[20]; \ - } \ - else if (laneCount < 16) { \ - if (laneCount < 8) { \ - if (laneCount < 4) { \ - if (laneCount < 2) { \ - if (laneCount < 1) { \ - } \ - else { \ - X##ba ^= input[ 0]; \ - } \ - } \ - else { \ - X##ba ^= input[ 0]; \ - X##be ^= input[ 1]; \ - if (laneCount < 3) { \ - } \ - else { \ - X##bi ^= input[ 2]; \ - } \ - } \ - } \ - else { \ - X##ba ^= input[ 0]; \ - X##be ^= input[ 1]; \ - X##bi ^= input[ 2]; \ - X##bo ^= input[ 3]; \ - if (laneCount < 6) { \ - if (laneCount < 5) { \ - } \ - else { \ - X##bu ^= input[ 4]; \ - } \ - } \ - else { \ - X##bu ^= input[ 4]; \ - X##ga ^= input[ 5]; \ - if (laneCount < 7) { \ - } \ - else { \ - X##ge ^= input[ 6]; \ - } \ - } \ - } \ - } \ - else { \ - X##ba ^= input[ 0]; \ - X##be ^= input[ 1]; \ - X##bi ^= input[ 2]; \ - X##bo ^= input[ 3]; \ - X##bu ^= input[ 4]; \ - X##ga ^= input[ 5]; \ - X##ge ^= input[ 6]; \ - X##gi ^= input[ 7]; \ - if (laneCount < 12) { \ - if (laneCount < 10) { \ - if (laneCount < 9) { \ - } \ - else { \ - X##go ^= input[ 8]; \ - } \ - } \ - else { \ - X##go ^= input[ 8]; \ - X##gu ^= input[ 9]; \ - if (laneCount < 11) { \ - } \ - else { \ - X##ka ^= input[10]; \ - } \ - } \ - } \ - else { \ - X##go ^= input[ 8]; \ - X##gu ^= input[ 9]; \ - X##ka ^= input[10]; \ - X##ke ^= input[11]; \ - if (laneCount < 14) { \ - if (laneCount < 13) { \ - } \ - else { \ - X##ki ^= input[12]; \ - } \ - } \ - else { \ - X##ki ^= input[12]; \ - X##ko ^= input[13]; \ - if (laneCount < 15) { \ - } \ - else { \ - X##ku ^= input[14]; \ - } \ - } \ - } \ - } \ - } \ - else { \ - X##ba ^= input[ 0]; \ - X##be ^= input[ 1]; \ - X##bi ^= input[ 2]; \ - X##bo ^= input[ 3]; \ - X##bu ^= input[ 4]; \ - X##ga ^= input[ 5]; \ - X##ge ^= input[ 6]; \ - X##gi ^= input[ 7]; \ - X##go ^= input[ 8]; \ - X##gu ^= input[ 9]; \ - X##ka ^= input[10]; \ - X##ke ^= input[11]; \ - X##ki ^= input[12]; \ - X##ko ^= input[13]; \ - X##ku ^= input[14]; \ - X##ma ^= input[15]; \ - if (laneCount < 24) { \ - if (laneCount < 20) { \ - if (laneCount < 18) { \ - if (laneCount < 17) { \ - } \ - else { \ - X##me ^= input[16]; \ - } \ - } \ - else { \ - X##me ^= input[16]; \ - X##mi ^= input[17]; \ - if (laneCount < 19) { \ - } \ - else { \ - X##mo ^= input[18]; \ - } \ - } \ - } \ - else { \ - X##me ^= input[16]; \ - X##mi ^= input[17]; \ - X##mo ^= input[18]; \ - X##mu ^= input[19]; \ - if (laneCount < 22) { \ - if (laneCount < 21) { \ - } \ - else { \ - X##sa ^= input[20]; \ - } \ - } \ - else { \ - X##sa ^= input[20]; \ - X##se ^= input[21]; \ - if (laneCount < 23) { \ - } \ - else { \ - X##si ^= input[22]; \ - } \ - } \ - } \ - } \ - else { \ - X##me ^= input[16]; \ - X##mi ^= input[17]; \ - X##mo ^= input[18]; \ - X##mu ^= input[19]; \ - X##sa ^= input[20]; \ - X##se ^= input[21]; \ - X##si ^= input[22]; \ - X##so ^= input[23]; \ - if (laneCount < 25) { \ - } \ - else { \ - X##su ^= input[24]; \ - } \ - } \ - } - -#ifdef UseBebigokimisa - -#define copyToStateAndOutput(X, state, output, laneCount) \ - if (laneCount < 16) { \ - if (laneCount < 8) { \ - if (laneCount < 4) { \ - if (laneCount < 2) { \ - state[ 0] = X##ba; \ - if (laneCount >= 1) { \ - output[ 0] = X##ba; \ - } \ - state[ 1] = X##be; \ - state[ 2] = X##bi; \ - } \ - else { \ - state[ 0] = X##ba; \ - output[ 0] = X##ba; \ - state[ 1] = X##be; \ - output[ 1] = ~X##be; \ - state[ 2] = X##bi; \ - if (laneCount >= 3) { \ - output[ 2] = ~X##bi; \ - } \ - } \ - state[ 3] = X##bo; \ - state[ 4] = X##bu; \ - state[ 5] = X##ga; \ - state[ 6] = X##ge; \ - } \ - else { \ - state[ 0] = X##ba; \ - output[ 0] = X##ba; \ - state[ 1] = X##be; \ - output[ 1] = ~X##be; \ - state[ 2] = X##bi; \ - output[ 2] = ~X##bi; \ - state[ 3] = X##bo; \ - output[ 3] = X##bo; \ - if (laneCount < 6) { \ - state[ 4] = X##bu; \ - if (laneCount >= 5) { \ - output[ 4] = X##bu; \ - } \ - state[ 5] = X##ga; \ - state[ 6] = X##ge; \ - } \ - else { \ - state[ 4] = X##bu; \ - output[ 4] = X##bu; \ - state[ 5] = X##ga; \ - output[ 5] = X##ga; \ - state[ 6] = X##ge; \ - if (laneCount >= 7) { \ - output[ 6] = X##ge; \ - } \ - } \ - } \ - state[ 7] = X##gi; \ - state[ 8] = X##go; \ - state[ 9] = X##gu; \ - state[10] = X##ka; \ - state[11] = X##ke; \ - state[12] = X##ki; \ - state[13] = X##ko; \ - state[14] = X##ku; \ - } \ - else { \ - state[ 0] = X##ba; \ - output[ 0] = X##ba; \ - state[ 1] = X##be; \ - output[ 1] = ~X##be; \ - state[ 2] = X##bi; \ - output[ 2] = ~X##bi; \ - state[ 3] = X##bo; \ - output[ 3] = X##bo; \ - state[ 4] = X##bu; \ - output[ 4] = X##bu; \ - state[ 5] = X##ga; \ - output[ 5] = X##ga; \ - state[ 6] = X##ge; \ - output[ 6] = X##ge; \ - state[ 7] = X##gi; \ - output[ 7] = X##gi; \ - if (laneCount < 12) { \ - if (laneCount < 10) { \ - state[ 8] = X##go; \ - if (laneCount >= 9) { \ - output[ 8] = ~X##go; \ - } \ - state[ 9] = X##gu; \ - state[10] = X##ka; \ - } \ - else { \ - state[ 8] = X##go; \ - output[ 8] = ~X##go; \ - state[ 9] = X##gu; \ - output[ 9] = X##gu; \ - state[10] = X##ka; \ - if (laneCount >= 11) { \ - output[10] = X##ka; \ - } \ - } \ - state[11] = X##ke; \ - state[12] = X##ki; \ - state[13] = X##ko; \ - state[14] = X##ku; \ - } \ - else { \ - state[ 8] = X##go; \ - output[ 8] = ~X##go; \ - state[ 9] = X##gu; \ - output[ 9] = X##gu; \ - state[10] = X##ka; \ - output[10] = X##ka; \ - state[11] = X##ke; \ - output[11] = X##ke; \ - if (laneCount < 14) { \ - state[12] = X##ki; \ - if (laneCount >= 13) { \ - output[12] = ~X##ki; \ - } \ - state[13] = X##ko; \ - state[14] = X##ku; \ - } \ - else { \ - state[12] = X##ki; \ - output[12] = ~X##ki; \ - state[13] = X##ko; \ - output[13] = X##ko; \ - state[14] = X##ku; \ - if (laneCount >= 15) { \ - output[14] = X##ku; \ - } \ - } \ - } \ - } \ - state[15] = X##ma; \ - state[16] = X##me; \ - state[17] = X##mi; \ - state[18] = X##mo; \ - state[19] = X##mu; \ - state[20] = X##sa; \ - state[21] = X##se; \ - state[22] = X##si; \ - state[23] = X##so; \ - state[24] = X##su; \ - } \ - else { \ - state[ 0] = X##ba; \ - output[ 0] = X##ba; \ - state[ 1] = X##be; \ - output[ 1] = ~X##be; \ - state[ 2] = X##bi; \ - output[ 2] = ~X##bi; \ - state[ 3] = X##bo; \ - output[ 3] = X##bo; \ - state[ 4] = X##bu; \ - output[ 4] = X##bu; \ - state[ 5] = X##ga; \ - output[ 5] = X##ga; \ - state[ 6] = X##ge; \ - output[ 6] = X##ge; \ - state[ 7] = X##gi; \ - output[ 7] = X##gi; \ - state[ 8] = X##go; \ - output[ 8] = ~X##go; \ - state[ 9] = X##gu; \ - output[ 9] = X##gu; \ - state[10] = X##ka; \ - output[10] = X##ka; \ - state[11] = X##ke; \ - output[11] = X##ke; \ - state[12] = X##ki; \ - output[12] = ~X##ki; \ - state[13] = X##ko; \ - output[13] = X##ko; \ - state[14] = X##ku; \ - output[14] = X##ku; \ - state[15] = X##ma; \ - output[15] = X##ma; \ - if (laneCount < 24) { \ - if (laneCount < 20) { \ - if (laneCount < 18) { \ - state[16] = X##me; \ - if (laneCount >= 17) { \ - output[16] = X##me; \ - } \ - state[17] = X##mi; \ - state[18] = X##mo; \ - } \ - else { \ - state[16] = X##me; \ - output[16] = X##me; \ - state[17] = X##mi; \ - output[17] = ~X##mi; \ - state[18] = X##mo; \ - if (laneCount >= 19) { \ - output[18] = X##mo; \ - } \ - } \ - state[19] = X##mu; \ - state[20] = X##sa; \ - state[21] = X##se; \ - state[22] = X##si; \ - } \ - else { \ - state[16] = X##me; \ - output[16] = X##me; \ - state[17] = X##mi; \ - output[17] = ~X##mi; \ - state[18] = X##mo; \ - output[18] = X##mo; \ - state[19] = X##mu; \ - output[19] = X##mu; \ - if (laneCount < 22) { \ - state[20] = X##sa; \ - if (laneCount >= 21) { \ - output[20] = ~X##sa; \ - } \ - state[21] = X##se; \ - state[22] = X##si; \ - } \ - else { \ - state[20] = X##sa; \ - output[20] = ~X##sa; \ - state[21] = X##se; \ - output[21] = X##se; \ - state[22] = X##si; \ - if (laneCount >= 23) { \ - output[22] = X##si; \ - } \ - } \ - } \ - state[23] = X##so; \ - state[24] = X##su; \ - } \ - else { \ - state[16] = X##me; \ - output[16] = X##me; \ - state[17] = X##mi; \ - output[17] = ~X##mi; \ - state[18] = X##mo; \ - output[18] = X##mo; \ - state[19] = X##mu; \ - output[19] = X##mu; \ - state[20] = X##sa; \ - output[20] = ~X##sa; \ - state[21] = X##se; \ - output[21] = X##se; \ - state[22] = X##si; \ - output[22] = X##si; \ - state[23] = X##so; \ - output[23] = X##so; \ - state[24] = X##su; \ - if (laneCount >= 25) { \ - output[24] = X##su; \ - } \ - } \ - } - -#define output(X, output, laneCount) \ - if (laneCount < 16) { \ - if (laneCount < 8) { \ - if (laneCount < 4) { \ - if (laneCount < 2) { \ - if (laneCount >= 1) { \ - output[ 0] = X##ba; \ - } \ - } \ - else { \ - output[ 0] = X##ba; \ - output[ 1] = ~X##be; \ - if (laneCount >= 3) { \ - output[ 2] = ~X##bi; \ - } \ - } \ - } \ - else { \ - output[ 0] = X##ba; \ - output[ 1] = ~X##be; \ - output[ 2] = ~X##bi; \ - output[ 3] = X##bo; \ - if (laneCount < 6) { \ - if (laneCount >= 5) { \ - output[ 4] = X##bu; \ - } \ - } \ - else { \ - output[ 4] = X##bu; \ - output[ 5] = X##ga; \ - if (laneCount >= 7) { \ - output[ 6] = X##ge; \ - } \ - } \ - } \ - } \ - else { \ - output[ 0] = X##ba; \ - output[ 1] = ~X##be; \ - output[ 2] = ~X##bi; \ - output[ 3] = X##bo; \ - output[ 4] = X##bu; \ - output[ 5] = X##ga; \ - output[ 6] = X##ge; \ - output[ 7] = X##gi; \ - if (laneCount < 12) { \ - if (laneCount < 10) { \ - if (laneCount >= 9) { \ - output[ 8] = ~X##go; \ - } \ - } \ - else { \ - output[ 8] = ~X##go; \ - output[ 9] = X##gu; \ - if (laneCount >= 11) { \ - output[10] = X##ka; \ - } \ - } \ - } \ - else { \ - output[ 8] = ~X##go; \ - output[ 9] = X##gu; \ - output[10] = X##ka; \ - output[11] = X##ke; \ - if (laneCount < 14) { \ - if (laneCount >= 13) { \ - output[12] = ~X##ki; \ - } \ - } \ - else { \ - output[12] = ~X##ki; \ - output[13] = X##ko; \ - if (laneCount >= 15) { \ - output[14] = X##ku; \ - } \ - } \ - } \ - } \ - } \ - else { \ - output[ 0] = X##ba; \ - output[ 1] = ~X##be; \ - output[ 2] = ~X##bi; \ - output[ 3] = X##bo; \ - output[ 4] = X##bu; \ - output[ 5] = X##ga; \ - output[ 6] = X##ge; \ - output[ 7] = X##gi; \ - output[ 8] = ~X##go; \ - output[ 9] = X##gu; \ - output[10] = X##ka; \ - output[11] = X##ke; \ - output[12] = ~X##ki; \ - output[13] = X##ko; \ - output[14] = X##ku; \ - output[15] = X##ma; \ - if (laneCount < 24) { \ - if (laneCount < 20) { \ - if (laneCount < 18) { \ - if (laneCount >= 17) { \ - output[16] = X##me; \ - } \ - } \ - else { \ - output[16] = X##me; \ - output[17] = ~X##mi; \ - if (laneCount >= 19) { \ - output[18] = X##mo; \ - } \ - } \ - } \ - else { \ - output[16] = X##me; \ - output[17] = ~X##mi; \ - output[18] = X##mo; \ - output[19] = X##mu; \ - if (laneCount < 22) { \ - if (laneCount >= 21) { \ - output[20] = ~X##sa; \ - } \ - } \ - else { \ - output[20] = ~X##sa; \ - output[21] = X##se; \ - if (laneCount >= 23) { \ - output[22] = X##si; \ - } \ - } \ - } \ - } \ - else { \ - output[16] = X##me; \ - output[17] = ~X##mi; \ - output[18] = X##mo; \ - output[19] = X##mu; \ - output[20] = ~X##sa; \ - output[21] = X##se; \ - output[22] = X##si; \ - output[23] = X##so; \ - if (laneCount >= 25) { \ - output[24] = X##su; \ - } \ - } \ - } - -#define wrapOne(X, input, output, index, name) \ - X##name ^= input[index]; \ - output[index] = X##name; - -#define wrapOneInvert(X, input, output, index, name) \ - X##name ^= input[index]; \ - output[index] = ~X##name; - -#define unwrapOne(X, input, output, index, name) \ - output[index] = input[index] ^ X##name; \ - X##name ^= output[index]; - -#define unwrapOneInvert(X, input, output, index, name) \ - output[index] = ~(input[index] ^ X##name); \ - X##name ^= output[index]; \ - -#else /* UseBebigokimisa */ - - -#define copyToStateAndOutput(X, state, output, laneCount) \ - if (laneCount < 16) { \ - if (laneCount < 8) { \ - if (laneCount < 4) { \ - if (laneCount < 2) { \ - state[ 0] = X##ba; \ - if (laneCount >= 1) { \ - output[ 0] = X##ba; \ - } \ - state[ 1] = X##be; \ - state[ 2] = X##bi; \ - } \ - else { \ - state[ 0] = X##ba; \ - output[ 0] = X##ba; \ - state[ 1] = X##be; \ - output[ 1] = X##be; \ - state[ 2] = X##bi; \ - if (laneCount >= 3) { \ - output[ 2] = X##bi; \ - } \ - } \ - state[ 3] = X##bo; \ - state[ 4] = X##bu; \ - state[ 5] = X##ga; \ - state[ 6] = X##ge; \ - } \ - else { \ - state[ 0] = X##ba; \ - output[ 0] = X##ba; \ - state[ 1] = X##be; \ - output[ 1] = X##be; \ - state[ 2] = X##bi; \ - output[ 2] = X##bi; \ - state[ 3] = X##bo; \ - output[ 3] = X##bo; \ - if (laneCount < 6) { \ - state[ 4] = X##bu; \ - if (laneCount >= 5) { \ - output[ 4] = X##bu; \ - } \ - state[ 5] = X##ga; \ - state[ 6] = X##ge; \ - } \ - else { \ - state[ 4] = X##bu; \ - output[ 4] = X##bu; \ - state[ 5] = X##ga; \ - output[ 5] = X##ga; \ - state[ 6] = X##ge; \ - if (laneCount >= 7) { \ - output[ 6] = X##ge; \ - } \ - } \ - } \ - state[ 7] = X##gi; \ - state[ 8] = X##go; \ - state[ 9] = X##gu; \ - state[10] = X##ka; \ - state[11] = X##ke; \ - state[12] = X##ki; \ - state[13] = X##ko; \ - state[14] = X##ku; \ - } \ - else { \ - state[ 0] = X##ba; \ - output[ 0] = X##ba; \ - state[ 1] = X##be; \ - output[ 1] = X##be; \ - state[ 2] = X##bi; \ - output[ 2] = X##bi; \ - state[ 3] = X##bo; \ - output[ 3] = X##bo; \ - state[ 4] = X##bu; \ - output[ 4] = X##bu; \ - state[ 5] = X##ga; \ - output[ 5] = X##ga; \ - state[ 6] = X##ge; \ - output[ 6] = X##ge; \ - state[ 7] = X##gi; \ - output[ 7] = X##gi; \ - if (laneCount < 12) { \ - if (laneCount < 10) { \ - state[ 8] = X##go; \ - if (laneCount >= 9) { \ - output[ 8] = X##go; \ - } \ - state[ 9] = X##gu; \ - state[10] = X##ka; \ - } \ - else { \ - state[ 8] = X##go; \ - output[ 8] = X##go; \ - state[ 9] = X##gu; \ - output[ 9] = X##gu; \ - state[10] = X##ka; \ - if (laneCount >= 11) { \ - output[10] = X##ka; \ - } \ - } \ - state[11] = X##ke; \ - state[12] = X##ki; \ - state[13] = X##ko; \ - state[14] = X##ku; \ - } \ - else { \ - state[ 8] = X##go; \ - output[ 8] = X##go; \ - state[ 9] = X##gu; \ - output[ 9] = X##gu; \ - state[10] = X##ka; \ - output[10] = X##ka; \ - state[11] = X##ke; \ - output[11] = X##ke; \ - if (laneCount < 14) { \ - state[12] = X##ki; \ - if (laneCount >= 13) { \ - output[12]= X##ki; \ - } \ - state[13] = X##ko; \ - state[14] = X##ku; \ - } \ - else { \ - state[12] = X##ki; \ - output[12]= X##ki; \ - state[13] = X##ko; \ - output[13] = X##ko; \ - state[14] = X##ku; \ - if (laneCount >= 15) { \ - output[14] = X##ku; \ - } \ - } \ - } \ - } \ - state[15] = X##ma; \ - state[16] = X##me; \ - state[17] = X##mi; \ - state[18] = X##mo; \ - state[19] = X##mu; \ - state[20] = X##sa; \ - state[21] = X##se; \ - state[22] = X##si; \ - state[23] = X##so; \ - state[24] = X##su; \ - } \ - else { \ - state[ 0] = X##ba; \ - output[ 0] = X##ba; \ - state[ 1] = X##be; \ - output[ 1] = X##be; \ - state[ 2] = X##bi; \ - output[ 2] = X##bi; \ - state[ 3] = X##bo; \ - output[ 3] = X##bo; \ - state[ 4] = X##bu; \ - output[ 4] = X##bu; \ - state[ 5] = X##ga; \ - output[ 5] = X##ga; \ - state[ 6] = X##ge; \ - output[ 6] = X##ge; \ - state[ 7] = X##gi; \ - output[ 7] = X##gi; \ - state[ 8] = X##go; \ - output[ 8] = X##go; \ - state[ 9] = X##gu; \ - output[ 9] = X##gu; \ - state[10] = X##ka; \ - output[10] = X##ka; \ - state[11] = X##ke; \ - output[11] = X##ke; \ - state[12] = X##ki; \ - output[12]= X##ki; \ - state[13] = X##ko; \ - output[13] = X##ko; \ - state[14] = X##ku; \ - output[14] = X##ku; \ - state[15] = X##ma; \ - output[15] = X##ma; \ - if (laneCount < 24) { \ - if (laneCount < 20) { \ - if (laneCount < 18) { \ - state[16] = X##me; \ - if (laneCount >= 17) { \ - output[16] = X##me; \ - } \ - state[17] = X##mi; \ - state[18] = X##mo; \ - } \ - else { \ - state[16] = X##me; \ - output[16] = X##me; \ - state[17] = X##mi; \ - output[17] = X##mi; \ - state[18] = X##mo; \ - if (laneCount >= 19) { \ - output[18] = X##mo; \ - } \ - } \ - state[19] = X##mu; \ - state[20] = X##sa; \ - state[21] = X##se; \ - state[22] = X##si; \ - } \ - else { \ - state[16] = X##me; \ - output[16] = X##me; \ - state[17] = X##mi; \ - output[17] = X##mi; \ - state[18] = X##mo; \ - output[18] = X##mo; \ - state[19] = X##mu; \ - output[19] = X##mu; \ - if (laneCount < 22) { \ - state[20] = X##sa; \ - if (laneCount >= 21) { \ - output[20] = X##sa; \ - } \ - state[21] = X##se; \ - state[22] = X##si; \ - } \ - else { \ - state[20] = X##sa; \ - output[20] = X##sa; \ - state[21] = X##se; \ - output[21] = X##se; \ - state[22] = X##si; \ - if (laneCount >= 23) { \ - output[22] = X##si; \ - } \ - } \ - } \ - state[23] = X##so; \ - state[24] = X##su; \ - } \ - else { \ - state[16] = X##me; \ - output[16] = X##me; \ - state[17] = X##mi; \ - output[17] = X##mi; \ - state[18] = X##mo; \ - output[18] = X##mo; \ - state[19] = X##mu; \ - output[19] = X##mu; \ - state[20] = X##sa; \ - output[20] = X##sa; \ - state[21] = X##se; \ - output[21] = X##se; \ - state[22] = X##si; \ - output[22] = X##si; \ - state[23] = X##so; \ - output[23] = X##so; \ - state[24] = X##su; \ - if (laneCount >= 25) { \ - output[24] = X##su; \ - } \ - } \ - } - -#define output(X, output, laneCount) \ - if (laneCount < 16) { \ - if (laneCount < 8) { \ - if (laneCount < 4) { \ - if (laneCount < 2) { \ - if (laneCount >= 1) { \ - output[ 0] = X##ba; \ - } \ - } \ - else { \ - output[ 0] = X##ba; \ - output[ 1] = X##be; \ - if (laneCount >= 3) { \ - output[ 2] = X##bi; \ - } \ - } \ - } \ - else { \ - output[ 0] = X##ba; \ - output[ 1] = X##be; \ - output[ 2] = X##bi; \ - output[ 3] = X##bo; \ - if (laneCount < 6) { \ - if (laneCount >= 5) { \ - output[ 4] = X##bu; \ - } \ - } \ - else { \ - output[ 4] = X##bu; \ - output[ 5] = X##ga; \ - if (laneCount >= 7) { \ - output[ 6] = X##ge; \ - } \ - } \ - } \ - } \ - else { \ - output[ 0] = X##ba; \ - output[ 1] = X##be; \ - output[ 2] = X##bi; \ - output[ 3] = X##bo; \ - output[ 4] = X##bu; \ - output[ 5] = X##ga; \ - output[ 6] = X##ge; \ - output[ 7] = X##gi; \ - if (laneCount < 12) { \ - if (laneCount < 10) { \ - if (laneCount >= 9) { \ - output[ 8] = X##go; \ - } \ - } \ - else { \ - output[ 8] = X##go; \ - output[ 9] = X##gu; \ - if (laneCount >= 11) { \ - output[10] = X##ka; \ - } \ - } \ - } \ - else { \ - output[ 8] = X##go; \ - output[ 9] = X##gu; \ - output[10] = X##ka; \ - output[11] = X##ke; \ - if (laneCount < 14) { \ - if (laneCount >= 13) { \ - output[12] = X##ki; \ - } \ - } \ - else { \ - output[12] = X##ki; \ - output[13] = X##ko; \ - if (laneCount >= 15) { \ - output[14] = X##ku; \ - } \ - } \ - } \ - } \ - } \ - else { \ - output[ 0] = X##ba; \ - output[ 1] = X##be; \ - output[ 2] = X##bi; \ - output[ 3] = X##bo; \ - output[ 4] = X##bu; \ - output[ 5] = X##ga; \ - output[ 6] = X##ge; \ - output[ 7] = X##gi; \ - output[ 8] = X##go; \ - output[ 9] = X##gu; \ - output[10] = X##ka; \ - output[11] = X##ke; \ - output[12] = X##ki; \ - output[13] = X##ko; \ - output[14] = X##ku; \ - output[15] = X##ma; \ - if (laneCount < 24) { \ - if (laneCount < 20) { \ - if (laneCount < 18) { \ - if (laneCount >= 17) { \ - output[16] = X##me; \ - } \ - } \ - else { \ - output[16] = X##me; \ - output[17] = X##mi; \ - if (laneCount >= 19) { \ - output[18] = X##mo; \ - } \ - } \ - } \ - else { \ - output[16] = X##me; \ - output[17] = X##mi; \ - output[18] = X##mo; \ - output[19] = X##mu; \ - if (laneCount < 22) { \ - if (laneCount >= 21) { \ - output[20] = X##sa; \ - } \ - } \ - else { \ - output[20] = X##sa; \ - output[21] = X##se; \ - if (laneCount >= 23) { \ - output[22] = X##si; \ - } \ - } \ - } \ - } \ - else { \ - output[16] = X##me; \ - output[17] = X##mi; \ - output[18] = X##mo; \ - output[19] = X##mu; \ - output[20] = X##sa; \ - output[21] = X##se; \ - output[22] = X##si; \ - output[23] = X##so; \ - if (laneCount >= 25) { \ - output[24] = X##su; \ - } \ - } \ - } - -#define wrapOne(X, input, output, index, name) \ - X##name ^= input[index]; \ - output[index] = X##name; - -#define wrapOneInvert(X, input, output, index, name) \ - X##name ^= input[index]; \ - output[index] = X##name; - -#define unwrapOne(X, input, output, index, name) \ - output[index] = input[index] ^ X##name; \ - X##name ^= output[index]; - -#define unwrapOneInvert(X, input, output, index, name) \ - output[index] = input[index] ^ X##name; \ - X##name ^= output[index]; - -#endif - -#define wrap(X, input, output, laneCount, trailingBits) \ - if (laneCount < 16) { \ - if (laneCount < 8) { \ - if (laneCount < 4) { \ - if (laneCount < 2) { \ - if (laneCount < 1) { \ - X##ba ^= trailingBits; \ - } \ - else { \ - wrapOne(X, input, output, 0, ba) \ - X##be ^= trailingBits; \ - } \ - } \ - else { \ - wrapOne(X, input, output, 0, ba) \ - wrapOneInvert(X, input, output, 1, be) \ - if (laneCount < 3) { \ - X##bi ^= trailingBits; \ - } \ - else { \ - wrapOneInvert(X, input, output, 2, bi) \ - X##bo ^= trailingBits; \ - } \ - } \ - } \ - else { \ - wrapOne(X, input, output, 0, ba) \ - wrapOneInvert(X, input, output, 1, be) \ - wrapOneInvert(X, input, output, 2, bi) \ - wrapOne(X, input, output, 3, bo) \ - if (laneCount < 6) { \ - if (laneCount < 5) { \ - X##bu ^= trailingBits; \ - } \ - else { \ - wrapOne(X, input, output, 4, bu) \ - X##ga ^= trailingBits; \ - } \ - } \ - else { \ - wrapOne(X, input, output, 4, bu) \ - wrapOne(X, input, output, 5, ga) \ - if (laneCount < 7) { \ - X##ge ^= trailingBits; \ - } \ - else { \ - wrapOne(X, input, output, 6, ge) \ - X##gi ^= trailingBits; \ - } \ - } \ - } \ - } \ - else { \ - wrapOne(X, input, output, 0, ba) \ - wrapOneInvert(X, input, output, 1, be) \ - wrapOneInvert(X, input, output, 2, bi) \ - wrapOne(X, input, output, 3, bo) \ - wrapOne(X, input, output, 4, bu) \ - wrapOne(X, input, output, 5, ga) \ - wrapOne(X, input, output, 6, ge) \ - wrapOne(X, input, output, 7, gi) \ - if (laneCount < 12) { \ - if (laneCount < 10) { \ - if (laneCount < 9) { \ - X##go ^= trailingBits; \ - } \ - else { \ - wrapOneInvert(X, input, output, 8, go) \ - X##gu ^= trailingBits; \ - } \ - } \ - else { \ - wrapOneInvert(X, input, output, 8, go) \ - wrapOne(X, input, output, 9, gu) \ - if (laneCount < 11) { \ - X##ka ^= trailingBits; \ - } \ - else { \ - wrapOne(X, input, output, 10, ka) \ - X##ke ^= trailingBits; \ - } \ - } \ - } \ - else { \ - wrapOneInvert(X, input, output, 8, go) \ - wrapOne(X, input, output, 9, gu) \ - wrapOne(X, input, output, 10, ka) \ - wrapOne(X, input, output, 11, ke) \ - if (laneCount < 14) { \ - if (laneCount < 13) { \ - X##ki ^= trailingBits; \ - } \ - else { \ - wrapOneInvert(X, input, output, 12, ki) \ - X##ko ^= trailingBits; \ - } \ - } \ - else { \ - wrapOneInvert(X, input, output, 12, ki) \ - wrapOne(X, input, output, 13, ko) \ - if (laneCount < 15) { \ - X##ku ^= trailingBits; \ - } \ - else { \ - wrapOne(X, input, output, 14, ku) \ - X##ma ^= trailingBits; \ - } \ - } \ - } \ - } \ - } \ - else { \ - wrapOne(X, input, output, 0, ba) \ - wrapOneInvert(X, input, output, 1, be) \ - wrapOneInvert(X, input, output, 2, bi) \ - wrapOne(X, input, output, 3, bo) \ - wrapOne(X, input, output, 4, bu) \ - wrapOne(X, input, output, 5, ga) \ - wrapOne(X, input, output, 6, ge) \ - wrapOne(X, input, output, 7, gi) \ - wrapOneInvert(X, input, output, 8, go) \ - wrapOne(X, input, output, 9, gu) \ - wrapOne(X, input, output, 10, ka) \ - wrapOne(X, input, output, 11, ke) \ - wrapOneInvert(X, input, output, 12, ki) \ - wrapOne(X, input, output, 13, ko) \ - wrapOne(X, input, output, 14, ku) \ - wrapOne(X, input, output, 15, ma) \ - if (laneCount < 24) { \ - if (laneCount < 20) { \ - if (laneCount < 18) { \ - if (laneCount < 17) { \ - X##me ^= trailingBits; \ - } \ - else { \ - wrapOne(X, input, output, 16, me) \ - X##mi ^= trailingBits; \ - } \ - } \ - else { \ - wrapOne(X, input, output, 16, me) \ - wrapOneInvert(X, input, output, 17, mi) \ - if (laneCount < 19) { \ - X##mo ^= trailingBits; \ - } \ - else { \ - wrapOne(X, input, output, 18, mo) \ - X##mu ^= trailingBits; \ - } \ - } \ - } \ - else { \ - wrapOne(X, input, output, 16, me) \ - wrapOneInvert(X, input, output, 17, mi) \ - wrapOne(X, input, output, 18, mo) \ - wrapOne(X, input, output, 19, mu) \ - if (laneCount < 22) { \ - if (laneCount < 21) { \ - X##sa ^= trailingBits; \ - } \ - else { \ - wrapOneInvert(X, input, output, 20, sa) \ - X##se ^= trailingBits; \ - } \ - } \ - else { \ - wrapOneInvert(X, input, output, 20, sa) \ - wrapOne(X, input, output, 21, se) \ - if (laneCount < 23) { \ - X##si ^= trailingBits; \ - } \ - else { \ - wrapOne(X, input, output, 22, si) \ - X##so ^= trailingBits; \ - } \ - } \ - } \ - } \ - else { \ - wrapOne(X, input, output, 16, me) \ - wrapOneInvert(X, input, output, 17, mi) \ - wrapOne(X, input, output, 18, mo) \ - wrapOne(X, input, output, 19, mu) \ - wrapOneInvert(X, input, output, 20, sa) \ - wrapOne(X, input, output, 21, se) \ - wrapOne(X, input, output, 22, si) \ - wrapOne(X, input, output, 23, so) \ - if (laneCount < 25) { \ - X##su ^= trailingBits; \ - } \ - else { \ - wrapOne(X, input, output, 24, su) \ - } \ - } \ - } - -#define unwrap(X, input, output, laneCount, trailingBits) \ - if (laneCount < 16) { \ - if (laneCount < 8) { \ - if (laneCount < 4) { \ - if (laneCount < 2) { \ - if (laneCount < 1) { \ - X##ba ^= trailingBits; \ - } \ - else { \ - unwrapOne(X, input, output, 0, ba) \ - X##be ^= trailingBits; \ - } \ - } \ - else { \ - unwrapOne(X, input, output, 0, ba) \ - unwrapOneInvert(X, input, output, 1, be) \ - if (laneCount < 3) { \ - X##bi ^= trailingBits; \ - } \ - else { \ - unwrapOneInvert(X, input, output, 2, bi) \ - X##bo ^= trailingBits; \ - } \ - } \ - } \ - else { \ - unwrapOne(X, input, output, 0, ba) \ - unwrapOneInvert(X, input, output, 1, be) \ - unwrapOneInvert(X, input, output, 2, bi) \ - unwrapOne(X, input, output, 3, bo) \ - if (laneCount < 6) { \ - if (laneCount < 5) { \ - X##bu ^= trailingBits; \ - } \ - else { \ - unwrapOne(X, input, output, 4, bu) \ - X##ga ^= trailingBits; \ - } \ - } \ - else { \ - unwrapOne(X, input, output, 4, bu) \ - unwrapOne(X, input, output, 5, ga) \ - if (laneCount < 7) { \ - X##ge ^= trailingBits; \ - } \ - else { \ - unwrapOne(X, input, output, 6, ge) \ - X##gi ^= trailingBits; \ - } \ - } \ - } \ - } \ - else { \ - unwrapOne(X, input, output, 0, ba) \ - unwrapOneInvert(X, input, output, 1, be) \ - unwrapOneInvert(X, input, output, 2, bi) \ - unwrapOne(X, input, output, 3, bo) \ - unwrapOne(X, input, output, 4, bu) \ - unwrapOne(X, input, output, 5, ga) \ - unwrapOne(X, input, output, 6, ge) \ - unwrapOne(X, input, output, 7, gi) \ - if (laneCount < 12) { \ - if (laneCount < 10) { \ - if (laneCount < 9) { \ - X##go ^= trailingBits; \ - } \ - else { \ - unwrapOneInvert(X, input, output, 8, go) \ - X##gu ^= trailingBits; \ - } \ - } \ - else { \ - unwrapOneInvert(X, input, output, 8, go) \ - unwrapOne(X, input, output, 9, gu) \ - if (laneCount < 11) { \ - X##ka ^= trailingBits; \ - } \ - else { \ - unwrapOne(X, input, output, 10, ka) \ - X##ke ^= trailingBits; \ - } \ - } \ - } \ - else { \ - unwrapOneInvert(X, input, output, 8, go) \ - unwrapOne(X, input, output, 9, gu) \ - unwrapOne(X, input, output, 10, ka) \ - unwrapOne(X, input, output, 11, ke) \ - if (laneCount < 14) { \ - if (laneCount < 13) { \ - X##ki ^= trailingBits; \ - } \ - else { \ - unwrapOneInvert(X, input, output, 12, ki) \ - X##ko ^= trailingBits; \ - } \ - } \ - else { \ - unwrapOneInvert(X, input, output, 12, ki) \ - unwrapOne(X, input, output, 13, ko) \ - if (laneCount < 15) { \ - X##ku ^= trailingBits; \ - } \ - else { \ - unwrapOne(X, input, output, 14, ku) \ - X##ma ^= trailingBits; \ - } \ - } \ - } \ - } \ - } \ - else { \ - unwrapOne(X, input, output, 0, ba) \ - unwrapOneInvert(X, input, output, 1, be) \ - unwrapOneInvert(X, input, output, 2, bi) \ - unwrapOne(X, input, output, 3, bo) \ - unwrapOne(X, input, output, 4, bu) \ - unwrapOne(X, input, output, 5, ga) \ - unwrapOne(X, input, output, 6, ge) \ - unwrapOne(X, input, output, 7, gi) \ - unwrapOneInvert(X, input, output, 8, go) \ - unwrapOne(X, input, output, 9, gu) \ - unwrapOne(X, input, output, 10, ka) \ - unwrapOne(X, input, output, 11, ke) \ - unwrapOneInvert(X, input, output, 12, ki) \ - unwrapOne(X, input, output, 13, ko) \ - unwrapOne(X, input, output, 14, ku) \ - unwrapOne(X, input, output, 15, ma) \ - if (laneCount < 24) { \ - if (laneCount < 20) { \ - if (laneCount < 18) { \ - if (laneCount < 17) { \ - X##me ^= trailingBits; \ - } \ - else { \ - unwrapOne(X, input, output, 16, me) \ - X##mi ^= trailingBits; \ - } \ - } \ - else { \ - unwrapOne(X, input, output, 16, me) \ - unwrapOneInvert(X, input, output, 17, mi) \ - if (laneCount < 19) { \ - X##mo ^= trailingBits; \ - } \ - else { \ - unwrapOne(X, input, output, 18, mo) \ - X##mu ^= trailingBits; \ - } \ - } \ - } \ - else { \ - unwrapOne(X, input, output, 16, me) \ - unwrapOneInvert(X, input, output, 17, mi) \ - unwrapOne(X, input, output, 18, mo) \ - unwrapOne(X, input, output, 19, mu) \ - if (laneCount < 22) { \ - if (laneCount < 21) { \ - X##sa ^= trailingBits; \ - } \ - else { \ - unwrapOneInvert(X, input, output, 20, sa) \ - X##se ^= trailingBits; \ - } \ - } \ - else { \ - unwrapOneInvert(X, input, output, 20, sa) \ - unwrapOne(X, input, output, 21, se) \ - if (laneCount < 23) { \ - X##si ^= trailingBits; \ - } \ - else { \ - unwrapOne(X, input, output, 22, si) \ - X##so ^= trailingBits; \ - } \ - } \ - } \ - } \ - else { \ - unwrapOne(X, input, output, 16, me) \ - unwrapOneInvert(X, input, output, 17, mi) \ - unwrapOne(X, input, output, 18, mo) \ - unwrapOne(X, input, output, 19, mu) \ - unwrapOneInvert(X, input, output, 20, sa) \ - unwrapOne(X, input, output, 21, se) \ - unwrapOne(X, input, output, 22, si) \ - unwrapOne(X, input, output, 23, so) \ - if (laneCount < 25) { \ - X##su ^= trailingBits; \ - } \ - else { \ - unwrapOne(X, input, output, 24, su) \ - } \ - } \ - } diff --git a/third_party/python/Modules/_sha3/kcp/KeccakP-1600-SnP-opt32.h b/third_party/python/Modules/_sha3/kcp/KeccakP-1600-SnP-opt32.h deleted file mode 100644 index 59b740324..000000000 --- a/third_party/python/Modules/_sha3/kcp/KeccakP-1600-SnP-opt32.h +++ /dev/null @@ -1,38 +0,0 @@ -/* clang-format off */ -/* -Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni, -Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby -denoted as "the implementer". - -For more information, feedback or questions, please refer to our websites: -http://keccak.noekeon.org/ -http://keyak.noekeon.org/ -http://ketje.noekeon.org/ - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#ifndef _KeccakP_1600_SnP_h_ -#define _KeccakP_1600_SnP_h_ - -/** For the documentation, see SnP-documentation.h. - */ - -#define KeccakP1600_implementation "in-place 32-bit optimized implementation" -#define KeccakP1600_stateSizeInBytes 200 -#define KeccakP1600_stateAlignment 8 - -#define KeccakP1600_StaticInitialize() -void KeccakP1600_Initialize(void *state); -void KeccakP1600_AddByte(void *state, unsigned char data, unsigned int offset); -void KeccakP1600_AddBytes(void *state, const unsigned char *data, unsigned int offset, unsigned int length); -void KeccakP1600_OverwriteBytes(void *state, const unsigned char *data, unsigned int offset, unsigned int length); -void KeccakP1600_OverwriteWithZeroes(void *state, unsigned int byteCount); -void KeccakP1600_Permute_12rounds(void *state); -void KeccakP1600_Permute_24rounds(void *state); -void KeccakP1600_ExtractBytes(const void *state, unsigned char *data, unsigned int offset, unsigned int length); -void KeccakP1600_ExtractAndAddBytes(const void *state, const unsigned char *input, unsigned char *output, unsigned int offset, unsigned int length); - -#endif diff --git a/third_party/python/Modules/_sha3/kcp/KeccakP-1600-SnP-opt64.h b/third_party/python/Modules/_sha3/kcp/KeccakP-1600-SnP-opt64.h deleted file mode 100644 index d2e69983f..000000000 --- a/third_party/python/Modules/_sha3/kcp/KeccakP-1600-SnP-opt64.h +++ /dev/null @@ -1,48 +0,0 @@ -/* clang-format off */ -/* -Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni, -Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby -denoted as "the implementer". - -For more information, feedback or questions, please refer to our websites: -http://keccak.noekeon.org/ -http://keyak.noekeon.org/ -http://ketje.noekeon.org/ - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#ifndef _KeccakP_1600_SnP_h_ -#define _KeccakP_1600_SnP_h_ - -/** For the documentation, see SnP-documentation.h. - */ - -/* #include "brg_endian.h" */ -#include "KeccakP-1600-opt64-config.h" - -#define KeccakP1600_implementation "generic 64-bit optimized implementation (" KeccakP1600_implementation_config ")" -#define KeccakP1600_stateSizeInBytes 200 -#define KeccakP1600_stateAlignment 8 -#define KeccakF1600_FastLoop_supported - -#define KeccakP1600_StaticInitialize() -void KeccakP1600_Initialize(void *state); -#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN) -#define KeccakP1600_AddByte(state, byte, offset) \ - ((unsigned char*)(state))[(offset)] ^= (byte) -#else -void KeccakP1600_AddByte(void *state, unsigned char data, unsigned int offset); -#endif -void KeccakP1600_AddBytes(void *state, const unsigned char *data, unsigned int offset, unsigned int length); -void KeccakP1600_OverwriteBytes(void *state, const unsigned char *data, unsigned int offset, unsigned int length); -void KeccakP1600_OverwriteWithZeroes(void *state, unsigned int byteCount); -void KeccakP1600_Permute_12rounds(void *state); -void KeccakP1600_Permute_24rounds(void *state); -void KeccakP1600_ExtractBytes(const void *state, unsigned char *data, unsigned int offset, unsigned int length); -void KeccakP1600_ExtractAndAddBytes(const void *state, const unsigned char *input, unsigned char *output, unsigned int offset, unsigned int length); -size_t KeccakF1600_FastLoop_Absorb(void *state, unsigned int laneCount, const unsigned char *data, size_t dataByteLen); - -#endif diff --git a/third_party/python/Modules/_sha3/kcp/KeccakP-1600-SnP.h b/third_party/python/Modules/_sha3/kcp/KeccakP-1600-SnP.h deleted file mode 100644 index c63a1e022..000000000 --- a/third_party/python/Modules/_sha3/kcp/KeccakP-1600-SnP.h +++ /dev/null @@ -1,8 +0,0 @@ -/* clang-format off */ -#if KeccakOpt == 64 - #include "KeccakP-1600-SnP-opt64.h" -#elif KeccakOpt == 32 - #include "KeccakP-1600-SnP-opt32.h" -#else - #error "No KeccakOpt" -#endif diff --git a/third_party/python/Modules/_sha3/kcp/KeccakP-1600-inplace32BI.c b/third_party/python/Modules/_sha3/kcp/KeccakP-1600-inplace32BI.c deleted file mode 100644 index 674c571be..000000000 --- a/third_party/python/Modules/_sha3/kcp/KeccakP-1600-inplace32BI.c +++ /dev/null @@ -1,1163 +0,0 @@ -/* clang-format off */ -/* -Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni, -Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby -denoted as "the implementer". - -For more information, feedback or questions, please refer to our websites: -http://keccak.noekeon.org/ -http://keyak.noekeon.org/ -http://ketje.noekeon.org/ - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#include -/* #include "brg_endian.h" */ -#include "KeccakP-1600-SnP.h" -#include "SnP-Relaned.h" - -typedef unsigned char UINT8; -typedef unsigned int UINT32; -/* WARNING: on 8-bit and 16-bit platforms, this should be replaced by: */ - -/*typedef unsigned long UINT32; */ - - -#define ROL32(a, offset) ((((UINT32)a) << (offset)) ^ (((UINT32)a) >> (32-(offset)))) - -/* Credit to Henry S. Warren, Hacker's Delight, Addison-Wesley, 2002 */ - -#define prepareToBitInterleaving(low, high, temp, temp0, temp1) \ - temp0 = (low); \ - temp = (temp0 ^ (temp0 >> 1)) & 0x22222222UL; temp0 = temp0 ^ temp ^ (temp << 1); \ - temp = (temp0 ^ (temp0 >> 2)) & 0x0C0C0C0CUL; temp0 = temp0 ^ temp ^ (temp << 2); \ - temp = (temp0 ^ (temp0 >> 4)) & 0x00F000F0UL; temp0 = temp0 ^ temp ^ (temp << 4); \ - temp = (temp0 ^ (temp0 >> 8)) & 0x0000FF00UL; temp0 = temp0 ^ temp ^ (temp << 8); \ - temp1 = (high); \ - temp = (temp1 ^ (temp1 >> 1)) & 0x22222222UL; temp1 = temp1 ^ temp ^ (temp << 1); \ - temp = (temp1 ^ (temp1 >> 2)) & 0x0C0C0C0CUL; temp1 = temp1 ^ temp ^ (temp << 2); \ - temp = (temp1 ^ (temp1 >> 4)) & 0x00F000F0UL; temp1 = temp1 ^ temp ^ (temp << 4); \ - temp = (temp1 ^ (temp1 >> 8)) & 0x0000FF00UL; temp1 = temp1 ^ temp ^ (temp << 8); - -#define toBitInterleavingAndXOR(low, high, even, odd, temp, temp0, temp1) \ - prepareToBitInterleaving(low, high, temp, temp0, temp1) \ - even ^= (temp0 & 0x0000FFFF) | (temp1 << 16); \ - odd ^= (temp0 >> 16) | (temp1 & 0xFFFF0000); - -#define toBitInterleavingAndAND(low, high, even, odd, temp, temp0, temp1) \ - prepareToBitInterleaving(low, high, temp, temp0, temp1) \ - even &= (temp0 & 0x0000FFFF) | (temp1 << 16); \ - odd &= (temp0 >> 16) | (temp1 & 0xFFFF0000); - -#define toBitInterleavingAndSet(low, high, even, odd, temp, temp0, temp1) \ - prepareToBitInterleaving(low, high, temp, temp0, temp1) \ - even = (temp0 & 0x0000FFFF) | (temp1 << 16); \ - odd = (temp0 >> 16) | (temp1 & 0xFFFF0000); - -/* Credit to Henry S. Warren, Hacker's Delight, Addison-Wesley, 2002 */ - -#define prepareFromBitInterleaving(even, odd, temp, temp0, temp1) \ - temp0 = (even); \ - temp1 = (odd); \ - temp = (temp0 & 0x0000FFFF) | (temp1 << 16); \ - temp1 = (temp0 >> 16) | (temp1 & 0xFFFF0000); \ - temp0 = temp; \ - temp = (temp0 ^ (temp0 >> 8)) & 0x0000FF00UL; temp0 = temp0 ^ temp ^ (temp << 8); \ - temp = (temp0 ^ (temp0 >> 4)) & 0x00F000F0UL; temp0 = temp0 ^ temp ^ (temp << 4); \ - temp = (temp0 ^ (temp0 >> 2)) & 0x0C0C0C0CUL; temp0 = temp0 ^ temp ^ (temp << 2); \ - temp = (temp0 ^ (temp0 >> 1)) & 0x22222222UL; temp0 = temp0 ^ temp ^ (temp << 1); \ - temp = (temp1 ^ (temp1 >> 8)) & 0x0000FF00UL; temp1 = temp1 ^ temp ^ (temp << 8); \ - temp = (temp1 ^ (temp1 >> 4)) & 0x00F000F0UL; temp1 = temp1 ^ temp ^ (temp << 4); \ - temp = (temp1 ^ (temp1 >> 2)) & 0x0C0C0C0CUL; temp1 = temp1 ^ temp ^ (temp << 2); \ - temp = (temp1 ^ (temp1 >> 1)) & 0x22222222UL; temp1 = temp1 ^ temp ^ (temp << 1); - -#define fromBitInterleaving(even, odd, low, high, temp, temp0, temp1) \ - prepareFromBitInterleaving(even, odd, temp, temp0, temp1) \ - low = temp0; \ - high = temp1; - -#define fromBitInterleavingAndXOR(even, odd, lowIn, highIn, lowOut, highOut, temp, temp0, temp1) \ - prepareFromBitInterleaving(even, odd, temp, temp0, temp1) \ - lowOut = lowIn ^ temp0; \ - highOut = highIn ^ temp1; - -void KeccakP1600_SetBytesInLaneToZero(void *state, unsigned int lanePosition, unsigned int offset, unsigned int length) -{ - UINT8 laneAsBytes[8]; - UINT32 low, high; - UINT32 temp, temp0, temp1; - UINT32 *stateAsHalfLanes = (UINT32*)state; - - memset(laneAsBytes, 0xFF, offset); - memset(laneAsBytes+offset, 0x00, length); - memset(laneAsBytes+offset+length, 0xFF, 8-offset-length); -#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN) - low = *((UINT32*)(laneAsBytes+0)); - high = *((UINT32*)(laneAsBytes+4)); -#else - low = laneAsBytes[0] - | ((UINT32)(laneAsBytes[1]) << 8) - | ((UINT32)(laneAsBytes[2]) << 16) - | ((UINT32)(laneAsBytes[3]) << 24); - high = laneAsBytes[4] - | ((UINT32)(laneAsBytes[5]) << 8) - | ((UINT32)(laneAsBytes[6]) << 16) - | ((UINT32)(laneAsBytes[7]) << 24); -#endif - toBitInterleavingAndAND(low, high, stateAsHalfLanes[lanePosition*2+0], stateAsHalfLanes[lanePosition*2+1], temp, temp0, temp1); -} - -/* ---------------------------------------------------------------- */ - -void KeccakP1600_Initialize(void *state) -{ - memset(state, 0, 200); -} - -/* ---------------------------------------------------------------- */ - -void KeccakP1600_AddByte(void *state, unsigned char byte, unsigned int offset) -{ - unsigned int lanePosition = offset/8; - unsigned int offsetInLane = offset%8; - UINT32 low, high; - UINT32 temp, temp0, temp1; - UINT32 *stateAsHalfLanes = (UINT32*)state; - - if (offsetInLane < 4) { - low = (UINT32)byte << (offsetInLane*8); - high = 0; - } - else { - low = 0; - high = (UINT32)byte << ((offsetInLane-4)*8); - } - toBitInterleavingAndXOR(low, high, stateAsHalfLanes[lanePosition*2+0], stateAsHalfLanes[lanePosition*2+1], temp, temp0, temp1); -} - -/* ---------------------------------------------------------------- */ - -void KeccakP1600_AddBytesInLane(void *state, unsigned int lanePosition, const unsigned char *data, unsigned int offset, unsigned int length) -{ - UINT8 laneAsBytes[8]; - UINT32 low, high; - UINT32 temp, temp0, temp1; - UINT32 *stateAsHalfLanes = (UINT32*)state; - - memset(laneAsBytes, 0, 8); - memcpy(laneAsBytes+offset, data, length); -#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN) - low = *((UINT32*)(laneAsBytes+0)); - high = *((UINT32*)(laneAsBytes+4)); -#else - low = laneAsBytes[0] - | ((UINT32)(laneAsBytes[1]) << 8) - | ((UINT32)(laneAsBytes[2]) << 16) - | ((UINT32)(laneAsBytes[3]) << 24); - high = laneAsBytes[4] - | ((UINT32)(laneAsBytes[5]) << 8) - | ((UINT32)(laneAsBytes[6]) << 16) - | ((UINT32)(laneAsBytes[7]) << 24); -#endif - toBitInterleavingAndXOR(low, high, stateAsHalfLanes[lanePosition*2+0], stateAsHalfLanes[lanePosition*2+1], temp, temp0, temp1); -} - -/* ---------------------------------------------------------------- */ - -void KeccakP1600_AddLanes(void *state, const unsigned char *data, unsigned int laneCount) -{ -#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN) - const UINT32 * pI = (const UINT32 *)data; - UINT32 * pS = (UINT32*)state; - UINT32 t, x0, x1; - int i; - for (i = laneCount-1; i >= 0; --i) { -#ifdef NO_MISALIGNED_ACCESSES - UINT32 low; - UINT32 high; - memcpy(&low, pI++, 4); - memcpy(&high, pI++, 4); - toBitInterleavingAndXOR(low, high, *(pS++), *(pS++), t, x0, x1); -#else - toBitInterleavingAndXOR(*(pI++), *(pI++), *(pS++), *(pS++), t, x0, x1) -#endif - } -#else - unsigned int lanePosition; - for(lanePosition=0; lanePosition= 0; --i) { -#ifdef NO_MISALIGNED_ACCESSES - UINT32 low; - UINT32 high; - memcpy(&low, pI++, 4); - memcpy(&high, pI++, 4); - toBitInterleavingAndSet(low, high, *(pS++), *(pS++), t, x0, x1); -#else - toBitInterleavingAndSet(*(pI++), *(pI++), *(pS++), *(pS++), t, x0, x1) -#endif - } -#else - unsigned int lanePosition; - for(lanePosition=0; lanePosition> 8) & 0xFF; - laneAsBytes[2] = (low >> 16) & 0xFF; - laneAsBytes[3] = (low >> 24) & 0xFF; - laneAsBytes[4] = high & 0xFF; - laneAsBytes[5] = (high >> 8) & 0xFF; - laneAsBytes[6] = (high >> 16) & 0xFF; - laneAsBytes[7] = (high >> 24) & 0xFF; -#endif - memcpy(data, laneAsBytes+offset, length); -} - -/* ---------------------------------------------------------------- */ - -void KeccakP1600_ExtractLanes(const void *state, unsigned char *data, unsigned int laneCount) -{ -#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN) - UINT32 * pI = (UINT32 *)data; - const UINT32 * pS = ( const UINT32 *)state; - UINT32 t, x0, x1; - int i; - for (i = laneCount-1; i >= 0; --i) { -#ifdef NO_MISALIGNED_ACCESSES - UINT32 low; - UINT32 high; - fromBitInterleaving(*(pS++), *(pS++), low, high, t, x0, x1); - memcpy(pI++, &low, 4); - memcpy(pI++, &high, 4); -#else - fromBitInterleaving(*(pS++), *(pS++), *(pI++), *(pI++), t, x0, x1) -#endif - } -#else - unsigned int lanePosition; - for(lanePosition=0; lanePosition> 8) & 0xFF; - laneAsBytes[2] = (low >> 16) & 0xFF; - laneAsBytes[3] = (low >> 24) & 0xFF; - laneAsBytes[4] = high & 0xFF; - laneAsBytes[5] = (high >> 8) & 0xFF; - laneAsBytes[6] = (high >> 16) & 0xFF; - laneAsBytes[7] = (high >> 24) & 0xFF; - memcpy(data+lanePosition*8, laneAsBytes, 8); - } -#endif -} - -/* ---------------------------------------------------------------- */ - -void KeccakP1600_ExtractBytes(const void *state, unsigned char *data, unsigned int offset, unsigned int length) -{ - SnP_ExtractBytes(state, data, offset, length, KeccakP1600_ExtractLanes, KeccakP1600_ExtractBytesInLane, 8); -} - -/* ---------------------------------------------------------------- */ - -void KeccakP1600_ExtractAndAddBytesInLane(const void *state, unsigned int lanePosition, const unsigned char *input, unsigned char *output, unsigned int offset, unsigned int length) -{ - UINT32 *stateAsHalfLanes = (UINT32*)state; - UINT32 low, high, temp, temp0, temp1; - UINT8 laneAsBytes[8]; - unsigned int i; - - fromBitInterleaving(stateAsHalfLanes[lanePosition*2], stateAsHalfLanes[lanePosition*2+1], low, high, temp, temp0, temp1); -#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN) - *((UINT32*)(laneAsBytes+0)) = low; - *((UINT32*)(laneAsBytes+4)) = high; -#else - laneAsBytes[0] = low & 0xFF; - laneAsBytes[1] = (low >> 8) & 0xFF; - laneAsBytes[2] = (low >> 16) & 0xFF; - laneAsBytes[3] = (low >> 24) & 0xFF; - laneAsBytes[4] = high & 0xFF; - laneAsBytes[5] = (high >> 8) & 0xFF; - laneAsBytes[6] = (high >> 16) & 0xFF; - laneAsBytes[7] = (high >> 24) & 0xFF; -#endif - for(i=0; i= 0; --i) { -#ifdef NO_MISALIGNED_ACCESSES - UINT32 low; - UINT32 high; - fromBitInterleaving(*(pS++), *(pS++), low, high, t, x0, x1); - *(pO++) = *(pI++) ^ low; - *(pO++) = *(pI++) ^ high; -#else - fromBitInterleavingAndXOR(*(pS++), *(pS++), *(pI++), *(pI++), *(pO++), *(pO++), t, x0, x1) -#endif - } -#else - unsigned int lanePosition; - for(lanePosition=0; lanePosition> 8) & 0xFF; - laneAsBytes[2] = (low >> 16) & 0xFF; - laneAsBytes[3] = (low >> 24) & 0xFF; - laneAsBytes[4] = high & 0xFF; - laneAsBytes[5] = (high >> 8) & 0xFF; - laneAsBytes[6] = (high >> 16) & 0xFF; - laneAsBytes[7] = (high >> 24) & 0xFF; - ((UINT32*)(output+lanePosition*8))[0] = ((UINT32*)(input+lanePosition*8))[0] ^ (*(const UINT32*)(laneAsBytes+0)); - ((UINT32*)(output+lanePosition*8))[1] = ((UINT32*)(input+lanePosition*8))[0] ^ (*(const UINT32*)(laneAsBytes+4)); - } -#endif -} -/* ---------------------------------------------------------------- */ - -void KeccakP1600_ExtractAndAddBytes(const void *state, const unsigned char *input, unsigned char *output, unsigned int offset, unsigned int length) -{ - SnP_ExtractAndAddBytes(state, input, output, offset, length, KeccakP1600_ExtractAndAddLanes, KeccakP1600_ExtractAndAddBytesInLane, 8); -} - -/* ---------------------------------------------------------------- */ - -static const UINT32 KeccakF1600RoundConstants_int2[2*24+1] = -{ - 0x00000001UL, 0x00000000UL, - 0x00000000UL, 0x00000089UL, - 0x00000000UL, 0x8000008bUL, - 0x00000000UL, 0x80008080UL, - 0x00000001UL, 0x0000008bUL, - 0x00000001UL, 0x00008000UL, - 0x00000001UL, 0x80008088UL, - 0x00000001UL, 0x80000082UL, - 0x00000000UL, 0x0000000bUL, - 0x00000000UL, 0x0000000aUL, - 0x00000001UL, 0x00008082UL, - 0x00000000UL, 0x00008003UL, - 0x00000001UL, 0x0000808bUL, - 0x00000001UL, 0x8000000bUL, - 0x00000001UL, 0x8000008aUL, - 0x00000001UL, 0x80000081UL, - 0x00000000UL, 0x80000081UL, - 0x00000000UL, 0x80000008UL, - 0x00000000UL, 0x00000083UL, - 0x00000000UL, 0x80008003UL, - 0x00000001UL, 0x80008088UL, - 0x00000000UL, 0x80000088UL, - 0x00000001UL, 0x00008000UL, - 0x00000000UL, 0x80008082UL, - 0x000000FFUL -}; - -#define KeccakAtoD_round0() \ - Cx = Abu0^Agu0^Aku0^Amu0^Asu0; \ - Du1 = Abe1^Age1^Ake1^Ame1^Ase1; \ - Da0 = Cx^ROL32(Du1, 1); \ - Cz = Abu1^Agu1^Aku1^Amu1^Asu1; \ - Du0 = Abe0^Age0^Ake0^Ame0^Ase0; \ - Da1 = Cz^Du0; \ -\ - Cw = Abi0^Agi0^Aki0^Ami0^Asi0; \ - Do0 = Cw^ROL32(Cz, 1); \ - Cy = Abi1^Agi1^Aki1^Ami1^Asi1; \ - Do1 = Cy^Cx; \ -\ - Cx = Aba0^Aga0^Aka0^Ama0^Asa0; \ - De0 = Cx^ROL32(Cy, 1); \ - Cz = Aba1^Aga1^Aka1^Ama1^Asa1; \ - De1 = Cz^Cw; \ -\ - Cy = Abo1^Ago1^Ako1^Amo1^Aso1; \ - Di0 = Du0^ROL32(Cy, 1); \ - Cw = Abo0^Ago0^Ako0^Amo0^Aso0; \ - Di1 = Du1^Cw; \ -\ - Du0 = Cw^ROL32(Cz, 1); \ - Du1 = Cy^Cx; \ - -#define KeccakAtoD_round1() \ - Cx = Asu0^Agu0^Amu0^Abu1^Aku1; \ - Du1 = Age1^Ame0^Abe0^Ake1^Ase1; \ - Da0 = Cx^ROL32(Du1, 1); \ - Cz = Asu1^Agu1^Amu1^Abu0^Aku0; \ - Du0 = Age0^Ame1^Abe1^Ake0^Ase0; \ - Da1 = Cz^Du0; \ -\ - Cw = Aki1^Asi1^Agi0^Ami1^Abi0; \ - Do0 = Cw^ROL32(Cz, 1); \ - Cy = Aki0^Asi0^Agi1^Ami0^Abi1; \ - Do1 = Cy^Cx; \ -\ - Cx = Aba0^Aka1^Asa0^Aga0^Ama1; \ - De0 = Cx^ROL32(Cy, 1); \ - Cz = Aba1^Aka0^Asa1^Aga1^Ama0; \ - De1 = Cz^Cw; \ -\ - Cy = Amo0^Abo1^Ako0^Aso1^Ago0; \ - Di0 = Du0^ROL32(Cy, 1); \ - Cw = Amo1^Abo0^Ako1^Aso0^Ago1; \ - Di1 = Du1^Cw; \ -\ - Du0 = Cw^ROL32(Cz, 1); \ - Du1 = Cy^Cx; \ - -#define KeccakAtoD_round2() \ - Cx = Aku1^Agu0^Abu1^Asu1^Amu1; \ - Du1 = Ame0^Ake0^Age0^Abe0^Ase1; \ - Da0 = Cx^ROL32(Du1, 1); \ - Cz = Aku0^Agu1^Abu0^Asu0^Amu0; \ - Du0 = Ame1^Ake1^Age1^Abe1^Ase0; \ - Da1 = Cz^Du0; \ -\ - Cw = Agi1^Abi1^Asi1^Ami0^Aki1; \ - Do0 = Cw^ROL32(Cz, 1); \ - Cy = Agi0^Abi0^Asi0^Ami1^Aki0; \ - Do1 = Cy^Cx; \ -\ - Cx = Aba0^Asa1^Ama1^Aka1^Aga1; \ - De0 = Cx^ROL32(Cy, 1); \ - Cz = Aba1^Asa0^Ama0^Aka0^Aga0; \ - De1 = Cz^Cw; \ -\ - Cy = Aso0^Amo0^Ako1^Ago0^Abo0; \ - Di0 = Du0^ROL32(Cy, 1); \ - Cw = Aso1^Amo1^Ako0^Ago1^Abo1; \ - Di1 = Du1^Cw; \ -\ - Du0 = Cw^ROL32(Cz, 1); \ - Du1 = Cy^Cx; \ - -#define KeccakAtoD_round3() \ - Cx = Amu1^Agu0^Asu1^Aku0^Abu0; \ - Du1 = Ake0^Abe1^Ame1^Age0^Ase1; \ - Da0 = Cx^ROL32(Du1, 1); \ - Cz = Amu0^Agu1^Asu0^Aku1^Abu1; \ - Du0 = Ake1^Abe0^Ame0^Age1^Ase0; \ - Da1 = Cz^Du0; \ -\ - Cw = Asi0^Aki0^Abi1^Ami1^Agi1; \ - Do0 = Cw^ROL32(Cz, 1); \ - Cy = Asi1^Aki1^Abi0^Ami0^Agi0; \ - Do1 = Cy^Cx; \ -\ - Cx = Aba0^Ama0^Aga1^Asa1^Aka0; \ - De0 = Cx^ROL32(Cy, 1); \ - Cz = Aba1^Ama1^Aga0^Asa0^Aka1; \ - De1 = Cz^Cw; \ -\ - Cy = Ago1^Aso0^Ako0^Abo0^Amo1; \ - Di0 = Du0^ROL32(Cy, 1); \ - Cw = Ago0^Aso1^Ako1^Abo1^Amo0; \ - Di1 = Du1^Cw; \ -\ - Du0 = Cw^ROL32(Cz, 1); \ - Du1 = Cy^Cx; \ - -void KeccakP1600_Permute_Nrounds(void *state, unsigned int nRounds) -{ - { - UINT32 Da0, De0, Di0, Do0, Du0; - UINT32 Da1, De1, Di1, Do1, Du1; - UINT32 Ca0, Ce0, Ci0, Co0, Cu0; - UINT32 Cx, Cy, Cz, Cw; - #define Ba Ca0 - #define Be Ce0 - #define Bi Ci0 - #define Bo Co0 - #define Bu Cu0 - const UINT32 *pRoundConstants = KeccakF1600RoundConstants_int2+(24-nRounds)*2; - UINT32 *stateAsHalfLanes = (UINT32*)state; - #define Aba0 stateAsHalfLanes[ 0] - #define Aba1 stateAsHalfLanes[ 1] - #define Abe0 stateAsHalfLanes[ 2] - #define Abe1 stateAsHalfLanes[ 3] - #define Abi0 stateAsHalfLanes[ 4] - #define Abi1 stateAsHalfLanes[ 5] - #define Abo0 stateAsHalfLanes[ 6] - #define Abo1 stateAsHalfLanes[ 7] - #define Abu0 stateAsHalfLanes[ 8] - #define Abu1 stateAsHalfLanes[ 9] - #define Aga0 stateAsHalfLanes[10] - #define Aga1 stateAsHalfLanes[11] - #define Age0 stateAsHalfLanes[12] - #define Age1 stateAsHalfLanes[13] - #define Agi0 stateAsHalfLanes[14] - #define Agi1 stateAsHalfLanes[15] - #define Ago0 stateAsHalfLanes[16] - #define Ago1 stateAsHalfLanes[17] - #define Agu0 stateAsHalfLanes[18] - #define Agu1 stateAsHalfLanes[19] - #define Aka0 stateAsHalfLanes[20] - #define Aka1 stateAsHalfLanes[21] - #define Ake0 stateAsHalfLanes[22] - #define Ake1 stateAsHalfLanes[23] - #define Aki0 stateAsHalfLanes[24] - #define Aki1 stateAsHalfLanes[25] - #define Ako0 stateAsHalfLanes[26] - #define Ako1 stateAsHalfLanes[27] - #define Aku0 stateAsHalfLanes[28] - #define Aku1 stateAsHalfLanes[29] - #define Ama0 stateAsHalfLanes[30] - #define Ama1 stateAsHalfLanes[31] - #define Ame0 stateAsHalfLanes[32] - #define Ame1 stateAsHalfLanes[33] - #define Ami0 stateAsHalfLanes[34] - #define Ami1 stateAsHalfLanes[35] - #define Amo0 stateAsHalfLanes[36] - #define Amo1 stateAsHalfLanes[37] - #define Amu0 stateAsHalfLanes[38] - #define Amu1 stateAsHalfLanes[39] - #define Asa0 stateAsHalfLanes[40] - #define Asa1 stateAsHalfLanes[41] - #define Ase0 stateAsHalfLanes[42] - #define Ase1 stateAsHalfLanes[43] - #define Asi0 stateAsHalfLanes[44] - #define Asi1 stateAsHalfLanes[45] - #define Aso0 stateAsHalfLanes[46] - #define Aso1 stateAsHalfLanes[47] - #define Asu0 stateAsHalfLanes[48] - #define Asu1 stateAsHalfLanes[49] - - do - { - /* --- Code for 4 rounds */ - - /* --- using factor 2 interleaving, 64-bit lanes mapped to 32-bit words */ - - KeccakAtoD_round0(); - - Ba = (Aba0^Da0); - Be = ROL32((Age0^De0), 22); - Bi = ROL32((Aki1^Di1), 22); - Bo = ROL32((Amo1^Do1), 11); - Bu = ROL32((Asu0^Du0), 7); - Aba0 = Ba ^((~Be)& Bi ); - Aba0 ^= *(pRoundConstants++); - Age0 = Be ^((~Bi)& Bo ); - Aki1 = Bi ^((~Bo)& Bu ); - Amo1 = Bo ^((~Bu)& Ba ); - Asu0 = Bu ^((~Ba)& Be ); - - Ba = (Aba1^Da1); - Be = ROL32((Age1^De1), 22); - Bi = ROL32((Aki0^Di0), 21); - Bo = ROL32((Amo0^Do0), 10); - Bu = ROL32((Asu1^Du1), 7); - Aba1 = Ba ^((~Be)& Bi ); - Aba1 ^= *(pRoundConstants++); - Age1 = Be ^((~Bi)& Bo ); - Aki0 = Bi ^((~Bo)& Bu ); - Amo0 = Bo ^((~Bu)& Ba ); - Asu1 = Bu ^((~Ba)& Be ); - - Bi = ROL32((Aka1^Da1), 2); - Bo = ROL32((Ame1^De1), 23); - Bu = ROL32((Asi1^Di1), 31); - Ba = ROL32((Abo0^Do0), 14); - Be = ROL32((Agu0^Du0), 10); - Aka1 = Ba ^((~Be)& Bi ); - Ame1 = Be ^((~Bi)& Bo ); - Asi1 = Bi ^((~Bo)& Bu ); - Abo0 = Bo ^((~Bu)& Ba ); - Agu0 = Bu ^((~Ba)& Be ); - - Bi = ROL32((Aka0^Da0), 1); - Bo = ROL32((Ame0^De0), 22); - Bu = ROL32((Asi0^Di0), 30); - Ba = ROL32((Abo1^Do1), 14); - Be = ROL32((Agu1^Du1), 10); - Aka0 = Ba ^((~Be)& Bi ); - Ame0 = Be ^((~Bi)& Bo ); - Asi0 = Bi ^((~Bo)& Bu ); - Abo1 = Bo ^((~Bu)& Ba ); - Agu1 = Bu ^((~Ba)& Be ); - - Bu = ROL32((Asa0^Da0), 9); - Ba = ROL32((Abe1^De1), 1); - Be = ROL32((Agi0^Di0), 3); - Bi = ROL32((Ako1^Do1), 13); - Bo = ROL32((Amu0^Du0), 4); - Asa0 = Ba ^((~Be)& Bi ); - Abe1 = Be ^((~Bi)& Bo ); - Agi0 = Bi ^((~Bo)& Bu ); - Ako1 = Bo ^((~Bu)& Ba ); - Amu0 = Bu ^((~Ba)& Be ); - - Bu = ROL32((Asa1^Da1), 9); - Ba = (Abe0^De0); - Be = ROL32((Agi1^Di1), 3); - Bi = ROL32((Ako0^Do0), 12); - Bo = ROL32((Amu1^Du1), 4); - Asa1 = Ba ^((~Be)& Bi ); - Abe0 = Be ^((~Bi)& Bo ); - Agi1 = Bi ^((~Bo)& Bu ); - Ako0 = Bo ^((~Bu)& Ba ); - Amu1 = Bu ^((~Ba)& Be ); - - Be = ROL32((Aga0^Da0), 18); - Bi = ROL32((Ake0^De0), 5); - Bo = ROL32((Ami1^Di1), 8); - Bu = ROL32((Aso0^Do0), 28); - Ba = ROL32((Abu1^Du1), 14); - Aga0 = Ba ^((~Be)& Bi ); - Ake0 = Be ^((~Bi)& Bo ); - Ami1 = Bi ^((~Bo)& Bu ); - Aso0 = Bo ^((~Bu)& Ba ); - Abu1 = Bu ^((~Ba)& Be ); - - Be = ROL32((Aga1^Da1), 18); - Bi = ROL32((Ake1^De1), 5); - Bo = ROL32((Ami0^Di0), 7); - Bu = ROL32((Aso1^Do1), 28); - Ba = ROL32((Abu0^Du0), 13); - Aga1 = Ba ^((~Be)& Bi ); - Ake1 = Be ^((~Bi)& Bo ); - Ami0 = Bi ^((~Bo)& Bu ); - Aso1 = Bo ^((~Bu)& Ba ); - Abu0 = Bu ^((~Ba)& Be ); - - Bo = ROL32((Ama1^Da1), 21); - Bu = ROL32((Ase0^De0), 1); - Ba = ROL32((Abi0^Di0), 31); - Be = ROL32((Ago1^Do1), 28); - Bi = ROL32((Aku1^Du1), 20); - Ama1 = Ba ^((~Be)& Bi ); - Ase0 = Be ^((~Bi)& Bo ); - Abi0 = Bi ^((~Bo)& Bu ); - Ago1 = Bo ^((~Bu)& Ba ); - Aku1 = Bu ^((~Ba)& Be ); - - Bo = ROL32((Ama0^Da0), 20); - Bu = ROL32((Ase1^De1), 1); - Ba = ROL32((Abi1^Di1), 31); - Be = ROL32((Ago0^Do0), 27); - Bi = ROL32((Aku0^Du0), 19); - Ama0 = Ba ^((~Be)& Bi ); - Ase1 = Be ^((~Bi)& Bo ); - Abi1 = Bi ^((~Bo)& Bu ); - Ago0 = Bo ^((~Bu)& Ba ); - Aku0 = Bu ^((~Ba)& Be ); - - KeccakAtoD_round1(); - - Ba = (Aba0^Da0); - Be = ROL32((Ame1^De0), 22); - Bi = ROL32((Agi1^Di1), 22); - Bo = ROL32((Aso1^Do1), 11); - Bu = ROL32((Aku1^Du0), 7); - Aba0 = Ba ^((~Be)& Bi ); - Aba0 ^= *(pRoundConstants++); - Ame1 = Be ^((~Bi)& Bo ); - Agi1 = Bi ^((~Bo)& Bu ); - Aso1 = Bo ^((~Bu)& Ba ); - Aku1 = Bu ^((~Ba)& Be ); - - Ba = (Aba1^Da1); - Be = ROL32((Ame0^De1), 22); - Bi = ROL32((Agi0^Di0), 21); - Bo = ROL32((Aso0^Do0), 10); - Bu = ROL32((Aku0^Du1), 7); - Aba1 = Ba ^((~Be)& Bi ); - Aba1 ^= *(pRoundConstants++); - Ame0 = Be ^((~Bi)& Bo ); - Agi0 = Bi ^((~Bo)& Bu ); - Aso0 = Bo ^((~Bu)& Ba ); - Aku0 = Bu ^((~Ba)& Be ); - - Bi = ROL32((Asa1^Da1), 2); - Bo = ROL32((Ake1^De1), 23); - Bu = ROL32((Abi1^Di1), 31); - Ba = ROL32((Amo1^Do0), 14); - Be = ROL32((Agu0^Du0), 10); - Asa1 = Ba ^((~Be)& Bi ); - Ake1 = Be ^((~Bi)& Bo ); - Abi1 = Bi ^((~Bo)& Bu ); - Amo1 = Bo ^((~Bu)& Ba ); - Agu0 = Bu ^((~Ba)& Be ); - - Bi = ROL32((Asa0^Da0), 1); - Bo = ROL32((Ake0^De0), 22); - Bu = ROL32((Abi0^Di0), 30); - Ba = ROL32((Amo0^Do1), 14); - Be = ROL32((Agu1^Du1), 10); - Asa0 = Ba ^((~Be)& Bi ); - Ake0 = Be ^((~Bi)& Bo ); - Abi0 = Bi ^((~Bo)& Bu ); - Amo0 = Bo ^((~Bu)& Ba ); - Agu1 = Bu ^((~Ba)& Be ); - - Bu = ROL32((Ama1^Da0), 9); - Ba = ROL32((Age1^De1), 1); - Be = ROL32((Asi1^Di0), 3); - Bi = ROL32((Ako0^Do1), 13); - Bo = ROL32((Abu1^Du0), 4); - Ama1 = Ba ^((~Be)& Bi ); - Age1 = Be ^((~Bi)& Bo ); - Asi1 = Bi ^((~Bo)& Bu ); - Ako0 = Bo ^((~Bu)& Ba ); - Abu1 = Bu ^((~Ba)& Be ); - - Bu = ROL32((Ama0^Da1), 9); - Ba = (Age0^De0); - Be = ROL32((Asi0^Di1), 3); - Bi = ROL32((Ako1^Do0), 12); - Bo = ROL32((Abu0^Du1), 4); - Ama0 = Ba ^((~Be)& Bi ); - Age0 = Be ^((~Bi)& Bo ); - Asi0 = Bi ^((~Bo)& Bu ); - Ako1 = Bo ^((~Bu)& Ba ); - Abu0 = Bu ^((~Ba)& Be ); - - Be = ROL32((Aka1^Da0), 18); - Bi = ROL32((Abe1^De0), 5); - Bo = ROL32((Ami0^Di1), 8); - Bu = ROL32((Ago1^Do0), 28); - Ba = ROL32((Asu1^Du1), 14); - Aka1 = Ba ^((~Be)& Bi ); - Abe1 = Be ^((~Bi)& Bo ); - Ami0 = Bi ^((~Bo)& Bu ); - Ago1 = Bo ^((~Bu)& Ba ); - Asu1 = Bu ^((~Ba)& Be ); - - Be = ROL32((Aka0^Da1), 18); - Bi = ROL32((Abe0^De1), 5); - Bo = ROL32((Ami1^Di0), 7); - Bu = ROL32((Ago0^Do1), 28); - Ba = ROL32((Asu0^Du0), 13); - Aka0 = Ba ^((~Be)& Bi ); - Abe0 = Be ^((~Bi)& Bo ); - Ami1 = Bi ^((~Bo)& Bu ); - Ago0 = Bo ^((~Bu)& Ba ); - Asu0 = Bu ^((~Ba)& Be ); - - Bo = ROL32((Aga1^Da1), 21); - Bu = ROL32((Ase0^De0), 1); - Ba = ROL32((Aki1^Di0), 31); - Be = ROL32((Abo1^Do1), 28); - Bi = ROL32((Amu1^Du1), 20); - Aga1 = Ba ^((~Be)& Bi ); - Ase0 = Be ^((~Bi)& Bo ); - Aki1 = Bi ^((~Bo)& Bu ); - Abo1 = Bo ^((~Bu)& Ba ); - Amu1 = Bu ^((~Ba)& Be ); - - Bo = ROL32((Aga0^Da0), 20); - Bu = ROL32((Ase1^De1), 1); - Ba = ROL32((Aki0^Di1), 31); - Be = ROL32((Abo0^Do0), 27); - Bi = ROL32((Amu0^Du0), 19); - Aga0 = Ba ^((~Be)& Bi ); - Ase1 = Be ^((~Bi)& Bo ); - Aki0 = Bi ^((~Bo)& Bu ); - Abo0 = Bo ^((~Bu)& Ba ); - Amu0 = Bu ^((~Ba)& Be ); - - KeccakAtoD_round2(); - - Ba = (Aba0^Da0); - Be = ROL32((Ake1^De0), 22); - Bi = ROL32((Asi0^Di1), 22); - Bo = ROL32((Ago0^Do1), 11); - Bu = ROL32((Amu1^Du0), 7); - Aba0 = Ba ^((~Be)& Bi ); - Aba0 ^= *(pRoundConstants++); - Ake1 = Be ^((~Bi)& Bo ); - Asi0 = Bi ^((~Bo)& Bu ); - Ago0 = Bo ^((~Bu)& Ba ); - Amu1 = Bu ^((~Ba)& Be ); - - Ba = (Aba1^Da1); - Be = ROL32((Ake0^De1), 22); - Bi = ROL32((Asi1^Di0), 21); - Bo = ROL32((Ago1^Do0), 10); - Bu = ROL32((Amu0^Du1), 7); - Aba1 = Ba ^((~Be)& Bi ); - Aba1 ^= *(pRoundConstants++); - Ake0 = Be ^((~Bi)& Bo ); - Asi1 = Bi ^((~Bo)& Bu ); - Ago1 = Bo ^((~Bu)& Ba ); - Amu0 = Bu ^((~Ba)& Be ); - - Bi = ROL32((Ama0^Da1), 2); - Bo = ROL32((Abe0^De1), 23); - Bu = ROL32((Aki0^Di1), 31); - Ba = ROL32((Aso1^Do0), 14); - Be = ROL32((Agu0^Du0), 10); - Ama0 = Ba ^((~Be)& Bi ); - Abe0 = Be ^((~Bi)& Bo ); - Aki0 = Bi ^((~Bo)& Bu ); - Aso1 = Bo ^((~Bu)& Ba ); - Agu0 = Bu ^((~Ba)& Be ); - - Bi = ROL32((Ama1^Da0), 1); - Bo = ROL32((Abe1^De0), 22); - Bu = ROL32((Aki1^Di0), 30); - Ba = ROL32((Aso0^Do1), 14); - Be = ROL32((Agu1^Du1), 10); - Ama1 = Ba ^((~Be)& Bi ); - Abe1 = Be ^((~Bi)& Bo ); - Aki1 = Bi ^((~Bo)& Bu ); - Aso0 = Bo ^((~Bu)& Ba ); - Agu1 = Bu ^((~Ba)& Be ); - - Bu = ROL32((Aga1^Da0), 9); - Ba = ROL32((Ame0^De1), 1); - Be = ROL32((Abi1^Di0), 3); - Bi = ROL32((Ako1^Do1), 13); - Bo = ROL32((Asu1^Du0), 4); - Aga1 = Ba ^((~Be)& Bi ); - Ame0 = Be ^((~Bi)& Bo ); - Abi1 = Bi ^((~Bo)& Bu ); - Ako1 = Bo ^((~Bu)& Ba ); - Asu1 = Bu ^((~Ba)& Be ); - - Bu = ROL32((Aga0^Da1), 9); - Ba = (Ame1^De0); - Be = ROL32((Abi0^Di1), 3); - Bi = ROL32((Ako0^Do0), 12); - Bo = ROL32((Asu0^Du1), 4); - Aga0 = Ba ^((~Be)& Bi ); - Ame1 = Be ^((~Bi)& Bo ); - Abi0 = Bi ^((~Bo)& Bu ); - Ako0 = Bo ^((~Bu)& Ba ); - Asu0 = Bu ^((~Ba)& Be ); - - Be = ROL32((Asa1^Da0), 18); - Bi = ROL32((Age1^De0), 5); - Bo = ROL32((Ami1^Di1), 8); - Bu = ROL32((Abo1^Do0), 28); - Ba = ROL32((Aku0^Du1), 14); - Asa1 = Ba ^((~Be)& Bi ); - Age1 = Be ^((~Bi)& Bo ); - Ami1 = Bi ^((~Bo)& Bu ); - Abo1 = Bo ^((~Bu)& Ba ); - Aku0 = Bu ^((~Ba)& Be ); - - Be = ROL32((Asa0^Da1), 18); - Bi = ROL32((Age0^De1), 5); - Bo = ROL32((Ami0^Di0), 7); - Bu = ROL32((Abo0^Do1), 28); - Ba = ROL32((Aku1^Du0), 13); - Asa0 = Ba ^((~Be)& Bi ); - Age0 = Be ^((~Bi)& Bo ); - Ami0 = Bi ^((~Bo)& Bu ); - Abo0 = Bo ^((~Bu)& Ba ); - Aku1 = Bu ^((~Ba)& Be ); - - Bo = ROL32((Aka0^Da1), 21); - Bu = ROL32((Ase0^De0), 1); - Ba = ROL32((Agi1^Di0), 31); - Be = ROL32((Amo0^Do1), 28); - Bi = ROL32((Abu0^Du1), 20); - Aka0 = Ba ^((~Be)& Bi ); - Ase0 = Be ^((~Bi)& Bo ); - Agi1 = Bi ^((~Bo)& Bu ); - Amo0 = Bo ^((~Bu)& Ba ); - Abu0 = Bu ^((~Ba)& Be ); - - Bo = ROL32((Aka1^Da0), 20); - Bu = ROL32((Ase1^De1), 1); - Ba = ROL32((Agi0^Di1), 31); - Be = ROL32((Amo1^Do0), 27); - Bi = ROL32((Abu1^Du0), 19); - Aka1 = Ba ^((~Be)& Bi ); - Ase1 = Be ^((~Bi)& Bo ); - Agi0 = Bi ^((~Bo)& Bu ); - Amo1 = Bo ^((~Bu)& Ba ); - Abu1 = Bu ^((~Ba)& Be ); - - KeccakAtoD_round3(); - - Ba = (Aba0^Da0); - Be = ROL32((Abe0^De0), 22); - Bi = ROL32((Abi0^Di1), 22); - Bo = ROL32((Abo0^Do1), 11); - Bu = ROL32((Abu0^Du0), 7); - Aba0 = Ba ^((~Be)& Bi ); - Aba0 ^= *(pRoundConstants++); - Abe0 = Be ^((~Bi)& Bo ); - Abi0 = Bi ^((~Bo)& Bu ); - Abo0 = Bo ^((~Bu)& Ba ); - Abu0 = Bu ^((~Ba)& Be ); - - Ba = (Aba1^Da1); - Be = ROL32((Abe1^De1), 22); - Bi = ROL32((Abi1^Di0), 21); - Bo = ROL32((Abo1^Do0), 10); - Bu = ROL32((Abu1^Du1), 7); - Aba1 = Ba ^((~Be)& Bi ); - Aba1 ^= *(pRoundConstants++); - Abe1 = Be ^((~Bi)& Bo ); - Abi1 = Bi ^((~Bo)& Bu ); - Abo1 = Bo ^((~Bu)& Ba ); - Abu1 = Bu ^((~Ba)& Be ); - - Bi = ROL32((Aga0^Da1), 2); - Bo = ROL32((Age0^De1), 23); - Bu = ROL32((Agi0^Di1), 31); - Ba = ROL32((Ago0^Do0), 14); - Be = ROL32((Agu0^Du0), 10); - Aga0 = Ba ^((~Be)& Bi ); - Age0 = Be ^((~Bi)& Bo ); - Agi0 = Bi ^((~Bo)& Bu ); - Ago0 = Bo ^((~Bu)& Ba ); - Agu0 = Bu ^((~Ba)& Be ); - - Bi = ROL32((Aga1^Da0), 1); - Bo = ROL32((Age1^De0), 22); - Bu = ROL32((Agi1^Di0), 30); - Ba = ROL32((Ago1^Do1), 14); - Be = ROL32((Agu1^Du1), 10); - Aga1 = Ba ^((~Be)& Bi ); - Age1 = Be ^((~Bi)& Bo ); - Agi1 = Bi ^((~Bo)& Bu ); - Ago1 = Bo ^((~Bu)& Ba ); - Agu1 = Bu ^((~Ba)& Be ); - - Bu = ROL32((Aka0^Da0), 9); - Ba = ROL32((Ake0^De1), 1); - Be = ROL32((Aki0^Di0), 3); - Bi = ROL32((Ako0^Do1), 13); - Bo = ROL32((Aku0^Du0), 4); - Aka0 = Ba ^((~Be)& Bi ); - Ake0 = Be ^((~Bi)& Bo ); - Aki0 = Bi ^((~Bo)& Bu ); - Ako0 = Bo ^((~Bu)& Ba ); - Aku0 = Bu ^((~Ba)& Be ); - - Bu = ROL32((Aka1^Da1), 9); - Ba = (Ake1^De0); - Be = ROL32((Aki1^Di1), 3); - Bi = ROL32((Ako1^Do0), 12); - Bo = ROL32((Aku1^Du1), 4); - Aka1 = Ba ^((~Be)& Bi ); - Ake1 = Be ^((~Bi)& Bo ); - Aki1 = Bi ^((~Bo)& Bu ); - Ako1 = Bo ^((~Bu)& Ba ); - Aku1 = Bu ^((~Ba)& Be ); - - Be = ROL32((Ama0^Da0), 18); - Bi = ROL32((Ame0^De0), 5); - Bo = ROL32((Ami0^Di1), 8); - Bu = ROL32((Amo0^Do0), 28); - Ba = ROL32((Amu0^Du1), 14); - Ama0 = Ba ^((~Be)& Bi ); - Ame0 = Be ^((~Bi)& Bo ); - Ami0 = Bi ^((~Bo)& Bu ); - Amo0 = Bo ^((~Bu)& Ba ); - Amu0 = Bu ^((~Ba)& Be ); - - Be = ROL32((Ama1^Da1), 18); - Bi = ROL32((Ame1^De1), 5); - Bo = ROL32((Ami1^Di0), 7); - Bu = ROL32((Amo1^Do1), 28); - Ba = ROL32((Amu1^Du0), 13); - Ama1 = Ba ^((~Be)& Bi ); - Ame1 = Be ^((~Bi)& Bo ); - Ami1 = Bi ^((~Bo)& Bu ); - Amo1 = Bo ^((~Bu)& Ba ); - Amu1 = Bu ^((~Ba)& Be ); - - Bo = ROL32((Asa0^Da1), 21); - Bu = ROL32((Ase0^De0), 1); - Ba = ROL32((Asi0^Di0), 31); - Be = ROL32((Aso0^Do1), 28); - Bi = ROL32((Asu0^Du1), 20); - Asa0 = Ba ^((~Be)& Bi ); - Ase0 = Be ^((~Bi)& Bo ); - Asi0 = Bi ^((~Bo)& Bu ); - Aso0 = Bo ^((~Bu)& Ba ); - Asu0 = Bu ^((~Ba)& Be ); - - Bo = ROL32((Asa1^Da0), 20); - Bu = ROL32((Ase1^De1), 1); - Ba = ROL32((Asi1^Di1), 31); - Be = ROL32((Aso1^Do0), 27); - Bi = ROL32((Asu1^Du0), 19); - Asa1 = Ba ^((~Be)& Bi ); - Ase1 = Be ^((~Bi)& Bo ); - Asi1 = Bi ^((~Bo)& Bu ); - Aso1 = Bo ^((~Bu)& Ba ); - Asu1 = Bu ^((~Ba)& Be ); - } - while ( *pRoundConstants != 0xFF ); - - #undef Aba0 - #undef Aba1 - #undef Abe0 - #undef Abe1 - #undef Abi0 - #undef Abi1 - #undef Abo0 - #undef Abo1 - #undef Abu0 - #undef Abu1 - #undef Aga0 - #undef Aga1 - #undef Age0 - #undef Age1 - #undef Agi0 - #undef Agi1 - #undef Ago0 - #undef Ago1 - #undef Agu0 - #undef Agu1 - #undef Aka0 - #undef Aka1 - #undef Ake0 - #undef Ake1 - #undef Aki0 - #undef Aki1 - #undef Ako0 - #undef Ako1 - #undef Aku0 - #undef Aku1 - #undef Ama0 - #undef Ama1 - #undef Ame0 - #undef Ame1 - #undef Ami0 - #undef Ami1 - #undef Amo0 - #undef Amo1 - #undef Amu0 - #undef Amu1 - #undef Asa0 - #undef Asa1 - #undef Ase0 - #undef Ase1 - #undef Asi0 - #undef Asi1 - #undef Aso0 - #undef Aso1 - #undef Asu0 - #undef Asu1 - } -} - -/* ---------------------------------------------------------------- */ - -void KeccakP1600_Permute_12rounds(void *state) -{ - KeccakP1600_Permute_Nrounds(state, 12); -} - -/* ---------------------------------------------------------------- */ - -void KeccakP1600_Permute_24rounds(void *state) -{ - KeccakP1600_Permute_Nrounds(state, 24); -} diff --git a/third_party/python/Modules/_sha3/kcp/KeccakP-1600-opt64-config.h b/third_party/python/Modules/_sha3/kcp/KeccakP-1600-opt64-config.h deleted file mode 100644 index ca76c5afb..000000000 --- a/third_party/python/Modules/_sha3/kcp/KeccakP-1600-opt64-config.h +++ /dev/null @@ -1,4 +0,0 @@ -/* clang-format off */ -#define KeccakP1600_implementation_config "lane complementing, all rounds unrolled" -#define KeccakP1600_fullUnrolling -#define KeccakP1600_useLaneComplementing diff --git a/third_party/python/Modules/_sha3/kcp/KeccakP-1600-opt64.c b/third_party/python/Modules/_sha3/kcp/KeccakP-1600-opt64.c deleted file mode 100644 index e499ba00f..000000000 --- a/third_party/python/Modules/_sha3/kcp/KeccakP-1600-opt64.c +++ /dev/null @@ -1,473 +0,0 @@ -/* clang-format off */ -/* -Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni, -Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby -denoted as "the implementer". - -For more information, feedback or questions, please refer to our websites: -http://keccak.noekeon.org/ -http://keyak.noekeon.org/ -http://ketje.noekeon.org/ - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -/* #include "brg_endian.h" */ -#include "KeccakP-1600-opt64-config.h" - -#if NOT_PYTHON -typedef unsigned char UINT8; -/* typedef unsigned long long int UINT64; */ -#endif - -#if defined(KeccakP1600_useLaneComplementing) -#define UseBebigokimisa -#endif - -#if defined(_MSC_VER) -#define ROL64(a, offset) _rotl64(a, offset) -#elif defined(KeccakP1600_useSHLD) - #define ROL64(x,N) ({ \ - register UINT64 __out; \ - register UINT64 __in = x; \ - __asm__ ("shld %2,%0,%0" : "=r"(__out) : "0"(__in), "i"(N)); \ - __out; \ - }) -#else -#define ROL64(a, offset) ((((UINT64)a) << offset) ^ (((UINT64)a) >> (64-offset))) -#endif - -#include "KeccakP-1600-64.macros" -#ifdef KeccakP1600_fullUnrolling -#define FullUnrolling -#else -#define Unrolling KeccakP1600_unrolling -#endif -#include "KeccakP-1600-unrolling.macros" -#include "SnP-Relaned.h" - -static const UINT64 KeccakF1600RoundConstants[24] = { - 0x0000000000000001ULL, - 0x0000000000008082ULL, - 0x800000000000808aULL, - 0x8000000080008000ULL, - 0x000000000000808bULL, - 0x0000000080000001ULL, - 0x8000000080008081ULL, - 0x8000000000008009ULL, - 0x000000000000008aULL, - 0x0000000000000088ULL, - 0x0000000080008009ULL, - 0x000000008000000aULL, - 0x000000008000808bULL, - 0x800000000000008bULL, - 0x8000000000008089ULL, - 0x8000000000008003ULL, - 0x8000000000008002ULL, - 0x8000000000000080ULL, - 0x000000000000800aULL, - 0x800000008000000aULL, - 0x8000000080008081ULL, - 0x8000000000008080ULL, - 0x0000000080000001ULL, - 0x8000000080008008ULL }; - -/* ---------------------------------------------------------------- */ - -void KeccakP1600_Initialize(void *state) -{ - memset(state, 0, 200); -#ifdef KeccakP1600_useLaneComplementing - ((UINT64*)state)[ 1] = ~(UINT64)0; - ((UINT64*)state)[ 2] = ~(UINT64)0; - ((UINT64*)state)[ 8] = ~(UINT64)0; - ((UINT64*)state)[12] = ~(UINT64)0; - ((UINT64*)state)[17] = ~(UINT64)0; - ((UINT64*)state)[20] = ~(UINT64)0; -#endif -} - -/* ---------------------------------------------------------------- */ - -void KeccakP1600_AddBytesInLane(void *state, unsigned int lanePosition, const unsigned char *data, unsigned int offset, unsigned int length) -{ -#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN) - UINT64 lane; - if (length == 0) - return; - if (length == 1) - lane = data[0]; - else { - lane = 0; - memcpy(&lane, data, length); - } - lane <<= offset*8; -#else - UINT64 lane = 0; - unsigned int i; - for(i=0; i>= offset*8; - for(i=0; i>= 8; - } -#endif -} - -/* ---------------------------------------------------------------- */ - -#if (PLATFORM_BYTE_ORDER != IS_LITTLE_ENDIAN) -void fromWordToBytes(UINT8 *bytes, const UINT64 word) -{ - unsigned int i; - - for(i=0; i<(64/8); i++) - bytes[i] = (word >> (8*i)) & 0xFF; -} -#endif - -void KeccakP1600_ExtractLanes(const void *state, unsigned char *data, unsigned int laneCount) -{ -#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN) - memcpy(data, state, laneCount*8); -#else - unsigned int i; - - for(i=0; i 1) { - ((UINT64*)data)[ 1] = ~((UINT64*)data)[ 1]; - if (laneCount > 2) { - ((UINT64*)data)[ 2] = ~((UINT64*)data)[ 2]; - if (laneCount > 8) { - ((UINT64*)data)[ 8] = ~((UINT64*)data)[ 8]; - if (laneCount > 12) { - ((UINT64*)data)[12] = ~((UINT64*)data)[12]; - if (laneCount > 17) { - ((UINT64*)data)[17] = ~((UINT64*)data)[17]; - if (laneCount > 20) { - ((UINT64*)data)[20] = ~((UINT64*)data)[20]; - } - } - } - } - } - } -#endif -} - -/* ---------------------------------------------------------------- */ - -void KeccakP1600_ExtractBytes(const void *state, unsigned char *data, unsigned int offset, unsigned int length) -{ - SnP_ExtractBytes(state, data, offset, length, KeccakP1600_ExtractLanes, KeccakP1600_ExtractBytesInLane, 8); -} - -/* ---------------------------------------------------------------- */ - -void KeccakP1600_ExtractAndAddBytesInLane(const void *state, unsigned int lanePosition, const unsigned char *input, unsigned char *output, unsigned int offset, unsigned int length) -{ - UINT64 lane = ((UINT64*)state)[lanePosition]; -#ifdef KeccakP1600_useLaneComplementing - if ((lanePosition == 1) || (lanePosition == 2) || (lanePosition == 8) || (lanePosition == 12) || (lanePosition == 17) || (lanePosition == 20)) - lane = ~lane; -#endif -#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN) - { - unsigned int i; - UINT64 lane1[1]; - lane1[0] = lane; - for(i=0; i>= offset*8; - for(i=0; i>= 8; - } -#endif -} - -/* ---------------------------------------------------------------- */ - -void KeccakP1600_ExtractAndAddLanes(const void *state, const unsigned char *input, unsigned char *output, unsigned int laneCount) -{ - unsigned int i; -#if (PLATFORM_BYTE_ORDER != IS_LITTLE_ENDIAN) - unsigned char temp[8]; - unsigned int j; -#endif - - for(i=0; i 1) { - ((UINT64*)output)[ 1] = ~((UINT64*)output)[ 1]; - if (laneCount > 2) { - ((UINT64*)output)[ 2] = ~((UINT64*)output)[ 2]; - if (laneCount > 8) { - ((UINT64*)output)[ 8] = ~((UINT64*)output)[ 8]; - if (laneCount > 12) { - ((UINT64*)output)[12] = ~((UINT64*)output)[12]; - if (laneCount > 17) { - ((UINT64*)output)[17] = ~((UINT64*)output)[17]; - if (laneCount > 20) { - ((UINT64*)output)[20] = ~((UINT64*)output)[20]; - } - } - } - } - } - } -#endif -} - -/* ---------------------------------------------------------------- */ - -void KeccakP1600_ExtractAndAddBytes(const void *state, const unsigned char *input, unsigned char *output, unsigned int offset, unsigned int length) -{ - SnP_ExtractAndAddBytes(state, input, output, offset, length, KeccakP1600_ExtractAndAddLanes, KeccakP1600_ExtractAndAddBytesInLane, 8); -} - -/* ---------------------------------------------------------------- */ - -size_t KeccakF1600_FastLoop_Absorb(void *state, unsigned int laneCount, const unsigned char *data, size_t dataByteLen) -{ - size_t originalDataByteLen = dataByteLen; - declareABCDE - #ifndef KeccakP1600_fullUnrolling - unsigned int i; - #endif - UINT64 *stateAsLanes = (UINT64*)state; - UINT64 *inDataAsLanes = (UINT64*)data; - - copyFromState(A, stateAsLanes) - while(dataByteLen >= laneCount*8) { - addInput(A, inDataAsLanes, laneCount) - rounds24 - inDataAsLanes += laneCount; - dataByteLen -= laneCount*8; - } - copyToState(stateAsLanes, A) - return originalDataByteLen - dataByteLen; -} diff --git a/third_party/python/Modules/_sha3/kcp/KeccakP-1600-unrolling.macros b/third_party/python/Modules/_sha3/kcp/KeccakP-1600-unrolling.macros deleted file mode 100644 index c20683015..000000000 --- a/third_party/python/Modules/_sha3/kcp/KeccakP-1600-unrolling.macros +++ /dev/null @@ -1,186 +0,0 @@ -/* clang-format off */ -/* -Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni, -Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby -denoted as "the implementer". - -For more information, feedback or questions, please refer to our websites: -http://keccak.noekeon.org/ -http://keyak.noekeon.org/ -http://ketje.noekeon.org/ - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#if (defined(FullUnrolling)) -#define rounds24 \ - prepareTheta \ - thetaRhoPiChiIotaPrepareTheta( 0, A, E) \ - thetaRhoPiChiIotaPrepareTheta( 1, E, A) \ - thetaRhoPiChiIotaPrepareTheta( 2, A, E) \ - thetaRhoPiChiIotaPrepareTheta( 3, E, A) \ - thetaRhoPiChiIotaPrepareTheta( 4, A, E) \ - thetaRhoPiChiIotaPrepareTheta( 5, E, A) \ - thetaRhoPiChiIotaPrepareTheta( 6, A, E) \ - thetaRhoPiChiIotaPrepareTheta( 7, E, A) \ - thetaRhoPiChiIotaPrepareTheta( 8, A, E) \ - thetaRhoPiChiIotaPrepareTheta( 9, E, A) \ - thetaRhoPiChiIotaPrepareTheta(10, A, E) \ - thetaRhoPiChiIotaPrepareTheta(11, E, A) \ - thetaRhoPiChiIotaPrepareTheta(12, A, E) \ - thetaRhoPiChiIotaPrepareTheta(13, E, A) \ - thetaRhoPiChiIotaPrepareTheta(14, A, E) \ - thetaRhoPiChiIotaPrepareTheta(15, E, A) \ - thetaRhoPiChiIotaPrepareTheta(16, A, E) \ - thetaRhoPiChiIotaPrepareTheta(17, E, A) \ - thetaRhoPiChiIotaPrepareTheta(18, A, E) \ - thetaRhoPiChiIotaPrepareTheta(19, E, A) \ - thetaRhoPiChiIotaPrepareTheta(20, A, E) \ - thetaRhoPiChiIotaPrepareTheta(21, E, A) \ - thetaRhoPiChiIotaPrepareTheta(22, A, E) \ - thetaRhoPiChiIota(23, E, A) \ - -#define rounds12 \ - prepareTheta \ - thetaRhoPiChiIotaPrepareTheta(12, A, E) \ - thetaRhoPiChiIotaPrepareTheta(13, E, A) \ - thetaRhoPiChiIotaPrepareTheta(14, A, E) \ - thetaRhoPiChiIotaPrepareTheta(15, E, A) \ - thetaRhoPiChiIotaPrepareTheta(16, A, E) \ - thetaRhoPiChiIotaPrepareTheta(17, E, A) \ - thetaRhoPiChiIotaPrepareTheta(18, A, E) \ - thetaRhoPiChiIotaPrepareTheta(19, E, A) \ - thetaRhoPiChiIotaPrepareTheta(20, A, E) \ - thetaRhoPiChiIotaPrepareTheta(21, E, A) \ - thetaRhoPiChiIotaPrepareTheta(22, A, E) \ - thetaRhoPiChiIota(23, E, A) \ - -#elif (Unrolling == 12) -#define rounds24 \ - prepareTheta \ - for(i=0; i<24; i+=12) { \ - thetaRhoPiChiIotaPrepareTheta(i , A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+ 1, E, A) \ - thetaRhoPiChiIotaPrepareTheta(i+ 2, A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+ 3, E, A) \ - thetaRhoPiChiIotaPrepareTheta(i+ 4, A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+ 5, E, A) \ - thetaRhoPiChiIotaPrepareTheta(i+ 6, A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+ 7, E, A) \ - thetaRhoPiChiIotaPrepareTheta(i+ 8, A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+ 9, E, A) \ - thetaRhoPiChiIotaPrepareTheta(i+10, A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+11, E, A) \ - } \ - -#define rounds12 \ - prepareTheta \ - thetaRhoPiChiIotaPrepareTheta(12, A, E) \ - thetaRhoPiChiIotaPrepareTheta(13, E, A) \ - thetaRhoPiChiIotaPrepareTheta(14, A, E) \ - thetaRhoPiChiIotaPrepareTheta(15, E, A) \ - thetaRhoPiChiIotaPrepareTheta(16, A, E) \ - thetaRhoPiChiIotaPrepareTheta(17, E, A) \ - thetaRhoPiChiIotaPrepareTheta(18, A, E) \ - thetaRhoPiChiIotaPrepareTheta(19, E, A) \ - thetaRhoPiChiIotaPrepareTheta(20, A, E) \ - thetaRhoPiChiIotaPrepareTheta(21, E, A) \ - thetaRhoPiChiIotaPrepareTheta(22, A, E) \ - thetaRhoPiChiIota(23, E, A) \ - -#elif (Unrolling == 6) -#define rounds24 \ - prepareTheta \ - for(i=0; i<24; i+=6) { \ - thetaRhoPiChiIotaPrepareTheta(i , A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \ - thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+3, E, A) \ - thetaRhoPiChiIotaPrepareTheta(i+4, A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+5, E, A) \ - } \ - -#define rounds12 \ - prepareTheta \ - for(i=12; i<24; i+=6) { \ - thetaRhoPiChiIotaPrepareTheta(i , A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \ - thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+3, E, A) \ - thetaRhoPiChiIotaPrepareTheta(i+4, A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+5, E, A) \ - } \ - -#elif (Unrolling == 4) -#define rounds24 \ - prepareTheta \ - for(i=0; i<24; i+=4) { \ - thetaRhoPiChiIotaPrepareTheta(i , A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \ - thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+3, E, A) \ - } \ - -#define rounds12 \ - prepareTheta \ - for(i=12; i<24; i+=4) { \ - thetaRhoPiChiIotaPrepareTheta(i , A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \ - thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+3, E, A) \ - } \ - -#elif (Unrolling == 3) -#define rounds24 \ - prepareTheta \ - for(i=0; i<24; i+=3) { \ - thetaRhoPiChiIotaPrepareTheta(i , A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \ - thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \ - copyStateVariables(A, E) \ - } \ - -#define rounds12 \ - prepareTheta \ - for(i=12; i<24; i+=3) { \ - thetaRhoPiChiIotaPrepareTheta(i , A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \ - thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \ - copyStateVariables(A, E) \ - } \ - -#elif (Unrolling == 2) -#define rounds24 \ - prepareTheta \ - for(i=0; i<24; i+=2) { \ - thetaRhoPiChiIotaPrepareTheta(i , A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \ - } \ - -#define rounds12 \ - prepareTheta \ - for(i=12; i<24; i+=2) { \ - thetaRhoPiChiIotaPrepareTheta(i , A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \ - } \ - -#elif (Unrolling == 1) -#define rounds24 \ - prepareTheta \ - for(i=0; i<24; i++) { \ - thetaRhoPiChiIotaPrepareTheta(i , A, E) \ - copyStateVariables(A, E) \ - } \ - -#define rounds12 \ - prepareTheta \ - for(i=12; i<24; i++) { \ - thetaRhoPiChiIotaPrepareTheta(i , A, E) \ - copyStateVariables(A, E) \ - } \ - -#else -#error "Unrolling is not correctly specified!" -#endif diff --git a/third_party/python/Modules/_sha3/kcp/KeccakSponge.c b/third_party/python/Modules/_sha3/kcp/KeccakSponge.c deleted file mode 100644 index 74dbd4284..000000000 --- a/third_party/python/Modules/_sha3/kcp/KeccakSponge.c +++ /dev/null @@ -1,93 +0,0 @@ -/* clang-format off */ -/* -Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni, -Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby -denoted as "the implementer". - -For more information, feedback or questions, please refer to our websites: -http://keccak.noekeon.org/ -http://keyak.noekeon.org/ -http://ketje.noekeon.org/ - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#include "KeccakSponge.h" - -#ifdef KeccakReference - #include "displayIntermediateValues.h" -#endif - -#ifndef KeccakP200_excluded - #include "KeccakP-200-SnP.h" - - #define prefix KeccakWidth200 - #define SnP KeccakP200 - #define SnP_width 200 - #define SnP_Permute KeccakP200_Permute_18rounds - #if defined(KeccakF200_FastLoop_supported) - #define SnP_FastLoop_Absorb KeccakF200_FastLoop_Absorb - #endif - #include "KeccakSponge.inc" - #undef prefix - #undef SnP - #undef SnP_width - #undef SnP_Permute - #undef SnP_FastLoop_Absorb -#endif - -#ifndef KeccakP400_excluded - #include "KeccakP-400-SnP.h" - - #define prefix KeccakWidth400 - #define SnP KeccakP400 - #define SnP_width 400 - #define SnP_Permute KeccakP400_Permute_20rounds - #if defined(KeccakF400_FastLoop_supported) - #define SnP_FastLoop_Absorb KeccakF400_FastLoop_Absorb - #endif - #include "KeccakSponge.inc" - #undef prefix - #undef SnP - #undef SnP_width - #undef SnP_Permute - #undef SnP_FastLoop_Absorb -#endif - -#ifndef KeccakP800_excluded - #include "KeccakP-800-SnP.h" - - #define prefix KeccakWidth800 - #define SnP KeccakP800 - #define SnP_width 800 - #define SnP_Permute KeccakP800_Permute_22rounds - #if defined(KeccakF800_FastLoop_supported) - #define SnP_FastLoop_Absorb KeccakF800_FastLoop_Absorb - #endif - #include "KeccakSponge.inc" - #undef prefix - #undef SnP - #undef SnP_width - #undef SnP_Permute - #undef SnP_FastLoop_Absorb -#endif - -#ifndef KeccakP1600_excluded - #include "KeccakP-1600-SnP.h" - - #define prefix KeccakWidth1600 - #define SnP KeccakP1600 - #define SnP_width 1600 - #define SnP_Permute KeccakP1600_Permute_24rounds - #if defined(KeccakF1600_FastLoop_supported) - #define SnP_FastLoop_Absorb KeccakF1600_FastLoop_Absorb - #endif - #include "KeccakSponge.inc" - #undef prefix - #undef SnP - #undef SnP_width - #undef SnP_Permute - #undef SnP_FastLoop_Absorb -#endif diff --git a/third_party/python/Modules/_sha3/kcp/KeccakSponge.h b/third_party/python/Modules/_sha3/kcp/KeccakSponge.h deleted file mode 100644 index 34ad62ead..000000000 --- a/third_party/python/Modules/_sha3/kcp/KeccakSponge.h +++ /dev/null @@ -1,172 +0,0 @@ -/* clang-format off */ -/* -Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni, -Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby -denoted as "the implementer". - -For more information, feedback or questions, please refer to our websites: -http://keccak.noekeon.org/ -http://keyak.noekeon.org/ -http://ketje.noekeon.org/ - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#ifndef _KeccakSponge_h_ -#define _KeccakSponge_h_ - -/** General information - * - * The following type and functions are not actually implemented. Their - * documentation is generic, with the prefix Prefix replaced by - * - KeccakWidth200 for a sponge function based on Keccak-f[200] - * - KeccakWidth400 for a sponge function based on Keccak-f[400] - * - KeccakWidth800 for a sponge function based on Keccak-f[800] - * - KeccakWidth1600 for a sponge function based on Keccak-f[1600] - * - * In all these functions, the rate and capacity must sum to the width of the - * chosen permutation. For instance, to use the sponge function - * Keccak[r=1344, c=256], one must use KeccakWidth1600_Sponge() or a combination - * of KeccakWidth1600_SpongeInitialize(), KeccakWidth1600_SpongeAbsorb(), - * KeccakWidth1600_SpongeAbsorbLastFewBits() and - * KeccakWidth1600_SpongeSqueeze(). - * - * The Prefix_SpongeInstance contains the sponge instance attributes for use - * with the Prefix_Sponge* functions. - * It gathers the state processed by the permutation as well as the rate, - * the position of input/output bytes in the state and the phase - * (absorbing or squeezing). - */ - -#ifdef DontReallyInclude_DocumentationOnly -/** Function to evaluate the sponge function Keccak[r, c] in a single call. - * @param rate The value of the rate r. - * @param capacity The value of the capacity c. - * @param input Pointer to the input message (before the suffix). - * @param inputByteLen The length of the input message in bytes. - * @param suffix Byte containing from 0 to 7 suffix bits - * that must be absorbed after @a input. - * These n bits must be in the least significant bit positions. - * These bits must be delimited with a bit 1 at position n - * (counting from 0=LSB to 7=MSB) and followed by bits 0 - * from position n+1 to position 7. - * Some examples: - * - If no bits are to be absorbed, then @a suffix must be 0x01. - * - If the 2-bit sequence 0,0 is to be absorbed, @a suffix must be 0x04. - * - If the 5-bit sequence 0,1,0,0,1 is to be absorbed, @a suffix must be 0x32. - * - If the 7-bit sequence 1,1,0,1,0,0,0 is to be absorbed, @a suffix must be 0x8B. - * . - * @param output Pointer to the output buffer. - * @param outputByteLen The desired number of output bytes. - * @pre One must have r+c equal to the supported width of this implementation - * and the rate a multiple of 8 bits (one byte) in this implementation. - * @pre @a suffix ≠ 0x00 - * @return Zero if successful, 1 otherwise. - */ -int Prefix_Sponge(unsigned int rate, unsigned int capacity, const unsigned char *input, size_t inputByteLen, unsigned char suffix, unsigned char *output, size_t outputByteLen); - -/** - * Function to initialize the state of the Keccak[r, c] sponge function. - * The phase of the sponge function is set to absorbing. - * @param spongeInstance Pointer to the sponge instance to be initialized. - * @param rate The value of the rate r. - * @param capacity The value of the capacity c. - * @pre One must have r+c equal to the supported width of this implementation - * and the rate a multiple of 8 bits (one byte) in this implementation. - * @return Zero if successful, 1 otherwise. - */ -int Prefix_SpongeInitialize(Prefix_SpongeInstance *spongeInstance, unsigned int rate, unsigned int capacity); - -/** - * Function to give input data bytes for the sponge function to absorb. - * @param spongeInstance Pointer to the sponge instance initialized by Prefix_SpongeInitialize(). - * @param data Pointer to the input data. - * @param dataByteLen The number of input bytes provided in the input data. - * @pre The sponge function must be in the absorbing phase, - * i.e., Prefix_SpongeSqueeze() or Prefix_SpongeAbsorbLastFewBits() - * must not have been called before. - * @return Zero if successful, 1 otherwise. - */ -int Prefix_SpongeAbsorb(Prefix_SpongeInstance *spongeInstance, const unsigned char *data, size_t dataByteLen); - -/** - * Function to give input data bits for the sponge function to absorb - * and then to switch to the squeezing phase. - * @param spongeInstance Pointer to the sponge instance initialized by Prefix_SpongeInitialize(). - * @param delimitedData Byte containing from 0 to 7 trailing bits - * that must be absorbed. - * These n bits must be in the least significant bit positions. - * These bits must be delimited with a bit 1 at position n - * (counting from 0=LSB to 7=MSB) and followed by bits 0 - * from position n+1 to position 7. - * Some examples: - * - If no bits are to be absorbed, then @a delimitedData must be 0x01. - * - If the 2-bit sequence 0,0 is to be absorbed, @a delimitedData must be 0x04. - * - If the 5-bit sequence 0,1,0,0,1 is to be absorbed, @a delimitedData must be 0x32. - * - If the 7-bit sequence 1,1,0,1,0,0,0 is to be absorbed, @a delimitedData must be 0x8B. - * . - * @pre The sponge function must be in the absorbing phase, - * i.e., Prefix_SpongeSqueeze() or Prefix_SpongeAbsorbLastFewBits() - * must not have been called before. - * @pre @a delimitedData ≠ 0x00 - * @return Zero if successful, 1 otherwise. - */ -int Prefix_SpongeAbsorbLastFewBits(Prefix_SpongeInstance *spongeInstance, unsigned char delimitedData); - -/** - * Function to squeeze output data from the sponge function. - * If the sponge function was in the absorbing phase, this function - * switches it to the squeezing phase - * as if Prefix_SpongeAbsorbLastFewBits(spongeInstance, 0x01) was called. - * @param spongeInstance Pointer to the sponge instance initialized by Prefix_SpongeInitialize(). - * @param data Pointer to the buffer where to store the output data. - * @param dataByteLen The number of output bytes desired. - * @return Zero if successful, 1 otherwise. - */ -int Prefix_SpongeSqueeze(Prefix_SpongeInstance *spongeInstance, unsigned char *data, size_t dataByteLen); -#endif - -#include "align.h" - -#define KCP_DeclareSpongeStructure(prefix, size, alignment) \ - ALIGN(alignment) typedef struct prefix##_SpongeInstanceStruct { \ - unsigned char state[size]; \ - unsigned int rate; \ - unsigned int byteIOIndex; \ - int squeezing; \ - } prefix##_SpongeInstance; - -#define KCP_DeclareSpongeFunctions(prefix) \ - int prefix##_Sponge(unsigned int rate, unsigned int capacity, const unsigned char *input, size_t inputByteLen, unsigned char suffix, unsigned char *output, size_t outputByteLen); \ - int prefix##_SpongeInitialize(prefix##_SpongeInstance *spongeInstance, unsigned int rate, unsigned int capacity); \ - int prefix##_SpongeAbsorb(prefix##_SpongeInstance *spongeInstance, const unsigned char *data, size_t dataByteLen); \ - int prefix##_SpongeAbsorbLastFewBits(prefix##_SpongeInstance *spongeInstance, unsigned char delimitedData); \ - int prefix##_SpongeSqueeze(prefix##_SpongeInstance *spongeInstance, unsigned char *data, size_t dataByteLen); - -#ifndef KeccakP200_excluded - #include "KeccakP-200-SnP.h" - KCP_DeclareSpongeStructure(KeccakWidth200, KeccakP200_stateSizeInBytes, KeccakP200_stateAlignment) - KCP_DeclareSpongeFunctions(KeccakWidth200) -#endif - -#ifndef KeccakP400_excluded - #include "KeccakP-400-SnP.h" - KCP_DeclareSpongeStructure(KeccakWidth400, KeccakP400_stateSizeInBytes, KeccakP400_stateAlignment) - KCP_DeclareSpongeFunctions(KeccakWidth400) -#endif - -#ifndef KeccakP800_excluded - #include "KeccakP-800-SnP.h" - KCP_DeclareSpongeStructure(KeccakWidth800, KeccakP800_stateSizeInBytes, KeccakP800_stateAlignment) - KCP_DeclareSpongeFunctions(KeccakWidth800) -#endif - -#ifndef KeccakP1600_excluded - #include "KeccakP-1600-SnP.h" - KCP_DeclareSpongeStructure(KeccakWidth1600, KeccakP1600_stateSizeInBytes, KeccakP1600_stateAlignment) - KCP_DeclareSpongeFunctions(KeccakWidth1600) -#endif - -#endif diff --git a/third_party/python/Modules/_sha3/kcp/KeccakSponge.inc b/third_party/python/Modules/_sha3/kcp/KeccakSponge.inc deleted file mode 100644 index 54767bd33..000000000 --- a/third_party/python/Modules/_sha3/kcp/KeccakSponge.inc +++ /dev/null @@ -1,333 +0,0 @@ -/* clang-format off */ -/* -Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni, -Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby -denoted as "the implementer". - -For more information, feedback or questions, please refer to our websites: -http://keccak.noekeon.org/ -http://keyak.noekeon.org/ -http://ketje.noekeon.org/ - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#define JOIN0(a, b) a ## b -#define JOIN(a, b) JOIN0(a, b) - -#define Sponge JOIN(prefix, _Sponge) -#define SpongeInstance JOIN(prefix, _SpongeInstance) -#define SpongeInitialize JOIN(prefix, _SpongeInitialize) -#define SpongeAbsorb JOIN(prefix, _SpongeAbsorb) -#define SpongeAbsorbLastFewBits JOIN(prefix, _SpongeAbsorbLastFewBits) -#define SpongeSqueeze JOIN(prefix, _SpongeSqueeze) - -#define SnP_stateSizeInBytes JOIN(SnP, _stateSizeInBytes) -#define SnP_stateAlignment JOIN(SnP, _stateAlignment) -#define SnP_StaticInitialize JOIN(SnP, _StaticInitialize) -#define SnP_Initialize JOIN(SnP, _Initialize) -#define SnP_AddByte JOIN(SnP, _AddByte) -#define SnP_AddBytes JOIN(SnP, _AddBytes) -#define SnP_ExtractBytes JOIN(SnP, _ExtractBytes) - -int Sponge(unsigned int rate, unsigned int capacity, const unsigned char *input, size_t inputByteLen, unsigned char suffix, unsigned char *output, size_t outputByteLen) -{ - ALIGN(SnP_stateAlignment) unsigned char state[SnP_stateSizeInBytes]; - unsigned int partialBlock; - const unsigned char *curInput = input; - unsigned char *curOutput = output; - unsigned int rateInBytes = rate/8; - - if (rate+capacity != SnP_width) - return 1; - if ((rate <= 0) || (rate > SnP_width) || ((rate % 8) != 0)) - return 1; - if (suffix == 0) - return 1; - - /* Initialize the state */ - - SnP_StaticInitialize(); - SnP_Initialize(state); - - /* First, absorb whole blocks */ - -#ifdef SnP_FastLoop_Absorb - if (((rateInBytes % (SnP_width/200)) == 0) && (inputByteLen >= rateInBytes)) { - /* fast lane: whole lane rate */ - - size_t j; - j = SnP_FastLoop_Absorb(state, rateInBytes/(SnP_width/200), curInput, inputByteLen); - curInput += j; - inputByteLen -= j; - } -#endif - while(inputByteLen >= (size_t)rateInBytes) { - #ifdef KeccakReference - displayBytes(1, "Block to be absorbed", curInput, rateInBytes); - #endif - SnP_AddBytes(state, curInput, 0, rateInBytes); - SnP_Permute(state); - curInput += rateInBytes; - inputByteLen -= rateInBytes; - } - - /* Then, absorb what remains */ - - partialBlock = (unsigned int)inputByteLen; - #ifdef KeccakReference - displayBytes(1, "Block to be absorbed (part)", curInput, partialBlock); - #endif - SnP_AddBytes(state, curInput, 0, partialBlock); - - /* Finally, absorb the suffix */ - - #ifdef KeccakReference - { - unsigned char delimitedData1[1]; - delimitedData1[0] = suffix; - displayBytes(1, "Block to be absorbed (last few bits + first bit of padding)", delimitedData1, 1); - } - #endif - /* Last few bits, whose delimiter coincides with first bit of padding */ - - SnP_AddByte(state, suffix, partialBlock); - /* If the first bit of padding is at position rate-1, we need a whole new block for the second bit of padding */ - - if ((suffix >= 0x80) && (partialBlock == (rateInBytes-1))) - SnP_Permute(state); - /* Second bit of padding */ - - SnP_AddByte(state, 0x80, rateInBytes-1); - #ifdef KeccakReference - { - unsigned char block[SnP_width/8]; - memset(block, 0, SnP_width/8); - block[rateInBytes-1] = 0x80; - displayBytes(1, "Second bit of padding", block, rateInBytes); - } - #endif - SnP_Permute(state); - #ifdef KeccakReference - displayText(1, "--- Switching to squeezing phase ---"); - #endif - - /* First, output whole blocks */ - - while(outputByteLen > (size_t)rateInBytes) { - SnP_ExtractBytes(state, curOutput, 0, rateInBytes); - SnP_Permute(state); - #ifdef KeccakReference - displayBytes(1, "Squeezed block", curOutput, rateInBytes); - #endif - curOutput += rateInBytes; - outputByteLen -= rateInBytes; - } - - /* Finally, output what remains */ - - partialBlock = (unsigned int)outputByteLen; - SnP_ExtractBytes(state, curOutput, 0, partialBlock); - #ifdef KeccakReference - displayBytes(1, "Squeezed block (part)", curOutput, partialBlock); - #endif - - return 0; -} - -/* ---------------------------------------------------------------- */ -/* ---------------------------------------------------------------- */ -/* ---------------------------------------------------------------- */ - -int SpongeInitialize(SpongeInstance *instance, unsigned int rate, unsigned int capacity) -{ - if (rate+capacity != SnP_width) - return 1; - if ((rate <= 0) || (rate > SnP_width) || ((rate % 8) != 0)) - return 1; - SnP_StaticInitialize(); - SnP_Initialize(instance->state); - instance->rate = rate; - instance->byteIOIndex = 0; - instance->squeezing = 0; - - return 0; -} - -/* ---------------------------------------------------------------- */ - -int SpongeAbsorb(SpongeInstance *instance, const unsigned char *data, size_t dataByteLen) -{ - size_t i, j; - unsigned int partialBlock; - const unsigned char *curData; - unsigned int rateInBytes = instance->rate/8; - - if (instance->squeezing) - return 1; /* Too late for additional input */ - - - i = 0; - curData = data; - while(i < dataByteLen) { - if ((instance->byteIOIndex == 0) && (dataByteLen >= (i + rateInBytes))) { -#ifdef SnP_FastLoop_Absorb - /* processing full blocks first */ - - if ((rateInBytes % (SnP_width/200)) == 0) { - /* fast lane: whole lane rate */ - - j = SnP_FastLoop_Absorb(instance->state, rateInBytes/(SnP_width/200), curData, dataByteLen - i); - i += j; - curData += j; - } - else { -#endif - for(j=dataByteLen-i; j>=rateInBytes; j-=rateInBytes) { - #ifdef KeccakReference - displayBytes(1, "Block to be absorbed", curData, rateInBytes); - #endif - SnP_AddBytes(instance->state, curData, 0, rateInBytes); - SnP_Permute(instance->state); - curData+=rateInBytes; - } - i = dataByteLen - j; -#ifdef SnP_FastLoop_Absorb - } -#endif - } - else { - /* normal lane: using the message queue */ - - partialBlock = (unsigned int)(dataByteLen - i); - if (partialBlock+instance->byteIOIndex > rateInBytes) - partialBlock = rateInBytes-instance->byteIOIndex; - #ifdef KeccakReference - displayBytes(1, "Block to be absorbed (part)", curData, partialBlock); - #endif - i += partialBlock; - - SnP_AddBytes(instance->state, curData, instance->byteIOIndex, partialBlock); - curData += partialBlock; - instance->byteIOIndex += partialBlock; - if (instance->byteIOIndex == rateInBytes) { - SnP_Permute(instance->state); - instance->byteIOIndex = 0; - } - } - } - return 0; -} - -/* ---------------------------------------------------------------- */ - -int SpongeAbsorbLastFewBits(SpongeInstance *instance, unsigned char delimitedData) -{ - unsigned int rateInBytes = instance->rate/8; - - if (delimitedData == 0) - return 1; - if (instance->squeezing) - return 1; /* Too late for additional input */ - - - #ifdef KeccakReference - { - unsigned char delimitedData1[1]; - delimitedData1[0] = delimitedData; - displayBytes(1, "Block to be absorbed (last few bits + first bit of padding)", delimitedData1, 1); - } - #endif - /* Last few bits, whose delimiter coincides with first bit of padding */ - - SnP_AddByte(instance->state, delimitedData, instance->byteIOIndex); - /* If the first bit of padding is at position rate-1, we need a whole new block for the second bit of padding */ - - if ((delimitedData >= 0x80) && (instance->byteIOIndex == (rateInBytes-1))) - SnP_Permute(instance->state); - /* Second bit of padding */ - - SnP_AddByte(instance->state, 0x80, rateInBytes-1); - #ifdef KeccakReference - { - unsigned char block[SnP_width/8]; - memset(block, 0, SnP_width/8); - block[rateInBytes-1] = 0x80; - displayBytes(1, "Second bit of padding", block, rateInBytes); - } - #endif - SnP_Permute(instance->state); - instance->byteIOIndex = 0; - instance->squeezing = 1; - #ifdef KeccakReference - displayText(1, "--- Switching to squeezing phase ---"); - #endif - return 0; -} - -/* ---------------------------------------------------------------- */ - -int SpongeSqueeze(SpongeInstance *instance, unsigned char *data, size_t dataByteLen) -{ - size_t i, j; - unsigned int partialBlock; - unsigned int rateInBytes = instance->rate/8; - unsigned char *curData; - - if (!instance->squeezing) - SpongeAbsorbLastFewBits(instance, 0x01); - - i = 0; - curData = data; - while(i < dataByteLen) { - if ((instance->byteIOIndex == rateInBytes) && (dataByteLen >= (i + rateInBytes))) { - for(j=dataByteLen-i; j>=rateInBytes; j-=rateInBytes) { - SnP_Permute(instance->state); - SnP_ExtractBytes(instance->state, curData, 0, rateInBytes); - #ifdef KeccakReference - displayBytes(1, "Squeezed block", curData, rateInBytes); - #endif - curData+=rateInBytes; - } - i = dataByteLen - j; - } - else { - /* normal lane: using the message queue */ - - if (instance->byteIOIndex == rateInBytes) { - SnP_Permute(instance->state); - instance->byteIOIndex = 0; - } - partialBlock = (unsigned int)(dataByteLen - i); - if (partialBlock+instance->byteIOIndex > rateInBytes) - partialBlock = rateInBytes-instance->byteIOIndex; - i += partialBlock; - - SnP_ExtractBytes(instance->state, curData, instance->byteIOIndex, partialBlock); - #ifdef KeccakReference - displayBytes(1, "Squeezed block (part)", curData, partialBlock); - #endif - curData += partialBlock; - instance->byteIOIndex += partialBlock; - } - } - return 0; -} - -/* ---------------------------------------------------------------- */ - -#undef Sponge -#undef SpongeInstance -#undef SpongeInitialize -#undef SpongeAbsorb -#undef SpongeAbsorbLastFewBits -#undef SpongeSqueeze -#undef SnP_stateSizeInBytes -#undef SnP_stateAlignment -#undef SnP_StaticInitialize -#undef SnP_Initialize -#undef SnP_AddByte -#undef SnP_AddBytes -#undef SnP_ExtractBytes diff --git a/third_party/python/Modules/_sha3/kcp/PlSnP-Fallback.inc b/third_party/python/Modules/_sha3/kcp/PlSnP-Fallback.inc deleted file mode 100644 index befabda25..000000000 --- a/third_party/python/Modules/_sha3/kcp/PlSnP-Fallback.inc +++ /dev/null @@ -1,258 +0,0 @@ -/* clang-format off */ -/* -Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni, -Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby -denoted as "the implementer". - -For more information, feedback or questions, please refer to our websites: -http://keccak.noekeon.org/ -http://keyak.noekeon.org/ -http://ketje.noekeon.org/ - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -/* expect PlSnP_baseParallelism, PlSnP_targetParallelism */ - -/* expect SnP_stateSizeInBytes, SnP_stateAlignment */ - -/* expect prefix */ - -/* expect SnP_* */ - - -#define JOIN0(a, b) a ## b -#define JOIN(a, b) JOIN0(a, b) - -#define PlSnP_StaticInitialize JOIN(prefix, _StaticInitialize) -#define PlSnP_InitializeAll JOIN(prefix, _InitializeAll) -#define PlSnP_AddByte JOIN(prefix, _AddByte) -#define PlSnP_AddBytes JOIN(prefix, _AddBytes) -#define PlSnP_AddLanesAll JOIN(prefix, _AddLanesAll) -#define PlSnP_OverwriteBytes JOIN(prefix, _OverwriteBytes) -#define PlSnP_OverwriteLanesAll JOIN(prefix, _OverwriteLanesAll) -#define PlSnP_OverwriteWithZeroes JOIN(prefix, _OverwriteWithZeroes) -#define PlSnP_ExtractBytes JOIN(prefix, _ExtractBytes) -#define PlSnP_ExtractLanesAll JOIN(prefix, _ExtractLanesAll) -#define PlSnP_ExtractAndAddBytes JOIN(prefix, _ExtractAndAddBytes) -#define PlSnP_ExtractAndAddLanesAll JOIN(prefix, _ExtractAndAddLanesAll) - -#if (PlSnP_baseParallelism == 1) - #define SnP_stateSizeInBytes JOIN(SnP, _stateSizeInBytes) - #define SnP_stateAlignment JOIN(SnP, _stateAlignment) -#else - #define SnP_stateSizeInBytes JOIN(SnP, _statesSizeInBytes) - #define SnP_stateAlignment JOIN(SnP, _statesAlignment) -#endif -#define PlSnP_factor ((PlSnP_targetParallelism)/(PlSnP_baseParallelism)) -#define SnP_stateOffset (((SnP_stateSizeInBytes+(SnP_stateAlignment-1))/SnP_stateAlignment)*SnP_stateAlignment) -#define stateWithIndex(i) ((unsigned char *)states+((i)*SnP_stateOffset)) - -#define SnP_StaticInitialize JOIN(SnP, _StaticInitialize) -#define SnP_Initialize JOIN(SnP, _Initialize) -#define SnP_InitializeAll JOIN(SnP, _InitializeAll) -#define SnP_AddByte JOIN(SnP, _AddByte) -#define SnP_AddBytes JOIN(SnP, _AddBytes) -#define SnP_AddLanesAll JOIN(SnP, _AddLanesAll) -#define SnP_OverwriteBytes JOIN(SnP, _OverwriteBytes) -#define SnP_OverwriteLanesAll JOIN(SnP, _OverwriteLanesAll) -#define SnP_OverwriteWithZeroes JOIN(SnP, _OverwriteWithZeroes) -#define SnP_ExtractBytes JOIN(SnP, _ExtractBytes) -#define SnP_ExtractLanesAll JOIN(SnP, _ExtractLanesAll) -#define SnP_ExtractAndAddBytes JOIN(SnP, _ExtractAndAddBytes) -#define SnP_ExtractAndAddLanesAll JOIN(SnP, _ExtractAndAddLanesAll) - -void PlSnP_StaticInitialize( void ) -{ - SnP_StaticInitialize(); -} - -void PlSnP_InitializeAll(void *states) -{ - unsigned int i; - - for(i=0; i 0) { \ - unsigned int _bytesInLane = SnP_laneLengthInBytes - _offsetInLane; \ - if (_bytesInLane > _sizeLeft) \ - _bytesInLane = _sizeLeft; \ - SnP_AddBytesInLane(state, _lanePosition, _curData, _offsetInLane, _bytesInLane); \ - _sizeLeft -= _bytesInLane; \ - _lanePosition++; \ - _offsetInLane = 0; \ - _curData += _bytesInLane; \ - } \ - } \ - } - -#define SnP_OverwriteBytes(state, data, offset, length, SnP_OverwriteLanes, SnP_OverwriteBytesInLane, SnP_laneLengthInBytes) \ - { \ - if ((offset) == 0) { \ - SnP_OverwriteLanes(state, data, (length)/SnP_laneLengthInBytes); \ - SnP_OverwriteBytesInLane(state, \ - (length)/SnP_laneLengthInBytes, \ - (data)+((length)/SnP_laneLengthInBytes)*SnP_laneLengthInBytes, \ - 0, \ - (length)%SnP_laneLengthInBytes); \ - } \ - else { \ - unsigned int _sizeLeft = (length); \ - unsigned int _lanePosition = (offset)/SnP_laneLengthInBytes; \ - unsigned int _offsetInLane = (offset)%SnP_laneLengthInBytes; \ - const unsigned char *_curData = (data); \ - while(_sizeLeft > 0) { \ - unsigned int _bytesInLane = SnP_laneLengthInBytes - _offsetInLane; \ - if (_bytesInLane > _sizeLeft) \ - _bytesInLane = _sizeLeft; \ - SnP_OverwriteBytesInLane(state, _lanePosition, _curData, _offsetInLane, _bytesInLane); \ - _sizeLeft -= _bytesInLane; \ - _lanePosition++; \ - _offsetInLane = 0; \ - _curData += _bytesInLane; \ - } \ - } \ - } - -#define SnP_ExtractBytes(state, data, offset, length, SnP_ExtractLanes, SnP_ExtractBytesInLane, SnP_laneLengthInBytes) \ - { \ - if ((offset) == 0) { \ - SnP_ExtractLanes(state, data, (length)/SnP_laneLengthInBytes); \ - SnP_ExtractBytesInLane(state, \ - (length)/SnP_laneLengthInBytes, \ - (data)+((length)/SnP_laneLengthInBytes)*SnP_laneLengthInBytes, \ - 0, \ - (length)%SnP_laneLengthInBytes); \ - } \ - else { \ - unsigned int _sizeLeft = (length); \ - unsigned int _lanePosition = (offset)/SnP_laneLengthInBytes; \ - unsigned int _offsetInLane = (offset)%SnP_laneLengthInBytes; \ - unsigned char *_curData = (data); \ - while(_sizeLeft > 0) { \ - unsigned int _bytesInLane = SnP_laneLengthInBytes - _offsetInLane; \ - if (_bytesInLane > _sizeLeft) \ - _bytesInLane = _sizeLeft; \ - SnP_ExtractBytesInLane(state, _lanePosition, _curData, _offsetInLane, _bytesInLane); \ - _sizeLeft -= _bytesInLane; \ - _lanePosition++; \ - _offsetInLane = 0; \ - _curData += _bytesInLane; \ - } \ - } \ - } - -#define SnP_ExtractAndAddBytes(state, input, output, offset, length, SnP_ExtractAndAddLanes, SnP_ExtractAndAddBytesInLane, SnP_laneLengthInBytes) \ - { \ - if ((offset) == 0) { \ - SnP_ExtractAndAddLanes(state, input, output, (length)/SnP_laneLengthInBytes); \ - SnP_ExtractAndAddBytesInLane(state, \ - (length)/SnP_laneLengthInBytes, \ - (input)+((length)/SnP_laneLengthInBytes)*SnP_laneLengthInBytes, \ - (output)+((length)/SnP_laneLengthInBytes)*SnP_laneLengthInBytes, \ - 0, \ - (length)%SnP_laneLengthInBytes); \ - } \ - else { \ - unsigned int _sizeLeft = (length); \ - unsigned int _lanePosition = (offset)/SnP_laneLengthInBytes; \ - unsigned int _offsetInLane = (offset)%SnP_laneLengthInBytes; \ - const unsigned char *_curInput = (input); \ - unsigned char *_curOutput = (output); \ - while(_sizeLeft > 0) { \ - unsigned int _bytesInLane = SnP_laneLengthInBytes - _offsetInLane; \ - if (_bytesInLane > _sizeLeft) \ - _bytesInLane = _sizeLeft; \ - SnP_ExtractAndAddBytesInLane(state, _lanePosition, _curInput, _curOutput, _offsetInLane, _bytesInLane); \ - _sizeLeft -= _bytesInLane; \ - _lanePosition++; \ - _offsetInLane = 0; \ - _curInput += _bytesInLane; \ - _curOutput += _bytesInLane; \ - } \ - } \ - } - -#endif diff --git a/third_party/python/Modules/_sha3/kcp/align.h b/third_party/python/Modules/_sha3/kcp/align.h deleted file mode 100644 index d57bec8a6..000000000 --- a/third_party/python/Modules/_sha3/kcp/align.h +++ /dev/null @@ -1,36 +0,0 @@ -/* clang-format off */ -/* -Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni, -Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby -denoted as "the implementer". - -For more information, feedback or questions, please refer to our websites: -http://keccak.noekeon.org/ -http://keyak.noekeon.org/ -http://ketje.noekeon.org/ - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#ifndef _align_h_ -#define _align_h_ - -/* on Mac OS-X and possibly others, ALIGN(x) is defined in param.h, and -Werror chokes on the redef. */ - -#ifdef ALIGN -#undef ALIGN -#endif - -#if defined(__GNUC__) -#define ALIGN(x) __attribute__ ((aligned(x))) -#elif defined(_MSC_VER) -#define ALIGN(x) __declspec(align(x)) -#elif defined(__ARMCC_VERSION) -#define ALIGN(x) __align(x) -#else -#define ALIGN(x) -#endif - -#endif diff --git a/third_party/python/Modules/_sha3/sha3module.c b/third_party/python/Modules/_sha3/sha3module.c deleted file mode 100644 index 583ba397e..000000000 --- a/third_party/python/Modules/_sha3/sha3module.c +++ /dev/null @@ -1,697 +0,0 @@ -/* clang-format off */ -/* SHA3 module - * - * This module provides an interface to the SHA3 algorithm - * - * See below for information about the original code this module was - * based upon. Additional work performed by: - * - * Andrew Kuchling (amk@amk.ca) - * Greg Stein (gstein@lyra.org) - * Trevor Perrin (trevp@trevp.net) - * Gregory P. Smith (greg@krypto.org) - * - * Copyright (C) 2012-2016 Christian Heimes (christian@python.org) - * Licensed to PSF under a Contributor Agreement. - * - */ - -#include "third_party/python/Modules/hashlib.h" -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/pystrhex.h" - -/* ************************************************************************** - * SHA-3 (Keccak) and SHAKE - * - * The code is based on KeccakCodePackage from 2016-04-23 - * commit 647f93079afc4ada3d23737477a6e52511ca41fd - * - * The reference implementation is altered in this points: - * - C++ comments are converted to ANSI C comments. - * - all function names are mangled - * - typedef for UINT64 is commented out. - * - brg_endian.h is removed - * - * *************************************************************************/ - -#ifdef __sparc -/* opt64 uses un-aligned memory access that causes a BUS error with msg - * 'invalid address alignment' on SPARC. */ -#define KeccakOpt 32 -#elif PY_BIG_ENDIAN -/* opt64 is not yet supported on big endian platforms */ -#define KeccakOpt 32 -#elif SIZEOF_VOID_P == 8 && defined(PY_UINT64_T) -/* opt64 works only on little-endian 64bit platforms with unsigned int64 */ -#define KeccakOpt 64 -#else -/* opt32 is used for the remaining 32 and 64bit platforms */ -#define KeccakOpt 32 -#endif - -#if KeccakOpt == 64 && defined(PY_UINT64_T) -/* 64bit platforms with unsigned int64 */ -typedef PY_UINT64_T UINT64; -typedef unsigned char UINT8; -#endif - -/* replacement for brg_endian.h */ -#define IS_LITTLE_ENDIAN 1234 -#define IS_BIG_ENDIAN 4321 -#if PY_LITTLE_ENDIAN -#define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN -#endif -#if PY_BIG_ENDIAN -#define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN -#endif - -/* mangle names */ -#define KeccakF1600_FastLoop_Absorb _PySHA3_KeccakF1600_FastLoop_Absorb -#define Keccak_HashFinal _PySHA3_Keccak_HashFinal -#define Keccak_HashInitialize _PySHA3_Keccak_HashInitialize -#define Keccak_HashSqueeze _PySHA3_Keccak_HashSqueeze -#define Keccak_HashUpdate _PySHA3_Keccak_HashUpdate -#define KeccakP1600_AddBytes _PySHA3_KeccakP1600_AddBytes -#define KeccakP1600_AddBytesInLane _PySHA3_KeccakP1600_AddBytesInLane -#define KeccakP1600_AddLanes _PySHA3_KeccakP1600_AddLanes -#define KeccakP1600_ExtractAndAddBytes _PySHA3_KeccakP1600_ExtractAndAddBytes -#define KeccakP1600_ExtractAndAddBytesInLane \ - _PySHA3_KeccakP1600_ExtractAndAddBytesInLane -#define KeccakP1600_ExtractAndAddLanes _PySHA3_KeccakP1600_ExtractAndAddLanes -#define KeccakP1600_ExtractBytes _PySHA3_KeccakP1600_ExtractBytes -#define KeccakP1600_ExtractBytesInLane _PySHA3_KeccakP1600_ExtractBytesInLane -#define KeccakP1600_ExtractLanes _PySHA3_KeccakP1600_ExtractLanes -#define KeccakP1600_Initialize _PySHA3_KeccakP1600_Initialize -#define KeccakP1600_OverwriteBytes _PySHA3_KeccakP1600_OverwriteBytes -#define KeccakP1600_OverwriteBytesInLane \ - _PySHA3_KeccakP1600_OverwriteBytesInLane -#define KeccakP1600_OverwriteLanes _PySHA3_KeccakP1600_OverwriteLanes -#define KeccakP1600_OverwriteWithZeroes _PySHA3_KeccakP1600_OverwriteWithZeroes -#define KeccakP1600_Permute_12rounds _PySHA3_KeccakP1600_Permute_12rounds -#define KeccakP1600_Permute_24rounds _PySHA3_KeccakP1600_Permute_24rounds -#define KeccakWidth1600_Sponge _PySHA3_KeccakWidth1600_Sponge -#define KeccakWidth1600_SpongeAbsorb _PySHA3_KeccakWidth1600_SpongeAbsorb -#define KeccakWidth1600_SpongeAbsorbLastFewBits \ - _PySHA3_KeccakWidth1600_SpongeAbsorbLastFewBits -#define KeccakWidth1600_SpongeInitialize \ - _PySHA3_KeccakWidth1600_SpongeInitialize -#define KeccakWidth1600_SpongeSqueeze _PySHA3_KeccakWidth1600_SpongeSqueeze -#if KeccakOpt == 32 -#define KeccakP1600_AddByte _PySHA3_KeccakP1600_AddByte -#define KeccakP1600_Permute_Nrounds _PySHA3_KeccakP1600_Permute_Nrounds -#define KeccakP1600_SetBytesInLaneToZero \ - _PySHA3_KeccakP1600_SetBytesInLaneToZero -#endif - -/* we are only interested in KeccakP1600 */ -#define KeccakP200_excluded 1 -#define KeccakP400_excluded 1 -#define KeccakP800_excluded 1 - -/* inline all Keccak dependencies */ -#include "kcp/KeccakHash.c" -#include "kcp/KeccakHash.h" -#include "kcp/KeccakSponge.c" -#include "kcp/KeccakSponge.h" -#if KeccakOpt == 64 -#include "kcp/KeccakP-1600-opt64.c" -#elif KeccakOpt == 32 -#include "kcp/KeccakP-1600-inplace32BI.c" -#endif - -#define SHA3_MAX_DIGESTSIZE 64 /* 64 Bytes (512 Bits) for 224 to 512 */ -#define SHA3_LANESIZE (20 * 8) /* ExtractLane needs max uint64_t[20] extra. */ -#define SHA3_state Keccak_HashInstance -#define SHA3_init Keccak_HashInitialize -#define SHA3_process Keccak_HashUpdate -#define SHA3_done Keccak_HashFinal -#define SHA3_squeeze Keccak_HashSqueeze -#define SHA3_copystate(dest, src) memcpy(&(dest), &(src), sizeof(SHA3_state)) - -/*[clinic input] -module _sha3 -class _sha3.sha3_224 "SHA3object *" "&SHA3_224typ" -class _sha3.sha3_256 "SHA3object *" "&SHA3_256typ" -class _sha3.sha3_384 "SHA3object *" "&SHA3_384typ" -class _sha3.sha3_512 "SHA3object *" "&SHA3_512typ" -class _sha3.shake_128 "SHA3object *" "&SHAKE128type" -class _sha3.shake_256 "SHA3object *" "&SHAKE256type" -[clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=b8a53680f370285a]*/ - -/* The structure for storing SHA3 info */ - -typedef struct { - PyObject_HEAD SHA3_state hash_state; -#ifdef WITH_THREAD - PyThread_type_lock lock; -#endif -} SHA3object; - -static PyTypeObject SHA3_224type; -static PyTypeObject SHA3_256type; -static PyTypeObject SHA3_384type; -static PyTypeObject SHA3_512type; -#ifdef PY_WITH_KECCAK -static PyTypeObject Keccak_224type; -static PyTypeObject Keccak_256type; -static PyTypeObject Keccak_384type; -static PyTypeObject Keccak_512type; -#endif -static PyTypeObject SHAKE128type; -static PyTypeObject SHAKE256type; - -#include "third_party/python/Modules/_sha3/clinic/sha3module.c.h" - -static SHA3object *newSHA3object(PyTypeObject *type) { - SHA3object *newobj; - newobj = (SHA3object *)PyObject_New(SHA3object, type); - if (newobj == NULL) { - return NULL; - } -#ifdef WITH_THREAD - newobj->lock = NULL; -#endif - return newobj; -} - -static PyObject *py_sha3_new(PyTypeObject *type, PyObject *args, - PyObject *kwargs) { - SHA3object *self = NULL; - Py_buffer buf = {NULL, NULL}; - HashReturn res; - PyObject *data = NULL; - - if (!_PyArg_NoKeywords(type->tp_name, kwargs)) { - return NULL; - } - if (!PyArg_UnpackTuple(args, type->tp_name, 0, 1, &data)) { - return NULL; - } - - self = newSHA3object(type); - if (self == NULL) { - goto error; - } - - if (type == &SHA3_224type) { - res = Keccak_HashInitialize_SHA3_224(&self->hash_state); - } else if (type == &SHA3_256type) { - res = Keccak_HashInitialize_SHA3_256(&self->hash_state); - } else if (type == &SHA3_384type) { - res = Keccak_HashInitialize_SHA3_384(&self->hash_state); - } else if (type == &SHA3_512type) { - res = Keccak_HashInitialize_SHA3_512(&self->hash_state); -#ifdef PY_WITH_KECCAK - } else if (type == &Keccak_224type) { - res = Keccak_HashInitialize(&self->hash_state, 1152, 448, 224, 0x01); - } else if (type == &Keccak_256type) { - res = Keccak_HashInitialize(&self->hash_state, 1088, 512, 256, 0x01); - } else if (type == &Keccak_384type) { - res = Keccak_HashInitialize(&self->hash_state, 832, 768, 384, 0x01); - } else if (type == &Keccak_512type) { - res = Keccak_HashInitialize(&self->hash_state, 576, 1024, 512, 0x01); -#endif - } else if (type == &SHAKE128type) { - res = Keccak_HashInitialize_SHAKE128(&self->hash_state); - } else if (type == &SHAKE256type) { - res = Keccak_HashInitialize_SHAKE256(&self->hash_state); - } else { - PyErr_BadInternalCall(); - goto error; - } - - if (data) { - GET_BUFFER_VIEW_OR_ERROR(data, &buf, goto error); -#ifdef WITH_THREAD - if (buf.len >= HASHLIB_GIL_MINSIZE) { - /* invariant: New objects can't be accessed by other code yet, - * thus it's safe to release the GIL without locking the object. - */ - Py_BEGIN_ALLOW_THREADS res = - SHA3_process(&self->hash_state, buf.buf, buf.len * 8); - Py_END_ALLOW_THREADS - } else { - res = SHA3_process(&self->hash_state, buf.buf, buf.len * 8); - } -#else - res = SHA3_process(&self->hash_state, buf.buf, buf.len * 8); -#endif - if (res != SUCCESS) { - PyErr_SetString(PyExc_RuntimeError, "internal error in SHA3 Update()"); - goto error; - } - PyBuffer_Release(&buf); - } - - return (PyObject *)self; - -error: - if (self) { - Py_DECREF(self); - } - if (data && buf.obj) { - PyBuffer_Release(&buf); - } - return NULL; -} - -/* Internal methods for a hash object */ - -static void SHA3_dealloc(SHA3object *self) { -#ifdef WITH_THREAD - if (self->lock) { - PyThread_free_lock(self->lock); - } -#endif - PyObject_Del(self); -} - -/* External methods for a hash object */ - -/*[clinic input] -_sha3.sha3_224.copy - -Return a copy of the hash object. -[clinic start generated code]*/ - -static PyObject *_sha3_sha3_224_copy_impl(SHA3object *self) -/*[clinic end generated code: output=6c537411ecdcda4c input=93a44aaebea51ba8]*/ -{ - SHA3object *newobj; - - if ((newobj = newSHA3object(Py_TYPE(self))) == NULL) { - return NULL; - } - ENTER_HASHLIB(self); - SHA3_copystate(newobj->hash_state, self->hash_state); - LEAVE_HASHLIB(self); - return (PyObject *)newobj; -} - -/*[clinic input] -_sha3.sha3_224.digest - -Return the digest value as a bytes object. -[clinic start generated code]*/ - -static PyObject *_sha3_sha3_224_digest_impl(SHA3object *self) -/*[clinic end generated code: output=fd531842e20b2d5b input=5b2a659536bbd248]*/ -{ - unsigned char digest[SHA3_MAX_DIGESTSIZE + SHA3_LANESIZE]; - SHA3_state temp; - HashReturn res; - - ENTER_HASHLIB(self); - SHA3_copystate(temp, self->hash_state); - LEAVE_HASHLIB(self); - res = SHA3_done(&temp, digest); - if (res != SUCCESS) { - PyErr_SetString(PyExc_RuntimeError, "internal error in SHA3 Final()"); - return NULL; - } - return PyBytes_FromStringAndSize((const char *)digest, - self->hash_state.fixedOutputLength / 8); -} - -/*[clinic input] -_sha3.sha3_224.hexdigest - -Return the digest value as a string of hexadecimal digits. -[clinic start generated code]*/ - -static PyObject *_sha3_sha3_224_hexdigest_impl(SHA3object *self) -/*[clinic end generated code: output=75ad03257906918d input=2d91bb6e0d114ee3]*/ -{ - unsigned char digest[SHA3_MAX_DIGESTSIZE + SHA3_LANESIZE]; - SHA3_state temp; - HashReturn res; - - /* Get the raw (binary) digest value */ - ENTER_HASHLIB(self); - SHA3_copystate(temp, self->hash_state); - LEAVE_HASHLIB(self); - res = SHA3_done(&temp, digest); - if (res != SUCCESS) { - PyErr_SetString(PyExc_RuntimeError, "internal error in SHA3 Final()"); - return NULL; - } - return _Py_strhex((const char *)digest, - self->hash_state.fixedOutputLength / 8); -} - -/*[clinic input] -_sha3.sha3_224.update - - data: object - / - -Update this hash object's state with the provided bytes-like object. -[clinic start generated code]*/ - -static PyObject *_sha3_sha3_224_update(SHA3object *self, PyObject *data) -/*[clinic end generated code: output=d3223352286ed357 input=a887f54dcc4ae227]*/ -{ - Py_buffer buf; - HashReturn res; - - GET_BUFFER_VIEW_OR_ERROUT(data, &buf); - - /* add new data, the function takes the length in bits not bytes */ -#ifdef WITH_THREAD - if (self->lock == NULL && buf.len >= HASHLIB_GIL_MINSIZE) { - self->lock = PyThread_allocate_lock(); - } - /* Once a lock exists all code paths must be synchronized. We have to - * release the GIL even for small buffers as acquiring the lock may take - * an unlimited amount of time when another thread updates this object - * with lots of data. */ - if (self->lock) { - Py_BEGIN_ALLOW_THREADS PyThread_acquire_lock(self->lock, 1); - res = SHA3_process(&self->hash_state, buf.buf, buf.len * 8); - PyThread_release_lock(self->lock); - Py_END_ALLOW_THREADS - } else { - res = SHA3_process(&self->hash_state, buf.buf, buf.len * 8); - } -#else - res = SHA3_process(&self->hash_state, buf.buf, buf.len * 8); -#endif - - if (res != SUCCESS) { - PyBuffer_Release(&buf); - PyErr_SetString(PyExc_RuntimeError, "internal error in SHA3 Update()"); - return NULL; - } - - PyBuffer_Release(&buf); - Py_INCREF(Py_None); - return Py_None; -} - -static PyMethodDef SHA3_methods[] = { - _SHA3_SHA3_224_COPY_METHODDEF _SHA3_SHA3_224_DIGEST_METHODDEF - _SHA3_SHA3_224_HEXDIGEST_METHODDEF _SHA3_SHA3_224_UPDATE_METHODDEF{ - NULL, NULL} /* sentinel */ -}; - -static PyObject *SHA3_get_block_size(SHA3object *self, void *closure) { - int rate = self->hash_state.sponge.rate; - return PyLong_FromLong(rate / 8); -} - -static PyObject *SHA3_get_name(SHA3object *self, void *closure) { - PyTypeObject *type = Py_TYPE(self); - if (type == &SHA3_224type) { - return PyUnicode_FromString("sha3_224"); - } else if (type == &SHA3_256type) { - return PyUnicode_FromString("sha3_256"); - } else if (type == &SHA3_384type) { - return PyUnicode_FromString("sha3_384"); - } else if (type == &SHA3_512type) { - return PyUnicode_FromString("sha3_512"); -#ifdef PY_WITH_KECCAK - } else if (type == &Keccak_224type) { - return PyUnicode_FromString("keccak_224"); - } else if (type == &Keccak_256type) { - return PyUnicode_FromString("keccak_256"); - } else if (type == &Keccak_384type) { - return PyUnicode_FromString("keccak_384"); - } else if (type == &Keccak_512type) { - return PyUnicode_FromString("keccak_512"); -#endif - } else if (type == &SHAKE128type) { - return PyUnicode_FromString("shake_128"); - } else if (type == &SHAKE256type) { - return PyUnicode_FromString("shake_256"); - } else { - PyErr_BadInternalCall(); - return NULL; - } -} - -static PyObject *SHA3_get_digest_size(SHA3object *self, void *closure) { - return PyLong_FromLong(self->hash_state.fixedOutputLength / 8); -} - -static PyObject *SHA3_get_capacity_bits(SHA3object *self, void *closure) { - int capacity = 1600 - self->hash_state.sponge.rate; - return PyLong_FromLong(capacity); -} - -static PyObject *SHA3_get_rate_bits(SHA3object *self, void *closure) { - unsigned int rate = self->hash_state.sponge.rate; - return PyLong_FromLong(rate); -} - -static PyObject *SHA3_get_suffix(SHA3object *self, void *closure) { - unsigned char suffix[2]; - suffix[0] = self->hash_state.delimitedSuffix; - suffix[1] = 0; - return PyBytes_FromStringAndSize((const char *)suffix, 1); -} - -static PyGetSetDef SHA3_getseters[] = { - {"block_size", (getter)SHA3_get_block_size, NULL, NULL, NULL}, - {"name", (getter)SHA3_get_name, NULL, NULL, NULL}, - {"digest_size", (getter)SHA3_get_digest_size, NULL, NULL, NULL}, - {"_capacity_bits", (getter)SHA3_get_capacity_bits, NULL, NULL, NULL}, - {"_rate_bits", (getter)SHA3_get_rate_bits, NULL, NULL, NULL}, - {"_suffix", (getter)SHA3_get_suffix, NULL, NULL, NULL}, - {NULL} /* Sentinel */ -}; - -#define SHA3_TYPE(type_obj, type_name, type_doc, type_methods) \ - static PyTypeObject type_obj = { \ - PyVarObject_HEAD_INIT(NULL, 0) type_name, /* tp_name */ \ - sizeof(SHA3object), /* tp_basicsize */ \ - 0, \ - /* tp_itemsize */ /* methods */ \ - (destructor)SHA3_dealloc, /* tp_dealloc */ \ - 0, /* tp_print */ \ - 0, /* tp_getattr */ \ - 0, /* tp_setattr */ \ - 0, /* tp_reserved */ \ - 0, /* tp_repr */ \ - 0, /* tp_as_number */ \ - 0, /* tp_as_sequence */ \ - 0, /* tp_as_mapping */ \ - 0, /* tp_hash */ \ - 0, /* tp_call */ \ - 0, /* tp_str */ \ - 0, /* tp_getattro */ \ - 0, /* tp_setattro */ \ - 0, /* tp_as_buffer */ \ - Py_TPFLAGS_DEFAULT, /* tp_flags */ \ - type_doc, /* tp_doc */ \ - 0, /* tp_traverse */ \ - 0, /* tp_clear */ \ - 0, /* tp_richcompare */ \ - 0, /* tp_weaklistoffset */ \ - 0, /* tp_iter */ \ - 0, /* tp_iternext */ \ - type_methods, /* tp_methods */ \ - NULL, /* tp_members */ \ - SHA3_getseters, /* tp_getset */ \ - 0, /* tp_base */ \ - 0, /* tp_dict */ \ - 0, /* tp_descr_get */ \ - 0, /* tp_descr_set */ \ - 0, /* tp_dictoffset */ \ - 0, /* tp_init */ \ - 0, /* tp_alloc */ \ - py_sha3_new, /* tp_new */ \ - } - -PyDoc_STRVAR(sha3_224__doc__, "sha3_224([data]) -> SHA3 object\n\ -\n\ -Return a new SHA3 hash object with a hashbit length of 28 bytes."); - -PyDoc_STRVAR(sha3_256__doc__, "sha3_256([data]) -> SHA3 object\n\ -\n\ -Return a new SHA3 hash object with a hashbit length of 32 bytes."); - -PyDoc_STRVAR(sha3_384__doc__, "sha3_384([data]) -> SHA3 object\n\ -\n\ -Return a new SHA3 hash object with a hashbit length of 48 bytes."); - -PyDoc_STRVAR(sha3_512__doc__, "sha3_512([data]) -> SHA3 object\n\ -\n\ -Return a new SHA3 hash object with a hashbit length of 64 bytes."); - -SHA3_TYPE(SHA3_224type, "_sha3.sha3_224", sha3_224__doc__, SHA3_methods); -SHA3_TYPE(SHA3_256type, "_sha3.sha3_256", sha3_256__doc__, SHA3_methods); -SHA3_TYPE(SHA3_384type, "_sha3.sha3_384", sha3_384__doc__, SHA3_methods); -SHA3_TYPE(SHA3_512type, "_sha3.sha3_512", sha3_512__doc__, SHA3_methods); - -#ifdef PY_WITH_KECCAK -PyDoc_STRVAR(keccak_224__doc__, "keccak_224([data]) -> Keccak object\n\ -\n\ -Return a new Keccak hash object with a hashbit length of 28 bytes."); - -PyDoc_STRVAR(keccak_256__doc__, "keccak_256([data]) -> Keccak object\n\ -\n\ -Return a new Keccak hash object with a hashbit length of 32 bytes."); - -PyDoc_STRVAR(keccak_384__doc__, "keccak_384([data]) -> Keccak object\n\ -\n\ -Return a new Keccak hash object with a hashbit length of 48 bytes."); - -PyDoc_STRVAR(keccak_512__doc__, "keccak_512([data]) -> Keccak object\n\ -\n\ -Return a new Keccak hash object with a hashbit length of 64 bytes."); - -SHA3_TYPE(Keccak_224type, "_sha3.keccak_224", keccak_224__doc__, SHA3_methods); -SHA3_TYPE(Keccak_256type, "_sha3.keccak_256", keccak_256__doc__, SHA3_methods); -SHA3_TYPE(Keccak_384type, "_sha3.keccak_384", keccak_384__doc__, SHA3_methods); -SHA3_TYPE(Keccak_512type, "_sha3.keccak_512", keccak_512__doc__, SHA3_methods); -#endif - -static PyObject *_SHAKE_digest(SHA3object *self, PyObject *digestlen_obj, - int hex) { - unsigned long digestlen; - unsigned char *digest = NULL; - SHA3_state temp; - int res; - PyObject *result = NULL; - - digestlen = PyLong_AsUnsignedLong(digestlen_obj); - if (digestlen == (unsigned long)-1 && PyErr_Occurred()) { - return NULL; - } - if (digestlen >= (1 << 29)) { - PyErr_SetString(PyExc_ValueError, "length is too large"); - return NULL; - } - /* ExtractLane needs at least SHA3_MAX_DIGESTSIZE + SHA3_LANESIZE and - * SHA3_LANESIZE extra space. - */ - digest = (unsigned char *)PyMem_Malloc(digestlen + SHA3_LANESIZE); - if (digest == NULL) { - return PyErr_NoMemory(); - } - - /* Get the raw (binary) digest value */ - ENTER_HASHLIB(self); - SHA3_copystate(temp, self->hash_state); - LEAVE_HASHLIB(self); - res = SHA3_done(&temp, NULL); - if (res != SUCCESS) { - PyErr_SetString(PyExc_RuntimeError, "internal error in SHA3 done()"); - goto error; - } - res = SHA3_squeeze(&temp, digest, digestlen * 8); - if (res != SUCCESS) { - PyErr_SetString(PyExc_RuntimeError, "internal error in SHA3 Squeeze()"); - return NULL; - } - if (hex) { - result = _Py_strhex((const char *)digest, digestlen); - } else { - result = PyBytes_FromStringAndSize((const char *)digest, digestlen); - } -error: - if (digest != NULL) { - PyMem_Free(digest); - } - return result; -} - -/*[clinic input] -_sha3.shake_128.digest - - length: object - / - -Return the digest value as a bytes object. -[clinic start generated code]*/ - -static PyObject *_sha3_shake_128_digest(SHA3object *self, PyObject *length) -/*[clinic end generated code: output=eaa80b6299142396 input=c579eb109f6227d2]*/ -{ - return _SHAKE_digest(self, length, 0); -} - -/*[clinic input] -_sha3.shake_128.hexdigest - - length: object - / - -Return the digest value as a string of hexadecimal digits. -[clinic start generated code]*/ - -static PyObject *_sha3_shake_128_hexdigest(SHA3object *self, PyObject *length) -/*[clinic end generated code: output=4752f90e53c8bf2a input=a82694ea83865f5a]*/ -{ - return _SHAKE_digest(self, length, 1); -} - -static PyMethodDef SHAKE_methods[] = { - _SHA3_SHA3_224_COPY_METHODDEF _SHA3_SHAKE_128_DIGEST_METHODDEF - _SHA3_SHAKE_128_HEXDIGEST_METHODDEF _SHA3_SHA3_224_UPDATE_METHODDEF{ - NULL, NULL} /* sentinel */ -}; - -PyDoc_STRVAR(shake_128__doc__, "shake_128([data]) -> SHAKE object\n\ -\n\ -Return a new SHAKE hash object."); - -PyDoc_STRVAR(shake_256__doc__, "shake_256([data]) -> SHAKE object\n\ -\n\ -Return a new SHAKE hash object."); - -SHA3_TYPE(SHAKE128type, "_sha3.shake_128", shake_128__doc__, SHAKE_methods); -SHA3_TYPE(SHAKE256type, "_sha3.shake_256", shake_256__doc__, SHAKE_methods); - -/* Initialize this module. */ -static struct PyModuleDef _SHA3module = { - PyModuleDef_HEAD_INIT, "_sha3", NULL, -1, NULL, NULL, NULL, NULL, NULL}; - -PyMODINIT_FUNC PyInit__sha3(void) { - PyObject *m = NULL; - - if ((m = PyModule_Create(&_SHA3module)) == NULL) { - return NULL; - } - -#define init_sha3type(name, type) \ - do { \ - Py_TYPE(type) = &PyType_Type; \ - if (PyType_Ready(type) < 0) { \ - goto error; \ - } \ - Py_INCREF((PyObject *)type); \ - if (PyModule_AddObject(m, name, (PyObject *)type) < 0) { \ - goto error; \ - } \ - } while (0) - - init_sha3type("sha3_224", &SHA3_224type); - init_sha3type("sha3_256", &SHA3_256type); - init_sha3type("sha3_384", &SHA3_384type); - init_sha3type("sha3_512", &SHA3_512type); -#ifdef PY_WITH_KECCAK - init_sha3type("keccak_224", &Keccak_224type); - init_sha3type("keccak_256", &Keccak_256type); - init_sha3type("keccak_384", &Keccak_384type); - init_sha3type("keccak_512", &Keccak_512type); -#endif - init_sha3type("shake_128", &SHAKE128type); - init_sha3type("shake_256", &SHAKE256type); - -#undef init_sha3type - - if (PyModule_AddIntConstant(m, "keccakopt", KeccakOpt) < 0) { - goto error; - } - if (PyModule_AddStringConstant(m, "implementation", - KeccakP1600_implementation) < 0) { - goto error; - } - - return m; -error: - Py_DECREF(m); - return NULL; -} diff --git a/third_party/python/Modules/_sqlite/cache.h b/third_party/python/Modules/_sqlite/cache.h index f4ba0b66f..ca0cbe312 100644 --- a/third_party/python/Modules/_sqlite/cache.h +++ b/third_party/python/Modules/_sqlite/cache.h @@ -1,30 +1,7 @@ -/* clang-format off */ -/* cache.h - definitions for the LRU cache - * - * Copyright (C) 2004-2010 Gerhard Häring - * - * This file is part of pysqlite. - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - #ifndef PYSQLITE_CACHE_H #define PYSQLITE_CACHE_H -#include "Python.h" +#include "third_party/python/Include/Python.h" +/* clang-format off */ /* The LRU cache is implemented as a combination of a doubly-linked with a * dictionary. The list items are of type 'Node' and the dictionary has the diff --git a/third_party/python/Modules/_sqlite/connection.c b/third_party/python/Modules/_sqlite/connection.c index c48059c9c..f798b3564 100644 --- a/third_party/python/Modules/_sqlite/connection.c +++ b/third_party/python/Modules/_sqlite/connection.c @@ -22,16 +22,15 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include "cache.h" -#include "module.h" -#include "structmember.h" -#include "connection.h" -#include "statement.h" -#include "cursor.h" -#include "prepare_protocol.h" -#include "util.h" - -#include "pythread.h" +#include "third_party/python/Modules/_sqlite/cache.h" +#include "third_party/python/Modules/_sqlite/module.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Modules/_sqlite/connection.h" +#include "third_party/python/Modules/_sqlite/statement.h" +#include "third_party/python/Modules/_sqlite/cursor.h" +#include "third_party/python/Modules/_sqlite/prepare_protocol.h" +#include "third_party/python/Modules/_sqlite/util.h" +#include "third_party/python/Include/pythread.h" #define ACTION_FINALIZE 1 #define ACTION_RESET 2 diff --git a/third_party/python/Modules/_sqlite/connection.h b/third_party/python/Modules/_sqlite/connection.h index 93f2c10a4..a1d59a5a8 100644 --- a/third_party/python/Modules/_sqlite/connection.h +++ b/third_party/python/Modules/_sqlite/connection.h @@ -1,37 +1,12 @@ -/* clang-format off */ -/* connection.h - definitions for the connection type - * - * Copyright (C) 2004-2010 Gerhard Häring - * - * This file is part of pysqlite. - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - #ifndef PYSQLITE_CONNECTION_H #define PYSQLITE_CONNECTION_H -#include "Python.h" -#include "pythread.h" -#include "structmember.h" - -#include "cache.h" -#include "module.h" - -#include "sqlite3.h" +#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/pythread.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Modules/_sqlite/cache.h" +#include "third_party/python/Modules/_sqlite/module.h" +#include "third_party/sqlite3/sqlite3.h" +/* clang-format off */ typedef struct { diff --git a/third_party/python/Modules/_sqlite/cursor.h b/third_party/python/Modules/_sqlite/cursor.h index a860b0310..e8e7dcba2 100644 --- a/third_party/python/Modules/_sqlite/cursor.h +++ b/third_party/python/Modules/_sqlite/cursor.h @@ -1,34 +1,12 @@ -/* clang-format off */ -/* cursor.h - definitions for the cursor type - * - * Copyright (C) 2004-2010 Gerhard Häring - * - * This file is part of pysqlite. - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - #ifndef PYSQLITE_CURSOR_H #define PYSQLITE_CURSOR_H -#include "Python.h" +#include "third_party/python/Include/Python.h" +/* clang-format off */ -#include "statement.h" -#include "connection.h" -#include "module.h" +#include "third_party/python/Modules/_sqlite/statement.h" +#include "third_party/python/Modules/_sqlite/connection.h" +#include "third_party/python/Modules/_sqlite/module.h" +#include "third_party/python/Modules/_sqlite/connection.h" typedef struct { diff --git a/third_party/python/Modules/_sqlite/microprotocols.h b/third_party/python/Modules/_sqlite/microprotocols.h index 594ce459b..bdb608f68 100644 --- a/third_party/python/Modules/_sqlite/microprotocols.h +++ b/third_party/python/Modules/_sqlite/microprotocols.h @@ -1,33 +1,8 @@ -/* clang-format off */ -/* microprotocols.c - definitions for minimalist and non-validating protocols - * - * Copyright (C) 2003-2004 Federico Di Gregorio - * - * This file is part of psycopg and was adapted for pysqlite. Federico Di - * Gregorio gave the permission to use it within pysqlite under the following - * license: - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - #ifndef PSYCOPG_MICROPROTOCOLS_H #define PSYCOPG_MICROPROTOCOLS_H 1 - -#include +#include "third_party/python/Include/Python.h" +#include "third_party/python/Modules/_sqlite/cursor.h" +/* clang-format off */ /** adapters registry **/ diff --git a/third_party/python/Modules/_sqlite/module.c b/third_party/python/Modules/_sqlite/module.c index a8ea73b48..a6418d115 100644 --- a/third_party/python/Modules/_sqlite/module.c +++ b/third_party/python/Modules/_sqlite/module.c @@ -22,7 +22,7 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include "connection.h" +#include "third_party/python/Modules/_sqlite/connection.h" #include "statement.h" #include "cursor.h" #include "cache.h" diff --git a/third_party/python/Modules/_sqlite/module.h b/third_party/python/Modules/_sqlite/module.h index 266b7a2f4..b1c24f60f 100644 --- a/third_party/python/Modules/_sqlite/module.h +++ b/third_party/python/Modules/_sqlite/module.h @@ -1,30 +1,7 @@ -/* clang-format off */ -/* module.h - definitions for the module - * - * Copyright (C) 2004-2010 Gerhard Häring - * - * This file is part of pysqlite. - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - #ifndef PYSQLITE_MODULE_H #define PYSQLITE_MODULE_H -#include "Python.h" +#include "third_party/python/Include/Python.h" +/* clang-format off */ #define PYSQLITE_VERSION "2.6.0" diff --git a/third_party/python/Modules/_sqlite/prepare_protocol.h b/third_party/python/Modules/_sqlite/prepare_protocol.h index 9ea67900a..2ea640625 100644 --- a/third_party/python/Modules/_sqlite/prepare_protocol.h +++ b/third_party/python/Modules/_sqlite/prepare_protocol.h @@ -1,30 +1,7 @@ -/* clang-format off */ -/* prepare_protocol.h - the protocol for preparing values for SQLite - * - * Copyright (C) 2005-2010 Gerhard Häring - * - * This file is part of pysqlite. - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - #ifndef PYSQLITE_PREPARE_PROTOCOL_H #define PYSQLITE_PREPARE_PROTOCOL_H -#include "Python.h" +#include "third_party/python/Include/Python.h" +/* clang-format off */ typedef struct { diff --git a/third_party/python/Modules/_sqlite/row.c b/third_party/python/Modules/_sqlite/row.c index 11dca19f6..1ade41c65 100644 --- a/third_party/python/Modules/_sqlite/row.c +++ b/third_party/python/Modules/_sqlite/row.c @@ -22,8 +22,8 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include "row.h" -#include "cursor.h" +#include "third_party/python/Modules/_sqlite/row.h" +#include "third_party/python/Modules/_sqlite/cursor.h" void pysqlite_row_dealloc(pysqlite_Row* self) { diff --git a/third_party/python/Modules/_sqlite/row.h b/third_party/python/Modules/_sqlite/row.h index 3159abfdb..95f08859a 100644 --- a/third_party/python/Modules/_sqlite/row.h +++ b/third_party/python/Modules/_sqlite/row.h @@ -1,30 +1,7 @@ -/* clang-format off */ -/* row.h - an enhanced tuple for database rows - * - * Copyright (C) 2005-2010 Gerhard Häring - * - * This file is part of pysqlite. - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - #ifndef PYSQLITE_ROW_H #define PYSQLITE_ROW_H -#include "Python.h" +#include "third_party/python/Include/Python.h" +/* clang-format off */ typedef struct _Row { diff --git a/third_party/python/Modules/_sqlite/statement.c b/third_party/python/Modules/_sqlite/statement.c index 7a5bb1b71..7f2cedd5d 100644 --- a/third_party/python/Modules/_sqlite/statement.c +++ b/third_party/python/Modules/_sqlite/statement.c @@ -22,12 +22,12 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include "statement.h" -#include "cursor.h" -#include "connection.h" -#include "microprotocols.h" -#include "prepare_protocol.h" -#include "util.h" +#include "third_party/python/Modules/_sqlite/statement.h" +#include "third_party/python/Modules/_sqlite/cursor.h" +#include "third_party/python/Modules/_sqlite/connection.h" +#include "third_party/python/Modules/_sqlite/microprotocols.h" +#include "third_party/python/Modules/_sqlite/prepare_protocol.h" +#include "third_party/python/Modules/_sqlite/util.h" /* prototypes */ static int pysqlite_check_remaining_sql(const char* tail); diff --git a/third_party/python/Modules/_sqlite/statement.h b/third_party/python/Modules/_sqlite/statement.h index 101e1e1f0..dc6adf82e 100644 --- a/third_party/python/Modules/_sqlite/statement.h +++ b/third_party/python/Modules/_sqlite/statement.h @@ -1,33 +1,9 @@ -/* clang-format off */ -/* statement.h - definitions for the statement type - * - * Copyright (C) 2005-2010 Gerhard Häring - * - * This file is part of pysqlite. - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - #ifndef PYSQLITE_STATEMENT_H #define PYSQLITE_STATEMENT_H -#include "Python.h" - -#include "connection.h" -#include "sqlite3.h" +#include "third_party/python/Include/Python.h" +#include "third_party/python/Modules/_sqlite/connection.h" +#include "third_party/sqlite3/sqlite3.h" +/* clang-format off */ #define PYSQLITE_TOO_MUCH_SQL (-100) #define PYSQLITE_SQL_WRONG_TYPE (-101) diff --git a/third_party/python/Modules/_sqlite/util.h b/third_party/python/Modules/_sqlite/util.h index 7245e600d..e301fb68c 100644 --- a/third_party/python/Modules/_sqlite/util.h +++ b/third_party/python/Modules/_sqlite/util.h @@ -1,33 +1,10 @@ -/* clang-format off */ -/* util.h - various utility functions - * - * Copyright (C) 2005-2010 Gerhard Häring - * - * This file is part of pysqlite. - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - #ifndef PYSQLITE_UTIL_H #define PYSQLITE_UTIL_H -#include "Python.h" -#include "pythread.h" -#include "sqlite3.h" -#include "connection.h" +/* clang-format off */ +#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/pythread.h" +#include "third_party/python/Modules/_sqlite/connection.h" +#include "third_party/sqlite3/sqlite3.h" int pysqlite_step(sqlite3_stmt* statement, pysqlite_Connection* connection); diff --git a/third_party/python/Modules/_sre.c b/third_party/python/Modules/_sre.c index 336ad1966..bc868ee77 100644 --- a/third_party/python/Modules/_sre.c +++ b/third_party/python/Modules/_sre.c @@ -1,4 +1,22 @@ +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/iterobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyctype.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pyhash.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/warnings.h" +#include "third_party/python/Modules/sre.h" /* clang-format off */ + /* * Secret Labs' Regular Expression Engine * @@ -41,10 +59,6 @@ static const char copyright[] = #define PY_SSIZE_T_CLEAN -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" -#include "third_party/python/Modules/sre.h" - #define SRE_CODE_BITS (8 * sizeof(SRE_CODE)) /* name of this module, minus the leading underscore */ @@ -65,12 +79,7 @@ static const char copyright[] = /* -------------------------------------------------------------------- */ -#if defined(_MSC_VER) -#pragma optimize("agtw", on) /* doesn't seem to make much difference... */ -#pragma warning(disable: 4710) /* who cares if functions are not inlined ;-) */ -/* fastest possible local call under MSVC */ -#define LOCAL(type) static __inline type __fastcall -#elif defined(USE_INLINE) +#if defined(USE_INLINE) #define LOCAL(type) static inline type #else #define LOCAL(type) static type @@ -232,21 +241,21 @@ data_stack_grow(SRE_STATE* state, Py_ssize_t size) #define SRE_CHAR Py_UCS1 #define SIZEOF_SRE_CHAR 1 #define SRE(F) sre_ucs1_##F -#include "sre_lib.h" +#include "third_party/python/Modules/sre_lib.inc" /* generate 16-bit unicode version */ #define SRE_CHAR Py_UCS2 #define SIZEOF_SRE_CHAR 2 #define SRE(F) sre_ucs2_##F -#include "sre_lib.h" +#include "third_party/python/Modules/sre_lib.inc" /* generate 32-bit unicode version */ #define SRE_CHAR Py_UCS4 #define SIZEOF_SRE_CHAR 4 #define SRE(F) sre_ucs4_##F -#include "sre_lib.h" +#include "third_party/python/Modules/sre_lib.inc" /* -------------------------------------------------------------------- */ /* factories and destructors */ @@ -303,7 +312,7 @@ LOCAL(void) state_reset(SRE_STATE* state) { /* FIXME: dynamic! */ - /*memset(state->mark, 0, sizeof(*state->mark) * SRE_MARK_SIZE);*/ + /*bzero(state->mark, sizeof(*state->mark) * SRE_MARK_SIZE);*/ state->lastmark = -1; state->lastindex = -1; @@ -362,7 +371,7 @@ state_init(SRE_STATE* state, PatternObject* pattern, PyObject* string, int isbytes, charsize; void* ptr; - memset(state, 0, sizeof(SRE_STATE)); + bzero(state, sizeof(SRE_STATE)); state->mark = PyMem_New(void *, pattern->groups * 2); if (!state->mark) { diff --git a/third_party/python/Modules/_ssl.c b/third_party/python/Modules/_ssl.c index 6bf79a9ec..d065c7c9a 100644 --- a/third_party/python/Modules/_ssl.c +++ b/third_party/python/Modules/_ssl.c @@ -1,4 +1,6 @@ +#define PY_SSIZE_T_CLEAN /* clang-format off */ + /* SSL socket module SSL support based on patches by Brian E Gallew and Laszlo Kovacs. @@ -15,14 +17,8 @@ http://bugs.python.org/issue8108#msg102867 ? */ -#define PY_SSIZE_T_CLEAN - -#include "third_party/python/Include/Python.h" - #ifdef WITH_THREAD #include "third_party/python/Include/pythread.h" - - #define PySSL_BEGIN_ALLOW_THREADS_S(save) \ do { if (_ssl_locks_count>0) { (save) = PyEval_SaveThread(); } } while (0) #define PySSL_END_ALLOW_THREADS_S(save) \ @@ -33,16 +29,13 @@ #define PySSL_BLOCK_THREADS PySSL_END_ALLOW_THREADS_S(_save); #define PySSL_UNBLOCK_THREADS PySSL_BEGIN_ALLOW_THREADS_S(_save); #define PySSL_END_ALLOW_THREADS PySSL_END_ALLOW_THREADS_S(_save); } - #else /* no WITH_THREAD */ - #define PySSL_BEGIN_ALLOW_THREADS_S(save) #define PySSL_END_ALLOW_THREADS_S(save) #define PySSL_BEGIN_ALLOW_THREADS #define PySSL_BLOCK_THREADS #define PySSL_UNBLOCK_THREADS #define PySSL_END_ALLOW_THREADS - #endif /* Include symbols from _socket module */ @@ -50,17 +43,6 @@ static PySocketModule_APIObject PySocketModule; -#if defined(HAVE_POLL_H) -#include -#elif defined(HAVE_SYS_POLL_H) -#include -#endif - -#ifndef MS_WINDOWS -/* inet_pton */ -#include -#endif - /* Don't warn about deprecated functions */ #ifdef __GNUC__ #pragma GCC diagnostic ignored "-Wdeprecated-declarations" diff --git a/third_party/python/Modules/_stat.c b/third_party/python/Modules/_stat.c index d79f3051d..7b6b949d5 100644 --- a/third_party/python/Modules/_stat.c +++ b/third_party/python/Modules/_stat.c @@ -1,4 +1,17 @@ +#define PY_SSIZE_T_CLEAN +#include "libc/calls/calls.h" +#include "libc/calls/weirdtypes.h" +#include "libc/sysv/consts/s.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/methodobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/moduleobject.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" /* clang-format off */ + /* stat.h interface * * The module defines all S_IF*, S_I*, UF_*, SF_* and ST_* constants to @@ -12,11 +25,6 @@ * */ -#define PY_SSIZE_T_CLEAN -#include "libc/sysv/consts/s.h" -#include "libc/calls/calls.h" -#include "third_party/python/Include/Python.h" - /* FILE_ATTRIBUTE_INTEGRITY_STREAM and FILE_ATTRIBUTE_NO_SCRUB_DATA are not present in VC2010, so define them manually */ #ifndef FILE_ATTRIBUTE_INTEGRITY_STREAM diff --git a/third_party/python/Modules/_struct.c b/third_party/python/Modules/_struct.c index b57cd0a67..759423321 100644 --- a/third_party/python/Modules/_struct.c +++ b/third_party/python/Modules/_struct.c @@ -1,14 +1,27 @@ +#define PY_SSIZE_T_CLEAN +#include "libc/assert.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/bytearrayobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyctype.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/tupleobject.h" /* clang-format off */ + /* struct module -- pack values into and (out of) bytes objects */ /* New version supporting byte order, alignment and size options, character strings, and unsigned numbers */ -#define PY_SSIZE_T_CLEAN - -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" - static PyTypeObject PyStructType; /* The translation function for each format character is table driven */ @@ -1303,7 +1316,7 @@ prepare_s(PyStructObject *self) len = 0; ncodes = 0; while ((c = *s++) != '\0') { - if (Py_ISSPACE(Py_CHARMASK(c))) + if (Py_ISSPACE(c)) continue; if ('0' <= c && c <= '9') { num = c - '0'; @@ -1368,7 +1381,7 @@ prepare_s(PyStructObject *self) s = fmt; size = 0; while ((c = *s++) != '\0') { - if (Py_ISSPACE(Py_CHARMASK(c))) + if (Py_ISSPACE(c)) continue; if ('0' <= c && c <= '9') { num = c - '0'; diff --git a/third_party/python/Modules/_testbuffer.c b/third_party/python/Modules/_testbuffer.c index cff050f62..489fbecb2 100644 --- a/third_party/python/Modules/_testbuffer.c +++ b/third_party/python/Modules/_testbuffer.c @@ -1,13 +1,23 @@ +#define PY_SSIZE_T_CLEAN +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/memoryobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/sliceobject.h" /* clang-format off */ + /* C Extension module to test all aspects of PEP-3118. Written by Stefan Krah. */ - -#define PY_SSIZE_T_CLEAN - -#include "Python.h" - - /* struct module */ static PyObject *structmodule = NULL; static PyObject *Struct = NULL; @@ -84,7 +94,7 @@ static PyTypeObject NDArray_Type; /* Single node of a list of base buffers. The list is needed to implement changes in memory layout while exported buffers are active. */ -static PyTypeObject NDArray_Type; +/* static PyTypeObject NDArray_Type; */ struct ndbuf; typedef struct ndbuf { diff --git a/third_party/python/Modules/_testcapimodule.c b/third_party/python/Modules/_testcapimodule.c index 51ce87514..7c3618b3b 100644 --- a/third_party/python/Modules/_testcapimodule.c +++ b/third_party/python/Modules/_testcapimodule.c @@ -1,4 +1,42 @@ +#define PY_SSIZE_T_CLEAN +#undef Py_BUILD_CORE +#include "libc/calls/calls.h" +#include "libc/calls/weirdtypes.h" +#include "libc/errno.h" +#include "libc/fmt/fmt.h" +#include "libc/limits.h" +#include "libc/math.h" +#include "libc/time/time.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/bytearrayobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/classobject.h" +#include "third_party/python/Include/code.h" +#include "third_party/python/Include/codecs.h" +#include "third_party/python/Include/complexobject.h" +#include "third_party/python/Include/datetime.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/genobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/marshal.h" +#include "third_party/python/Include/memoryobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pycapsule.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pylifecycle.h" +#include "third_party/python/Include/pystrtod.h" +#include "third_party/python/Include/pythonrun.h" +#include "third_party/python/Include/pytime.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/traceback.h" /* clang-format off */ + /* * C Extension module to test Python interpreter C APIs. * @@ -6,14 +44,6 @@ * standard Python regression test, via Lib/test/test_capi.py. */ -#define PY_SSIZE_T_CLEAN -#undef Py_BUILD_CORE - -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" -#include "third_party/python/Include/datetime.h" -#include "third_party/python/Include/marshal.h" - #ifdef WITH_THREAD #include "third_party/python/Include/pythread.h" #endif @@ -407,7 +437,7 @@ raise_test_long_error(const char* msg) #define F_U_TO_PY PyLong_FromUnsignedLong #define F_PY_TO_U PyLong_AsUnsignedLong -#include "testcapi_long.h" +#include "third_party/python/Modules/testcapi_long.inc" static PyObject * test_long_api(PyObject* self) @@ -435,7 +465,7 @@ raise_test_longlong_error(const char* msg) #define F_U_TO_PY PyLong_FromUnsignedLongLong #define F_PY_TO_U PyLong_AsUnsignedLongLong -#include "testcapi_long.h" +#include "third_party/python/Modules/testcapi_long.inc" static PyObject * test_longlong_api(PyObject* self, PyObject *args) @@ -1598,9 +1628,9 @@ parse_tuple_and_keywords(PyObject *self, PyObject *args) return NULL; } - memset(buffers, 0, sizeof(buffers)); - memset(converted, 0, sizeof(converted)); - memset(keywords, 0, sizeof(keywords)); + bzero(buffers, sizeof(buffers)); + bzero(converted, sizeof(converted)); + bzero(keywords, sizeof(keywords)); size = PySequence_Fast_GET_SIZE(sub_keywords); if (size > 8) { @@ -1886,7 +1916,7 @@ unicode_asucs4(PyObject *self, PyObject *args) if (buffer == NULL) { return PyErr_NoMemory(); } - memset(buffer, 0, sizeof(Py_UCS4)*buf_len); + bzero(buffer, sizeof(Py_UCS4)*buf_len); buffer[str_len] = 0xffffU; if (!PyUnicode_AsUCS4(unicode, buffer, buf_len, copy_null)) { @@ -3313,7 +3343,7 @@ test_setallocators(PyMemAllocatorDomain domain) size_t size, size2, nelem, elsize; void *ptr, *ptr2; - memset(&hook, 0, sizeof(hook)); + bzero(&hook, sizeof(hook)); alloc.ctx = &hook; alloc.malloc = &hook_malloc; @@ -4577,7 +4607,7 @@ test_structmembers_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) ob = PyObject_New(test_structmembers, type); if (ob == NULL) return NULL; - memset(&ob->structmembers, 0, sizeof(all_structmembers)); + bzero(&ob->structmembers, sizeof(all_structmembers)); if (!PyArg_ParseTupleAndKeywords(args, kwargs, fmt, keywords, &ob->structmembers.bool_member, &ob->structmembers.byte_member, diff --git a/third_party/python/Modules/_testmultiphase.c b/third_party/python/Modules/_testmultiphase.c index a9e0db1b5..d386bcf8e 100644 --- a/third_party/python/Modules/_testmultiphase.c +++ b/third_party/python/Modules/_testmultiphase.c @@ -1,10 +1,17 @@ +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/methodobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/namespaceobject.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pystate.h" +#include "third_party/python/Include/typeslots.h" /* clang-format off */ /* Testing module for multi-phase initialization of extension modules (PEP 489) */ -#include "Python.h" - /* Example objects */ typedef struct { PyObject_HEAD diff --git a/third_party/python/Modules/_threadmodule.c b/third_party/python/Modules/_threadmodule.c index e16860b23..50ad09423 100644 --- a/third_party/python/Modules/_threadmodule.c +++ b/third_party/python/Modules/_threadmodule.c @@ -1,18 +1,16 @@ +#include "third_party/python/Include/structmember.h" /* clang-format off */ /* Thread module */ /* Interface to Sjoerd's portable C thread library */ -#include "Python.h" -#include "structmember.h" /* offsetof */ - #ifndef WITH_THREAD #error "Error! The rest of Python is not compiled with thread support." #error "Rerun configure, adding a --with-threads option." #error "Then run `make clean' followed by `make'." #endif -#include "pythread.h" +#include "third_party/python/Include/pythread.h" static PyObject *ThreadError; static long nb_threads = 0; @@ -555,7 +553,7 @@ newlockobject(void) /* Thread-local objects */ -#include "structmember.h" +#include "third_party/python/Include/structmember.h" /* Quick overview: diff --git a/third_party/python/Modules/_tkinter.c b/third_party/python/Modules/_tkinter.c deleted file mode 100644 index 3b5b313a6..000000000 --- a/third_party/python/Modules/_tkinter.c +++ /dev/null @@ -1,3660 +0,0 @@ -/* clang-format off */ -/*********************************************************** -Copyright (C) 1994 Steen Lumholt. - - All Rights Reserved - -******************************************************************/ - -/* _tkinter.c -- Interface to libtk.a and libtcl.a. */ - -/* TCL/TK VERSION INFO: - - Only Tcl/Tk 8.4 and later are supported. Older versions are not - supported. Use Python 3.4 or older if you cannot upgrade your - Tcl/Tk libraries. -*/ - -/* XXX Further speed-up ideas, involving Tcl 8.0 features: - - - Register a new Tcl type, "Python callable", which can be called more - efficiently and passed to Tcl_EvalObj() directly (if this is possible). - -*/ - -#define PY_SSIZE_T_CLEAN - -#include "Python.h" -#include - -#ifdef WITH_THREAD -#include "pythread.h" -#endif - -#ifdef MS_WINDOWS -#include -#endif - -#define CHECK_SIZE(size, elemsize) \ - ((size_t)(size) <= Py_MIN((size_t)INT_MAX, UINT_MAX / (size_t)(elemsize))) - -/* If Tcl is compiled for threads, we must also define TCL_THREAD. We define - it always; if Tcl is not threaded, the thread functions in - Tcl are empty. */ -#define TCL_THREADS - -#ifdef TK_FRAMEWORK -#include -#include -#else -#include -#include -#endif - -#include "tkinter.h" - -#if TK_HEX_VERSION < 0x08040200 -#error "Tk older than 8.4 not supported" -#endif - -#if TK_HEX_VERSION >= 0x08050208 && TK_HEX_VERSION < 0x08060000 || \ - TK_HEX_VERSION >= 0x08060200 -#define HAVE_LIBTOMMAMTH -#include -#endif - -#if !(defined(MS_WINDOWS) || defined(__CYGWIN__)) -#define HAVE_CREATEFILEHANDLER -#endif - -#ifdef HAVE_CREATEFILEHANDLER - -/* This bit is to ensure that TCL_UNIX_FD is defined and doesn't interfere - with the proper calculation of FHANDLETYPE == TCL_UNIX_FD below. */ -#ifndef TCL_UNIX_FD -# ifdef TCL_WIN_SOCKET -# define TCL_UNIX_FD (! TCL_WIN_SOCKET) -# else -# define TCL_UNIX_FD 1 -# endif -#endif - -/* Tcl_CreateFileHandler() changed several times; these macros deal with the - messiness. In Tcl 8.0 and later, it is not available on Windows (and on - Unix, only because Jack added it back); when available on Windows, it only - applies to sockets. */ - -#ifdef MS_WINDOWS -#define FHANDLETYPE TCL_WIN_SOCKET -#else -#define FHANDLETYPE TCL_UNIX_FD -#endif - -/* If Tcl can wait for a Unix file descriptor, define the EventHook() routine - which uses this to handle Tcl events while the user is typing commands. */ - -#if FHANDLETYPE == TCL_UNIX_FD -#define WAIT_FOR_STDIN -#endif - -#endif /* HAVE_CREATEFILEHANDLER */ - -#ifdef MS_WINDOWS -#include -#define WAIT_FOR_STDIN - -static PyObject * -_get_tcl_lib_path() -{ - static PyObject *tcl_library_path = NULL; - static int already_checked = 0; - - if (already_checked == 0) { - PyObject *prefix; - struct stat stat_buf; - int stat_return_value; - - prefix = PyUnicode_FromWideChar(Py_GetPrefix(), -1); - if (prefix == NULL) { - return NULL; - } - - /* Check expected location for an installed Python first */ - tcl_library_path = PyUnicode_FromString("\\tcl\\tcl" TCL_VERSION); - if (tcl_library_path == NULL) { - return NULL; - } - tcl_library_path = PyUnicode_Concat(prefix, tcl_library_path); - if (tcl_library_path == NULL) { - return NULL; - } - stat_return_value = _Py_stat(tcl_library_path, &stat_buf); - if (stat_return_value == -2) { - return NULL; - } - if (stat_return_value == -1) { - /* install location doesn't exist, reset errno and see if - we're a repository build */ - errno = 0; -#ifdef Py_TCLTK_DIR - tcl_library_path = PyUnicode_FromString( - Py_TCLTK_DIR "\\lib\\tcl" TCL_VERSION); - if (tcl_library_path == NULL) { - return NULL; - } - stat_return_value = _Py_stat(tcl_library_path, &stat_buf); - if (stat_return_value == -2) { - return NULL; - } - if (stat_return_value == -1) { - /* tcltkDir for a repository build doesn't exist either, - reset errno and leave Tcl to its own devices */ - errno = 0; - tcl_library_path = NULL; - } -#else - tcl_library_path = NULL; -#endif - } - already_checked = 1; - } - return tcl_library_path; -} -#endif /* MS_WINDOWS */ - -#ifdef WITH_THREAD - -/* The threading situation is complicated. Tcl is not thread-safe, except - when configured with --enable-threads. - - So we need to use a lock around all uses of Tcl. Previously, the - Python interpreter lock was used for this. However, this causes - problems when other Python threads need to run while Tcl is blocked - waiting for events. - - To solve this problem, a separate lock for Tcl is introduced. - Holding it is incompatible with holding Python's interpreter lock. - The following four macros manipulate both locks together. - - ENTER_TCL and LEAVE_TCL are brackets, just like - Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS. They should be - used whenever a call into Tcl is made that could call an event - handler, or otherwise affect the state of a Tcl interpreter. These - assume that the surrounding code has the Python interpreter lock; - inside the brackets, the Python interpreter lock has been released - and the lock for Tcl has been acquired. - - Sometimes, it is necessary to have both the Python lock and the Tcl - lock. (For example, when transferring data from the Tcl - interpreter result to a Python string object.) This can be done by - using different macros to close the ENTER_TCL block: ENTER_OVERLAP - reacquires the Python lock (and restores the thread state) but - doesn't release the Tcl lock; LEAVE_OVERLAP_TCL releases the Tcl - lock. - - By contrast, ENTER_PYTHON and LEAVE_PYTHON are used in Tcl event - handlers when the handler needs to use Python. Such event handlers - are entered while the lock for Tcl is held; the event handler - presumably needs to use Python. ENTER_PYTHON releases the lock for - Tcl and acquires the Python interpreter lock, restoring the - appropriate thread state, and LEAVE_PYTHON releases the Python - interpreter lock and re-acquires the lock for Tcl. It is okay for - ENTER_TCL/LEAVE_TCL pairs to be contained inside the code between - ENTER_PYTHON and LEAVE_PYTHON. - - These locks expand to several statements and brackets; they should - not be used in branches of if statements and the like. - - If Tcl is threaded, this approach won't work anymore. The Tcl - interpreter is only valid in the thread that created it, and all Tk - activity must happen in this thread, also. That means that the - mainloop must be invoked in the thread that created the - interpreter. Invoking commands from other threads is possible; - _tkinter will queue an event for the interpreter thread, which will - then execute the command and pass back the result. If the main - thread is not in the mainloop, and invoking commands causes an - exception; if the main loop is running but not processing events, - the command invocation will block. - - In addition, for a threaded Tcl, a single global tcl_tstate won't - be sufficient anymore, since multiple Tcl interpreters may - simultaneously dispatch in different threads. So we use the Tcl TLS - API. - -*/ - -static PyThread_type_lock tcl_lock = 0; - -#ifdef TCL_THREADS -static Tcl_ThreadDataKey state_key; -typedef PyThreadState *ThreadSpecificData; -#define tcl_tstate \ - (*(PyThreadState**)Tcl_GetThreadData(&state_key, sizeof(PyThreadState*))) -#else -static PyThreadState *tcl_tstate = NULL; -#endif - -#define ENTER_TCL \ - { PyThreadState *tstate = PyThreadState_Get(); Py_BEGIN_ALLOW_THREADS \ - if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1); tcl_tstate = tstate; - -#define LEAVE_TCL \ - tcl_tstate = NULL; \ - if(tcl_lock)PyThread_release_lock(tcl_lock); Py_END_ALLOW_THREADS} - -#define ENTER_OVERLAP \ - Py_END_ALLOW_THREADS - -#define LEAVE_OVERLAP_TCL \ - tcl_tstate = NULL; if(tcl_lock)PyThread_release_lock(tcl_lock); } - -#define ENTER_PYTHON \ - { PyThreadState *tstate = tcl_tstate; tcl_tstate = NULL; \ - if(tcl_lock) \ - PyThread_release_lock(tcl_lock); PyEval_RestoreThread((tstate)); } - -#define LEAVE_PYTHON \ - { PyThreadState *tstate = PyEval_SaveThread(); \ - if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1); tcl_tstate = tstate; } - -#define CHECK_TCL_APPARTMENT \ - if (((TkappObject *)self)->threaded && \ - ((TkappObject *)self)->thread_id != Tcl_GetCurrentThread()) { \ - PyErr_SetString(PyExc_RuntimeError, \ - "Calling Tcl from different appartment"); \ - return 0; \ - } - -#else - -#define ENTER_TCL -#define LEAVE_TCL -#define ENTER_OVERLAP -#define LEAVE_OVERLAP_TCL -#define ENTER_PYTHON -#define LEAVE_PYTHON -#define CHECK_TCL_APPARTMENT - -#endif - -#ifndef FREECAST -#define FREECAST (char *) -#endif - -/**** Tkapp Object Declaration ****/ - -static PyObject *Tkapp_Type; - -typedef struct { - PyObject_HEAD - Tcl_Interp *interp; - int wantobjects; - int threaded; /* True if tcl_platform[threaded] */ - Tcl_ThreadId thread_id; - int dispatching; - /* We cannot include tclInt.h, as this is internal. - So we cache interesting types here. */ - const Tcl_ObjType *OldBooleanType; - const Tcl_ObjType *BooleanType; - const Tcl_ObjType *ByteArrayType; - const Tcl_ObjType *DoubleType; - const Tcl_ObjType *IntType; - const Tcl_ObjType *WideIntType; - const Tcl_ObjType *BignumType; - const Tcl_ObjType *ListType; - const Tcl_ObjType *ProcBodyType; - const Tcl_ObjType *StringType; -} TkappObject; - -#define Tkapp_Interp(v) (((TkappObject *) (v))->interp) -#define Tkapp_Result(v) Tcl_GetStringResult(Tkapp_Interp(v)) - -#define DEBUG_REFCNT(v) (printf("DEBUG: id=%p, refcnt=%i\n", \ -(void *) v, Py_REFCNT(v))) - - - -/**** Error Handling ****/ - -static PyObject *Tkinter_TclError; -static int quitMainLoop = 0; -static int errorInCmd = 0; -static PyObject *excInCmd; -static PyObject *valInCmd; -static PyObject *trbInCmd; - -#ifdef TKINTER_PROTECT_LOADTK -static int tk_load_failed = 0; -#endif - - -static PyObject * -Tkinter_Error(PyObject *v) -{ - PyErr_SetString(Tkinter_TclError, Tkapp_Result(v)); - return NULL; -} - - - -/**** Utils ****/ - -static int Tkinter_busywaitinterval = 20; - -#ifdef WITH_THREAD -#ifndef MS_WINDOWS - -/* Millisecond sleep() for Unix platforms. */ - -static void -Sleep(int milli) -{ - /* XXX Too bad if you don't have select(). */ - struct timeval t; - t.tv_sec = milli/1000; - t.tv_usec = (milli%1000) * 1000; - select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t); -} -#endif /* MS_WINDOWS */ - -/* Wait up to 1s for the mainloop to come up. */ - -static int -WaitForMainloop(TkappObject* self) -{ - int i; - for (i = 0; i < 10; i++) { - if (self->dispatching) - return 1; - Py_BEGIN_ALLOW_THREADS - Sleep(100); - Py_END_ALLOW_THREADS - } - if (self->dispatching) - return 1; - PyErr_SetString(PyExc_RuntimeError, "main thread is not in main loop"); - return 0; -} -#endif /* WITH_THREAD */ - - - -#define ARGSZ 64 - - - -static PyObject * -unicodeFromTclStringAndSize(const char *s, Py_ssize_t size) -{ - PyObject *r = PyUnicode_DecodeUTF8(s, size, NULL); - if (!r && PyErr_ExceptionMatches(PyExc_UnicodeDecodeError)) { - /* Tcl encodes null character as \xc0\x80 */ - if (memchr(s, '\xc0', size)) { - char *buf, *q; - const char *e = s + size; - PyErr_Clear(); - q = buf = (char *)PyMem_Malloc(size); - if (buf == NULL) { - PyErr_NoMemory(); - return NULL; - } - while (s != e) { - if (s + 1 != e && s[0] == '\xc0' && s[1] == '\x80') { - *q++ = '\0'; - s += 2; - } - else - *q++ = *s++; - } - s = buf; - size = q - s; - r = PyUnicode_DecodeUTF8(s, size, NULL); - PyMem_Free(buf); - } - } - return r; -} - -static PyObject * -unicodeFromTclString(const char *s) -{ - return unicodeFromTclStringAndSize(s, strlen(s)); -} - -static PyObject * -unicodeFromTclObj(Tcl_Obj *value) -{ - int len; - char *s = Tcl_GetStringFromObj(value, &len); - return unicodeFromTclStringAndSize(s, len); -} - - -static PyObject * -Split(const char *list) -{ - int argc; - const char **argv; - PyObject *v; - - if (list == NULL) { - Py_RETURN_NONE; - } - - if (Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) { - /* Not a list. - * Could be a quoted string containing funnies, e.g. {"}. - * Return the string itself. - */ - return unicodeFromTclString(list); - } - - if (argc == 0) - v = PyUnicode_FromString(""); - else if (argc == 1) - v = unicodeFromTclString(argv[0]); - else if ((v = PyTuple_New(argc)) != NULL) { - int i; - PyObject *w; - - for (i = 0; i < argc; i++) { - if ((w = Split(argv[i])) == NULL) { - Py_DECREF(v); - v = NULL; - break; - } - PyTuple_SET_ITEM(v, i, w); - } - } - Tcl_Free(FREECAST argv); - return v; -} - -/* In some cases, Tcl will still return strings that are supposed to - be lists. SplitObj walks through a nested tuple, finding string - objects that need to be split. */ - -static PyObject * -SplitObj(PyObject *arg) -{ - if (PyTuple_Check(arg)) { - Py_ssize_t i, size; - PyObject *elem, *newelem, *result; - - size = PyTuple_GET_SIZE(arg); - result = NULL; - /* Recursively invoke SplitObj for all tuple items. - If this does not return a new object, no action is - needed. */ - for(i = 0; i < size; i++) { - elem = PyTuple_GET_ITEM(arg, i); - newelem = SplitObj(elem); - if (!newelem) { - Py_XDECREF(result); - return NULL; - } - if (!result) { - Py_ssize_t k; - if (newelem == elem) { - Py_DECREF(newelem); - continue; - } - result = PyTuple_New(size); - if (!result) - return NULL; - for(k = 0; k < i; k++) { - elem = PyTuple_GET_ITEM(arg, k); - Py_INCREF(elem); - PyTuple_SET_ITEM(result, k, elem); - } - } - PyTuple_SET_ITEM(result, i, newelem); - } - if (result) - return result; - /* Fall through, returning arg. */ - } - else if (PyList_Check(arg)) { - Py_ssize_t i, size; - PyObject *elem, *newelem, *result; - - size = PyList_GET_SIZE(arg); - result = PyTuple_New(size); - if (!result) - return NULL; - /* Recursively invoke SplitObj for all list items. */ - for(i = 0; i < size; i++) { - elem = PyList_GET_ITEM(arg, i); - newelem = SplitObj(elem); - if (!newelem) { - Py_XDECREF(result); - return NULL; - } - PyTuple_SET_ITEM(result, i, newelem); - } - return result; - } - else if (PyUnicode_Check(arg)) { - int argc; - const char **argv; - char *list = PyUnicode_AsUTF8(arg); - - if (list == NULL || - Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) { - Py_INCREF(arg); - return arg; - } - Tcl_Free(FREECAST argv); - if (argc > 1) - return Split(list); - /* Fall through, returning arg. */ - } - else if (PyBytes_Check(arg)) { - int argc; - const char **argv; - char *list = PyBytes_AS_STRING(arg); - - if (Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) { - Py_INCREF(arg); - return arg; - } - Tcl_Free(FREECAST argv); - if (argc > 1) - return Split(PyBytes_AS_STRING(arg)); - /* Fall through, returning arg. */ - } - Py_INCREF(arg); - return arg; -} - - -/*[clinic input] -module _tkinter -class _tkinter.tkapp "TkappObject *" "&Tkapp_Type_spec" -class _tkinter.Tcl_Obj "PyTclObject *" "&PyTclObject_Type_spec" -class _tkinter.tktimertoken "TkttObject *" "&Tktt_Type_spec" -[clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=b1ebf15c162ee229]*/ - -/**** Tkapp Object ****/ - -#ifndef WITH_APPINIT -int -Tcl_AppInit(Tcl_Interp *interp) -{ - const char * _tkinter_skip_tk_init; - - if (Tcl_Init(interp) == TCL_ERROR) { - PySys_WriteStderr("Tcl_Init error: %s\n", Tcl_GetStringResult(interp)); - return TCL_ERROR; - } - - _tkinter_skip_tk_init = Tcl_GetVar(interp, - "_tkinter_skip_tk_init", TCL_GLOBAL_ONLY); - if (_tkinter_skip_tk_init != NULL && - strcmp(_tkinter_skip_tk_init, "1") == 0) { - return TCL_OK; - } - -#ifdef TKINTER_PROTECT_LOADTK - if (tk_load_failed) { - PySys_WriteStderr("Tk_Init error: %s\n", TKINTER_LOADTK_ERRMSG); - return TCL_ERROR; - } -#endif - - if (Tk_Init(interp) == TCL_ERROR) { -#ifdef TKINTER_PROTECT_LOADTK - tk_load_failed = 1; -#endif - PySys_WriteStderr("Tk_Init error: %s\n", Tcl_GetStringResult(interp)); - return TCL_ERROR; - } - - return TCL_OK; -} -#endif /* !WITH_APPINIT */ - - - - -/* Initialize the Tk application; see the `main' function in - * `tkMain.c'. - */ - -static void EnableEventHook(void); /* Forward */ -static void DisableEventHook(void); /* Forward */ - -static TkappObject * -Tkapp_New(const char *screenName, const char *className, - int interactive, int wantobjects, int wantTk, int sync, - const char *use) -{ - TkappObject *v; - char *argv0; - - v = PyObject_New(TkappObject, (PyTypeObject *) Tkapp_Type); - if (v == NULL) - return NULL; - Py_INCREF(Tkapp_Type); - - v->interp = Tcl_CreateInterp(); - v->wantobjects = wantobjects; - v->threaded = Tcl_GetVar2Ex(v->interp, "tcl_platform", "threaded", - TCL_GLOBAL_ONLY) != NULL; - v->thread_id = Tcl_GetCurrentThread(); - v->dispatching = 0; - -#ifndef TCL_THREADS - if (v->threaded) { - PyErr_SetString(PyExc_RuntimeError, - "Tcl is threaded but _tkinter is not"); - Py_DECREF(v); - return 0; - } -#endif -#ifdef WITH_THREAD - if (v->threaded && tcl_lock) { - /* If Tcl is threaded, we don't need the lock. */ - PyThread_free_lock(tcl_lock); - tcl_lock = NULL; - } -#endif - - v->OldBooleanType = Tcl_GetObjType("boolean"); - v->BooleanType = Tcl_GetObjType("booleanString"); - v->ByteArrayType = Tcl_GetObjType("bytearray"); - v->DoubleType = Tcl_GetObjType("double"); - v->IntType = Tcl_GetObjType("int"); - v->WideIntType = Tcl_GetObjType("wideInt"); - v->BignumType = Tcl_GetObjType("bignum"); - v->ListType = Tcl_GetObjType("list"); - v->ProcBodyType = Tcl_GetObjType("procbody"); - v->StringType = Tcl_GetObjType("string"); - - /* Delete the 'exit' command, which can screw things up */ - Tcl_DeleteCommand(v->interp, "exit"); - - if (screenName != NULL) - Tcl_SetVar2(v->interp, "env", "DISPLAY", - screenName, TCL_GLOBAL_ONLY); - - if (interactive) - Tcl_SetVar(v->interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY); - else - Tcl_SetVar(v->interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY); - - /* This is used to get the application class for Tk 4.1 and up */ - argv0 = (char*)PyMem_Malloc(strlen(className) + 1); - if (!argv0) { - PyErr_NoMemory(); - Py_DECREF(v); - return NULL; - } - - strcpy(argv0, className); - if (Py_ISUPPER(Py_CHARMASK(argv0[0]))) - argv0[0] = Py_TOLOWER(Py_CHARMASK(argv0[0])); - Tcl_SetVar(v->interp, "argv0", argv0, TCL_GLOBAL_ONLY); - PyMem_Free(argv0); - - if (! wantTk) { - Tcl_SetVar(v->interp, - "_tkinter_skip_tk_init", "1", TCL_GLOBAL_ONLY); - } -#ifdef TKINTER_PROTECT_LOADTK - else if (tk_load_failed) { - Tcl_SetVar(v->interp, - "_tkinter_tk_failed", "1", TCL_GLOBAL_ONLY); - } -#endif - - /* some initial arguments need to be in argv */ - if (sync || use) { - char *args; - Py_ssize_t len = 0; - - if (sync) - len += sizeof "-sync"; - if (use) - len += strlen(use) + sizeof "-use "; /* never overflows */ - - args = (char*)PyMem_Malloc(len); - if (!args) { - PyErr_NoMemory(); - Py_DECREF(v); - return NULL; - } - - args[0] = '\0'; - if (sync) - strcat(args, "-sync"); - if (use) { - if (sync) - strcat(args, " "); - strcat(args, "-use "); - strcat(args, use); - } - - Tcl_SetVar(v->interp, "argv", args, TCL_GLOBAL_ONLY); - PyMem_Free(args); - } - -#ifdef MS_WINDOWS - { - PyObject *str_path; - PyObject *utf8_path; - DWORD ret; - - ret = GetEnvironmentVariableW(L"TCL_LIBRARY", NULL, 0); - if (!ret && GetLastError() == ERROR_ENVVAR_NOT_FOUND) { - str_path = _get_tcl_lib_path(); - if (str_path == NULL && PyErr_Occurred()) { - return NULL; - } - if (str_path != NULL) { - utf8_path = PyUnicode_AsUTF8String(str_path); - if (utf8_path == NULL) { - return NULL; - } - Tcl_SetVar(v->interp, - "tcl_library", - PyBytes_AS_STRING(utf8_path), - TCL_GLOBAL_ONLY); - Py_DECREF(utf8_path); - } - } - } -#endif - - if (Tcl_AppInit(v->interp) != TCL_OK) { - PyObject *result = Tkinter_Error((PyObject *)v); -#ifdef TKINTER_PROTECT_LOADTK - if (wantTk) { - const char *_tkinter_tk_failed; - _tkinter_tk_failed = Tcl_GetVar(v->interp, - "_tkinter_tk_failed", TCL_GLOBAL_ONLY); - - if ( _tkinter_tk_failed != NULL && - strcmp(_tkinter_tk_failed, "1") == 0) { - tk_load_failed = 1; - } - } -#endif - Py_DECREF((PyObject *)v); - return (TkappObject *)result; - } - - EnableEventHook(); - - return v; -} - - -#ifdef WITH_THREAD -static void -Tkapp_ThreadSend(TkappObject *self, Tcl_Event *ev, - Tcl_Condition *cond, Tcl_Mutex *mutex) -{ - Py_BEGIN_ALLOW_THREADS; - Tcl_MutexLock(mutex); - Tcl_ThreadQueueEvent(self->thread_id, ev, TCL_QUEUE_TAIL); - Tcl_ThreadAlert(self->thread_id); - Tcl_ConditionWait(cond, mutex, NULL); - Tcl_MutexUnlock(mutex); - Py_END_ALLOW_THREADS -} -#endif - - -/** Tcl Eval **/ - -typedef struct { - PyObject_HEAD - Tcl_Obj *value; - PyObject *string; /* This cannot cause cycles. */ -} PyTclObject; - -static PyObject *PyTclObject_Type; -#define PyTclObject_Check(v) ((v)->ob_type == (PyTypeObject *) PyTclObject_Type) - -static PyObject * -newPyTclObject(Tcl_Obj *arg) -{ - PyTclObject *self; - self = PyObject_New(PyTclObject, (PyTypeObject *) PyTclObject_Type); - if (self == NULL) - return NULL; - Py_INCREF(PyTclObject_Type); - Tcl_IncrRefCount(arg); - self->value = arg; - self->string = NULL; - return (PyObject*)self; -} - -static void -PyTclObject_dealloc(PyTclObject *self) -{ - PyObject *tp = (PyObject *) Py_TYPE(self); - Tcl_DecrRefCount(self->value); - Py_XDECREF(self->string); - PyObject_Del(self); - Py_DECREF(tp); -} - -static const char * -PyTclObject_TclString(PyObject *self) -{ - return Tcl_GetString(((PyTclObject*)self)->value); -} - -/* Like _str, but create Unicode if necessary. */ -PyDoc_STRVAR(PyTclObject_string__doc__, -"the string representation of this object, either as str or bytes"); - -static PyObject * -PyTclObject_string(PyTclObject *self, void *ignored) -{ - if (!self->string) { - self->string = unicodeFromTclObj(self->value); - if (!self->string) - return NULL; - } - Py_INCREF(self->string); - return self->string; -} - -static PyObject * -PyTclObject_str(PyTclObject *self) -{ - if (self->string) { - Py_INCREF(self->string); - return self->string; - } - /* XXX Could chache result if it is non-ASCII. */ - return unicodeFromTclObj(self->value); -} - -static PyObject * -PyTclObject_repr(PyTclObject *self) -{ - PyObject *repr, *str = PyTclObject_str(self); - if (str == NULL) - return NULL; - repr = PyUnicode_FromFormat("<%s object: %R>", - self->value->typePtr->name, str); - Py_DECREF(str); - return repr; -} - -#define TEST_COND(cond) ((cond) ? Py_True : Py_False) - -static PyObject * -PyTclObject_richcompare(PyObject *self, PyObject *other, int op) -{ - int result; - PyObject *v; - - /* neither argument should be NULL, unless something's gone wrong */ - if (self == NULL || other == NULL) { - PyErr_BadInternalCall(); - return NULL; - } - - /* both arguments should be instances of PyTclObject */ - if (!PyTclObject_Check(self) || !PyTclObject_Check(other)) { - v = Py_NotImplemented; - goto finished; - } - - if (self == other) - /* fast path when self and other are identical */ - result = 0; - else - result = strcmp(Tcl_GetString(((PyTclObject *)self)->value), - Tcl_GetString(((PyTclObject *)other)->value)); - /* Convert return value to a Boolean */ - switch (op) { - case Py_EQ: - v = TEST_COND(result == 0); - break; - case Py_NE: - v = TEST_COND(result != 0); - break; - case Py_LE: - v = TEST_COND(result <= 0); - break; - case Py_GE: - v = TEST_COND(result >= 0); - break; - case Py_LT: - v = TEST_COND(result < 0); - break; - case Py_GT: - v = TEST_COND(result > 0); - break; - default: - PyErr_BadArgument(); - return NULL; - } - finished: - Py_INCREF(v); - return v; -} - -PyDoc_STRVAR(get_typename__doc__, "name of the Tcl type"); - -static PyObject* -get_typename(PyTclObject* obj, void* ignored) -{ - return unicodeFromTclString(obj->value->typePtr->name); -} - - -static PyGetSetDef PyTclObject_getsetlist[] = { - {"typename", (getter)get_typename, NULL, get_typename__doc__}, - {"string", (getter)PyTclObject_string, NULL, - PyTclObject_string__doc__}, - {0}, -}; - -static PyType_Slot PyTclObject_Type_slots[] = { - {Py_tp_dealloc, (destructor)PyTclObject_dealloc}, - {Py_tp_repr, (reprfunc)PyTclObject_repr}, - {Py_tp_str, (reprfunc)PyTclObject_str}, - {Py_tp_getattro, PyObject_GenericGetAttr}, - {Py_tp_richcompare, PyTclObject_richcompare}, - {Py_tp_getset, PyTclObject_getsetlist}, - {0, 0} -}; - -static PyType_Spec PyTclObject_Type_spec = { - "_tkinter.Tcl_Obj", - sizeof(PyTclObject), - 0, - Py_TPFLAGS_DEFAULT, - PyTclObject_Type_slots, -}; - - -#if SIZE_MAX > INT_MAX -#define CHECK_STRING_LENGTH(s) do { \ - if (s != NULL && strlen(s) >= INT_MAX) { \ - PyErr_SetString(PyExc_OverflowError, "string is too long"); \ - return NULL; \ - } } while(0) -#else -#define CHECK_STRING_LENGTH(s) -#endif - -#ifdef HAVE_LIBTOMMAMTH -static Tcl_Obj* -asBignumObj(PyObject *value) -{ - Tcl_Obj *result; - int neg; - PyObject *hexstr; - char *hexchars; - mp_int bigValue; - - neg = Py_SIZE(value) < 0; - hexstr = _PyLong_Format(value, 16); - if (hexstr == NULL) - return NULL; - hexchars = PyUnicode_AsUTF8(hexstr); - if (hexchars == NULL) { - Py_DECREF(hexstr); - return NULL; - } - hexchars += neg + 2; /* skip sign and "0x" */ - mp_init(&bigValue); - if (mp_read_radix(&bigValue, hexchars, 16) != MP_OKAY) { - mp_clear(&bigValue); - Py_DECREF(hexstr); - PyErr_NoMemory(); - return NULL; - } - Py_DECREF(hexstr); - bigValue.sign = neg ? MP_NEG : MP_ZPOS; - result = Tcl_NewBignumObj(&bigValue); - mp_clear(&bigValue); - if (result == NULL) { - PyErr_NoMemory(); - return NULL; - } - return result; -} -#endif - -static Tcl_Obj* -AsObj(PyObject *value) -{ - Tcl_Obj *result; - - if (PyBytes_Check(value)) { - if (PyBytes_GET_SIZE(value) >= INT_MAX) { - PyErr_SetString(PyExc_OverflowError, "bytes object is too long"); - return NULL; - } - return Tcl_NewByteArrayObj((unsigned char *)PyBytes_AS_STRING(value), - (int)PyBytes_GET_SIZE(value)); - } - - if (PyBool_Check(value)) - return Tcl_NewBooleanObj(PyObject_IsTrue(value)); - - if (PyLong_CheckExact(value)) { - int overflow; - long longValue; -#ifdef TCL_WIDE_INT_TYPE - Tcl_WideInt wideValue; -#endif - longValue = PyLong_AsLongAndOverflow(value, &overflow); - if (!overflow) { - return Tcl_NewLongObj(longValue); - } - /* If there is an overflow in the long conversion, - fall through to wideInt handling. */ -#ifdef TCL_WIDE_INT_TYPE - if (_PyLong_AsByteArray((PyLongObject *)value, - (unsigned char *)(void *)&wideValue, - sizeof(wideValue), - PY_LITTLE_ENDIAN, - /* signed */ 1) == 0) { - return Tcl_NewWideIntObj(wideValue); - } - PyErr_Clear(); -#endif - /* If there is an overflow in the wideInt conversion, - fall through to bignum handling. */ -#ifdef HAVE_LIBTOMMAMTH - return asBignumObj(value); -#endif - /* If there is no wideInt or bignum support, - fall through to default object handling. */ - } - - if (PyFloat_Check(value)) - return Tcl_NewDoubleObj(PyFloat_AS_DOUBLE(value)); - - if (PyTuple_Check(value) || PyList_Check(value)) { - Tcl_Obj **argv; - Py_ssize_t size, i; - - size = PySequence_Fast_GET_SIZE(value); - if (size == 0) - return Tcl_NewListObj(0, NULL); - if (!CHECK_SIZE(size, sizeof(Tcl_Obj *))) { - PyErr_SetString(PyExc_OverflowError, - PyTuple_Check(value) ? "tuple is too long" : - "list is too long"); - return NULL; - } - argv = (Tcl_Obj **) PyMem_Malloc(((size_t)size) * sizeof(Tcl_Obj *)); - if (!argv) { - PyErr_NoMemory(); - return NULL; - } - for (i = 0; i < size; i++) - argv[i] = AsObj(PySequence_Fast_GET_ITEM(value,i)); - result = Tcl_NewListObj((int)size, argv); - PyMem_Free(argv); - return result; - } - - if (PyUnicode_Check(value)) { - void *inbuf; - Py_ssize_t size; - int kind; - Tcl_UniChar *outbuf = NULL; - Py_ssize_t i; - size_t allocsize; - - if (PyUnicode_READY(value) == -1) - return NULL; - - inbuf = PyUnicode_DATA(value); - size = PyUnicode_GET_LENGTH(value); - if (size == 0) - return Tcl_NewUnicodeObj((const void *)"", 0); - if (!CHECK_SIZE(size, sizeof(Tcl_UniChar))) { - PyErr_SetString(PyExc_OverflowError, "string is too long"); - return NULL; - } - kind = PyUnicode_KIND(value); - if (kind == sizeof(Tcl_UniChar)) - return Tcl_NewUnicodeObj(inbuf, (int)size); - allocsize = ((size_t)size) * sizeof(Tcl_UniChar); - outbuf = (Tcl_UniChar*)PyMem_Malloc(allocsize); - /* Else overflow occurred, and we take the next exit */ - if (!outbuf) { - PyErr_NoMemory(); - return NULL; - } - for (i = 0; i < size; i++) { - Py_UCS4 ch = PyUnicode_READ(kind, inbuf, i); - /* We cannot test for sizeof(Tcl_UniChar) directly, - so we test for UTF-8 size instead. */ -#if TCL_UTF_MAX == 3 - if (ch >= 0x10000) { - /* Tcl doesn't do UTF-16, yet. */ - PyErr_Format(Tkinter_TclError, - "character U+%x is above the range " - "(U+0000-U+FFFF) allowed by Tcl", - ch); - PyMem_Free(outbuf); - return NULL; - } -#endif - outbuf[i] = ch; - } - result = Tcl_NewUnicodeObj(outbuf, (int)size); - PyMem_Free(outbuf); - return result; - } - - if (PyTclObject_Check(value)) { - return ((PyTclObject*)value)->value; - } - - { - PyObject *v = PyObject_Str(value); - if (!v) - return 0; - result = AsObj(v); - Py_DECREF(v); - return result; - } -} - -static PyObject * -fromBoolean(PyObject* tkapp, Tcl_Obj *value) -{ - int boolValue; - if (Tcl_GetBooleanFromObj(Tkapp_Interp(tkapp), value, &boolValue) == TCL_ERROR) - return Tkinter_Error(tkapp); - return PyBool_FromLong(boolValue); -} - -static PyObject* -fromWideIntObj(PyObject* tkapp, Tcl_Obj *value) -{ - Tcl_WideInt wideValue; - if (Tcl_GetWideIntFromObj(Tkapp_Interp(tkapp), value, &wideValue) == TCL_OK) { - if (sizeof(wideValue) <= SIZEOF_LONG_LONG) - return PyLong_FromLongLong(wideValue); - return _PyLong_FromByteArray((unsigned char *)(void *)&wideValue, - sizeof(wideValue), - PY_LITTLE_ENDIAN, - /* signed */ 1); - } - return NULL; -} - -#ifdef HAVE_LIBTOMMAMTH -static PyObject* -fromBignumObj(PyObject* tkapp, Tcl_Obj *value) -{ - mp_int bigValue; - unsigned long numBytes; - unsigned char *bytes; - PyObject *res; - - if (Tcl_GetBignumFromObj(Tkapp_Interp(tkapp), value, &bigValue) != TCL_OK) - return Tkinter_Error(tkapp); - numBytes = mp_unsigned_bin_size(&bigValue); - bytes = PyMem_Malloc(numBytes); - if (bytes == NULL) { - mp_clear(&bigValue); - return PyErr_NoMemory(); - } - if (mp_to_unsigned_bin_n(&bigValue, bytes, - &numBytes) != MP_OKAY) { - mp_clear(&bigValue); - PyMem_Free(bytes); - return PyErr_NoMemory(); - } - res = _PyLong_FromByteArray(bytes, numBytes, - /* big-endian */ 0, - /* unsigned */ 0); - PyMem_Free(bytes); - if (res != NULL && bigValue.sign == MP_NEG) { - PyObject *res2 = PyNumber_Negative(res); - Py_DECREF(res); - res = res2; - } - mp_clear(&bigValue); - return res; -} -#endif - -static PyObject* -FromObj(PyObject* tkapp, Tcl_Obj *value) -{ - PyObject *result = NULL; - TkappObject *app = (TkappObject*)tkapp; - Tcl_Interp *interp = Tkapp_Interp(tkapp); - - if (value->typePtr == NULL) { - return unicodeFromTclStringAndSize(value->bytes, value->length); - } - - if (value->typePtr == app->BooleanType || - value->typePtr == app->OldBooleanType) { - return fromBoolean(tkapp, value); - } - - if (value->typePtr == app->ByteArrayType) { - int size; - char *data = (char*)Tcl_GetByteArrayFromObj(value, &size); - return PyBytes_FromStringAndSize(data, size); - } - - if (value->typePtr == app->DoubleType) { - return PyFloat_FromDouble(value->internalRep.doubleValue); - } - - if (value->typePtr == app->IntType) { - long longValue; - if (Tcl_GetLongFromObj(interp, value, &longValue) == TCL_OK) - return PyLong_FromLong(longValue); - /* If there is an error in the long conversion, - fall through to wideInt handling. */ - } - - if (value->typePtr == app->IntType || - value->typePtr == app->WideIntType) { - result = fromWideIntObj(tkapp, value); - if (result != NULL || PyErr_Occurred()) - return result; - Tcl_ResetResult(interp); - /* If there is an error in the wideInt conversion, - fall through to bignum handling. */ - } - -#ifdef HAVE_LIBTOMMAMTH - if (value->typePtr == app->IntType || - value->typePtr == app->WideIntType || - value->typePtr == app->BignumType) { - return fromBignumObj(tkapp, value); - } -#endif - - if (value->typePtr == app->ListType) { - int size; - int i, status; - PyObject *elem; - Tcl_Obj *tcl_elem; - - status = Tcl_ListObjLength(interp, value, &size); - if (status == TCL_ERROR) - return Tkinter_Error(tkapp); - result = PyTuple_New(size); - if (!result) - return NULL; - for (i = 0; i < size; i++) { - status = Tcl_ListObjIndex(interp, value, i, &tcl_elem); - if (status == TCL_ERROR) { - Py_DECREF(result); - return Tkinter_Error(tkapp); - } - elem = FromObj(tkapp, tcl_elem); - if (!elem) { - Py_DECREF(result); - return NULL; - } - PyTuple_SET_ITEM(result, i, elem); - } - return result; - } - - if (value->typePtr == app->ProcBodyType) { - /* fall through: return tcl object. */ - } - - if (value->typePtr == app->StringType) { - return PyUnicode_FromKindAndData( - sizeof(Tcl_UniChar), Tcl_GetUnicode(value), - Tcl_GetCharLength(value)); - } - -#if TK_HEX_VERSION >= 0x08050000 - if (app->BooleanType == NULL && - strcmp(value->typePtr->name, "booleanString") == 0) { - /* booleanString type is not registered in Tcl */ - app->BooleanType = value->typePtr; - return fromBoolean(tkapp, value); - } -#endif - -#ifdef HAVE_LIBTOMMAMTH - if (app->BignumType == NULL && - strcmp(value->typePtr->name, "bignum") == 0) { - /* bignum type is not registered in Tcl */ - app->BignumType = value->typePtr; - return fromBignumObj(tkapp, value); - } -#endif - - return newPyTclObject(value); -} - -#ifdef WITH_THREAD -/* This mutex synchronizes inter-thread command calls. */ -TCL_DECLARE_MUTEX(call_mutex) - -typedef struct Tkapp_CallEvent { - Tcl_Event ev; /* Must be first */ - TkappObject *self; - PyObject *args; - int flags; - PyObject **res; - PyObject **exc_type, **exc_value, **exc_tb; - Tcl_Condition *done; -} Tkapp_CallEvent; -#endif - -void -Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, int objc) -{ - int i; - for (i = 0; i < objc; i++) - Tcl_DecrRefCount(objv[i]); - if (objv != objStore) - PyMem_Free(objv); -} - -/* Convert Python objects to Tcl objects. This must happen in the - interpreter thread, which may or may not be the calling thread. */ - -static Tcl_Obj** -Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, int *pobjc) -{ - Tcl_Obj **objv = objStore; - Py_ssize_t objc = 0, i; - if (args == NULL) - /* do nothing */; - - else if (!(PyTuple_Check(args) || PyList_Check(args))) { - objv[0] = AsObj(args); - if (objv[0] == 0) - goto finally; - objc = 1; - Tcl_IncrRefCount(objv[0]); - } - else { - objc = PySequence_Fast_GET_SIZE(args); - - if (objc > ARGSZ) { - if (!CHECK_SIZE(objc, sizeof(Tcl_Obj *))) { - PyErr_SetString(PyExc_OverflowError, - PyTuple_Check(args) ? "tuple is too long" : - "list is too long"); - return NULL; - } - objv = (Tcl_Obj **)PyMem_Malloc(((size_t)objc) * sizeof(Tcl_Obj *)); - if (objv == NULL) { - PyErr_NoMemory(); - objc = 0; - goto finally; - } - } - - for (i = 0; i < objc; i++) { - PyObject *v = PySequence_Fast_GET_ITEM(args, i); - if (v == Py_None) { - objc = i; - break; - } - objv[i] = AsObj(v); - if (!objv[i]) { - /* Reset objc, so it attempts to clear - objects only up to i. */ - objc = i; - goto finally; - } - Tcl_IncrRefCount(objv[i]); - } - } - *pobjc = (int)objc; - return objv; -finally: - Tkapp_CallDeallocArgs(objv, objStore, (int)objc); - return NULL; -} - -/* Convert the results of a command call into a Python objects. */ - -static PyObject* -Tkapp_CallResult(TkappObject *self) -{ - PyObject *res = NULL; - Tcl_Obj *value = Tcl_GetObjResult(self->interp); - if(self->wantobjects) { - /* Not sure whether the IncrRef is necessary, but something - may overwrite the interpreter result while we are - converting it. */ - Tcl_IncrRefCount(value); - res = FromObj((PyObject*)self, value); - Tcl_DecrRefCount(value); - } else { - res = unicodeFromTclObj(value); - } - return res; -} - -#ifdef WITH_THREAD - -/* Tkapp_CallProc is the event procedure that is executed in the context of - the Tcl interpreter thread. Initially, it holds the Tcl lock, and doesn't - hold the Python lock. */ - -static int -Tkapp_CallProc(Tkapp_CallEvent *e, int flags) -{ - Tcl_Obj *objStore[ARGSZ]; - Tcl_Obj **objv; - int objc; - int i; - ENTER_PYTHON - objv = Tkapp_CallArgs(e->args, objStore, &objc); - if (!objv) { - PyErr_Fetch(e->exc_type, e->exc_value, e->exc_tb); - *(e->res) = NULL; - } - LEAVE_PYTHON - if (!objv) - goto done; - i = Tcl_EvalObjv(e->self->interp, objc, objv, e->flags); - ENTER_PYTHON - if (i == TCL_ERROR) { - *(e->res) = NULL; - *(e->exc_type) = NULL; - *(e->exc_tb) = NULL; - *(e->exc_value) = PyObject_CallFunction( - Tkinter_TclError, "s", - Tcl_GetStringResult(e->self->interp)); - } - else { - *(e->res) = Tkapp_CallResult(e->self); - } - LEAVE_PYTHON - - Tkapp_CallDeallocArgs(objv, objStore, objc); -done: - /* Wake up calling thread. */ - Tcl_MutexLock(&call_mutex); - Tcl_ConditionNotify(e->done); - Tcl_MutexUnlock(&call_mutex); - return 1; -} - -#endif - -/* This is the main entry point for calling a Tcl command. - It supports three cases, with regard to threading: - 1. Tcl is not threaded: Must have the Tcl lock, then can invoke command in - the context of the calling thread. - 2. Tcl is threaded, caller of the command is in the interpreter thread: - Execute the command in the calling thread. Since the Tcl lock will - not be used, we can merge that with case 1. - 3. Tcl is threaded, caller is in a different thread: Must queue an event to - the interpreter thread. Allocation of Tcl objects needs to occur in the - interpreter thread, so we ship the PyObject* args to the target thread, - and perform processing there. */ - -static PyObject * -Tkapp_Call(PyObject *selfptr, PyObject *args) -{ - Tcl_Obj *objStore[ARGSZ]; - Tcl_Obj **objv = NULL; - int objc, i; - PyObject *res = NULL; - TkappObject *self = (TkappObject*)selfptr; - int flags = TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL; - - /* If args is a single tuple, replace with contents of tuple */ - if (PyTuple_GET_SIZE(args) == 1) { - PyObject *item = PyTuple_GET_ITEM(args, 0); - if (PyTuple_Check(item)) - args = item; - } -#ifdef WITH_THREAD - if (self->threaded && self->thread_id != Tcl_GetCurrentThread()) { - /* We cannot call the command directly. Instead, we must - marshal the parameters to the interpreter thread. */ - Tkapp_CallEvent *ev; - Tcl_Condition cond = NULL; - PyObject *exc_type, *exc_value, *exc_tb; - if (!WaitForMainloop(self)) - return NULL; - ev = (Tkapp_CallEvent*)attemptckalloc(sizeof(Tkapp_CallEvent)); - if (ev == NULL) { - PyErr_NoMemory(); - return NULL; - } - ev->ev.proc = (Tcl_EventProc*)Tkapp_CallProc; - ev->self = self; - ev->args = args; - ev->res = &res; - ev->exc_type = &exc_type; - ev->exc_value = &exc_value; - ev->exc_tb = &exc_tb; - ev->done = &cond; - - Tkapp_ThreadSend(self, (Tcl_Event*)ev, &cond, &call_mutex); - - if (res == NULL) { - if (exc_type) - PyErr_Restore(exc_type, exc_value, exc_tb); - else - PyErr_SetObject(Tkinter_TclError, exc_value); - } - Tcl_ConditionFinalize(&cond); - } - else -#endif - { - - objv = Tkapp_CallArgs(args, objStore, &objc); - if (!objv) - return NULL; - - ENTER_TCL - - i = Tcl_EvalObjv(self->interp, objc, objv, flags); - - ENTER_OVERLAP - - if (i == TCL_ERROR) - Tkinter_Error(selfptr); - else - res = Tkapp_CallResult(self); - - LEAVE_OVERLAP_TCL - - Tkapp_CallDeallocArgs(objv, objStore, objc); - } - return res; -} - - -/*[clinic input] -_tkinter.tkapp.eval - - script: str - / - -[clinic start generated code]*/ - -static PyObject * -_tkinter_tkapp_eval_impl(TkappObject *self, const char *script) -/*[clinic end generated code: output=24b79831f700dea0 input=481484123a455f22]*/ -{ - PyObject *res = NULL; - int err; - - CHECK_STRING_LENGTH(script); - CHECK_TCL_APPARTMENT; - - ENTER_TCL - err = Tcl_Eval(Tkapp_Interp(self), script); - ENTER_OVERLAP - if (err == TCL_ERROR) - res = Tkinter_Error((PyObject *)self); - else - res = unicodeFromTclString(Tkapp_Result(self)); - LEAVE_OVERLAP_TCL - return res; -} - -/*[clinic input] -_tkinter.tkapp.evalfile - - fileName: str - / - -[clinic start generated code]*/ - -static PyObject * -_tkinter_tkapp_evalfile_impl(TkappObject *self, const char *fileName) -/*[clinic end generated code: output=63be88dcee4f11d3 input=873ab707e5e947e1]*/ -{ - PyObject *res = NULL; - int err; - - CHECK_STRING_LENGTH(fileName); - CHECK_TCL_APPARTMENT; - - ENTER_TCL - err = Tcl_EvalFile(Tkapp_Interp(self), fileName); - ENTER_OVERLAP - if (err == TCL_ERROR) - res = Tkinter_Error((PyObject *)self); - else - res = unicodeFromTclString(Tkapp_Result(self)); - LEAVE_OVERLAP_TCL - return res; -} - -/*[clinic input] -_tkinter.tkapp.record - - script: str - / - -[clinic start generated code]*/ - -static PyObject * -_tkinter_tkapp_record_impl(TkappObject *self, const char *script) -/*[clinic end generated code: output=0ffe08a0061730df input=c0b0db5a21412cac]*/ -{ - PyObject *res = NULL; - int err; - - CHECK_STRING_LENGTH(script); - CHECK_TCL_APPARTMENT; - - ENTER_TCL - err = Tcl_RecordAndEval(Tkapp_Interp(self), script, TCL_NO_EVAL); - ENTER_OVERLAP - if (err == TCL_ERROR) - res = Tkinter_Error((PyObject *)self); - else - res = unicodeFromTclString(Tkapp_Result(self)); - LEAVE_OVERLAP_TCL - return res; -} - -/*[clinic input] -_tkinter.tkapp.adderrorinfo - - msg: str - / - -[clinic start generated code]*/ - -static PyObject * -_tkinter_tkapp_adderrorinfo_impl(TkappObject *self, const char *msg) -/*[clinic end generated code: output=52162eaca2ee53cb input=f4b37aec7c7e8c77]*/ -{ - CHECK_STRING_LENGTH(msg); - CHECK_TCL_APPARTMENT; - - ENTER_TCL - Tcl_AddErrorInfo(Tkapp_Interp(self), msg); - LEAVE_TCL - - Py_RETURN_NONE; -} - - - -/** Tcl Variable **/ - -typedef PyObject* (*EventFunc)(PyObject*, PyObject *args, int flags); - -#ifdef WITH_THREAD -TCL_DECLARE_MUTEX(var_mutex) - -typedef struct VarEvent { - Tcl_Event ev; /* must be first */ - PyObject *self; - PyObject *args; - int flags; - EventFunc func; - PyObject **res; - PyObject **exc_type; - PyObject **exc_val; - Tcl_Condition *cond; -} VarEvent; -#endif - -/*[python] - -class varname_converter(CConverter): - type = 'const char *' - converter = 'varname_converter' - -[python]*/ -/*[python checksum: da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ - -static int -varname_converter(PyObject *in, void *_out) -{ - char *s; - const char **out = (const char**)_out; - if (PyBytes_Check(in)) { - if (PyBytes_GET_SIZE(in) > INT_MAX) { - PyErr_SetString(PyExc_OverflowError, "bytes object is too long"); - return 0; - } - s = PyBytes_AS_STRING(in); - if (strlen(s) != (size_t)PyBytes_GET_SIZE(in)) { - PyErr_SetString(PyExc_ValueError, "embedded null byte"); - return 0; - } - *out = s; - return 1; - } - if (PyUnicode_Check(in)) { - Py_ssize_t size; - s = PyUnicode_AsUTF8AndSize(in, &size); - if (s == NULL) { - return 0; - } - if (size > INT_MAX) { - PyErr_SetString(PyExc_OverflowError, "string is too long"); - return 0; - } - if (strlen(s) != (size_t)size) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - return 0; - } - *out = s; - return 1; - } - if (PyTclObject_Check(in)) { - *out = PyTclObject_TclString(in); - return 1; - } - PyErr_Format(PyExc_TypeError, - "must be str, bytes or Tcl_Obj, not %.50s", - in->ob_type->tp_name); - return 0; -} - -#ifdef WITH_THREAD - -static void -var_perform(VarEvent *ev) -{ - *(ev->res) = ev->func(ev->self, ev->args, ev->flags); - if (!*(ev->res)) { - PyObject *exc, *val, *tb; - PyErr_Fetch(&exc, &val, &tb); - PyErr_NormalizeException(&exc, &val, &tb); - *(ev->exc_type) = exc; - *(ev->exc_val) = val; - Py_XDECREF(tb); - } - -} - -static int -var_proc(VarEvent* ev, int flags) -{ - ENTER_PYTHON - var_perform(ev); - Tcl_MutexLock(&var_mutex); - Tcl_ConditionNotify(ev->cond); - Tcl_MutexUnlock(&var_mutex); - LEAVE_PYTHON - return 1; -} - -#endif - -static PyObject* -var_invoke(EventFunc func, PyObject *selfptr, PyObject *args, int flags) -{ -#ifdef WITH_THREAD - TkappObject *self = (TkappObject*)selfptr; - if (self->threaded && self->thread_id != Tcl_GetCurrentThread()) { - VarEvent *ev; - PyObject *res, *exc_type, *exc_val; - Tcl_Condition cond = NULL; - - /* The current thread is not the interpreter thread. Marshal - the call to the interpreter thread, then wait for - completion. */ - if (!WaitForMainloop(self)) - return NULL; - - ev = (VarEvent*)attemptckalloc(sizeof(VarEvent)); - if (ev == NULL) { - PyErr_NoMemory(); - return NULL; - } - ev->self = selfptr; - ev->args = args; - ev->flags = flags; - ev->func = func; - ev->res = &res; - ev->exc_type = &exc_type; - ev->exc_val = &exc_val; - ev->cond = &cond; - ev->ev.proc = (Tcl_EventProc*)var_proc; - Tkapp_ThreadSend(self, (Tcl_Event*)ev, &cond, &var_mutex); - Tcl_ConditionFinalize(&cond); - if (!res) { - PyErr_SetObject(exc_type, exc_val); - Py_DECREF(exc_type); - Py_DECREF(exc_val); - return NULL; - } - return res; - } -#endif - /* Tcl is not threaded, or this is the interpreter thread. */ - return func(selfptr, args, flags); -} - -static PyObject * -SetVar(PyObject *self, PyObject *args, int flags) -{ - const char *name1, *name2; - PyObject *newValue; - PyObject *res = NULL; - Tcl_Obj *newval, *ok; - - switch (PyTuple_GET_SIZE(args)) { - case 2: - if (!PyArg_ParseTuple(args, "O&O:setvar", - varname_converter, &name1, &newValue)) - return NULL; - /* XXX Acquire tcl lock??? */ - newval = AsObj(newValue); - if (newval == NULL) - return NULL; - ENTER_TCL - ok = Tcl_SetVar2Ex(Tkapp_Interp(self), name1, NULL, - newval, flags); - ENTER_OVERLAP - if (!ok) - Tkinter_Error(self); - else { - res = Py_None; - Py_INCREF(res); - } - LEAVE_OVERLAP_TCL - break; - case 3: - if (!PyArg_ParseTuple(args, "ssO:setvar", - &name1, &name2, &newValue)) - return NULL; - CHECK_STRING_LENGTH(name1); - CHECK_STRING_LENGTH(name2); - /* XXX must hold tcl lock already??? */ - newval = AsObj(newValue); - ENTER_TCL - ok = Tcl_SetVar2Ex(Tkapp_Interp(self), name1, name2, newval, flags); - ENTER_OVERLAP - if (!ok) - Tkinter_Error(self); - else { - res = Py_None; - Py_INCREF(res); - } - LEAVE_OVERLAP_TCL - break; - default: - PyErr_SetString(PyExc_TypeError, "setvar requires 2 to 3 arguments"); - return NULL; - } - return res; -} - -static PyObject * -Tkapp_SetVar(PyObject *self, PyObject *args) -{ - return var_invoke(SetVar, self, args, TCL_LEAVE_ERR_MSG); -} - -static PyObject * -Tkapp_GlobalSetVar(PyObject *self, PyObject *args) -{ - return var_invoke(SetVar, self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY); -} - - - -static PyObject * -GetVar(PyObject *self, PyObject *args, int flags) -{ - const char *name1, *name2=NULL; - PyObject *res = NULL; - Tcl_Obj *tres; - - if (!PyArg_ParseTuple(args, "O&|s:getvar", - varname_converter, &name1, &name2)) - return NULL; - - CHECK_STRING_LENGTH(name2); - ENTER_TCL - tres = Tcl_GetVar2Ex(Tkapp_Interp(self), name1, name2, flags); - ENTER_OVERLAP - if (tres == NULL) { - PyErr_SetString(Tkinter_TclError, - Tcl_GetStringResult(Tkapp_Interp(self))); - } else { - if (((TkappObject*)self)->wantobjects) { - res = FromObj(self, tres); - } - else { - res = unicodeFromTclObj(tres); - } - } - LEAVE_OVERLAP_TCL - return res; -} - -static PyObject * -Tkapp_GetVar(PyObject *self, PyObject *args) -{ - return var_invoke(GetVar, self, args, TCL_LEAVE_ERR_MSG); -} - -static PyObject * -Tkapp_GlobalGetVar(PyObject *self, PyObject *args) -{ - return var_invoke(GetVar, self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY); -} - - - -static PyObject * -UnsetVar(PyObject *self, PyObject *args, int flags) -{ - char *name1, *name2=NULL; - int code; - PyObject *res = NULL; - - if (!PyArg_ParseTuple(args, "s|s:unsetvar", &name1, &name2)) - return NULL; - - CHECK_STRING_LENGTH(name1); - CHECK_STRING_LENGTH(name2); - ENTER_TCL - code = Tcl_UnsetVar2(Tkapp_Interp(self), name1, name2, flags); - ENTER_OVERLAP - if (code == TCL_ERROR) - res = Tkinter_Error(self); - else { - Py_INCREF(Py_None); - res = Py_None; - } - LEAVE_OVERLAP_TCL - return res; -} - -static PyObject * -Tkapp_UnsetVar(PyObject *self, PyObject *args) -{ - return var_invoke(UnsetVar, self, args, TCL_LEAVE_ERR_MSG); -} - -static PyObject * -Tkapp_GlobalUnsetVar(PyObject *self, PyObject *args) -{ - return var_invoke(UnsetVar, self, args, - TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY); -} - - - -/** Tcl to Python **/ - -/*[clinic input] -_tkinter.tkapp.getint - - arg: object - / - -[clinic start generated code]*/ - -static PyObject * -_tkinter_tkapp_getint(TkappObject *self, PyObject *arg) -/*[clinic end generated code: output=88cf293fae307cfe input=034026997c5b91f8]*/ -{ - char *s; - Tcl_Obj *value; - PyObject *result; - - if (PyLong_Check(arg)) { - Py_INCREF(arg); - return arg; - } - - if (PyTclObject_Check(arg)) { - value = ((PyTclObject*)arg)->value; - Tcl_IncrRefCount(value); - } - else { - if (!PyArg_Parse(arg, "s:getint", &s)) - return NULL; - CHECK_STRING_LENGTH(s); - value = Tcl_NewStringObj(s, -1); - if (value == NULL) - return Tkinter_Error((PyObject *)self); - } - /* Don't use Tcl_GetInt() because it returns ambiguous result for value - in ranges -2**32..-2**31-1 and 2**31..2**32-1 (on 32-bit platform). - - Prefer bignum because Tcl_GetWideIntFromObj returns ambiguous result for - value in ranges -2**64..-2**63-1 and 2**63..2**64-1 (on 32-bit platform). - */ -#ifdef HAVE_LIBTOMMAMTH - result = fromBignumObj((PyObject *)self, value); -#else - result = fromWideIntObj((PyObject *)self, value); -#endif - Tcl_DecrRefCount(value); - if (result != NULL || PyErr_Occurred()) - return result; - return Tkinter_Error((PyObject *)self); -} - -/*[clinic input] -_tkinter.tkapp.getdouble - - arg: object - / - -[clinic start generated code]*/ - -static PyObject * -_tkinter_tkapp_getdouble(TkappObject *self, PyObject *arg) -/*[clinic end generated code: output=c52b138bd8b956b9 input=22015729ce9ef7f8]*/ -{ - char *s; - double v; - - if (PyFloat_Check(arg)) { - Py_INCREF(arg); - return arg; - } - - if (PyNumber_Check(arg)) { - return PyNumber_Float(arg); - } - - if (PyTclObject_Check(arg)) { - if (Tcl_GetDoubleFromObj(Tkapp_Interp(self), - ((PyTclObject*)arg)->value, - &v) == TCL_ERROR) - return Tkinter_Error((PyObject *)self); - return PyFloat_FromDouble(v); - } - - if (!PyArg_Parse(arg, "s:getdouble", &s)) - return NULL; - CHECK_STRING_LENGTH(s); - if (Tcl_GetDouble(Tkapp_Interp(self), s, &v) == TCL_ERROR) - return Tkinter_Error((PyObject *)self); - return PyFloat_FromDouble(v); -} - -/*[clinic input] -_tkinter.tkapp.getboolean - - arg: object - / - -[clinic start generated code]*/ - -static PyObject * -_tkinter_tkapp_getboolean(TkappObject *self, PyObject *arg) -/*[clinic end generated code: output=726a9ae445821d91 input=7f11248ef8f8776e]*/ -{ - char *s; - int v; - - if (PyLong_Check(arg)) { /* int or bool */ - return PyBool_FromLong(Py_SIZE(arg) != 0); - } - - if (PyTclObject_Check(arg)) { - if (Tcl_GetBooleanFromObj(Tkapp_Interp(self), - ((PyTclObject*)arg)->value, - &v) == TCL_ERROR) - return Tkinter_Error((PyObject *)self); - return PyBool_FromLong(v); - } - - if (!PyArg_Parse(arg, "s:getboolean", &s)) - return NULL; - CHECK_STRING_LENGTH(s); - if (Tcl_GetBoolean(Tkapp_Interp(self), s, &v) == TCL_ERROR) - return Tkinter_Error((PyObject *)self); - return PyBool_FromLong(v); -} - -/*[clinic input] -_tkinter.tkapp.exprstring - - s: str - / - -[clinic start generated code]*/ - -static PyObject * -_tkinter_tkapp_exprstring_impl(TkappObject *self, const char *s) -/*[clinic end generated code: output=beda323d3ed0abb1 input=fa78f751afb2f21b]*/ -{ - PyObject *res = NULL; - int retval; - - CHECK_STRING_LENGTH(s); - CHECK_TCL_APPARTMENT; - - ENTER_TCL - retval = Tcl_ExprString(Tkapp_Interp(self), s); - ENTER_OVERLAP - if (retval == TCL_ERROR) - res = Tkinter_Error((PyObject *)self); - else - res = unicodeFromTclString(Tkapp_Result(self)); - LEAVE_OVERLAP_TCL - return res; -} - -/*[clinic input] -_tkinter.tkapp.exprlong - - s: str - / - -[clinic start generated code]*/ - -static PyObject * -_tkinter_tkapp_exprlong_impl(TkappObject *self, const char *s) -/*[clinic end generated code: output=5d6a46b63c6ebcf9 input=11bd7eee0c57b4dc]*/ -{ - PyObject *res = NULL; - int retval; - long v; - - CHECK_STRING_LENGTH(s); - CHECK_TCL_APPARTMENT; - - ENTER_TCL - retval = Tcl_ExprLong(Tkapp_Interp(self), s, &v); - ENTER_OVERLAP - if (retval == TCL_ERROR) - res = Tkinter_Error((PyObject *)self); - else - res = PyLong_FromLong(v); - LEAVE_OVERLAP_TCL - return res; -} - -/*[clinic input] -_tkinter.tkapp.exprdouble - - s: str - / - -[clinic start generated code]*/ - -static PyObject * -_tkinter_tkapp_exprdouble_impl(TkappObject *self, const char *s) -/*[clinic end generated code: output=ff78df1081ea4158 input=ff02bc11798832d5]*/ -{ - PyObject *res = NULL; - double v; - int retval; - - CHECK_STRING_LENGTH(s); - CHECK_TCL_APPARTMENT; - PyFPE_START_PROTECT("Tkapp_ExprDouble", return 0) - ENTER_TCL - retval = Tcl_ExprDouble(Tkapp_Interp(self), s, &v); - ENTER_OVERLAP - PyFPE_END_PROTECT(retval) - if (retval == TCL_ERROR) - res = Tkinter_Error((PyObject *)self); - else - res = PyFloat_FromDouble(v); - LEAVE_OVERLAP_TCL - return res; -} - -/*[clinic input] -_tkinter.tkapp.exprboolean - - s: str - / - -[clinic start generated code]*/ - -static PyObject * -_tkinter_tkapp_exprboolean_impl(TkappObject *self, const char *s) -/*[clinic end generated code: output=8b28038c22887311 input=c8c66022bdb8d5d3]*/ -{ - PyObject *res = NULL; - int retval; - int v; - - CHECK_STRING_LENGTH(s); - CHECK_TCL_APPARTMENT; - ENTER_TCL - retval = Tcl_ExprBoolean(Tkapp_Interp(self), s, &v); - ENTER_OVERLAP - if (retval == TCL_ERROR) - res = Tkinter_Error((PyObject *)self); - else - res = PyLong_FromLong(v); - LEAVE_OVERLAP_TCL - return res; -} - - - -/*[clinic input] -_tkinter.tkapp.splitlist - - arg: object - / - -[clinic start generated code]*/ - -static PyObject * -_tkinter_tkapp_splitlist(TkappObject *self, PyObject *arg) -/*[clinic end generated code: output=13b51d34386d36fb input=2b2e13351e3c0b53]*/ -{ - char *list; - int argc; - const char **argv; - PyObject *v; - int i; - - if (PyTclObject_Check(arg)) { - int objc; - Tcl_Obj **objv; - if (Tcl_ListObjGetElements(Tkapp_Interp(self), - ((PyTclObject*)arg)->value, - &objc, &objv) == TCL_ERROR) { - return Tkinter_Error((PyObject *)self); - } - if (!(v = PyTuple_New(objc))) - return NULL; - for (i = 0; i < objc; i++) { - PyObject *s = FromObj((PyObject*)self, objv[i]); - if (!s) { - Py_DECREF(v); - return NULL; - } - PyTuple_SET_ITEM(v, i, s); - } - return v; - } - if (PyTuple_Check(arg)) { - Py_INCREF(arg); - return arg; - } - if (PyList_Check(arg)) { - return PySequence_Tuple(arg); - } - - if (!PyArg_Parse(arg, "et:splitlist", "utf-8", &list)) - return NULL; - - if (strlen(list) >= INT_MAX) { - PyErr_SetString(PyExc_OverflowError, "string is too long"); - PyMem_Free(list); - return NULL; - } - if (Tcl_SplitList(Tkapp_Interp(self), list, - &argc, &argv) == TCL_ERROR) { - PyMem_Free(list); - return Tkinter_Error((PyObject *)self); - } - - if (!(v = PyTuple_New(argc))) - goto finally; - - for (i = 0; i < argc; i++) { - PyObject *s = unicodeFromTclString(argv[i]); - if (!s) { - Py_DECREF(v); - v = NULL; - goto finally; - } - PyTuple_SET_ITEM(v, i, s); - } - - finally: - ckfree(FREECAST argv); - PyMem_Free(list); - return v; -} - -/*[clinic input] -_tkinter.tkapp.split - - arg: object - / - -[clinic start generated code]*/ - -static PyObject * -_tkinter_tkapp_split(TkappObject *self, PyObject *arg) -/*[clinic end generated code: output=e08ad832363facfd input=a1c78349eacaa140]*/ -{ - PyObject *v; - char *list; - - if (PyTclObject_Check(arg)) { - Tcl_Obj *value = ((PyTclObject*)arg)->value; - int objc; - Tcl_Obj **objv; - int i; - if (Tcl_ListObjGetElements(Tkapp_Interp(self), value, - &objc, &objv) == TCL_ERROR) { - return FromObj((PyObject*)self, value); - } - if (objc == 0) - return PyUnicode_FromString(""); - if (objc == 1) - return FromObj((PyObject*)self, objv[0]); - if (!(v = PyTuple_New(objc))) - return NULL; - for (i = 0; i < objc; i++) { - PyObject *s = FromObj((PyObject*)self, objv[i]); - if (!s) { - Py_DECREF(v); - return NULL; - } - PyTuple_SET_ITEM(v, i, s); - } - return v; - } - if (PyTuple_Check(arg) || PyList_Check(arg)) - return SplitObj(arg); - - if (!PyArg_Parse(arg, "et:split", "utf-8", &list)) - return NULL; - if (strlen(list) >= INT_MAX) { - PyErr_SetString(PyExc_OverflowError, "string is too long"); - PyMem_Free(list); - return NULL; - } - v = Split(list); - PyMem_Free(list); - return v; -} - - - -/** Tcl Command **/ - -/* Client data struct */ -typedef struct { - PyObject *self; - PyObject *func; -} PythonCmd_ClientData; - -static int -PythonCmd_Error(Tcl_Interp *interp) -{ - errorInCmd = 1; - PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd); - LEAVE_PYTHON - return TCL_ERROR; -} - -/* This is the Tcl command that acts as a wrapper for Python - * function or method. - */ -static int -PythonCmd(ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[]) -{ - PythonCmd_ClientData *data = (PythonCmd_ClientData *)clientData; - PyObject *func, *arg, *res; - int i, rv; - Tcl_Obj *obj_res; - - ENTER_PYTHON - - /* TBD: no error checking here since we know, via the - * Tkapp_CreateCommand() that the client data is a two-tuple - */ - func = data->func; - - /* Create argument list (argv1, ..., argvN) */ - if (!(arg = PyTuple_New(argc - 1))) - return PythonCmd_Error(interp); - - for (i = 0; i < (argc - 1); i++) { - PyObject *s = unicodeFromTclString(argv[i + 1]); - if (!s) { - Py_DECREF(arg); - return PythonCmd_Error(interp); - } - PyTuple_SET_ITEM(arg, i, s); - } - res = PyEval_CallObject(func, arg); - Py_DECREF(arg); - - if (res == NULL) - return PythonCmd_Error(interp); - - obj_res = AsObj(res); - if (obj_res == NULL) { - Py_DECREF(res); - return PythonCmd_Error(interp); - } - else { - Tcl_SetObjResult(interp, obj_res); - rv = TCL_OK; - } - - Py_DECREF(res); - - LEAVE_PYTHON - - return rv; -} - -static void -PythonCmdDelete(ClientData clientData) -{ - PythonCmd_ClientData *data = (PythonCmd_ClientData *)clientData; - - ENTER_PYTHON - Py_XDECREF(data->self); - Py_XDECREF(data->func); - PyMem_DEL(data); - LEAVE_PYTHON -} - - - - -#ifdef WITH_THREAD -TCL_DECLARE_MUTEX(command_mutex) - -typedef struct CommandEvent{ - Tcl_Event ev; - Tcl_Interp* interp; - const char *name; - int create; - int *status; - ClientData *data; - Tcl_Condition *done; -} CommandEvent; - -static int -Tkapp_CommandProc(CommandEvent *ev, int flags) -{ - if (ev->create) - *ev->status = Tcl_CreateCommand( - ev->interp, ev->name, PythonCmd, - ev->data, PythonCmdDelete) == NULL; - else - *ev->status = Tcl_DeleteCommand(ev->interp, ev->name); - Tcl_MutexLock(&command_mutex); - Tcl_ConditionNotify(ev->done); - Tcl_MutexUnlock(&command_mutex); - return 1; -} -#endif - -/*[clinic input] -_tkinter.tkapp.createcommand - - name: str - func: object - / - -[clinic start generated code]*/ - -static PyObject * -_tkinter_tkapp_createcommand_impl(TkappObject *self, const char *name, - PyObject *func) -/*[clinic end generated code: output=2a1c79a4ee2af410 input=255785cb70edc6a0]*/ -{ - PythonCmd_ClientData *data; - int err; - - CHECK_STRING_LENGTH(name); - if (!PyCallable_Check(func)) { - PyErr_SetString(PyExc_TypeError, "command not callable"); - return NULL; - } - -#ifdef WITH_THREAD - if (self->threaded && self->thread_id != Tcl_GetCurrentThread() && - !WaitForMainloop(self)) - return NULL; -#endif - - data = PyMem_NEW(PythonCmd_ClientData, 1); - if (!data) - return PyErr_NoMemory(); - Py_INCREF(self); - Py_INCREF(func); - data->self = (PyObject *) self; - data->func = func; -#ifdef WITH_THREAD - if (self->threaded && self->thread_id != Tcl_GetCurrentThread()) { - Tcl_Condition cond = NULL; - CommandEvent *ev = (CommandEvent*)attemptckalloc(sizeof(CommandEvent)); - if (ev == NULL) { - PyErr_NoMemory(); - PyMem_DEL(data); - return NULL; - } - ev->ev.proc = (Tcl_EventProc*)Tkapp_CommandProc; - ev->interp = self->interp; - ev->create = 1; - ev->name = name; - ev->data = (ClientData)data; - ev->status = &err; - ev->done = &cond; - Tkapp_ThreadSend(self, (Tcl_Event*)ev, &cond, &command_mutex); - Tcl_ConditionFinalize(&cond); - } - else -#endif - { - ENTER_TCL - err = Tcl_CreateCommand( - Tkapp_Interp(self), name, PythonCmd, - (ClientData)data, PythonCmdDelete) == NULL; - LEAVE_TCL - } - if (err) { - PyErr_SetString(Tkinter_TclError, "can't create Tcl command"); - PyMem_DEL(data); - return NULL; - } - - Py_RETURN_NONE; -} - - - -/*[clinic input] -_tkinter.tkapp.deletecommand - - name: str - / - -[clinic start generated code]*/ - -static PyObject * -_tkinter_tkapp_deletecommand_impl(TkappObject *self, const char *name) -/*[clinic end generated code: output=a67e8cb5845e0d2d input=53e9952eae1f85f5]*/ -{ - int err; - - CHECK_STRING_LENGTH(name); - -#ifdef WITH_THREAD - if (self->threaded && self->thread_id != Tcl_GetCurrentThread()) { - Tcl_Condition cond = NULL; - CommandEvent *ev; - ev = (CommandEvent*)attemptckalloc(sizeof(CommandEvent)); - if (ev == NULL) { - PyErr_NoMemory(); - return NULL; - } - ev->ev.proc = (Tcl_EventProc*)Tkapp_CommandProc; - ev->interp = self->interp; - ev->create = 0; - ev->name = name; - ev->status = &err; - ev->done = &cond; - Tkapp_ThreadSend(self, (Tcl_Event*)ev, &cond, - &command_mutex); - Tcl_ConditionFinalize(&cond); - } - else -#endif - { - ENTER_TCL - err = Tcl_DeleteCommand(self->interp, name); - LEAVE_TCL - } - if (err == -1) { - PyErr_SetString(Tkinter_TclError, "can't delete Tcl command"); - return NULL; - } - Py_RETURN_NONE; -} - - - -#ifdef HAVE_CREATEFILEHANDLER -/** File Handler **/ - -typedef struct _fhcdata { - PyObject *func; - PyObject *file; - int id; - struct _fhcdata *next; -} FileHandler_ClientData; - -static FileHandler_ClientData *HeadFHCD; - -static FileHandler_ClientData * -NewFHCD(PyObject *func, PyObject *file, int id) -{ - FileHandler_ClientData *p; - p = PyMem_NEW(FileHandler_ClientData, 1); - if (p != NULL) { - Py_XINCREF(func); - Py_XINCREF(file); - p->func = func; - p->file = file; - p->id = id; - p->next = HeadFHCD; - HeadFHCD = p; - } - return p; -} - -static void -DeleteFHCD(int id) -{ - FileHandler_ClientData *p, **pp; - - pp = &HeadFHCD; - while ((p = *pp) != NULL) { - if (p->id == id) { - *pp = p->next; - Py_XDECREF(p->func); - Py_XDECREF(p->file); - PyMem_DEL(p); - } - else - pp = &p->next; - } -} - -static void -FileHandler(ClientData clientData, int mask) -{ - FileHandler_ClientData *data = (FileHandler_ClientData *)clientData; - PyObject *func, *file, *arg, *res; - - ENTER_PYTHON - func = data->func; - file = data->file; - - arg = Py_BuildValue("(Oi)", file, (long) mask); - res = PyEval_CallObject(func, arg); - Py_DECREF(arg); - - if (res == NULL) { - errorInCmd = 1; - PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd); - } - Py_XDECREF(res); - LEAVE_PYTHON -} - -/*[clinic input] -_tkinter.tkapp.createfilehandler - - file: object - mask: int - func: object - / - -[clinic start generated code]*/ - -static PyObject * -_tkinter_tkapp_createfilehandler_impl(TkappObject *self, PyObject *file, - int mask, PyObject *func) -/*[clinic end generated code: output=f73ce82de801c353 input=84943a5286e47947]*/ -{ - FileHandler_ClientData *data; - int tfile; - - CHECK_TCL_APPARTMENT; - - tfile = PyObject_AsFileDescriptor(file); - if (tfile < 0) - return NULL; - if (!PyCallable_Check(func)) { - PyErr_SetString(PyExc_TypeError, "bad argument list"); - return NULL; - } - - data = NewFHCD(func, file, tfile); - if (data == NULL) - return NULL; - - /* Ought to check for null Tcl_File object... */ - ENTER_TCL - Tcl_CreateFileHandler(tfile, mask, FileHandler, (ClientData) data); - LEAVE_TCL - Py_RETURN_NONE; -} - -/*[clinic input] -_tkinter.tkapp.deletefilehandler - - file: object - / - -[clinic start generated code]*/ - -static PyObject * -_tkinter_tkapp_deletefilehandler(TkappObject *self, PyObject *file) -/*[clinic end generated code: output=b53cc96ebf9476fd input=abbec19d66312e2a]*/ -{ - int tfile; - - CHECK_TCL_APPARTMENT; - - tfile = PyObject_AsFileDescriptor(file); - if (tfile < 0) - return NULL; - - DeleteFHCD(tfile); - - /* Ought to check for null Tcl_File object... */ - ENTER_TCL - Tcl_DeleteFileHandler(tfile); - LEAVE_TCL - Py_RETURN_NONE; -} -#endif /* HAVE_CREATEFILEHANDLER */ - - -/**** Tktt Object (timer token) ****/ - -static PyObject *Tktt_Type; - -typedef struct { - PyObject_HEAD - Tcl_TimerToken token; - PyObject *func; -} TkttObject; - -/*[clinic input] -_tkinter.tktimertoken.deletetimerhandler - -[clinic start generated code]*/ - -static PyObject * -_tkinter_tktimertoken_deletetimerhandler_impl(TkttObject *self) -/*[clinic end generated code: output=bd7fe17f328cfa55 input=40bd070ff85f5cf3]*/ -{ - TkttObject *v = self; - PyObject *func = v->func; - - if (v->token != NULL) { - Tcl_DeleteTimerHandler(v->token); - v->token = NULL; - } - if (func != NULL) { - v->func = NULL; - Py_DECREF(func); - Py_DECREF(v); /* See Tktt_New() */ - } - Py_RETURN_NONE; -} - -static TkttObject * -Tktt_New(PyObject *func) -{ - TkttObject *v; - - v = PyObject_New(TkttObject, (PyTypeObject *) Tktt_Type); - if (v == NULL) - return NULL; - Py_INCREF(Tktt_Type); - - Py_INCREF(func); - v->token = NULL; - v->func = func; - - /* Extra reference, deleted when called or when handler is deleted */ - Py_INCREF(v); - return v; -} - -static void -Tktt_Dealloc(PyObject *self) -{ - TkttObject *v = (TkttObject *)self; - PyObject *func = v->func; - PyObject *tp = (PyObject *) Py_TYPE(self); - - Py_XDECREF(func); - - PyObject_Del(self); - Py_DECREF(tp); -} - -static PyObject * -Tktt_Repr(PyObject *self) -{ - TkttObject *v = (TkttObject *)self; - return PyUnicode_FromFormat("", - v, - v->func == NULL ? ", handler deleted" : ""); -} - -/** Timer Handler **/ - -static void -TimerHandler(ClientData clientData) -{ - TkttObject *v = (TkttObject *)clientData; - PyObject *func = v->func; - PyObject *res; - - if (func == NULL) - return; - - v->func = NULL; - - ENTER_PYTHON - - res = PyEval_CallObject(func, NULL); - Py_DECREF(func); - Py_DECREF(v); /* See Tktt_New() */ - - if (res == NULL) { - errorInCmd = 1; - PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd); - } - else - Py_DECREF(res); - - LEAVE_PYTHON -} - -/*[clinic input] -_tkinter.tkapp.createtimerhandler - - milliseconds: int - func: object - / - -[clinic start generated code]*/ - -static PyObject * -_tkinter_tkapp_createtimerhandler_impl(TkappObject *self, int milliseconds, - PyObject *func) -/*[clinic end generated code: output=2da5959b9d031911 input=ba6729f32f0277a5]*/ -{ - TkttObject *v; - - if (!PyCallable_Check(func)) { - PyErr_SetString(PyExc_TypeError, "bad argument list"); - return NULL; - } - - CHECK_TCL_APPARTMENT; - - v = Tktt_New(func); - if (v) { - v->token = Tcl_CreateTimerHandler(milliseconds, TimerHandler, - (ClientData)v); - } - - return (PyObject *) v; -} - - -/** Event Loop **/ - -/*[clinic input] -_tkinter.tkapp.mainloop - - threshold: int = 0 - / - -[clinic start generated code]*/ - -static PyObject * -_tkinter_tkapp_mainloop_impl(TkappObject *self, int threshold) -/*[clinic end generated code: output=0ba8eabbe57841b0 input=036bcdcf03d5eca0]*/ -{ -#ifdef WITH_THREAD - PyThreadState *tstate = PyThreadState_Get(); -#endif - - CHECK_TCL_APPARTMENT; - self->dispatching = 1; - - quitMainLoop = 0; - while (Tk_GetNumMainWindows() > threshold && - !quitMainLoop && - !errorInCmd) - { - int result; - -#ifdef WITH_THREAD - if (self->threaded) { - /* Allow other Python threads to run. */ - ENTER_TCL - result = Tcl_DoOneEvent(0); - LEAVE_TCL - } - else { - Py_BEGIN_ALLOW_THREADS - if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1); - tcl_tstate = tstate; - result = Tcl_DoOneEvent(TCL_DONT_WAIT); - tcl_tstate = NULL; - if(tcl_lock)PyThread_release_lock(tcl_lock); - if (result == 0) - Sleep(Tkinter_busywaitinterval); - Py_END_ALLOW_THREADS - } -#else - result = Tcl_DoOneEvent(0); -#endif - - if (PyErr_CheckSignals() != 0) { - self->dispatching = 0; - return NULL; - } - if (result < 0) - break; - } - self->dispatching = 0; - quitMainLoop = 0; - - if (errorInCmd) { - errorInCmd = 0; - PyErr_Restore(excInCmd, valInCmd, trbInCmd); - excInCmd = valInCmd = trbInCmd = NULL; - return NULL; - } - Py_RETURN_NONE; -} - -/*[clinic input] -_tkinter.tkapp.dooneevent - - flags: int = 0 - / - -[clinic start generated code]*/ - -static PyObject * -_tkinter_tkapp_dooneevent_impl(TkappObject *self, int flags) -/*[clinic end generated code: output=27c6b2aa464cac29 input=6542b928e364b793]*/ -{ - int rv; - - ENTER_TCL - rv = Tcl_DoOneEvent(flags); - LEAVE_TCL - return PyLong_FromLong(rv); -} - -/*[clinic input] -_tkinter.tkapp.quit -[clinic start generated code]*/ - -static PyObject * -_tkinter_tkapp_quit_impl(TkappObject *self) -/*[clinic end generated code: output=7f21eeff481f754f input=e03020dc38aff23c]*/ -{ - quitMainLoop = 1; - Py_RETURN_NONE; -} - -/*[clinic input] -_tkinter.tkapp.interpaddr -[clinic start generated code]*/ - -static PyObject * -_tkinter_tkapp_interpaddr_impl(TkappObject *self) -/*[clinic end generated code: output=6caaae3273b3c95a input=2dd32cbddb55a111]*/ -{ - return PyLong_FromVoidPtr(Tkapp_Interp(self)); -} - -/*[clinic input] -_tkinter.tkapp.loadtk -[clinic start generated code]*/ - -static PyObject * -_tkinter_tkapp_loadtk_impl(TkappObject *self) -/*[clinic end generated code: output=e9e10a954ce46d2a input=b5e82afedd6354f0]*/ -{ - Tcl_Interp *interp = Tkapp_Interp(self); - const char * _tk_exists = NULL; - int err; - -#ifdef TKINTER_PROTECT_LOADTK - /* Up to Tk 8.4.13, Tk_Init deadlocks on the second call when the - * first call failed. - * To avoid the deadlock, we just refuse the second call through - * a static variable. - */ - if (tk_load_failed) { - PyErr_SetString(Tkinter_TclError, TKINTER_LOADTK_ERRMSG); - return NULL; - } -#endif - - /* We want to guard against calling Tk_Init() multiple times */ - CHECK_TCL_APPARTMENT; - ENTER_TCL - err = Tcl_Eval(Tkapp_Interp(self), "info exists tk_version"); - ENTER_OVERLAP - if (err == TCL_ERROR) { - /* This sets an exception, but we cannot return right - away because we need to exit the overlap first. */ - Tkinter_Error((PyObject *)self); - } else { - _tk_exists = Tkapp_Result(self); - } - LEAVE_OVERLAP_TCL - if (err == TCL_ERROR) { - return NULL; - } - if (_tk_exists == NULL || strcmp(_tk_exists, "1") != 0) { - if (Tk_Init(interp) == TCL_ERROR) { - PyErr_SetString(Tkinter_TclError, - Tcl_GetStringResult(Tkapp_Interp(self))); -#ifdef TKINTER_PROTECT_LOADTK - tk_load_failed = 1; -#endif - return NULL; - } - } - Py_RETURN_NONE; -} - -static PyObject * -Tkapp_WantObjects(PyObject *self, PyObject *args) -{ - - int wantobjects = -1; - if (!PyArg_ParseTuple(args, "|i:wantobjects", &wantobjects)) - return NULL; - if (wantobjects == -1) - return PyBool_FromLong(((TkappObject*)self)->wantobjects); - ((TkappObject*)self)->wantobjects = wantobjects; - - Py_RETURN_NONE; -} - -/*[clinic input] -_tkinter.tkapp.willdispatch - -[clinic start generated code]*/ - -static PyObject * -_tkinter_tkapp_willdispatch_impl(TkappObject *self) -/*[clinic end generated code: output=0e3f46d244642155 input=d88f5970843d6dab]*/ -{ - self->dispatching = 1; - - Py_RETURN_NONE; -} - - -/**** Tkapp Type Methods ****/ - -static void -Tkapp_Dealloc(PyObject *self) -{ - PyObject *tp = (PyObject *) Py_TYPE(self); - /*CHECK_TCL_APPARTMENT;*/ - ENTER_TCL - Tcl_DeleteInterp(Tkapp_Interp(self)); - LEAVE_TCL - PyObject_Del(self); - Py_DECREF(tp); - DisableEventHook(); -} - - - -/**** Tkinter Module ****/ - -typedef struct { - PyObject* tuple; - Py_ssize_t size; /* current size */ - Py_ssize_t maxsize; /* allocated size */ -} FlattenContext; - -static int -_bump(FlattenContext* context, Py_ssize_t size) -{ - /* expand tuple to hold (at least) size new items. - return true if successful, false if an exception was raised */ - - Py_ssize_t maxsize = context->maxsize * 2; /* never overflows */ - - if (maxsize < context->size + size) - maxsize = context->size + size; /* never overflows */ - - context->maxsize = maxsize; - - return _PyTuple_Resize(&context->tuple, maxsize) >= 0; -} - -static int -_flatten1(FlattenContext* context, PyObject* item, int depth) -{ - /* add tuple or list to argument tuple (recursively) */ - - Py_ssize_t i, size; - - if (depth > 1000) { - PyErr_SetString(PyExc_ValueError, - "nesting too deep in _flatten"); - return 0; - } else if (PyTuple_Check(item) || PyList_Check(item)) { - size = PySequence_Fast_GET_SIZE(item); - /* preallocate (assume no nesting) */ - if (context->size + size > context->maxsize && - !_bump(context, size)) - return 0; - /* copy items to output tuple */ - for (i = 0; i < size; i++) { - PyObject *o = PySequence_Fast_GET_ITEM(item, i); - if (PyList_Check(o) || PyTuple_Check(o)) { - if (!_flatten1(context, o, depth + 1)) - return 0; - } else if (o != Py_None) { - if (context->size + 1 > context->maxsize && - !_bump(context, 1)) - return 0; - Py_INCREF(o); - PyTuple_SET_ITEM(context->tuple, - context->size++, o); - } - } - } else { - PyErr_SetString(PyExc_TypeError, "argument must be sequence"); - return 0; - } - return 1; -} - -/*[clinic input] -_tkinter._flatten - - item: object - / - -[clinic start generated code]*/ - -static PyObject * -_tkinter__flatten(PyObject *module, PyObject *item) -/*[clinic end generated code: output=cad02a3f97f29862 input=6b9c12260aa1157f]*/ -{ - FlattenContext context; - - context.maxsize = PySequence_Size(item); - if (context.maxsize < 0) - return NULL; - if (context.maxsize == 0) - return PyTuple_New(0); - - context.tuple = PyTuple_New(context.maxsize); - if (!context.tuple) - return NULL; - - context.size = 0; - - if (!_flatten1(&context, item,0)) - return NULL; - - if (_PyTuple_Resize(&context.tuple, context.size)) - return NULL; - - return context.tuple; -} - -/*[clinic input] -_tkinter.create - - screenName: str(accept={str, NoneType}) = NULL - baseName: str = NULL - className: str = "Tk" - interactive: int(c_default="0") = False - wantobjects: int(c_default="0") = False - wantTk: int(c_default="1") = True - if false, then Tk_Init() doesn't get called - sync: int(c_default="0") = False - if true, then pass -sync to wish - use: str(accept={str, NoneType}) = NULL - if not None, then pass -use to wish - / - -[clinic start generated code]*/ - -static PyObject * -_tkinter_create_impl(PyObject *module, const char *screenName, - const char *baseName, const char *className, - int interactive, int wantobjects, int wantTk, int sync, - const char *use) -/*[clinic end generated code: output=e3315607648e6bb4 input=0d522aad1cb0ca0e]*/ -{ - /* XXX baseName is not used anymore; - * try getting rid of it. */ - CHECK_STRING_LENGTH(screenName); - CHECK_STRING_LENGTH(baseName); - CHECK_STRING_LENGTH(className); - CHECK_STRING_LENGTH(use); - - return (PyObject *) Tkapp_New(screenName, className, - interactive, wantobjects, wantTk, - sync, use); -} - -/*[clinic input] -_tkinter.setbusywaitinterval - - new_val: int - / - -Set the busy-wait interval in milliseconds between successive calls to Tcl_DoOneEvent in a threaded Python interpreter. - -It should be set to a divisor of the maximum time between frames in an animation. -[clinic start generated code]*/ - -static PyObject * -_tkinter_setbusywaitinterval_impl(PyObject *module, int new_val) -/*[clinic end generated code: output=42bf7757dc2d0ab6 input=deca1d6f9e6dae47]*/ -{ - if (new_val < 0) { - PyErr_SetString(PyExc_ValueError, - "busywaitinterval must be >= 0"); - return NULL; - } - Tkinter_busywaitinterval = new_val; - Py_RETURN_NONE; -} - -/*[clinic input] -_tkinter.getbusywaitinterval -> int - -Return the current busy-wait interval between successive calls to Tcl_DoOneEvent in a threaded Python interpreter. -[clinic start generated code]*/ - -static int -_tkinter_getbusywaitinterval_impl(PyObject *module) -/*[clinic end generated code: output=23b72d552001f5c7 input=a695878d2d576a84]*/ -{ - return Tkinter_busywaitinterval; -} - -#include "third_party/python/Modules/clinic/_tkinter.inc" - -static PyMethodDef Tktt_methods[] = -{ - _TKINTER_TKTIMERTOKEN_DELETETIMERHANDLER_METHODDEF - {NULL, NULL} -}; - -static PyType_Slot Tktt_Type_slots[] = { - {Py_tp_dealloc, Tktt_Dealloc}, - {Py_tp_repr, Tktt_Repr}, - {Py_tp_methods, Tktt_methods}, - {0, 0} -}; - -static PyType_Spec Tktt_Type_spec = { - "_tkinter.tktimertoken", - sizeof(TkttObject), - 0, - Py_TPFLAGS_DEFAULT, - Tktt_Type_slots, -}; - - -/**** Tkapp Method List ****/ - -static PyMethodDef Tkapp_methods[] = -{ - _TKINTER_TKAPP_WILLDISPATCH_METHODDEF - {"wantobjects", Tkapp_WantObjects, METH_VARARGS}, - {"call", Tkapp_Call, METH_VARARGS}, - _TKINTER_TKAPP_EVAL_METHODDEF - _TKINTER_TKAPP_EVALFILE_METHODDEF - _TKINTER_TKAPP_RECORD_METHODDEF - _TKINTER_TKAPP_ADDERRORINFO_METHODDEF - {"setvar", Tkapp_SetVar, METH_VARARGS}, - {"globalsetvar", Tkapp_GlobalSetVar, METH_VARARGS}, - {"getvar", Tkapp_GetVar, METH_VARARGS}, - {"globalgetvar", Tkapp_GlobalGetVar, METH_VARARGS}, - {"unsetvar", Tkapp_UnsetVar, METH_VARARGS}, - {"globalunsetvar", Tkapp_GlobalUnsetVar, METH_VARARGS}, - _TKINTER_TKAPP_GETINT_METHODDEF - _TKINTER_TKAPP_GETDOUBLE_METHODDEF - _TKINTER_TKAPP_GETBOOLEAN_METHODDEF - _TKINTER_TKAPP_EXPRSTRING_METHODDEF - _TKINTER_TKAPP_EXPRLONG_METHODDEF - _TKINTER_TKAPP_EXPRDOUBLE_METHODDEF - _TKINTER_TKAPP_EXPRBOOLEAN_METHODDEF - _TKINTER_TKAPP_SPLITLIST_METHODDEF - _TKINTER_TKAPP_SPLIT_METHODDEF - _TKINTER_TKAPP_CREATECOMMAND_METHODDEF - _TKINTER_TKAPP_DELETECOMMAND_METHODDEF - _TKINTER_TKAPP_CREATEFILEHANDLER_METHODDEF - _TKINTER_TKAPP_DELETEFILEHANDLER_METHODDEF - _TKINTER_TKAPP_CREATETIMERHANDLER_METHODDEF - _TKINTER_TKAPP_MAINLOOP_METHODDEF - _TKINTER_TKAPP_DOONEEVENT_METHODDEF - _TKINTER_TKAPP_QUIT_METHODDEF - _TKINTER_TKAPP_INTERPADDR_METHODDEF - _TKINTER_TKAPP_LOADTK_METHODDEF - {NULL, NULL} -}; - -static PyType_Slot Tkapp_Type_slots[] = { - {Py_tp_dealloc, Tkapp_Dealloc}, - {Py_tp_methods, Tkapp_methods}, - {0, 0} -}; - - -static PyType_Spec Tkapp_Type_spec = { - "_tkinter.tkapp", - sizeof(TkappObject), - 0, - Py_TPFLAGS_DEFAULT, - Tkapp_Type_slots, -}; - -static PyMethodDef moduleMethods[] = -{ - _TKINTER__FLATTEN_METHODDEF - _TKINTER_CREATE_METHODDEF - _TKINTER_SETBUSYWAITINTERVAL_METHODDEF - _TKINTER_GETBUSYWAITINTERVAL_METHODDEF - {NULL, NULL} -}; - -#ifdef WAIT_FOR_STDIN - -static int stdin_ready = 0; - -#ifndef MS_WINDOWS -static void -MyFileProc(void *clientData, int mask) -{ - stdin_ready = 1; -} -#endif - -#ifdef WITH_THREAD -static PyThreadState *event_tstate = NULL; -#endif - -static int -EventHook(void) -{ -#ifndef MS_WINDOWS - int tfile; -#endif -#ifdef WITH_THREAD - PyEval_RestoreThread(event_tstate); -#endif - stdin_ready = 0; - errorInCmd = 0; -#ifndef MS_WINDOWS - tfile = fileno(stdin); - Tcl_CreateFileHandler(tfile, TCL_READABLE, MyFileProc, NULL); -#endif - while (!errorInCmd && !stdin_ready) { - int result; -#ifdef MS_WINDOWS - if (_kbhit()) { - stdin_ready = 1; - break; - } -#endif -#if defined(WITH_THREAD) || defined(MS_WINDOWS) - Py_BEGIN_ALLOW_THREADS - if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1); - tcl_tstate = event_tstate; - - result = Tcl_DoOneEvent(TCL_DONT_WAIT); - - tcl_tstate = NULL; - if(tcl_lock)PyThread_release_lock(tcl_lock); - if (result == 0) - Sleep(Tkinter_busywaitinterval); - Py_END_ALLOW_THREADS -#else - result = Tcl_DoOneEvent(0); -#endif - - if (result < 0) - break; - } -#ifndef MS_WINDOWS - Tcl_DeleteFileHandler(tfile); -#endif - if (errorInCmd) { - errorInCmd = 0; - PyErr_Restore(excInCmd, valInCmd, trbInCmd); - excInCmd = valInCmd = trbInCmd = NULL; - PyErr_Print(); - } -#ifdef WITH_THREAD - PyEval_SaveThread(); -#endif - return 0; -} - -#endif - -static void -EnableEventHook(void) -{ -#ifdef WAIT_FOR_STDIN - if (PyOS_InputHook == NULL) { -#ifdef WITH_THREAD - event_tstate = PyThreadState_Get(); -#endif - PyOS_InputHook = EventHook; - } -#endif -} - -static void -DisableEventHook(void) -{ -#ifdef WAIT_FOR_STDIN - if (Tk_GetNumMainWindows() == 0 && PyOS_InputHook == EventHook) { - PyOS_InputHook = NULL; - } -#endif -} - - -static struct PyModuleDef _tkintermodule = { - PyModuleDef_HEAD_INIT, - "_tkinter", - NULL, - -1, - moduleMethods, - NULL, - NULL, - NULL, - NULL -}; - -PyMODINIT_FUNC -PyInit__tkinter(void) -{ - PyObject *m, *uexe, *cexe, *o; - -#ifdef WITH_THREAD - tcl_lock = PyThread_allocate_lock(); - if (tcl_lock == NULL) - return NULL; -#endif - - m = PyModule_Create(&_tkintermodule); - if (m == NULL) - return NULL; - - o = PyErr_NewException("_tkinter.TclError", NULL, NULL); - if (o == NULL) { - Py_DECREF(m); - return NULL; - } - Py_INCREF(o); - if (PyModule_AddObject(m, "TclError", o)) { - Py_DECREF(o); - Py_DECREF(m); - return NULL; - } - Tkinter_TclError = o; - - if (PyModule_AddIntConstant(m, "READABLE", TCL_READABLE)) { - Py_DECREF(m); - return NULL; - } - if (PyModule_AddIntConstant(m, "WRITABLE", TCL_WRITABLE)) { - Py_DECREF(m); - return NULL; - } - if (PyModule_AddIntConstant(m, "EXCEPTION", TCL_EXCEPTION)) { - Py_DECREF(m); - return NULL; - } - if (PyModule_AddIntConstant(m, "WINDOW_EVENTS", TCL_WINDOW_EVENTS)) { - Py_DECREF(m); - return NULL; - } - if (PyModule_AddIntConstant(m, "FILE_EVENTS", TCL_FILE_EVENTS)) { - Py_DECREF(m); - return NULL; - } - if (PyModule_AddIntConstant(m, "TIMER_EVENTS", TCL_TIMER_EVENTS)) { - Py_DECREF(m); - return NULL; - } - if (PyModule_AddIntConstant(m, "IDLE_EVENTS", TCL_IDLE_EVENTS)) { - Py_DECREF(m); - return NULL; - } - if (PyModule_AddIntConstant(m, "ALL_EVENTS", TCL_ALL_EVENTS)) { - Py_DECREF(m); - return NULL; - } - if (PyModule_AddIntConstant(m, "DONT_WAIT", TCL_DONT_WAIT)) { - Py_DECREF(m); - return NULL; - } - if (PyModule_AddStringConstant(m, "TK_VERSION", TK_VERSION)) { - Py_DECREF(m); - return NULL; - } - if (PyModule_AddStringConstant(m, "TCL_VERSION", TCL_VERSION)) { - Py_DECREF(m); - return NULL; - } - - o = PyType_FromSpec(&Tkapp_Type_spec); - if (o == NULL) { - Py_DECREF(m); - return NULL; - } - ((PyTypeObject *)o)->tp_new = NULL; - if (PyModule_AddObject(m, "TkappType", o)) { - Py_DECREF(o); - Py_DECREF(m); - return NULL; - } - Tkapp_Type = o; - - o = PyType_FromSpec(&Tktt_Type_spec); - if (o == NULL) { - Py_DECREF(m); - return NULL; - } - ((PyTypeObject *)o)->tp_new = NULL; - if (PyModule_AddObject(m, "TkttType", o)) { - Py_DECREF(o); - Py_DECREF(m); - return NULL; - } - Tktt_Type = o; - - o = PyType_FromSpec(&PyTclObject_Type_spec); - if (o == NULL) { - Py_DECREF(m); - return NULL; - } - ((PyTypeObject *)o)->tp_new = NULL; - if (PyModule_AddObject(m, "Tcl_Obj", o)) { - Py_DECREF(o); - Py_DECREF(m); - return NULL; - } - PyTclObject_Type = o; - -#ifdef TK_AQUA - /* Tk_MacOSXSetupTkNotifier must be called before Tcl's subsystems - * start waking up. Note that Tcl_FindExecutable will do this, this - * code must be above it! The original warning from - * tkMacOSXAppInit.c is copied below. - * - * NB - You have to swap in the Tk Notifier BEFORE you start up the - * Tcl interpreter for now. It probably should work to do this - * in the other order, but for now it doesn't seem to. - * - */ - Tk_MacOSXSetupTkNotifier(); -#endif - - - /* This helps the dynamic loader; in Unicode aware Tcl versions - it also helps Tcl find its encodings. */ - uexe = PyUnicode_FromWideChar(Py_GetProgramName(), -1); - if (uexe) { - cexe = PyUnicode_EncodeFSDefault(uexe); - if (cexe) { -#ifdef MS_WINDOWS - int set_var = 0; - PyObject *str_path; - wchar_t *wcs_path; - DWORD ret; - - ret = GetEnvironmentVariableW(L"TCL_LIBRARY", NULL, 0); - - if (!ret && GetLastError() == ERROR_ENVVAR_NOT_FOUND) { - str_path = _get_tcl_lib_path(); - if (str_path == NULL && PyErr_Occurred()) { - return NULL; - } - if (str_path != NULL) { - wcs_path = _PyUnicode_AsWideCharString(str_path); - if (wcs_path == NULL) { - return NULL; - } - SetEnvironmentVariableW(L"TCL_LIBRARY", wcs_path); - set_var = 1; - } - } - - Tcl_FindExecutable(PyBytes_AS_STRING(cexe)); - - if (set_var) { - SetEnvironmentVariableW(L"TCL_LIBRARY", NULL); - PyMem_Free(wcs_path); - } -#else - Tcl_FindExecutable(PyBytes_AS_STRING(cexe)); -#endif /* MS_WINDOWS */ - } - Py_XDECREF(cexe); - Py_DECREF(uexe); - } - - if (PyErr_Occurred()) { - Py_DECREF(m); - return NULL; - } - -#if 0 - /* This was not a good idea; through bindings, - Tcl_Finalize() may invoke Python code but at that point the - interpreter and thread state have already been destroyed! */ - Py_AtExit(Tcl_Finalize); -#endif - return m; -} diff --git a/third_party/python/Modules/_tracemalloc.c b/third_party/python/Modules/_tracemalloc.c index faddec677..da772251a 100644 --- a/third_party/python/Modules/_tracemalloc.c +++ b/third_party/python/Modules/_tracemalloc.c @@ -1,9 +1,26 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Modules/hashtable.h" +#include "libc/errno.h" +#include "libc/fmt/conv.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/fileutils.h" #include "third_party/python/Include/frameobject.h" -#include "third_party/python/Include/pythread.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" #include "third_party/python/Include/osdefs.h" +#include "third_party/python/Include/pydebug.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pyhash.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pythread.h" +#include "third_party/python/Include/sysmodule.h" +#include "third_party/python/Include/traceback.h" +#include "third_party/python/Include/tupleobject.h" +#include "third_party/python/Include/unicodeobject.h" +#include "third_party/python/Modules/hashtable.h" +/* clang-format off */ /* Trace memory blocks allocated by PyMem_RawMalloc() */ #define TRACE_RAW_MALLOC diff --git a/third_party/python/Modules/_weakref.c b/third_party/python/Modules/_weakref.c index f49c78dec..3a497c0c3 100644 --- a/third_party/python/Modules/_weakref.c +++ b/third_party/python/Modules/_weakref.c @@ -1,5 +1,12 @@ +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/weakrefobject.h" +#include "third_party/python/Modules/clinic/_weakref.inc" /* clang-format off */ -#include "third_party/python/Include/Python.h" #define GET_WEAKREFS_LISTPTR(o) \ ((PyWeakReference **) PyObject_GET_WEAKREFS_LISTPTR(o)) @@ -9,8 +16,6 @@ module _weakref [clinic start generated code]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=ffec73b85846596d]*/ -#include "third_party/python/Modules/clinic/_weakref.inc" - /*[clinic input] _weakref.getweakrefcount -> Py_ssize_t diff --git a/third_party/python/Modules/_winapi.c b/third_party/python/Modules/_winapi.c index 558dfbc3c..f4a284434 100644 --- a/third_party/python/Modules/_winapi.c +++ b/third_party/python/Modules/_winapi.c @@ -35,13 +35,9 @@ /* Licensed to PSF under a Contributor Agreement. */ /* See http://www.python.org/2.4/license for licensing details. */ -#include "Python.h" -#include "structmember.h" - -#define WINDOWS_LEAN_AND_MEAN -#include "windows.h" -#include -#include "winreparse.h" +#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Modules/winreparse.h" #if defined(MS_WIN32) && !defined(MS_WIN64) #define HANDLE_TO_PYNUM(handle) \ @@ -349,8 +345,8 @@ new_overlapped(HANDLE handle) self->read_buffer = NULL; self->pending = 0; self->completed = 0; - memset(&self->overlapped, 0, sizeof(OVERLAPPED)); - memset(&self->write_buffer, 0, sizeof(Py_buffer)); + bzero(&self->overlapped, sizeof(OVERLAPPED)); + bzero(&self->write_buffer, sizeof(Py_buffer)); /* Manual reset, initially non-signalled */ self->overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); return self; @@ -552,7 +548,7 @@ _winapi_CreateJunction_impl(PyObject *module, LPWSTR src_path, if (rdb == NULL) goto cleanup; - memset(rdb, 0, rdb_size); + bzero(rdb, rdb_size); rdb->ReparseTag = IO_REPARSE_TAG_MOUNT_POINT; rdb->ReparseDataLength = rdb_size - _Py_REPARSE_DATA_BUFFER_HEADER_SIZE; rdb->MountPointReparseBuffer.SubstituteNameOffset = 0; diff --git a/third_party/python/Modules/addrinfo.h b/third_party/python/Modules/addrinfo.h deleted file mode 100644 index c95d250ca..000000000 --- a/third_party/python/Modules/addrinfo.h +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the project nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#define HAVE_GETADDRINFO 1 -#define HAVE_GETNAMEINFO 1 -#ifndef HAVE_GETADDRINFO - -/* - * Error return codes from getaddrinfo() - */ -#ifdef EAI_ADDRFAMILY -/* If this is defined, there is a conflicting implementation - in the C library, which can't be used for some reason. - Make sure it won't interfere with this emulation. */ - -#undef EAI_ADDRFAMILY -#undef EAI_AGAIN -#undef EAI_BADFLAGS -#undef EAI_FAIL -#undef EAI_FAMILY -#undef EAI_MEMORY -#undef EAI_NODATA -#undef EAI_NONAME -#undef EAI_SERVICE -#undef EAI_SOCKTYPE -#undef EAI_SYSTEM -#undef EAI_BADHINTS -#undef EAI_PROTOCOL -#undef EAI_MAX -#undef getaddrinfo -#define getaddrinfo fake_getaddrinfo -#endif /* EAI_ADDRFAMILY */ - -#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ -#define EAI_AGAIN 2 /* temporary failure in name resolution */ -#define EAI_BADFLAGS 3 /* invalid value for ai_flags */ -#define EAI_FAIL 4 /* non-recoverable failure in name resolution */ -#define EAI_FAMILY 5 /* ai_family not supported */ -#define EAI_MEMORY 6 /* memory allocation failure */ -#define EAI_NODATA 7 /* no address associated with hostname */ -#define EAI_NONAME 8 /* hostname nor servname provided, or not known */ -#define EAI_SERVICE 9 /* servname not supported for ai_socktype */ -#define EAI_SOCKTYPE 10 /* ai_socktype not supported */ -#define EAI_SYSTEM 11 /* system error returned in errno */ -#define EAI_BADHINTS 12 -#define EAI_PROTOCOL 13 -#define EAI_MAX 14 - -/* - * Flag values for getaddrinfo() - */ -#ifdef AI_PASSIVE -#undef AI_PASSIVE -#undef AI_CANONNAME -#undef AI_NUMERICHOST -#undef AI_MASK -#undef AI_ALL -#undef AI_V4MAPPED_CFG -#undef AI_ADDRCONFIG -#undef AI_V4MAPPED -#undef AI_DEFAULT -#endif /* AI_PASSIVE */ - -#define AI_PASSIVE 0x00000001 /* get address to use bind() */ -#define AI_CANONNAME 0x00000002 /* fill ai_canonname */ -#define AI_NUMERICHOST 0x00000004 /* prevent name resolution */ -/* valid flags for addrinfo */ -#define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST) - -#define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */ -#define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */ -#define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */ -#define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */ -/* special recommended flags for getipnodebyname */ -#define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG) - -#endif /* !HAVE_GETADDRINFO */ - -#ifndef HAVE_GETNAMEINFO - -/* - * Constants for getnameinfo() - */ -#ifndef NI_MAXHOST -#define NI_MAXHOST 1025 -#define NI_MAXSERV 32 -#endif /* !NI_MAXHOST */ - -/* - * Flag values for getnameinfo() - */ -#ifndef NI_NOFQDN -#define NI_NOFQDN 0x00000001 -#define NI_NUMERICHOST 0x00000002 -#define NI_NAMEREQD 0x00000004 -#define NI_NUMERICSERV 0x00000008 -#define NI_DGRAM 0x00000010 -#endif /* !NI_NOFQDN */ - -#endif /* !HAVE_GETNAMEINFO */ - -#ifndef HAVE_ADDRINFO -struct addrinfo { - int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ - int ai_family; /* PF_xxx */ - int ai_socktype; /* SOCK_xxx */ - int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ - size_t ai_addrlen; /* length of ai_addr */ - char *ai_canonname; /* canonical name for hostname */ - struct sockaddr *ai_addr; /* binary address */ - struct addrinfo *ai_next; /* next structure in linked list */ -}; -#endif /* !HAVE_ADDRINFO */ - -#ifndef HAVE_SOCKADDR_STORAGE -/* - * RFC 2553: protocol-independent placeholder for socket addresses - */ -#define _SS_MAXSIZE 128 -#define _SS_ALIGNSIZE (sizeof(long long)) -#define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(u_char) * 2) -#define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(u_char) * 2 - \ - _SS_PAD1SIZE - _SS_ALIGNSIZE) - -struct sockaddr_storage { -#ifdef HAVE_SOCKADDR_SA_LEN - unsigned char ss_len; /* address length */ - unsigned char ss_family; /* address family */ -#else - unsigned short ss_family; /* address family */ -#endif /* HAVE_SOCKADDR_SA_LEN */ - char __ss_pad1[_SS_PAD1SIZE]; - long long __ss_align; /* force desired structure storage alignment */ - char __ss_pad2[_SS_PAD2SIZE]; -}; -#endif /* !HAVE_SOCKADDR_STORAGE */ - -#ifdef __cplusplus -extern "C" { -#endif -extern void freehostent(struct hostent *); -#ifdef __cplusplus -} -#endif diff --git a/third_party/python/Modules/arraymodule.c b/third_party/python/Modules/arraymodule.c index 75fe68e69..bbffdc312 100644 --- a/third_party/python/Modules/arraymodule.c +++ b/third_party/python/Modules/arraymodule.c @@ -1,13 +1,27 @@ +#define PY_SSIZE_T_CLEAN +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/bytearrayobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/sliceobject.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/unicodeobject.h" +#include "third_party/python/Include/warnings.h" /* clang-format off */ + /* Array object implementation */ /* An array is a uniform list -- all items have the same type. The item type is restricted to simple C types like int or float */ -#define PY_SSIZE_T_CLEAN -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" - /*[clinic input] module array [clinic start generated code]*/ diff --git a/third_party/python/Modules/atexitmodule.c b/third_party/python/Modules/atexitmodule.c index c807e5fd1..c84722065 100644 --- a/third_party/python/Modules/atexitmodule.c +++ b/third_party/python/Modules/atexitmodule.c @@ -1,4 +1,18 @@ +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/moduleobject.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pgenheaders.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pylifecycle.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pystate.h" +#include "third_party/python/Include/pythonrun.h" /* clang-format off */ + /* * atexit - allow programmer to define multiple exit functions to be executed * upon normal program termination. @@ -7,8 +21,6 @@ + Copyright 2007 Python Software Foundation. */ -#include "third_party/python/Include/Python.h" - /* Forward declaration (for atexit_cleanup) */ static PyObject *atexit_clear(PyObject*, PyObject*); /* Forward declaration of module object */ diff --git a/third_party/python/Modules/audioop.c b/third_party/python/Modules/audioop.c index 08df33c72..d58741f9d 100644 --- a/third_party/python/Modules/audioop.c +++ b/third_party/python/Modules/audioop.c @@ -1,11 +1,18 @@ +#define PY_SSIZE_T_CLEAN +#include "libc/math.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/tupleobject.h" /* clang-format off */ /* audioopmodule - Module to detect peak values in arrays */ -#define PY_SSIZE_T_CLEAN - -#include "third_party/python/Include/Python.h" - #if defined(__CHAR_UNSIGNED__) #if defined(signed) /* This module currently does not work on systems where only unsigned diff --git a/third_party/python/Modules/binascii.c b/third_party/python/Modules/binascii.c index ac6933d38..72e6b55e5 100644 --- a/third_party/python/Modules/binascii.c +++ b/third_party/python/Modules/binascii.c @@ -1,3 +1,16 @@ +#define PY_SSIZE_T_CLEAN +#include "libc/assert.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/pyctype.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pystrhex.h" +#include "third_party/python/Include/unicodeobject.h" +#include "third_party/zlib/zlib.h" /* clang-format off */ /* ** Routines to represent binary data in ASCII and vice-versa @@ -54,12 +67,6 @@ ** Brandon Long, September 2001. */ -#define PY_SSIZE_T_CLEAN - -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/pystrhex.h" -#include "third_party/zlib/zlib.h" - static PyObject *Error; static PyObject *Incomplete; @@ -1116,7 +1123,7 @@ binascii_a2b_qp_impl(PyObject *module, Py_buffer *data, int header) PyErr_NoMemory(); return NULL; } - memset(odata, 0, datalen); + bzero(odata, datalen); in = out = 0; while (in < datalen) { @@ -1304,7 +1311,7 @@ binascii_b2a_qp_impl(PyObject *module, Py_buffer *data, int quotetabs, PyErr_NoMemory(); return NULL; } - memset(odata, 0, odatalen); + bzero(odata, odatalen); in = out = linelen = 0; while (in < datalen) { diff --git a/third_party/python/Modules/cjkcodecs/_codecs_cn.c b/third_party/python/Modules/cjkcodecs/_codecs_cn.c index cd4ce7150..2db085637 100644 --- a/third_party/python/Modules/cjkcodecs/_codecs_cn.c +++ b/third_party/python/Modules/cjkcodecs/_codecs_cn.c @@ -1,3 +1,5 @@ +#include "third_party/python/Modules/cjkcodecs/cjkcodecs.h" +#include "third_party/python/Modules/cjkcodecs/mappings_cn.inc" /* clang-format off */ /* @@ -6,9 +8,6 @@ * Written by Hye-Shik Chang */ -#include "third_party/python/Modules/cjkcodecs/cjkcodecs.h" -#include "third_party/python/Modules/cjkcodecs/mappings_cn.inc" - /** * hz is predefined as 100 on AIX. So we undefine it to avoid * conflict against hz codec's. diff --git a/third_party/python/Modules/cjkcodecs/_codecs_hk.c b/third_party/python/Modules/cjkcodecs/_codecs_hk.c index 84b851fb8..4aba5c9b2 100644 --- a/third_party/python/Modules/cjkcodecs/_codecs_hk.c +++ b/third_party/python/Modules/cjkcodecs/_codecs_hk.c @@ -1,3 +1,6 @@ +#define USING_IMPORTED_MAPS +#include "third_party/python/Modules/cjkcodecs/cjkcodecs.h" +#include "third_party/python/Modules/cjkcodecs/mappings_hk.inc" /* clang-format off */ /* * _codecs_hk.c: Codecs collection for encodings from Hong Kong @@ -5,11 +8,6 @@ * Written by Hye-Shik Chang */ -#define USING_IMPORTED_MAPS - -#include "third_party/python/Modules/cjkcodecs/cjkcodecs.h" -#include "third_party/python/Modules/cjkcodecs/mappings_hk.inc" - /* * BIG5HKSCS codec */ diff --git a/third_party/python/Modules/cjkcodecs/cjkcodecs.h b/third_party/python/Modules/cjkcodecs/cjkcodecs.h index 9a1e5078b..7ffa96fdd 100644 --- a/third_party/python/Modules/cjkcodecs/cjkcodecs.h +++ b/third_party/python/Modules/cjkcodecs/cjkcodecs.h @@ -1,17 +1,15 @@ #ifndef _CJKCODECS_H_ #define _CJKCODECS_H_ -/* clang-format off */ - -/* - * cjkcodecs.h: common header for cjkcodecs - * - * Written by Hye-Shik Chang - */ - #define PY_SSIZE_T_CLEAN -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/methodobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/pycapsule.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" #include "third_party/python/Modules/cjkcodecs/multibytecodec.h" - +/* clang-format off */ /* a unicode "undefined" code point */ #define UNIINV 0xFFFE diff --git a/third_party/python/Modules/cjkcodecs/clinic/multibytecodec.inc b/third_party/python/Modules/cjkcodecs/clinic/multibytecodec.inc index 84ffd12c6..08c82a91c 100644 --- a/third_party/python/Modules/cjkcodecs/clinic/multibytecodec.inc +++ b/third_party/python/Modules/cjkcodecs/clinic/multibytecodec.inc @@ -1,3 +1,4 @@ +/* clang-format off */ /*[clinic input] preserve [clinic start generated code]*/ diff --git a/third_party/python/Modules/cjkcodecs/multibytecodec.c b/third_party/python/Modules/cjkcodecs/multibytecodec.c index a4802a4a2..a44284e0c 100644 --- a/third_party/python/Modules/cjkcodecs/multibytecodec.c +++ b/third_party/python/Modules/cjkcodecs/multibytecodec.c @@ -1,16 +1,27 @@ +#define PY_SSIZE_T_CLEAN +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/codecs.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pycapsule.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/tupleobject.h" +#include "third_party/python/Modules/cjkcodecs/multibytecodec.h" /* clang-format off */ + +#include "third_party/python/Modules/cjkcodecs/clinic/multibytecodec.inc" + /* * multibytecodec.c: Common Multibyte Codec Implementation * * Written by Hye-Shik Chang */ -#define PY_SSIZE_T_CLEAN -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" -#include "third_party/python/Modules/cjkcodecs/multibytecodec.h" -#include "third_party/python/Modules/cjkcodecs/clinic/multibytecodec.inc" - /*[clinic input] module _multibytecodec class _multibytecodec.MultibyteCodec "MultibyteCodecObject *" "&MultibyteCodec_Type" diff --git a/third_party/python/Modules/cjkcodecs/multibytecodec.h b/third_party/python/Modules/cjkcodecs/multibytecodec.h index 1a270ce56..dc9d04d25 100644 --- a/third_party/python/Modules/cjkcodecs/multibytecodec.h +++ b/third_party/python/Modules/cjkcodecs/multibytecodec.h @@ -1,8 +1,7 @@ #ifndef _PYTHON_MULTIBYTECODEC_H_ #define _PYTHON_MULTIBYTECODEC_H_ -#ifdef __cplusplus -extern "C" { -#endif +#include "third_party/python/Include/unicodeobject.h" +COSMOPOLITAN_C_START_ /* clang-format off */ /* @@ -130,8 +129,5 @@ typedef struct { #define PyMultibyteCodec_CAPSULE_NAME "multibytecodec.__map_*" - -#ifdef __cplusplus -} -#endif +COSMOPOLITAN_C_END_ #endif diff --git a/third_party/python/Modules/clinic/audioop.inc b/third_party/python/Modules/clinic/audioop.inc index d9a51f19c..b5757121c 100644 --- a/third_party/python/Modules/clinic/audioop.inc +++ b/third_party/python/Modules/clinic/audioop.inc @@ -2,6 +2,7 @@ /*[clinic input] preserve [clinic start generated code]*/ +#include "third_party/python/Include/abstract.h" PyDoc_STRVAR(audioop_getsample__doc__, "getsample($module, fragment, width, index, /)\n" diff --git a/third_party/python/Modules/clinic/zlibmodule.inc b/third_party/python/Modules/clinic/zlibmodule.inc index 242bb34c0..4921b8e7e 100644 --- a/third_party/python/Modules/clinic/zlibmodule.inc +++ b/third_party/python/Modules/clinic/zlibmodule.inc @@ -17,9 +17,6 @@ PyDoc_STRVAR(zlib_compress__doc__, #define ZLIB_COMPRESS_METHODDEF \ {"compress", (PyCFunction)zlib_compress, METH_FASTCALL, zlib_compress__doc__}, -static PyObject * -zlib_compress_impl(PyObject *module, Py_buffer *data, int level); - static PyObject * zlib_compress(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) { diff --git a/third_party/python/Modules/cmathmodule.c b/third_party/python/Modules/cmathmodule.c index 6c2191054..bcfa6b1d0 100644 --- a/third_party/python/Modules/cmathmodule.c +++ b/third_party/python/Modules/cmathmodule.c @@ -1,10 +1,23 @@ +#include "libc/errno.h" +#include "libc/math.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/complexobject.h" +#include "third_party/python/Include/dtoa.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pyfpe.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymath.h" +#include "third_party/python/Include/pyport.h" +#include "third_party/python/Modules/_math.h" /* clang-format off */ + /* Complex math module */ /* much code borrowed from mathmodule.c */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Modules/_math.h" /* we need DBL_MAX, DBL_MIN, DBL_EPSILON, DBL_MANT_DIG and FLT_RADIX from float.h. We assume that FLT_RADIX is either 2 or 16. */ diff --git a/third_party/python/Modules/config.c b/third_party/python/Modules/config.c index 9f431d003..8bb6d96f4 100644 --- a/third_party/python/Modules/config.c +++ b/third_party/python/Modules/config.c @@ -20,6 +20,7 @@ redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. #include "third_party/python/Include/Python.h" extern PyObject* PyInit__decimal(void); +extern PyObject* PyInit_audioop(void); extern PyObject* PyInit_posix(void); extern PyObject* PyInit_errno(void); extern PyObject* PyInit_pwd(void); @@ -65,7 +66,6 @@ extern PyObject* PyInit__sha1(void); extern PyObject* PyInit__sha256(void); extern PyObject* PyInit__sha512(void); extern PyObject* PyInit__sha3(void); -extern PyObject* PyInit__blake2(void); extern PyObject* PyInit_syslog(void); extern PyObject* PyInit_binascii(void); extern PyObject* PyInit_parser(void); @@ -96,6 +96,7 @@ struct _inittab _PyImport_Inittab[] = { {"_decimal", PyInit__decimal}, {"posix", PyInit_posix}, + {"audioop", PyInit_audioop}, {"errno", PyInit_errno}, {"pwd", PyInit_pwd}, {"_sre", PyInit__sre}, @@ -140,7 +141,6 @@ struct _inittab _PyImport_Inittab[] = { {"_sha256", PyInit__sha256}, {"_sha512", PyInit__sha512}, {"_sha3", PyInit__sha3}, - {"_blake2", PyInit__blake2}, {"syslog", PyInit_syslog}, {"binascii", PyInit_binascii}, {"parser", PyInit_parser}, diff --git a/third_party/python/Modules/config.c.in b/third_party/python/Modules/config.c.in index d93fe5a63..a595bd691 100644 --- a/third_party/python/Modules/config.c.in +++ b/third_party/python/Modules/config.c.in @@ -16,12 +16,7 @@ redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. /* This file contains the table of built-in modules. See create_builtin() in import.c. */ -#include "Python.h" - -#ifdef __cplusplus -extern "C" { -#endif - +#include "third_party/python/Include/Python.h" /* -- ADDMODULE MARKER 1 -- */ @@ -62,7 +57,3 @@ struct _inittab _PyImport_Inittab[] = { {0, 0} }; - -#ifdef __cplusplus -} -#endif diff --git a/third_party/python/Modules/errnomodule.c b/third_party/python/Modules/errnomodule.c index 248b93f72..65d6b9e48 100644 --- a/third_party/python/Modules/errnomodule.c +++ b/third_party/python/Modules/errnomodule.c @@ -1,5 +1,14 @@ +#include "libc/dce.h" +#include "libc/errno.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/methodobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/moduleobject.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/unicodeobject.h" /* clang-format off */ -#include "third_party/python/Include/Python.h" /* * Pull in the system error definitions @@ -80,746 +89,143 @@ PyInit_errno(void) * MacOSX. */ -#ifdef ENODEV - inscode(d, ds, de, "ENODEV", ENODEV, "No such device"); -#endif -#ifdef ENOCSI - inscode(d, ds, de, "ENOCSI", ENOCSI, "No CSI structure available"); -#endif -#ifdef EHOSTUNREACH - inscode(d, ds, de, "EHOSTUNREACH", EHOSTUNREACH, "No route to host"); -#else -#ifdef WSAEHOSTUNREACH - inscode(d, ds, de, "EHOSTUNREACH", WSAEHOSTUNREACH, "No route to host"); -#endif -#endif -#ifdef ENOMSG - inscode(d, ds, de, "ENOMSG", ENOMSG, "No message of desired type"); -#endif -#ifdef EUCLEAN - inscode(d, ds, de, "EUCLEAN", EUCLEAN, "Structure needs cleaning"); -#endif -#ifdef EL2NSYNC - inscode(d, ds, de, "EL2NSYNC", EL2NSYNC, "Level 2 not synchronized"); -#endif -#ifdef EL2HLT - inscode(d, ds, de, "EL2HLT", EL2HLT, "Level 2 halted"); -#endif -#ifdef ENODATA - inscode(d, ds, de, "ENODATA", ENODATA, "No data available"); -#endif -#ifdef ENOTBLK - inscode(d, ds, de, "ENOTBLK", ENOTBLK, "Block device required"); -#endif -#ifdef ENOSYS - inscode(d, ds, de, "ENOSYS", ENOSYS, "Function not implemented"); -#endif -#ifdef EPIPE inscode(d, ds, de, "EPIPE", EPIPE, "Broken pipe"); -#endif -#ifdef EINVAL + inscode(d, ds, de, "ENODEV", ENODEV, "No such device"); inscode(d, ds, de, "EINVAL", EINVAL, "Invalid argument"); -#else -#ifdef WSAEINVAL - inscode(d, ds, de, "EINVAL", WSAEINVAL, "Invalid argument"); -#endif -#endif -#ifdef EOVERFLOW - inscode(d, ds, de, "EOVERFLOW", EOVERFLOW, "Value too large for defined data type"); -#endif -#ifdef EADV - inscode(d, ds, de, "EADV", EADV, "Advertise error"); -#endif -#ifdef EINTR inscode(d, ds, de, "EINTR", EINTR, "Interrupted system call"); -#else -#ifdef WSAEINTR - inscode(d, ds, de, "EINTR", WSAEINTR, "Interrupted system call"); -#endif -#endif -#ifdef EUSERS - inscode(d, ds, de, "EUSERS", EUSERS, "Too many users"); -#else -#ifdef WSAEUSERS - inscode(d, ds, de, "EUSERS", WSAEUSERS, "Too many users"); -#endif -#endif -#ifdef ENOTEMPTY - inscode(d, ds, de, "ENOTEMPTY", ENOTEMPTY, "Directory not empty"); -#else -#ifdef WSAENOTEMPTY - inscode(d, ds, de, "ENOTEMPTY", WSAENOTEMPTY, "Directory not empty"); -#endif -#endif -#ifdef ENOBUFS - inscode(d, ds, de, "ENOBUFS", ENOBUFS, "No buffer space available"); -#else -#ifdef WSAENOBUFS - inscode(d, ds, de, "ENOBUFS", WSAENOBUFS, "No buffer space available"); -#endif -#endif -#ifdef EPROTO - inscode(d, ds, de, "EPROTO", EPROTO, "Protocol error"); -#endif -#ifdef EREMOTE - inscode(d, ds, de, "EREMOTE", EREMOTE, "Object is remote"); -#else -#ifdef WSAEREMOTE - inscode(d, ds, de, "EREMOTE", WSAEREMOTE, "Object is remote"); -#endif -#endif -#ifdef ENAVAIL - inscode(d, ds, de, "ENAVAIL", ENAVAIL, "No XENIX semaphores available"); -#endif -#ifdef ECHILD - inscode(d, ds, de, "ECHILD", ECHILD, "No child processes"); -#endif -#ifdef ELOOP - inscode(d, ds, de, "ELOOP", ELOOP, "Too many symbolic links encountered"); -#else -#ifdef WSAELOOP - inscode(d, ds, de, "ELOOP", WSAELOOP, "Too many symbolic links encountered"); -#endif -#endif -#ifdef EXDEV - inscode(d, ds, de, "EXDEV", EXDEV, "Cross-device link"); -#endif -#ifdef E2BIG - inscode(d, ds, de, "E2BIG", E2BIG, "Arg list too long"); -#endif -#ifdef ESRCH + inscode(d, ds, de, "ENOTBLK", ENOTBLK, "Block device required"); + inscode(d, ds, de, "ENOSYS", ENOSYS, "Function not implemented"); + inscode(d, ds, de, "EHOSTUNREACH", EHOSTUNREACH, "No route to host"); inscode(d, ds, de, "ESRCH", ESRCH, "No such process"); -#endif -#ifdef EMSGSIZE + inscode(d, ds, de, "EUSERS", EUSERS, "Too many users"); + inscode(d, ds, de, "EXDEV", EXDEV, "Cross-device link"); + inscode(d, ds, de, "E2BIG", E2BIG, "Arg list too long"); + inscode(d, ds, de, "EREMOTE", EREMOTE, "Object is remote"); + inscode(d, ds, de, "ECHILD", ECHILD, "No child processes"); inscode(d, ds, de, "EMSGSIZE", EMSGSIZE, "Message too long"); -#else -#ifdef WSAEMSGSIZE - inscode(d, ds, de, "EMSGSIZE", WSAEMSGSIZE, "Message too long"); -#endif -#endif -#ifdef EAFNOSUPPORT + inscode(d, ds, de, "ENOTEMPTY", ENOTEMPTY, "Directory not empty"); + inscode(d, ds, de, "ENOBUFS", ENOBUFS, "No buffer space available"); + inscode(d, ds, de, "ELOOP", ELOOP, "Too many symbolic links encountered"); inscode(d, ds, de, "EAFNOSUPPORT", EAFNOSUPPORT, "Address family not supported by protocol"); -#else -#ifdef WSAEAFNOSUPPORT - inscode(d, ds, de, "EAFNOSUPPORT", WSAEAFNOSUPPORT, "Address family not supported by protocol"); -#endif -#endif -#ifdef EBADR - inscode(d, ds, de, "EBADR", EBADR, "Invalid request descriptor"); -#endif -#ifdef EHOSTDOWN + + if (EPROTO) inscode(d, ds, de, "EPROTO", EPROTO, "Protocol error"); + if (ENOMSG) inscode(d, ds, de, "ENOMSG", ENOMSG, "No message of desired type"); + if (ENODATA) inscode(d, ds, de, "ENODATA", ENODATA, "No data available"); + if (EOVERFLOW) inscode(d, ds, de, "EOVERFLOW", EOVERFLOW, "Value too large for defined data type"); + inscode(d, ds, de, "EHOSTDOWN", EHOSTDOWN, "Host is down"); -#else -#ifdef WSAEHOSTDOWN - inscode(d, ds, de, "EHOSTDOWN", WSAEHOSTDOWN, "Host is down"); -#endif -#endif -#ifdef EPFNOSUPPORT inscode(d, ds, de, "EPFNOSUPPORT", EPFNOSUPPORT, "Protocol family not supported"); -#else -#ifdef WSAEPFNOSUPPORT - inscode(d, ds, de, "EPFNOSUPPORT", WSAEPFNOSUPPORT, "Protocol family not supported"); -#endif -#endif -#ifdef ENOPROTOOPT inscode(d, ds, de, "ENOPROTOOPT", ENOPROTOOPT, "Protocol not available"); -#else -#ifdef WSAENOPROTOOPT - inscode(d, ds, de, "ENOPROTOOPT", WSAENOPROTOOPT, "Protocol not available"); -#endif -#endif -#ifdef EBUSY inscode(d, ds, de, "EBUSY", EBUSY, "Device or resource busy"); -#endif -#ifdef EWOULDBLOCK inscode(d, ds, de, "EWOULDBLOCK", EWOULDBLOCK, "Operation would block"); -#else -#ifdef WSAEWOULDBLOCK - inscode(d, ds, de, "EWOULDBLOCK", WSAEWOULDBLOCK, "Operation would block"); -#endif -#endif -#ifdef EBADFD inscode(d, ds, de, "EBADFD", EBADFD, "File descriptor in bad state"); -#endif -#ifdef EDOTDOT - inscode(d, ds, de, "EDOTDOT", EDOTDOT, "RFS specific error"); -#endif -#ifdef EISCONN + inscode(d, ds, de, "EISCONN", EISCONN, "Transport endpoint is already connected"); -#else -#ifdef WSAEISCONN - inscode(d, ds, de, "EISCONN", WSAEISCONN, "Transport endpoint is already connected"); -#endif -#endif -#ifdef ENOANO - inscode(d, ds, de, "ENOANO", ENOANO, "No anode"); -#endif -#ifdef ESHUTDOWN inscode(d, ds, de, "ESHUTDOWN", ESHUTDOWN, "Cannot send after transport endpoint shutdown"); -#else -#ifdef WSAESHUTDOWN - inscode(d, ds, de, "ESHUTDOWN", WSAESHUTDOWN, "Cannot send after transport endpoint shutdown"); -#endif -#endif -#ifdef ECHRNG - inscode(d, ds, de, "ECHRNG", ECHRNG, "Channel number out of range"); -#endif -#ifdef ELIBBAD - inscode(d, ds, de, "ELIBBAD", ELIBBAD, "Accessing a corrupted shared library"); -#endif -#ifdef ENONET inscode(d, ds, de, "ENONET", ENONET, "Machine is not on the network"); -#endif -#ifdef EBADE inscode(d, ds, de, "EBADE", EBADE, "Invalid exchange"); -#endif -#ifdef EBADF inscode(d, ds, de, "EBADF", EBADF, "Bad file number"); -#else -#ifdef WSAEBADF - inscode(d, ds, de, "EBADF", WSAEBADF, "Bad file number"); -#endif -#endif -#ifdef EMULTIHOP inscode(d, ds, de, "EMULTIHOP", EMULTIHOP, "Multihop attempted"); -#endif -#ifdef EIO inscode(d, ds, de, "EIO", EIO, "I/O error"); -#endif -#ifdef EUNATCH inscode(d, ds, de, "EUNATCH", EUNATCH, "Protocol driver not attached"); -#endif -#ifdef EPROTOTYPE inscode(d, ds, de, "EPROTOTYPE", EPROTOTYPE, "Protocol wrong type for socket"); -#else -#ifdef WSAEPROTOTYPE - inscode(d, ds, de, "EPROTOTYPE", WSAEPROTOTYPE, "Protocol wrong type for socket"); -#endif -#endif -#ifdef ENOSPC inscode(d, ds, de, "ENOSPC", ENOSPC, "No space left on device"); -#endif -#ifdef ENOEXEC inscode(d, ds, de, "ENOEXEC", ENOEXEC, "Exec format error"); -#endif -#ifdef EALREADY inscode(d, ds, de, "EALREADY", EALREADY, "Operation already in progress"); -#else -#ifdef WSAEALREADY - inscode(d, ds, de, "EALREADY", WSAEALREADY, "Operation already in progress"); -#endif -#endif -#ifdef ENETDOWN inscode(d, ds, de, "ENETDOWN", ENETDOWN, "Network is down"); -#else -#ifdef WSAENETDOWN - inscode(d, ds, de, "ENETDOWN", WSAENETDOWN, "Network is down"); -#endif -#endif -#ifdef ENOTNAM inscode(d, ds, de, "ENOTNAM", ENOTNAM, "Not a XENIX named type file"); -#endif -#ifdef EACCES inscode(d, ds, de, "EACCES", EACCES, "Permission denied"); -#else -#ifdef WSAEACCES - inscode(d, ds, de, "EACCES", WSAEACCES, "Permission denied"); -#endif -#endif -#ifdef ELNRNG inscode(d, ds, de, "ELNRNG", ELNRNG, "Link number out of range"); -#endif -#ifdef EILSEQ inscode(d, ds, de, "EILSEQ", EILSEQ, "Illegal byte sequence"); -#endif -#ifdef ENOTDIR inscode(d, ds, de, "ENOTDIR", ENOTDIR, "Not a directory"); -#endif -#ifdef ENOTUNIQ inscode(d, ds, de, "ENOTUNIQ", ENOTUNIQ, "Name not unique on network"); -#endif -#ifdef EPERM inscode(d, ds, de, "EPERM", EPERM, "Operation not permitted"); -#endif -#ifdef EDOM inscode(d, ds, de, "EDOM", EDOM, "Math argument out of domain of func"); -#endif -#ifdef EXFULL inscode(d, ds, de, "EXFULL", EXFULL, "Exchange full"); -#endif -#ifdef ECONNREFUSED inscode(d, ds, de, "ECONNREFUSED", ECONNREFUSED, "Connection refused"); -#else -#ifdef WSAECONNREFUSED - inscode(d, ds, de, "ECONNREFUSED", WSAECONNREFUSED, "Connection refused"); -#endif -#endif -#ifdef EISDIR inscode(d, ds, de, "EISDIR", EISDIR, "Is a directory"); -#endif -#ifdef EPROTONOSUPPORT inscode(d, ds, de, "EPROTONOSUPPORT", EPROTONOSUPPORT, "Protocol not supported"); -#else -#ifdef WSAEPROTONOSUPPORT - inscode(d, ds, de, "EPROTONOSUPPORT", WSAEPROTONOSUPPORT, "Protocol not supported"); -#endif -#endif -#ifdef EROFS inscode(d, ds, de, "EROFS", EROFS, "Read-only file system"); -#endif -#ifdef EADDRNOTAVAIL inscode(d, ds, de, "EADDRNOTAVAIL", EADDRNOTAVAIL, "Cannot assign requested address"); -#else -#ifdef WSAEADDRNOTAVAIL - inscode(d, ds, de, "EADDRNOTAVAIL", WSAEADDRNOTAVAIL, "Cannot assign requested address"); -#endif -#endif -#ifdef EIDRM inscode(d, ds, de, "EIDRM", EIDRM, "Identifier removed"); -#endif -#ifdef ECOMM inscode(d, ds, de, "ECOMM", ECOMM, "Communication error on send"); -#endif -#ifdef ESRMNT inscode(d, ds, de, "ESRMNT", ESRMNT, "Srmount error"); -#endif -#ifdef EREMOTEIO inscode(d, ds, de, "EREMOTEIO", EREMOTEIO, "Remote I/O error"); -#endif -#ifdef EL3RST inscode(d, ds, de, "EL3RST", EL3RST, "Level 3 reset"); -#endif -#ifdef EBADMSG inscode(d, ds, de, "EBADMSG", EBADMSG, "Not a data message"); -#endif -#ifdef ENFILE inscode(d, ds, de, "ENFILE", ENFILE, "File table overflow"); -#endif -#ifdef ELIBMAX inscode(d, ds, de, "ELIBMAX", ELIBMAX, "Attempting to link in too many shared libraries"); -#endif -#ifdef ESPIPE inscode(d, ds, de, "ESPIPE", ESPIPE, "Illegal seek"); -#endif -#ifdef ENOLINK inscode(d, ds, de, "ENOLINK", ENOLINK, "Link has been severed"); -#endif -#ifdef ENETRESET inscode(d, ds, de, "ENETRESET", ENETRESET, "Network dropped connection because of reset"); -#else -#ifdef WSAENETRESET - inscode(d, ds, de, "ENETRESET", WSAENETRESET, "Network dropped connection because of reset"); -#endif -#endif -#ifdef ETIMEDOUT inscode(d, ds, de, "ETIMEDOUT", ETIMEDOUT, "Connection timed out"); -#else -#ifdef WSAETIMEDOUT - inscode(d, ds, de, "ETIMEDOUT", WSAETIMEDOUT, "Connection timed out"); -#endif -#endif -#ifdef ENOENT inscode(d, ds, de, "ENOENT", ENOENT, "No such file or directory"); -#endif -#ifdef EEXIST inscode(d, ds, de, "EEXIST", EEXIST, "File exists"); -#endif -#ifdef EDQUOT inscode(d, ds, de, "EDQUOT", EDQUOT, "Quota exceeded"); -#else -#ifdef WSAEDQUOT - inscode(d, ds, de, "EDQUOT", WSAEDQUOT, "Quota exceeded"); -#endif -#endif -#ifdef ENOSTR inscode(d, ds, de, "ENOSTR", ENOSTR, "Device not a stream"); -#endif -#ifdef EBADSLT inscode(d, ds, de, "EBADSLT", EBADSLT, "Invalid slot"); -#endif -#ifdef EBADRQC inscode(d, ds, de, "EBADRQC", EBADRQC, "Invalid request code"); -#endif -#ifdef ELIBACC inscode(d, ds, de, "ELIBACC", ELIBACC, "Can not access a needed shared library"); -#endif -#ifdef EFAULT inscode(d, ds, de, "EFAULT", EFAULT, "Bad address"); -#else -#ifdef WSAEFAULT - inscode(d, ds, de, "EFAULT", WSAEFAULT, "Bad address"); -#endif -#endif -#ifdef EFBIG inscode(d, ds, de, "EFBIG", EFBIG, "File too large"); -#endif -#ifdef EDEADLK inscode(d, ds, de, "EDEADLK", EDEADLK, "Resource deadlock would occur"); -#endif -#ifdef ENOTCONN inscode(d, ds, de, "ENOTCONN", ENOTCONN, "Transport endpoint is not connected"); -#else -#ifdef WSAENOTCONN - inscode(d, ds, de, "ENOTCONN", WSAENOTCONN, "Transport endpoint is not connected"); -#endif -#endif -#ifdef EDESTADDRREQ inscode(d, ds, de, "EDESTADDRREQ", EDESTADDRREQ, "Destination address required"); -#else -#ifdef WSAEDESTADDRREQ - inscode(d, ds, de, "EDESTADDRREQ", WSAEDESTADDRREQ, "Destination address required"); -#endif -#endif -#ifdef ELIBSCN inscode(d, ds, de, "ELIBSCN", ELIBSCN, ".lib section in a.out corrupted"); -#endif -#ifdef ENOLCK inscode(d, ds, de, "ENOLCK", ENOLCK, "No record locks available"); -#endif -#ifdef EISNAM inscode(d, ds, de, "EISNAM", EISNAM, "Is a named type file"); -#endif -#ifdef ECONNABORTED inscode(d, ds, de, "ECONNABORTED", ECONNABORTED, "Software caused connection abort"); -#else -#ifdef WSAECONNABORTED - inscode(d, ds, de, "ECONNABORTED", WSAECONNABORTED, "Software caused connection abort"); -#endif -#endif -#ifdef ENETUNREACH inscode(d, ds, de, "ENETUNREACH", ENETUNREACH, "Network is unreachable"); -#else -#ifdef WSAENETUNREACH - inscode(d, ds, de, "ENETUNREACH", WSAENETUNREACH, "Network is unreachable"); -#endif -#endif -#ifdef ESTALE inscode(d, ds, de, "ESTALE", ESTALE, "Stale NFS file handle"); -#else -#ifdef WSAESTALE - inscode(d, ds, de, "ESTALE", WSAESTALE, "Stale NFS file handle"); -#endif -#endif -#ifdef ENOSR inscode(d, ds, de, "ENOSR", ENOSR, "Out of streams resources"); -#endif -#ifdef ENOMEM inscode(d, ds, de, "ENOMEM", ENOMEM, "Out of memory"); -#endif -#ifdef ENOTSOCK inscode(d, ds, de, "ENOTSOCK", ENOTSOCK, "Socket operation on non-socket"); -#else -#ifdef WSAENOTSOCK - inscode(d, ds, de, "ENOTSOCK", WSAENOTSOCK, "Socket operation on non-socket"); -#endif -#endif -#ifdef ESTRPIPE inscode(d, ds, de, "ESTRPIPE", ESTRPIPE, "Streams pipe error"); -#endif -#ifdef EMLINK inscode(d, ds, de, "EMLINK", EMLINK, "Too many links"); -#endif -#ifdef ERANGE inscode(d, ds, de, "ERANGE", ERANGE, "Math result not representable"); -#endif -#ifdef ELIBEXEC inscode(d, ds, de, "ELIBEXEC", ELIBEXEC, "Cannot exec a shared library directly"); -#endif -#ifdef EL3HLT inscode(d, ds, de, "EL3HLT", EL3HLT, "Level 3 halted"); -#endif -#ifdef ECONNRESET inscode(d, ds, de, "ECONNRESET", ECONNRESET, "Connection reset by peer"); -#else -#ifdef WSAECONNRESET - inscode(d, ds, de, "ECONNRESET", WSAECONNRESET, "Connection reset by peer"); -#endif -#endif -#ifdef EADDRINUSE inscode(d, ds, de, "EADDRINUSE", EADDRINUSE, "Address already in use"); -#else -#ifdef WSAEADDRINUSE - inscode(d, ds, de, "EADDRINUSE", WSAEADDRINUSE, "Address already in use"); -#endif -#endif -#ifdef EOPNOTSUPP inscode(d, ds, de, "EOPNOTSUPP", EOPNOTSUPP, "Operation not supported on transport endpoint"); -#else -#ifdef WSAEOPNOTSUPP - inscode(d, ds, de, "EOPNOTSUPP", WSAEOPNOTSUPP, "Operation not supported on transport endpoint"); -#endif -#endif -#ifdef EREMCHG inscode(d, ds, de, "EREMCHG", EREMCHG, "Remote address changed"); -#endif -#ifdef EAGAIN inscode(d, ds, de, "EAGAIN", EAGAIN, "Try again"); -#endif -#ifdef ENAMETOOLONG inscode(d, ds, de, "ENAMETOOLONG", ENAMETOOLONG, "File name too long"); -#else -#ifdef WSAENAMETOOLONG - inscode(d, ds, de, "ENAMETOOLONG", WSAENAMETOOLONG, "File name too long"); -#endif -#endif -#ifdef ENOTTY inscode(d, ds, de, "ENOTTY", ENOTTY, "Not a typewriter"); -#endif -#ifdef ERESTART inscode(d, ds, de, "ERESTART", ERESTART, "Interrupted system call should be restarted"); -#endif -#ifdef ESOCKTNOSUPPORT inscode(d, ds, de, "ESOCKTNOSUPPORT", ESOCKTNOSUPPORT, "Socket type not supported"); -#else -#ifdef WSAESOCKTNOSUPPORT - inscode(d, ds, de, "ESOCKTNOSUPPORT", WSAESOCKTNOSUPPORT, "Socket type not supported"); -#endif -#endif -#ifdef ETIME inscode(d, ds, de, "ETIME", ETIME, "Timer expired"); -#endif -#ifdef EBFONT - inscode(d, ds, de, "EBFONT", EBFONT, "Bad font file format"); -#endif -#ifdef EDEADLOCK - inscode(d, ds, de, "EDEADLOCK", EDEADLOCK, "Error EDEADLOCK"); -#endif -#ifdef ETOOMANYREFS inscode(d, ds, de, "ETOOMANYREFS", ETOOMANYREFS, "Too many references: cannot splice"); -#else -#ifdef WSAETOOMANYREFS - inscode(d, ds, de, "ETOOMANYREFS", WSAETOOMANYREFS, "Too many references: cannot splice"); -#endif -#endif -#ifdef EMFILE inscode(d, ds, de, "EMFILE", EMFILE, "Too many open files"); -#else -#ifdef WSAEMFILE - inscode(d, ds, de, "EMFILE", WSAEMFILE, "Too many open files"); -#endif -#endif -#ifdef ETXTBSY inscode(d, ds, de, "ETXTBSY", ETXTBSY, "Text file busy"); -#endif -#ifdef EINPROGRESS inscode(d, ds, de, "EINPROGRESS", EINPROGRESS, "Operation now in progress"); -#else -#ifdef WSAEINPROGRESS - inscode(d, ds, de, "EINPROGRESS", WSAEINPROGRESS, "Operation now in progress"); -#endif -#endif -#ifdef ENXIO inscode(d, ds, de, "ENXIO", ENXIO, "No such device or address"); -#endif -#ifdef ENOPKG - inscode(d, ds, de, "ENOPKG", ENOPKG, "Package not installed"); -#endif -#ifdef WSASY - inscode(d, ds, de, "WSASY", WSASY, "Error WSASY"); -#endif -#ifdef WSAEHOSTDOWN - inscode(d, ds, de, "WSAEHOSTDOWN", WSAEHOSTDOWN, "Host is down"); -#endif -#ifdef WSAENETDOWN - inscode(d, ds, de, "WSAENETDOWN", WSAENETDOWN, "Network is down"); -#endif -#ifdef WSAENOTSOCK - inscode(d, ds, de, "WSAENOTSOCK", WSAENOTSOCK, "Socket operation on non-socket"); -#endif -#ifdef WSAEHOSTUNREACH - inscode(d, ds, de, "WSAEHOSTUNREACH", WSAEHOSTUNREACH, "No route to host"); -#endif -#ifdef WSAELOOP - inscode(d, ds, de, "WSAELOOP", WSAELOOP, "Too many symbolic links encountered"); -#endif -#ifdef WSAEMFILE - inscode(d, ds, de, "WSAEMFILE", WSAEMFILE, "Too many open files"); -#endif -#ifdef WSAESTALE - inscode(d, ds, de, "WSAESTALE", WSAESTALE, "Stale NFS file handle"); -#endif -#ifdef WSAVERNOTSUPPORTED - inscode(d, ds, de, "WSAVERNOTSUPPORTED", WSAVERNOTSUPPORTED, "Error WSAVERNOTSUPPORTED"); -#endif -#ifdef WSAENETUNREACH - inscode(d, ds, de, "WSAENETUNREACH", WSAENETUNREACH, "Network is unreachable"); -#endif -#ifdef WSAEPROCLIM - inscode(d, ds, de, "WSAEPROCLIM", WSAEPROCLIM, "Error WSAEPROCLIM"); -#endif -#ifdef WSAEFAULT - inscode(d, ds, de, "WSAEFAULT", WSAEFAULT, "Bad address"); -#endif -#ifdef WSANOTINITIALISED - inscode(d, ds, de, "WSANOTINITIALISED", WSANOTINITIALISED, "Error WSANOTINITIALISED"); -#endif -#ifdef WSAEUSERS - inscode(d, ds, de, "WSAEUSERS", WSAEUSERS, "Too many users"); -#endif -#ifdef WSAMAKEASYNCREPL - inscode(d, ds, de, "WSAMAKEASYNCREPL", WSAMAKEASYNCREPL, "Error WSAMAKEASYNCREPL"); -#endif -#ifdef WSAENOPROTOOPT - inscode(d, ds, de, "WSAENOPROTOOPT", WSAENOPROTOOPT, "Protocol not available"); -#endif -#ifdef WSAECONNABORTED - inscode(d, ds, de, "WSAECONNABORTED", WSAECONNABORTED, "Software caused connection abort"); -#endif -#ifdef WSAENAMETOOLONG - inscode(d, ds, de, "WSAENAMETOOLONG", WSAENAMETOOLONG, "File name too long"); -#endif -#ifdef WSAENOTEMPTY - inscode(d, ds, de, "WSAENOTEMPTY", WSAENOTEMPTY, "Directory not empty"); -#endif -#ifdef WSAESHUTDOWN - inscode(d, ds, de, "WSAESHUTDOWN", WSAESHUTDOWN, "Cannot send after transport endpoint shutdown"); -#endif -#ifdef WSAEAFNOSUPPORT - inscode(d, ds, de, "WSAEAFNOSUPPORT", WSAEAFNOSUPPORT, "Address family not supported by protocol"); -#endif -#ifdef WSAETOOMANYREFS - inscode(d, ds, de, "WSAETOOMANYREFS", WSAETOOMANYREFS, "Too many references: cannot splice"); -#endif -#ifdef WSAEACCES - inscode(d, ds, de, "WSAEACCES", WSAEACCES, "Permission denied"); -#endif -#ifdef WSATR - inscode(d, ds, de, "WSATR", WSATR, "Error WSATR"); -#endif -#ifdef WSABASEERR - inscode(d, ds, de, "WSABASEERR", WSABASEERR, "Error WSABASEERR"); -#endif -#ifdef WSADESCRIPTIO - inscode(d, ds, de, "WSADESCRIPTIO", WSADESCRIPTIO, "Error WSADESCRIPTIO"); -#endif -#ifdef WSAEMSGSIZE - inscode(d, ds, de, "WSAEMSGSIZE", WSAEMSGSIZE, "Message too long"); -#endif -#ifdef WSAEBADF - inscode(d, ds, de, "WSAEBADF", WSAEBADF, "Bad file number"); -#endif -#ifdef WSAECONNRESET - inscode(d, ds, de, "WSAECONNRESET", WSAECONNRESET, "Connection reset by peer"); -#endif -#ifdef WSAGETSELECTERRO - inscode(d, ds, de, "WSAGETSELECTERRO", WSAGETSELECTERRO, "Error WSAGETSELECTERRO"); -#endif -#ifdef WSAETIMEDOUT - inscode(d, ds, de, "WSAETIMEDOUT", WSAETIMEDOUT, "Connection timed out"); -#endif -#ifdef WSAENOBUFS - inscode(d, ds, de, "WSAENOBUFS", WSAENOBUFS, "No buffer space available"); -#endif -#ifdef WSAEDISCON - inscode(d, ds, de, "WSAEDISCON", WSAEDISCON, "Error WSAEDISCON"); -#endif -#ifdef WSAEINTR - inscode(d, ds, de, "WSAEINTR", WSAEINTR, "Interrupted system call"); -#endif -#ifdef WSAEPROTOTYPE - inscode(d, ds, de, "WSAEPROTOTYPE", WSAEPROTOTYPE, "Protocol wrong type for socket"); -#endif -#ifdef WSAHOS - inscode(d, ds, de, "WSAHOS", WSAHOS, "Error WSAHOS"); -#endif -#ifdef WSAEADDRINUSE - inscode(d, ds, de, "WSAEADDRINUSE", WSAEADDRINUSE, "Address already in use"); -#endif -#ifdef WSAEADDRNOTAVAIL - inscode(d, ds, de, "WSAEADDRNOTAVAIL", WSAEADDRNOTAVAIL, "Cannot assign requested address"); -#endif -#ifdef WSAEALREADY - inscode(d, ds, de, "WSAEALREADY", WSAEALREADY, "Operation already in progress"); -#endif -#ifdef WSAEPROTONOSUPPORT - inscode(d, ds, de, "WSAEPROTONOSUPPORT", WSAEPROTONOSUPPORT, "Protocol not supported"); -#endif -#ifdef WSASYSNOTREADY - inscode(d, ds, de, "WSASYSNOTREADY", WSASYSNOTREADY, "Error WSASYSNOTREADY"); -#endif -#ifdef WSAEWOULDBLOCK - inscode(d, ds, de, "WSAEWOULDBLOCK", WSAEWOULDBLOCK, "Operation would block"); -#endif -#ifdef WSAEPFNOSUPPORT - inscode(d, ds, de, "WSAEPFNOSUPPORT", WSAEPFNOSUPPORT, "Protocol family not supported"); -#endif -#ifdef WSAEOPNOTSUPP - inscode(d, ds, de, "WSAEOPNOTSUPP", WSAEOPNOTSUPP, "Operation not supported on transport endpoint"); -#endif -#ifdef WSAEISCONN - inscode(d, ds, de, "WSAEISCONN", WSAEISCONN, "Transport endpoint is already connected"); -#endif -#ifdef WSAEDQUOT - inscode(d, ds, de, "WSAEDQUOT", WSAEDQUOT, "Quota exceeded"); -#endif -#ifdef WSAENOTCONN - inscode(d, ds, de, "WSAENOTCONN", WSAENOTCONN, "Transport endpoint is not connected"); -#endif -#ifdef WSAEREMOTE - inscode(d, ds, de, "WSAEREMOTE", WSAEREMOTE, "Object is remote"); -#endif -#ifdef WSAEINVAL - inscode(d, ds, de, "WSAEINVAL", WSAEINVAL, "Invalid argument"); -#endif -#ifdef WSAEINPROGRESS - inscode(d, ds, de, "WSAEINPROGRESS", WSAEINPROGRESS, "Operation now in progress"); -#endif -#ifdef WSAGETSELECTEVEN - inscode(d, ds, de, "WSAGETSELECTEVEN", WSAGETSELECTEVEN, "Error WSAGETSELECTEVEN"); -#endif -#ifdef WSAESOCKTNOSUPPORT - inscode(d, ds, de, "WSAESOCKTNOSUPPORT", WSAESOCKTNOSUPPORT, "Socket type not supported"); -#endif -#ifdef WSAGETASYNCERRO - inscode(d, ds, de, "WSAGETASYNCERRO", WSAGETASYNCERRO, "Error WSAGETASYNCERRO"); -#endif -#ifdef WSAMAKESELECTREPL - inscode(d, ds, de, "WSAMAKESELECTREPL", WSAMAKESELECTREPL, "Error WSAMAKESELECTREPL"); -#endif -#ifdef WSAGETASYNCBUFLE - inscode(d, ds, de, "WSAGETASYNCBUFLE", WSAGETASYNCBUFLE, "Error WSAGETASYNCBUFLE"); -#endif -#ifdef WSAEDESTADDRREQ - inscode(d, ds, de, "WSAEDESTADDRREQ", WSAEDESTADDRREQ, "Destination address required"); -#endif -#ifdef WSAECONNREFUSED - inscode(d, ds, de, "WSAECONNREFUSED", WSAECONNREFUSED, "Connection refused"); -#endif -#ifdef WSAENETRESET - inscode(d, ds, de, "WSAENETRESET", WSAENETRESET, "Network dropped connection because of reset"); -#endif -#ifdef WSAN - inscode(d, ds, de, "WSAN", WSAN, "Error WSAN"); -#endif -#ifdef ENOMEDIUM - inscode(d, ds, de, "ENOMEDIUM", ENOMEDIUM, "No medium found"); -#endif -#ifdef EMEDIUMTYPE - inscode(d, ds, de, "EMEDIUMTYPE", EMEDIUMTYPE, "Wrong medium type"); -#endif -#ifdef ECANCELED - inscode(d, ds, de, "ECANCELED", ECANCELED, "Operation Canceled"); -#endif -#ifdef ENOKEY - inscode(d, ds, de, "ENOKEY", ENOKEY, "Required key not available"); -#endif -#ifdef EKEYEXPIRED - inscode(d, ds, de, "EKEYEXPIRED", EKEYEXPIRED, "Key has expired"); -#endif -#ifdef EKEYREVOKED - inscode(d, ds, de, "EKEYREVOKED", EKEYREVOKED, "Key has been revoked"); -#endif -#ifdef EKEYREJECTED - inscode(d, ds, de, "EKEYREJECTED", EKEYREJECTED, "Key was rejected by service"); -#endif -#ifdef EOWNERDEAD - inscode(d, ds, de, "EOWNERDEAD", EOWNERDEAD, "Owner died"); -#endif -#ifdef ENOTRECOVERABLE - inscode(d, ds, de, "ENOTRECOVERABLE", ENOTRECOVERABLE, "State not recoverable"); -#endif -#ifdef ERFKILL - inscode(d, ds, de, "ERFKILL", ERFKILL, "Operation not possible due to RF-kill"); + + if (ENOMEDIUM) inscode(d, ds, de, "ENOMEDIUM", ENOMEDIUM, "No medium found"); + if (EMEDIUMTYPE) inscode(d, ds, de, "EMEDIUMTYPE", EMEDIUMTYPE, "Wrong medium type"); + if (ECANCELED) inscode(d, ds, de, "ECANCELED", ECANCELED, "Operation Canceled"); + if (EOWNERDEAD) inscode(d, ds, de, "EOWNERDEAD", EOWNERDEAD, "Owner died"); + if (ENOTRECOVERABLE) inscode(d, ds, de, "ENOTRECOVERABLE", ENOTRECOVERABLE, "State not recoverable"); + +#if !IsTiny() + /* Linux junk errors */ + if (ENOANO) inscode(d, ds, de, "ENOANO", ENOANO, "No anode"); + if (EADV) inscode(d, ds, de, "EADV", EADV, "Advertise error"); + if (EL2HLT) inscode(d, ds, de, "EL2HLT", EL2HLT, "Level 2 halted"); + if (EDOTDOT) inscode(d, ds, de, "EDOTDOT", EDOTDOT, "RFS specific error"); + if (ENOPKG) inscode(d, ds, de, "ENOPKG", ENOPKG, "Package not installed"); + if (EBADR) inscode(d, ds, de, "EBADR", EBADR, "Invalid request descriptor"); + if (ENOCSI) inscode(d, ds, de, "ENOCSI", ENOCSI, "No CSI structure available"); + if (ENOKEY) inscode(d, ds, de, "ENOKEY", ENOKEY, "Required key not available"); + if (EUCLEAN) inscode(d, ds, de, "EUCLEAN", EUCLEAN, "Structure needs cleaning"); + if (ECHRNG) inscode(d, ds, de, "ECHRNG", ECHRNG, "Channel number out of range"); + if (EL2NSYNC) inscode(d, ds, de, "EL2NSYNC", EL2NSYNC, "Level 2 not synchronized"); + if (EKEYEXPIRED) inscode(d, ds, de, "EKEYEXPIRED", EKEYEXPIRED, "Key has expired"); + if (ENAVAIL) inscode(d, ds, de, "ENAVAIL", ENAVAIL, "No XENIX semaphores available"); + if (EKEYREVOKED) inscode(d, ds, de, "EKEYREVOKED", EKEYREVOKED, "Key has been revoked"); + if (ELIBBAD) inscode(d, ds, de, "ELIBBAD", ELIBBAD, "Accessing a corrupted shared library"); + if (EKEYREJECTED) inscode(d, ds, de, "EKEYREJECTED", EKEYREJECTED, "Key was rejected by service"); + if (ERFKILL) inscode(d, ds, de, "ERFKILL", ERFKILL, "Operation not possible due to RF-kill"); #endif /* Solaris-specific errnos */ diff --git a/third_party/python/Modules/expat/ascii.h b/third_party/python/Modules/expat/ascii.inc similarity index 56% rename from third_party/python/Modules/expat/ascii.h rename to third_party/python/Modules/expat/ascii.inc index 814a4a02a..412ab820d 100644 --- a/third_party/python/Modules/expat/ascii.h +++ b/third_party/python/Modules/expat/ascii.inc @@ -1,35 +1,4 @@ /* clang-format off */ -/* - __ __ _ - ___\ \/ /_ __ __ _| |_ - / _ \\ /| '_ \ / _` | __| - | __// \| |_) | (_| | |_ - \___/_/\_\ .__/ \__,_|\__| - |_| XML parser - - Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team - Licensed under the MIT license: - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to permit - persons to whom the Software is furnished to do so, subject to the - following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ #define ASCII_A 0x41 #define ASCII_B 0x42 diff --git a/third_party/python/Modules/expat/asciitab.h b/third_party/python/Modules/expat/asciitab.inc similarity index 100% rename from third_party/python/Modules/expat/asciitab.h rename to third_party/python/Modules/expat/asciitab.inc diff --git a/third_party/python/Modules/expat/expat.h b/third_party/python/Modules/expat/expat.h index 09fe13faa..c0b8a1198 100644 --- a/third_party/python/Modules/expat/expat.h +++ b/third_party/python/Modules/expat/expat.h @@ -1,50 +1,13 @@ -/* clang-format off */ -/* - __ __ _ - ___\ \/ /_ __ __ _| |_ - / _ \\ /| '_ \ / _` | __| - | __// \| |_) | (_| | |_ - \___/_/\_\ .__/ \__,_|\__| - |_| XML parser - - Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team - Licensed under the MIT license: - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to permit - persons to whom the Software is furnished to do so, subject to the - following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - #ifndef Expat_INCLUDED #define Expat_INCLUDED 1 - -#include "expat_external.h" - -#ifdef __cplusplus -extern "C" { -#endif +#include "third_party/python/Modules/expat/expat_external.h" +COSMOPOLITAN_C_START_ struct XML_ParserStruct; typedef struct XML_ParserStruct *XML_Parser; typedef unsigned char XML_Bool; -#define XML_TRUE ((XML_Bool)1) +#define XML_TRUE ((XML_Bool)1) #define XML_FALSE ((XML_Bool)0) /* The XML_Status enum gives the possible return values for several @@ -166,12 +129,11 @@ struct XML_cp { description of the model argument. It's the caller's responsibility to free model when finished with it. */ -typedef void(XMLCALL *XML_ElementDeclHandler)(void *userData, - const XML_Char *name, - XML_Content *model); +typedef void (*XML_ElementDeclHandler)(void *userData, const XML_Char *name, + XML_Content *model); -XMLPARSEAPI(void) -XML_SetElementDeclHandler(XML_Parser parser, XML_ElementDeclHandler eldecl); +void XML_SetElementDeclHandler(XML_Parser parser, + XML_ElementDeclHandler eldecl); /* The Attlist declaration handler is called for *each* attribute. So a single Attlist declaration with multiple attributes declared will @@ -181,12 +143,13 @@ XML_SetElementDeclHandler(XML_Parser parser, XML_ElementDeclHandler eldecl); value will be NULL in the case of "#REQUIRED". If "isrequired" is true and default is non-NULL, then this is a "#FIXED" default. */ -typedef void(XMLCALL *XML_AttlistDeclHandler)( - void *userData, const XML_Char *elname, const XML_Char *attname, - const XML_Char *att_type, const XML_Char *dflt, int isrequired); +typedef void (*XML_AttlistDeclHandler)(void *userData, const XML_Char *elname, + const XML_Char *attname, + const XML_Char *att_type, + const XML_Char *dflt, int isrequired); -XMLPARSEAPI(void) -XML_SetAttlistDeclHandler(XML_Parser parser, XML_AttlistDeclHandler attdecl); +void XML_SetAttlistDeclHandler(XML_Parser parser, + XML_AttlistDeclHandler attdecl); /* The XML declaration handler is called for *both* XML declarations and text declarations. The way to distinguish is that the version @@ -196,13 +159,10 @@ XML_SetAttlistDeclHandler(XML_Parser parser, XML_AttlistDeclHandler attdecl); was no standalone parameter in the declaration, that it was given as no, or that it was given as yes. */ -typedef void(XMLCALL *XML_XmlDeclHandler)(void *userData, - const XML_Char *version, - const XML_Char *encoding, - int standalone); +typedef void (*XML_XmlDeclHandler)(void *userData, const XML_Char *version, + const XML_Char *encoding, int standalone); -XMLPARSEAPI(void) -XML_SetXmlDeclHandler(XML_Parser parser, XML_XmlDeclHandler xmldecl); +void XML_SetXmlDeclHandler(XML_Parser parser, XML_XmlDeclHandler xmldecl); typedef struct { void *(*malloc_fcn)(size_t size); @@ -213,8 +173,7 @@ typedef struct { /* Constructs a new parser; encoding is the encoding specified by the external protocol or NULL if there is none specified. */ -XMLPARSEAPI(XML_Parser) -XML_ParserCreate(const XML_Char *encoding); +XML_Parser XML_ParserCreate(const XML_Char *encoding); /* Constructs a new parser and namespace processor. Element type names and attribute names that belong to a namespace will be @@ -227,8 +186,8 @@ XML_ParserCreate(const XML_Char *encoding); It is a programming error to use the separator '\0' with namespace triplets (see XML_SetReturnNSTriplet). */ -XMLPARSEAPI(XML_Parser) -XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator); +XML_Parser XML_ParserCreateNS(const XML_Char *encoding, + XML_Char namespaceSeparator); /* Constructs a new parser using the memory management suite referred to by memsuite. If memsuite is NULL, then use the standard library memory @@ -239,10 +198,9 @@ XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator); All further memory operations used for the created parser will come from the given suite. */ -XMLPARSEAPI(XML_Parser) -XML_ParserCreate_MM(const XML_Char *encoding, - const XML_Memory_Handling_Suite *memsuite, - const XML_Char *namespaceSeparator); +XML_Parser XML_ParserCreate_MM(const XML_Char *encoding, + const XML_Memory_Handling_Suite *memsuite, + const XML_Char *namespaceSeparator); /* Prepare a parser object to be re-used. This is particularly valuable when memory allocation overhead is disproportionately high, @@ -253,33 +211,30 @@ XML_ParserCreate_MM(const XML_Char *encoding, Added in Expat 1.95.3. */ -XMLPARSEAPI(XML_Bool) -XML_ParserReset(XML_Parser parser, const XML_Char *encoding); +XML_Bool XML_ParserReset(XML_Parser parser, const XML_Char *encoding); /* atts is array of name/value pairs, terminated by 0; names and values are 0 terminated. */ -typedef void(XMLCALL *XML_StartElementHandler)(void *userData, - const XML_Char *name, - const XML_Char **atts); +typedef void (*XML_StartElementHandler)(void *userData, const XML_Char *name, + const XML_Char **atts); -typedef void(XMLCALL *XML_EndElementHandler)(void *userData, - const XML_Char *name); +typedef void (*XML_EndElementHandler)(void *userData, const XML_Char *name); /* s is not 0 terminated. */ -typedef void(XMLCALL *XML_CharacterDataHandler)(void *userData, - const XML_Char *s, int len); +typedef void (*XML_CharacterDataHandler)(void *userData, const XML_Char *s, + int len); /* target and data are 0 terminated */ -typedef void(XMLCALL *XML_ProcessingInstructionHandler)(void *userData, - const XML_Char *target, - const XML_Char *data); +typedef void (*XML_ProcessingInstructionHandler)(void *userData, + const XML_Char *target, + const XML_Char *data); /* data is 0 terminated */ -typedef void(XMLCALL *XML_CommentHandler)(void *userData, const XML_Char *data); +typedef void (*XML_CommentHandler)(void *userData, const XML_Char *data); -typedef void(XMLCALL *XML_StartCdataSectionHandler)(void *userData); -typedef void(XMLCALL *XML_EndCdataSectionHandler)(void *userData); +typedef void (*XML_StartCdataSectionHandler)(void *userData); +typedef void (*XML_EndCdataSectionHandler)(void *userData); /* This is called for any characters in the XML document for which there is no applicable handler. This includes both characters that @@ -294,23 +249,22 @@ typedef void(XMLCALL *XML_EndCdataSectionHandler)(void *userData); default handler: for example, a comment might be split between multiple calls. */ -typedef void(XMLCALL *XML_DefaultHandler)(void *userData, const XML_Char *s, - int len); +typedef void (*XML_DefaultHandler)(void *userData, const XML_Char *s, int len); /* This is called for the start of the DOCTYPE declaration, before any DTD or internal subset is parsed. */ -typedef void(XMLCALL *XML_StartDoctypeDeclHandler)(void *userData, - const XML_Char *doctypeName, - const XML_Char *sysid, - const XML_Char *pubid, - int has_internal_subset); +typedef void (*XML_StartDoctypeDeclHandler)(void *userData, + const XML_Char *doctypeName, + const XML_Char *sysid, + const XML_Char *pubid, + int has_internal_subset); /* This is called for the start of the DOCTYPE declaration when the closing > is encountered, but after processing any external subset. */ -typedef void(XMLCALL *XML_EndDoctypeDeclHandler)(void *userData); +typedef void (*XML_EndDoctypeDeclHandler)(void *userData); /* This is called for entity declarations. The is_parameter_entity argument will be non-zero if the entity is a parameter entity, zero @@ -330,14 +284,13 @@ typedef void(XMLCALL *XML_EndDoctypeDeclHandler)(void *userData); Note that is_parameter_entity can't be changed to XML_Bool, since that would break binary compatibility. */ -typedef void(XMLCALL *XML_EntityDeclHandler)( +typedef void (*XML_EntityDeclHandler)( void *userData, const XML_Char *entityName, int is_parameter_entity, const XML_Char *value, int value_length, const XML_Char *base, const XML_Char *systemId, const XML_Char *publicId, const XML_Char *notationName); -XMLPARSEAPI(void) -XML_SetEntityDeclHandler(XML_Parser parser, XML_EntityDeclHandler handler); +void XML_SetEntityDeclHandler(XML_Parser parser, XML_EntityDeclHandler handler); /* OBSOLETE -- OBSOLETE -- OBSOLETE This handler has been superseded by the EntityDeclHandler above. @@ -348,20 +301,22 @@ XML_SetEntityDeclHandler(XML_Parser parser, XML_EntityDeclHandler handler); entityName, systemId and notationName arguments will never be NULL. The other arguments may be. */ -typedef void(XMLCALL *XML_UnparsedEntityDeclHandler)( - void *userData, const XML_Char *entityName, const XML_Char *base, - const XML_Char *systemId, const XML_Char *publicId, - const XML_Char *notationName); +typedef void (*XML_UnparsedEntityDeclHandler)(void *userData, + const XML_Char *entityName, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId, + const XML_Char *notationName); /* This is called for a declaration of notation. The base argument is whatever was set by XML_SetBase. The notationName will never be NULL. The other arguments can be. */ -typedef void(XMLCALL *XML_NotationDeclHandler)(void *userData, - const XML_Char *notationName, - const XML_Char *base, - const XML_Char *systemId, - const XML_Char *publicId); +typedef void (*XML_NotationDeclHandler)(void *userData, + const XML_Char *notationName, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); /* When namespace processing is enabled, these are called once for each namespace declaration. The call to the start and end element @@ -369,12 +324,12 @@ typedef void(XMLCALL *XML_NotationDeclHandler)(void *userData, declaration handlers. For an xmlns attribute, prefix will be NULL. For an xmlns="" attribute, uri will be NULL. */ -typedef void(XMLCALL *XML_StartNamespaceDeclHandler)(void *userData, - const XML_Char *prefix, - const XML_Char *uri); +typedef void (*XML_StartNamespaceDeclHandler)(void *userData, + const XML_Char *prefix, + const XML_Char *uri); -typedef void(XMLCALL *XML_EndNamespaceDeclHandler)(void *userData, - const XML_Char *prefix); +typedef void (*XML_EndNamespaceDeclHandler)(void *userData, + const XML_Char *prefix); /* This is called if the document is not standalone, that is, it has an external subset or a reference to a parameter entity, but does not @@ -385,7 +340,7 @@ typedef void(XMLCALL *XML_EndNamespaceDeclHandler)(void *userData, conditions above this handler will only be called if the referenced entity was actually read. */ -typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData); +typedef int (*XML_NotStandaloneHandler)(void *userData); /* This is called for a reference to an external parsed general entity. The referenced entity is not automatically parsed. The @@ -421,25 +376,25 @@ typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData); Note that unlike other handlers the first argument is the parser, not userData. */ -typedef int(XMLCALL *XML_ExternalEntityRefHandler)(XML_Parser parser, - const XML_Char *context, - const XML_Char *base, - const XML_Char *systemId, - const XML_Char *publicId); +typedef int (*XML_ExternalEntityRefHandler)(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); /* This is called in two situations: 1) An entity reference is encountered for which no declaration - has been read *and* this is not an error. + has been read *and* this is not an error. 2) An internal entity reference is read, but not expanded, because - XML_SetDefaultHandler has been called. + XML_SetDefaultHandler has been called. Note: skipped parameter entities in declarations and skipped general - entities in attribute values cannot be reported, because - the event would be out of sync with the reporting of the - declarations or attribute values + entities in attribute values cannot be reported, because + the event would be out of sync with the reporting of the + declarations or attribute values */ -typedef void(XMLCALL *XML_SkippedEntityHandler)(void *userData, - const XML_Char *entityName, - int is_parameter_entity); +typedef void (*XML_SkippedEntityHandler)(void *userData, + const XML_Char *entityName, + int is_parameter_entity); /* This structure is filled in by the XML_UnknownEncodingHandler to provide information to the parser about encodings that are unknown @@ -476,28 +431,28 @@ typedef void(XMLCALL *XML_SkippedEntityHandler)(void *userData, using this mechanism. 1. Every ASCII character that can appear in a well-formed XML document, - other than the characters + other than the characters - $@\^`{}~ + $@\^`{}~ - must be represented by a single byte, and that byte must be the - same byte that represents that character in ASCII. + must be represented by a single byte, and that byte must be the + same byte that represents that character in ASCII. 2. No character may require more than 4 bytes to encode. 3. All characters encoded must have Unicode scalar values <= - 0xFFFF, (i.e., characters that would be encoded by surrogates in - UTF-16 are not allowed). Note that this restriction doesn't - apply to the built-in support for UTF-8 and UTF-16. + 0xFFFF, (i.e., characters that would be encoded by surrogates in + UTF-16 are not allowed). Note that this restriction doesn't + apply to the built-in support for UTF-8 and UTF-16. 4. No Unicode character may be encoded by more than one distinct - sequence of bytes. + sequence of bytes. */ typedef struct { int map[256]; void *data; - int(XMLCALL *convert)(void *data, const char *s); - void(XMLCALL *release)(void *data); + int (*convert)(void *data, const char *s); + void (*release)(void *data); } XML_Encoding; /* This is called for an encoding that is unknown to the parser. @@ -515,118 +470,97 @@ typedef struct { If info does not describe a suitable encoding, then the parser will return an XML_UNKNOWN_ENCODING error. */ -typedef int(XMLCALL *XML_UnknownEncodingHandler)(void *encodingHandlerData, - const XML_Char *name, - XML_Encoding *info); +typedef int (*XML_UnknownEncodingHandler)(void *encodingHandlerData, + const XML_Char *name, + XML_Encoding *info); -XMLPARSEAPI(void) -XML_SetElementHandler(XML_Parser parser, XML_StartElementHandler start, - XML_EndElementHandler end); +void XML_SetElementHandler(XML_Parser parser, XML_StartElementHandler start, + XML_EndElementHandler end); -XMLPARSEAPI(void) -XML_SetStartElementHandler(XML_Parser parser, XML_StartElementHandler handler); +void XML_SetStartElementHandler(XML_Parser parser, + XML_StartElementHandler handler); -XMLPARSEAPI(void) -XML_SetEndElementHandler(XML_Parser parser, XML_EndElementHandler handler); +void XML_SetEndElementHandler(XML_Parser parser, XML_EndElementHandler handler); -XMLPARSEAPI(void) -XML_SetCharacterDataHandler(XML_Parser parser, - XML_CharacterDataHandler handler); +void XML_SetCharacterDataHandler(XML_Parser parser, + XML_CharacterDataHandler handler); -XMLPARSEAPI(void) -XML_SetProcessingInstructionHandler(XML_Parser parser, - XML_ProcessingInstructionHandler handler); -XMLPARSEAPI(void) -XML_SetCommentHandler(XML_Parser parser, XML_CommentHandler handler); +void XML_SetProcessingInstructionHandler( + XML_Parser parser, XML_ProcessingInstructionHandler handler); +void XML_SetCommentHandler(XML_Parser parser, XML_CommentHandler handler); -XMLPARSEAPI(void) -XML_SetCdataSectionHandler(XML_Parser parser, - XML_StartCdataSectionHandler start, - XML_EndCdataSectionHandler end); +void XML_SetCdataSectionHandler(XML_Parser parser, + XML_StartCdataSectionHandler start, + XML_EndCdataSectionHandler end); -XMLPARSEAPI(void) -XML_SetStartCdataSectionHandler(XML_Parser parser, - XML_StartCdataSectionHandler start); +void XML_SetStartCdataSectionHandler(XML_Parser parser, + XML_StartCdataSectionHandler start); -XMLPARSEAPI(void) -XML_SetEndCdataSectionHandler(XML_Parser parser, - XML_EndCdataSectionHandler end); +void XML_SetEndCdataSectionHandler(XML_Parser parser, + XML_EndCdataSectionHandler end); /* This sets the default handler and also inhibits expansion of internal entities. These entity references will be passed to the default handler, or to the skipped entity handler, if one is set. */ -XMLPARSEAPI(void) -XML_SetDefaultHandler(XML_Parser parser, XML_DefaultHandler handler); +void XML_SetDefaultHandler(XML_Parser parser, XML_DefaultHandler handler); /* This sets the default handler but does not inhibit expansion of internal entities. The entity reference will not be passed to the default handler. */ -XMLPARSEAPI(void) -XML_SetDefaultHandlerExpand(XML_Parser parser, XML_DefaultHandler handler); +void XML_SetDefaultHandlerExpand(XML_Parser parser, XML_DefaultHandler handler); -XMLPARSEAPI(void) -XML_SetDoctypeDeclHandler(XML_Parser parser, XML_StartDoctypeDeclHandler start, - XML_EndDoctypeDeclHandler end); +void XML_SetDoctypeDeclHandler(XML_Parser parser, + XML_StartDoctypeDeclHandler start, + XML_EndDoctypeDeclHandler end); -XMLPARSEAPI(void) -XML_SetStartDoctypeDeclHandler(XML_Parser parser, - XML_StartDoctypeDeclHandler start); +void XML_SetStartDoctypeDeclHandler(XML_Parser parser, + XML_StartDoctypeDeclHandler start); -XMLPARSEAPI(void) -XML_SetEndDoctypeDeclHandler(XML_Parser parser, XML_EndDoctypeDeclHandler end); +void XML_SetEndDoctypeDeclHandler(XML_Parser parser, + XML_EndDoctypeDeclHandler end); -XMLPARSEAPI(void) -XML_SetUnparsedEntityDeclHandler(XML_Parser parser, - XML_UnparsedEntityDeclHandler handler); +void XML_SetUnparsedEntityDeclHandler(XML_Parser parser, + XML_UnparsedEntityDeclHandler handler); -XMLPARSEAPI(void) -XML_SetNotationDeclHandler(XML_Parser parser, XML_NotationDeclHandler handler); +void XML_SetNotationDeclHandler(XML_Parser parser, + XML_NotationDeclHandler handler); -XMLPARSEAPI(void) -XML_SetNamespaceDeclHandler(XML_Parser parser, - XML_StartNamespaceDeclHandler start, - XML_EndNamespaceDeclHandler end); +void XML_SetNamespaceDeclHandler(XML_Parser parser, + XML_StartNamespaceDeclHandler start, + XML_EndNamespaceDeclHandler end); -XMLPARSEAPI(void) -XML_SetStartNamespaceDeclHandler(XML_Parser parser, - XML_StartNamespaceDeclHandler start); +void XML_SetStartNamespaceDeclHandler(XML_Parser parser, + XML_StartNamespaceDeclHandler start); -XMLPARSEAPI(void) -XML_SetEndNamespaceDeclHandler(XML_Parser parser, - XML_EndNamespaceDeclHandler end); +void XML_SetEndNamespaceDeclHandler(XML_Parser parser, + XML_EndNamespaceDeclHandler end); -XMLPARSEAPI(void) -XML_SetNotStandaloneHandler(XML_Parser parser, - XML_NotStandaloneHandler handler); +void XML_SetNotStandaloneHandler(XML_Parser parser, + XML_NotStandaloneHandler handler); -XMLPARSEAPI(void) -XML_SetExternalEntityRefHandler(XML_Parser parser, - XML_ExternalEntityRefHandler handler); +void XML_SetExternalEntityRefHandler(XML_Parser parser, + XML_ExternalEntityRefHandler handler); /* If a non-NULL value for arg is specified here, then it will be passed as the first argument to the external entity ref handler instead of the parser object. */ -XMLPARSEAPI(void) -XML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg); +void XML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg); -XMLPARSEAPI(void) -XML_SetSkippedEntityHandler(XML_Parser parser, - XML_SkippedEntityHandler handler); +void XML_SetSkippedEntityHandler(XML_Parser parser, + XML_SkippedEntityHandler handler); -XMLPARSEAPI(void) -XML_SetUnknownEncodingHandler(XML_Parser parser, - XML_UnknownEncodingHandler handler, - void *encodingHandlerData); +void XML_SetUnknownEncodingHandler(XML_Parser parser, + XML_UnknownEncodingHandler handler, + void *encodingHandlerData); /* This can be called within a handler for a start element, end element, processing instruction or character data. It causes the corresponding markup to be passed to the default handler. */ -XMLPARSEAPI(void) -XML_DefaultCurrent(XML_Parser parser); +void XML_DefaultCurrent(XML_Parser parser); /* If do_nst is non-zero, and namespace processing is in effect, and a name has a prefix (i.e. an explicit namespace qualifier) then @@ -639,15 +573,13 @@ XML_DefaultCurrent(XML_Parser parser); has a prefix. Note: Calling XML_SetReturnNSTriplet after XML_Parse or - XML_ParseBuffer has no effect. + XML_ParseBuffer has no effect. */ -XMLPARSEAPI(void) -XML_SetReturnNSTriplet(XML_Parser parser, int do_nst); +void XML_SetReturnNSTriplet(XML_Parser parser, int do_nst); /* This value is passed as the userData argument to callbacks. */ -XMLPARSEAPI(void) -XML_SetUserData(XML_Parser parser, void *userData); +void XML_SetUserData(XML_Parser parser, void *userData); /* Returns the last value set by XML_SetUserData or NULL. */ #define XML_GetUserData(parser) (*(void **)(parser)) @@ -656,17 +588,15 @@ XML_SetUserData(XML_Parser parser, void *userData); XML_ParserCreate. On success XML_SetEncoding returns non-zero, zero otherwise. Note: Calling XML_SetEncoding after XML_Parse or XML_ParseBuffer - has no effect and returns XML_STATUS_ERROR. + has no effect and returns XML_STATUS_ERROR. */ -XMLPARSEAPI(enum XML_Status) -XML_SetEncoding(XML_Parser parser, const XML_Char *encoding); +enum XML_Status XML_SetEncoding(XML_Parser parser, const XML_Char *encoding); /* If this function is called, then the parser will be passed as the first argument to callbacks instead of userData. The userData will still be accessible using XML_GetUserData. */ -XMLPARSEAPI(void) -XML_UseParserAsHandlerArg(XML_Parser parser); +void XML_UseParserAsHandlerArg(XML_Parser parser); /* If useDTD == XML_TRUE is passed to this function, then the parser will assume that there is an external subset, even if none is @@ -674,21 +604,20 @@ XML_UseParserAsHandlerArg(XML_Parser parser); externalEntityRefHandler with a value of NULL for the systemId argument (the publicId and context arguments will be NULL as well). Note: For the purpose of checking WFC: Entity Declared, passing - useDTD == XML_TRUE will make the parser behave as if the document - had a DTD with an external subset. + useDTD == XML_TRUE will make the parser behave as if the document + had a DTD with an external subset. Note: If this function is called, then this must be done before - the first call to XML_Parse or XML_ParseBuffer, since it will - have no effect after that. Returns - XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING. + the first call to XML_Parse or XML_ParseBuffer, since it will + have no effect after that. Returns + XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING. Note: If the document does not have a DOCTYPE declaration at all, - then startDoctypeDeclHandler and endDoctypeDeclHandler will not - be called, despite an external subset being parsed. + then startDoctypeDeclHandler and endDoctypeDeclHandler will not + be called, despite an external subset being parsed. Note: If XML_DTD is not defined when Expat is compiled, returns - XML_ERROR_FEATURE_REQUIRES_XML_DTD. + XML_ERROR_FEATURE_REQUIRES_XML_DTD. Note: If parser == NULL, returns XML_ERROR_INVALID_ARGUMENT. */ -XMLPARSEAPI(enum XML_Error) -XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD); +enum XML_Error XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD); /* Sets the base to be used for resolving relative URIs in system identifiers in declarations. Resolving relative identifiers is @@ -698,11 +627,9 @@ XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD); argument will be copied. Returns XML_STATUS_ERROR if out of memory, XML_STATUS_OK otherwise. */ -XMLPARSEAPI(enum XML_Status) -XML_SetBase(XML_Parser parser, const XML_Char *base); +enum XML_Status XML_SetBase(XML_Parser parser, const XML_Char *base); -XMLPARSEAPI(const XML_Char *) -XML_GetBase(XML_Parser parser); +const XML_Char *XML_GetBase(XML_Parser parser); /* Returns the number of the attribute/value pairs passed in last call to the XML_StartElementHandler that were specified in the start-tag @@ -710,8 +637,7 @@ XML_GetBase(XML_Parser parser); this correspondds to an index into the atts array passed to the XML_StartElementHandler. Returns -1 if parser == NULL. */ -XMLPARSEAPI(int) -XML_GetSpecifiedAttributeCount(XML_Parser parser); +int XML_GetSpecifiedAttributeCount(XML_Parser parser); /* Returns the index of the ID attribute passed in the last call to XML_StartElementHandler, or -1 if there is no ID attribute or @@ -719,8 +645,7 @@ XML_GetSpecifiedAttributeCount(XML_Parser parser); correspondds to an index into the atts array passed to the XML_StartElementHandler. */ -XMLPARSEAPI(int) -XML_GetIdAttributeIndex(XML_Parser parser); +int XML_GetIdAttributeIndex(XML_Parser parser); #ifdef XML_ATTR_INFO /* Source file byte offsets for the start and end of attribute names and values. @@ -741,8 +666,7 @@ typedef struct { as 1; thus the number of entries in the array is XML_GetSpecifiedAttributeCount(parser) / 2. */ -XMLPARSEAPI(const XML_AttrInfo *) -XML_GetAttributeInfo(XML_Parser parser); +const XML_AttrInfo *XML_GetAttributeInfo(XML_Parser parser); #endif /* Parses some input. Returns XML_STATUS_ERROR if a fatal error is @@ -754,21 +678,19 @@ XML_GetAttributeInfo(XML_Parser parser); 1.95.x series, has always returned exactly one of the XML_Status values. */ -XMLPARSEAPI(enum XML_Status) -XML_Parse(XML_Parser parser, const char *s, int len, int isFinal); +enum XML_Status XML_Parse(XML_Parser parser, const char *s, int len, + int isFinal); -XMLPARSEAPI(void *) -XML_GetBuffer(XML_Parser parser, int len); +void *XML_GetBuffer(XML_Parser parser, int len); -XMLPARSEAPI(enum XML_Status) -XML_ParseBuffer(XML_Parser parser, int len, int isFinal); +enum XML_Status XML_ParseBuffer(XML_Parser parser, int len, int isFinal); /* Stops parsing, causing XML_Parse() or XML_ParseBuffer() to return. Must be called from within a call-back handler, except when aborting (resumable = 0) an already suspended parser. Some call-backs may still follow because they would otherwise get lost. Examples: - endElementHandler() for empty elements when stopped in - startElementHandler(), + startElementHandler(), - endNameSpaceDeclHandler() when stopped in endElementHandler(), and possibly others. @@ -794,8 +716,7 @@ XML_ParseBuffer(XML_Parser parser, int len, int isFinal); When suspended, parsing can be resumed by calling XML_ResumeParser(). */ -XMLPARSEAPI(enum XML_Status) -XML_StopParser(XML_Parser parser, XML_Bool resumable); +enum XML_Status XML_StopParser(XML_Parser parser, XML_Bool resumable); /* Resumes parsing after it has been suspended with XML_StopParser(). Must not be called from within a handler call-back. Returns same @@ -809,8 +730,7 @@ XML_StopParser(XML_Parser parser, XML_Bool resumable); That is, the parent parser will not resume by itself and it is up to the application to call XML_ResumeParser() on it at the appropriate moment. */ -XMLPARSEAPI(enum XML_Status) -XML_ResumeParser(XML_Parser parser); +enum XML_Status XML_ResumeParser(XML_Parser parser); enum XML_Parsing { XML_INITIALIZED, XML_PARSING, XML_FINISHED, XML_SUSPENDED }; @@ -824,8 +744,7 @@ typedef struct { XXX XML_Parse() and XML_ParseBuffer() should return XML_ParsingStatus, XXX with XML_FINISHED_OK or XML_FINISHED_ERROR replacing XML_FINISHED */ -XMLPARSEAPI(void) -XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status); +void XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status); /* Creates an XML_Parser object that can parse an external general entity; context is a '\0'-terminated string specifying the parse @@ -843,9 +762,9 @@ XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status); initialized from the parser argument. Returns NULL if out of memory. Otherwise returns a new XML_Parser object. */ -XMLPARSEAPI(XML_Parser) -XML_ExternalEntityParserCreate(XML_Parser parser, const XML_Char *context, - const XML_Char *encoding); +XML_Parser XML_ExternalEntityParserCreate(XML_Parser parser, + const XML_Char *context, + const XML_Char *encoding); enum XML_ParamEntityParsing { XML_PARAM_ENTITY_PARSING_NEVER, @@ -874,12 +793,11 @@ enum XML_ParamEntityParsing { XML_SetParamEntityParsing will return 0 if parsing of parameter entities is requested; otherwise it will return non-zero. Note: If XML_SetParamEntityParsing is called after XML_Parse or - XML_ParseBuffer, then it has no effect and will always return 0. + XML_ParseBuffer, then it has no effect and will always return 0. Note: If parser == NULL, the function will do nothing and return 0. */ -XMLPARSEAPI(int) -XML_SetParamEntityParsing(XML_Parser parser, - enum XML_ParamEntityParsing parsing); +int XML_SetParamEntityParsing(XML_Parser parser, + enum XML_ParamEntityParsing parsing); /* Sets the hash salt to use for internal hash calculations. Helps in preventing DoS attacks based on predicting hash @@ -887,14 +805,12 @@ XML_SetParamEntityParsing(XML_Parser parser, Returns 1 if successful, 0 when called after parsing has started. Note: If parser == NULL, the function will do nothing and return 0. */ -XMLPARSEAPI(int) -XML_SetHashSalt(XML_Parser parser, unsigned long hash_salt); +int XML_SetHashSalt(XML_Parser parser, unsigned long hash_salt); /* If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then XML_GetErrorCode returns information about the error. */ -XMLPARSEAPI(enum XML_Error) -XML_GetErrorCode(XML_Parser parser); +enum XML_Error XML_GetErrorCode(XML_Parser parser); /* These functions return information about the current parse location. They may be called from any callback called to report @@ -916,15 +832,14 @@ XML_GetErrorCode(XML_Parser parser); return 0 to indicate an error. Note: XML_GetCurrentByteIndex returns -1 to indicate an error. */ -XMLPARSEAPI(XML_Size) XML_GetCurrentLineNumber(XML_Parser parser); -XMLPARSEAPI(XML_Size) XML_GetCurrentColumnNumber(XML_Parser parser); -XMLPARSEAPI(XML_Index) XML_GetCurrentByteIndex(XML_Parser parser); +XML_Size XML_GetCurrentLineNumber(XML_Parser parser); +XML_Size XML_GetCurrentColumnNumber(XML_Parser parser); +XML_Index XML_GetCurrentByteIndex(XML_Parser parser); /* Return the number of bytes in the current event. Returns 0 if the event is in an internal entity. */ -XMLPARSEAPI(int) -XML_GetCurrentByteCount(XML_Parser parser); +int XML_GetCurrentByteCount(XML_Parser parser); /* If XML_CONTEXT_BYTES is defined, returns the input buffer, sets the integer pointed to by offset to the offset within this buffer @@ -936,42 +851,33 @@ XML_GetCurrentByteCount(XML_Parser parser); NOTE: The character pointer returned should not be used outside the handler that makes the call. */ -XMLPARSEAPI(const char *) -XML_GetInputContext(XML_Parser parser, int *offset, int *size); +const char *XML_GetInputContext(XML_Parser parser, int *offset, int *size); /* For backwards compatibility with previous versions. */ -#define XML_GetErrorLineNumber XML_GetCurrentLineNumber +#define XML_GetErrorLineNumber XML_GetCurrentLineNumber #define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber -#define XML_GetErrorByteIndex XML_GetCurrentByteIndex +#define XML_GetErrorByteIndex XML_GetCurrentByteIndex /* Frees the content model passed to the element declaration handler */ -XMLPARSEAPI(void) -XML_FreeContentModel(XML_Parser parser, XML_Content *model); +void XML_FreeContentModel(XML_Parser parser, XML_Content *model); /* Exposing the memory handling functions used in Expat */ -XMLPARSEAPI(void *) -XML_ATTR_MALLOC -XML_ATTR_ALLOC_SIZE(2) -XML_MemMalloc(XML_Parser parser, size_t size); +void *XML_ATTR_MALLOC XML_ATTR_ALLOC_SIZE(2) + XML_MemMalloc(XML_Parser parser, size_t size); -XMLPARSEAPI(void *) -XML_ATTR_ALLOC_SIZE(3) -XML_MemRealloc(XML_Parser parser, void *ptr, size_t size); +void *XML_ATTR_ALLOC_SIZE(3) + XML_MemRealloc(XML_Parser parser, void *ptr, size_t size); -XMLPARSEAPI(void) -XML_MemFree(XML_Parser parser, void *ptr); +void XML_MemFree(XML_Parser parser, void *ptr); /* Frees memory used by the parser. */ -XMLPARSEAPI(void) -XML_ParserFree(XML_Parser parser); +void XML_ParserFree(XML_Parser parser); /* Returns a string describing the error. */ -XMLPARSEAPI(const XML_LChar *) -XML_ErrorString(enum XML_Error code); +const XML_LChar *XML_ErrorString(enum XML_Error code); /* Return a string containing the version number of this expat */ -XMLPARSEAPI(const XML_LChar *) -XML_ExpatVersion(void); +const XML_LChar *XML_ExpatVersion(void); typedef struct { int major; @@ -982,8 +888,7 @@ typedef struct { /* Return an XML_Expat_Version structure containing numeric version number information for this version of expat. */ -XMLPARSEAPI(XML_Expat_Version) -XML_ExpatVersionInfo(void); +XML_Expat_Version XML_ExpatVersionInfo(void); /* Added in Expat 1.95.5. */ enum XML_FeatureEnum { @@ -1007,8 +912,7 @@ typedef struct { long int value; } XML_Feature; -XMLPARSEAPI(const XML_Feature *) -XML_GetFeatureList(void); +const XML_Feature *XML_GetFeatureList(void); /* Expat follows the semantic versioning convention. See http://semver.org. @@ -1017,8 +921,5 @@ XML_GetFeatureList(void); #define XML_MINOR_VERSION 2 #define XML_MICRO_VERSION 8 -#ifdef __cplusplus -} -#endif - +COSMOPOLITAN_C_END_ #endif /* not Expat_INCLUDED */ diff --git a/third_party/python/Modules/expat/expat_external.h b/third_party/python/Modules/expat/expat_external.h index 2997880ad..349b2198f 100644 --- a/third_party/python/Modules/expat/expat_external.h +++ b/third_party/python/Modules/expat/expat_external.h @@ -1,111 +1,8 @@ -/* clang-format off */ -/* - __ __ _ - ___\ \/ /_ __ __ _| |_ - / _ \\ /| '_ \ / _` | __| - | __// \| |_) | (_| | |_ - \___/_/\_\ .__/ \__,_|\__| - |_| XML parser - - Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team - Licensed under the MIT license: - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to permit - persons to whom the Software is furnished to do so, subject to the - following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - #ifndef Expat_External_INCLUDED #define Expat_External_INCLUDED 1 - -/* External API definitions */ - -/* Expat tries very hard to make the API boundary very specifically - defined. There are two macros defined to control this boundary; - each of these can be defined before including this header to - achieve some different behavior, but doing so it not recommended or - tested frequently. - - XMLCALL - The calling convention to use for all calls across the - "library boundary." This will default to cdecl, and - try really hard to tell the compiler that's what we - want. - - XMLIMPORT - Whatever magic is needed to note that a function is - to be imported from a dynamically loaded library - (.dll, .so, or .sl, depending on your platform). - - The XMLCALL macro was added in Expat 1.95.7. The only one which is - expected to be directly useful in client code is XMLCALL. - - Note that on at least some Unix versions, the Expat library must be - compiled with the cdecl calling convention as the default since - system headers may assume the cdecl convention. -*/ - -/* Namespace external symbols to allow multiple libexpat version to - co-exist. */ -#include "pyexpatns.h" - -#ifndef XMLCALL -# if defined(_MSC_VER) -# define XMLCALL __cdecl -# elif defined(__GNUC__) && defined(__i386) && ! defined(__INTEL_COMPILER) -# define XMLCALL __attribute__((cdecl)) -# else -/* For any platform which uses this definition and supports more than - one calling convention, we need to extend this definition to - declare the convention used on that platform, if it's possible to - do so. - - If this is the case for your platform, please file a bug report - with information on how to identify your platform via the C - pre-processor and how to specify the same calling convention as the - platform's malloc() implementation. -*/ -# define XMLCALL -# endif -#endif /* not defined XMLCALL */ - -#if ! defined(XML_STATIC) && ! defined(XMLIMPORT) -# ifndef XML_BUILDING_EXPAT -/* using Expat from an application */ - -# if defined(_MSC_EXTENSIONS) && ! defined(__BEOS__) && ! defined(__CYGWIN__) -# define XMLIMPORT __declspec(dllimport) -# endif - -# endif -#endif /* not defined XML_STATIC */ - -#ifndef XML_ENABLE_VISIBILITY -# define XML_ENABLE_VISIBILITY 0 -#endif - -#if ! defined(XMLIMPORT) && XML_ENABLE_VISIBILITY -# define XMLIMPORT __attribute__((visibility("default"))) -#endif - -/* If we didn't define it above, define it away: */ -#ifndef XMLIMPORT -# define XMLIMPORT -#endif +#include "third_party/python/Modules/expat/pyexpatns.h" +COSMOPOLITAN_C_START_ +/* clang-format off */ #if defined(__GNUC__) \ && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)) @@ -121,44 +18,11 @@ # define XML_ATTR_ALLOC_SIZE(x) #endif -#define XMLPARSEAPI(type) XMLIMPORT type XMLCALL - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef XML_UNICODE_WCHAR_T -# ifndef XML_UNICODE -# define XML_UNICODE -# endif -# if defined(__SIZEOF_WCHAR_T__) && (__SIZEOF_WCHAR_T__ != 2) -# error "sizeof(wchar_t) != 2; Need -fshort-wchar for both Expat and libc" -# endif -#endif - -#ifdef XML_UNICODE /* Information is UTF-16 encoded. */ -# ifdef XML_UNICODE_WCHAR_T -typedef wchar_t XML_Char; -typedef wchar_t XML_LChar; -# else -typedef unsigned short XML_Char; -typedef char XML_LChar; -# endif /* XML_UNICODE_WCHAR_T */ -#else /* Information is UTF-8 encoded. */ typedef char XML_Char; typedef char XML_LChar; -#endif /* XML_UNICODE */ -#ifdef XML_LARGE_SIZE /* Use large integers for file/stream positions. */ typedef long long XML_Index; typedef unsigned long long XML_Size; -#else -typedef long XML_Index; -typedef unsigned long XML_Size; -#endif /* XML_LARGE_SIZE */ - -#ifdef __cplusplus -} -#endif +COSMOPOLITAN_C_END_ #endif /* not Expat_External_INCLUDED */ diff --git a/third_party/python/Modules/expat/iasciitab.h b/third_party/python/Modules/expat/iasciitab.inc similarity index 100% rename from third_party/python/Modules/expat/iasciitab.h rename to third_party/python/Modules/expat/iasciitab.inc diff --git a/third_party/python/Modules/expat/internal.h b/third_party/python/Modules/expat/internal.inc similarity index 81% rename from third_party/python/Modules/expat/internal.h rename to third_party/python/Modules/expat/internal.inc index 86622e32a..f724fc72e 100644 --- a/third_party/python/Modules/expat/internal.h +++ b/third_party/python/Modules/expat/internal.inc @@ -1,22 +1,6 @@ /* clang-format off */ /* internal.h - Internal definitions used by Expat. This is not needed to compile - client code. - - The following calling convention macros are defined for frequently - called functions: - - FASTCALL - Used for those internal functions that have a simple - body and a low number of arguments and local variables. - - PTRCALL - Used for functions called though function pointers. - - PTRFASTCALL - Like PTRCALL, but for low number of arguments. - - inline - Used for selected internal functions for which inlining - may improve performance on some platforms. - Note: Use of these macros is based on judgement, not hard rules, and therefore subject to change. __ __ _ @@ -74,18 +58,6 @@ /* Make sure all of these are defined if they aren't already. */ -#ifndef FASTCALL -# define FASTCALL -#endif - -#ifndef PTRCALL -# define PTRCALL -#endif - -#ifndef PTRFASTCALL -# define PTRFASTCALL -#endif - #ifndef XML_MIN_SIZE # if ! defined(__cplusplus) && ! defined(inline) # ifdef __GNUC__ diff --git a/third_party/python/Modules/expat/latin1tab.h b/third_party/python/Modules/expat/latin1tab.inc similarity index 100% rename from third_party/python/Modules/expat/latin1tab.h rename to third_party/python/Modules/expat/latin1tab.inc diff --git a/third_party/python/Modules/expat/nametab.h b/third_party/python/Modules/expat/nametab.inc similarity index 100% rename from third_party/python/Modules/expat/nametab.h rename to third_party/python/Modules/expat/nametab.inc diff --git a/third_party/python/Modules/expat/pyexpatns.h b/third_party/python/Modules/expat/pyexpatns.h index 5219f7bba..5d3f4c569 100644 --- a/third_party/python/Modules/expat/pyexpatns.h +++ b/third_party/python/Modules/expat/pyexpatns.h @@ -1,43 +1,6 @@ -/* clang-format off */ -/* Copyright (c) 2005-2006 ActiveState Software Inc. - * - * Namespace all expat exported symbols to avoid dynamic loading symbol - * collisions when embedding Python. - * - * The Problem: - * - you embed Python in some app - * - the app dynamically loads libexpat of version X - * - the embedded Python imports pyexpat (which was built against - * libexpat version X+n) - * --> pyexpat gets the expat symbols from the already loaded and *older* - * libexpat: crash (Specifically the crash we observed was in - * getting an old XML_ErrorString (from xmlparse.c) and then calling - * it with newer values in the XML_Error enum: - * - * // pyexpat.c, line 1970 - * ... - * // Added in Expat 1.95.7. - * MYCONST(XML_ERROR_UNBOUND_PREFIX); - * ... - * - * - * The Solution: - * Prefix all exported symbols with "PyExpat_". This is similar to - * what Mozilla does for some common libs: - * http://lxr.mozilla.org/seamonkey/source/modules/libimg/png/mozpngconf.h#115 - * - * The list of relevant exported symbols can be had with this command: - * - nm pyexpat.so \ - | grep -v " [a-zBUA] " \ - | grep -v "_fini\|_init\|initpyexpat" - * - * If any of those symbols are NOT prefixed with "PyExpat_" then - * a #define should be added for it here. - */ - #ifndef PYEXPATNS_H #define PYEXPATNS_H +/* clang-format off */ #define XML_DefaultCurrent PyExpat_XML_DefaultCurrent #define XML_ErrorString PyExpat_XML_ErrorString @@ -121,6 +84,4 @@ #define XmlUtf16Encode PyExpat_XmlUtf16Encode #define XmlUtf8Encode PyExpat_XmlUtf8Encode - #endif /* !PYEXPATNS_H */ - diff --git a/third_party/python/Modules/expat/siphash.h b/third_party/python/Modules/expat/siphash.inc similarity index 100% rename from third_party/python/Modules/expat/siphash.h rename to third_party/python/Modules/expat/siphash.inc diff --git a/third_party/python/Modules/expat/utf8tab.h b/third_party/python/Modules/expat/utf8tab.inc similarity index 100% rename from third_party/python/Modules/expat/utf8tab.h rename to third_party/python/Modules/expat/utf8tab.inc diff --git a/third_party/python/Modules/expat/winconfig.h b/third_party/python/Modules/expat/winconfig.h deleted file mode 100644 index 0cfdd9ba7..000000000 --- a/third_party/python/Modules/expat/winconfig.h +++ /dev/null @@ -1,57 +0,0 @@ -/* clang-format off */ -/* - __ __ _ - ___\ \/ /_ __ __ _| |_ - / _ \\ /| '_ \ / _` | __| - | __// \| |_) | (_| | |_ - \___/_/\_\ .__/ \__,_|\__| - |_| XML parser - - Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team - Licensed under the MIT license: - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to permit - persons to whom the Software is furnished to do so, subject to the - following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#ifndef WINCONFIG_H -#define WINCONFIG_H - -#define WIN32_LEAN_AND_MEAN -#include -#undef WIN32_LEAN_AND_MEAN - -#include -#include - -#if defined(HAVE_EXPAT_CONFIG_H) /* e.g. MinGW */ -# include -#else /* !defined(HAVE_EXPAT_CONFIG_H) */ - -# define XML_NS 1 -# define XML_DTD 1 -# define XML_CONTEXT_BYTES 1024 - -/* we will assume all Windows platforms are little endian */ -# define BYTEORDER 1234 - -#endif /* !defined(HAVE_EXPAT_CONFIG_H) */ - -#endif /* ndef WINCONFIG_H */ diff --git a/third_party/python/Modules/expat/xmlparse.c b/third_party/python/Modules/expat/xmlparse.c index 2ec05eb69..c5fa75b9b 100644 --- a/third_party/python/Modules/expat/xmlparse.c +++ b/third_party/python/Modules/expat/xmlparse.c @@ -31,14 +31,11 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#if !defined(_GNU_SOURCE) -#define _GNU_SOURCE 1 /* syscall prototype */ -#endif - -#ifdef _WIN32 -/* force stdlib to define rand_s() */ -#define _CRT_RAND_S -#endif +asm(".ident\t\"\\n\\n\ +expat (MIT License)\\n\ +Copyright (c) 1997-2000 Thai Open Source Software Center Ltd\\n\ +Copyright (c) 2000-2017 Expat development team\""); +asm(".include \"libc/disclaimer.inc\""); #define XML_BUILDING_EXPAT 1 @@ -55,12 +52,12 @@ #include "libc/calls/calls.h" #include "libc/assert.h" #include "libc/limits.h" -#include "expat_config.h" +#include "third_party/python/Modules/expat/expat_config.h" #endif -#include "ascii.h" -#include "expat.h" -#include "siphash.h" +#include "third_party/python/Modules/expat/ascii.inc" +#include "third_party/python/Modules/expat/expat.h" +#include "third_party/python/Modules/expat/siphash.inc" #if defined(_WIN32) && !defined(LOAD_LIBRARY_SEARCH_SYSTEM32) #define LOAD_LIBRARY_SEARCH_SYSTEM32 0x00000800 @@ -119,9 +116,9 @@ typedef char ICHAR; /* Do safe (NULL-aware) pointer arithmetic */ #define EXPAT_SAFE_PTR_DIFF(p, q) (((p) && (q)) ? ((p) - (q)) : 0) -#include "internal.h" -#include "xmlrole.h" -#include "xmltok.h" +#include "third_party/python/Modules/expat/internal.inc" +#include "third_party/python/Modules/expat/xmlrole.h" +#include "third_party/python/Modules/expat/xmltok.h" typedef const XML_Char *KEY; @@ -324,7 +321,7 @@ typedef struct open_internal_entity { XML_Bool betweenDecl; /* WFC: PE Between Declarations */ } OPEN_INTERNAL_ENTITY; -typedef enum XML_Error PTRCALL Processor(XML_Parser parser, const char *start, +typedef enum XML_Error Processor(XML_Parser parser, const char *start, const char *end, const char **endPtr); static Processor prologProcessor; @@ -401,7 +398,7 @@ static void reportDefault(XML_Parser parser, const ENCODING *enc, static const XML_Char *getContext(XML_Parser parser); static XML_Bool setContext(XML_Parser parser, const XML_Char *context); -static void FASTCALL normalizePublicId(XML_Char *s); +static void normalizePublicId(XML_Char *s); static DTD *dtdCreate(const XML_Memory_Handling_Suite *ms); /* do not call if m_parentParser != NULL */ @@ -414,30 +411,30 @@ static int copyEntityTable(XML_Parser oldParser, HASH_TABLE *, STRING_POOL *, const HASH_TABLE *); static NAMED *lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize); -static void FASTCALL hashTableInit(HASH_TABLE *, +static void hashTableInit(HASH_TABLE *, const XML_Memory_Handling_Suite *ms); -static void FASTCALL hashTableClear(HASH_TABLE *); -static void FASTCALL hashTableDestroy(HASH_TABLE *); -static void FASTCALL hashTableIterInit(HASH_TABLE_ITER *, const HASH_TABLE *); -static NAMED *FASTCALL hashTableIterNext(HASH_TABLE_ITER *); +static void hashTableClear(HASH_TABLE *); +static void hashTableDestroy(HASH_TABLE *); +static void hashTableIterInit(HASH_TABLE_ITER *, const HASH_TABLE *); +static NAMED *hashTableIterNext(HASH_TABLE_ITER *); -static void FASTCALL poolInit(STRING_POOL *, +static void poolInit(STRING_POOL *, const XML_Memory_Handling_Suite *ms); -static void FASTCALL poolClear(STRING_POOL *); -static void FASTCALL poolDestroy(STRING_POOL *); +static void poolClear(STRING_POOL *); +static void poolDestroy(STRING_POOL *); static XML_Char *poolAppend(STRING_POOL *pool, const ENCODING *enc, const char *ptr, const char *end); static XML_Char *poolStoreString(STRING_POOL *pool, const ENCODING *enc, const char *ptr, const char *end); -static XML_Bool FASTCALL poolGrow(STRING_POOL *pool); -static const XML_Char *FASTCALL poolCopyString(STRING_POOL *pool, +static XML_Bool poolGrow(STRING_POOL *pool); +static const XML_Char *poolCopyString(STRING_POOL *pool, const XML_Char *s); static const XML_Char *poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n); -static const XML_Char *FASTCALL poolAppendString(STRING_POOL *pool, +static const XML_Char *poolAppendString(STRING_POOL *pool, const XML_Char *s); -static int FASTCALL nextScaffoldPart(XML_Parser parser); +static int nextScaffoldPart(XML_Parser parser); static XML_Content *build_model(XML_Parser parser); static ELEMENT_TYPE *getElementType(XML_Parser parser, const ENCODING *enc, const char *ptr, const char *end); @@ -515,7 +512,7 @@ struct XML_ParserStruct { void *m_unknownEncodingMem; void *m_unknownEncodingData; void *m_unknownEncodingHandlerData; - void(XMLCALL *m_unknownEncodingRelease)(void *); + void(*m_unknownEncodingRelease)(void *); PROLOG_STATE m_prologState; Processor *m_processor; enum XML_Error m_errorCode; @@ -573,12 +570,12 @@ struct XML_ParserStruct { #define REALLOC(parser, p, s) (parser->m_mem.realloc_fcn((p), (s))) #define FREE(parser, p) (parser->m_mem.free_fcn((p))) -XML_Parser XMLCALL XML_ParserCreate(const XML_Char *encodingName) { +XML_Parser XML_ParserCreate(const XML_Char *encodingName) { return XML_ParserCreate_MM(encodingName, NULL, NULL); } -XML_Parser XMLCALL XML_ParserCreateNS(const XML_Char *encodingName, - XML_Char nsSep) { +XML_Parser XML_ParserCreateNS(const XML_Char *encodingName, + XML_Char nsSep) { XML_Char tmp[2]; *tmp = nsSep; return XML_ParserCreate_MM(encodingName, NULL, tmp); @@ -802,7 +799,7 @@ startParsing(XML_Parser parser) { return XML_TRUE; } -XML_Parser XMLCALL XML_ParserCreate_MM( +XML_Parser XML_ParserCreate_MM( const XML_Char *encodingName, const XML_Memory_Handling_Suite *memsuite, const XML_Char *nameSep) { return parserCreate(encodingName, memsuite, nameSep, NULL); @@ -968,7 +965,7 @@ static void parserInit(XML_Parser parser, const XML_Char *encodingName) { parser->m_declNotationPublicId = NULL; parser->m_declAttributeIsCdata = XML_FALSE; parser->m_declAttributeIsId = XML_FALSE; - memset(&parser->m_position, 0, sizeof(POSITION)); + bzero(&parser->m_position, sizeof(POSITION)); parser->m_errorCode = XML_ERROR_NONE; parser->m_eventPtr = NULL; parser->m_eventEndPtr = NULL; @@ -993,7 +990,7 @@ static void parserInit(XML_Parser parser, const XML_Char *encodingName) { } /* moves list of bindings to m_freeBindingList */ -static void FASTCALL moveToFreeBindingList(XML_Parser parser, +static void moveToFreeBindingList(XML_Parser parser, BINDING *bindings) { while (bindings) { BINDING *b = bindings; @@ -1003,7 +1000,7 @@ static void FASTCALL moveToFreeBindingList(XML_Parser parser, } } -XML_Bool XMLCALL XML_ParserReset(XML_Parser parser, +XML_Bool XML_ParserReset(XML_Parser parser, const XML_Char *encodingName) { TAG *tStk; OPEN_INTERNAL_ENTITY *openEntityList; @@ -1042,7 +1039,7 @@ XML_Bool XMLCALL XML_ParserReset(XML_Parser parser, return XML_TRUE; } -enum XML_Status XMLCALL XML_SetEncoding(XML_Parser parser, +enum XML_Status XML_SetEncoding(XML_Parser parser, const XML_Char *encodingName) { if (parser == NULL) return XML_STATUS_ERROR; /* Block after XML_Parse()/XML_ParseBuffer() has been called. @@ -1066,7 +1063,7 @@ enum XML_Status XMLCALL XML_SetEncoding(XML_Parser parser, return XML_STATUS_OK; } -XML_Parser XMLCALL +XML_Parser XML_ExternalEntityParserCreate(XML_Parser oldParser, const XML_Char *context, const XML_Char *encodingName) { XML_Parser parser = oldParser; @@ -1232,7 +1229,7 @@ XML_ExternalEntityParserCreate(XML_Parser oldParser, const XML_Char *context, return parser; } -static void FASTCALL destroyBindings(BINDING *bindings, XML_Parser parser) { +static void destroyBindings(BINDING *bindings, XML_Parser parser) { for (;;) { BINDING *b = bindings; if (!b) break; @@ -1242,7 +1239,7 @@ static void FASTCALL destroyBindings(BINDING *bindings, XML_Parser parser) { } } -void XMLCALL XML_ParserFree(XML_Parser parser) { +void XML_ParserFree(XML_Parser parser) { TAG *tagList; OPEN_INTERNAL_ENTITY *entityList; if (parser == NULL) return; @@ -1304,11 +1301,11 @@ void XMLCALL XML_ParserFree(XML_Parser parser) { FREE(parser, parser); } -void XMLCALL XML_UseParserAsHandlerArg(XML_Parser parser) { +void XML_UseParserAsHandlerArg(XML_Parser parser) { if (parser != NULL) parser->m_handlerArg = parser; } -enum XML_Error XMLCALL XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD) { +enum XML_Error XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD) { if (parser == NULL) return XML_ERROR_INVALID_ARGUMENT; #ifdef XML_DTD /* block after XML_Parse()/XML_ParseBuffer() has been called */ @@ -1322,7 +1319,7 @@ enum XML_Error XMLCALL XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD) { #endif } -void XMLCALL XML_SetReturnNSTriplet(XML_Parser parser, int do_nst) { +void XML_SetReturnNSTriplet(XML_Parser parser, int do_nst) { if (parser == NULL) return; /* block after XML_Parse()/XML_ParseBuffer() has been called */ if (parser->m_parsingStatus.parsing == XML_PARSING || @@ -1331,7 +1328,7 @@ void XMLCALL XML_SetReturnNSTriplet(XML_Parser parser, int do_nst) { parser->m_ns_triplets = do_nst ? XML_TRUE : XML_FALSE; } -void XMLCALL XML_SetUserData(XML_Parser parser, void *p) { +void XML_SetUserData(XML_Parser parser, void *p) { if (parser == NULL) return; if (parser->m_handlerArg == parser->m_userData) parser->m_handlerArg = parser->m_userData = p; @@ -1339,7 +1336,7 @@ void XMLCALL XML_SetUserData(XML_Parser parser, void *p) { parser->m_userData = p; } -enum XML_Status XMLCALL XML_SetBase(XML_Parser parser, const XML_Char *p) { +enum XML_Status XML_SetBase(XML_Parser parser, const XML_Char *p) { if (parser == NULL) return XML_STATUS_ERROR; if (p) { p = poolCopyString(&parser->m_dtd->pool, p); @@ -1350,29 +1347,29 @@ enum XML_Status XMLCALL XML_SetBase(XML_Parser parser, const XML_Char *p) { return XML_STATUS_OK; } -const XML_Char *XMLCALL XML_GetBase(XML_Parser parser) { +const XML_Char *XML_GetBase(XML_Parser parser) { if (parser == NULL) return NULL; return parser->m_curBase; } -int XMLCALL XML_GetSpecifiedAttributeCount(XML_Parser parser) { +int XML_GetSpecifiedAttributeCount(XML_Parser parser) { if (parser == NULL) return -1; return parser->m_nSpecifiedAtts; } -int XMLCALL XML_GetIdAttributeIndex(XML_Parser parser) { +int XML_GetIdAttributeIndex(XML_Parser parser) { if (parser == NULL) return -1; return parser->m_idAttIndex; } #ifdef XML_ATTR_INFO -const XML_AttrInfo *XMLCALL XML_GetAttributeInfo(XML_Parser parser) { +const XML_AttrInfo *XML_GetAttributeInfo(XML_Parser parser) { if (parser == NULL) return NULL; return parser->m_attInfo; } #endif -void XMLCALL XML_SetElementHandler(XML_Parser parser, +void XML_SetElementHandler(XML_Parser parser, XML_StartElementHandler start, XML_EndElementHandler end) { if (parser == NULL) return; @@ -1380,32 +1377,32 @@ void XMLCALL XML_SetElementHandler(XML_Parser parser, parser->m_endElementHandler = end; } -void XMLCALL XML_SetStartElementHandler(XML_Parser parser, +void XML_SetStartElementHandler(XML_Parser parser, XML_StartElementHandler start) { if (parser != NULL) parser->m_startElementHandler = start; } -void XMLCALL XML_SetEndElementHandler(XML_Parser parser, +void XML_SetEndElementHandler(XML_Parser parser, XML_EndElementHandler end) { if (parser != NULL) parser->m_endElementHandler = end; } -void XMLCALL XML_SetCharacterDataHandler(XML_Parser parser, +void XML_SetCharacterDataHandler(XML_Parser parser, XML_CharacterDataHandler handler) { if (parser != NULL) parser->m_characterDataHandler = handler; } -void XMLCALL XML_SetProcessingInstructionHandler( +void XML_SetProcessingInstructionHandler( XML_Parser parser, XML_ProcessingInstructionHandler handler) { if (parser != NULL) parser->m_processingInstructionHandler = handler; } -void XMLCALL XML_SetCommentHandler(XML_Parser parser, +void XML_SetCommentHandler(XML_Parser parser, XML_CommentHandler handler) { if (parser != NULL) parser->m_commentHandler = handler; } -void XMLCALL XML_SetCdataSectionHandler(XML_Parser parser, +void XML_SetCdataSectionHandler(XML_Parser parser, XML_StartCdataSectionHandler start, XML_EndCdataSectionHandler end) { if (parser == NULL) return; @@ -1413,31 +1410,31 @@ void XMLCALL XML_SetCdataSectionHandler(XML_Parser parser, parser->m_endCdataSectionHandler = end; } -void XMLCALL XML_SetStartCdataSectionHandler( +void XML_SetStartCdataSectionHandler( XML_Parser parser, XML_StartCdataSectionHandler start) { if (parser != NULL) parser->m_startCdataSectionHandler = start; } -void XMLCALL XML_SetEndCdataSectionHandler(XML_Parser parser, +void XML_SetEndCdataSectionHandler(XML_Parser parser, XML_EndCdataSectionHandler end) { if (parser != NULL) parser->m_endCdataSectionHandler = end; } -void XMLCALL XML_SetDefaultHandler(XML_Parser parser, +void XML_SetDefaultHandler(XML_Parser parser, XML_DefaultHandler handler) { if (parser == NULL) return; parser->m_defaultHandler = handler; parser->m_defaultExpandInternalEntities = XML_FALSE; } -void XMLCALL XML_SetDefaultHandlerExpand(XML_Parser parser, +void XML_SetDefaultHandlerExpand(XML_Parser parser, XML_DefaultHandler handler) { if (parser == NULL) return; parser->m_defaultHandler = handler; parser->m_defaultExpandInternalEntities = XML_TRUE; } -void XMLCALL XML_SetDoctypeDeclHandler(XML_Parser parser, +void XML_SetDoctypeDeclHandler(XML_Parser parser, XML_StartDoctypeDeclHandler start, XML_EndDoctypeDeclHandler end) { if (parser == NULL) return; @@ -1445,27 +1442,27 @@ void XMLCALL XML_SetDoctypeDeclHandler(XML_Parser parser, parser->m_endDoctypeDeclHandler = end; } -void XMLCALL XML_SetStartDoctypeDeclHandler(XML_Parser parser, +void XML_SetStartDoctypeDeclHandler(XML_Parser parser, XML_StartDoctypeDeclHandler start) { if (parser != NULL) parser->m_startDoctypeDeclHandler = start; } -void XMLCALL XML_SetEndDoctypeDeclHandler(XML_Parser parser, +void XML_SetEndDoctypeDeclHandler(XML_Parser parser, XML_EndDoctypeDeclHandler end) { if (parser != NULL) parser->m_endDoctypeDeclHandler = end; } -void XMLCALL XML_SetUnparsedEntityDeclHandler( +void XML_SetUnparsedEntityDeclHandler( XML_Parser parser, XML_UnparsedEntityDeclHandler handler) { if (parser != NULL) parser->m_unparsedEntityDeclHandler = handler; } -void XMLCALL XML_SetNotationDeclHandler(XML_Parser parser, +void XML_SetNotationDeclHandler(XML_Parser parser, XML_NotationDeclHandler handler) { if (parser != NULL) parser->m_notationDeclHandler = handler; } -void XMLCALL XML_SetNamespaceDeclHandler(XML_Parser parser, +void XML_SetNamespaceDeclHandler(XML_Parser parser, XML_StartNamespaceDeclHandler start, XML_EndNamespaceDeclHandler end) { if (parser == NULL) return; @@ -1473,27 +1470,27 @@ void XMLCALL XML_SetNamespaceDeclHandler(XML_Parser parser, parser->m_endNamespaceDeclHandler = end; } -void XMLCALL XML_SetStartNamespaceDeclHandler( +void XML_SetStartNamespaceDeclHandler( XML_Parser parser, XML_StartNamespaceDeclHandler start) { if (parser != NULL) parser->m_startNamespaceDeclHandler = start; } -void XMLCALL XML_SetEndNamespaceDeclHandler(XML_Parser parser, +void XML_SetEndNamespaceDeclHandler(XML_Parser parser, XML_EndNamespaceDeclHandler end) { if (parser != NULL) parser->m_endNamespaceDeclHandler = end; } -void XMLCALL XML_SetNotStandaloneHandler(XML_Parser parser, +void XML_SetNotStandaloneHandler(XML_Parser parser, XML_NotStandaloneHandler handler) { if (parser != NULL) parser->m_notStandaloneHandler = handler; } -void XMLCALL XML_SetExternalEntityRefHandler( +void XML_SetExternalEntityRefHandler( XML_Parser parser, XML_ExternalEntityRefHandler handler) { if (parser != NULL) parser->m_externalEntityRefHandler = handler; } -void XMLCALL XML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg) { +void XML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg) { if (parser == NULL) return; if (arg) parser->m_externalEntityRefHandlerArg = (XML_Parser)arg; @@ -1501,12 +1498,12 @@ void XMLCALL XML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg) { parser->m_externalEntityRefHandlerArg = parser; } -void XMLCALL XML_SetSkippedEntityHandler(XML_Parser parser, +void XML_SetSkippedEntityHandler(XML_Parser parser, XML_SkippedEntityHandler handler) { if (parser != NULL) parser->m_skippedEntityHandler = handler; } -void XMLCALL XML_SetUnknownEncodingHandler(XML_Parser parser, +void XML_SetUnknownEncodingHandler(XML_Parser parser, XML_UnknownEncodingHandler handler, void *data) { if (parser == NULL) return; @@ -1514,27 +1511,27 @@ void XMLCALL XML_SetUnknownEncodingHandler(XML_Parser parser, parser->m_unknownEncodingHandlerData = data; } -void XMLCALL XML_SetElementDeclHandler(XML_Parser parser, +void XML_SetElementDeclHandler(XML_Parser parser, XML_ElementDeclHandler eldecl) { if (parser != NULL) parser->m_elementDeclHandler = eldecl; } -void XMLCALL XML_SetAttlistDeclHandler(XML_Parser parser, +void XML_SetAttlistDeclHandler(XML_Parser parser, XML_AttlistDeclHandler attdecl) { if (parser != NULL) parser->m_attlistDeclHandler = attdecl; } -void XMLCALL XML_SetEntityDeclHandler(XML_Parser parser, +void XML_SetEntityDeclHandler(XML_Parser parser, XML_EntityDeclHandler handler) { if (parser != NULL) parser->m_entityDeclHandler = handler; } -void XMLCALL XML_SetXmlDeclHandler(XML_Parser parser, +void XML_SetXmlDeclHandler(XML_Parser parser, XML_XmlDeclHandler handler) { if (parser != NULL) parser->m_xmlDeclHandler = handler; } -int XMLCALL XML_SetParamEntityParsing(XML_Parser parser, +int XML_SetParamEntityParsing(XML_Parser parser, enum XML_ParamEntityParsing peParsing) { if (parser == NULL) return 0; /* block after XML_Parse()/XML_ParseBuffer() has been called */ @@ -1549,7 +1546,7 @@ int XMLCALL XML_SetParamEntityParsing(XML_Parser parser, #endif } -int XMLCALL XML_SetHashSalt(XML_Parser parser, unsigned long hash_salt) { +int XML_SetHashSalt(XML_Parser parser, unsigned long hash_salt) { if (parser == NULL) return 0; if (parser->m_parentParser) return XML_SetHashSalt(parser->m_parentParser, hash_salt); @@ -1561,7 +1558,7 @@ int XMLCALL XML_SetHashSalt(XML_Parser parser, unsigned long hash_salt) { return 1; } -enum XML_Status XMLCALL XML_Parse(XML_Parser parser, const char *s, int len, +enum XML_Status XML_Parse(XML_Parser parser, const char *s, int len, int isFinal) { if ((parser == NULL) || (len < 0) || ((s == NULL) && (len != 0))) { if (parser != NULL) parser->m_errorCode = XML_ERROR_INVALID_ARGUMENT; @@ -1713,7 +1710,7 @@ enum XML_Status XMLCALL XML_Parse(XML_Parser parser, const char *s, int len, } } -enum XML_Status XMLCALL XML_ParseBuffer(XML_Parser parser, int len, +enum XML_Status XML_ParseBuffer(XML_Parser parser, int len, int isFinal) { const char *start; enum XML_Status result = XML_STATUS_OK; @@ -1771,7 +1768,7 @@ enum XML_Status XMLCALL XML_ParseBuffer(XML_Parser parser, int len, return result; } -void *XMLCALL XML_GetBuffer(XML_Parser parser, int len) { +void *XML_GetBuffer(XML_Parser parser, int len) { if (parser == NULL) return NULL; if (len < 0) { parser->m_errorCode = XML_ERROR_NO_MEMORY; @@ -1884,7 +1881,7 @@ void *XMLCALL XML_GetBuffer(XML_Parser parser, int len) { return parser->m_bufferEnd; } -enum XML_Status XMLCALL XML_StopParser(XML_Parser parser, XML_Bool resumable) { +enum XML_Status XML_StopParser(XML_Parser parser, XML_Bool resumable) { if (parser == NULL) return XML_STATUS_ERROR; switch (parser->m_parsingStatus.parsing) { case XML_SUSPENDED: @@ -1912,7 +1909,7 @@ enum XML_Status XMLCALL XML_StopParser(XML_Parser parser, XML_Bool resumable) { return XML_STATUS_OK; } -enum XML_Status XMLCALL XML_ResumeParser(XML_Parser parser) { +enum XML_Status XML_ResumeParser(XML_Parser parser) { enum XML_Status result = XML_STATUS_OK; if (parser == NULL) return XML_STATUS_ERROR; @@ -1950,19 +1947,19 @@ enum XML_Status XMLCALL XML_ResumeParser(XML_Parser parser) { return result; } -void XMLCALL XML_GetParsingStatus(XML_Parser parser, +void XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status) { if (parser == NULL) return; assert(status != NULL); *status = parser->m_parsingStatus; } -enum XML_Error XMLCALL XML_GetErrorCode(XML_Parser parser) { +enum XML_Error XML_GetErrorCode(XML_Parser parser) { if (parser == NULL) return XML_ERROR_INVALID_ARGUMENT; return parser->m_errorCode; } -XML_Index XMLCALL XML_GetCurrentByteIndex(XML_Parser parser) { +XML_Index XML_GetCurrentByteIndex(XML_Parser parser) { if (parser == NULL) return -1; if (parser->m_eventPtr) return (XML_Index)(parser->m_parseEndByteIndex - @@ -1970,14 +1967,14 @@ XML_Index XMLCALL XML_GetCurrentByteIndex(XML_Parser parser) { return -1; } -int XMLCALL XML_GetCurrentByteCount(XML_Parser parser) { +int XML_GetCurrentByteCount(XML_Parser parser) { if (parser == NULL) return 0; if (parser->m_eventEndPtr && parser->m_eventPtr) return (int)(parser->m_eventEndPtr - parser->m_eventPtr); return 0; } -const char *XMLCALL XML_GetInputContext(XML_Parser parser, int *offset, +const char *XML_GetInputContext(XML_Parser parser, int *offset, int *size) { #ifdef XML_CONTEXT_BYTES if (parser == NULL) return NULL; @@ -1994,7 +1991,7 @@ const char *XMLCALL XML_GetInputContext(XML_Parser parser, int *offset, return (char *)0; } -XML_Size XMLCALL XML_GetCurrentLineNumber(XML_Parser parser) { +XML_Size XML_GetCurrentLineNumber(XML_Parser parser) { if (parser == NULL) return 0; if (parser->m_eventPtr && parser->m_eventPtr >= parser->m_positionPtr) { XmlUpdatePosition(parser->m_encoding, parser->m_positionPtr, @@ -2004,7 +2001,7 @@ XML_Size XMLCALL XML_GetCurrentLineNumber(XML_Parser parser) { return parser->m_position.lineNumber + 1; } -XML_Size XMLCALL XML_GetCurrentColumnNumber(XML_Parser parser) { +XML_Size XML_GetCurrentColumnNumber(XML_Parser parser) { if (parser == NULL) return 0; if (parser->m_eventPtr && parser->m_eventPtr >= parser->m_positionPtr) { XmlUpdatePosition(parser->m_encoding, parser->m_positionPtr, @@ -2014,25 +2011,25 @@ XML_Size XMLCALL XML_GetCurrentColumnNumber(XML_Parser parser) { return parser->m_position.columnNumber; } -void XMLCALL XML_FreeContentModel(XML_Parser parser, XML_Content *model) { +void XML_FreeContentModel(XML_Parser parser, XML_Content *model) { if (parser != NULL) FREE(parser, model); } -void *XMLCALL XML_MemMalloc(XML_Parser parser, size_t size) { +void *XML_MemMalloc(XML_Parser parser, size_t size) { if (parser == NULL) return NULL; return MALLOC(parser, size); } -void *XMLCALL XML_MemRealloc(XML_Parser parser, void *ptr, size_t size) { +void *XML_MemRealloc(XML_Parser parser, void *ptr, size_t size) { if (parser == NULL) return NULL; return REALLOC(parser, ptr, size); } -void XMLCALL XML_MemFree(XML_Parser parser, void *ptr) { +void XML_MemFree(XML_Parser parser, void *ptr) { if (parser != NULL) FREE(parser, ptr); } -void XMLCALL XML_DefaultCurrent(XML_Parser parser) { +void XML_DefaultCurrent(XML_Parser parser) { if (parser == NULL) return; if (parser->m_defaultHandler) { if (parser->m_openInternalEntities) @@ -2045,7 +2042,7 @@ void XMLCALL XML_DefaultCurrent(XML_Parser parser) { } } -const XML_LChar *XMLCALL XML_ErrorString(enum XML_Error code) { +const XML_LChar *XML_ErrorString(enum XML_Error code) { switch (code) { case XML_ERROR_NONE: return NULL; @@ -2142,7 +2139,7 @@ const XML_LChar *XMLCALL XML_ErrorString(enum XML_Error code) { return NULL; } -const XML_LChar *XMLCALL XML_ExpatVersion(void) { +const XML_LChar *XML_ExpatVersion(void) { /* V1 is used to string-ize the version number. However, it would string-ize the actual version macro *names* unless we get them substituted before being passed to V1. CPP is defined to expand @@ -2160,7 +2157,7 @@ const XML_LChar *XMLCALL XML_ExpatVersion(void) { #undef V2 } -XML_Expat_Version XMLCALL XML_ExpatVersionInfo(void) { +XML_Expat_Version XML_ExpatVersionInfo(void) { XML_Expat_Version version; version.major = XML_MAJOR_VERSION; @@ -2170,7 +2167,7 @@ XML_Expat_Version XMLCALL XML_ExpatVersionInfo(void) { return version; } -const XML_Feature *XMLCALL XML_GetFeatureList(void) { +const XML_Feature *XML_GetFeatureList(void) { static const XML_Feature features[] = { {XML_FEATURE_SIZEOF_XML_CHAR, XML_L("sizeof(XML_Char)"), sizeof(XML_Char)}, @@ -2252,7 +2249,7 @@ static XML_Bool storeRawNames(XML_Parser parser) { return XML_TRUE; } -static enum XML_Error PTRCALL contentProcessor(XML_Parser parser, +static enum XML_Error contentProcessor(XML_Parser parser, const char *start, const char *end, const char **endPtr) { @@ -2265,7 +2262,7 @@ static enum XML_Error PTRCALL contentProcessor(XML_Parser parser, return result; } -static enum XML_Error PTRCALL externalEntityInitProcessor(XML_Parser parser, +static enum XML_Error externalEntityInitProcessor(XML_Parser parser, const char *start, const char *end, const char **endPtr) { @@ -2275,7 +2272,7 @@ static enum XML_Error PTRCALL externalEntityInitProcessor(XML_Parser parser, return externalEntityInitProcessor2(parser, start, end, endPtr); } -static enum XML_Error PTRCALL +static enum XML_Error externalEntityInitProcessor2(XML_Parser parser, const char *start, const char *end, const char **endPtr) { const char *next = start; /* XmlContentTok doesn't always set the last arg */ @@ -2313,7 +2310,7 @@ externalEntityInitProcessor2(XML_Parser parser, const char *start, return externalEntityInitProcessor3(parser, start, end, endPtr); } -static enum XML_Error PTRCALL +static enum XML_Error externalEntityInitProcessor3(XML_Parser parser, const char *start, const char *end, const char **endPtr) { int tok; @@ -2355,7 +2352,7 @@ externalEntityInitProcessor3(XML_Parser parser, const char *start, return externalEntityContentProcessor(parser, start, end, endPtr); } -static enum XML_Error PTRCALL +static enum XML_Error externalEntityContentProcessor(XML_Parser parser, const char *start, const char *end, const char **endPtr) { enum XML_Error result = @@ -3303,10 +3300,10 @@ static enum XML_Error addBinding(XML_Parser parser, PREFIX *prefix, /* The idea here is to avoid using stack for each CDATA section when the whole file is parsed with one call. */ -static enum XML_Error PTRCALL cdataSectionProcessor(XML_Parser parser, - const char *start, - const char *end, - const char **endPtr) { +static enum XML_Error cdataSectionProcessor(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr) { enum XML_Error result = doCdataSection(parser, parser->m_encoding, &start, end, endPtr, (XML_Bool)!parser->m_parsingStatus.finalBuffer); @@ -3442,10 +3439,10 @@ static enum XML_Error doCdataSection(XML_Parser parser, const ENCODING *enc, /* The idea here is to avoid using stack for each IGNORE section when the whole file is parsed with one call. */ -static enum XML_Error PTRCALL ignoreSectionProcessor(XML_Parser parser, - const char *start, - const char *end, - const char **endPtr) { +static enum XML_Error ignoreSectionProcessor(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr) { enum XML_Error result = doIgnoreSection(parser, parser->m_encoding, &start, end, endPtr, (XML_Bool)!parser->m_parsingStatus.finalBuffer); @@ -3672,10 +3669,10 @@ static enum XML_Error handleUnknownEncoding(XML_Parser parser, return XML_ERROR_UNKNOWN_ENCODING; } -static enum XML_Error PTRCALL prologInitProcessor(XML_Parser parser, - const char *s, - const char *end, - const char **nextPtr) { +static enum XML_Error prologInitProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) { enum XML_Error result = initializeEncoding(parser); if (result != XML_ERROR_NONE) return result; parser->m_processor = prologProcessor; @@ -3684,7 +3681,7 @@ static enum XML_Error PTRCALL prologInitProcessor(XML_Parser parser, #ifdef XML_DTD -static enum XML_Error PTRCALL externalParEntInitProcessor( +static enum XML_Error externalParEntInitProcessor( XML_Parser parser, const char *s, const char *end, const char **nextPtr) { enum XML_Error result = initializeEncoding(parser); if (result != XML_ERROR_NONE) return result; @@ -3702,10 +3699,10 @@ static enum XML_Error PTRCALL externalParEntInitProcessor( } } -static enum XML_Error PTRCALL entityValueInitProcessor(XML_Parser parser, - const char *s, - const char *end, - const char **nextPtr) { +static enum XML_Error entityValueInitProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) { int tok; const char *start = s; const char *next = start; @@ -3773,10 +3770,10 @@ static enum XML_Error PTRCALL entityValueInitProcessor(XML_Parser parser, } } -static enum XML_Error PTRCALL externalParEntProcessor(XML_Parser parser, - const char *s, - const char *end, - const char **nextPtr) { +static enum XML_Error externalParEntProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) { const char *next = s; int tok; @@ -3812,10 +3809,10 @@ static enum XML_Error PTRCALL externalParEntProcessor(XML_Parser parser, (XML_Bool)!parser->m_parsingStatus.finalBuffer, XML_TRUE); } -static enum XML_Error PTRCALL entityValueProcessor(XML_Parser parser, - const char *s, - const char *end, - const char **nextPtr) { +static enum XML_Error entityValueProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) { const char *start = s; const char *next = s; const ENCODING *enc = parser->m_encoding; @@ -3848,9 +3845,9 @@ static enum XML_Error PTRCALL entityValueProcessor(XML_Parser parser, #endif /* XML_DTD */ -static enum XML_Error PTRCALL prologProcessor(XML_Parser parser, const char *s, - const char *end, - const char **nextPtr) { +static enum XML_Error prologProcessor(XML_Parser parser, const char *s, + const char *end, + const char **nextPtr) { const char *next = s; int tok = XmlPrologTok(parser->m_encoding, s, end, &next); return doProlog(parser, parser->m_encoding, s, end, tok, next, nextPtr, @@ -4805,9 +4802,9 @@ static enum XML_Error doProlog(XML_Parser parser, const ENCODING *enc, /* not reached */ } -static enum XML_Error PTRCALL epilogProcessor(XML_Parser parser, const char *s, - const char *end, - const char **nextPtr) { +static enum XML_Error epilogProcessor(XML_Parser parser, const char *s, + const char *end, + const char **nextPtr) { parser->m_processor = epilogProcessor; parser->m_eventPtr = s; for (;;) { @@ -4924,10 +4921,10 @@ static enum XML_Error processInternalEntity(XML_Parser parser, ENTITY *entity, return result; } -static enum XML_Error PTRCALL internalEntityProcessor(XML_Parser parser, - const char *s, - const char *end, - const char **nextPtr) { +static enum XML_Error internalEntityProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) { ENTITY *entity; const char *textStart, *textEnd; const char *next; @@ -4985,8 +4982,8 @@ static enum XML_Error PTRCALL internalEntityProcessor(XML_Parser parser, } } -static enum XML_Error PTRCALL errorProcessor(XML_Parser parser, const char *s, - const char *end, +static enum XML_Error errorProcessor(XML_Parser parser, const char *s, + const char *end, const char **nextPtr) { UNUSED_P(s); UNUSED_P(end); @@ -5327,7 +5324,7 @@ endEntityValue: return result; } -static void FASTCALL normalizeLines(XML_Char *s) { +static void normalizeLines(XML_Char *s) { XML_Char *p; for (;; s++) { if (*s == XML_T('\0')) return; @@ -5683,7 +5680,7 @@ static XML_Bool setContext(XML_Parser parser, const XML_Char *context) { return XML_TRUE; } -static void FASTCALL normalizePublicId(XML_Char *publicId) { +static void normalizePublicId(XML_Char *publicId) { XML_Char *p = publicId; XML_Char *s; for (s = publicId; *s; s++) { @@ -5967,7 +5964,7 @@ static int copyEntityTable(XML_Parser oldParser, HASH_TABLE *newTable, #define INIT_POWER 6 -static XML_Bool FASTCALL keyeq(KEY s1, KEY s2) { +static XML_Bool keyeq(KEY s1, KEY s2) { for (; *s1 == *s2; s1++, s2++) if (*s1 == 0) return XML_TRUE; return XML_FALSE; @@ -5985,7 +5982,7 @@ static void copy_salt_to_sipkey(XML_Parser parser, struct sipkey *key) { key->k[1] = get_hash_secret_salt(parser); } -static unsigned long FASTCALL hash(XML_Parser parser, KEY s) { +static unsigned long hash(XML_Parser parser, KEY s) { struct siphash state; struct sipkey key; (void)sip24_valid; @@ -6010,7 +6007,7 @@ static NAMED *lookup(XML_Parser parser, HASH_TABLE *table, KEY name, table->size = 0; return NULL; } - memset(table->v, 0, tsize); + bzero(table->v, tsize); i = hash(parser, name) & ((unsigned long)table->size - 1); } else { unsigned long h = hash(parser, name); @@ -6032,7 +6029,7 @@ static NAMED *lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t tsize = newSize * sizeof(NAMED *); NAMED **newV = (NAMED **)table->mem->malloc_fcn(tsize); if (!newV) return NULL; - memset(newV, 0, tsize); + bzero(newV, tsize); for (i = 0; i < table->size; i++) if (table->v[i]) { unsigned long newHash = hash(parser, table->v[i]->name); @@ -6058,13 +6055,13 @@ static NAMED *lookup(XML_Parser parser, HASH_TABLE *table, KEY name, } table->v[i] = (NAMED *)table->mem->malloc_fcn(createSize); if (!table->v[i]) return NULL; - memset(table->v[i], 0, createSize); + bzero(table->v[i], createSize); table->v[i]->name = name; (table->used)++; return table->v[i]; } -static void FASTCALL hashTableClear(HASH_TABLE *table) { +static void hashTableClear(HASH_TABLE *table) { size_t i; for (i = 0; i < table->size; i++) { table->mem->free_fcn(table->v[i]); @@ -6073,13 +6070,13 @@ static void FASTCALL hashTableClear(HASH_TABLE *table) { table->used = 0; } -static void FASTCALL hashTableDestroy(HASH_TABLE *table) { +static void hashTableDestroy(HASH_TABLE *table) { size_t i; for (i = 0; i < table->size; i++) table->mem->free_fcn(table->v[i]); table->mem->free_fcn(table->v); } -static void FASTCALL hashTableInit(HASH_TABLE *p, +static void hashTableInit(HASH_TABLE *p, const XML_Memory_Handling_Suite *ms) { p->power = 0; p->size = 0; @@ -6088,13 +6085,13 @@ static void FASTCALL hashTableInit(HASH_TABLE *p, p->mem = ms; } -static void FASTCALL hashTableIterInit(HASH_TABLE_ITER *iter, +static void hashTableIterInit(HASH_TABLE_ITER *iter, const HASH_TABLE *table) { iter->p = table->v; iter->end = iter->p + table->size; } -static NAMED *FASTCALL hashTableIterNext(HASH_TABLE_ITER *iter) { +static NAMED *hashTableIterNext(HASH_TABLE_ITER *iter) { while (iter->p != iter->end) { NAMED *tem = *(iter->p)++; if (tem) return tem; @@ -6102,7 +6099,7 @@ static NAMED *FASTCALL hashTableIterNext(HASH_TABLE_ITER *iter) { return NULL; } -static void FASTCALL poolInit(STRING_POOL *pool, +static void poolInit(STRING_POOL *pool, const XML_Memory_Handling_Suite *ms) { pool->blocks = NULL; pool->freeBlocks = NULL; @@ -6112,7 +6109,7 @@ static void FASTCALL poolInit(STRING_POOL *pool, pool->mem = ms; } -static void FASTCALL poolClear(STRING_POOL *pool) { +static void poolClear(STRING_POOL *pool) { if (!pool->freeBlocks) pool->freeBlocks = pool->blocks; else { @@ -6130,7 +6127,7 @@ static void FASTCALL poolClear(STRING_POOL *pool) { pool->end = NULL; } -static void FASTCALL poolDestroy(STRING_POOL *pool) { +static void poolDestroy(STRING_POOL *pool) { BLOCK *p = pool->blocks; while (p) { BLOCK *tem = p->next; @@ -6159,7 +6156,7 @@ static XML_Char *poolAppend(STRING_POOL *pool, const ENCODING *enc, return pool->start; } -static const XML_Char *FASTCALL poolCopyString(STRING_POOL *pool, +static const XML_Char *poolCopyString(STRING_POOL *pool, const XML_Char *s) { do { if (!poolAppendChar(pool, *s)) return NULL; @@ -6193,7 +6190,7 @@ static const XML_Char *poolCopyStringN(STRING_POOL *pool, const XML_Char *s, return s; } -static const XML_Char *FASTCALL poolAppendString(STRING_POOL *pool, +static const XML_Char *poolAppendString(STRING_POOL *pool, const XML_Char *s) { while (*s) { if (!poolAppendChar(pool, *s)) return NULL; @@ -6234,7 +6231,7 @@ static size_t poolBytesToAllocateFor(int blockSize) { } } -static XML_Bool FASTCALL poolGrow(STRING_POOL *pool) { +static XML_Bool poolGrow(STRING_POOL *pool) { if (pool->freeBlocks) { if (pool->start == 0) { pool->blocks = pool->freeBlocks; @@ -6333,7 +6330,7 @@ static XML_Bool FASTCALL poolGrow(STRING_POOL *pool) { return XML_TRUE; } -static int FASTCALL nextScaffoldPart(XML_Parser parser) { +static int nextScaffoldPart(XML_Parser parser) { DTD *const dtd = parser->m_dtd; /* save one level of indirection */ CONTENT_SCAFFOLD *me; int next; diff --git a/third_party/python/Modules/expat/xmlrole.c b/third_party/python/Modules/expat/xmlrole.c index ed9d7edf6..7b002df9f 100644 --- a/third_party/python/Modules/expat/xmlrole.c +++ b/third_party/python/Modules/expat/xmlrole.c @@ -31,11 +31,17 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "expat_config.h" -#include "expat_external.h" -#include "internal.h" -#include "xmlrole.h" -#include "ascii.h" +asm(".ident\t\"\\n\\n\ +expat (MIT License)\\n\ +Copyright (c) 1997-2000 Thai Open Source Software Center Ltd\\n\ +Copyright (c) 2000-2017 Expat development team\""); +asm(".include \"libc/disclaimer.inc\""); + +#include "third_party/python/Modules/expat/expat_config.h" +#include "third_party/python/Modules/expat/expat_external.h" +#include "third_party/python/Modules/expat/internal.inc" +#include "third_party/python/Modules/expat/xmlrole.h" +#include "third_party/python/Modules/expat/ascii.inc" /* Doesn't check: @@ -105,9 +111,9 @@ static const char KW_SYSTEM[] # define setTopLevel(state) ((state)->handler = internalSubset) #endif /* not XML_DTD */ -typedef int PTRCALL PROLOG_HANDLER(PROLOG_STATE *state, int tok, - const char *ptr, const char *end, - const ENCODING *enc); +typedef int PROLOG_HANDLER(PROLOG_STATE *state, int tok, + const char *ptr, const char *end, + const ENCODING *enc); static PROLOG_HANDLER prolog0, prolog1, prolog2, doctype0, doctype1, doctype2, doctype3, doctype4, doctype5, internalSubset, entity0, entity1, entity2, @@ -121,9 +127,9 @@ static PROLOG_HANDLER prolog0, prolog1, prolog2, doctype0, doctype1, doctype2, #endif /* XML_DTD */ declClose, error; -static int FASTCALL common(PROLOG_STATE *state, int tok); +static int common(PROLOG_STATE *state, int tok); -static int PTRCALL +static int prolog0(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { switch (tok) { @@ -154,7 +160,7 @@ prolog0(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int prolog1(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { switch (tok) { @@ -186,7 +192,7 @@ prolog1(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int prolog2(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -206,7 +212,7 @@ prolog2(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int doctype0(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -223,7 +229,7 @@ doctype0(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int doctype1(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { switch (tok) { @@ -249,7 +255,7 @@ doctype1(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int doctype2(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -265,7 +271,7 @@ doctype2(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int doctype3(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -281,7 +287,7 @@ doctype3(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int doctype4(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -300,7 +306,7 @@ doctype4(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int doctype5(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -316,7 +322,7 @@ doctype5(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int internalSubset(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { switch (tok) { @@ -361,7 +367,7 @@ internalSubset(PROLOG_STATE *state, int tok, const char *ptr, const char *end, #ifdef XML_DTD -static int PTRCALL +static int externalSubset0(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { state->handler = externalSubset1; @@ -370,7 +376,7 @@ externalSubset0(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return externalSubset1(state, tok, ptr, end, enc); } -static int PTRCALL +static int externalSubset1(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { switch (tok) { @@ -398,7 +404,7 @@ externalSubset1(PROLOG_STATE *state, int tok, const char *ptr, const char *end, #endif /* XML_DTD */ -static int PTRCALL +static int entity0(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -417,7 +423,7 @@ entity0(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int entity1(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -433,7 +439,7 @@ entity1(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int entity2(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { switch (tok) { @@ -457,7 +463,7 @@ entity2(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int entity3(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -473,7 +479,7 @@ entity3(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int entity4(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -489,7 +495,7 @@ entity4(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int entity5(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { switch (tok) { @@ -508,7 +514,7 @@ entity5(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int entity6(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -525,7 +531,7 @@ entity6(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int entity7(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { switch (tok) { @@ -549,7 +555,7 @@ entity7(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int entity8(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -565,7 +571,7 @@ entity8(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int entity9(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -581,7 +587,7 @@ entity9(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int entity10(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -597,7 +603,7 @@ entity10(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int notation0(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -613,7 +619,7 @@ notation0(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int notation1(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { switch (tok) { @@ -633,7 +639,7 @@ notation1(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int notation2(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -649,7 +655,7 @@ notation2(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int notation3(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -666,7 +672,7 @@ notation3(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int notation4(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -686,7 +692,7 @@ notation4(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int attlist0(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -703,7 +709,7 @@ attlist0(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int attlist1(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -723,7 +729,7 @@ attlist1(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int attlist2(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { switch (tok) { @@ -753,7 +759,7 @@ attlist2(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int attlist3(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -771,7 +777,7 @@ attlist3(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int attlist4(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -790,7 +796,7 @@ attlist4(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int attlist5(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -806,7 +812,7 @@ attlist5(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int attlist6(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -822,7 +828,7 @@ attlist6(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int attlist7(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -842,7 +848,7 @@ attlist7(PROLOG_STATE *state, int tok, const char *ptr, const char *end, } /* default value */ -static int PTRCALL +static int attlist8(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { switch (tok) { @@ -872,7 +878,7 @@ attlist8(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int attlist9(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -888,7 +894,7 @@ attlist9(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int element0(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -905,7 +911,7 @@ element0(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int element1(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { switch (tok) { @@ -931,7 +937,7 @@ element1(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int element2(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { switch (tok) { @@ -965,7 +971,7 @@ element2(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int element3(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -989,7 +995,7 @@ element3(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int element4(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -1006,7 +1012,7 @@ element4(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int element5(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -1026,7 +1032,7 @@ element5(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int element6(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -1055,7 +1061,7 @@ element6(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int element7(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -1104,7 +1110,7 @@ element7(PROLOG_STATE *state, int tok, const char *ptr, const char *end, #ifdef XML_DTD -static int PTRCALL +static int condSect0(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { switch (tok) { @@ -1124,7 +1130,7 @@ condSect0(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int condSect1(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -1141,7 +1147,7 @@ condSect1(PROLOG_STATE *state, int tok, const char *ptr, const char *end, return common(state, tok); } -static int PTRCALL +static int condSect2(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -1159,7 +1165,7 @@ condSect2(PROLOG_STATE *state, int tok, const char *ptr, const char *end, #endif /* XML_DTD */ -static int PTRCALL +static int declClose(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(ptr); @@ -1195,7 +1201,7 @@ declClose(PROLOG_STATE *state, int tok, const char *ptr, const char *end, * * LCOV_EXCL_START */ -static int PTRCALL +static int error(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc) { UNUSED_P(state); @@ -1207,7 +1213,7 @@ error(PROLOG_STATE *state, int tok, const char *ptr, const char *end, } /* LCOV_EXCL_STOP */ -static int FASTCALL +static int common(PROLOG_STATE *state, int tok) { #ifdef XML_DTD if (! state->documentEntity && tok == XML_TOK_PARAM_ENTITY_REF) diff --git a/third_party/python/Modules/expat/xmlrole.h b/third_party/python/Modules/expat/xmlrole.h index 62536f903..72fd5afcc 100644 --- a/third_party/python/Modules/expat/xmlrole.h +++ b/third_party/python/Modules/expat/xmlrole.h @@ -1,50 +1,8 @@ -/* clang-format off */ -/* - __ __ _ - ___\ \/ /_ __ __ _| |_ - / _ \\ /| '_ \ / _` | __| - | __// \| |_) | (_| | |_ - \___/_/\_\ .__/ \__,_|\__| - |_| XML parser - - Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team - Licensed under the MIT license: - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to permit - persons to whom the Software is furnished to do so, subject to the - following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - #ifndef XmlRole_INCLUDED #define XmlRole_INCLUDED 1 - -#ifdef __VMS -/* 0 1 2 3 0 1 2 3 - 1234567890123456789012345678901 1234567890123456789012345678901 */ -# define XmlPrologStateInitExternalEntity XmlPrologStateInitExternalEnt -#endif - -#include "xmltok.h" - -#ifdef __cplusplus -extern "C" { -#endif +#include "third_party/python/Modules/expat/xmltok.h" +COSMOPOLITAN_C_START_ +/* clang-format off */ enum { XML_ROLE_ERROR = -1, @@ -114,8 +72,8 @@ enum { }; typedef struct prolog_state { - int(PTRCALL *handler)(struct prolog_state *state, int tok, const char *ptr, - const char *end, const ENCODING *enc); + int(*handler)(struct prolog_state *state, int tok, const char *ptr, + const char *end, const ENCODING *enc); unsigned level; int role_none; #ifdef XML_DTD @@ -133,8 +91,5 @@ void XmlPrologStateInitExternalEntity(PROLOG_STATE *); #define XmlTokenRole(state, tok, ptr, end, enc) \ (((state)->handler)(state, tok, ptr, end, enc)) -#ifdef __cplusplus -} -#endif - +COSMOPOLITAN_C_END_ #endif /* not XmlRole_INCLUDED */ diff --git a/third_party/python/Modules/expat/xmltok.c b/third_party/python/Modules/expat/xmltok.c index f354d11a5..d457a65c6 100644 --- a/third_party/python/Modules/expat/xmltok.c +++ b/third_party/python/Modules/expat/xmltok.c @@ -31,12 +31,19 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "expat_config.h" -#include "expat_external.h" -#include "internal.h" -#include "xmltok.h" +asm(".ident\t\"\\n\\n\ +expat (MIT License)\\n\ +Copyright (c) 1997-2000 Thai Open Source Software Center Ltd\\n\ +Copyright (c) 2000-2017 Expat development team\""); +asm(".include \"libc/disclaimer.inc\""); + +#include "third_party/python/Modules/expat/expat_config.h" +#include "third_party/python/Modules/expat/expat_external.h" +#include "third_party/python/Modules/expat/internal.inc" +#include "third_party/python/Modules/expat/xmltok.h" #include "libc/str/str.h" -#include "nametab.h" +#include "third_party/python/Modules/expat/nametab.inc" +#include "third_party/python/Modules/expat/xmltok_impl.h.inc" #ifdef XML_DTD # define IGNORE_SECTION_TOK_VTABLE , PREFIX(ignoreSectionTok) @@ -113,20 +120,20 @@ : ((p)[1] & 0x80) == 0 \ || ((*p) == 0xF4 ? (p)[1] > 0x8F : ((p)[1] & 0xC0) == 0xC0))) -static int PTRFASTCALL +static int isNever(const ENCODING *enc, const char *p) { UNUSED_P(enc); UNUSED_P(p); return 0; } -static int PTRFASTCALL +static int utf8_isName2(const ENCODING *enc, const char *p) { UNUSED_P(enc); return UTF8_GET_NAMING2(namePages, (const unsigned char *)p); } -static int PTRFASTCALL +static int utf8_isName3(const ENCODING *enc, const char *p) { UNUSED_P(enc); return UTF8_GET_NAMING3(namePages, (const unsigned char *)p); @@ -134,13 +141,13 @@ utf8_isName3(const ENCODING *enc, const char *p) { #define utf8_isName4 isNever -static int PTRFASTCALL +static int utf8_isNmstrt2(const ENCODING *enc, const char *p) { UNUSED_P(enc); return UTF8_GET_NAMING2(nmstrtPages, (const unsigned char *)p); } -static int PTRFASTCALL +static int utf8_isNmstrt3(const ENCODING *enc, const char *p) { UNUSED_P(enc); return UTF8_GET_NAMING3(nmstrtPages, (const unsigned char *)p); @@ -148,19 +155,19 @@ utf8_isNmstrt3(const ENCODING *enc, const char *p) { #define utf8_isNmstrt4 isNever -static int PTRFASTCALL +static int utf8_isInvalid2(const ENCODING *enc, const char *p) { UNUSED_P(enc); return UTF8_INVALID2((const unsigned char *)p); } -static int PTRFASTCALL +static int utf8_isInvalid3(const ENCODING *enc, const char *p) { UNUSED_P(enc); return UTF8_INVALID3((const unsigned char *)p); } -static int PTRFASTCALL +static int utf8_isInvalid4(const ENCODING *enc, const char *p) { UNUSED_P(enc); return UTF8_INVALID4((const unsigned char *)p); @@ -170,21 +177,21 @@ struct normal_encoding { ENCODING enc; unsigned char type[256]; #ifdef XML_MIN_SIZE - int(PTRFASTCALL *byteType)(const ENCODING *, const char *); - int(PTRFASTCALL *isNameMin)(const ENCODING *, const char *); - int(PTRFASTCALL *isNmstrtMin)(const ENCODING *, const char *); - int(PTRFASTCALL *byteToAscii)(const ENCODING *, const char *); - int(PTRCALL *charMatches)(const ENCODING *, const char *, int); + int(*byteType)(const ENCODING *, const char *); + int(*isNameMin)(const ENCODING *, const char *); + int(*isNmstrtMin)(const ENCODING *, const char *); + int(*byteToAscii)(const ENCODING *, const char *); + int(*charMatches)(const ENCODING *, const char *, int); #endif /* XML_MIN_SIZE */ - int(PTRFASTCALL *isName2)(const ENCODING *, const char *); - int(PTRFASTCALL *isName3)(const ENCODING *, const char *); - int(PTRFASTCALL *isName4)(const ENCODING *, const char *); - int(PTRFASTCALL *isNmstrt2)(const ENCODING *, const char *); - int(PTRFASTCALL *isNmstrt3)(const ENCODING *, const char *); - int(PTRFASTCALL *isNmstrt4)(const ENCODING *, const char *); - int(PTRFASTCALL *isInvalid2)(const ENCODING *, const char *); - int(PTRFASTCALL *isInvalid3)(const ENCODING *, const char *); - int(PTRFASTCALL *isInvalid4)(const ENCODING *, const char *); + int(*isName2)(const ENCODING *, const char *); + int(*isName3)(const ENCODING *, const char *); + int(*isName4)(const ENCODING *, const char *); + int(*isNmstrt2)(const ENCODING *, const char *); + int(*isNmstrt3)(const ENCODING *, const char *); + int(*isNmstrt4)(const ENCODING *, const char *); + int(*isInvalid2)(const ENCODING *, const char *); + int(*isInvalid3)(const ENCODING *, const char *); + int(*isInvalid4)(const ENCODING *, const char *); }; #define AS_NORMAL_ENCODING(enc) ((const struct normal_encoding *)(enc)) @@ -209,10 +216,9 @@ struct normal_encoding { /* isNmstrt2 */ NULL, /* isNmstrt3 */ NULL, /* isNmstrt4 */ NULL, \ /* isInvalid2 */ NULL, /* isInvalid3 */ NULL, /* isInvalid4 */ NULL -static int FASTCALL checkCharRefNumber(int); +static int checkCharRefNumber(int); -#include "xmltok_impl.h" -#include "ascii.h" +#include "third_party/python/Modules/expat/ascii.inc" #ifdef XML_MIN_SIZE # define sb_isNameMin isNever @@ -230,7 +236,7 @@ static int FASTCALL checkCharRefNumber(int); (((struct normal_encoding *)(enc))->type[(unsigned char)*(p)]) #ifdef XML_MIN_SIZE -static int PTRFASTCALL +static int sb_byteType(const ENCODING *enc, const char *p) { return SB_BYTE_TYPE(enc, p); } @@ -241,7 +247,7 @@ sb_byteType(const ENCODING *enc, const char *p) { #ifdef XML_MIN_SIZE # define BYTE_TO_ASCII(enc, p) (AS_NORMAL_ENCODING(enc)->byteToAscii(enc, p)) -static int PTRFASTCALL +static int sb_byteToAscii(const ENCODING *enc, const char *p) { UNUSED_P(enc); return *p; @@ -268,7 +274,7 @@ sb_byteToAscii(const ENCODING *enc, const char *p) { #ifdef XML_MIN_SIZE # define CHAR_MATCHES(enc, p, c) \ (AS_NORMAL_ENCODING(enc)->charMatches(enc, p, c)) -static int PTRCALL +static int sb_charMatches(const ENCODING *enc, const char *p, int c) { UNUSED_P(enc); return *p == c; @@ -280,7 +286,7 @@ sb_charMatches(const ENCODING *enc, const char *p, int c) { #define PREFIX(ident) normal_##ident #define XML_TOK_IMPL_C -#include "xmltok_impl.c" +#include "third_party/python/Modules/expat/xmltok_impl.inc" #undef XML_TOK_IMPL_C #undef MINBPC @@ -339,7 +345,7 @@ _INTERNAL_trim_to_complete_utf8_characters(const char *from, *fromLimRef = fromLim; } -static enum XML_Convert_Result PTRCALL +static enum XML_Convert_Result utf8_toUtf8(const ENCODING *enc, const char **fromP, const char *fromLim, char **toP, const char *toLim) { bool input_incomplete = false; @@ -378,7 +384,7 @@ utf8_toUtf8(const ENCODING *enc, const char **fromP, const char *fromLim, return XML_CONVERT_COMPLETED; } -static enum XML_Convert_Result PTRCALL +static enum XML_Convert_Result utf8_toUtf16(const ENCODING *enc, const char **fromP, const char *fromLim, unsigned short **toP, const unsigned short *toLim) { enum XML_Convert_Result res = XML_CONVERT_COMPLETED; @@ -438,8 +444,8 @@ after: static const struct normal_encoding utf8_encoding_ns = {{VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0}, { -# include "asciitab.h" -# include "utf8tab.h" +#include "third_party/python/Modules/expat/asciitab.inc" +#include "third_party/python/Modules/expat/utf8tab.inc" }, STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_)}; #endif @@ -448,9 +454,9 @@ static const struct normal_encoding utf8_encoding = {{VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0}, { #define BT_COLON BT_NMSTRT -#include "asciitab.h" +#include "third_party/python/Modules/expat/asciitab.inc" #undef BT_COLON -#include "utf8tab.h" +#include "third_party/python/Modules/expat/utf8tab.inc" }, STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_)}; @@ -459,8 +465,8 @@ static const struct normal_encoding utf8_encoding static const struct normal_encoding internal_utf8_encoding_ns = {{VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0}, { -# include "iasciitab.h" -# include "utf8tab.h" +#include "third_party/python/Modules/expat/iasciitab.inc" +#include "third_party/python/Modules/expat/utf8tab.inc" }, STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_)}; @@ -470,13 +476,13 @@ static const struct normal_encoding internal_utf8_encoding = {{VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0}, { #define BT_COLON BT_NMSTRT -#include "iasciitab.h" +#include "third_party/python/Modules/expat/iasciitab.inc" #undef BT_COLON -#include "utf8tab.h" +#include "third_party/python/Modules/expat/utf8tab.inc" }, STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_)}; -static enum XML_Convert_Result PTRCALL +static enum XML_Convert_Result latin1_toUtf8(const ENCODING *enc, const char **fromP, const char *fromLim, char **toP, const char *toLim) { UNUSED_P(enc); @@ -499,7 +505,7 @@ latin1_toUtf8(const ENCODING *enc, const char **fromP, const char *fromLim, } } -static enum XML_Convert_Result PTRCALL +static enum XML_Convert_Result latin1_toUtf16(const ENCODING *enc, const char **fromP, const char *fromLim, unsigned short **toP, const unsigned short *toLim) { UNUSED_P(enc); @@ -517,8 +523,8 @@ latin1_toUtf16(const ENCODING *enc, const char **fromP, const char *fromLim, static const struct normal_encoding latin1_encoding_ns = {{VTABLE1, latin1_toUtf8, latin1_toUtf16, 1, 0, 0}, { -# include "asciitab.h" -# include "latin1tab.h" +#include "third_party/python/Modules/expat/asciitab.inc" +#include "third_party/python/Modules/expat/latin1tab.inc" }, STANDARD_VTABLE(sb_) NULL_VTABLE}; @@ -528,13 +534,13 @@ static const struct normal_encoding latin1_encoding = {{VTABLE1, latin1_toUtf8, latin1_toUtf16, 1, 0, 0}, { #define BT_COLON BT_NMSTRT -#include "asciitab.h" +#include "third_party/python/Modules/expat/asciitab.inc" #undef BT_COLON -#include "latin1tab.h" +#include "third_party/python/Modules/expat/latin1tab.inc" }, STANDARD_VTABLE(sb_) NULL_VTABLE}; -static enum XML_Convert_Result PTRCALL +static enum XML_Convert_Result ascii_toUtf8(const ENCODING *enc, const char **fromP, const char *fromLim, char **toP, const char *toLim) { UNUSED_P(enc); @@ -552,7 +558,7 @@ ascii_toUtf8(const ENCODING *enc, const char **fromP, const char *fromLim, static const struct normal_encoding ascii_encoding_ns = {{VTABLE1, ascii_toUtf8, latin1_toUtf16, 1, 1, 0}, { -# include "asciitab.h" +#include "third_party/python/Modules/expat/asciitab.inc" /* BT_NONXML == 0 */ }, STANDARD_VTABLE(sb_) NULL_VTABLE}; @@ -563,13 +569,13 @@ static const struct normal_encoding ascii_encoding = {{VTABLE1, ascii_toUtf8, latin1_toUtf16, 1, 1, 0}, { #define BT_COLON BT_NMSTRT -#include "asciitab.h" +#include "third_party/python/Modules/expat/asciitab.inc" #undef BT_COLON /* BT_NONXML == 0 */ }, STANDARD_VTABLE(sb_) NULL_VTABLE}; -static int PTRFASTCALL +static int unicode_byte_type(char hi, char lo) { switch ((unsigned char)hi) { /* 0xD800–0xDBFF first 16-bit code unit or high surrogate (W1) */ @@ -596,7 +602,7 @@ unicode_byte_type(char hi, char lo) { } #define DEFINE_UTF16_TO_UTF8(E) \ - static enum XML_Convert_Result PTRCALL E##toUtf8( \ + static enum XML_Convert_Result E##toUtf8( \ const ENCODING *enc, const char **fromP, const char *fromLim, \ char **toP, const char *toLim) { \ const char *from = *fromP; \ @@ -673,7 +679,7 @@ unicode_byte_type(char hi, char lo) { } #define DEFINE_UTF16_TO_UTF16(E) \ - static enum XML_Convert_Result PTRCALL E##toUtf16( \ + static enum XML_Convert_Result E##toUtf16( \ const ENCODING *enc, const char **fromP, const char *fromLim, \ unsigned short **toP, const unsigned short *toLim) { \ enum XML_Convert_Result res = XML_CONVERT_COMPLETED; \ @@ -727,30 +733,30 @@ DEFINE_UTF16_TO_UTF16(big2_) #ifdef XML_MIN_SIZE -static int PTRFASTCALL +static int little2_byteType(const ENCODING *enc, const char *p) { return LITTLE2_BYTE_TYPE(enc, p); } -static int PTRFASTCALL +static int little2_byteToAscii(const ENCODING *enc, const char *p) { UNUSED_P(enc); return LITTLE2_BYTE_TO_ASCII(p); } -static int PTRCALL +static int little2_charMatches(const ENCODING *enc, const char *p, int c) { UNUSED_P(enc); return LITTLE2_CHAR_MATCHES(p, c); } -static int PTRFASTCALL +static int little2_isNameMin(const ENCODING *enc, const char *p) { UNUSED_P(enc); return LITTLE2_IS_NAME_CHAR_MINBPC(p); } -static int PTRFASTCALL +static int little2_isNmstrtMin(const ENCODING *enc, const char *p) { UNUSED_P(enc); return LITTLE2_IS_NMSTRT_CHAR_MINBPC(p); @@ -774,7 +780,7 @@ little2_isNmstrtMin(const ENCODING *enc, const char *p) { # define IS_NMSTRT_CHAR_MINBPC(enc, p) LITTLE2_IS_NMSTRT_CHAR_MINBPC(p) # define XML_TOK_IMPL_C -# include "xmltok_impl.c" +#include "third_party/python/Modules/expat/xmltok_impl.inc" # undef XML_TOK_IMPL_C # undef MINBPC @@ -800,8 +806,8 @@ static const struct normal_encoding little2_encoding_ns # endif }, { -# include "asciitab.h" -# include "latin1tab.h" +#include "third_party/python/Modules/expat/asciitab.inc" +#include "third_party/python/Modules/expat/latin1tab.inc" }, STANDARD_VTABLE(little2_) NULL_VTABLE}; @@ -817,9 +823,9 @@ static const struct normal_encoding little2_encoding }, { #define BT_COLON BT_NMSTRT -#include "asciitab.h" +#include "third_party/python/Modules/expat/asciitab.inc" #undef BT_COLON -#include "latin1tab.h" +#include "third_party/python/Modules/expat/latin1tab.inc" }, STANDARD_VTABLE(little2_) NULL_VTABLE}; @@ -830,8 +836,8 @@ static const struct normal_encoding little2_encoding static const struct normal_encoding internal_little2_encoding_ns = {{VTABLE, 2, 0, 1}, { -# include "iasciitab.h" -# include "latin1tab.h" +# include "third_party/python/Modules/expat/iasciitab.inc" +# include "third_party/python/Modules/expat/latin1tab.inc" }, STANDARD_VTABLE(little2_) NULL_VTABLE}; @@ -841,9 +847,9 @@ static const struct normal_encoding internal_little2_encoding = {{VTABLE, 2, 0, 1}, { # define BT_COLON BT_NMSTRT -# include "iasciitab.h" +#include "third_party/python/Modules/expat/iasciitab.inc" # undef BT_COLON -# include "latin1tab.h" +#include "third_party/python/Modules/expat/latin1tab.inc" }, STANDARD_VTABLE(little2_) NULL_VTABLE}; @@ -862,30 +868,30 @@ static const struct normal_encoding internal_little2_encoding #ifdef XML_MIN_SIZE -static int PTRFASTCALL +static int big2_byteType(const ENCODING *enc, const char *p) { return BIG2_BYTE_TYPE(enc, p); } -static int PTRFASTCALL +static int big2_byteToAscii(const ENCODING *enc, const char *p) { UNUSED_P(enc); return BIG2_BYTE_TO_ASCII(p); } -static int PTRCALL +static int big2_charMatches(const ENCODING *enc, const char *p, int c) { UNUSED_P(enc); return BIG2_CHAR_MATCHES(p, c); } -static int PTRFASTCALL +static int big2_isNameMin(const ENCODING *enc, const char *p) { UNUSED_P(enc); return BIG2_IS_NAME_CHAR_MINBPC(p); } -static int PTRFASTCALL +static int big2_isNmstrtMin(const ENCODING *enc, const char *p) { UNUSED_P(enc); return BIG2_IS_NMSTRT_CHAR_MINBPC(p); @@ -909,7 +915,7 @@ big2_isNmstrtMin(const ENCODING *enc, const char *p) { # define IS_NMSTRT_CHAR_MINBPC(enc, p) BIG2_IS_NMSTRT_CHAR_MINBPC(p) # define XML_TOK_IMPL_C -# include "xmltok_impl.c" +#include "third_party/python/Modules/expat/xmltok_impl.inc" # undef XML_TOK_IMPL_C # undef MINBPC @@ -935,8 +941,8 @@ static const struct normal_encoding big2_encoding_ns # endif }, { -# include "asciitab.h" -# include "latin1tab.h" +#include "third_party/python/Modules/expat/asciitab.inc" +#include "third_party/python/Modules/expat/latin1tab.inc" }, STANDARD_VTABLE(big2_) NULL_VTABLE}; @@ -952,9 +958,9 @@ static const struct normal_encoding big2_encoding }, { #define BT_COLON BT_NMSTRT -#include "asciitab.h" +#include "third_party/python/Modules/expat/asciitab.inc" #undef BT_COLON -#include "latin1tab.h" +#include "third_party/python/Modules/expat/latin1tab.inc" }, STANDARD_VTABLE(big2_) NULL_VTABLE}; @@ -965,8 +971,8 @@ static const struct normal_encoding big2_encoding static const struct normal_encoding internal_big2_encoding_ns = {{VTABLE, 2, 0, 1}, { -# include "iasciitab.h" -# include "latin1tab.h" +# include "third_party/python/Modules/expat/iasciitab.inc" +# include "third_party/python/Modules/expat/latin1tab.inc" }, STANDARD_VTABLE(big2_) NULL_VTABLE}; @@ -976,9 +982,9 @@ static const struct normal_encoding internal_big2_encoding = {{VTABLE, 2, 0, 1}, { # define BT_COLON BT_NMSTRT -# include "iasciitab.h" +#include "third_party/python/Modules/expat/iasciitab.inc" # undef BT_COLON -# include "latin1tab.h" +#include "third_party/python/Modules/expat/latin1tab.inc" }, STANDARD_VTABLE(big2_) NULL_VTABLE}; @@ -986,7 +992,7 @@ static const struct normal_encoding internal_big2_encoding #undef PREFIX -static int FASTCALL +static int streqci(const char *s1, const char *s2) { for (;;) { char c1 = *s1++; @@ -1007,7 +1013,7 @@ streqci(const char *s1, const char *s2) { return 1; } -static void PTRCALL +static void initUpdatePosition(const ENCODING *enc, const char *ptr, const char *end, POSITION *pos) { UNUSED_P(enc); @@ -1025,7 +1031,7 @@ toAscii(const ENCODING *enc, const char *ptr, const char *end) { return buf[0]; } -static int FASTCALL +static int isSpace(int c) { switch (c) { case 0x20: @@ -1212,7 +1218,7 @@ doParseXmlDecl(const ENCODING *(*encodingFinder)(const ENCODING *, const char *, return 1; } -static int FASTCALL +static int checkCharRefNumber(int result) { switch (result >> 8) { case 0xD8: @@ -1236,7 +1242,7 @@ checkCharRefNumber(int result) { return result; } -int FASTCALL +int XmlUtf8Encode(int c, char *buf) { enum { /* minN is minimum legal resulting value for N byte sequence */ @@ -1272,7 +1278,7 @@ XmlUtf8Encode(int c, char *buf) { return 0; /* LCOV_EXCL_LINE: this case too is eliminated before calling */ } -int FASTCALL +int XmlUtf16Encode(int charNum, unsigned short *buf) { if (charNum < 0) return 0; @@ -1304,7 +1310,7 @@ XmlSizeOfUnknownEncoding(void) { return sizeof(struct unknown_encoding); } -static int PTRFASTCALL +static int unknown_isName(const ENCODING *enc, const char *p) { const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); int c = uenc->convert(uenc->userData, p); @@ -1313,7 +1319,7 @@ unknown_isName(const ENCODING *enc, const char *p) { return UCS2_GET_NAMING(namePages, c >> 8, c & 0xFF); } -static int PTRFASTCALL +static int unknown_isNmstrt(const ENCODING *enc, const char *p) { const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); int c = uenc->convert(uenc->userData, p); @@ -1322,14 +1328,14 @@ unknown_isNmstrt(const ENCODING *enc, const char *p) { return UCS2_GET_NAMING(nmstrtPages, c >> 8, c & 0xFF); } -static int PTRFASTCALL +static int unknown_isInvalid(const ENCODING *enc, const char *p) { const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); int c = uenc->convert(uenc->userData, p); return (c & ~0xFFFF) || checkCharRefNumber(c) < 0; } -static enum XML_Convert_Result PTRCALL +static enum XML_Convert_Result unknown_toUtf8(const ENCODING *enc, const char **fromP, const char *fromLim, char **toP, const char *toLim) { const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); @@ -1359,7 +1365,7 @@ unknown_toUtf8(const ENCODING *enc, const char **fromP, const char *fromLim, } } -static enum XML_Convert_Result PTRCALL +static enum XML_Convert_Result unknown_toUtf16(const ENCODING *enc, const char **fromP, const char *fromLim, unsigned short **toP, const unsigned short *toLim) { const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); @@ -1483,7 +1489,7 @@ static const char KW_UTF_16LE[] = {ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_1, ASCII_6, ASCII_L, ASCII_E, '\0'}; -static int FASTCALL +static int getEncodingIndex(const char *name) { static const char *const encodingNames[] = { KW_ISO_8859_1, KW_US_ASCII, KW_UTF_8, KW_UTF_16, KW_UTF_16BE, KW_UTF_16LE, @@ -1626,7 +1632,7 @@ initScan(const ENCODING *const *encodingTable, const INIT_ENCODING *enc, #define NS(x) x #define ns(x) x #define XML_TOK_NS_C -#include "xmltok_ns.c" +#include "third_party/python/Modules/expat/xmltok_ns.inc" #undef XML_TOK_NS_C #undef NS #undef ns @@ -1637,7 +1643,7 @@ initScan(const ENCODING *const *encodingTable, const INIT_ENCODING *enc, # define ns(x) x##_ns # define XML_TOK_NS_C -# include "xmltok_ns.c" +#include "third_party/python/Modules/expat/xmltok_ns.inc" # undef XML_TOK_NS_C # undef NS diff --git a/third_party/python/Modules/expat/xmltok.h b/third_party/python/Modules/expat/xmltok.h index 933b5a637..bea6bb97d 100644 --- a/third_party/python/Modules/expat/xmltok.h +++ b/third_party/python/Modules/expat/xmltok.h @@ -1,42 +1,8 @@ -/* clang-format off */ -/* - __ __ _ - ___\ \/ /_ __ __ _| |_ - / _ \\ /| '_ \ / _` | __| - | __// \| |_) | (_| | |_ - \___/_/\_\ .__/ \__,_|\__| - |_| XML parser - - Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team - Licensed under the MIT license: - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to permit - persons to whom the Software is furnished to do so, subject to the - following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - #ifndef XmlTok_INCLUDED #define XmlTok_INCLUDED 1 - -#ifdef __cplusplus -extern "C" { -#endif +#include "third_party/python/Modules/expat/expat_external.h" +COSMOPOLITAN_C_START_ +/* clang-format off */ /* The following token may be returned by XmlContentTok */ #define XML_TOK_TRAILING_RSQB \ @@ -156,7 +122,7 @@ typedef struct { struct encoding; typedef struct encoding ENCODING; -typedef int(PTRCALL *SCANNER)(const ENCODING *, const char *, const char *, +typedef int( *SCANNER)(const ENCODING *, const char *, const char *, const char **); enum XML_Convert_Result { @@ -169,28 +135,28 @@ enum XML_Convert_Result { struct encoding { SCANNER scanners[XML_N_STATES]; SCANNER literalScanners[XML_N_LITERAL_TYPES]; - int(PTRCALL *nameMatchesAscii)(const ENCODING *, const char *, const char *, - const char *); - int(PTRFASTCALL *nameLength)(const ENCODING *, const char *); - const char *(PTRFASTCALL *skipS)(const ENCODING *, const char *); - int(PTRCALL *getAtts)(const ENCODING *enc, const char *ptr, int attsMax, - ATTRIBUTE *atts); - int(PTRFASTCALL *charRefNumber)(const ENCODING *enc, const char *ptr); - int(PTRCALL *predefinedEntityName)(const ENCODING *, const char *, - const char *); - void(PTRCALL *updatePosition)(const ENCODING *, const char *ptr, - const char *end, POSITION *); - int(PTRCALL *isPublicId)(const ENCODING *enc, const char *ptr, - const char *end, const char **badPtr); - enum XML_Convert_Result(PTRCALL *utf8Convert)(const ENCODING *enc, - const char **fromP, - const char *fromLim, char **toP, - const char *toLim); - enum XML_Convert_Result(PTRCALL *utf16Convert)(const ENCODING *enc, - const char **fromP, - const char *fromLim, - unsigned short **toP, - const unsigned short *toLim); + int(*nameMatchesAscii)(const ENCODING *, const char *, const char *, + const char *); + int(*nameLength)(const ENCODING *, const char *); + const char *(*skipS)(const ENCODING *, const char *); + int(*getAtts)(const ENCODING *enc, const char *ptr, int attsMax, + ATTRIBUTE *atts); + int(*charRefNumber)(const ENCODING *enc, const char *ptr); + int(*predefinedEntityName)(const ENCODING *, const char *, + const char *); + void(*updatePosition)(const ENCODING *, const char *ptr, + const char *end, POSITION *); + int(*isPublicId)(const ENCODING *enc, const char *ptr, + const char *end, const char **badPtr); + enum XML_Convert_Result(*utf8Convert)(const ENCODING *enc, + const char **fromP, + const char *fromLim, char **toP, + const char *toLim); + enum XML_Convert_Result(*utf16Convert)(const ENCODING *enc, + const char **fromP, + const char *fromLim, + unsigned short **toP, + const unsigned short *toLim); int minBytesPerChar; char isUtf8; char isUtf16; @@ -289,11 +255,11 @@ int XmlParseXmlDecl(int isGeneralTextEntity, const ENCODING *enc, int XmlInitEncoding(INIT_ENCODING *, const ENCODING **, const char *name); const ENCODING *XmlGetUtf8InternalEncoding(void); const ENCODING *XmlGetUtf16InternalEncoding(void); -int FASTCALL XmlUtf8Encode(int charNumber, char *buf); -int FASTCALL XmlUtf16Encode(int charNumber, unsigned short *buf); +int XmlUtf8Encode(int charNumber, char *buf); +int XmlUtf16Encode(int charNumber, unsigned short *buf); int XmlSizeOfUnknownEncoding(void); -typedef int(XMLCALL *CONVERTER)(void *userData, const char *p); +typedef int(*CONVERTER)(void *userData, const char *p); ENCODING *XmlInitUnknownEncoding(void *mem, int *table, CONVERTER convert, void *userData); @@ -309,8 +275,6 @@ const ENCODING *XmlGetUtf8InternalEncodingNS(void); const ENCODING *XmlGetUtf16InternalEncodingNS(void); ENCODING *XmlInitUnknownEncodingNS(void *mem, int *table, CONVERTER convert, void *userData); -#ifdef __cplusplus -} -#endif +COSMOPOLITAN_C_END_ #endif /* not XmlTok_INCLUDED */ diff --git a/third_party/python/Modules/expat/xmltok_impl.h b/third_party/python/Modules/expat/xmltok_impl.h.inc similarity index 100% rename from third_party/python/Modules/expat/xmltok_impl.h rename to third_party/python/Modules/expat/xmltok_impl.h.inc diff --git a/third_party/python/Modules/expat/xmltok_impl.c b/third_party/python/Modules/expat/xmltok_impl.inc similarity index 98% rename from third_party/python/Modules/expat/xmltok_impl.c rename to third_party/python/Modules/expat/xmltok_impl.inc index 0e8af24bd..f5880a790 100644 --- a/third_party/python/Modules/expat/xmltok_impl.c +++ b/third_party/python/Modules/expat/xmltok_impl.inc @@ -132,7 +132,7 @@ /* ptr points to character following "= end) @@ -418,7 +418,7 @@ PREFIX(cdataSectionTok)(const ENCODING *enc, const char *ptr, const char *end, /* ptr points to character following "= end) @@ -910,7 +910,7 @@ PREFIX(contentTok)(const ENCODING *enc, const char *ptr, const char *end, /* ptr points to character following "%" */ -static int PTRCALL +static int PREFIX(scanPercent)(const ENCODING *enc, const char *ptr, const char *end, const char **nextTokPtr) { REQUIRE_CHAR(enc, ptr, end); @@ -940,7 +940,7 @@ PREFIX(scanPercent)(const ENCODING *enc, const char *ptr, const char *end, return XML_TOK_PARTIAL; } -static int PTRCALL +static int PREFIX(scanPoundName)(const ENCODING *enc, const char *ptr, const char *end, const char **nextTokPtr) { REQUIRE_CHAR(enc, ptr, end); @@ -970,7 +970,7 @@ PREFIX(scanPoundName)(const ENCODING *enc, const char *ptr, const char *end, return -XML_TOK_POUND_NAME; } -static int PTRCALL +static int PREFIX(scanLit)(int open, const ENCODING *enc, const char *ptr, const char *end, const char **nextTokPtr) { while (HAS_CHAR(enc, ptr, end)) { @@ -1004,7 +1004,7 @@ PREFIX(scanLit)(int open, const ENCODING *enc, const char *ptr, const char *end, return XML_TOK_PARTIAL; } -static int PTRCALL +static int PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end, const char **nextTokPtr) { int tok; @@ -1244,7 +1244,7 @@ PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end, return -tok; } -static int PTRCALL +static int PREFIX(attributeValueTok)(const ENCODING *enc, const char *ptr, const char *end, const char **nextTokPtr) { const char *start; @@ -1313,7 +1313,7 @@ PREFIX(attributeValueTok)(const ENCODING *enc, const char *ptr, const char *end, return XML_TOK_DATA_CHARS; } -static int PTRCALL +static int PREFIX(entityValueTok)(const ENCODING *enc, const char *ptr, const char *end, const char **nextTokPtr) { const char *start; @@ -1380,7 +1380,7 @@ PREFIX(entityValueTok)(const ENCODING *enc, const char *ptr, const char *end, # ifdef XML_DTD -static int PTRCALL +static int PREFIX(ignoreSectionTok)(const ENCODING *enc, const char *ptr, const char *end, const char **nextTokPtr) { int level = 0; @@ -1432,7 +1432,7 @@ PREFIX(ignoreSectionTok)(const ENCODING *enc, const char *ptr, const char *end, # endif /* XML_DTD */ -static int PTRCALL +static int PREFIX(isPublicId)(const ENCODING *enc, const char *ptr, const char *end, const char **badPtr) { ptr += MINBPC(enc); @@ -1492,7 +1492,7 @@ PREFIX(isPublicId)(const ENCODING *enc, const char *ptr, const char *end, first attsMax attributes are stored in atts. */ -static int PTRCALL +static int PREFIX(getAtts)(const ENCODING *enc, const char *ptr, int attsMax, ATTRIBUTE *atts) { enum { other, inName, inValue } state = inName; @@ -1585,7 +1585,7 @@ PREFIX(getAtts)(const ENCODING *enc, const char *ptr, int attsMax, /* not reached */ } -static int PTRFASTCALL +static int PREFIX(charRefNumber)(const ENCODING *enc, const char *ptr) { int result = 0; /* skip &# */ @@ -1643,7 +1643,7 @@ PREFIX(charRefNumber)(const ENCODING *enc, const char *ptr) { return checkCharRefNumber(result); } -static int PTRCALL +static int PREFIX(predefinedEntityName)(const ENCODING *enc, const char *ptr, const char *end) { UNUSED_P(enc); @@ -1697,7 +1697,7 @@ PREFIX(predefinedEntityName)(const ENCODING *enc, const char *ptr, return 0; } -static int PTRCALL +static int PREFIX(nameMatchesAscii)(const ENCODING *enc, const char *ptr1, const char *end1, const char *ptr2) { UNUSED_P(enc); @@ -1716,7 +1716,7 @@ PREFIX(nameMatchesAscii)(const ENCODING *enc, const char *ptr1, return ptr1 == end1; } -static int PTRFASTCALL +static int PREFIX(nameLength)(const ENCODING *enc, const char *ptr) { const char *start = ptr; for (;;) { @@ -1746,7 +1746,7 @@ PREFIX(nameLength)(const ENCODING *enc, const char *ptr) { } } -static const char *PTRFASTCALL +static const char * PREFIX(skipS)(const ENCODING *enc, const char *ptr) { for (;;) { switch (BYTE_TYPE(enc, ptr)) { @@ -1761,7 +1761,7 @@ PREFIX(skipS)(const ENCODING *enc, const char *ptr) { } } -static void PTRCALL +static void PREFIX(updatePosition)(const ENCODING *enc, const char *ptr, const char *end, POSITION *pos) { while (HAS_CHAR(enc, ptr, end)) { diff --git a/third_party/python/Modules/expat/xmltok_ns.c b/third_party/python/Modules/expat/xmltok_ns.inc similarity index 98% rename from third_party/python/Modules/expat/xmltok_ns.c rename to third_party/python/Modules/expat/xmltok_ns.inc index 546876179..6475a4e38 100644 --- a/third_party/python/Modules/expat/xmltok_ns.c +++ b/third_party/python/Modules/expat/xmltok_ns.inc @@ -9,7 +9,7 @@ Copyright (c) 1997-2000 Thai Open Source Software Center Ltd Copyright (c) 2000-2017 Expat development team - Licensed under the MIT license: +i Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -58,14 +58,14 @@ static const ENCODING *const NS(encodings)[] = { &ns(utf8_encoding).enc /* NO_ENC */ }; -static int PTRCALL +static int NS(initScanProlog)(const ENCODING *enc, const char *ptr, const char *end, const char **nextTokPtr) { return initScan(NS(encodings), (const INIT_ENCODING *)enc, XML_PROLOG_STATE, ptr, end, nextTokPtr); } -static int PTRCALL +static int NS(initScanContent)(const ENCODING *enc, const char *ptr, const char *end, const char **nextTokPtr) { return initScan(NS(encodings), (const INIT_ENCODING *)enc, XML_CONTENT_STATE, diff --git a/third_party/python/Modules/faulthandler.c b/third_party/python/Modules/faulthandler.c index 385d95f19..3e93c8171 100644 --- a/third_party/python/Modules/faulthandler.c +++ b/third_party/python/Modules/faulthandler.c @@ -1,9 +1,29 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/pythread.h" +#include "libc/calls/calls.h" #include "libc/calls/sigbits.h" -#include "libc/sysv/consts/sa.h" +#include "libc/calls/struct/sigaction.h" +#include "libc/errno.h" #include "libc/sysv/consts/rlimit.h" +#include "libc/sysv/consts/sa.h" +#include "libc/sysv/consts/sig.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.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/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pythread.h" +#include "third_party/python/Include/sysmodule.h" +#include "third_party/python/Include/traceback.h" +#include "third_party/python/pyconfig.h" +/* clang-format off */ /* Allocate at maximum 100 MB of the stack to raise the stack overflow */ #define STACK_OVERFLOW_MAX_SIZE (100*1024*1024) @@ -83,19 +103,6 @@ typedef struct { static user_signal_t *user_signals; -/* the following macros come from Python: Modules/signalmodule.c */ -#ifndef NSIG -# if defined(_NSIG) -# define NSIG _NSIG /* For BSD/SysV */ -# elif defined(_SIGMAX) -# define NSIG (_SIGMAX + 1) /* For QNX */ -# elif defined(SIGMAX) -# define NSIG (SIGMAX + 1) /* For djgpp */ -# else -# define NSIG 64 /* Use a reasonable default value */ -# endif -#endif - static void faulthandler_user(int signum); #endif /* FAULTHANDLER_USER */ @@ -814,7 +821,7 @@ check_signum(int signum) return 0; } } - if (signum < 1 || NSIG <= signum) { + if (signum < 1 || Py_NSIG <= signum) { PyErr_SetString(PyExc_ValueError, "signal number out of range"); return 0; } @@ -853,10 +860,10 @@ faulthandler_register_py(PyObject *self, return NULL; if (user_signals == NULL) { - user_signals = PyMem_Malloc(NSIG * sizeof(user_signal_t)); + user_signals = PyMem_Malloc(Py_NSIG * sizeof(user_signal_t)); if (user_signals == NULL) return PyErr_NoMemory(); - memset(user_signals, 0, NSIG * sizeof(user_signal_t)); + bzero(user_signals, Py_NSIG * sizeof(user_signal_t)); } user = &user_signals[signum]; @@ -1148,7 +1155,7 @@ faulthandler_traverse(PyObject *module, visitproc visit, void *arg) #endif #ifdef FAULTHANDLER_USER if (user_signals != NULL) { - for (signum=0; signum < NSIG; signum++) + for (signum=0; signum < Py_NSIG; signum++) Py_VISIT(user_signals[signum].file); } #endif @@ -1381,7 +1388,7 @@ void _PyFaulthandler_Fini(void) #ifdef FAULTHANDLER_USER /* user */ if (user_signals != NULL) { - for (signum=0; signum < NSIG; signum++) + for (signum=0; signum < Py_NSIG; signum++) faulthandler_unregister(&user_signals[signum], signum); PyMem_Free(user_signals); user_signals = NULL; diff --git a/third_party/python/Modules/fcntlmodule.c b/third_party/python/Modules/fcntlmodule.c index d16af2a84..5990a2153 100644 --- a/third_party/python/Modules/fcntlmodule.c +++ b/third_party/python/Modules/fcntlmodule.c @@ -1,16 +1,23 @@ +#define PY_SSIZE_T_CLEAN #include "libc/calls/calls.h" #include "libc/calls/ioctl.h" #include "libc/calls/struct/flock.h" +#include "libc/errno.h" #include "libc/sysv/consts/f.h" #include "libc/sysv/consts/fd.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/fileobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" /* clang-format off */ /* fcntl module */ -#define PY_SSIZE_T_CLEAN - -#include "third_party/python/Include/Python.h" - /*[clinic input] module fcntl [clinic start generated code]*/ diff --git a/third_party/python/Modules/fpectlmodule.c b/third_party/python/Modules/fpectlmodule.c index 1740b8965..75a0f50a2 100644 --- a/third_party/python/Modules/fpectlmodule.c +++ b/third_party/python/Modules/fpectlmodule.c @@ -1,4 +1,13 @@ +#include "libc/runtime/runtime.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/methodobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/moduleobject.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pyport.h" /* clang-format off */ + /* --------------------------------------------------------------------- / Copyright (c) 1996. \ @@ -62,9 +71,6 @@ ** Version 1.0: September 20, 1996. Lee Busby, LLNL. */ -#include "libc/runtime/runtime.h" -#include "third_party/python/Include/Python.h" - #ifndef WANT_SIGFPE_HANDLER /* Define locally if they are not defined in Python. This gives only * the limited control to induce a core dump in case of an exception. diff --git a/third_party/python/Modules/fpetestmodule.c b/third_party/python/Modules/fpetestmodule.c index 508b1c77a..5a949c7dd 100644 --- a/third_party/python/Modules/fpetestmodule.c +++ b/third_party/python/Modules/fpetestmodule.c @@ -1,4 +1,12 @@ +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/methodobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pyfpe.h" +#include "third_party/python/Include/pythonrun.h" /* clang-format off */ + /* --------------------------------------------------------------------- / Copyright (c) 1996. \ @@ -42,8 +50,6 @@ */ -#include "Python.h" - static PyObject *fpe_error; PyMODINIT_FUNC PyInit_fpetest(void); diff --git a/third_party/python/Modules/gc_weakref.txt b/third_party/python/Modules/gc_weakref.txt deleted file mode 100644 index 2f18402c0..000000000 --- a/third_party/python/Modules/gc_weakref.txt +++ /dev/null @@ -1,219 +0,0 @@ -Intro -===== - -The basic rule for dealing with weakref callbacks (and __del__ methods too, -for that matter) during cyclic gc: - - Once gc has computed the set of unreachable objects, no Python-level - code can be allowed to access an unreachable object. - -If that can happen, then the Python code can resurrect unreachable objects -too, and gc can't detect that without starting over. Since gc eventually -runs tp_clear on all unreachable objects, if an unreachable object is -resurrected then tp_clear will eventually be called on it (or may already -have been called before resurrection). At best (and this has been an -historically common bug), tp_clear empties an instance's __dict__, and -"impossible" AttributeErrors result. At worst, tp_clear leaves behind an -insane object at the C level, and segfaults result (historically, most -often by setting a class's mro pointer to NULL, after which attribute -lookups performed by the class can segfault). - -OTOH, it's OK to run Python-level code that can't access unreachable -objects, and sometimes that's necessary. The chief example is the callback -attached to a reachable weakref W to an unreachable object O. Since O is -going away, and W is still alive, the callback must be invoked. Because W -is still alive, everything reachable from its callback is also reachable, -so it's also safe to invoke the callback (although that's trickier than it -sounds, since other reachable weakrefs to other unreachable objects may -still exist, and be accessible to the callback -- there are lots of painful -details like this covered in the rest of this file). - -Python 2.4/2.3.5 -================ - -The "Before 2.3.3" section below turned out to be wrong in some ways, but -I'm leaving it as-is because it's more right than wrong, and serves as a -wonderful example of how painful analysis can miss not only the forest for -the trees, but also miss the trees for the aphids sucking the trees -dry . - -The primary thing it missed is that when a weakref to a piece of cyclic -trash (CT) exists, then any call to any Python code whatsoever can end up -materializing a strong reference to that weakref's CT referent, and so -possibly resurrect an insane object (one for which cyclic gc has called-- or -will call before it's done --tp_clear()). It's not even necessarily that a -weakref callback or __del__ method does something nasty on purpose: as -soon as we execute Python code, threads other than the gc thread can run -too, and they can do ordinary things with weakrefs that end up resurrecting -CT while gc is running. - - http://www.python.org/sf/1055820 - -shows how innocent it can be, and also how nasty. Variants of the three -focussed test cases attached to that bug report are now part of Python's -standard Lib/test/test_gc.py. - -Jim Fulton gave the best nutshell summary of the new (in 2.4 and 2.3.5) -approach: - - Clearing cyclic trash can call Python code. If there are weakrefs to - any of the cyclic trash, then those weakrefs can be used to resurrect - the objects. Therefore, *before* clearing cyclic trash, we need to - remove any weakrefs. If any of the weakrefs being removed have - callbacks, then we need to save the callbacks and call them *after* all - of the weakrefs have been cleared. - -Alas, doing just that much doesn't work, because it overlooks what turned -out to be the much subtler problems that were fixed earlier, and described -below. We do clear all weakrefs to CT now before breaking cycles, but not -all callbacks encountered can be run later. That's explained in horrid -detail below. - -Older text follows, with a some later comments in [] brackets: - -Before 2.3.3 -============ - -Before 2.3.3, Python's cyclic gc didn't pay any attention to weakrefs. -Segfaults in Zope3 resulted. - -weakrefs in Python are designed to, at worst, let *other* objects learn -that a given object has died, via a callback function. The weakly -referenced object itself is not passed to the callback, and the presumption -is that the weakly referenced object is unreachable trash at the time the -callback is invoked. - -That's usually true, but not always. Suppose a weakly referenced object -becomes part of a clump of cyclic trash. When enough cycles are broken by -cyclic gc that the object is reclaimed, the callback is invoked. If it's -possible for the callback to get at objects in the cycle(s), then it may be -possible for those objects to access (via strong references in the cycle) -the weakly referenced object being torn down, or other objects in the cycle -that have already suffered a tp_clear() call. There's no guarantee that an -object is in a sane state after tp_clear(). Bad things (including -segfaults) can happen right then, during the callback's execution, or can -happen at any later time if the callback manages to resurrect an insane -object. - -[That missed that, in addition, a weakref to CT can exist outside CT, and - any callback into Python can use such a non-CT weakref to resurrect its CT - referent. The same bad kinds of things can happen then.] - -Note that if it's possible for the callback to get at objects in the trash -cycles, it must also be the case that the callback itself is part of the -trash cycles. Else the callback would have acted as an external root to -the current collection, and nothing reachable from it would be in cyclic -trash either. - -[Except that a non-CT callback can also use a non-CT weakref to get at - CT objects.] - -More, if the callback itself is in cyclic trash, then the weakref to which -the callback is attached must also be trash, and for the same kind of -reason: if the weakref acted as an external root, then the callback could -not have been cyclic trash. - -So a problem here requires that a weakref, that weakref's callback, and the -weakly referenced object, all be in cyclic trash at the same time. This -isn't easy to stumble into by accident while Python is running, and, indeed, -it took quite a while to dream up failing test cases. Zope3 saw segfaults -during shutdown, during the second call of gc in Py_Finalize, after most -modules had been torn down. That creates many trash cycles (esp. those -involving classes), making the problem much more likely. Once you -know what's required to provoke the problem, though, it's easy to create -tests that segfault before shutdown. - -In 2.3.3, before breaking cycles, we first clear all the weakrefs with -callbacks in cyclic trash. Since the weakrefs *are* trash, and there's no -defined-- or even predictable --order in which tp_clear() gets called on -cyclic trash, it's defensible to first clear weakrefs with callbacks. It's -a feature of Python's weakrefs too that when a weakref goes away, the -callback (if any) associated with it is thrown away too, unexecuted. - -[In 2.4/2.3.5, we first clear all weakrefs to CT objects, whether or not - those weakrefs are themselves CT, and whether or not they have callbacks. - The callbacks (if any) on non-CT weakrefs (if any) are invoked later, - after all weakrefs-to-CT have been cleared. The callbacks (if any) on CT - weakrefs (if any) are never invoked, for the excruciating reasons - explained here.] - -Just that much is almost enough to prevent problems, by throwing away -*almost* all the weakref callbacks that could get triggered by gc. The -problem remaining is that clearing a weakref with a callback decrefs the -callback object, and the callback object may *itself* be weakly referenced, -via another weakref with another callback. So the process of clearing -weakrefs can trigger callbacks attached to other weakrefs, and those -latter weakrefs may or may not be part of cyclic trash. - -So, to prevent any Python code from running while gc is invoking tp_clear() -on all the objects in cyclic trash, - -[That was always wrong: we can't stop Python code from running when gc - is breaking cycles. If an object with a __del__ method is not itself in - a cycle, but is reachable only from CT, then breaking cycles will, as a - matter of course, drop the refcount on that object to 0, and its __del__ - will run right then. What we can and must stop is running any Python - code that could access CT.] - it's not quite enough just to invoke -tp_clear() on weakrefs with callbacks first. Instead the weakref module -grew a new private function (_PyWeakref_ClearRef) that does only part of -tp_clear(): it removes the weakref from the weakly-referenced object's list -of weakrefs, but does not decref the callback object. So calling -_PyWeakref_ClearRef(wr) ensures that wr's callback object will never -trigger, and (unlike weakref's tp_clear()) also prevents any callback -associated *with* wr's callback object from triggering. - -[Although we may trigger such callbacks later, as explained below.] - -Then we can call tp_clear on all the cyclic objects and never trigger -Python code. - -[As above, not so: it means never trigger Python code that can access CT.] - -After we do that, the callback objects still need to be decref'ed. Callbacks -(if any) *on* the callback objects that were also part of cyclic trash won't -get invoked, because we cleared all trash weakrefs with callbacks at the -start. Callbacks on the callback objects that were not part of cyclic trash -acted as external roots to everything reachable from them, so nothing -reachable from them was part of cyclic trash, so gc didn't do any damage to -objects reachable from them, and it's safe to call them at the end of gc. - -[That's so. In addition, now we also invoke (if any) the callbacks on - non-CT weakrefs to CT objects, during the same pass that decrefs the - callback objects.] - -An alternative would have been to treat objects with callbacks like objects -with __del__ methods, refusing to collect them, appending them to gc.garbage -instead. That would have been much easier. Jim Fulton gave a strong -argument against that (on Python-Dev): - - There's a big difference between __del__ and weakref callbacks. - The __del__ method is "internal" to a design. When you design a - class with a del method, you know you have to avoid including the - class in cycles. - - Now, suppose you have a design that makes has no __del__ methods but - that does use cyclic data structures. You reason about the design, - run tests, and convince yourself you don't have a leak. - - Now, suppose some external code creates a weakref to one of your - objects. All of a sudden, you start leaking. You can look at your - code all you want and you won't find a reason for the leak. - -IOW, a class designer can out-think __del__ problems, but has no control -over who creates weakrefs to his classes or class instances. The class -user has little chance either of predicting when the weakrefs he creates -may end up in cycles. - -Callbacks on weakref callbacks are executed in an arbitrary order, and -that's not good (a primary reason not to collect cycles with objects with -__del__ methods is to avoid running finalizers in an arbitrary order). -However, a weakref callback on a weakref callback has got to be rare. -It's possible to do such a thing, so gc has to be robust against it, but -I doubt anyone has done it outside the test case I wrote for it. - -[The callbacks (if any) on non-CT weakrefs to CT objects are also executed - in an arbitrary order now. But they were before too, depending on the - vagaries of when tp_clear() happened to break enough cycles to trigger - them. People simply shouldn't try to use __del__ or weakref callbacks to - do fancy stuff.] diff --git a/third_party/python/Modules/gcmodule.c b/third_party/python/Modules/gcmodule.c index b04ad0a36..68979e9a9 100644 --- a/third_party/python/Modules/gcmodule.c +++ b/third_party/python/Modules/gcmodule.c @@ -1,4 +1,23 @@ +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/classobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/frameobject.h" +#include "third_party/python/Include/genobject.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pgenheaders.h" +#include "third_party/python/Include/pydtrace.h" +#include "third_party/python/Include/pytime.h" +#include "third_party/python/Include/setobject.h" +#include "third_party/python/Include/sysmodule.h" +#include "third_party/python/Include/warnings.h" +#include "third_party/python/Include/weakrefobject.h" /* clang-format off */ + /* Reference Cycle Garbage Collection @@ -29,11 +48,6 @@ #undef unreachable #endif -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/frameobject.h" -#include "third_party/python/Include/pydtrace.h" -#include "third_party/python/Include/pytime.h" - /* Get an object's GC head */ #define AS_GC(o) ((PyGC_Head *)(o)-1) diff --git a/third_party/python/Modules/getbuildinfo.c b/third_party/python/Modules/getbuildinfo.c index 99c6ecfa2..a92426c95 100644 --- a/third_party/python/Modules/getbuildinfo.c +++ b/third_party/python/Modules/getbuildinfo.c @@ -1,5 +1,6 @@ +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pylifecycle.h" /* clang-format off */ -#include "third_party/python/Include/Python.h" #ifndef DATE #ifdef __DATE__ diff --git a/third_party/python/Modules/getpath.c b/third_party/python/Modules/getpath.c index 6ffbb5b65..c90fa8779 100644 --- a/third_party/python/Modules/getpath.c +++ b/third_party/python/Modules/getpath.c @@ -1,9 +1,13 @@ +#include "libc/calls/calls.h" +#include "libc/calls/struct/stat.h" +#include "libc/errno.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/osdefs.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymem.h" /* clang-format off */ /* Return the initial module search path. */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/osdefs.h" - #pragma GCC diagnostic ignored "-Wunused-function" // search_for_exec_prefix #pragma GCC diagnostic ignored "-Wunused-but-set-variable" // separator @@ -93,6 +97,8 @@ * NOTE: Windows MSVC builds use PC/getpathp.c instead! */ +wchar_t *Py_GetProgramName(void); + #if !defined(PREFIX) || !defined(EXEC_PREFIX) || !defined(VERSION) || !defined(VPATH) #define PREFIX L"Lib" #define EXEC_PREFIX L"build" @@ -454,8 +460,6 @@ search_for_exec_prefix(wchar_t *argv0_path, wchar_t *home, static void calculate_path(void) { - extern wchar_t *Py_GetProgramName(void); - static wchar_t delimiter[2] = {DELIM, '\0'}; static wchar_t separator[2] = {SEP, '\0'}; /* ignore PYTHONPATH/PYTHONHOME for now */ @@ -539,10 +543,13 @@ calculate_path(void) /* not searching for pyvenv.cfg */ - - /* Avoid absolute path for prefix */ - wcsncpy(prefix, L"third_party/python/Lib", MAXPATHLEN); + wcsncpy(prefix, + L"third_party/python/Lib", + MAXPATHLEN); + /* wcsncpy(prefix, */ + /* L"zip!third_party/python/Lib/", */ + /* MAXPATHLEN); */ /* Avoid absolute path for exec_prefix */ wcsncpy(exec_prefix, L"build/lib.linux-x86_64-3.6", MAXPATHLEN); @@ -636,7 +643,6 @@ Py_SetPath(const wchar_t *path) module_search_path = NULL; } if (path != NULL) { - extern wchar_t *Py_GetProgramName(void); wchar_t *prog = Py_GetProgramName(); wcsncpy(progpath, prog, MAXPATHLEN); exec_prefix[0] = prefix[0] = L'\0'; diff --git a/third_party/python/Modules/grpmodule.c b/third_party/python/Modules/grpmodule.c index 75457e9bd..200e96497 100644 --- a/third_party/python/Modules/grpmodule.c +++ b/third_party/python/Modules/grpmodule.c @@ -1,11 +1,21 @@ +#include "third_party/musl/passwd.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/structseq.h" +#include "third_party/python/Include/unicodeobject.h" +#include "third_party/python/Include/warnings.h" +#include "third_party/python/Modules/clinic/grpmodule.inc" +#include "third_party/python/Modules/posixmodule.h" /* clang-format off */ /* UNIX group file access module */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Modules/posixmodule.h" -#include "third_party/musl/passwd.h" -#include "third_party/python/Modules/clinic/grpmodule.inc" /*[clinic input] module grp [clinic start generated code]*/ diff --git a/third_party/python/Modules/hashlib.h b/third_party/python/Modules/hashlib.h index 530b6b172..dc1484005 100644 --- a/third_party/python/Modules/hashlib.h +++ b/third_party/python/Modules/hashlib.h @@ -1,3 +1,6 @@ +#ifndef COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES_HASHLIB_H_ +#define COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES_HASHLIB_H_ +/* clang-format off */ /* Common code for use by all hashlib related modules. */ /* @@ -40,7 +43,7 @@ */ #ifdef WITH_THREAD -#include "pythread.h" +#include "third_party/python/Include/pythread.h" #define ENTER_HASHLIB(obj) \ if ((obj)->lock) { \ if (!PyThread_acquire_lock((obj)->lock, 0)) { \ @@ -62,3 +65,4 @@ * to allow the user to optimize based on the platform they're using. */ #define HASHLIB_GIL_MINSIZE 2048 +#endif /* COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES_HASHLIB_H_ */ diff --git a/third_party/python/Modules/hashtable.c b/third_party/python/Modules/hashtable.c index f7efb4ad2..5984b9dfc 100644 --- a/third_party/python/Modules/hashtable.c +++ b/third_party/python/Modules/hashtable.c @@ -1,4 +1,8 @@ +#include "third_party/python/Include/pyhash.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Modules/hashtable.h" /* clang-format off */ + /* The implementation of the hash table (_Py_hashtable_t) is based on the cfuhash project: http://sourceforge.net/projects/libcfu/ @@ -45,9 +49,6 @@ ---------------------------------- */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Modules/hashtable.h" - #define HASHTABLE_MIN_SIZE 16 #define HASHTABLE_HIGH 0.50 #define HASHTABLE_LOW 0.10 @@ -171,7 +172,7 @@ _Py_hashtable_new_full(size_t key_size, size_t data_size, alloc.free(ht); return NULL; } - memset(ht->buckets, 0, buckets_size); + bzero(ht->buckets, buckets_size); ht->hash_func = hash_func; ht->compare_func = compare_func; @@ -432,7 +433,7 @@ hashtable_rehash(_Py_hashtable_t *ht) /* memory allocation failed */ return; } - memset(ht->buckets, 0, buckets_size); + bzero(ht->buckets, buckets_size); ht->num_buckets = new_size; diff --git a/third_party/python/Modules/hashtable.h b/third_party/python/Modules/hashtable.h index dbec23d28..9e4b433e9 100644 --- a/third_party/python/Modules/hashtable.h +++ b/third_party/python/Modules/hashtable.h @@ -1,6 +1,9 @@ #ifndef Py_HASHTABLE_H #define Py_HASHTABLE_H -/* The whole API is private */ +#include "libc/assert.h" +#include "libc/str/str.h" +#include "third_party/python/Include/pyport.h" +/* clang-format off */ #ifndef Py_LIMITED_API /* Single linked list */ @@ -102,23 +105,23 @@ typedef struct _Py_hashtable_t { } _Py_hashtable_t; /* hash a pointer (void*) */ -PyAPI_FUNC(Py_uhash_t) _Py_hashtable_hash_ptr( +Py_uhash_t _Py_hashtable_hash_ptr( struct _Py_hashtable_t *ht, const void *pkey); /* comparison using memcmp() */ -PyAPI_FUNC(int) _Py_hashtable_compare_direct( +int _Py_hashtable_compare_direct( _Py_hashtable_t *ht, const void *pkey, const _Py_hashtable_entry_t *entry); -PyAPI_FUNC(_Py_hashtable_t *) _Py_hashtable_new( +_Py_hashtable_t * _Py_hashtable_new( size_t key_size, size_t data_size, _Py_hashtable_hash_func hash_func, _Py_hashtable_compare_func compare_func); -PyAPI_FUNC(_Py_hashtable_t *) _Py_hashtable_new_full( +_Py_hashtable_t * _Py_hashtable_new_full( size_t key_size, size_t data_size, size_t init_size, @@ -126,12 +129,12 @@ PyAPI_FUNC(_Py_hashtable_t *) _Py_hashtable_new_full( _Py_hashtable_compare_func compare_func, _Py_hashtable_allocator_t *allocator); -PyAPI_FUNC(void) _Py_hashtable_destroy(_Py_hashtable_t *ht); +void _Py_hashtable_destroy(_Py_hashtable_t *ht); /* Return a copy of the hash table */ -PyAPI_FUNC(_Py_hashtable_t *) _Py_hashtable_copy(_Py_hashtable_t *src); +_Py_hashtable_t * _Py_hashtable_copy(_Py_hashtable_t *src); -PyAPI_FUNC(void) _Py_hashtable_clear(_Py_hashtable_t *ht); +void _Py_hashtable_clear(_Py_hashtable_t *ht); typedef int (*_Py_hashtable_foreach_func) (_Py_hashtable_t *ht, _Py_hashtable_entry_t *entry, @@ -140,19 +143,19 @@ typedef int (*_Py_hashtable_foreach_func) (_Py_hashtable_t *ht, /* Call func() on each entry of the hashtable. Iteration stops if func() result is non-zero, in this case it's the result of the call. Otherwise, the function returns 0. */ -PyAPI_FUNC(int) _Py_hashtable_foreach( +int _Py_hashtable_foreach( _Py_hashtable_t *ht, _Py_hashtable_foreach_func func, void *arg); -PyAPI_FUNC(size_t) _Py_hashtable_size(_Py_hashtable_t *ht); +size_t _Py_hashtable_size(_Py_hashtable_t *ht); /* Add a new entry to the hash. The key must not be present in the hash table. Return 0 on success, -1 on memory error. Don't call directly this function, but use _Py_HASHTABLE_SET() and _Py_HASHTABLE_SET_NODATA() macros */ -PyAPI_FUNC(int) _Py_hashtable_set( +int _Py_hashtable_set( _Py_hashtable_t *ht, size_t key_size, const void *pkey, @@ -171,7 +174,7 @@ PyAPI_FUNC(int) _Py_hashtable_set( Don't call directly this function, but use _Py_HASHTABLE_GET_ENTRY() macro */ -PyAPI_FUNC(_Py_hashtable_entry_t*) _Py_hashtable_get_entry( +_Py_hashtable_entry_t* _Py_hashtable_get_entry( _Py_hashtable_t *ht, size_t key_size, const void *pkey); @@ -184,7 +187,7 @@ PyAPI_FUNC(_Py_hashtable_entry_t*) _Py_hashtable_get_entry( exists, return 0 if the entry does not exist. Don't call directly this function, but use _Py_HASHTABLE_GET() macro */ -PyAPI_FUNC(int) _Py_hashtable_get( +int _Py_hashtable_get( _Py_hashtable_t *ht, size_t key_size, const void *pkey, @@ -196,7 +199,7 @@ PyAPI_FUNC(int) _Py_hashtable_get( /* Don't call directly this function, but use _Py_HASHTABLE_POP() macro */ -PyAPI_FUNC(int) _Py_hashtable_pop( +int _Py_hashtable_pop( _Py_hashtable_t *ht, size_t key_size, const void *pkey, @@ -206,6 +209,5 @@ PyAPI_FUNC(int) _Py_hashtable_pop( #define _Py_HASHTABLE_POP(TABLE, KEY, DATA) \ _Py_hashtable_pop(TABLE, sizeof(KEY), &(KEY), sizeof(DATA), &(DATA)) - #endif /* Py_LIMITED_API */ #endif diff --git a/third_party/python/Modules/itertoolsmodule.c b/third_party/python/Modules/itertoolsmodule.c index b7716b430..d35bcf244 100644 --- a/third_party/python/Modules/itertoolsmodule.c +++ b/third_party/python/Modules/itertoolsmodule.c @@ -1,8 +1,13 @@ -/* clang-format off */ - #define PY_SSIZE_T_CLEAN -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" #include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/tupleobject.h" +/* clang-format off */ /* Itertools module written and maintained by Raymond D. Hettinger diff --git a/third_party/python/Modules/main.c b/third_party/python/Modules/main.c index d52caa5ac..e83d64650 100644 --- a/third_party/python/Modules/main.c +++ b/third_party/python/Modules/main.c @@ -1,9 +1,25 @@ -/* clang-format off */ -/* Python interpreter main program */ - -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/osdefs.h" +#include "libc/calls/calls.h" +#include "libc/errno.h" +#include "libc/stdio/stdio.h" #include "libc/unicode/locale.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/osdefs.h" +#include "third_party/python/Include/patchlevel.h" +#include "third_party/python/Include/pgenheaders.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/pythonrun.h" +#include "third_party/python/Include/sysmodule.h" +/* clang-format off */ + +/* Python interpreter main program */ #if defined(MS_WINDOWS) #define PYTHONHOMEHELP "\\python{major}{minor}" @@ -562,7 +578,7 @@ Py_Main(int argc, wchar_t **argv) oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL)); setlocale(LC_ALL, ""); for (p = strtok(buf, ","); p != NULL; p = strtok(NULL, ",")) { -#ifdef __APPLE__ +#if defined(__APPLE__) || defined(__COSMOPOLITAN__) /* Use utf-8 on Mac OS X */ unicode = PyUnicode_FromString(p); #else diff --git a/third_party/python/Modules/mathmodule.c b/third_party/python/Modules/mathmodule.c index 64599862f..762e6ac47 100644 --- a/third_party/python/Modules/mathmodule.c +++ b/third_party/python/Modules/mathmodule.c @@ -1,4 +1,22 @@ +#include "libc/assert.h" +#include "libc/errno.h" +#include "libc/math.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/dtoa.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pyfpe.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymath.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pyport.h" +#include "third_party/python/Modules/_math.h" +#include "third_party/python/pyconfig.h" /* clang-format off */ + /* Math module -- standard C math library functions, pi and e */ /* Here are some comments from Tim Peters, extracted from the @@ -53,9 +71,6 @@ raised for division by zero and mod by zero. returned. */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Modules/_math.h" - /* sin(pi*x), giving accurate results for all finite x (especially x integral or close to an integer). This is here for use in the diff --git a/third_party/python/Modules/md5module.c b/third_party/python/Modules/md5module.c index 2e8298665..dd02246fe 100644 --- a/third_party/python/Modules/md5module.c +++ b/third_party/python/Modules/md5module.c @@ -1,7 +1,14 @@ +#include "libc/assert.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pystrhex.h" +#include "third_party/python/Modules/hashlib.h" /* clang-format off */ -/* MD5 module */ - -/* This module provides an interface to the MD5 algorithm */ /* See below for information about the original code this module was based upon. Additional work performed by: @@ -15,12 +22,6 @@ */ -/* MD5 objects */ - -#include "third_party/python/Include/Python.h" -#include "third_party/python/Modules/hashlib.h" -#include "third_party/python/Include/pystrhex.h" - /*[clinic input] module _md5 class MD5Type "MD5object *" "&PyType_Type" diff --git a/third_party/python/Modules/mmapmodule.c b/third_party/python/Modules/mmapmodule.c index 04b98b9fd..9420e294b 100644 --- a/third_party/python/Modules/mmapmodule.c +++ b/third_party/python/Modules/mmapmodule.c @@ -1,9 +1,27 @@ +#define PY_SSIZE_T_CLEAN +#include "libc/calls/calls.h" +#include "libc/calls/weirdtypes.h" #include "libc/mem/mem.h" #include "libc/runtime/sysconf.h" #include "libc/sysv/consts/map.h" #include "libc/sysv/consts/msync.h" #include "libc/sysv/consts/prot.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/sliceobject.h" +#include "third_party/python/Include/structmember.h" /* clang-format off */ + /* / Author: Sam Rushing / Hacked for Unix by AMK @@ -24,10 +42,6 @@ / ftp://squirl.nightmare.com/pub/python/python-ext. */ -#define PY_SSIZE_T_CLEAN -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" - #define UNIX #ifdef UNIX diff --git a/third_party/python/Modules/nismodule.c b/third_party/python/Modules/nismodule.c deleted file mode 100644 index 286e3ef6e..000000000 --- a/third_party/python/Modules/nismodule.c +++ /dev/null @@ -1,464 +0,0 @@ -/* clang-format off */ -/*********************************************************** - Written by: - Fred Gansevles - B&O group, - Faculteit der Informatica, - Universiteit Twente, - Enschede, - the Netherlands. -******************************************************************/ - -/* NIS module implementation */ - -#include "third_party/python/Include/Python.h" - -#ifdef __sgi -/* This is missing from rpcsvc/ypclnt.h */ -extern int yp_get_default_domain(char **); -#endif - -PyDoc_STRVAR(get_default_domain__doc__, -"get_default_domain() -> str\n\ -Corresponds to the C library yp_get_default_domain() call, returning\n\ -the default NIS domain.\n"); - -PyDoc_STRVAR(match__doc__, -"match(key, map, domain = defaultdomain)\n\ -Corresponds to the C library yp_match() call, returning the value of\n\ -key in the given map. Optionally domain can be specified but it\n\ -defaults to the system default domain.\n"); - -PyDoc_STRVAR(cat__doc__, -"cat(map, domain = defaultdomain)\n\ -Returns the entire map as a dictionary. Optionally domain can be\n\ -specified but it defaults to the system default domain.\n"); - -PyDoc_STRVAR(maps__doc__, -"maps(domain = defaultdomain)\n\ -Returns an array of all available NIS maps within a domain. If domain\n\ -is not specified it defaults to the system default domain.\n"); - -static PyObject *NisError; - -static PyObject * -nis_error (int err) -{ - PyErr_SetString(NisError, yperr_string(err)); - return NULL; -} - -static struct nis_map { - char *alias; - char *map; - int fix; -} aliases [] = { - {"passwd", "passwd.byname", 0}, - {"group", "group.byname", 0}, - {"networks", "networks.byaddr", 0}, - {"hosts", "hosts.byname", 0}, - {"protocols", "protocols.bynumber", 0}, - {"services", "services.byname", 0}, - {"aliases", "mail.aliases", 1}, /* created with 'makedbm -a' */ - {"ethers", "ethers.byname", 0}, - {0L, 0L, 0} -}; - -static char * -nis_mapname (char *map, int *pfix) -{ - int i; - - *pfix = 0; - for (i=0; aliases[i].alias != 0L; i++) { - if (!strcmp (aliases[i].alias, map) || !strcmp (aliases[i].map, map)) { - *pfix = aliases[i].fix; - return aliases[i].map; - } - } - - return map; -} - -#if defined(__APPLE__) || defined(__OpenBSD__) || defined(__FreeBSD__) -typedef int (*foreachfunc)(unsigned long, char *, int, char *, int, void *); -#else -typedef int (*foreachfunc)(int, char *, int, char *, int, char *); -#endif - -struct ypcallback_data { - PyObject *dict; - int fix; - PyThreadState *state; -}; - -static int -nis_foreach (int instatus, char *inkey, int inkeylen, char *inval, - int invallen, struct ypcallback_data *indata) -{ - if (instatus == YP_TRUE) { - PyObject *key; - PyObject *val; - int err; - - PyEval_RestoreThread(indata->state); - if (indata->fix) { - if (inkeylen > 0 && inkey[inkeylen-1] == '\0') - inkeylen--; - if (invallen > 0 && inval[invallen-1] == '\0') - invallen--; - } - key = PyUnicode_DecodeFSDefaultAndSize(inkey, inkeylen); - val = PyUnicode_DecodeFSDefaultAndSize(inval, invallen); - if (key == NULL || val == NULL) { - /* XXX error -- don't know how to handle */ - PyErr_Clear(); - Py_XDECREF(key); - Py_XDECREF(val); - indata->state = PyEval_SaveThread(); - return 1; - } - err = PyDict_SetItem(indata->dict, key, val); - Py_DECREF(key); - Py_DECREF(val); - if (err != 0) - PyErr_Clear(); - indata->state = PyEval_SaveThread(); - if (err != 0) - return 1; - return 0; - } - return 1; -} - -static PyObject * -nis_get_default_domain (PyObject *self) -{ - char *domain; - int err; - PyObject *res; - - if ((err = yp_get_default_domain(&domain)) != 0) - return nis_error(err); - - res = PyUnicode_FromStringAndSize (domain, strlen(domain)); - return res; -} - -static PyObject * -nis_match (PyObject *self, PyObject *args, PyObject *kwdict) -{ - char *match; - char *domain = NULL; - Py_ssize_t keylen; - int len; - char *key, *map; - int err; - PyObject *ukey, *bkey, *res; - int fix; - static char *kwlist[] = {"key", "map", "domain", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwdict, - "Us|s:match", kwlist, - &ukey, &map, &domain)) - return NULL; - if ((bkey = PyUnicode_EncodeFSDefault(ukey)) == NULL) - return NULL; - /* check for embedded null bytes */ - if (PyBytes_AsStringAndSize(bkey, &key, &keylen) == -1) { - Py_DECREF(bkey); - return NULL; - } - if (!domain && ((err = yp_get_default_domain(&domain)) != 0)) { - Py_DECREF(bkey); - return nis_error(err); - } - map = nis_mapname (map, &fix); - if (fix) - keylen++; - Py_BEGIN_ALLOW_THREADS - err = yp_match (domain, map, key, keylen, &match, &len); - Py_END_ALLOW_THREADS - Py_DECREF(bkey); - if (fix) - len--; - if (err != 0) - return nis_error(err); - res = PyUnicode_DecodeFSDefaultAndSize(match, len); - free (match); - return res; -} - -static PyObject * -nis_cat (PyObject *self, PyObject *args, PyObject *kwdict) -{ - char *domain = NULL; - char *map; - struct ypall_callback cb; - struct ypcallback_data data; - PyObject *dict; - int err; - static char *kwlist[] = {"map", "domain", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwdict, "s|s:cat", - kwlist, &map, &domain)) - return NULL; - if (!domain && ((err = yp_get_default_domain(&domain)) != 0)) - return nis_error(err); - dict = PyDict_New (); - if (dict == NULL) - return NULL; - cb.foreach = (foreachfunc)nis_foreach; - data.dict = dict; - map = nis_mapname (map, &data.fix); - cb.data = (char *)&data; - data.state = PyEval_SaveThread(); - err = yp_all (domain, map, &cb); - PyEval_RestoreThread(data.state); - if (err != 0) { - Py_DECREF(dict); - return nis_error(err); - } - return dict; -} - -/* These should be u_long on Sun h/w but not on 64-bit h/w. - This is not portable to machines with 16-bit ints and no prototypes */ -#ifndef YPPROC_MAPLIST -#define YPPROC_MAPLIST 11 -#endif -#ifndef YPPROG -#define YPPROG 100004 -#endif -#ifndef YPVERS -#define YPVERS 2 -#endif - -typedef char *domainname; -typedef char *mapname; - -enum nisstat { - NIS_TRUE = 1, - NIS_NOMORE = 2, - NIS_FALSE = 0, - NIS_NOMAP = -1, - NIS_NODOM = -2, - NIS_NOKEY = -3, - NIS_BADOP = -4, - NIS_BADDB = -5, - NIS_YPERR = -6, - NIS_BADARGS = -7, - NIS_VERS = -8 -}; -typedef enum nisstat nisstat; - -struct nismaplist { - mapname map; - struct nismaplist *next; -}; -typedef struct nismaplist nismaplist; - -struct nisresp_maplist { - nisstat stat; - nismaplist *maps; -}; -typedef struct nisresp_maplist nisresp_maplist; - -static struct timeval TIMEOUT = { 25, 0 }; - -static -bool_t -nis_xdr_domainname(XDR *xdrs, domainname *objp) -{ - if (!xdr_string(xdrs, objp, YPMAXDOMAIN)) { - return (FALSE); - } - return (TRUE); -} - -static -bool_t -nis_xdr_mapname(XDR *xdrs, mapname *objp) -{ - if (!xdr_string(xdrs, objp, YPMAXMAP)) { - return (FALSE); - } - return (TRUE); -} - -static -bool_t -nis_xdr_ypmaplist(XDR *xdrs, nismaplist *objp) -{ - if (!nis_xdr_mapname(xdrs, &objp->map)) { - return (FALSE); - } - if (!xdr_pointer(xdrs, (char **)&objp->next, - sizeof(nismaplist), (xdrproc_t)nis_xdr_ypmaplist)) - { - return (FALSE); - } - return (TRUE); -} - -static -bool_t -nis_xdr_ypstat(XDR *xdrs, nisstat *objp) -{ - if (!xdr_enum(xdrs, (enum_t *)objp)) { - return (FALSE); - } - return (TRUE); -} - - -static -bool_t -nis_xdr_ypresp_maplist(XDR *xdrs, nisresp_maplist *objp) -{ - if (!nis_xdr_ypstat(xdrs, &objp->stat)) { - return (FALSE); - } - if (!xdr_pointer(xdrs, (char **)&objp->maps, - sizeof(nismaplist), (xdrproc_t)nis_xdr_ypmaplist)) - { - return (FALSE); - } - return (TRUE); -} - - -static -nisresp_maplist * -nisproc_maplist_2(domainname *argp, CLIENT *clnt) -{ - static nisresp_maplist res; - - memset(&res, 0, sizeof(res)); - if (clnt_call(clnt, YPPROC_MAPLIST, - (xdrproc_t)nis_xdr_domainname, (caddr_t)argp, - (xdrproc_t)nis_xdr_ypresp_maplist, (caddr_t)&res, - TIMEOUT) != RPC_SUCCESS) - { - return (NULL); - } - return (&res); -} - -static -nismaplist * -nis_maplist (char *dom) -{ - nisresp_maplist *list; - CLIENT *cl; - char *server = NULL; - int mapi = 0; - - while (!server && aliases[mapi].map != 0L) { - yp_master (dom, aliases[mapi].map, &server); - mapi++; - } - if (!server) { - PyErr_SetString(NisError, "No NIS master found for any map"); - return NULL; - } - cl = clnt_create(server, YPPROG, YPVERS, "tcp"); - if (cl == NULL) { - PyErr_SetString(NisError, clnt_spcreateerror(server)); - goto finally; - } - list = nisproc_maplist_2 (&dom, cl); - clnt_destroy(cl); - if (list == NULL) - goto finally; - if (list->stat != NIS_TRUE) - goto finally; - - free(server); - return list->maps; - - finally: - free(server); - return NULL; -} - -static PyObject * -nis_maps (PyObject *self, PyObject *args, PyObject *kwdict) -{ - char *domain = NULL; - nismaplist *maps; - PyObject *list; - int err; - static char *kwlist[] = {"domain", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwdict, - "|s:maps", kwlist, &domain)) - return NULL; - if (!domain && ((err = yp_get_default_domain (&domain)) != 0)) { - nis_error(err); - return NULL; - } - - if ((maps = nis_maplist (domain)) == NULL) - return NULL; - if ((list = PyList_New(0)) == NULL) - return NULL; - for (; maps; maps = maps->next) { - PyObject *str = PyUnicode_FromString(maps->map); - if (!str || PyList_Append(list, str) < 0) - { - Py_XDECREF(str); - Py_DECREF(list); - list = NULL; - break; - } - Py_DECREF(str); - } - /* XXX Shouldn't we free the list of maps now? */ - return list; -} - -static PyMethodDef nis_methods[] = { - {"match", (PyCFunction)nis_match, - METH_VARARGS | METH_KEYWORDS, - match__doc__}, - {"cat", (PyCFunction)nis_cat, - METH_VARARGS | METH_KEYWORDS, - cat__doc__}, - {"maps", (PyCFunction)nis_maps, - METH_VARARGS | METH_KEYWORDS, - maps__doc__}, - {"get_default_domain", (PyCFunction)nis_get_default_domain, - METH_NOARGS, - get_default_domain__doc__}, - {NULL, NULL} /* Sentinel */ -}; - -PyDoc_STRVAR(nis__doc__, -"This module contains functions for accessing NIS maps.\n"); - -static struct PyModuleDef nismodule = { - PyModuleDef_HEAD_INIT, - "nis", - nis__doc__, - -1, - nis_methods, - NULL, - NULL, - NULL, - NULL -}; - -PyMODINIT_FUNC -PyInit_nis(void) -{ - PyObject *m, *d; - m = PyModule_Create(&nismodule); - if (m == NULL) - return NULL; - d = PyModule_GetDict(m); - NisError = PyErr_NewException("nis.error", NULL, NULL); - if (NisError != NULL) - PyDict_SetItemString(d, "error", NisError); - return m; -} diff --git a/third_party/python/Modules/ossaudiodev.c b/third_party/python/Modules/ossaudiodev.c index 10573e6b2..dbe92d7ef 100644 --- a/third_party/python/Modules/ossaudiodev.c +++ b/third_party/python/Modules/ossaudiodev.c @@ -1,3 +1,5 @@ +#define PY_SSIZE_T_CLEAN +#include "third_party/python/Include/structmember.h" /* clang-format off */ /* * ossaudiodev -- Python interface to the OSS (Open Sound System) API. @@ -20,10 +22,6 @@ * $Id$ */ -#define PY_SSIZE_T_CLEAN -#include "Python.h" -#include "structmember.h" - #ifdef HAVE_FCNTL_H #include #else @@ -31,13 +29,6 @@ #define O_WRONLY 01 #endif -#include -#ifdef __ANDROID__ -#include -#else -#include -#endif - #ifdef __linux__ #ifndef HAVE_STDINT_H diff --git a/third_party/python/Modules/overlapped.c b/third_party/python/Modules/overlapped.c index c5dea560b..b2ae3fe94 100644 --- a/third_party/python/Modules/overlapped.c +++ b/third_party/python/Modules/overlapped.c @@ -1,3 +1,4 @@ +#include "third_party/python/Include/structmember.h" /* clang-format off */ /* * Support for overlapped IO @@ -8,9 +9,6 @@ /* XXX check overflow and DWORD <-> Py_ssize_t conversions Check itemsize */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" - #define WINDOWS_LEAN_AND_MEAN #include #include @@ -442,14 +440,14 @@ overlapped_BindLocal(PyObject *self, PyObject *args) if (Family == AF_INET) { struct sockaddr_in addr; - memset(&addr, 0, sizeof(addr)); + bzero(&addr, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = 0; addr.sin_addr.S_un.S_addr = INADDR_ANY; ret = bind(Socket, (SOCKADDR*)&addr, sizeof(addr)) != SOCKET_ERROR; } else if (Family == AF_INET6) { struct sockaddr_in6 addr; - memset(&addr, 0, sizeof(addr)); + bzero(&addr, sizeof(addr)); addr.sin6_family = AF_INET6; addr.sin6_port = 0; addr.sin6_addr = in6addr_any; @@ -552,8 +550,8 @@ Overlapped_new(PyTypeObject *type, PyObject *args, PyObject *kwds) self->error = 0; self->type = TYPE_NONE; self->read_buffer = NULL; - memset(&self->overlapped, 0, sizeof(OVERLAPPED)); - memset(&self->write_buffer, 0, sizeof(Py_buffer)); + bzero(&self->overlapped, sizeof(OVERLAPPED)); + bzero(&self->write_buffer, sizeof(Py_buffer)); if (event) self->overlapped.hEvent = event; return (PyObject *)self; @@ -979,7 +977,7 @@ parse_address(PyObject *obj, SOCKADDR *Address, int Length) unsigned long FlowInfo; unsigned long ScopeId; - memset(Address, 0, Length); + bzero(Address, Length); if (PyArg_ParseTuple(obj, "uH", &Host, &Port)) { diff --git a/third_party/python/Modules/parsermodule.c b/third_party/python/Modules/parsermodule.c index b62430c09..0685b43ae 100644 --- a/third_party/python/Modules/parsermodule.c +++ b/third_party/python/Modules/parsermodule.c @@ -1,3 +1,22 @@ +#include "third_party/python/Include/Python-ast.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/compile.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/errcode.h" +#include "third_party/python/Include/graminit.h" +#include "third_party/python/Include/grammar.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/node.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/parsetok.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/token.h" +#include "third_party/python/Include/unicodeobject.h" /* clang-format off */ /* parsermodule.c * @@ -31,14 +50,6 @@ * Lib/symbol.h and Include/token.h. */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/Python-ast.h" -#include "third_party/python/Include/graminit.h" -#include "third_party/python/Include/node.h" -#include "third_party/python/Include/errcode.h" -#include "third_party/python/Include/token.h" -#include "third_party/python/Include/grammar.h" -#include "third_party/python/Include/parsetok.h" #undef Yield #include "third_party/python/Include/ast.h" diff --git a/third_party/python/Modules/posixmodule.c b/third_party/python/Modules/posixmodule.c index f0274d9f7..64b63b763 100644 --- a/third_party/python/Modules/posixmodule.c +++ b/third_party/python/Modules/posixmodule.c @@ -1,12 +1,53 @@ +#define PY_SSIZE_T_CLEAN #include "libc/alg/alg.h" +#include "libc/assert.h" +#include "libc/calls/calls.h" +#include "libc/calls/internal.h" +#include "libc/calls/struct/dirent.h" #include "libc/calls/termios.h" -#include "libc/sock/sock.h" +#include "libc/calls/weirdtypes.h" +#include "libc/errno.h" +#include "libc/runtime/dlfcn.h" #include "libc/runtime/sysconf.h" -#include "libc/sysv/consts/at.h" -#include "third_party/musl/passwd.h" +#include "libc/sock/sock.h" #include "libc/sysv/consts/at.h" #include "libc/sysv/consts/dt.h" -#include "libc/runtime/dlfcn.h" +#include "libc/sysv/consts/ex.h" +#include "libc/sysv/consts/f.h" +#include "libc/sysv/consts/grnd.h" +#include "libc/sysv/consts/o.h" +#include "libc/sysv/consts/posix.h" +#include "libc/sysv/consts/prio.h" +#include "libc/sysv/consts/sched.h" +#include "libc/sysv/consts/sf.h" +#include "libc/sysv/consts/sicode.h" +#include "libc/sysv/consts/st.h" +#include "libc/sysv/consts/w.h" +#include "libc/sysv/consts/waitid.h" +#include "libc/time/time.h" +#include "third_party/musl/passwd.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/fileobject.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/intrcheck.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pylifecycle.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pytime.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/structseq.h" +#include "third_party/python/Include/warnings.h" +#include "third_party/python/Modules/posixmodule.h" +#include "third_party/python/pyconfig.h" /* clang-format off */ /* POSIX module implementation */ @@ -21,23 +62,8 @@ #ifdef __APPLE__ - /* - * Step 1 of support for weak-linking a number of symbols existing on - * OSX 10.4 and later, see the comment in the #ifdef __APPLE__ block - * at the end of this file for more information. - */ -# pragma weak lchown -# pragma weak statvfs -# pragma weak fstatvfs - #endif /* __APPLE__ */ -#define PY_SSIZE_T_CLEAN - -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" -#include "third_party/python/Modules/posixmodule.h" - PyDoc_STRVAR(posix__doc__, "This module provides access to operating system functionality that is\n\ standardized by the C Standard and the POSIX standard (a thinly\n\ @@ -58,68 +84,14 @@ module os [clinic start generated code]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=94a0f0f978acae17]*/ -#ifndef _MSC_VER - -#if defined(__sgi)&&_COMPILER_VERSION>=700 -/* declare ctermid_r if compiling with MIPSPro 7.x in ANSI C mode - (default) */ -extern char *ctermid_r(char *); -#endif - -#ifndef HAVE_UNISTD_H -#if defined(PYCC_VACPP) -extern int mkdir(char *); -#else -#if ( defined(__WATCOMC__) || defined(_MSC_VER) ) && !defined(__QNX__) -extern int mkdir(const char *); -#else -extern int mkdir(const char *, mode_t); -#endif -#endif -#if defined(__IBMC__) || defined(__IBMCPP__) -extern int chdir(char *); -extern int rmdir(char *); -#else -extern int chdir(const char *); -extern int rmdir(const char *); -#endif -extern int chmod(const char *, mode_t); -/*#ifdef HAVE_FCHMOD -extern int fchmod(int, mode_t); -#endif*/ -/*#ifdef HAVE_LCHMOD -extern int lchmod(const char *, mode_t); -#endif*/ -extern int chown(const char *, uid_t, gid_t); -extern char *getcwd(char *, int); -extern char *strerror(int); -extern int link(const char *, const char *); -extern int rename(const char *, const char *); -extern int stat(const char *, struct stat *); -extern int unlink(const char *); -#ifdef HAVE_SYMLINK -extern int symlink(const char *, const char *); -#endif /* HAVE_SYMLINK */ -#ifdef HAVE_LSTAT -extern int lstat(const char *, struct stat *); -#endif /* HAVE_LSTAT */ -#endif /* !HAVE_UNISTD_H */ - -#endif /* !_MSC_VER */ - #ifdef HAVE_DIRENT_H #define NAMLEN(dirent) strlen((dirent)->d_name) #else -#if defined(__WATCOMC__) && !defined(__QNX__) -#define NAMLEN(dirent) strlen((dirent)->d_name) -#else -#define dirent direct #define NAMLEN(dirent) (dirent)->d_namlen #endif -#endif #ifndef MAXPATHLEN -#if defined(PATH_MAX) && PATH_MAX > 1024 +#if defined(PATH_MAX) && PATH_MAX > 1024 /* TODO: wut? */ #define MAXPATHLEN PATH_MAX #else #define MAXPATHLEN 1024 @@ -183,8 +155,8 @@ extern int lstat(const char *, struct stat *); #ifdef MS_WINDOWS /* defined in fileutils.c */ -PyAPI_FUNC(void) _Py_time_t_to_FILE_TIME(time_t, int, FILETIME *); -PyAPI_FUNC(void) _Py_attribute_data_to_stat(BY_HANDLE_FILE_INFORMATION *, +void _Py_time_t_to_FILE_TIME(time_t, int, FILETIME *); +void _Py_attribute_data_to_stat(BY_HANDLE_FILE_INFORMATION *, ULONG, struct _Py_stat_struct *); #endif @@ -587,7 +559,7 @@ dir_fd_converter(PyObject *o, void *p) * * Use as follows: * path_t path; - * memset(&path, 0, sizeof(path)); + * bzero(&path, sizeof(path)); * PyArg_ParseTuple(args, "O&", path_converter, &path); * // ... use values from path ... * path_cleanup(&path); @@ -992,17 +964,6 @@ win32_get_reparse_tag(HANDLE reparse_point_handle, ULONG *reparse_tag) #endif /* MS_WINDOWS */ -/* Return a dictionary corresponding to the POSIX environment table */ -#if defined(WITH_NEXT_FRAMEWORK) || (defined(__APPLE__) && defined(Py_ENABLE_SHARED)) -/* On Darwin/MacOSX a shared library or framework has no access to -** environ directly, we must obtain it with _NSGetEnviron(). See also -** man environ(7). -*/ -static char **environ; -#elif !defined(_MSC_VER) && ( !defined(__WATCOMC__) || defined(__QNX__) ) -extern char **environ; -#endif /* !_MSC_VER */ - static PyObject * convertenviron(void) { @@ -1260,7 +1221,7 @@ find_data_to_file_info(WIN32_FIND_DATAW *pFileData, BY_HANDLE_FILE_INFORMATION *info, ULONG *reparse_tag) { - memset(info, 0, sizeof(*info)); + bzero(info, sizeof(*info)); info->dwFileAttributes = pFileData->dwFileAttributes; info->ftCreationTime = pFileData->ftCreationTime; info->ftLastAccessTime = pFileData->ftLastAccessTime; @@ -3362,7 +3323,7 @@ _posix_listdir(path_t *path, PyObject *list) exit: if (dirp != NULL) { Py_BEGIN_ALLOW_THREADS -#if 0 && HAVE_FDOPENDIR +#if HAVE_FDOPENDIR if (fd > -1) rewinddir(dirp); #endif @@ -4375,7 +4336,7 @@ os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns, utime_t utime; - memset(&utime, 0, sizeof(utime_t)); + bzero(&utime, sizeof(utime_t)); if (times && (times != Py_None) && ns) { PyErr_SetString(PyExc_ValueError, @@ -6804,7 +6765,7 @@ posix_readlink(PyObject *self, PyObject *args, PyObject *kwargs) PyObject *return_value = NULL; static char *keywords[] = {"path", "dir_fd", NULL}; - memset(&path, 0, sizeof(path)); + bzero(&path, sizeof(path)); path.function_name = "readlink"; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|$O&:readlink", keywords, path_converter, &path, @@ -7486,11 +7447,6 @@ os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable) /*[clinic end generated code: output=db832a2d872ccc5f input=76e96f511be0352f]*/ { int res; -#if defined(HAVE_DUP3) && \ - !(defined(HAVE_FCNTL_H) && defined(F_DUP2FD_CLOEXEC)) - /* dup3() is available on Linux 2.6.27+ and glibc 2.9 */ - static int dup3_works = -1; -#endif if (fd < 0 || fd2 < 0) return posix_error(); @@ -7526,22 +7482,16 @@ os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable) #else -#ifdef HAVE_DUP3 - if (!inheritable && dup3_works != 0) { + if (!inheritable) { Py_BEGIN_ALLOW_THREADS res = dup3(fd, fd2, O_CLOEXEC); Py_END_ALLOW_THREADS - if (res < 0) { - if (dup3_works == -1) - dup3_works = (errno != ENOSYS); - if (dup3_works) - return posix_error(); - } + if (res < 0) + return posix_error(); } - if (inheritable || dup3_works == 0) + if (inheritable) { -#endif Py_BEGIN_ALLOW_THREADS res = dup2(fd, fd2); Py_END_ALLOW_THREADS @@ -7552,9 +7502,7 @@ os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable) close(fd2); return NULL; } -#ifdef HAVE_DUP3 } -#endif #endif @@ -7882,10 +7830,8 @@ posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict) int async_err = 0; off_t offset; -#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__APPLE__) -#ifndef __APPLE__ + if (IsFreebsd() || IsXnu()) { Py_ssize_t len; -#endif PyObject *headers = NULL, *trailers = NULL; Py_buffer *hbuf, *tbuf; off_t sbytes; @@ -7899,15 +7845,18 @@ posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict) sf.headers = NULL; sf.trailers = NULL; -#ifdef __APPLE__ + if (IsXnu()) { if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iiO&O&|OOi:sendfile", keywords, &out, &in, Py_off_t_converter, &offset, Py_off_t_converter, &sbytes, -#else - if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iiO&n|OOi:sendfile", - keywords, &out, &in, Py_off_t_converter, &offset, &len, -#endif &headers, &trailers, &flags)) return NULL; + } else { + if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iiO&n|OOi:sendfile", + keywords, &out, &in, Py_off_t_converter, &offset, &len, + &headers, &trailers, &flags)) + return NULL; + } + if (headers != NULL) { if (!PySequence_Check(headers)) { PyErr_SetString(PyExc_TypeError, @@ -7927,18 +7876,17 @@ posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict) if (iov_setup(&(sf.headers), &hbuf, headers, sf.hdr_cnt, PyBUF_SIMPLE) < 0) return NULL; -#ifdef __APPLE__ + if (IsXnu()) { for (i = 0; i < sf.hdr_cnt; i++) { Py_ssize_t blen = sf.headers[i].iov_len; -# define OFF_T_MAX 0x7fffffffffffffff - if (sbytes >= OFF_T_MAX - blen) { + if (sbytes >= 0x7fffffffffffffff - blen) { PyErr_SetString(PyExc_OverflowError, "sendfile() header is too large"); return NULL; } sbytes += blen; } -#endif + } } } } @@ -7968,11 +7916,11 @@ posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict) _Py_BEGIN_SUPPRESS_IPH do { Py_BEGIN_ALLOW_THREADS -#ifdef __APPLE__ - ret = sendfile(in, out, offset, &sbytes, &sf, flags); -#else - ret = sendfile(in, out, offset, len, &sf, &sbytes, flags); -#endif + if (IsXnu()) { + ret = sys_sendfile_xnu(in, out, offset, &sbytes, &sf, flags); + } else { + ret = sys_sendfile_freebsd(in, out, offset, len, &sf, &sbytes, flags); + } Py_END_ALLOW_THREADS } while (ret < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals())); _Py_END_SUPPRESS_IPH @@ -8004,8 +7952,7 @@ done: #else return Py_BuildValue("L", sbytes); #endif - -#else + } else { Py_ssize_t count; PyObject *offobj; static char *keywords[] = {"out", "in", @@ -8013,18 +7960,18 @@ done: if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iiOn:sendfile", keywords, &out, &in, &offobj, &count)) return NULL; -#ifdef __linux__ - if (offobj == Py_None) { - do { - Py_BEGIN_ALLOW_THREADS - ret = sendfile(out, in, NULL, count); - Py_END_ALLOW_THREADS - } while (ret < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals())); - if (ret < 0) - return (!async_err) ? posix_error() : NULL; - return Py_BuildValue("n", ret); + if (IsLinux()) { + if (offobj == Py_None) { + do { + Py_BEGIN_ALLOW_THREADS + ret = sys_sendfile(out, in, NULL, count); + Py_END_ALLOW_THREADS + } while (ret < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals())); + if (ret < 0) + return (!async_err) ? posix_error() : NULL; + return Py_BuildValue("n", ret); + } } -#endif if (!Py_off_t_converter(offobj, &offset)) return NULL; @@ -8036,7 +7983,7 @@ done: if (ret < 0) return (!async_err) ? posix_error() : NULL; return Py_BuildValue("n", ret); -#endif + } } #endif /* HAVE_SENDFILE */ @@ -8115,46 +8062,14 @@ os_pipe_impl(PyObject *module) /*[clinic end generated code: output=ff9b76255793b440 input=02535e8c8fa6c4d4]*/ { int fds[2]; -#ifdef MS_WINDOWS - HANDLE read, write; - SECURITY_ATTRIBUTES attr; - BOOL ok; -#else int res; -#endif -#ifdef MS_WINDOWS - attr.nLength = sizeof(attr); - attr.lpSecurityDescriptor = NULL; - attr.bInheritHandle = FALSE; - - Py_BEGIN_ALLOW_THREADS - _Py_BEGIN_SUPPRESS_IPH - ok = CreatePipe(&read, &write, &attr, 0); - if (ok) { - fds[0] = _open_osfhandle((intptr_t)read, _O_RDONLY); - fds[1] = _open_osfhandle((intptr_t)write, _O_WRONLY); - if (fds[0] == -1 || fds[1] == -1) { - CloseHandle(read); - CloseHandle(write); - ok = 0; - } - } - _Py_END_SUPPRESS_IPH - Py_END_ALLOW_THREADS - - if (!ok) - return PyErr_SetFromWindowsErr(0); -#else - -#ifdef HAVE_PIPE2 Py_BEGIN_ALLOW_THREADS res = pipe2(fds, O_CLOEXEC); Py_END_ALLOW_THREADS if (res != 0 && errno == ENOSYS) { -#endif Py_BEGIN_ALLOW_THREADS res = pipe(fds); Py_END_ALLOW_THREADS @@ -8171,13 +8086,10 @@ os_pipe_impl(PyObject *module) return NULL; } } -#ifdef HAVE_PIPE2 } -#endif if (res != 0) return PyErr_SetFromErrno(PyExc_OSError); -#endif /* !MS_WINDOWS */ return Py_BuildValue("(ii)", fds[0], fds[1]); } #endif /* HAVE_PIPE */ @@ -8329,12 +8241,13 @@ os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd) do { Py_BEGIN_ALLOW_THREADS -#ifdef HAVE_MKFIFOAT - if (dir_fd != DEFAULT_DIR_FD) + if (dir_fd != DEFAULT_DIR_FD) { result = mkfifoat(dir_fd, path->narrow, mode); - else -#endif + if (result == -1 && result == ENOSYS) + result = mkfifo(path->narrow, mode); + } else { result = mkfifo(path->narrow, mode); + } Py_END_ALLOW_THREADS } while (result != 0 && errno == EINTR && !(async_err = PyErr_CheckSignals())); @@ -8381,11 +8294,11 @@ os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device, do { Py_BEGIN_ALLOW_THREADS -#ifdef HAVE_MKNODAT - if (dir_fd != DEFAULT_DIR_FD) + if (dir_fd != DEFAULT_DIR_FD) { result = mknodat(dir_fd, path->narrow, mode, device); - else -#endif + if (result == -1 && result == ENOSYS) + result = mknod(path->narrow, mode, device); + } else result = mknod(path->narrow, mode, device); Py_END_ALLOW_THREADS } while (result != 0 && errno == EINTR && @@ -8469,15 +8382,10 @@ os_ftruncate_impl(PyObject *module, int fd, Py_off_t length) { int result; int async_err = 0; - do { Py_BEGIN_ALLOW_THREADS _Py_BEGIN_SUPPRESS_IPH -#ifdef MS_WINDOWS - result = _chsize_s(fd, length); -#else result = ftruncate(fd, length); -#endif _Py_END_SUPPRESS_IPH Py_END_ALLOW_THREADS } while (result != 0 && errno == EINTR && @@ -8506,28 +8414,13 @@ os_truncate_impl(PyObject *module, path_t *path, Py_off_t length) /*[clinic end generated code: output=43009c8df5c0a12b input=77229cf0b50a9b77]*/ { int result; -#ifdef MS_WINDOWS - int fd; -#endif if (path->fd != -1) return os_ftruncate_impl(module, path->fd, length); Py_BEGIN_ALLOW_THREADS _Py_BEGIN_SUPPRESS_IPH -#ifdef MS_WINDOWS - fd = _wopen(path->wide, _O_WRONLY | _O_BINARY | _O_NOINHERIT); - if (fd < 0) - result = -1; - else { - result = _chsize_s(fd, length); - close(fd); - if (result < 0) - errno = result; - } -#else result = truncate(path->narrow, length); -#endif _Py_END_SUPPRESS_IPH Py_END_ALLOW_THREADS if (result < 0) @@ -10822,40 +10715,8 @@ static PyObject * os_cpu_count_impl(PyObject *module) /*[clinic end generated code: output=5fc29463c3936a9c input=e7c8f4ba6dbbadd3]*/ { - int ncpu = 0; -#ifdef MS_WINDOWS - /* Vista is supported and the GetMaximumProcessorCount API is Win7+ - Need to fallback to Vista behavior if this call isn't present */ - HINSTANCE hKernel32; - hKernel32 = GetModuleHandleW(L"KERNEL32"); - - static DWORD(CALLBACK *_GetMaximumProcessorCount)(WORD) = NULL; - *(FARPROC*)&_GetMaximumProcessorCount = GetProcAddress(hKernel32, - "GetMaximumProcessorCount"); - if (_GetMaximumProcessorCount != NULL) { - ncpu = _GetMaximumProcessorCount(ALL_PROCESSOR_GROUPS); - } - else { - SYSTEM_INFO sysinfo; - GetSystemInfo(&sysinfo); - ncpu = sysinfo.dwNumberOfProcessors; - } -#elif defined(__hpux) - ncpu = mpctl(MPC_GETNUMSPUS, NULL, NULL); -#elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN) - ncpu = sysconf(_SC_NPROCESSORS_ONLN); -#elif defined(__DragonFly__) || \ - defined(__OpenBSD__) || \ - defined(__FreeBSD__) || \ - defined(__NetBSD__) || \ - defined(__APPLE__) - int mib[2]; - size_t len = sizeof(ncpu); - mib[0] = CTL_HW; - mib[1] = HW_NCPU; - if (sysctl(mib, 2, &ncpu, &len, NULL, 0) != 0) - ncpu = 0; -#endif + int ncpu; + ncpu = GetCpuCount(); if (ncpu >= 1) return PyLong_FromLong(ncpu); else @@ -11813,7 +11674,7 @@ posix_scandir(PyObject *self, PyObject *args, PyObject *kwargs) iterator = PyObject_New(ScandirIterator, &ScandirIteratorType); if (!iterator) return NULL; - memset(&iterator->path, 0, sizeof(path_t)); + bzero(&iterator->path, sizeof(path_t)); iterator->path.function_name = "scandir"; iterator->path.nullable = 1; @@ -11838,7 +11699,7 @@ posix_scandir(PyObject *self, PyObject *args, PyObject *kwargs) iterator->handle = FindFirstFileW(path_strW, &iterator->file_data); Py_END_ALLOW_THREADS - PyMem_Free(path_strW); + PyeeMem_Free(path_strW); if (iterator->handle == INVALID_HANDLE_VALUE) { path_error(&iterator->path); @@ -12231,72 +12092,45 @@ enable_symlink() static int all_ins(PyObject *m) { -#ifdef F_OK if (PyModule_AddIntMacro(m, F_OK)) return -1; -#endif -#ifdef R_OK if (PyModule_AddIntMacro(m, R_OK)) return -1; -#endif -#ifdef W_OK if (PyModule_AddIntMacro(m, W_OK)) return -1; -#endif -#ifdef X_OK if (PyModule_AddIntMacro(m, X_OK)) return -1; -#endif #ifdef NGROUPS_MAX if (PyModule_AddIntMacro(m, NGROUPS_MAX)) return -1; #endif #ifdef TMP_MAX if (PyModule_AddIntMacro(m, TMP_MAX)) return -1; #endif -#ifdef WCONTINUED - if (PyModule_AddIntMacro(m, WCONTINUED)) return -1; -#endif -#ifdef WNOHANG - if (PyModule_AddIntMacro(m, WNOHANG)) return -1; -#endif -#ifdef WUNTRACED - if (PyModule_AddIntMacro(m, WUNTRACED)) return -1; -#endif -#ifdef O_RDONLY + if (WCONTINUED && PyModule_AddIntMacro(m, WCONTINUED)) return -1; + if (WNOHANG && PyModule_AddIntMacro(m, WNOHANG)) return -1; + if (WUNTRACED && PyModule_AddIntMacro(m, WUNTRACED)) return -1; if (PyModule_AddIntMacro(m, O_RDONLY)) return -1; -#endif -#ifdef O_WRONLY if (PyModule_AddIntMacro(m, O_WRONLY)) return -1; -#endif -#ifdef O_RDWR if (PyModule_AddIntMacro(m, O_RDWR)) return -1; -#endif -#ifdef O_NDELAY + if (PyModule_AddIntMacro(m, O_ACCMODE)) return -1; if (PyModule_AddIntMacro(m, O_NDELAY)) return -1; -#endif -#ifdef O_NONBLOCK if (PyModule_AddIntMacro(m, O_NONBLOCK)) return -1; -#endif -#ifdef O_APPEND if (PyModule_AddIntMacro(m, O_APPEND)) return -1; -#endif -#ifdef O_DSYNC - if (PyModule_AddIntMacro(m, O_DSYNC)) return -1; -#endif -#ifdef O_RSYNC - if (PyModule_AddIntMacro(m, O_RSYNC)) return -1; -#endif -#ifdef O_SYNC - if (PyModule_AddIntMacro(m, O_SYNC)) return -1; -#endif -#ifdef O_NOCTTY - if (PyModule_AddIntMacro(m, O_NOCTTY)) return -1; -#endif -#ifdef O_CREAT + if (PyModule_AddIntMacro(m, O_CLOEXEC)) return -1; if (PyModule_AddIntMacro(m, O_CREAT)) return -1; -#endif -#ifdef O_EXCL - if (PyModule_AddIntMacro(m, O_EXCL)) return -1; -#endif -#ifdef O_TRUNC - if (PyModule_AddIntMacro(m, O_TRUNC)) return -1; -#endif + if (PyModule_AddIntMacro(m, O_LARGEFILE)) return -1; + if (O_DSYNC && PyModule_AddIntMacro(m, O_DSYNC)) return -1; + if (O_RSYNC && PyModule_AddIntMacro(m, O_RSYNC)) return -1; + if (O_SYNC && PyModule_AddIntMacro(m, O_SYNC)) return -1; + if (O_NOCTTY && PyModule_AddIntMacro(m, O_NOCTTY)) return -1; + if (O_EXCL && PyModule_AddIntMacro(m, O_EXCL)) return -1; + if (O_TRUNC && PyModule_AddIntMacro(m, O_TRUNC)) return -1; + if (O_EXEC && PyModule_AddIntMacro(m, O_EXEC)) return -1; + if (O_SEARCH && PyModule_AddIntMacro(m, O_SEARCH)) return -1; + if (O_SHLOCK && PyModule_AddIntMacro(m, O_SHLOCK)) return -1; + if (O_EXLOCK && PyModule_AddIntMacro(m, O_EXLOCK)) return -1; + if (O_TTY_INIT && PyModule_AddIntMacro(m, O_TTY_INIT)) return -1; + if (O_TMPFILE && PyModule_AddIntMacro(m, O_TMPFILE)) return -1; + if (O_PATH && PyModule_AddIntMacro(m, O_PATH)) return -1; + if (PyModule_AddIntMacro(m, PRIO_PROCESS)) return -1; + if (PyModule_AddIntMacro(m, PRIO_PGRP)) return -1; + if (PyModule_AddIntMacro(m, PRIO_USER)) return -1; #ifdef O_BINARY if (PyModule_AddIntMacro(m, O_BINARY)) return -1; #endif @@ -12306,48 +12140,6 @@ all_ins(PyObject *m) #ifdef O_XATTR if (PyModule_AddIntMacro(m, O_XATTR)) return -1; #endif -#ifdef O_LARGEFILE - if (PyModule_AddIntMacro(m, O_LARGEFILE)) return -1; -#endif -#ifndef __GNU__ -#ifdef O_SHLOCK - if (PyModule_AddIntMacro(m, O_SHLOCK)) return -1; -#endif -#ifdef O_EXLOCK - if (PyModule_AddIntMacro(m, O_EXLOCK)) return -1; -#endif -#endif -#ifdef O_EXEC - if (PyModule_AddIntMacro(m, O_EXEC)) return -1; -#endif -#ifdef O_SEARCH - if (PyModule_AddIntMacro(m, O_SEARCH)) return -1; -#endif -#ifdef O_PATH - if (PyModule_AddIntMacro(m, O_PATH)) return -1; -#endif -#ifdef O_TTY_INIT - if (PyModule_AddIntMacro(m, O_TTY_INIT)) return -1; -#endif -#ifdef O_TMPFILE - if (PyModule_AddIntMacro(m, O_TMPFILE)) return -1; -#endif -#ifdef PRIO_PROCESS - if (PyModule_AddIntMacro(m, PRIO_PROCESS)) return -1; -#endif -#ifdef PRIO_PGRP - if (PyModule_AddIntMacro(m, PRIO_PGRP)) return -1; -#endif -#ifdef PRIO_USER - if (PyModule_AddIntMacro(m, PRIO_USER)) return -1; -#endif -#ifdef O_CLOEXEC - if (PyModule_AddIntMacro(m, O_CLOEXEC)) return -1; -#endif -#ifdef O_ACCMODE - if (PyModule_AddIntMacro(m, O_ACCMODE)) return -1; -#endif - #ifdef SEEK_HOLE if (PyModule_AddIntMacro(m, SEEK_HOLE)) return -1; @@ -12379,195 +12171,86 @@ all_ins(PyObject *m) if (PyModule_AddIntMacro(m, O_SEQUENTIAL)) return -1; #endif -/* GNU extensions. */ -#ifdef O_ASYNC /* Send a SIGIO signal whenever input or output becomes available on file descriptor */ - if (PyModule_AddIntMacro(m, O_ASYNC)) return -1; -#endif -#ifdef O_DIRECT + if (O_ASYNC && PyModule_AddIntMacro(m, O_ASYNC)) return -1; /* Direct disk access. */ - if (PyModule_AddIntMacro(m, O_DIRECT)) return -1; -#endif -#ifdef O_DIRECTORY + if (O_DIRECT && PyModule_AddIntMacro(m, O_DIRECT)) return -1; /* Must be a directory. */ if (PyModule_AddIntMacro(m, O_DIRECTORY)) return -1; -#endif -#ifdef O_NOFOLLOW /* Do not follow links. */ - if (PyModule_AddIntMacro(m, O_NOFOLLOW)) return -1; -#endif + if (O_NOFOLLOW && PyModule_AddIntMacro(m, O_NOFOLLOW)) return -1; #ifdef O_NOLINKS /* Fails if link count of the named file is greater than 1 */ if (PyModule_AddIntMacro(m, O_NOLINKS)) return -1; #endif -#ifdef O_NOATIME /* Do not update the access time. */ - if (PyModule_AddIntMacro(m, O_NOATIME)) return -1; -#endif + if (O_NOATIME && PyModule_AddIntMacro(m, O_NOATIME)) return -1; /* These come from sysexits.h */ -#ifdef EX_OK if (PyModule_AddIntMacro(m, EX_OK)) return -1; -#endif /* EX_OK */ -#ifdef EX_USAGE if (PyModule_AddIntMacro(m, EX_USAGE)) return -1; -#endif /* EX_USAGE */ -#ifdef EX_DATAERR if (PyModule_AddIntMacro(m, EX_DATAERR)) return -1; -#endif /* EX_DATAERR */ -#ifdef EX_NOINPUT if (PyModule_AddIntMacro(m, EX_NOINPUT)) return -1; -#endif /* EX_NOINPUT */ -#ifdef EX_NOUSER if (PyModule_AddIntMacro(m, EX_NOUSER)) return -1; -#endif /* EX_NOUSER */ -#ifdef EX_NOHOST if (PyModule_AddIntMacro(m, EX_NOHOST)) return -1; -#endif /* EX_NOHOST */ -#ifdef EX_UNAVAILABLE if (PyModule_AddIntMacro(m, EX_UNAVAILABLE)) return -1; -#endif /* EX_UNAVAILABLE */ -#ifdef EX_SOFTWARE if (PyModule_AddIntMacro(m, EX_SOFTWARE)) return -1; -#endif /* EX_SOFTWARE */ -#ifdef EX_OSERR if (PyModule_AddIntMacro(m, EX_OSERR)) return -1; -#endif /* EX_OSERR */ -#ifdef EX_OSFILE if (PyModule_AddIntMacro(m, EX_OSFILE)) return -1; -#endif /* EX_OSFILE */ -#ifdef EX_CANTCREAT if (PyModule_AddIntMacro(m, EX_CANTCREAT)) return -1; -#endif /* EX_CANTCREAT */ -#ifdef EX_IOERR if (PyModule_AddIntMacro(m, EX_IOERR)) return -1; -#endif /* EX_IOERR */ -#ifdef EX_TEMPFAIL if (PyModule_AddIntMacro(m, EX_TEMPFAIL)) return -1; -#endif /* EX_TEMPFAIL */ -#ifdef EX_PROTOCOL if (PyModule_AddIntMacro(m, EX_PROTOCOL)) return -1; -#endif /* EX_PROTOCOL */ -#ifdef EX_NOPERM if (PyModule_AddIntMacro(m, EX_NOPERM)) return -1; -#endif /* EX_NOPERM */ -#ifdef EX_CONFIG if (PyModule_AddIntMacro(m, EX_CONFIG)) return -1; -#endif /* EX_CONFIG */ -#ifdef EX_NOTFOUND - if (PyModule_AddIntMacro(m, EX_NOTFOUND)) return -1; -#endif /* EX_NOTFOUND */ /* statvfs */ -#ifdef ST_RDONLY - if (PyModule_AddIntMacro(m, ST_RDONLY)) return -1; -#endif /* ST_RDONLY */ -#ifdef ST_NOSUID - if (PyModule_AddIntMacro(m, ST_NOSUID)) return -1; -#endif /* ST_NOSUID */ + if (ST_RDONLY && PyModule_AddIntMacro(m, ST_RDONLY)) return -1; + if (ST_NOSUID && PyModule_AddIntMacro(m, ST_NOSUID)) return -1; - /* GNU extensions */ -#ifdef ST_NODEV - if (PyModule_AddIntMacro(m, ST_NODEV)) return -1; -#endif /* ST_NODEV */ -#ifdef ST_NOEXEC - if (PyModule_AddIntMacro(m, ST_NOEXEC)) return -1; -#endif /* ST_NOEXEC */ -#ifdef ST_SYNCHRONOUS - if (PyModule_AddIntMacro(m, ST_SYNCHRONOUS)) return -1; -#endif /* ST_SYNCHRONOUS */ -#ifdef ST_MANDLOCK - if (PyModule_AddIntMacro(m, ST_MANDLOCK)) return -1; -#endif /* ST_MANDLOCK */ -#ifdef ST_WRITE - if (PyModule_AddIntMacro(m, ST_WRITE)) return -1; -#endif /* ST_WRITE */ -#ifdef ST_APPEND - if (PyModule_AddIntMacro(m, ST_APPEND)) return -1; -#endif /* ST_APPEND */ -#ifdef ST_NOATIME - if (PyModule_AddIntMacro(m, ST_NOATIME)) return -1; -#endif /* ST_NOATIME */ -#ifdef ST_NODIRATIME - if (PyModule_AddIntMacro(m, ST_NODIRATIME)) return -1; -#endif /* ST_NODIRATIME */ -#ifdef ST_RELATIME - if (PyModule_AddIntMacro(m, ST_RELATIME)) return -1; -#endif /* ST_RELATIME */ + if (ST_NODEV && PyModule_AddIntMacro(m, ST_NODEV)) return -1; + if (ST_NOEXEC && PyModule_AddIntMacro(m, ST_NOEXEC)) return -1; + if (ST_SYNCHRONOUS && PyModule_AddIntMacro(m, ST_SYNCHRONOUS)) return -1; + if (ST_MANDLOCK && PyModule_AddIntMacro(m, ST_MANDLOCK)) return -1; + if (ST_WRITE && PyModule_AddIntMacro(m, ST_WRITE)) return -1; + if (ST_APPEND && PyModule_AddIntMacro(m, ST_APPEND)) return -1; + if (ST_NOATIME && PyModule_AddIntMacro(m, ST_NOATIME)) return -1; + if (ST_NODIRATIME && PyModule_AddIntMacro(m, ST_NODIRATIME)) return -1; + if (ST_RELATIME && PyModule_AddIntMacro(m, ST_RELATIME)) return -1; /* FreeBSD sendfile() constants */ -#ifdef SF_NODISKIO - if (PyModule_AddIntMacro(m, SF_NODISKIO)) return -1; -#endif -#ifdef SF_MNOWAIT - if (PyModule_AddIntMacro(m, SF_MNOWAIT)) return -1; -#endif -#ifdef SF_SYNC - if (PyModule_AddIntMacro(m, SF_SYNC)) return -1; -#endif + if (SF_NODISKIO && PyModule_AddIntMacro(m, SF_NODISKIO)) return -1; + if (SF_MNOWAIT && PyModule_AddIntMacro(m, SF_MNOWAIT)) return -1; + if (SF_SYNC && PyModule_AddIntMacro(m, SF_SYNC)) return -1; /* constants for posix_fadvise */ -#ifdef POSIX_FADV_NORMAL - if (PyModule_AddIntMacro(m, POSIX_FADV_NORMAL)) return -1; -#endif -#ifdef POSIX_FADV_SEQUENTIAL - if (PyModule_AddIntMacro(m, POSIX_FADV_SEQUENTIAL)) return -1; -#endif -#ifdef POSIX_FADV_RANDOM - if (PyModule_AddIntMacro(m, POSIX_FADV_RANDOM)) return -1; -#endif -#ifdef POSIX_FADV_NOREUSE - if (PyModule_AddIntMacro(m, POSIX_FADV_NOREUSE)) return -1; -#endif -#ifdef POSIX_FADV_WILLNEED - if (PyModule_AddIntMacro(m, POSIX_FADV_WILLNEED)) return -1; -#endif -#ifdef POSIX_FADV_DONTNEED - if (PyModule_AddIntMacro(m, POSIX_FADV_DONTNEED)) return -1; -#endif + if (POSIX_FADV_NORMAL && PyModule_AddIntMacro(m, POSIX_FADV_NORMAL)) return -1; + if (POSIX_FADV_SEQUENTIAL && PyModule_AddIntMacro(m, POSIX_FADV_SEQUENTIAL)) return -1; + if (POSIX_FADV_RANDOM && PyModule_AddIntMacro(m, POSIX_FADV_RANDOM)) return -1; + if (POSIX_FADV_NOREUSE && PyModule_AddIntMacro(m, POSIX_FADV_NOREUSE)) return -1; + if (POSIX_FADV_WILLNEED && PyModule_AddIntMacro(m, POSIX_FADV_WILLNEED)) return -1; + if (POSIX_FADV_DONTNEED && PyModule_AddIntMacro(m, POSIX_FADV_DONTNEED)) return -1; /* constants for waitid */ #if defined(HAVE_SYS_WAIT_H) && defined(HAVE_WAITID) - if (PyModule_AddIntMacro(m, P_PID)) return -1; - if (PyModule_AddIntMacro(m, P_PGID)) return -1; - if (PyModule_AddIntMacro(m, P_ALL)) return -1; + if (P_PID && PyModule_AddIntMacro(m, P_PID)) return -1; + if (P_PGID && PyModule_AddIntMacro(m, P_PGID)) return -1; + if (P_ALL && PyModule_AddIntMacro(m, P_ALL)) return -1; #endif -#ifdef WEXITED - if (PyModule_AddIntMacro(m, WEXITED)) return -1; -#endif -#ifdef WNOWAIT - if (PyModule_AddIntMacro(m, WNOWAIT)) return -1; -#endif -#ifdef WSTOPPED - if (PyModule_AddIntMacro(m, WSTOPPED)) return -1; -#endif -#ifdef CLD_EXITED + if (WEXITED && PyModule_AddIntMacro(m, WEXITED)) return -1; + if (WNOWAIT && PyModule_AddIntMacro(m, WNOWAIT)) return -1; + if (WSTOPPED && PyModule_AddIntMacro(m, WSTOPPED)) return -1; if (PyModule_AddIntMacro(m, CLD_EXITED)) return -1; -#endif -#ifdef CLD_DUMPED if (PyModule_AddIntMacro(m, CLD_DUMPED)) return -1; -#endif -#ifdef CLD_TRAPPED if (PyModule_AddIntMacro(m, CLD_TRAPPED)) return -1; -#endif -#ifdef CLD_CONTINUED if (PyModule_AddIntMacro(m, CLD_CONTINUED)) return -1; -#endif /* constants for lockf */ -#ifdef F_LOCK - if (PyModule_AddIntMacro(m, F_LOCK)) return -1; -#endif -#ifdef F_TLOCK - if (PyModule_AddIntMacro(m, F_TLOCK)) return -1; -#endif -#ifdef F_ULOCK - if (PyModule_AddIntMacro(m, F_ULOCK)) return -1; -#endif -#ifdef F_TEST - if (PyModule_AddIntMacro(m, F_TEST)) return -1; -#endif + if (F_LOCK && PyModule_AddIntMacro(m, F_LOCK)) return -1; + if (F_TLOCK && PyModule_AddIntMacro(m, F_TLOCK)) return -1; + if (F_ULOCK && PyModule_AddIntMacro(m, F_ULOCK)) return -1; + if (F_TEST && PyModule_AddIntMacro(m, F_TEST)) return -1; #ifdef HAVE_SPAWNV if (PyModule_AddIntConstant(m, "P_WAIT", _P_WAIT)) return -1; @@ -12641,10 +12324,8 @@ all_ins(PyObject *m) if (PyModule_AddIntMacro(m, RTLD_DEEPBIND)) return -1; #endif -#ifdef HAVE_GETRANDOM_SYSCALL if (PyModule_AddIntMacro(m, GRND_RANDOM)) return -1; if (PyModule_AddIntMacro(m, GRND_NONBLOCK)) return -1; -#endif return 0; } @@ -12849,15 +12530,7 @@ INITFUNC(void) if (PyStructSequence_InitType2(&StatVFSResultType, &statvfs_result_desc) < 0) return NULL; -#ifdef NEED_TICKS_PER_SECOND -# if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK) ticks_per_second = sysconf(_SC_CLK_TCK); -# elif defined(HZ) - ticks_per_second = HZ; -# else - ticks_per_second = 60; /* magic fallback value; may be bogus */ -# endif -#endif #if defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) sched_param_desc.name = MODNAME ".sched_param"; diff --git a/third_party/python/Modules/posixmodule.h b/third_party/python/Modules/posixmodule.h index 2c5545a59..1975ed686 100644 --- a/third_party/python/Modules/posixmodule.h +++ b/third_party/python/Modules/posixmodule.h @@ -1,13 +1,15 @@ #ifndef Py_POSIXMODULE_H #define Py_POSIXMODULE_H +#include "libc/calls/weirdtypes.h" +#include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ #ifndef Py_LIMITED_API #ifndef MS_WINDOWS -PyAPI_FUNC(PyObject *) _PyLong_FromUid(uid_t); -PyAPI_FUNC(PyObject *) _PyLong_FromGid(gid_t); -PyAPI_FUNC(int) _Py_Uid_Converter(PyObject *, void *); -PyAPI_FUNC(int) _Py_Gid_Converter(PyObject *, void *); +PyObject *_PyLong_FromUid(uid_t); +PyObject *_PyLong_FromGid(gid_t); +int _Py_Uid_Converter(PyObject *, void *); +int _Py_Gid_Converter(PyObject *, void *); #endif /* MS_WINDOWS */ #endif diff --git a/third_party/python/Modules/pwdmodule.c b/third_party/python/Modules/pwdmodule.c index 0bed920b1..250ad53db 100644 --- a/third_party/python/Modules/pwdmodule.c +++ b/third_party/python/Modules/pwdmodule.c @@ -1,12 +1,18 @@ #include "third_party/musl/passwd.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/structseq.h" +#include "third_party/python/Include/unicodeobject.h" +#include "third_party/python/Modules/clinic/pwdmodule.inc" +#include "third_party/python/Modules/posixmodule.h" /* clang-format off */ /* UNIX password file access module */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Modules/posixmodule.h" - -#include "third_party/python/Modules/clinic/pwdmodule.inc" /*[clinic input] module pwd [clinic start generated code]*/ diff --git a/third_party/python/Modules/pyexpat.c b/third_party/python/Modules/pyexpat.c index ffc59c8b2..e413cae18 100644 --- a/third_party/python/Modules/pyexpat.c +++ b/third_party/python/Modules/pyexpat.c @@ -1,8 +1,21 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" +#include "libc/fmt/fmt.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/bytearrayobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/dictobject.h" #include "third_party/python/Include/frameobject.h" -#include "third_party/python/Modules/expat/expat.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pycapsule.h" #include "third_party/python/Include/pyexpat.h" +#include "third_party/python/Include/pyhash.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/sysmodule.h" +#include "third_party/python/Include/traceback.h" +#include "third_party/python/Modules/expat/expat.h" +/* clang-format off */ /* Do not emit Clinic output to a file as that wreaks havoc with conditionally included methods. */ diff --git a/third_party/python/Modules/readline.c b/third_party/python/Modules/readline.c index a3cee8bb1..a226761cb 100644 --- a/third_party/python/Modules/readline.c +++ b/third_party/python/Modules/readline.c @@ -1,4 +1,5 @@ /* clang-format off */ + /* This module makes GNU readline available to Python. It has ideas * contributed by Lee Busby, LLNL, and William Magro, Cornell Theory * Center. The completer interface was inspired by Lele Gaifax. More @@ -6,7 +7,6 @@ */ /* Standard definitions */ -#include "third_party/python/Include/Python.h" #if defined(HAVE_SETLOCALE) /* GNU readline() mistakenly sets the LC_CTYPE locale. diff --git a/third_party/python/Modules/resource.c b/third_party/python/Modules/resource.c index 3898db045..b5980e2ea 100644 --- a/third_party/python/Modules/resource.c +++ b/third_party/python/Modules/resource.c @@ -1,7 +1,20 @@ -/* clang-format off */ - -#include "third_party/python/Include/Python.h" +#include "libc/calls/calls.h" +#include "libc/calls/struct/rlimit.h" +#include "libc/calls/struct/rusage.h" +#include "libc/calls/weirdtypes.h" +#include "libc/errno.h" #include "libc/sysv/consts/rlim.h" +#include "libc/sysv/consts/rlimit.h" +#include "libc/sysv/consts/rusage.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/structseq.h" +#include "third_party/python/pyconfig.h" +/* clang-format off */ /* On some systems, these aren't in any header file. On others they are, with inconsistent prototypes. @@ -324,109 +337,36 @@ PyInit_resource(void) (PyObject*) &StructRUsageType); /* insert constants */ -#ifdef RLIMIT_CPU - PyModule_AddIntMacro(m, RLIMIT_CPU); -#endif + if (RLIMIT_CPU!=127) PyModule_AddIntMacro(m, RLIMIT_CPU); + if (RLIMIT_FSIZE!=127) PyModule_AddIntMacro(m, RLIMIT_FSIZE); + if (RLIMIT_DATA!=127) PyModule_AddIntMacro(m, RLIMIT_DATA); + if (RLIMIT_STACK!=127) PyModule_AddIntMacro(m, RLIMIT_STACK); + if (RLIMIT_CORE!=127) PyModule_AddIntMacro(m, RLIMIT_CORE); + if (RLIMIT_NOFILE!=127) PyModule_AddIntMacro(m, RLIMIT_NOFILE); + if (RLIMIT_VMEM!=127) PyModule_AddIntMacro(m, RLIMIT_VMEM); + if (RLIMIT_AS!=127) PyModule_AddIntMacro(m, RLIMIT_AS); + if (RLIMIT_RSS!=127) PyModule_AddIntMacro(m, RLIMIT_RSS); + if (RLIMIT_NPROC!=127) PyModule_AddIntMacro(m, RLIMIT_NPROC); + if (RLIMIT_MEMLOCK!=127) PyModule_AddIntMacro(m, RLIMIT_MEMLOCK); + if (RLIMIT_SBSIZE!=127) PyModule_AddIntMacro(m, RLIMIT_SBSIZE); + + /* Linux specific */ + if (RLIMIT_MSGQUEUE!=127) PyModule_AddIntMacro(m, RLIMIT_MSGQUEUE); + if (RLIMIT_NICE!=127) PyModule_AddIntMacro(m, RLIMIT_NICE); + if (RLIMIT_RTPRIO!=127) PyModule_AddIntMacro(m, RLIMIT_RTPRIO); + if (RLIMIT_RTTIME!=127) PyModule_AddIntMacro(m, RLIMIT_RTTIME); + if (RLIMIT_SIGPENDING!=127) PyModule_AddIntMacro(m, RLIMIT_SIGPENDING); -#ifdef RLIMIT_FSIZE - PyModule_AddIntMacro(m, RLIMIT_FSIZE); -#endif + /* FreeBSD specific */ + if (RLIMIT_SWAP!=127) PyModule_AddIntMacro(m, RLIMIT_SWAP); + if (RLIMIT_SBSIZE!=127) PyModule_AddIntMacro(m, RLIMIT_SBSIZE); + if (RLIMIT_NPTS!=127) PyModule_AddIntMacro(m, RLIMIT_NPTS); -#ifdef RLIMIT_DATA - PyModule_AddIntMacro(m, RLIMIT_DATA); -#endif - -#ifdef RLIMIT_STACK - PyModule_AddIntMacro(m, RLIMIT_STACK); -#endif - -#ifdef RLIMIT_CORE - PyModule_AddIntMacro(m, RLIMIT_CORE); -#endif - -#ifdef RLIMIT_NOFILE - PyModule_AddIntMacro(m, RLIMIT_NOFILE); -#endif - -#ifdef RLIMIT_OFILE - PyModule_AddIntMacro(m, RLIMIT_OFILE); -#endif - -#ifdef RLIMIT_VMEM - PyModule_AddIntMacro(m, RLIMIT_VMEM); -#endif - -#ifdef RLIMIT_AS - PyModule_AddIntMacro(m, RLIMIT_AS); -#endif - -#ifdef RLIMIT_RSS - PyModule_AddIntMacro(m, RLIMIT_RSS); -#endif - -#ifdef RLIMIT_NPROC - PyModule_AddIntMacro(m, RLIMIT_NPROC); -#endif - -#ifdef RLIMIT_MEMLOCK - PyModule_AddIntMacro(m, RLIMIT_MEMLOCK); -#endif - -#ifdef RLIMIT_SBSIZE - PyModule_AddIntMacro(m, RLIMIT_SBSIZE); -#endif - -/* Linux specific */ -#ifdef RLIMIT_MSGQUEUE - PyModule_AddIntMacro(m, RLIMIT_MSGQUEUE); -#endif - -#ifdef RLIMIT_NICE - PyModule_AddIntMacro(m, RLIMIT_NICE); -#endif - -#ifdef RLIMIT_RTPRIO - PyModule_AddIntMacro(m, RLIMIT_RTPRIO); -#endif - -#ifdef RLIMIT_RTTIME - PyModule_AddIntMacro(m, RLIMIT_RTTIME); -#endif - -#ifdef RLIMIT_SIGPENDING - PyModule_AddIntMacro(m, RLIMIT_SIGPENDING); -#endif - -/* target */ -#ifdef RUSAGE_SELF + /* target */ PyModule_AddIntMacro(m, RUSAGE_SELF); -#endif - -#ifdef RUSAGE_CHILDREN - PyModule_AddIntMacro(m, RUSAGE_CHILDREN); -#endif - -#ifdef RUSAGE_BOTH - PyModule_AddIntMacro(m, RUSAGE_BOTH); -#endif - -#ifdef RUSAGE_THREAD - PyModule_AddIntMacro(m, RUSAGE_THREAD); -#endif - -/* FreeBSD specific */ - -#ifdef RLIMIT_SWAP - PyModule_AddIntMacro(m, RLIMIT_SWAP); -#endif - -#ifdef RLIMIT_SBSIZE - PyModule_AddIntMacro(m, RLIMIT_SBSIZE); -#endif - -#ifdef RLIMIT_NPTS - PyModule_AddIntMacro(m, RLIMIT_NPTS); -#endif + if (RUSAGE_CHILDREN!=99) PyModule_AddIntMacro(m, RUSAGE_CHILDREN); + if (RUSAGE_BOTH!=99) PyModule_AddIntMacro(m, RUSAGE_BOTH); + if (RUSAGE_THREAD!=99) PyModule_AddIntMacro(m, RUSAGE_THREAD); if (sizeof(RLIM_INFINITY) > sizeof(long)) { v = PyLong_FromLongLong((long long) RLIM_INFINITY); diff --git a/third_party/python/Modules/rotatingtree.c b/third_party/python/Modules/rotatingtree.c index 679d019f2..0f6874dc6 100644 --- a/third_party/python/Modules/rotatingtree.c +++ b/third_party/python/Modules/rotatingtree.c @@ -1,5 +1,5 @@ +#include "third_party/python/Modules/rotatingtree.h" /* clang-format off */ -#include "rotatingtree.h" #define KEY_LOWER_THAN(key1, key2) ((char*)(key1) < (char*)(key2)) diff --git a/third_party/python/Modules/selectmodule.c b/third_party/python/Modules/selectmodule.c index 5ef3bba49..27a8c29cb 100644 --- a/third_party/python/Modules/selectmodule.c +++ b/third_party/python/Modules/selectmodule.c @@ -1,20 +1,31 @@ +#include "libc/calls/calls.h" +#include "libc/errno.h" +#include "libc/nt/efi.h" +#include "libc/sock/select.h" +#include "libc/sock/sock.h" +#include "libc/sysv/consts/poll.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/fileobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pytime.h" +#include "third_party/python/Include/structmember.h" /* clang-format off */ + /* select - Module containing unix select(2) call. Under Unix, the file descriptors are small integers. Under Win32, select only exists for sockets, and sockets may have any value except INVALID_SOCKET. */ -#if defined(HAVE_POLL_H) && !defined(_GNU_SOURCE) -#define _GNU_SOURCE -#endif - -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" -#include "libc/sock/sock.h" -#include "libc/sysv/consts/poll.h" -#include "libc/sock/select.h" - #define SOCKET int /* list of Python objects and their file descriptor */ diff --git a/third_party/python/Modules/sha1module.c b/third_party/python/Modules/sha1module.c index e0c563bf6..5253099d9 100644 --- a/third_party/python/Modules/sha1module.c +++ b/third_party/python/Modules/sha1module.c @@ -1,4 +1,15 @@ +#include "libc/assert.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pystrhex.h" +#include "third_party/python/Modules/hashlib.h" /* clang-format off */ + /* SHA1 module */ /* This module provides an interface to the SHA1 algorithm */ @@ -17,10 +28,6 @@ /* SHA1 objects */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Modules/hashlib.h" -#include "third_party/python/Include/pystrhex.h" - /*[clinic input] module _sha1 class SHA1Type "SHA1object *" "&PyType_Type" diff --git a/third_party/python/Modules/sha256module.c b/third_party/python/Modules/sha256module.c index 5fac84209..33e57efaa 100644 --- a/third_party/python/Modules/sha256module.c +++ b/third_party/python/Modules/sha256module.c @@ -1,5 +1,16 @@ +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pystrhex.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/unicodeobject.h" +#include "third_party/python/Modules/hashlib.h" /* clang-format off */ -/* SHA256 module */ /* This module provides an interface to NIST's SHA-256 and SHA-224 Algorithms */ @@ -15,13 +26,6 @@ */ -/* SHA objects */ - -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" -#include "third_party/python/Modules/hashlib.h" -#include "third_party/python/Include/pystrhex.h" - /*[clinic input] module _sha256 class SHA256Type "SHAobject *" "&PyType_Type" @@ -314,14 +318,12 @@ sha_final(unsigned char digest[SHA_DIGESTSIZE], SHAobject *sha_info) count = (int) ((lo_bit_count >> 3) & 0x3f); ((SHA_BYTE *) sha_info->data)[count++] = 0x80; if (count > SHA_BLOCKSIZE - 8) { - memset(((SHA_BYTE *) sha_info->data) + count, 0, - SHA_BLOCKSIZE - count); + bzero(((SHA_BYTE *) sha_info->data) + count, SHA_BLOCKSIZE - count); sha_transform(sha_info); - memset((SHA_BYTE *) sha_info->data, 0, SHA_BLOCKSIZE - 8); + bzero((SHA_BYTE *) sha_info->data, SHA_BLOCKSIZE - 8); } else { - memset(((SHA_BYTE *) sha_info->data) + count, 0, - SHA_BLOCKSIZE - 8 - count); + bzero(((SHA_BYTE *)sha_info->data) + count, SHA_BLOCKSIZE - 8 - count); } /* GJS: note that we add the hi/lo in big-endian. sha_transform will diff --git a/third_party/python/Modules/sha512module.c b/third_party/python/Modules/sha512module.c index 870671ba3..b80a16fd9 100644 --- a/third_party/python/Modules/sha512module.c +++ b/third_party/python/Modules/sha512module.c @@ -1,3 +1,14 @@ +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pystrhex.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Modules/hashlib.h" /* clang-format off */ /* SHA512 module */ @@ -17,11 +28,6 @@ /* SHA objects */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" -#include "third_party/python/Modules/hashlib.h" -#include "third_party/python/Include/pystrhex.h" - /*[clinic input] module _sha512 class SHA512Type "SHAobject *" "&PyType_Type" @@ -339,14 +345,12 @@ sha512_final(unsigned char digest[SHA_DIGESTSIZE], SHAobject *sha_info) count = (int) ((lo_bit_count >> 3) & 0x7f); ((SHA_BYTE *) sha_info->data)[count++] = 0x80; if (count > SHA_BLOCKSIZE - 16) { - memset(((SHA_BYTE *) sha_info->data) + count, 0, - SHA_BLOCKSIZE - count); + bzero(((SHA_BYTE *) sha_info->data) + count, SHA_BLOCKSIZE - count); sha512_transform(sha_info); - memset((SHA_BYTE *) sha_info->data, 0, SHA_BLOCKSIZE - 16); + bzero((SHA_BYTE *) sha_info->data, SHA_BLOCKSIZE - 16); } else { - memset(((SHA_BYTE *) sha_info->data) + count, 0, - SHA_BLOCKSIZE - 16 - count); + bzero(((SHA_BYTE *)sha_info->data) + count, SHA_BLOCKSIZE - 16 - count); } /* GJS: note that we add the hi/lo in big-endian. sha512_transform will diff --git a/third_party/python/Modules/signalmodule.c b/third_party/python/Modules/signalmodule.c index f1bb2092e..597bae9f4 100644 --- a/third_party/python/Modules/signalmodule.c +++ b/third_party/python/Modules/signalmodule.c @@ -1,22 +1,36 @@ +#include "libc/calls/calls.h" +#include "libc/calls/struct/itimerval.h" +#include "libc/dce.h" +#include "libc/errno.h" +#include "libc/math.h" +#include "libc/sysv/consts/itimer.h" +#include "libc/sysv/consts/sig.h" +#include "libc/time/time.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/intrcheck.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/pgenheaders.h" +#include "third_party/python/Include/pyatomic.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pylifecycle.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/tupleobject.h" +#include "third_party/python/Modules/posixmodule.h" /* clang-format off */ /* Signal module -- many thanks to Lance Ellinghaus */ /* XXX Signals should be recorded per thread, now we have thread state. */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Modules/posixmodule.h" -#include "libc/dce.h" -#include "libc/calls/calls.h" - #if defined(HAVE_PTHREAD_SIGMASK) && !defined(HAVE_BROKEN_PTHREAD_SIGMASK) # define PYPTHREAD_SIGMASK #endif -#ifndef NSIG -#define NSIG (IsNetbsd() ? 64 : 32) -#endif - #include "third_party/python/Modules/clinic/signalmodule.inc" /*[clinic input] @@ -59,7 +73,7 @@ static pid_t main_pid; static volatile struct { _Py_atomic_int tripped; PyObject *func; -} Handlers[NSIG]; +} Handlers[Py_NSIG]; #ifdef MS_WINDOWS #define INVALID_FD ((SOCKET_T)-1) @@ -403,7 +417,7 @@ signal_signal_impl(PyObject *module, int signalnum, PyObject *handler) return NULL; } #endif - if (signalnum < 1 || signalnum >= NSIG) { + if (signalnum < 1 || signalnum >= Py_NSIG) { PyErr_SetString(PyExc_ValueError, "signal number out of range"); return NULL; @@ -457,7 +471,7 @@ signal_getsignal_impl(PyObject *module, int signalnum) /*[clinic end generated code: output=35b3e0e796fd555e input=ac23a00f19dfa509]*/ { PyObject *old_handler; - if (signalnum < 1 || signalnum >= NSIG) { + if (signalnum < 1 || signalnum >= Py_NSIG) { PyErr_SetString(PyExc_ValueError, "signal number out of range"); return NULL; @@ -491,7 +505,7 @@ static PyObject * signal_siginterrupt_impl(PyObject *module, int signalnum, int flag) /*[clinic end generated code: output=063816243d85dd19 input=4160acacca3e2099]*/ { - if (signalnum < 1 || signalnum >= NSIG) { + if (signalnum < 1 || signalnum >= Py_NSIG) { PyErr_SetString(PyExc_ValueError, "signal number out of range"); return NULL; @@ -737,7 +751,7 @@ iterable_to_sigset(PyObject *iterable, sigset_t *mask) Py_DECREF(item); if (signum == -1 && PyErr_Occurred()) goto error; - if (0 < signum && signum < NSIG) { + if (0 < signum && signum < Py_NSIG) { /* bpo-33329: ignore sigaddset() return value as it can fail * for some reserved signals, but we want the `range(1, NSIG)` * idiom to allow selecting all valid signals. @@ -769,7 +783,7 @@ sigset_to_set(sigset_t mask) if (result == NULL) return NULL; - for (sig = 1; sig < NSIG; sig++) { + for (sig = 1; sig < Py_NSIG; sig++) { if (sigismember(&mask, sig) != 1) continue; @@ -1137,7 +1151,7 @@ default_int_handler() -- default SIGINT handler\n\ signal constants:\n\ SIG_DFL -- used to refer to the system default handler\n\ SIG_IGN -- used to ignore the signal\n\ -NSIG -- number of defined signals\n\ +Py_NSIG -- number of defined signals\n\ SIGINT, SIGTERM, etc. -- signal numbers\n\ \n\ itimer constants:\n\ @@ -1205,7 +1219,7 @@ PyInit__signal(void) if (!x || PyDict_SetItemString(d, "SIG_IGN", x) < 0) goto finally; - x = PyLong_FromLong((long)NSIG); + x = PyLong_FromLong((long)Py_NSIG); if (!x || PyDict_SetItemString(d, "NSIG", x) < 0) goto finally; Py_DECREF(x); @@ -1229,7 +1243,7 @@ PyInit__signal(void) Py_INCREF(IntHandler); _Py_atomic_store_relaxed(&Handlers[0].tripped, 0); - for (i = 1; i < NSIG; i++) { + for (i = 1; i < Py_NSIG; i++) { void (*t)(int); t = PyOS_getsig(i); _Py_atomic_store_relaxed(&Handlers[i].tripped, 0); @@ -1451,7 +1465,7 @@ finisignal(void) int i; PyObject *func; - for (i = 1; i < NSIG; i++) { + for (i = 1; i < Py_NSIG; i++) { func = Handlers[i].func; _Py_atomic_store_relaxed(&Handlers[i].tripped, 0); Handlers[i].func = NULL; @@ -1501,7 +1515,7 @@ PyErr_CheckSignals(void) if (!(f = (PyObject *)PyEval_GetFrame())) f = Py_None; - for (i = 1; i < NSIG; i++) { + for (i = 1; i < Py_NSIG; i++) { if (_Py_atomic_load_relaxed(&Handlers[i].tripped)) { PyObject *result = NULL; PyObject *arglist = Py_BuildValue("(iO)", i, f); @@ -1570,7 +1584,7 @@ _clear_pending_signals(void) if (!_Py_atomic_load(&is_tripped)) return; _Py_atomic_store(&is_tripped, 0); - for (i = 1; i < NSIG; ++i) { + for (i = 1; i < Py_NSIG; ++i) { _Py_atomic_store_relaxed(&Handlers[i].tripped, 0); } } diff --git a/third_party/python/Modules/socketmodule.c b/third_party/python/Modules/socketmodule.c index c6fa8a3cb..d961e3f36 100644 --- a/third_party/python/Modules/socketmodule.c +++ b/third_party/python/Modules/socketmodule.c @@ -3,6 +3,7 @@ #include "libc/dce.h" #include "libc/dns/dns.h" #include "libc/dns/ent.h" +#include "libc/errno.h" #include "libc/runtime/runtime.h" #include "libc/sock/sock.h" #include "libc/sysv/consts/af.h" @@ -17,13 +18,31 @@ #include "libc/sysv/consts/pf.h" #include "libc/sysv/consts/poll.h" #include "libc/sysv/consts/shut.h" +#include "libc/sysv/consts/sio.h" #include "libc/sysv/consts/so.h" #include "libc/sysv/consts/sock.h" #include "libc/sysv/consts/sol.h" #include "libc/sysv/consts/tcp.h" -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/bytearrayobject.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pycapsule.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" #include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/tupleobject.h" +#include "third_party/python/Include/warnings.h" #include "third_party/python/Modules/socketmodule.h" +#include "third_party/python/pyconfig.h" /* clang-format off */ /* Socket module */ @@ -228,58 +247,10 @@ http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/net/getaddrinfo.c.diff?r1=1.82& #undef AF_CAN #endif -#ifndef HAVE_INET_PTON -#if !defined(NTDDI_VERSION) || (NTDDI_VERSION < NTDDI_LONGHORN) -int inet_pton(int af, const char *src, void *dst); -const char *inet_ntop(int af, const void *src, char *dst, socklen_t size); -#endif -#endif - -#ifdef __APPLE__ -/* On OS X, getaddrinfo returns no error indication of lookup - failure, so we must use the emulation instead of the libinfo - implementation. Unfortunately, performing an autoconf test - for this bug would require DNS access for the machine performing - the configuration, which is not acceptable. Therefore, we - determine the bug just by checking for __APPLE__. If this bug - gets ever fixed, perhaps checking for sys/version.h would be - appropriate, which is 10/0 on the system with the bug. */ -#ifndef HAVE_GETNAMEINFO -/* This bug seems to be fixed in Jaguar. Ths easiest way I could - Find to check for Jaguar is that it has getnameinfo(), which - older releases don't have */ -#undef HAVE_GETADDRINFO -#endif - #ifdef HAVE_INET_ATON #define USE_INET_ATON_WEAKLINK #endif -#endif - -/* I know this is a bad practice, but it is the easiest... */ -#if !defined(HAVE_GETADDRINFO) -/* avoid clashes with the C library definition of the symbol. */ -#define getaddrinfo fake_getaddrinfo -#define gai_strerror fake_gai_strerror -#define freeaddrinfo fake_freeaddrinfo -#include "getaddrinfo.c" -#endif -#if !defined(HAVE_GETNAMEINFO) -#define getnameinfo fake_getnameinfo -#include "getnameinfo.c" -#endif - -#ifdef MS_WINDOWS -#define SOCKETCLOSE closesocket -#endif - -#ifdef MS_WIN32 -#undef EAFNOSUPPORT -#define EAFNOSUPPORT WSAEAFNOSUPPORT -#define snprintf _snprintf -#endif - #ifndef SOCKETCLOSE #define SOCKETCLOSE close #endif @@ -857,7 +828,7 @@ setipaddr(const char *name, struct sockaddr *addr_ret, size_t addr_ret_size, int memset((void *) addr_ret, '\0', sizeof(*addr_ret)); if (name[0] == '\0') { int siz; - memset(&hints, 0, sizeof(hints)); + bzero(&hints, sizeof(hints)); hints.ai_family = af; hints.ai_socktype = SOCK_DGRAM; /*dummy*/ hints.ai_flags = AI_PASSIVE; @@ -926,7 +897,7 @@ setipaddr(const char *name, struct sockaddr *addr_ret, size_t addr_ret_size, int /* check for an IPv4 address */ if (af == AF_UNSPEC || af == AF_INET) { struct sockaddr_in *sin = (struct sockaddr_in *)addr_ret; - memset(sin, 0, sizeof(*sin)); + bzero(sin, sizeof(*sin)); if (inet_pton(AF_INET, name, &sin->sin_addr) > 0) { sin->sin_family = AF_INET; #ifdef HAVE_SOCKADDR_SA_LEN @@ -941,7 +912,7 @@ setipaddr(const char *name, struct sockaddr *addr_ret, size_t addr_ret_size, int * name to interface index */ if ((af == AF_UNSPEC || af == AF_INET6) && !strchr(name, '%')) { struct sockaddr_in6 *sin = (struct sockaddr_in6 *)addr_ret; - memset(sin, 0, sizeof(*sin)); + bzero(sin, sizeof(*sin)); if (inet_pton(AF_INET6, name, &sin->sin6_addr) > 0) { sin->sin6_family = AF_INET6; #ifdef HAVE_SOCKADDR_SA_LEN @@ -955,7 +926,7 @@ setipaddr(const char *name, struct sockaddr *addr_ret, size_t addr_ret_size, int /* check for an IPv4 address */ if (af == AF_INET || af == AF_UNSPEC) { struct sockaddr_in *sin = (struct sockaddr_in *)addr_ret; - memset(sin, 0, sizeof(*sin)); + bzero(sin, sizeof(*sin)); if ((sin->sin_addr.s_addr = inet_addr(name)) != INADDR_NONE) { sin->sin_family = AF_INET; #ifdef HAVE_SOCKADDR_SA_LEN @@ -967,7 +938,7 @@ setipaddr(const char *name, struct sockaddr *addr_ret, size_t addr_ret_size, int #endif /* HAVE_INET_PTON */ /* perform a name resolution */ - memset(&hints, 0, sizeof(hints)); + bzero(&hints, sizeof(hints)); hints.ai_family = af; Py_BEGIN_ALLOW_THREADS ACQUIRE_GETADDRINFO_LOCK @@ -1535,7 +1506,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, const char *straddr; addr = (struct sockaddr_l2 *)addr_ret; - memset(addr, 0, sizeof(struct sockaddr_l2)); + bzero(addr, sizeof(struct sockaddr_l2)); _BT_L2_MEMB(addr, family) = AF_BLUETOOTH; if (!PyArg_ParseTuple(args, "si", &straddr, &_BT_L2_MEMB(addr, psm))) { @@ -1704,7 +1675,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, return 0; addr = (struct sockaddr_tipc *) addr_ret; - memset(addr, 0, sizeof(struct sockaddr_tipc)); + bzero(addr, sizeof(struct sockaddr_tipc)); addr->family = AF_TIPC; addr->scope = scope; @@ -1851,7 +1822,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, const char *name; sa = (struct sockaddr_alg *)addr_ret; - memset(sa, 0, sizeof(*sa)); + bzero(sa, sizeof(*sa)); sa->salg_family = AF_ALG; if (!PyArg_ParseTuple(args, "ss|HH:getsockaddrarg", @@ -2204,7 +2175,7 @@ sock_accept(PySocketSockObject *s) if (!getsockaddrlen(s, &addrlen)) return NULL; - memset(&addrbuf, 0, addrlen); + bzero(&addrbuf, addrlen); if (!IS_SELECTABLE(s)) return select_error(); @@ -2758,7 +2729,7 @@ sock_getsockname(PySocketSockObject *s) if (!getsockaddrlen(s, &addrlen)) return NULL; - memset(&addrbuf, 0, addrlen); + bzero(&addrbuf, addrlen); Py_BEGIN_ALLOW_THREADS res = getsockname(s->sock_fd, SAS2SA(&addrbuf), &addrlen); Py_END_ALLOW_THREADS @@ -2787,7 +2758,7 @@ sock_getpeername(PySocketSockObject *s) if (!getsockaddrlen(s, &addrlen)) return NULL; - memset(&addrbuf, 0, addrlen); + bzero(&addrbuf, addrlen); Py_BEGIN_ALLOW_THREADS res = getpeername(s->sock_fd, SAS2SA(&addrbuf), &addrlen); Py_END_ALLOW_THREADS @@ -3020,7 +2991,7 @@ sock_recvfrom_impl(PySocketSockObject *s, void *data) { struct sock_recvfrom *ctx = data; - memset(ctx->addrbuf, 0, *ctx->addrlen); + bzero(ctx->addrbuf, *ctx->addrlen); #ifdef MS_WINDOWS if (ctx->len > INT_MAX) @@ -3239,7 +3210,7 @@ sock_recvmsg_guts(PySocketSockObject *s, struct iovec *iov, int iovlen, real address if that doesn't happen. */ if (!getsockaddrlen(s, &addrbuflen)) return NULL; - memset(&addrbuf, 0, addrbuflen); + bzero(&addrbuf, addrbuflen); SAS2SA(&addrbuf)->sa_family = AF_UNSPEC; if (controllen < 0 || controllen > SOCKLEN_T_LIMIT) { @@ -3842,7 +3813,7 @@ sock_sendmsg(PySocketSockObject *s, PyObject *args) return NULL; } - memset(&msg, 0, sizeof(msg)); + bzero(&msg, sizeof(msg)); /* Parse destination address. */ if (addr_arg != NULL && addr_arg != Py_None) { @@ -3929,7 +3900,7 @@ sock_sendmsg(PySocketSockObject *s, PyObject *args) member to see if the "message" fits in the buffer, and returns NULL if it doesn't. Zero-filling the buffer ensures that this doesn't happen. */ - memset(controlbuf, 0, controllen); + bzero(controlbuf, controllen); for (i = 0; i < ncmsgbufs; i++) { size_t msg_len, data_len = cmsgs[i].data.len; @@ -4054,7 +4025,7 @@ sock_sendmsg_afalg(PySocketSockObject *self, PyObject *args, PyObject *kwds) return NULL; } - memset(&msg, 0, sizeof(msg)); + bzero(&msg, sizeof(msg)); /* op is a required, keyword-only argument >= 0 */ if (opobj != NULL) { @@ -4092,7 +4063,7 @@ sock_sendmsg_afalg(PySocketSockObject *self, PyObject *args, PyObject *kwds) PyErr_NoMemory(); goto finally; } - memset(controlbuf, 0, controllen); + bzero(controlbuf, controllen); msg.msg_controllen = controllen; msg.msg_control = controlbuf; @@ -4877,7 +4848,7 @@ gethost_common(struct hostent *h, struct sockaddr *addr, size_t alen, int af) case AF_INET: { struct sockaddr_in sin; - memset(&sin, 0, sizeof(sin)); + bzero(&sin, sizeof(sin)); sin.sin_family = af; #ifdef HAVE_SOCKADDR_SA_LEN sin.sin_len = sizeof(sin); @@ -4894,7 +4865,7 @@ gethost_common(struct hostent *h, struct sockaddr *addr, size_t alen, int af) case AF_INET6: { struct sockaddr_in6 sin6; - memset(&sin6, 0, sizeof(sin6)); + bzero(&sin6, sizeof(sin6)); sin6.sin6_family = af; #ifdef HAVE_SOCKADDR_SA_LEN sin6.sin6_len = sizeof(sin6); @@ -5735,7 +5706,7 @@ socket_inet_ntop(PyObject *self, PyObject *args) PyBuffer_Release(&packed_ip); return NULL; } - memset(addr4, 0, sizeof(struct sockaddr_in)); + bzero(addr4, sizeof(struct sockaddr_in)); addr4->sin_family = AF_INET; memcpy(&(addr4->sin_addr), packed_ip.buf, sizeof(addr4->sin_addr)); addrlen = sizeof(struct sockaddr_in); @@ -5747,7 +5718,7 @@ socket_inet_ntop(PyObject *self, PyObject *args) return NULL; } - memset(&addr, 0, sizeof(addr)); + bzero(&addr, sizeof(addr)); addr.sin6_family = AF_INET6; memcpy(&(addr.sin6_addr), packed_ip.buf, sizeof(addr.sin6_addr)); addrlen = sizeof(addr); @@ -5841,7 +5812,7 @@ socket_getaddrinfo(PyObject *self, PyObject *args, PyObject* kwargs) pptr = "00"; } #endif - memset(&hints, 0, sizeof(hints)); + bzero(&hints, sizeof(hints)); hints.ai_family = family; hints.ai_socktype = socktype; hints.ai_protocol = protocol; @@ -5931,7 +5902,7 @@ socket_getnameinfo(PyObject *self, PyObject *args) return NULL; } PyOS_snprintf(pbuf, sizeof(pbuf), "%d", port); - memset(&hints, 0, sizeof(hints)); + bzero(&hints, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_DGRAM; /* make numeric port happy */ hints.ai_flags = AI_NUMERICHOST; /* don't do any name resolution */ diff --git a/third_party/python/Modules/socketmodule.h b/third_party/python/Modules/socketmodule.h index a78f24e30..735d75000 100644 --- a/third_party/python/Modules/socketmodule.h +++ b/third_party/python/Modules/socketmodule.h @@ -1,9 +1,9 @@ #ifndef Py__SOCKET_H #define Py__SOCKET_H #include "libc/sock/sock.h" -#ifdef __cplusplus -extern "C" { -#endif +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pytime.h" +COSMOPOLITAN_C_START_ /* clang-format off */ /* Python module and C API name */ @@ -127,7 +127,5 @@ typedef struct { #define PySocketModule_ImportModuleAndAPI() PyCapsule_Import(PySocket_CAPSULE_NAME, 1) -#ifdef __cplusplus -} -#endif +COSMOPOLITAN_C_END_ #endif /* !Py__SOCKET_H */ diff --git a/third_party/python/Modules/spwdmodule.c b/third_party/python/Modules/spwdmodule.c index bf1cb5df3..b97fef78f 100644 --- a/third_party/python/Modules/spwdmodule.c +++ b/third_party/python/Modules/spwdmodule.c @@ -1,12 +1,14 @@ +#include "third_party/python/Include/methodobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/moduleobject.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Modules/clinic/spwdmodule.inc" /* clang-format off */ /* UNIX shadow password file access module */ /* A lot of code has been taken from pwdmodule.c */ /* For info also see http://www.unixpapa.com/incnote/passwd.html */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Modules/clinic/spwdmodule.inc" - /*[clinic input] module spwd [clinic start generated code]*/ diff --git a/third_party/python/Modules/sre.h b/third_party/python/Modules/sre.h index b632165a1..0d81d086a 100644 --- a/third_party/python/Modules/sre.h +++ b/third_party/python/Modules/sre.h @@ -1,96 +1,85 @@ -/* - * Secret Labs' Regular Expression Engine - * - * regular expression matching engine - * - * Copyright (c) 1997-2001 by Secret Labs AB. All rights reserved. - * - * See the _sre.c file for information on usage and redistribution. - */ - #ifndef SRE_INCLUDED #define SRE_INCLUDED - -#include "sre_constants.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/unicodeobject.h" +#include "third_party/python/Modules/sre_constants.h" /* size of a code word (must be unsigned short or larger, and large enough to hold a UCS4 character) */ #define SRE_CODE Py_UCS4 #if SIZEOF_SIZE_T > 4 -# define SRE_MAXREPEAT (~(SRE_CODE)0) -# define SRE_MAXGROUPS ((~(SRE_CODE)0) / 2) +#define SRE_MAXREPEAT (~(SRE_CODE)0) +#define SRE_MAXGROUPS ((~(SRE_CODE)0) / 2) #else -# define SRE_MAXREPEAT ((SRE_CODE)PY_SSIZE_T_MAX) -# define SRE_MAXGROUPS ((SRE_CODE)PY_SSIZE_T_MAX / SIZEOF_SIZE_T / 2) +#define SRE_MAXREPEAT ((SRE_CODE)PY_SSIZE_T_MAX) +#define SRE_MAXGROUPS ((SRE_CODE)PY_SSIZE_T_MAX / SIZEOF_SIZE_T / 2) #endif typedef struct { - PyObject_VAR_HEAD - Py_ssize_t groups; /* must be first! */ - PyObject* groupindex; - PyObject* indexgroup; - /* compatibility */ - PyObject* pattern; /* pattern source (or None) */ - int flags; /* flags used when compiling pattern source */ - PyObject *weakreflist; /* List of weak references */ - int isbytes; /* pattern type (1 - bytes, 0 - string, -1 - None) */ - /* pattern code */ - Py_ssize_t codesize; - SRE_CODE code[1]; + PyObject_VAR_HEAD Py_ssize_t groups; /* must be first! */ + PyObject* groupindex; + PyObject* indexgroup; + /* compatibility */ + PyObject* pattern; /* pattern source (or None) */ + int flags; /* flags used when compiling pattern source */ + PyObject* weakreflist; /* List of weak references */ + int isbytes; /* pattern type (1 - bytes, 0 - string, -1 - None) */ + /* pattern code */ + Py_ssize_t codesize; + SRE_CODE code[1]; } PatternObject; #define PatternObject_GetCode(o) (((PatternObject*)(o))->code) typedef struct { - PyObject_VAR_HEAD - PyObject* string; /* link to the target string (must be first) */ - PyObject* regs; /* cached list of matching spans */ - PatternObject* pattern; /* link to the regex (pattern) object */ - Py_ssize_t pos, endpos; /* current target slice */ - Py_ssize_t lastindex; /* last index marker seen by the engine (-1 if none) */ - Py_ssize_t groups; /* number of groups (start/end marks) */ - Py_ssize_t mark[1]; + PyObject_VAR_HEAD PyObject* + string; /* link to the target string (must be first) */ + PyObject* regs; /* cached list of matching spans */ + PatternObject* pattern; /* link to the regex (pattern) object */ + Py_ssize_t pos, endpos; /* current target slice */ + Py_ssize_t lastindex; /* last index marker seen by the engine (-1 if none) */ + Py_ssize_t groups; /* number of groups (start/end marks) */ + Py_ssize_t mark[1]; } MatchObject; typedef unsigned int (*SRE_TOLOWER_HOOK)(unsigned int ch); typedef struct SRE_REPEAT_T { - Py_ssize_t count; - SRE_CODE* pattern; /* points to REPEAT operator arguments */ - void* last_ptr; /* helper to check for infinite loops */ - struct SRE_REPEAT_T *prev; /* points to previous repeat context */ + Py_ssize_t count; + SRE_CODE* pattern; /* points to REPEAT operator arguments */ + void* last_ptr; /* helper to check for infinite loops */ + struct SRE_REPEAT_T* prev; /* points to previous repeat context */ } SRE_REPEAT; typedef struct { - /* string pointers */ - void* ptr; /* current position (also end of current slice) */ - void* beginning; /* start of original string */ - void* start; /* start of current slice */ - void* end; /* end of original string */ - /* attributes for the match object */ - PyObject* string; - Py_ssize_t pos, endpos; - int isbytes; - int charsize; /* character size */ - /* registers */ - Py_ssize_t lastindex; - Py_ssize_t lastmark; - void** mark; - /* dynamically allocated stuff */ - char* data_stack; - size_t data_stack_size; - size_t data_stack_base; - Py_buffer buffer; - /* current repeat context */ - SRE_REPEAT *repeat; - /* hooks */ - SRE_TOLOWER_HOOK lower, upper; + /* string pointers */ + void* ptr; /* current position (also end of current slice) */ + void* beginning; /* start of original string */ + void* start; /* start of current slice */ + void* end; /* end of original string */ + /* attributes for the match object */ + PyObject* string; + Py_ssize_t pos, endpos; + int isbytes; + int charsize; /* character size */ + /* registers */ + Py_ssize_t lastindex; + Py_ssize_t lastmark; + void** mark; + /* dynamically allocated stuff */ + char* data_stack; + size_t data_stack_size; + size_t data_stack_base; + Py_buffer buffer; + /* current repeat context */ + SRE_REPEAT* repeat; + /* hooks */ + SRE_TOLOWER_HOOK lower, upper; } SRE_STATE; typedef struct { - PyObject_HEAD - PyObject* pattern; - SRE_STATE state; + PyObject_HEAD PyObject* pattern; + SRE_STATE state; } ScannerObject; #endif diff --git a/third_party/python/Modules/sre_lib.h b/third_party/python/Modules/sre_lib.inc similarity index 99% rename from third_party/python/Modules/sre_lib.h rename to third_party/python/Modules/sre_lib.inc index 0865fc63a..c8f1b0e2f 100644 --- a/third_party/python/Modules/sre_lib.h +++ b/third_party/python/Modules/sre_lib.inc @@ -1,3 +1,4 @@ +/* clang-format off */ /* * Secret Labs' Regular Expression Engine * diff --git a/third_party/python/Modules/symtablemodule.c b/third_party/python/Modules/symtablemodule.c index 1f25d0c2c..36a1abf98 100644 --- a/third_party/python/Modules/symtablemodule.c +++ b/third_party/python/Modules/symtablemodule.c @@ -1,9 +1,12 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" - -#include "third_party/python/Include/code.h" #include "third_party/python/Include/Python-ast.h" +#include "third_party/python/Include/code.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" #include "third_party/python/Include/symtable.h" +#include "third_party/python/Include/unicodeobject.h" +/* clang-format off */ static PyObject * symtable_symtable(PyObject *self, PyObject *args) diff --git a/third_party/python/Modules/syslogmodule.c b/third_party/python/Modules/syslogmodule.c index bdb995b88..c12926c5b 100644 --- a/third_party/python/Modules/syslogmodule.c +++ b/third_party/python/Modules/syslogmodule.c @@ -1,4 +1,17 @@ +#include "libc/sock/syslog.h" +#include "libc/sysv/consts/log.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/osdefs.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/sysmodule.h" +#include "third_party/python/Include/tupleobject.h" +#include "third_party/python/Include/unicodeobject.h" /* clang-format off */ + /*********************************************************** Copyright 1994 by Lance Ellinghouse, Cathedral City, California Republic, United States of America. @@ -50,12 +63,6 @@ Revision history: /* syslog module */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/osdefs.h" - -#include "libc/sock/syslog.h" -#include "libc/sysv/consts/log.h" - /* only one instance, only one syslog, so globals should be ok */ static PyObject *S_ident_o = NULL; /* identifier, held by openlog() */ static char S_log_open = 0; diff --git a/third_party/python/Modules/termios.c b/third_party/python/Modules/termios.c index 5250b5a0a..3c148cd95 100644 --- a/third_party/python/Modules/termios.c +++ b/third_party/python/Modules/termios.c @@ -1,7 +1,19 @@ +#include "libc/calls/struct/termios.h" +#include "libc/calls/termios.h" +#include "libc/calls/weirdtypes.h" +#include "libc/sysv/consts/baud.h" +#include "libc/sysv/consts/modem.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/fileobject.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" /* clang-format off */ -/* termiosmodule.c -- POSIX terminal I/O module implementation. */ -#include "Python.h" +/* termiosmodule.c -- POSIX terminal I/O module implementation. */ /* Apparently, on SGI, termios.h won't define CTRL if _XOPEN_SOURCE is defined, so we define it here. */ @@ -9,21 +21,6 @@ #define CTRL(c) ((c)&037) #endif -#include -#include - -/* HP-UX requires that this be included to pick up MDCD, MCTS, MDSR, - * MDTR, MRI, and MRTS (appearantly used internally by some things - * defined as macros; these are not used here directly). - */ -#ifdef HAVE_SYS_MODEM_H -#include -#endif -/* HP-UX requires that this be included to pick up TIOCGPGRP and friends */ -#ifdef HAVE_SYS_BSDTTY_H -#include -#endif - PyDoc_STRVAR(termios__doc__, "This module provides an interface to the Posix calls for tty I/O control.\n\ For a complete description of these calls, see the Posix or Unix manual\n\ @@ -313,628 +310,6 @@ static PyMethodDef termios_methods[] = #define VSWTCH VSWTC #endif -static struct constant { - char *name; - long value; -} termios_constants[] = { - /* cfgetospeed(), cfsetospeed() constants */ - {"B0", B0}, - {"B50", B50}, - {"B75", B75}, - {"B110", B110}, - {"B134", B134}, - {"B150", B150}, - {"B200", B200}, - {"B300", B300}, - {"B600", B600}, - {"B1200", B1200}, - {"B1800", B1800}, - {"B2400", B2400}, - {"B4800", B4800}, - {"B9600", B9600}, - {"B19200", B19200}, - {"B38400", B38400}, -#ifdef B57600 - {"B57600", B57600}, -#endif -#ifdef B115200 - {"B115200", B115200}, -#endif -#ifdef B230400 - {"B230400", B230400}, -#endif -#ifdef B460800 - {"B460800", B460800}, -#endif -#ifdef B500000 - {"B500000", B500000}, -#endif -#ifdef B576000 - {"B576000", B576000}, -#endif -#ifdef B921600 - {"B921600", B921600}, -#endif -#ifdef B1000000 - {"B1000000", B1000000}, -#endif -#ifdef B1152000 - {"B1152000", B1152000}, -#endif -#ifdef B1500000 - {"B1500000", B1500000}, -#endif -#ifdef B2000000 - {"B2000000", B2000000}, -#endif -#ifdef B2500000 - {"B2500000", B2500000}, -#endif -#ifdef B3000000 - {"B3000000", B3000000}, -#endif -#ifdef B3500000 - {"B3500000", B3500000}, -#endif -#ifdef B4000000 - {"B4000000", B4000000}, -#endif - -#ifdef CBAUDEX - {"CBAUDEX", CBAUDEX}, -#endif - - /* tcsetattr() constants */ - {"TCSANOW", TCSANOW}, - {"TCSADRAIN", TCSADRAIN}, - {"TCSAFLUSH", TCSAFLUSH}, -#ifdef TCSASOFT - {"TCSASOFT", TCSASOFT}, -#endif - - /* tcflush() constants */ - {"TCIFLUSH", TCIFLUSH}, - {"TCOFLUSH", TCOFLUSH}, - {"TCIOFLUSH", TCIOFLUSH}, - - /* tcflow() constants */ - {"TCOOFF", TCOOFF}, - {"TCOON", TCOON}, - {"TCIOFF", TCIOFF}, - {"TCION", TCION}, - - /* struct termios.c_iflag constants */ - {"IGNBRK", IGNBRK}, - {"BRKINT", BRKINT}, - {"IGNPAR", IGNPAR}, - {"PARMRK", PARMRK}, - {"INPCK", INPCK}, - {"ISTRIP", ISTRIP}, - {"INLCR", INLCR}, - {"IGNCR", IGNCR}, - {"ICRNL", ICRNL}, -#ifdef IUCLC - {"IUCLC", IUCLC}, -#endif - {"IXON", IXON}, - {"IXANY", IXANY}, - {"IXOFF", IXOFF}, -#ifdef IMAXBEL - {"IMAXBEL", IMAXBEL}, -#endif - - /* struct termios.c_oflag constants */ - {"OPOST", OPOST}, -#ifdef OLCUC - {"OLCUC", OLCUC}, -#endif -#ifdef ONLCR - {"ONLCR", ONLCR}, -#endif -#ifdef OCRNL - {"OCRNL", OCRNL}, -#endif -#ifdef ONOCR - {"ONOCR", ONOCR}, -#endif -#ifdef ONLRET - {"ONLRET", ONLRET}, -#endif -#ifdef OFILL - {"OFILL", OFILL}, -#endif -#ifdef OFDEL - {"OFDEL", OFDEL}, -#endif -#ifdef NLDLY - {"NLDLY", NLDLY}, -#endif -#ifdef CRDLY - {"CRDLY", CRDLY}, -#endif -#ifdef TABDLY - {"TABDLY", TABDLY}, -#endif -#ifdef BSDLY - {"BSDLY", BSDLY}, -#endif -#ifdef VTDLY - {"VTDLY", VTDLY}, -#endif -#ifdef FFDLY - {"FFDLY", FFDLY}, -#endif - - /* struct termios.c_oflag-related values (delay mask) */ -#ifdef NL0 - {"NL0", NL0}, -#endif -#ifdef NL1 - {"NL1", NL1}, -#endif -#ifdef CR0 - {"CR0", CR0}, -#endif -#ifdef CR1 - {"CR1", CR1}, -#endif -#ifdef CR2 - {"CR2", CR2}, -#endif -#ifdef CR3 - {"CR3", CR3}, -#endif -#ifdef TAB0 - {"TAB0", TAB0}, -#endif -#ifdef TAB1 - {"TAB1", TAB1}, -#endif -#ifdef TAB2 - {"TAB2", TAB2}, -#endif -#ifdef TAB3 - {"TAB3", TAB3}, -#endif -#ifdef XTABS - {"XTABS", XTABS}, -#endif -#ifdef BS0 - {"BS0", BS0}, -#endif -#ifdef BS1 - {"BS1", BS1}, -#endif -#ifdef VT0 - {"VT0", VT0}, -#endif -#ifdef VT1 - {"VT1", VT1}, -#endif -#ifdef FF0 - {"FF0", FF0}, -#endif -#ifdef FF1 - {"FF1", FF1}, -#endif - - /* struct termios.c_cflag constants */ - {"CSIZE", CSIZE}, - {"CSTOPB", CSTOPB}, - {"CREAD", CREAD}, - {"PARENB", PARENB}, - {"PARODD", PARODD}, - {"HUPCL", HUPCL}, - {"CLOCAL", CLOCAL}, -#ifdef CIBAUD - {"CIBAUD", CIBAUD}, -#endif -#ifdef CRTSCTS - {"CRTSCTS", (long)CRTSCTS}, -#endif - - /* struct termios.c_cflag-related values (character size) */ - {"CS5", CS5}, - {"CS6", CS6}, - {"CS7", CS7}, - {"CS8", CS8}, - - /* struct termios.c_lflag constants */ - {"ISIG", ISIG}, - {"ICANON", ICANON}, -#ifdef XCASE - {"XCASE", XCASE}, -#endif - {"ECHO", ECHO}, - {"ECHOE", ECHOE}, - {"ECHOK", ECHOK}, - {"ECHONL", ECHONL}, -#ifdef ECHOCTL - {"ECHOCTL", ECHOCTL}, -#endif -#ifdef ECHOPRT - {"ECHOPRT", ECHOPRT}, -#endif -#ifdef ECHOKE - {"ECHOKE", ECHOKE}, -#endif -#ifdef FLUSHO - {"FLUSHO", FLUSHO}, -#endif - {"NOFLSH", NOFLSH}, - {"TOSTOP", TOSTOP}, -#ifdef PENDIN - {"PENDIN", PENDIN}, -#endif - {"IEXTEN", IEXTEN}, - - /* indexes into the control chars array returned by tcgetattr() */ - {"VINTR", VINTR}, - {"VQUIT", VQUIT}, - {"VERASE", VERASE}, - {"VKILL", VKILL}, - {"VEOF", VEOF}, - {"VTIME", VTIME}, - {"VMIN", VMIN}, -#ifdef VSWTC - /* The #defines above ensure that if either is defined, both are, - * but both may be omitted by the system headers. ;-( */ - {"VSWTC", VSWTC}, - {"VSWTCH", VSWTCH}, -#endif - {"VSTART", VSTART}, - {"VSTOP", VSTOP}, - {"VSUSP", VSUSP}, - {"VEOL", VEOL}, -#ifdef VREPRINT - {"VREPRINT", VREPRINT}, -#endif -#ifdef VDISCARD - {"VDISCARD", VDISCARD}, -#endif -#ifdef VWERASE - {"VWERASE", VWERASE}, -#endif -#ifdef VLNEXT - {"VLNEXT", VLNEXT}, -#endif -#ifdef VEOL2 - {"VEOL2", VEOL2}, -#endif - - -#ifdef B460800 - {"B460800", B460800}, -#endif -#ifdef CBAUD - {"CBAUD", CBAUD}, -#endif -#ifdef CDEL - {"CDEL", CDEL}, -#endif -#ifdef CDSUSP - {"CDSUSP", CDSUSP}, -#endif -#ifdef CEOF - {"CEOF", CEOF}, -#endif -#ifdef CEOL - {"CEOL", CEOL}, -#endif -#ifdef CEOL2 - {"CEOL2", CEOL2}, -#endif -#ifdef CEOT - {"CEOT", CEOT}, -#endif -#ifdef CERASE - {"CERASE", CERASE}, -#endif -#ifdef CESC - {"CESC", CESC}, -#endif -#ifdef CFLUSH - {"CFLUSH", CFLUSH}, -#endif -#ifdef CINTR - {"CINTR", CINTR}, -#endif -#ifdef CKILL - {"CKILL", CKILL}, -#endif -#ifdef CLNEXT - {"CLNEXT", CLNEXT}, -#endif -#ifdef CNUL - {"CNUL", CNUL}, -#endif -#ifdef COMMON - {"COMMON", COMMON}, -#endif -#ifdef CQUIT - {"CQUIT", CQUIT}, -#endif -#ifdef CRPRNT - {"CRPRNT", CRPRNT}, -#endif -#ifdef CSTART - {"CSTART", CSTART}, -#endif -#ifdef CSTOP - {"CSTOP", CSTOP}, -#endif -#ifdef CSUSP - {"CSUSP", CSUSP}, -#endif -#ifdef CSWTCH - {"CSWTCH", CSWTCH}, -#endif -#ifdef CWERASE - {"CWERASE", CWERASE}, -#endif -#ifdef EXTA - {"EXTA", EXTA}, -#endif -#ifdef EXTB - {"EXTB", EXTB}, -#endif -#ifdef FIOASYNC - {"FIOASYNC", FIOASYNC}, -#endif -#ifdef FIOCLEX - {"FIOCLEX", FIOCLEX}, -#endif -#ifdef FIONBIO - {"FIONBIO", FIONBIO}, -#endif -#ifdef FIONCLEX - {"FIONCLEX", FIONCLEX}, -#endif -#ifdef FIONREAD - {"FIONREAD", FIONREAD}, -#endif -#ifdef IBSHIFT - {"IBSHIFT", IBSHIFT}, -#endif -#ifdef INIT_C_CC - {"INIT_C_CC", INIT_C_CC}, -#endif -#ifdef IOCSIZE_MASK - {"IOCSIZE_MASK", IOCSIZE_MASK}, -#endif -#ifdef IOCSIZE_SHIFT - {"IOCSIZE_SHIFT", IOCSIZE_SHIFT}, -#endif -#ifdef NCC - {"NCC", NCC}, -#endif -#ifdef NCCS - {"NCCS", NCCS}, -#endif -#ifdef NSWTCH - {"NSWTCH", NSWTCH}, -#endif -#ifdef N_MOUSE - {"N_MOUSE", N_MOUSE}, -#endif -#ifdef N_PPP - {"N_PPP", N_PPP}, -#endif -#ifdef N_SLIP - {"N_SLIP", N_SLIP}, -#endif -#ifdef N_STRIP - {"N_STRIP", N_STRIP}, -#endif -#ifdef N_TTY - {"N_TTY", N_TTY}, -#endif -#ifdef TCFLSH - {"TCFLSH", TCFLSH}, -#endif -#ifdef TCGETA - {"TCGETA", TCGETA}, -#endif -#ifdef TCGETS - {"TCGETS", TCGETS}, -#endif -#ifdef TCSBRK - {"TCSBRK", TCSBRK}, -#endif -#ifdef TCSBRKP - {"TCSBRKP", TCSBRKP}, -#endif -#ifdef TCSETA - {"TCSETA", TCSETA}, -#endif -#ifdef TCSETAF - {"TCSETAF", TCSETAF}, -#endif -#ifdef TCSETAW - {"TCSETAW", TCSETAW}, -#endif -#ifdef TCSETS - {"TCSETS", TCSETS}, -#endif -#ifdef TCSETSF - {"TCSETSF", TCSETSF}, -#endif -#ifdef TCSETSW - {"TCSETSW", TCSETSW}, -#endif -#ifdef TCXONC - {"TCXONC", TCXONC}, -#endif -#ifdef TIOCCONS - {"TIOCCONS", TIOCCONS}, -#endif -#ifdef TIOCEXCL - {"TIOCEXCL", TIOCEXCL}, -#endif -#ifdef TIOCGETD - {"TIOCGETD", TIOCGETD}, -#endif -#ifdef TIOCGICOUNT - {"TIOCGICOUNT", TIOCGICOUNT}, -#endif -#ifdef TIOCGLCKTRMIOS - {"TIOCGLCKTRMIOS", TIOCGLCKTRMIOS}, -#endif -#ifdef TIOCGPGRP - {"TIOCGPGRP", TIOCGPGRP}, -#endif -#ifdef TIOCGSERIAL - {"TIOCGSERIAL", TIOCGSERIAL}, -#endif -#ifdef TIOCGSOFTCAR - {"TIOCGSOFTCAR", TIOCGSOFTCAR}, -#endif -#ifdef TIOCGWINSZ - {"TIOCGWINSZ", TIOCGWINSZ}, -#endif -#ifdef TIOCINQ - {"TIOCINQ", TIOCINQ}, -#endif -#ifdef TIOCLINUX - {"TIOCLINUX", TIOCLINUX}, -#endif -#ifdef TIOCMBIC - {"TIOCMBIC", TIOCMBIC}, -#endif -#ifdef TIOCMBIS - {"TIOCMBIS", TIOCMBIS}, -#endif -#ifdef TIOCMGET - {"TIOCMGET", TIOCMGET}, -#endif -#ifdef TIOCMIWAIT - {"TIOCMIWAIT", TIOCMIWAIT}, -#endif -#ifdef TIOCMSET - {"TIOCMSET", TIOCMSET}, -#endif -#ifdef TIOCM_CAR - {"TIOCM_CAR", TIOCM_CAR}, -#endif -#ifdef TIOCM_CD - {"TIOCM_CD", TIOCM_CD}, -#endif -#ifdef TIOCM_CTS - {"TIOCM_CTS", TIOCM_CTS}, -#endif -#ifdef TIOCM_DSR - {"TIOCM_DSR", TIOCM_DSR}, -#endif -#ifdef TIOCM_DTR - {"TIOCM_DTR", TIOCM_DTR}, -#endif -#ifdef TIOCM_LE - {"TIOCM_LE", TIOCM_LE}, -#endif -#ifdef TIOCM_RI - {"TIOCM_RI", TIOCM_RI}, -#endif -#ifdef TIOCM_RNG - {"TIOCM_RNG", TIOCM_RNG}, -#endif -#ifdef TIOCM_RTS - {"TIOCM_RTS", TIOCM_RTS}, -#endif -#ifdef TIOCM_SR - {"TIOCM_SR", TIOCM_SR}, -#endif -#ifdef TIOCM_ST - {"TIOCM_ST", TIOCM_ST}, -#endif -#ifdef TIOCNOTTY - {"TIOCNOTTY", TIOCNOTTY}, -#endif -#ifdef TIOCNXCL - {"TIOCNXCL", TIOCNXCL}, -#endif -#ifdef TIOCOUTQ - {"TIOCOUTQ", TIOCOUTQ}, -#endif -#ifdef TIOCPKT - {"TIOCPKT", TIOCPKT}, -#endif -#ifdef TIOCPKT_DATA - {"TIOCPKT_DATA", TIOCPKT_DATA}, -#endif -#ifdef TIOCPKT_DOSTOP - {"TIOCPKT_DOSTOP", TIOCPKT_DOSTOP}, -#endif -#ifdef TIOCPKT_FLUSHREAD - {"TIOCPKT_FLUSHREAD", TIOCPKT_FLUSHREAD}, -#endif -#ifdef TIOCPKT_FLUSHWRITE - {"TIOCPKT_FLUSHWRITE", TIOCPKT_FLUSHWRITE}, -#endif -#ifdef TIOCPKT_NOSTOP - {"TIOCPKT_NOSTOP", TIOCPKT_NOSTOP}, -#endif -#ifdef TIOCPKT_START - {"TIOCPKT_START", TIOCPKT_START}, -#endif -#ifdef TIOCPKT_STOP - {"TIOCPKT_STOP", TIOCPKT_STOP}, -#endif -#ifdef TIOCSCTTY - {"TIOCSCTTY", TIOCSCTTY}, -#endif -#ifdef TIOCSERCONFIG - {"TIOCSERCONFIG", TIOCSERCONFIG}, -#endif -#ifdef TIOCSERGETLSR - {"TIOCSERGETLSR", TIOCSERGETLSR}, -#endif -#ifdef TIOCSERGETMULTI - {"TIOCSERGETMULTI", TIOCSERGETMULTI}, -#endif -#ifdef TIOCSERGSTRUCT - {"TIOCSERGSTRUCT", TIOCSERGSTRUCT}, -#endif -#ifdef TIOCSERGWILD - {"TIOCSERGWILD", TIOCSERGWILD}, -#endif -#ifdef TIOCSERSETMULTI - {"TIOCSERSETMULTI", TIOCSERSETMULTI}, -#endif -#ifdef TIOCSERSWILD - {"TIOCSERSWILD", TIOCSERSWILD}, -#endif -#ifdef TIOCSER_TEMT - {"TIOCSER_TEMT", TIOCSER_TEMT}, -#endif -#ifdef TIOCSETD - {"TIOCSETD", TIOCSETD}, -#endif -#ifdef TIOCSLCKTRMIOS - {"TIOCSLCKTRMIOS", TIOCSLCKTRMIOS}, -#endif -#ifdef TIOCSPGRP - {"TIOCSPGRP", TIOCSPGRP}, -#endif -#ifdef TIOCSSERIAL - {"TIOCSSERIAL", TIOCSSERIAL}, -#endif -#ifdef TIOCSSOFTCAR - {"TIOCSSOFTCAR", TIOCSSOFTCAR}, -#endif -#ifdef TIOCSTI - {"TIOCSTI", TIOCSTI}, -#endif -#ifdef TIOCSWINSZ - {"TIOCSWINSZ", TIOCSWINSZ}, -#endif -#ifdef TIOCTTYGSTRUCT - {"TIOCTTYGSTRUCT", TIOCTTYGSTRUCT}, -#endif - - /* sentinel */ - {NULL, 0} -}; - static struct PyModuleDef termiosmodule = { PyModuleDef_HEAD_INIT, @@ -952,7 +327,6 @@ PyMODINIT_FUNC PyInit_termios(void) { PyObject *m; - struct constant *constant = termios_constants; m = PyModule_Create(&termiosmodule); if (m == NULL) @@ -964,9 +338,245 @@ PyInit_termios(void) Py_INCREF(TermiosError); PyModule_AddObject(m, "error", TermiosError); - while (constant->name != NULL) { - PyModule_AddIntConstant(m, constant->name, constant->value); - ++constant; - } + if (B50) PyModule_AddIntConstant(m, "B50", B50); + if (B75) PyModule_AddIntConstant(m, "B75", B75); + if (B110) PyModule_AddIntConstant(m, "B110", B110); + if (B134) PyModule_AddIntConstant(m, "B134", B134); + if (B150) PyModule_AddIntConstant(m, "B150", B150); + if (B200) PyModule_AddIntConstant(m, "B200", B200); + if (B300) PyModule_AddIntConstant(m, "B300", B300); + if (B600) PyModule_AddIntConstant(m, "B600", B600); + if (B1200) PyModule_AddIntConstant(m, "B1200", B1200); + if (B1800) PyModule_AddIntConstant(m, "B1800", B1800); + if (B2400) PyModule_AddIntConstant(m, "B2400", B2400); + if (B4800) PyModule_AddIntConstant(m, "B4800", B4800); + if (B9600) PyModule_AddIntConstant(m, "B9600", B9600); + if (B19200) PyModule_AddIntConstant(m, "B19200", B19200); + if (B38400) PyModule_AddIntConstant(m, "B38400", B38400); + if (B57600) PyModule_AddIntConstant(m, "B57600", B57600); + if (B115200) PyModule_AddIntConstant(m, "B115200", B115200); + if (B230400) PyModule_AddIntConstant(m, "B230400", B230400); + /* TODO(jart): B460800 */ + if (B500000) PyModule_AddIntConstant(m, "B500000", B500000); + if (B576000) PyModule_AddIntConstant(m, "B576000", B576000); + /* TODO(jart): B921600 */ + if (B1000000) PyModule_AddIntConstant(m, "B1000000", B1000000); + if (B1152000) PyModule_AddIntConstant(m, "B1152000", B1152000); + if (B1500000) PyModule_AddIntConstant(m, "B1500000", B1500000); + if (B2000000) PyModule_AddIntConstant(m, "B2000000", B2000000); + if (B2500000) PyModule_AddIntConstant(m, "B2500000", B2500000); + if (B3000000) PyModule_AddIntConstant(m, "B3000000", B3000000); + if (B3500000) PyModule_AddIntConstant(m, "B3500000", B3500000); + if (B4000000) PyModule_AddIntConstant(m, "B4000000", B4000000); + if (CBAUDEX) PyModule_AddIntConstant(m, "CBAUDEX", CBAUDEX); + PyModule_AddIntConstant(m, "TCSANOW", TCSANOW); + if (TCSADRAIN) PyModule_AddIntConstant(m, "TCSADRAIN", TCSADRAIN); + if (TCSAFLUSH) PyModule_AddIntConstant(m, "TCSAFLUSH", TCSAFLUSH); + /* TODO(jart): TCSASOFT */ + if (TCIFLUSH) PyModule_AddIntConstant(m, "TCIFLUSH", TCIFLUSH); + if (TCOFLUSH) PyModule_AddIntConstant(m, "TCOFLUSH", TCOFLUSH); + if (TCIOFLUSH) PyModule_AddIntConstant(m, "TCIOFLUSH", TCIOFLUSH); + if (TCOOFF) PyModule_AddIntConstant(m, "TCOOFF", TCOOFF); + if (TCOON) PyModule_AddIntConstant(m, "TCOON", TCOON); + if (TCIOFF) PyModule_AddIntConstant(m, "TCIOFF", TCIOFF); + if (TCION) PyModule_AddIntConstant(m, "TCION", TCION); + if (IGNBRK) PyModule_AddIntConstant(m, "IGNBRK", IGNBRK); + if (BRKINT) PyModule_AddIntConstant(m, "BRKINT", BRKINT); + if (IGNPAR) PyModule_AddIntConstant(m, "IGNPAR", IGNPAR); + if (PARMRK) PyModule_AddIntConstant(m, "PARMRK", PARMRK); + if (INPCK) PyModule_AddIntConstant(m, "INPCK", INPCK); + if (ISTRIP) PyModule_AddIntConstant(m, "ISTRIP", ISTRIP); + if (INLCR) PyModule_AddIntConstant(m, "INLCR", INLCR); + if (IGNCR) PyModule_AddIntConstant(m, "IGNCR", IGNCR); + if (ICRNL) PyModule_AddIntConstant(m, "ICRNL", ICRNL); + if (IUCLC) PyModule_AddIntConstant(m, "IUCLC", IUCLC); + if (IXON) PyModule_AddIntConstant(m, "IXON", IXON); + if (IXANY) PyModule_AddIntConstant(m, "IXANY", IXANY); + if (IXOFF) PyModule_AddIntConstant(m, "IXOFF", IXOFF); + if (IMAXBEL) PyModule_AddIntConstant(m, "IMAXBEL", IMAXBEL); + if (OPOST) PyModule_AddIntConstant(m, "OPOST", OPOST); + if (OLCUC) PyModule_AddIntConstant(m, "OLCUC", OLCUC); + if (ONLCR) PyModule_AddIntConstant(m, "ONLCR", ONLCR); + if (OCRNL) PyModule_AddIntConstant(m, "OCRNL", OCRNL); + if (ONOCR) PyModule_AddIntConstant(m, "ONOCR", ONOCR); + if (ONLRET) PyModule_AddIntConstant(m, "ONLRET", ONLRET); + if (OFILL) PyModule_AddIntConstant(m, "OFILL", OFILL); + if (OFDEL) PyModule_AddIntConstant(m, "OFDEL", OFDEL); + if (NLDLY) PyModule_AddIntConstant(m, "NLDLY", NLDLY); + if (CRDLY) PyModule_AddIntConstant(m, "CRDLY", CRDLY); + if (TABDLY) PyModule_AddIntConstant(m, "TABDLY", TABDLY); + if (BSDLY) PyModule_AddIntConstant(m, "BSDLY", BSDLY); + if (VTDLY) PyModule_AddIntConstant(m, "VTDLY", VTDLY); + if (FFDLY) PyModule_AddIntConstant(m, "FFDLY", FFDLY); + PyModule_AddIntConstant(m, "NL0", NL0); + if (NL1) PyModule_AddIntConstant(m, "NL1", NL1); + PyModule_AddIntConstant(m, "CR0", CR0); + if (CR1) PyModule_AddIntConstant(m, "CR1", CR1); + if (CR2) PyModule_AddIntConstant(m, "CR2", CR2); + if (CR3) PyModule_AddIntConstant(m, "CR3", CR3); + PyModule_AddIntConstant(m, "TAB0", TAB0); + if (TAB1) PyModule_AddIntConstant(m, "TAB1", TAB1); + if (TAB2) PyModule_AddIntConstant(m, "TAB2", TAB2); + if (TAB3) PyModule_AddIntConstant(m, "TAB3", TAB3); + if (XTABS) PyModule_AddIntConstant(m, "XTABS", XTABS); + PyModule_AddIntConstant(m, "BS0", BS0); + if (BS1) PyModule_AddIntConstant(m, "BS1", BS1); + PyModule_AddIntConstant(m, "VT0", VT0); + if (VT1) PyModule_AddIntConstant(m, "VT1", VT1); + PyModule_AddIntConstant(m, "FF0", FF0); + if (FF1) PyModule_AddIntConstant(m, "FF1", FF1); + if (CSIZE) PyModule_AddIntConstant(m, "CSIZE", CSIZE); + if (CSTOPB) PyModule_AddIntConstant(m, "CSTOPB", CSTOPB); + if (CREAD) PyModule_AddIntConstant(m, "CREAD", CREAD); + if (PARENB) PyModule_AddIntConstant(m, "PARENB", PARENB); + if (PARODD) PyModule_AddIntConstant(m, "PARODD", PARODD); + if (HUPCL) PyModule_AddIntConstant(m, "HUPCL", HUPCL); + if (CLOCAL) PyModule_AddIntConstant(m, "CLOCAL", CLOCAL); + if (CIBAUD) PyModule_AddIntConstant(m, "CIBAUD", CIBAUD); + /* TODO(jart): CRTSCTS */ + if (CS5) PyModule_AddIntConstant(m, "CS5", CS5); + if (CS6) PyModule_AddIntConstant(m, "CS6", CS6); + if (CS7) PyModule_AddIntConstant(m, "CS7", CS7); + if (CS8) PyModule_AddIntConstant(m, "CS8", CS8); + if (ISIG) PyModule_AddIntConstant(m, "ISIG", ISIG); + if (ICANON) PyModule_AddIntConstant(m, "ICANON", ICANON); + if (XCASE) PyModule_AddIntConstant(m, "XCASE", XCASE); + if (ECHO) PyModule_AddIntConstant(m, "ECHO", ECHO); + if (ECHOE) PyModule_AddIntConstant(m, "ECHOE", ECHOE); + if (ECHOK) PyModule_AddIntConstant(m, "ECHOK", ECHOK); + if (ECHONL) PyModule_AddIntConstant(m, "ECHONL", ECHONL); + if (ECHOCTL) PyModule_AddIntConstant(m, "ECHOCTL", ECHOCTL); + if (ECHOPRT) PyModule_AddIntConstant(m, "ECHOPRT", ECHOPRT); + if (ECHOKE) PyModule_AddIntConstant(m, "ECHOKE", ECHOKE); + if (FLUSHO) PyModule_AddIntConstant(m, "FLUSHO", FLUSHO); + if (NOFLSH) PyModule_AddIntConstant(m, "NOFLSH", NOFLSH); + if (TOSTOP) PyModule_AddIntConstant(m, "TOSTOP", TOSTOP); + if (PENDIN) PyModule_AddIntConstant(m, "PENDIN", PENDIN); + if (IEXTEN) PyModule_AddIntConstant(m, "IEXTEN", IEXTEN); + if (VINTR) PyModule_AddIntConstant(m, "VINTR", VINTR); + if (VQUIT) PyModule_AddIntConstant(m, "VQUIT", VQUIT); + if (VERASE) PyModule_AddIntConstant(m, "VERASE", VERASE); + if (VKILL) PyModule_AddIntConstant(m, "VKILL", VKILL); + if (VEOF) PyModule_AddIntConstant(m, "VEOF", VEOF); + if (VTIME) PyModule_AddIntConstant(m, "VTIME", VTIME); + if (VMIN) PyModule_AddIntConstant(m, "VMIN", VMIN); + if (VSTART) PyModule_AddIntConstant(m, "VSTART", VSTART); + if (VSTOP) PyModule_AddIntConstant(m, "VSTOP", VSTOP); + if (VSUSP) PyModule_AddIntConstant(m, "VSUSP", VSUSP); + if (VEOL) PyModule_AddIntConstant(m, "VEOL", VEOL); + if (VREPRINT) PyModule_AddIntConstant(m, "VREPRINT", VREPRINT); + if (VDISCARD) PyModule_AddIntConstant(m, "VDISCARD", VDISCARD); + if (VWERASE) PyModule_AddIntConstant(m, "VWERASE", VWERASE); + if (VLNEXT) PyModule_AddIntConstant(m, "VLNEXT", VLNEXT); + if (VEOL2) PyModule_AddIntConstant(m, "VEOL2", VEOL2); + /* TODO(jart): B460800 */ + if (CBAUD) PyModule_AddIntConstant(m, "CBAUD", CBAUD); + /* TODO(jart): CDEL */ + /* TODO(jart): CDSUSP */ + /* TODO(jart): CEOF */ + if (CEOL) PyModule_AddIntConstant(m, "CEOL", CEOL); + /* TODO(jart): CEOL2 */ + /* TODO(jart): CEOT */ + /* TODO(jart): CERASE */ + /* TODO(jart): CESC */ + /* TODO(jart): CFLUSH */ + /* TODO(jart): CINTR */ + /* TODO(jart): CKILL */ + /* TODO(jart): CLNEXT */ + /* TODO(jart): CNUL */ + /* TODO(jart): COMMON */ + /* TODO(jart): CQUIT */ + /* TODO(jart): CRPRNT */ + /* TODO(jart): CSTART */ + /* TODO(jart): CSTOP */ + if (CSUSP) PyModule_AddIntConstant(m, "CSUSP", CSUSP); + /* TODO(jart): CSWTCH */ + if (CWERASE) PyModule_AddIntConstant(m, "CWERASE", CWERASE); + /* TODO(jart): EXTA */ + /* TODO(jart): EXTB */ + /* TODO(jart): FIOASYNC */ + /* TODO(jart): FIOCLEX */ + /* TODO(jart): FIONBIO */ + /* TODO(jart): FIONCLEX */ + /* TODO(jart): FIONREAD */ + /* TODO(jart): IBSHIFT */ + /* TODO(jart): CC */ + /* TODO(jart): MASK */ + /* TODO(jart): SHIFT */ + /* TODO(jart): NCC */ + if (NCCS) PyModule_AddIntConstant(m, "NCCS", NCCS); + /* TODO(jart): MOUSE */ + /* TODO(jart): PPP */ + /* TODO(jart): SLIP */ + /* TODO(jart): STRIP */ + /* TODO(jart): TTY */ + if (TCFLSH) PyModule_AddIntConstant(m, "TCFLSH", TCFLSH); + /* TODO(jart): TCGETA */ + if (TCGETS) PyModule_AddIntConstant(m, "TCGETS", TCGETS); + if (TCSBRK) PyModule_AddIntConstant(m, "TCSBRK", TCSBRK); + /* TODO(jart): TCSBRKP */ + /* TODO(jart): TCSETA */ + /* TODO(jart): TCSETAF */ + /* TODO(jart): TCSETAW */ + if (TCSETS) PyModule_AddIntConstant(m, "TCSETS", TCSETS); + if (TCSETSF) PyModule_AddIntConstant(m, "TCSETSF", TCSETSF); + if (TCSETSW) PyModule_AddIntConstant(m, "TCSETSW", TCSETSW); + if (TCXONC) PyModule_AddIntConstant(m, "TCXONC", TCXONC); + if (TIOCCONS) PyModule_AddIntConstant(m, "TIOCCONS", TIOCCONS); + /* TODO(jart): TIOCEXCL */ + if (TIOCGETD) PyModule_AddIntConstant(m, "TIOCGETD", TIOCGETD); + /* TODO(jart): TIOCGICOUNT */ + /* TODO(jart): TIOCGLCKTRMIOS */ + if (TIOCGPGRP) PyModule_AddIntConstant(m, "TIOCGPGRP", TIOCGPGRP); + /* TODO(jart): TIOCGSERIAL */ + /* TODO(jart): TIOCGSOFTCAR */ + if (TIOCGWINSZ) PyModule_AddIntConstant(m, "TIOCGWINSZ", TIOCGWINSZ); + /* TODO(jart): TIOCINQ */ + /* TODO(jart): TIOCLINUX */ + if (TIOCMBIC) PyModule_AddIntConstant(m, "TIOCMBIC", TIOCMBIC); + if (TIOCMBIS) PyModule_AddIntConstant(m, "TIOCMBIS", TIOCMBIS); + if (TIOCMGET) PyModule_AddIntConstant(m, "TIOCMGET", TIOCMGET); + /* TODO(jart): TIOCMIWAIT */ + if (TIOCMSET) PyModule_AddIntConstant(m, "TIOCMSET", TIOCMSET); + if (TIOCM_CAR) PyModule_AddIntConstant(m, "TIOCM_CAR", TIOCM_CAR); + if (TIOCM_CD) PyModule_AddIntConstant(m, "TIOCM_CD", TIOCM_CD); + if (TIOCM_CTS) PyModule_AddIntConstant(m, "TIOCM_CTS", TIOCM_CTS); + if (TIOCM_DSR) PyModule_AddIntConstant(m, "TIOCM_DSR", TIOCM_DSR); + if (TIOCM_DTR) PyModule_AddIntConstant(m, "TIOCM_DTR", TIOCM_DTR); + if (TIOCM_LE) PyModule_AddIntConstant(m, "TIOCM_LE", TIOCM_LE); + if (TIOCM_RI) PyModule_AddIntConstant(m, "TIOCM_RI", TIOCM_RI); + if (TIOCM_RNG) PyModule_AddIntConstant(m, "TIOCM_RNG", TIOCM_RNG); + if (TIOCM_RTS) PyModule_AddIntConstant(m, "TIOCM_RTS", TIOCM_RTS); + if (TIOCM_SR) PyModule_AddIntConstant(m, "TIOCM_SR", TIOCM_SR); + if (TIOCM_ST) PyModule_AddIntConstant(m, "TIOCM_ST", TIOCM_ST); + if (TIOCNOTTY) PyModule_AddIntConstant(m, "TIOCNOTTY", TIOCNOTTY); + if (TIOCNXCL) PyModule_AddIntConstant(m, "TIOCNXCL", TIOCNXCL); + if (TIOCOUTQ) PyModule_AddIntConstant(m, "TIOCOUTQ", TIOCOUTQ); + /* TODO(jart): TIOCPKT */ + /* TODO(jart): DATA */ + /* TODO(jart): DOSTOP */ + /* TODO(jart): FLUSHREAD */ + /* TODO(jart): FLUSHWRITE */ + /* TODO(jart): NOSTOP */ + /* TODO(jart): START */ + /* TODO(jart): STOP */ + if (TIOCSCTTY) PyModule_AddIntConstant(m, "TIOCSCTTY", TIOCSCTTY); + /* TODO(jart): TIOCSERCONFIG */ + if (TIOCSERGETLSR) PyModule_AddIntConstant(m, "TIOCSERGETLSR", TIOCSERGETLSR); + if (TIOCSERGETMULTI) PyModule_AddIntConstant(m, "TIOCSERGETMULTI", TIOCSERGETMULTI); + /* TODO(jart): TIOCSERGSTRUCT */ + /* TODO(jart): TIOCSERGWILD */ + if (TIOCSERSETMULTI) PyModule_AddIntConstant(m, "TIOCSERSETMULTI", TIOCSERSETMULTI); + /* TODO(jart): TIOCSERSWILD */ + if (TIOCSER_TEMT) PyModule_AddIntConstant(m, "TIOCSER_TEMT", TIOCSER_TEMT); + if (TIOCSETD) PyModule_AddIntConstant(m, "TIOCSETD", TIOCSETD); + /* TODO(jart): TIOCSLCKTRMIOS */ + if (TIOCSPGRP) PyModule_AddIntConstant(m, "TIOCSPGRP", TIOCSPGRP); + /* TODO(jart): TIOCSSERIAL */ + /* TODO(jart): TIOCSSOFTCAR */ + if (TIOCSTI) PyModule_AddIntConstant(m, "TIOCSTI", TIOCSTI); + if (TIOCSWINSZ) PyModule_AddIntConstant(m, "TIOCSWINSZ", TIOCSWINSZ); + /* TODO(jart): TIOCTTYGSTRUCT */ + return m; } diff --git a/third_party/python/Modules/testcapi_long.h b/third_party/python/Modules/testcapi_long.inc similarity index 99% rename from third_party/python/Modules/testcapi_long.h rename to third_party/python/Modules/testcapi_long.inc index 6bddad7bb..fa09d8b6c 100644 --- a/third_party/python/Modules/testcapi_long.h +++ b/third_party/python/Modules/testcapi_long.inc @@ -1,3 +1,4 @@ +/* clang-format off */ /* Poor-man's template. Macros used: TESTNAME name of the test (like test_long_api_inner) TYPENAME the signed type (like long) diff --git a/third_party/python/Modules/timemodule.c b/third_party/python/Modules/timemodule.c index 62036312a..871b1d26e 100644 --- a/third_party/python/Modules/timemodule.c +++ b/third_party/python/Modules/timemodule.c @@ -1,12 +1,31 @@ -/* clang-format off */ -/* Time module */ - -#include "third_party/python/Include/Python.h" - +#include "libc/calls/calls.h" +#include "libc/calls/struct/rusage.h" +#include "libc/calls/struct/timespec.h" +#include "libc/calls/struct/tms.h" +#include "libc/errno.h" #include "libc/sock/select.h" -#include "libc/time/time.h" -#include "libc/time/struct/tm.h" #include "libc/sysv/consts/rusage.h" +#include "libc/time/struct/tm.h" +#include "libc/time/time.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/namespaceobject.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pytime.h" +#include "third_party/python/Include/structseq.h" +#include "third_party/python/pyconfig.h" +/* clang-format off */ + +/* Time module */ typedef int clockid_t; #undef HAVE_CLOCK_SETTIME diff --git a/third_party/python/Modules/tkappinit.c b/third_party/python/Modules/tkappinit.c deleted file mode 100644 index 48bdd2491..000000000 --- a/third_party/python/Modules/tkappinit.c +++ /dev/null @@ -1,167 +0,0 @@ -/* clang-format off */ -/* appinit.c -- Tcl and Tk application initialization. - - The function Tcl_AppInit() below initializes various Tcl packages. - It is called for each Tcl interpreter created by _tkinter.create(). - It needs to be compiled with -DWITH_ flags for each package - that you are statically linking with. You may have to add sections - for packages not yet listed below. - - Note that those packages for which Tcl_StaticPackage() is called with - a NULL first argument are known as "static loadable" packages to - Tcl but not actually initialized. To use these, you have to load - it explicitly, e.g. tkapp.eval("load {} Blt"). - */ - -#include -#include -#include - -#include "tkinter.h" - -#ifdef TKINTER_PROTECT_LOADTK -/* See Tkapp_TkInit in _tkinter.c for the usage of tk_load_faile */ -static int tk_load_failed; -#endif - -int -Tcl_AppInit(Tcl_Interp *interp) -{ - const char *_tkinter_skip_tk_init; -#ifdef TKINTER_PROTECT_LOADTK - const char *_tkinter_tk_failed; -#endif - -#ifdef TK_AQUA -#ifndef MAX_PATH_LEN -#define MAX_PATH_LEN 1024 -#endif - char tclLibPath[MAX_PATH_LEN], tkLibPath[MAX_PATH_LEN]; - Tcl_Obj* pathPtr; - - /* pre- Tcl_Init code copied from tkMacOSXAppInit.c */ - Tk_MacOSXOpenBundleResources (interp, "com.tcltk.tcllibrary", - tclLibPath, MAX_PATH_LEN, 0); - - if (tclLibPath[0] != '\0') { - Tcl_SetVar(interp, "tcl_library", tclLibPath, TCL_GLOBAL_ONLY); - Tcl_SetVar(interp, "tclDefaultLibrary", tclLibPath, TCL_GLOBAL_ONLY); - Tcl_SetVar(interp, "tcl_pkgPath", tclLibPath, TCL_GLOBAL_ONLY); - } - - if (tclLibPath[0] != '\0') { - Tcl_SetVar(interp, "tcl_library", tclLibPath, TCL_GLOBAL_ONLY); - Tcl_SetVar(interp, "tclDefaultLibrary", tclLibPath, TCL_GLOBAL_ONLY); - Tcl_SetVar(interp, "tcl_pkgPath", tclLibPath, TCL_GLOBAL_ONLY); - } -#endif - if (Tcl_Init (interp) == TCL_ERROR) - return TCL_ERROR; - -#ifdef TK_AQUA - /* pre- Tk_Init code copied from tkMacOSXAppInit.c */ - Tk_MacOSXOpenBundleResources (interp, "com.tcltk.tklibrary", - tkLibPath, MAX_PATH_LEN, 1); - - if (tclLibPath[0] != '\0') { - pathPtr = Tcl_NewStringObj(tclLibPath, -1); - } else { - Tcl_Obj *pathPtr = TclGetLibraryPath(); - } - - if (tkLibPath[0] != '\0') { - Tcl_Obj *objPtr; - - Tcl_SetVar(interp, "tk_library", tkLibPath, TCL_GLOBAL_ONLY); - objPtr = Tcl_NewStringObj(tkLibPath, -1); - Tcl_ListObjAppendElement(NULL, pathPtr, objPtr); - } - - TclSetLibraryPath(pathPtr); -#endif - -#ifdef WITH_XXX - /* Initialize modules that don't require Tk */ -#endif - - _tkinter_skip_tk_init = Tcl_GetVar(interp, - "_tkinter_skip_tk_init", TCL_GLOBAL_ONLY); - if (_tkinter_skip_tk_init != NULL && - strcmp(_tkinter_skip_tk_init, "1") == 0) { - return TCL_OK; - } - -#ifdef TKINTER_PROTECT_LOADTK - _tkinter_tk_failed = Tcl_GetVar(interp, - "_tkinter_tk_failed", TCL_GLOBAL_ONLY); - - if (tk_load_failed || ( - _tkinter_tk_failed != NULL && - strcmp(_tkinter_tk_failed, "1") == 0)) { - Tcl_SetResult(interp, TKINTER_LOADTK_ERRMSG, TCL_STATIC); - return TCL_ERROR; - } -#endif - - if (Tk_Init(interp) == TCL_ERROR) { -#ifdef TKINTER_PROTECT_LOADTK - tk_load_failed = 1; - Tcl_SetVar(interp, "_tkinter_tk_failed", "1", TCL_GLOBAL_ONLY); -#endif - return TCL_ERROR; - } - - Tk_MainWindow(interp); - -#ifdef TK_AQUA - TkMacOSXInitAppleEvents(interp); - TkMacOSXInitMenus(interp); -#endif - -#ifdef WITH_PIL /* 0.2b5 and later -- not yet released as of May 14 */ - { - extern void TkImaging_Init(Tcl_Interp *); - TkImaging_Init(interp); - /* XXX TkImaging_Init() doesn't have the right return type */ - /*Tcl_StaticPackage(interp, "Imaging", TkImaging_Init, NULL);*/ - } -#endif - -#ifdef WITH_PIL_OLD /* 0.2b4 and earlier */ - { - extern void TkImaging_Init(void); - /* XXX TkImaging_Init() doesn't have the right prototype */ - /*Tcl_StaticPackage(interp, "Imaging", TkImaging_Init, NULL);*/ - } -#endif - -#ifdef WITH_TIX - { - extern int Tix_Init(Tcl_Interp *interp); - extern int Tix_SafeInit(Tcl_Interp *interp); - Tcl_StaticPackage(NULL, "Tix", Tix_Init, Tix_SafeInit); - } -#endif - -#ifdef WITH_BLT - { - extern int Blt_Init(Tcl_Interp *); - extern int Blt_SafeInit(Tcl_Interp *); - Tcl_StaticPackage(NULL, "Blt", Blt_Init, Blt_SafeInit); - } -#endif - -#ifdef WITH_TOGL - { - /* XXX I've heard rumors that this doesn't work */ - extern int Togl_Init(Tcl_Interp *); - /* XXX Is there no Togl_SafeInit? */ - Tcl_StaticPackage(NULL, "Togl", Togl_Init, NULL); - } -#endif - -#ifdef WITH_XXX - -#endif - return TCL_OK; -} diff --git a/third_party/python/Modules/tkinter.h b/third_party/python/Modules/tkinter.h index cb5a806b0..80c27e4cb 100644 --- a/third_party/python/Modules/tkinter.h +++ b/third_party/python/Modules/tkinter.h @@ -1,5 +1,6 @@ #ifndef TKINTER_H #define TKINTER_H +/* clang-format off */ /* This header is used to share some macros between _tkinter.c and * tkappinit.c. diff --git a/third_party/python/Modules/unicodedata.c b/third_party/python/Modules/unicodedata.c index 32a02e987..18478f867 100644 --- a/third_party/python/Modules/unicodedata.c +++ b/third_party/python/Modules/unicodedata.c @@ -1,4 +1,17 @@ +#define PY_SSIZE_T_CLEAN +#include "libc/fmt/fmt.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pycapsule.h" +#include "third_party/python/Include/pyctype.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/ucnhash.h" /* clang-format off */ + /* ------------------------------------------------------------------------ unicodedata -- Provides access to the Unicode database. @@ -14,12 +27,6 @@ ------------------------------------------------------------------------ */ -#define PY_SSIZE_T_CLEAN - -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/ucnhash.h" -#include "third_party/python/Include/structmember.h" - /*[clinic input] module unicodedata class unicodedata.UCD 'PreviousDBVersion *' '&UCD_Type' @@ -51,7 +58,7 @@ typedef struct change_record { } change_record; /* data file generated by Tools/unicode/makeunicodedata.py */ -#include "unicodedata_db.h" +#include "third_party/python/Modules/unicodedata_db.inc" static const _PyUnicode_DatabaseRecord* _getrecord_ex(Py_UCS4 code) @@ -872,7 +879,7 @@ unicodedata_UCD_normalize_impl(PyObject *self, const char *form, /* unicode character name tables */ /* data file generated by Tools/unicode/makeunicodedata.py */ -#include "unicodename_db.h" +#include "third_party/python/Modules/unicodename_db.inc" /* -------------------------------------------------------------------- */ /* database code (cut and pasted from the unidb package) */ diff --git a/third_party/python/Modules/unicodedata_db.h b/third_party/python/Modules/unicodedata_db.inc similarity index 99% rename from third_party/python/Modules/unicodedata_db.h rename to third_party/python/Modules/unicodedata_db.inc index ea40c2bf5..f33ee6038 100644 --- a/third_party/python/Modules/unicodedata_db.h +++ b/third_party/python/Modules/unicodedata_db.inc @@ -1,3 +1,4 @@ +/* clang-format off */ /* this file was generated by Tools/unicode/makeunicodedata.py 3.2 */ #define UNIDATA_VERSION "9.0.0" diff --git a/third_party/python/Modules/unicodename_db.h b/third_party/python/Modules/unicodename_db.inc similarity index 99% rename from third_party/python/Modules/unicodename_db.h rename to third_party/python/Modules/unicodename_db.inc index a81d8e31e..09de96e71 100644 --- a/third_party/python/Modules/unicodename_db.h +++ b/third_party/python/Modules/unicodename_db.inc @@ -1,3 +1,4 @@ +/* clang-format off */ /* this file was generated by Tools/unicode/makeunicodedata.py 3.2 */ #define NAME_MAXLEN 256 diff --git a/third_party/python/Modules/xxlimited.c b/third_party/python/Modules/xxlimited.c index 029273afa..aa4f6cc29 100644 --- a/third_party/python/Modules/xxlimited.c +++ b/third_party/python/Modules/xxlimited.c @@ -1,3 +1,11 @@ +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/methodobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/typeslots.h" +#include "third_party/python/Include/unicodeobject.h" /* clang-format off */ /* Use this file as a template to start implementing a module that @@ -15,8 +23,6 @@ /* Xxo objects */ -#include "Python.h" - static PyObject *ErrorObject; typedef struct { diff --git a/third_party/python/Modules/xxmodule.c b/third_party/python/Modules/xxmodule.c index 9c56f2171..bfe0d7008 100644 --- a/third_party/python/Modules/xxmodule.c +++ b/third_party/python/Modules/xxmodule.c @@ -1,3 +1,10 @@ +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/methodobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" /* clang-format off */ /* Use this file as a template to start implementing a module that @@ -15,7 +22,6 @@ /* Xxo objects */ -#include "Python.h" static PyObject *ErrorObject; diff --git a/third_party/python/Modules/xxsubtype.c b/third_party/python/Modules/xxsubtype.c index c99133779..8c9f8728d 100644 --- a/third_party/python/Modules/xxsubtype.c +++ b/third_party/python/Modules/xxsubtype.c @@ -1,6 +1,15 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" +#include "libc/calls/weirdtypes.h" +#include "libc/time/time.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/pymacro.h" #include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/tupleobject.h" +/* clang-format off */ PyDoc_STRVAR(xxsubtype__doc__, "xxsubtype is an example module showing how to subtype builtin types from C.\n" diff --git a/third_party/python/Modules/zipimport.c b/third_party/python/Modules/zipimport.c index ac4c5f129..4b1a82410 100644 --- a/third_party/python/Modules/zipimport.c +++ b/third_party/python/Modules/zipimport.c @@ -1,9 +1,32 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" -#include "third_party/python/Include/osdefs.h" -#include "third_party/python/Include/marshal.h" +#include "libc/bits/bits.h" +#include "libc/calls/calls.h" +#include "libc/calls/weirdtypes.h" #include "libc/time/struct/tm.h" +#include "libc/time/time.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/code.h" +#include "third_party/python/Include/compile.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/marshal.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/osdefs.h" +#include "third_party/python/Include/patchlevel.h" +#include "third_party/python/Include/pgenheaders.h" +#include "third_party/python/Include/pydebug.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pystate.h" +#include "third_party/python/Include/pythonrun.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/sysmodule.h" +#include "third_party/python/Include/unicodeobject.h" +/* clang-format off */ #define IS_SOURCE 0x0 #define IS_BYTECODE 0x1 @@ -828,32 +851,6 @@ static PyTypeObject ZipImporter_Type = { /* implementation */ -/* Given a buffer, return the unsigned int that is represented by the first - 4 bytes, encoded as little endian. This partially reimplements - marshal.c:r_long() */ -static unsigned int -get_uint32(const unsigned char *buf) -{ - unsigned int x; - x = buf[0]; - x |= (unsigned int)buf[1] << 8; - x |= (unsigned int)buf[2] << 16; - x |= (unsigned int)buf[3] << 24; - return x; -} - -/* Given a buffer, return the unsigned int that is represented by the first - 2 bytes, encoded as little endian. This partially reimplements - marshal.c:r_short() */ -static unsigned short -get_uint16(const unsigned char *buf) -{ - unsigned short x; - x = buf[0]; - x |= (unsigned short)buf[1] << 8; - return x; -} - static void set_file_error(PyObject *archive, int eof) { @@ -925,14 +922,14 @@ read_directory(PyObject *archive) if (fread(buffer, 1, 22, fp) != 22) { goto file_error; } - if (get_uint32(buffer) != 0x06054B50u) { + if (READ32LE(buffer) != 0x06054B50u) { /* Bad: End of Central Dir signature */ errmsg = "not a Zip file"; goto invalid_header; } - header_size = get_uint32(buffer + 12); - header_offset = get_uint32(buffer + 16); + header_size = READ32LE(buffer + 12); + header_offset = READ32LE(buffer + 16); if (header_position < header_size) { errmsg = "bad central directory size"; goto invalid_header; @@ -967,25 +964,25 @@ read_directory(PyObject *archive) goto eof_error; } /* Start of file header */ - if (get_uint32(buffer) != 0x02014B50u) { + if (READ32LE(buffer) != 0x02014B50u) { break; /* Bad: Central Dir File Header */ } if (n != 46) { goto eof_error; } - flags = get_uint16(buffer + 8); - compress = get_uint16(buffer + 10); - time = get_uint16(buffer + 12); - date = get_uint16(buffer + 14); - crc = get_uint32(buffer + 16); - data_size = get_uint32(buffer + 20); - file_size = get_uint32(buffer + 24); - name_size = get_uint16(buffer + 28); + flags = READ16LE(buffer + 8); + compress = READ16LE(buffer + 10); + time = READ16LE(buffer + 12); + date = READ16LE(buffer + 14); + crc = READ32LE(buffer + 16); + data_size = READ32LE(buffer + 20); + file_size = READ32LE(buffer + 24); + name_size = READ16LE(buffer + 28); header_size = (unsigned int)name_size + - get_uint16(buffer + 30) /* extra field */ + - get_uint16(buffer + 32) /* comment */; + READ16LE(buffer + 30) /* extra field */ + + READ16LE(buffer + 32) /* comment */; - file_offset = get_uint32(buffer + 42); + file_offset = READ32LE(buffer + 42); if (file_offset > header_offset) { errmsg = "bad local header offset"; goto invalid_header; @@ -1161,15 +1158,15 @@ get_data(PyObject *archive, PyObject *toc_entry) if (fread(buffer, 1, 30, fp) != 30) { goto eof_error; } - if (get_uint32(buffer) != 0x04034B50u) { + if (READ32LE(buffer) != 0x04034B50u) { /* Bad: Local File Header */ errmsg = "bad local file header"; goto invalid_header; } header_size = (unsigned int)30 + - get_uint16(buffer + 26) /* file name */ + - get_uint16(buffer + 28) /* extra field */; + READ16LE(buffer + 26) /* file name */ + + READ16LE(buffer + 28) /* extra field */; if (file_offset > LONG_MAX - header_size) { errmsg = "bad local file header size"; goto invalid_header; @@ -1282,7 +1279,7 @@ unmarshal_code(PyObject *pathname, PyObject *data, time_t mtime) return NULL; } - if (get_uint32(buf) != (unsigned int)PyImport_GetMagicNumber()) { + if (READ32LE(buf) != (unsigned int)PyImport_GetMagicNumber()) { if (Py_VerboseFlag) { PySys_FormatStderr("# %R has bad magic\n", pathname); @@ -1291,7 +1288,7 @@ unmarshal_code(PyObject *pathname, PyObject *data, time_t mtime) return Py_None; /* signal caller to try alternative */ } - if (mtime != 0 && !eq_mtime(get_uint32(buf + 4), mtime)) { + if (mtime != 0 && !eq_mtime(READ32LE(buf + 4), mtime)) { if (Py_VerboseFlag) { PySys_FormatStderr("# %R has bad mtime\n", pathname); diff --git a/third_party/python/Modules/zlibmodule.c b/third_party/python/Modules/zlibmodule.c index a7cd7e0a8..b5735bef9 100644 --- a/third_party/python/Modules/zlibmodule.c +++ b/third_party/python/Modules/zlibmodule.c @@ -1,26 +1,30 @@ +#define PY_SSIZE_T_CLEAN +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/zlib/zlib.h" /* clang-format off */ + /* zlibmodule.c -- gzip-compatible data compression */ /* See http://zlib.net/ */ /* Windows users: read Python's PCbuild\readme.txt */ -#define PY_SSIZE_T_CLEAN - -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" -#include "third_party/zlib/zlib.h" - - #ifdef WITH_THREAD - #include "pythread.h" - #define ENTER_ZLIB(obj) \ - Py_BEGIN_ALLOW_THREADS; \ - PyThread_acquire_lock((obj)->lock, 1); \ - Py_END_ALLOW_THREADS; - #define LEAVE_ZLIB(obj) PyThread_release_lock((obj)->lock); +#include "third_party/python/Include/pythread.h" +#define ENTER_ZLIB(obj) \ + Py_BEGIN_ALLOW_THREADS; \ + PyThread_acquire_lock((obj)->lock, 1); \ + Py_END_ALLOW_THREADS; +#define LEAVE_ZLIB(obj) PyThread_release_lock((obj)->lock); #else - #define ENTER_ZLIB(obj) - #define LEAVE_ZLIB(obj) +#define ENTER_ZLIB(obj) +#define LEAVE_ZLIB(obj) #endif #if defined(ZLIB_VERNUM) && ZLIB_VERNUM >= 0x1221 diff --git a/third_party/python/Objects/abstract.c b/third_party/python/Objects/abstract.c index a5fbe207c..86f2c64bb 100644 --- a/third_party/python/Objects/abstract.c +++ b/third_party/python/Objects/abstract.c @@ -1,9 +1,26 @@ -/* clang-format off */ -/* Abstract Object Interface (many thanks to Jim Fulton) */ - -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" +#include "libc/assert.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/bytearrayobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/funcobject.h" +#include "third_party/python/Include/iterobject.h" +#include "third_party/python/Include/listobject.h" #include "third_party/python/Include/longintrepr.h" +#include "third_party/python/Include/methodobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/sliceobject.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/tupleobject.h" +#include "third_party/python/Include/warnings.h" +/* clang-format off */ + +/* Abstract Object Interface (many thanks to Jim Fulton) */ /* Shorthands to return certain errors */ diff --git a/third_party/python/Objects/accu.c b/third_party/python/Objects/accu.c index d3667f2dd..226ebb099 100644 --- a/third_party/python/Objects/accu.c +++ b/third_party/python/Objects/accu.c @@ -1,8 +1,10 @@ -/* clang-format off */ -/* Accumulator struct implementation */ - -#include "third_party/python/Include/Python.h" +#include "libc/assert.h" #include "third_party/python/Include/accu.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/unicodeobject.h" +/* clang-format off */ + +/* Accumulator struct implementation */ static PyObject * join_list_unicode(PyObject *lst) diff --git a/third_party/python/Objects/boolobject.c b/third_party/python/Objects/boolobject.c index 0863e51ca..1e2574c73 100644 --- a/third_party/python/Objects/boolobject.c +++ b/third_party/python/Objects/boolobject.c @@ -1,8 +1,10 @@ -/* clang-format off */ -/* Boolean type, a subtype of int */ - -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/boolobject.h" #include "third_party/python/Include/longintrepr.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/pymacro.h" +/* clang-format off */ + +/* Boolean type, a subtype of int */ /* We define bool_repr to return "False" or "True" */ diff --git a/third_party/python/Objects/bytearrayobject.c b/third_party/python/Objects/bytearrayobject.c index 5637a700b..c9b27b4b9 100644 --- a/third_party/python/Objects/bytearrayobject.c +++ b/third_party/python/Objects/bytearrayobject.c @@ -1,12 +1,26 @@ -/* clang-format off */ -/* PyByteArray (bytearray) implementation */ - #define PY_SSIZE_T_CLEAN -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/bytearrayobject.h" #include "third_party/python/Include/bytes_methods.h" #include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/codecs.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyctype.h" +#include "third_party/python/Include/pydebug.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" #include "third_party/python/Include/pystrhex.h" +#include "third_party/python/Include/pythonrun.h" +#include "third_party/python/Include/sliceobject.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/warnings.h" +/* clang-format off */ + +/* PyByteArray (bytearray) implementation */ /*[clinic input] class bytearray "PyByteArrayObject *" "&PyByteArray_Type" @@ -831,7 +845,7 @@ bytearray_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds) if (count > 0) { if (PyByteArray_Resize((PyObject *)self, count)) return -1; - memset(PyByteArray_AS_STRING(self), 0, count); + bzero(PyByteArray_AS_STRING(self), count); } return 0; } diff --git a/third_party/python/Objects/bytes_methods.c b/third_party/python/Objects/bytes_methods.c index 96784f713..b7a42f39e 100644 --- a/third_party/python/Objects/bytes_methods.c +++ b/third_party/python/Objects/bytes_methods.c @@ -1,7 +1,13 @@ -/* clang-format off */ #define PY_SSIZE_T_CLEAN -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" #include "third_party/python/Include/bytes_methods.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/pyctype.h" +#include "third_party/python/Include/pyerrors.h" +/* clang-format off */ PyDoc_STRVAR_shared(_Py_isspace__doc__, "B.isspace() -> bool\n\ diff --git a/third_party/python/Objects/bytesobject.c b/third_party/python/Objects/bytesobject.c index 3dcc621f1..5f3ac0ff1 100644 --- a/third_party/python/Objects/bytesobject.c +++ b/third_party/python/Objects/bytesobject.c @@ -1,11 +1,30 @@ -/* clang-format off */ -/* bytes object implementation */ - #define PY_SSIZE_T_CLEAN - -#include "third_party/python/Include/Python.h" +#include "libc/assert.h" +#include "libc/fmt/fmt.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/bytearrayobject.h" #include "third_party/python/Include/bytes_methods.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/codecs.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyctype.h" +#include "third_party/python/Include/pydebug.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pyhash.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pyport.h" #include "third_party/python/Include/pystrhex.h" +#include "third_party/python/Include/pystrtod.h" +#include "third_party/python/Include/sliceobject.h" +#include "third_party/python/Include/warnings.h" +/* clang-format off */ + +/* bytes object implementation */ /*[clinic input] class bytes "PyBytesObject *" "&PyBytes_Type" @@ -3204,7 +3223,7 @@ void _PyBytesWriter_Init(_PyBytesWriter *writer) { /* Set all attributes before small_buffer to 0 */ - memset(writer, 0, offsetof(_PyBytesWriter, small_buffer)); + bzero(writer, offsetof(_PyBytesWriter, small_buffer)); #ifdef Py_DEBUG memset(writer->small_buffer, 0xCB, sizeof(writer->small_buffer)); #endif diff --git a/third_party/python/Objects/capsule.c b/third_party/python/Objects/capsule.c index f6c06b9d0..5feb4a26d 100644 --- a/third_party/python/Objects/capsule.c +++ b/third_party/python/Objects/capsule.c @@ -1,8 +1,12 @@ +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pycapsule.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" /* clang-format off */ /* Wrap void * pointers to be passed between C modules */ -#include "third_party/python/Include/Python.h" - /* Internal structure of PyCapsule */ typedef struct { PyObject_HEAD diff --git a/third_party/python/Objects/cellobject.c b/third_party/python/Objects/cellobject.c index 2e62f9373..d2166c55e 100644 --- a/third_party/python/Objects/cellobject.c +++ b/third_party/python/Objects/cellobject.c @@ -1,8 +1,11 @@ +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/cellobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" /* clang-format off */ /* Cell object implementation */ -#include "third_party/python/Include/Python.h" - PyObject * PyCell_New(PyObject *obj) { diff --git a/third_party/python/Objects/classobject.c b/third_party/python/Objects/classobject.c index 34e9c8dd5..28dfab2c8 100644 --- a/third_party/python/Objects/classobject.c +++ b/third_party/python/Objects/classobject.c @@ -1,8 +1,18 @@ -/* clang-format off */ -/* Class object implementation (dead now except for methods) */ - -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/classobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/methodobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" #include "third_party/python/Include/structmember.h" +/* clang-format off */ + +/* Class object implementation (dead now except for methods) */ #define TP_DESCR_GET(t) ((t)->tp_descr_get) diff --git a/third_party/python/Objects/clinic/bytearrayobject.inc b/third_party/python/Objects/clinic/bytearrayobject.inc index c164c79f6..2fe1d24e7 100644 --- a/third_party/python/Objects/clinic/bytearrayobject.inc +++ b/third_party/python/Objects/clinic/bytearrayobject.inc @@ -1,3 +1,4 @@ +/* clang-format off */ /*[clinic input] preserve [clinic start generated code]*/ diff --git a/third_party/python/Objects/clinic/bytesobject.inc b/third_party/python/Objects/clinic/bytesobject.inc index 191de20f5..2cca9dac8 100644 --- a/third_party/python/Objects/clinic/bytesobject.inc +++ b/third_party/python/Objects/clinic/bytesobject.inc @@ -1,3 +1,4 @@ +/* clang-format off */ /*[clinic input] preserve [clinic start generated code]*/ diff --git a/third_party/python/Objects/clinic/dictobject.inc b/third_party/python/Objects/clinic/dictobject.inc index d0cdfc3ed..8bfb357fa 100644 --- a/third_party/python/Objects/clinic/dictobject.inc +++ b/third_party/python/Objects/clinic/dictobject.inc @@ -1,43 +1,42 @@ +/* clang-format off */ /*[clinic input] preserve [clinic start generated code]*/ -PyDoc_STRVAR(dict_fromkeys__doc__, -"fromkeys($type, iterable, value=None, /)\n" -"--\n" -"\n" -"Returns a new dict with keys from iterable and values equal to value."); +PyDoc_STRVAR( + dict_fromkeys__doc__, + "fromkeys($type, iterable, value=None, /)\n" + "--\n" + "\n" + "Returns a new dict with keys from iterable and values equal to value."); -#define DICT_FROMKEYS_METHODDEF \ - {"fromkeys", (PyCFunction)dict_fromkeys, METH_VARARGS|METH_CLASS, dict_fromkeys__doc__}, +#define DICT_FROMKEYS_METHODDEF \ + {"fromkeys", (PyCFunction)dict_fromkeys, METH_VARARGS | METH_CLASS, \ + dict_fromkeys__doc__}, -static PyObject * -dict_fromkeys_impl(PyTypeObject *type, PyObject *iterable, PyObject *value); +static PyObject *dict_fromkeys_impl(PyTypeObject *type, PyObject *iterable, + PyObject *value); -static PyObject * -dict_fromkeys(PyTypeObject *type, PyObject *args) -{ - PyObject *return_value = NULL; - PyObject *iterable; - PyObject *value = Py_None; +static PyObject *dict_fromkeys(PyTypeObject *type, PyObject *args) { + PyObject *return_value = NULL; + PyObject *iterable; + PyObject *value = Py_None; - if (!PyArg_UnpackTuple(args, "fromkeys", - 1, 2, - &iterable, &value)) { - goto exit; - } - return_value = dict_fromkeys_impl(type, iterable, value); + if (!PyArg_UnpackTuple(args, "fromkeys", 1, 2, &iterable, &value)) { + goto exit; + } + return_value = dict_fromkeys_impl(type, iterable, value); exit: - return return_value; + return return_value; } -PyDoc_STRVAR(dict___contains____doc__, -"__contains__($self, key, /)\n" -"--\n" -"\n" -"True if D has a key k, else False."); +PyDoc_STRVAR(dict___contains____doc__, "__contains__($self, key, /)\n" + "--\n" + "\n" + "True if D has a key k, else False."); -#define DICT___CONTAINS___METHODDEF \ - {"__contains__", (PyCFunction)dict___contains__, METH_O|METH_COEXIST, dict___contains____doc__}, +#define DICT___CONTAINS___METHODDEF \ + {"__contains__", (PyCFunction)dict___contains__, METH_O | METH_COEXIST, \ + dict___contains____doc__}, /*[clinic end generated code: output=926326109e3d9839 input=a9049054013a1b77]*/ diff --git a/third_party/python/Objects/clinic/unicodeobject.inc b/third_party/python/Objects/clinic/unicodeobject.inc index 891e90c31..58c854b17 100644 --- a/third_party/python/Objects/clinic/unicodeobject.inc +++ b/third_party/python/Objects/clinic/unicodeobject.inc @@ -1,3 +1,4 @@ +/* clang-format off */ /*[clinic input] preserve [clinic start generated code]*/ diff --git a/third_party/python/Objects/codeobject.c b/third_party/python/Objects/codeobject.c index d3f562b4f..a8f3759c4 100644 --- a/third_party/python/Objects/codeobject.c +++ b/third_party/python/Objects/codeobject.c @@ -1,7 +1,23 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" +#include "libc/math.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/bytesobject.h" #include "third_party/python/Include/code.h" +#include "third_party/python/Include/complexobject.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pystate.h" +#include "third_party/python/Include/setobject.h" +#include "third_party/python/Include/sliceobject.h" #include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/tupleobject.h" +#include "third_party/python/Include/unicodeobject.h" +/* clang-format off */ #define NAME_CHARS \ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" diff --git a/third_party/python/Objects/complexobject.c b/third_party/python/Objects/complexobject.c index f5b5a4a9b..86b60e353 100644 --- a/third_party/python/Objects/complexobject.c +++ b/third_party/python/Objects/complexobject.c @@ -1,6 +1,20 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" +#include "libc/errno.h" +#include "libc/math.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/complexobject.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyctype.h" +#include "third_party/python/Include/pyfpe.h" +#include "third_party/python/Include/pyhash.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymath.h" +#include "third_party/python/Include/pystrtod.h" #include "third_party/python/Include/structmember.h" +/* clang-format off */ /* Complex object implementation */ /* Borrows heavily from floatobject.c */ diff --git a/third_party/python/Objects/descrobject.c b/third_party/python/Objects/descrobject.c index f8afd0459..10ce58f30 100644 --- a/third_party/python/Objects/descrobject.c +++ b/third_party/python/Objects/descrobject.c @@ -1,6 +1,17 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyhash.h" +#include "third_party/python/Include/pymacro.h" #include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/tupleobject.h" +#include "third_party/python/Include/unicodeobject.h" +/* clang-format off */ /* Descriptors -- a new, flexible way to describe attributes */ diff --git a/third_party/python/Objects/dict-common.h b/third_party/python/Objects/dict-common.h index 65789ef94..9d6dda1d4 100644 --- a/third_party/python/Objects/dict-common.h +++ b/third_party/python/Objects/dict-common.h @@ -1,5 +1,7 @@ #ifndef Py_DICT_COMMON_H #define Py_DICT_COMMON_H +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/object.h" /* clang-format off */ typedef struct { diff --git a/third_party/python/Objects/dictobject.c b/third_party/python/Objects/dictobject.c index d4e501d9d..4fddcf418 100644 --- a/third_party/python/Objects/dictobject.c +++ b/third_party/python/Objects/dictobject.c @@ -1,4 +1,16 @@ +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pystate.h" +#include "third_party/python/Include/setobject.h" +#include "third_party/python/Include/unicodeobject.h" +#include "third_party/python/Objects/dict-common.h" +#include "third_party/python/pyconfig.h" /* clang-format off */ + /* Dictionary object implementation using a hash table */ /* The distribution includes a separate file, Objects/dictnotes.txt, @@ -110,9 +122,7 @@ converting the dict to the combined table. */ #define PyDict_MINSIZE 8 -#include "third_party/python/Include/Python.h" -#include "third_party/python/Objects/dict-common.h" -#include "third_party/python/Objects/stringlib/eq.inc" /* to get unicode_eq() */ +#include "third_party/python/Objects/stringlib/eq.inc" /*[clinic input] class dict "PyDictObject *" "&PyDict_Type" @@ -549,7 +559,7 @@ static PyDictKeysObject *new_keys_object(Py_ssize_t size) dk->dk_lookup = lookdict_unicode_nodummy; dk->dk_nentries = 0; memset(&dk->dk_indices[0], 0xff, es * size); - memset(DK_ENTRIES(dk), 0, sizeof(PyDictKeyEntry) * usable); + bzero(DK_ENTRIES(dk), sizeof(PyDictKeyEntry) * usable); return dk; } diff --git a/third_party/python/Objects/enumobject.c b/third_party/python/Objects/enumobject.c index 7dd989cc3..e15038a04 100644 --- a/third_party/python/Objects/enumobject.c +++ b/third_party/python/Objects/enumobject.c @@ -1,7 +1,16 @@ +#include "libc/assert.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/enumobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/methodobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" /* clang-format off */ -/* enumerate object */ -#include "third_party/python/Include/Python.h" +/* enumerate object */ typedef struct { PyObject_HEAD diff --git a/third_party/python/Objects/exceptions.c b/third_party/python/Objects/exceptions.c index 502688f35..467dc0dce 100644 --- a/third_party/python/Objects/exceptions.c +++ b/third_party/python/Objects/exceptions.c @@ -1,3 +1,18 @@ +#define PY_SSIZE_T_CLEAN +#include "libc/errno.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/osdefs.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/traceback.h" +#include "third_party/python/Include/tupleobject.h" /* clang-format off */ /* * New exceptions.c written in Iceland by Richard Jones and Georg Brandl. @@ -5,12 +20,6 @@ * Thanks go to Tim Peters and Michael Hudson for debugging. */ -#define PY_SSIZE_T_CLEAN -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" -#include "third_party/python/Include/osdefs.h" - - /* Compatibility aliases */ PyObject *PyExc_EnvironmentError = NULL; PyObject *PyExc_IOError = NULL; @@ -771,10 +780,6 @@ MiddlingExtendsException(PyExc_ImportError, ModuleNotFoundError, ImportError, * OSError extends Exception */ -#ifdef MS_WINDOWS -#include "errmap.h" -#endif - /* Where a function has a single filename, such as open() or some * of the os module functions, PyErr_SetFromErrnoWithFilename() is * called, giving a third argument which is the filename. But, so diff --git a/third_party/python/Objects/fileobject.c b/third_party/python/Objects/fileobject.c index 78e2e6b99..ebb053082 100644 --- a/third_party/python/Objects/fileobject.c +++ b/third_party/python/Objects/fileobject.c @@ -1,9 +1,25 @@ -/* clang-format off */ -/* File object implementation (what's left of it -- see io.py) */ - #define PY_SSIZE_T_CLEAN -#include "third_party/python/Include/Python.h" +#include "libc/calls/calls.h" +#include "libc/errno.h" #include "libc/stdio/unlocked.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/fileobject.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/tupleobject.h" +#include "third_party/python/Include/unicodeobject.h" +/* clang-format off */ + +/* File object implementation (what's left of it -- see io.py) */ #if defined(HAVE_GETC_UNLOCKED) && !defined(_Py_MEMORY_SANITIZER) /* clang MemorySanitizer doesn't yet understand getc_unlocked. */ @@ -35,8 +51,8 @@ PyFile_FromFd(int fd, const char *name, const char *mode, int buffering, const c if (io == NULL) return NULL; stream = _PyObject_CallMethodId(io, &PyId_open, "isisssi", fd, mode, - buffering, encoding, errors, - newline, closefd); + buffering, encoding, errors, + newline, closefd); Py_DECREF(io); if (stream == NULL) return NULL; diff --git a/third_party/python/Objects/floatobject.c b/third_party/python/Objects/floatobject.c index 6a6e5ff08..8d6763005 100644 --- a/third_party/python/Objects/floatobject.c +++ b/third_party/python/Objects/floatobject.c @@ -1,12 +1,35 @@ +#include "libc/errno.h" +#include "libc/fmt/conv.h" +#include "libc/math.h" +#include "libc/runtime/fenv.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/bytearrayobject.h" +#include "third_party/python/Include/codecs.h" +#include "third_party/python/Include/complexobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dtoa.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyctype.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pyfpe.h" +#include "third_party/python/Include/pyhash.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymath.h" +#include "third_party/python/Include/pystrtod.h" +#include "third_party/python/Include/structseq.h" +#include "third_party/python/Include/warnings.h" /* clang-format off */ + /* Float object implementation */ /* XXX There should be overflow checks here, but it's hard to check for any kind of float exception without losing portability. */ -#include "third_party/python/Include/Python.h" -#include "libc/runtime/fenv.h" - /* Special free list free_list is a singly-linked list of available PyFloatObjects, linked via abuse of their ob_type members. diff --git a/third_party/python/Objects/frameobject.c b/third_party/python/Objects/frameobject.c index 0ce969fd2..a757fb48c 100644 --- a/third_party/python/Objects/frameobject.c +++ b/third_party/python/Objects/frameobject.c @@ -1,11 +1,20 @@ -/* clang-format off */ -/* Frame object implementation */ - -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/cellobject.h" #include "third_party/python/Include/code.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" #include "third_party/python/Include/frameobject.h" +#include "third_party/python/Include/genobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/objimpl.h" #include "third_party/python/Include/opcode.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" #include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/tupleobject.h" +/* clang-format off */ + +/* Frame object implementation */ #define OFF(x) offsetof(PyFrameObject, x) diff --git a/third_party/python/Objects/funcobject.c b/third_party/python/Objects/funcobject.c index ee6e5053d..c11a6829e 100644 --- a/third_party/python/Objects/funcobject.c +++ b/third_party/python/Objects/funcobject.c @@ -1,11 +1,21 @@ +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/cellobject.h" +#include "third_party/python/Include/classobject.h" +#include "third_party/python/Include/code.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/eval.h" +#include "third_party/python/Include/funcobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/unicodeobject.h" /* clang-format off */ /* Function object implementation */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/code.h" -#include "third_party/python/Include/structmember.h" - PyObject * PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname) { diff --git a/third_party/python/Objects/genobject.c b/third_party/python/Objects/genobject.c index 72ed18347..ccb17025f 100644 --- a/third_party/python/Objects/genobject.c +++ b/third_party/python/Objects/genobject.c @@ -1,11 +1,20 @@ +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/frameobject.h" +#include "third_party/python/Include/genobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/opcode.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/traceback.h" +#include "third_party/python/Include/warnings.h" /* clang-format off */ /* Generator object implementation */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/frameobject.h" -#include "third_party/python/Include/structmember.h" -#include "third_party/python/Include/opcode.h" - static PyObject *gen_close(PyGenObject *, PyObject *); static PyObject *async_gen_asend_new(PyAsyncGenObject *, PyObject *); static PyObject *async_gen_athrow_new(PyAsyncGenObject *, PyObject *); diff --git a/third_party/python/Objects/iterobject.c b/third_party/python/Objects/iterobject.c index 18506ca85..a4820ddcf 100644 --- a/third_party/python/Objects/iterobject.c +++ b/third_party/python/Objects/iterobject.c @@ -1,8 +1,14 @@ +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/iterobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" /* clang-format off */ /* Iterator objects */ -#include "third_party/python/Include/Python.h" - typedef struct { PyObject_HEAD Py_ssize_t it_index; diff --git a/third_party/python/Objects/listobject.c b/third_party/python/Objects/listobject.c index b5e9eecfa..3eaaad27e 100644 --- a/third_party/python/Objects/listobject.c +++ b/third_party/python/Objects/listobject.c @@ -1,8 +1,21 @@ -/* clang-format off */ -/* List object implementation */ - -#include "third_party/python/Include/Python.h" +#include "libc/assert.h" +#include "third_party/python/Include/abstract.h" #include "third_party/python/Include/accu.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pystate.h" +#include "third_party/python/Include/sliceobject.h" +/* clang-format off */ + +/* List object implementation */ /* Ensure ob_item has room for at least newsize elements, and set * ob_size to newsize. If newsize > ob_size on entry, the content diff --git a/third_party/python/Objects/longobject.c b/third_party/python/Objects/longobject.c index 601c0c944..ff1195cc4 100644 --- a/third_party/python/Objects/longobject.c +++ b/third_party/python/Objects/longobject.c @@ -1,11 +1,28 @@ -/* clang-format off */ -/* Long (arbitrary precision) integer object implementation */ - -/* XXX The functional organization of this file is terrible */ - -#include "third_party/python/Include/Python.h" +#include "libc/assert.h" +#include "libc/fmt/conv.h" +#include "libc/limits.h" #include "libc/log/check.h" +#include "libc/math.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/bytearrayobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/floatobject.h" #include "third_party/python/Include/longintrepr.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyctype.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pyhash.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymath.h" +#include "third_party/python/Include/structseq.h" +#include "third_party/python/Include/tupleobject.h" +#include "third_party/python/Include/warnings.h" +/* clang-format off */ + +/* Long (arbitrary precision) integer object implementation */ +/* XXX The functional organization of this file is terrible */ #ifndef NSMALLPOSINTS #define NSMALLPOSINTS 257 @@ -3189,7 +3206,7 @@ x_mul(PyLongObject *a, PyLongObject *b) if (z == NULL) return NULL; - memset(z->ob_digit, 0, Py_SIZE(z) * sizeof(digit)); + bzero(z->ob_digit, Py_SIZE(z) * sizeof(digit)); if (a == b) { /* Efficient squaring per HAC, Algorithm 14.16: * http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf @@ -3401,9 +3418,7 @@ k_mul(PyLongObject *a, PyLongObject *b) /* Zero-out the digits higher than the ah*bh copy. */ i = Py_SIZE(ret) - 2*shift - Py_SIZE(t1); - if (i) - memset(ret->ob_digit + 2*shift + Py_SIZE(t1), 0, - i * sizeof(digit)); + if (i) bzero(ret->ob_digit + 2*shift + Py_SIZE(t1), i * sizeof(digit)); /* 3. t2 <- al*bl, and copy into the low digits. */ if ((t2 = k_mul(al, bl)) == NULL) { @@ -3416,8 +3431,7 @@ k_mul(PyLongObject *a, PyLongObject *b) /* Zero out remaining digits. */ i = 2*shift - Py_SIZE(t2); /* number of uninitialized digits */ - if (i) - memset(ret->ob_digit + Py_SIZE(t2), 0, i * sizeof(digit)); + if (i) bzero(ret->ob_digit + Py_SIZE(t2), i * sizeof(digit)); /* 4 & 5. Subtract ah*bh (t1) and al*bl (t2). We do al*bl first * because it's fresher in cache. @@ -3539,7 +3553,7 @@ k_lopsided_mul(PyLongObject *a, PyLongObject *b) ret = _PyLong_New(asize + bsize); if (ret == NULL) return NULL; - memset(ret->ob_digit, 0, Py_SIZE(ret) * sizeof(digit)); + bzero(ret->ob_digit, Py_SIZE(ret) * sizeof(digit)); /* Successive slices of b are copied into bslice. */ bslice = _PyLong_New(asize); diff --git a/third_party/python/Objects/memoryobject.c b/third_party/python/Objects/memoryobject.c index 1c9b4a9ba..4c8081dc6 100644 --- a/third_party/python/Objects/memoryobject.c +++ b/third_party/python/Objects/memoryobject.c @@ -1,9 +1,23 @@ -/* clang-format off */ -/* Memoryview object implementation */ - -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/memoryobject.h" +#include "third_party/python/Include/methodobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pyhash.h" +#include "third_party/python/Include/pymacro.h" #include "third_party/python/Include/pystrhex.h" +#include "third_party/python/Include/sliceobject.h" +/* clang-format off */ +/* Memoryview object implementation */ /****************************************************************************/ /* ManagedBuffer Object */ diff --git a/third_party/python/Objects/methodobject.c b/third_party/python/Objects/methodobject.c index f6eda3145..805c1bba8 100644 --- a/third_party/python/Objects/methodobject.c +++ b/third_party/python/Objects/methodobject.c @@ -1,10 +1,18 @@ +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/methodobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/moduleobject.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyhash.h" +#include "third_party/python/Include/structmember.h" /* clang-format off */ /* Method object implementation */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" - /* Free list for method objects to safe malloc/free overhead * The m_self element is used to chain the objects. */ @@ -17,7 +25,7 @@ static int numfree = 0; /* undefine macro trampoline to PyCFunction_NewEx */ #undef PyCFunction_New -PyAPI_FUNC(PyObject *) +PyObject * PyCFunction_New(PyMethodDef *ml, PyObject *self) { return PyCFunction_NewEx(ml, self, NULL); diff --git a/third_party/python/Objects/moduleobject.c b/third_party/python/Objects/moduleobject.c index c4bd9c33f..be61f5ce8 100644 --- a/third_party/python/Objects/moduleobject.c +++ b/third_party/python/Objects/moduleobject.c @@ -1,6 +1,18 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/moduleobject.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pgenheaders.h" +#include "third_party/python/Include/pydebug.h" +#include "third_party/python/Include/pystate.h" #include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/sysmodule.h" +#include "third_party/python/Include/unicodeobject.h" +#include "third_party/python/Include/warnings.h" +/* clang-format off */ static Py_ssize_t max_module_number; @@ -213,7 +225,7 @@ PyModule_Create2(struct PyModuleDef* module, int module_api_version) Py_DECREF(m); return NULL; } - memset(m->md_state, 0, module->m_size); + bzero(m->md_state, module->m_size); } if (module->m_methods != NULL) { @@ -388,7 +400,7 @@ PyModule_ExecDef(PyObject *module, PyModuleDef *def) PyErr_NoMemory(); return -1; } - memset(md->md_state, 0, def->m_size); + bzero(md->md_state, def->m_size); } } diff --git a/third_party/python/Objects/namespaceobject.c b/third_party/python/Objects/namespaceobject.c index a6a69a420..04ab8f8c0 100644 --- a/third_party/python/Objects/namespaceobject.c +++ b/third_party/python/Objects/namespaceobject.c @@ -1,6 +1,17 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" +#include "libc/assert.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/namespaceobject.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" #include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/unicodeobject.h" +/* clang-format off */ typedef struct { PyObject_HEAD diff --git a/third_party/python/Objects/object.c b/third_party/python/Objects/object.c index 794d79f8d..3a6afe500 100644 --- a/third_party/python/Objects/object.c +++ b/third_party/python/Objects/object.c @@ -1,6 +1,35 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/bytearrayobject.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/cellobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/classobject.h" +#include "third_party/python/Include/complexobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/enumobject.h" +#include "third_party/python/Include/fileobject.h" +#include "third_party/python/Include/floatobject.h" #include "third_party/python/Include/frameobject.h" +#include "third_party/python/Include/funcobject.h" +#include "third_party/python/Include/genobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/iterobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/memoryobject.h" +#include "third_party/python/Include/namespaceobject.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/odictobject.h" +#include "third_party/python/Include/pycapsule.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/rangeobject.h" +#include "third_party/python/Include/setobject.h" +#include "third_party/python/Include/sliceobject.h" +#include "third_party/python/Include/traceback.h" +#include "third_party/python/Include/weakrefobject.h" +/* clang-format off */ _Py_IDENTIFIER(Py_Repr); _Py_IDENTIFIER(__bytes__); @@ -2060,7 +2089,7 @@ _PyTrash_thread_destroy_chain(void) /* For Py_LIMITED_API, we need an out-of-line version of _Py_Dealloc. Define this here, so we can undefine the macro. */ #undef _Py_Dealloc -PyAPI_FUNC(void) _Py_Dealloc(PyObject *); +void _Py_Dealloc(PyObject *); void _Py_Dealloc(PyObject *op) { diff --git a/third_party/python/Objects/obmalloc.c b/third_party/python/Objects/obmalloc.c index 6dabf64c0..8a3e5b71a 100644 --- a/third_party/python/Objects/obmalloc.c +++ b/third_party/python/Objects/obmalloc.c @@ -1,9 +1,14 @@ +#include "libc/assert.h" +#include "libc/calls/calls.h" +#include "libc/fmt/fmt.h" +#include "libc/sysv/consts/map.h" +#include "libc/sysv/consts/prot.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pydebug.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" /* clang-format off */ -#include "third_party/python/Include/Python.h" -#include "libc/sysv/consts/map.h" -#include "libc/sysv/consts/map.h" -#include "libc/sysv/consts/prot.h" -#include "libc/sysv/consts/prot.h" /* Defined in tracemalloc.c */ extern void _PyMem_DumpTraceback(int fd, const void *ptr); @@ -1272,7 +1277,7 @@ _PyObject_Alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize) if ((pool->freeblock = *(block **)bp) != NULL) { UNLOCK(); if (use_calloc) - memset(bp, 0, nbytes); + bzero(bp, nbytes); return (void *)bp; } /* @@ -1286,7 +1291,7 @@ _PyObject_Alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize) *(block **)(pool->freeblock) = NULL; UNLOCK(); if (use_calloc) - memset(bp, 0, nbytes); + bzero(bp, nbytes); return (void *)bp; } /* Pool is full, unlink from used pools. */ @@ -1296,7 +1301,7 @@ _PyObject_Alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize) pool->nextpool = next; UNLOCK(); if (use_calloc) - memset(bp, 0, nbytes); + bzero(bp, nbytes); return (void *)bp; } @@ -1377,7 +1382,7 @@ _PyObject_Alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize) pool->freeblock = *(block **)bp; UNLOCK(); if (use_calloc) - memset(bp, 0, nbytes); + bzero(bp, nbytes); return (void *)bp; } /* @@ -1394,7 +1399,7 @@ _PyObject_Alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize) *(block **)(pool->freeblock) = NULL; UNLOCK(); if (use_calloc) - memset(bp, 0, nbytes); + bzero(bp, nbytes); return (void *)bp; } diff --git a/third_party/python/Objects/odictobject.c b/third_party/python/Objects/odictobject.c index 4cc308156..452bdb5fb 100644 --- a/third_party/python/Objects/odictobject.c +++ b/third_party/python/Objects/odictobject.c @@ -1,4 +1,20 @@ +#include "libc/assert.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/odictobject.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pystate.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/tupleobject.h" +#include "third_party/python/Objects/dict-common.h" /* clang-format off */ + /* Ordered Dictionary object implementation. This implementation is necessarily explicitly equivalent to the pure Python @@ -465,10 +481,6 @@ later: */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/structmember.h" -#include "third_party/python/Objects/dict-common.h" - typedef struct _odictnode _ODictNode; /* PyODictObject */ diff --git a/third_party/python/Objects/rangeobject.c b/third_party/python/Objects/rangeobject.c index 0e5d29a1f..2517767a6 100644 --- a/third_party/python/Objects/rangeobject.c +++ b/third_party/python/Objects/rangeobject.c @@ -1,6 +1,14 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/rangeobject.h" +#include "third_party/python/Include/sliceobject.h" #include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/warnings.h" +/* clang-format off */ /* Support objects whose length is > PY_SSIZE_T_MAX. diff --git a/third_party/python/Objects/setobject.c b/third_party/python/Objects/setobject.c index c8b89e1f1..149723713 100644 --- a/third_party/python/Objects/setobject.c +++ b/third_party/python/Objects/setobject.c @@ -1,6 +1,17 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" +#include "libc/assert.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pystate.h" +#include "third_party/python/Include/setobject.h" #include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/unicodeobject.h" +/* clang-format off */ /* set object implementation @@ -345,7 +356,7 @@ set_table_resize(PySetObject *so, Py_ssize_t minused) /* Make the set empty, using the new table. */ assert(newtable != oldtable); - memset(newtable, 0, sizeof(setentry) * newsize); + bzero(newtable, sizeof(setentry) * newsize); so->fill = oldused; so->used = oldused; so->mask = newsize - 1; @@ -451,7 +462,7 @@ set_discard_key(PySetObject *so, PyObject *key) static void set_empty_to_minsize(PySetObject *so) { - memset(so->smalltable, 0, sizeof(so->smalltable)); + bzero(so->smalltable, sizeof(so->smalltable)); so->fill = 0; so->used = 0; so->mask = PySet_MINSIZE - 1; diff --git a/third_party/python/Objects/sliceobject.c b/third_party/python/Objects/sliceobject.c index 15e494e9b..ea126d04b 100644 --- a/third_party/python/Objects/sliceobject.c +++ b/third_party/python/Objects/sliceobject.c @@ -1,6 +1,17 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/methodobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/sliceobject.h" #include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/tupleobject.h" +#include "third_party/python/Include/unicodeobject.h" +/* clang-format off */ /* Written by Jim Hugunin and Chris Chase. diff --git a/third_party/python/Objects/stringlib/find.inc b/third_party/python/Objects/stringlib/find.inc index 68ba2ce7a..3ddee1636 100644 --- a/third_party/python/Objects/stringlib/find.inc +++ b/third_party/python/Objects/stringlib/find.inc @@ -1,5 +1,6 @@ /* clang-format off */ /* stringlib: find/index implementation */ +#include "third_party/python/Include/modsupport.h" #ifndef STRINGLIB_FASTSEARCH_H #error must include fastsearch.inc before including this module diff --git a/third_party/python/Objects/structseq.c b/third_party/python/Objects/structseq.c index 46af9fc57..904214300 100644 --- a/third_party/python/Objects/structseq.c +++ b/third_party/python/Objects/structseq.c @@ -1,6 +1,11 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" #include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/structseq.h" +/* clang-format off */ /* Implementation helper: a struct that looks like a tuple. See timemodule and posixmodule for example uses. */ diff --git a/third_party/python/Objects/tupleobject.c b/third_party/python/Objects/tupleobject.c index da1740c14..f9006ca67 100644 --- a/third_party/python/Objects/tupleobject.c +++ b/third_party/python/Objects/tupleobject.c @@ -1,6 +1,17 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/abstract.h" #include "third_party/python/Include/accu.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pyhash.h" +#include "third_party/python/Include/pystate.h" +#include "third_party/python/Include/sliceobject.h" +#include "third_party/python/Include/tupleobject.h" +/* clang-format off */ /* Tuple object implementation */ @@ -882,8 +893,8 @@ _PyTuple_Resize(PyObject **pv, Py_ssize_t newsize) _Py_NewReference((PyObject *) sv); /* Zero out items added by growing */ if (newsize > oldsize) - memset(&sv->ob_item[oldsize], 0, - sizeof(*sv->ob_item) * (newsize - oldsize)); + bzero(&sv->ob_item[oldsize], + sizeof(*sv->ob_item) * (newsize - oldsize)); *pv = (PyObject *) sv; _PyObject_GC_TRACK(sv); return 0; diff --git a/third_party/python/Objects/typeobject.c b/third_party/python/Objects/typeobject.c index ee6ba23b2..36e19c135 100644 --- a/third_party/python/Objects/typeobject.c +++ b/third_party/python/Objects/typeobject.c @@ -1,7 +1,29 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" +#include "libc/assert.h" +#include "libc/fmt/fmt.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/cellobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/compile.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" #include "third_party/python/Include/frameobject.h" +#include "third_party/python/Include/funcobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/iterobject.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pyhash.h" #include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/tupleobject.h" +#include "third_party/python/Include/typeslots.h" +#include "third_party/python/Include/unicodeobject.h" +#include "third_party/python/Include/warnings.h" +#include "third_party/python/Include/weakrefobject.h" +/* clang-format off */ /* Type object implementation */ diff --git a/third_party/python/Objects/unicodectype.c b/third_party/python/Objects/unicodectype.c index a1d31e346..e7de2e615 100644 --- a/third_party/python/Objects/unicodectype.c +++ b/third_party/python/Objects/unicodectype.c @@ -1,5 +1,5 @@ +#include "third_party/python/Include/unicodeobject.h" /* clang-format off */ -#include "third_party/python/Include/Python.h" /* Unicode character type helpers. diff --git a/third_party/python/Objects/unicodeobject.c b/third_party/python/Objects/unicodeobject.c index 3e423076b..fd2731a11 100644 --- a/third_party/python/Objects/unicodeobject.c +++ b/third_party/python/Objects/unicodeobject.c @@ -1,9 +1,39 @@ -/* clang-format off */ #define PY_SSIZE_T_CLEAN -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/ucnhash.h" +#include "libc/assert.h" +#include "libc/errno.h" +#include "libc/fmt/fmt.h" +#include "libc/str/str.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/bytearrayobject.h" #include "third_party/python/Include/bytes_methods.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/codecs.h" +#include "third_party/python/Include/complexobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/fileobject.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/memoryobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/osmodule.h" +#include "third_party/python/Include/pycapsule.h" +#include "third_party/python/Include/pyctype.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pyhash.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pystrtod.h" +#include "third_party/python/Include/sliceobject.h" +#include "third_party/python/Include/tupleobject.h" +#include "third_party/python/Include/ucnhash.h" +#include "third_party/python/Include/unicodeobject.h" +#include "third_party/python/Include/warnings.h" #include "third_party/python/Objects/stringlib/eq.inc" +/* clang-format off */ /* @@ -2620,10 +2650,10 @@ unicode_fromformat_arg(_PyUnicodeWriter *writer, /* parse the width.precision part, e.g. "%2.5s" => width=2, precision=5 */ width = -1; - if (Py_ISDIGIT((unsigned)*f)) { + if (Py_ISDIGIT(*f)) { width = *f - '0'; f++; - while (Py_ISDIGIT((unsigned)*f)) { + while (Py_ISDIGIT(*f)) { if (width > (PY_SSIZE_T_MAX - ((int)*f - '0')) / 10) { PyErr_SetString(PyExc_ValueError, "width too big"); @@ -2636,10 +2666,10 @@ unicode_fromformat_arg(_PyUnicodeWriter *writer, precision = -1; if (*f == '.') { f++; - if (Py_ISDIGIT((unsigned)*f)) { + if (Py_ISDIGIT(*f)) { precision = (*f - '0'); f++; - while (Py_ISDIGIT((unsigned)*f)) { + while (Py_ISDIGIT(*f)) { if (precision > (PY_SSIZE_T_MAX - ((int)*f - '0')) / 10) { PyErr_SetString(PyExc_ValueError, "precision too big"); @@ -3753,7 +3783,7 @@ mbstowcs_errorpos(const char *str, size_t len) size_t converted; wchar_t ch; - memset(&mbs, 0, sizeof mbs); + bzero(&mbs, sizeof mbs); while (len) { converted = mbrtowc(&ch, str, len, &mbs); @@ -5007,33 +5037,6 @@ ascii_decode(const char *start, const char *end, Py_UCS1 *dest) * won't work; also, tests have shown that skipping the "optimised * version" will even speed up m68k. */ -#if !defined(__m68k__) -#if SIZEOF_LONG <= SIZEOF_VOID_P - assert(_Py_IS_ALIGNED(dest, SIZEOF_LONG)); - if (_Py_IS_ALIGNED(p, SIZEOF_LONG)) { - /* Fast path, see in STRINGLIB(utf8_decode) for - an explanation. */ - /* Help allocation */ - const char *_p = p; - Py_UCS1 * q = dest; - while (_p < aligned_end) { - unsigned long value = *(const unsigned long *) _p; - if (value & ASCII_CHAR_MASK) - break; - *((unsigned long *)q) = value; - _p += SIZEOF_LONG; - q += SIZEOF_LONG; - } - p = _p; - while (p < end) { - if ((unsigned char)*p & 0x80) - break; - *q++ = *p++; - } - return p - start; - } -#endif -#endif while (p < end) { /* Fast path, see in STRINGLIB(utf8_decode) in stringlib/codecs.h for an explanation. */ @@ -5192,8 +5195,6 @@ onError: return NULL; } -#if defined(__APPLE__) || defined(__ANDROID__) - /* Simplified UTF-8 decoder using surrogateescape error handler, used to decode the command line arguments on Mac OS X and Android. @@ -5246,8 +5247,6 @@ _Py_DecodeUTF8_surrogateescape(const char *s, Py_ssize_t size) return unicode; } -#endif /* __APPLE__ or __ANDROID__ */ - /* Primary internal function which creates utf8 encoded bytes objects. Allocation strategy: if the string is short, convert into a stack buffer @@ -8312,7 +8311,7 @@ PyUnicode_BuildEncodingMap(PyObject* string) mlevel3 = mresult->level23 + 16*count2; memcpy(mlevel1, level1, 32); memset(mlevel2, 0xFF, 16*count2); - memset(mlevel3, 0, 128*count3); + bzero(mlevel3, 128*count3); count3 = 0; for (i = 1; i < length; i++) { int o1, o2, o3, i2, i3; @@ -13583,7 +13582,7 @@ _PyUnicodeWriter_Update(_PyUnicodeWriter *writer) void _PyUnicodeWriter_Init(_PyUnicodeWriter *writer) { - memset(writer, 0, sizeof(*writer)); + bzero(writer, sizeof(*writer)); /* ASCII is the bare minimum */ writer->min_char = 127; diff --git a/third_party/python/Objects/weakrefobject.c b/third_party/python/Objects/weakrefobject.c index b945bb0e3..8b7ea473f 100644 --- a/third_party/python/Objects/weakrefobject.c +++ b/third_party/python/Objects/weakrefobject.c @@ -1,6 +1,12 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" #include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/weakrefobject.h" +#include "third_party/quickjs/quickjs.h" +/* clang-format off */ #define GET_WEAKREFS_LISTPTR(o) \ ((PyWeakReference **) PyObject_GET_WEAKREFS_LISTPTR(o)) diff --git a/third_party/python/PC/config.c b/third_party/python/PC/config.c deleted file mode 100644 index 3b41861c3..000000000 --- a/third_party/python/PC/config.c +++ /dev/null @@ -1,171 +0,0 @@ -/* clang-format off */ -/* Module configuration */ - -/* This file contains the table of built-in modules. - See create_builtin() in import.c. */ - -#include "third_party/python/Include/Python.h" - -extern PyObject* PyInit_array(void); -#ifndef MS_WINI64 -extern PyObject* PyInit_audioop(void); -#endif -extern PyObject* PyInit_binascii(void); -extern PyObject* PyInit_cmath(void); -extern PyObject* PyInit_errno(void); -extern PyObject* PyInit_faulthandler(void); -extern PyObject* PyInit__tracemalloc(void); -extern PyObject* PyInit_gc(void); -extern PyObject* PyInit_math(void); -extern PyObject* PyInit__md5(void); -extern PyObject* PyInit_nt(void); -extern PyObject* PyInit__operator(void); -extern PyObject* PyInit__signal(void); -extern PyObject* PyInit__sha1(void); -extern PyObject* PyInit__sha256(void); -extern PyObject* PyInit__sha512(void); -extern PyObject* PyInit__sha3(void); -extern PyObject* PyInit__blake2(void); -extern PyObject* PyInit_time(void); -extern PyObject* PyInit__thread(void); -#ifdef WIN32 -extern PyObject* PyInit_msvcrt(void); -extern PyObject* PyInit__locale(void); -#endif -extern PyObject* PyInit__codecs(void); -extern PyObject* PyInit__weakref(void); -extern PyObject* PyInit_xxsubtype(void); -extern PyObject* PyInit_zipimport(void); -extern PyObject* PyInit__random(void); -extern PyObject* PyInit_itertools(void); -extern PyObject* PyInit__collections(void); -extern PyObject* PyInit__heapq(void); -extern PyObject* PyInit__bisect(void); -extern PyObject* PyInit__symtable(void); -extern PyObject* PyInit_mmap(void); -extern PyObject* PyInit__csv(void); -extern PyObject* PyInit__sre(void); -extern PyObject* PyInit_parser(void); -extern PyObject* PyInit_winreg(void); -extern PyObject* PyInit__struct(void); -extern PyObject* PyInit__datetime(void); -extern PyObject* PyInit__functools(void); -extern PyObject* PyInit__json(void); -extern PyObject* PyInit_zlib(void); - -extern PyObject* PyInit__multibytecodec(void); -extern PyObject* PyInit__codecs_cn(void); -extern PyObject* PyInit__codecs_hk(void); -extern PyObject* PyInit__codecs_iso2022(void); -extern PyObject* PyInit__codecs_jp(void); -extern PyObject* PyInit__codecs_kr(void); -extern PyObject* PyInit__codecs_tw(void); -extern PyObject* PyInit__winapi(void); -extern PyObject* PyInit__lsprof(void); -extern PyObject* PyInit__ast(void); -extern PyObject* PyInit__io(void); -extern PyObject* PyInit__pickle(void); -extern PyObject* PyInit_atexit(void); -extern PyObject* _PyWarnings_Init(void); -extern PyObject* PyInit__string(void); -extern PyObject* PyInit__stat(void); -extern PyObject* PyInit__opcode(void); - -/* tools/freeze/makeconfig.py marker for additional "extern" */ -/* -- ADDMODULE MARKER 1 -- */ - -extern PyObject* PyMarshal_Init(void); -extern PyObject* PyInit_imp(void); - -struct _inittab _PyImport_Inittab[] = { - - {"array", PyInit_array}, - {"_ast", PyInit__ast}, -#ifdef MS_WINDOWS -#ifndef MS_WINI64 - {"audioop", PyInit_audioop}, -#endif -#endif - {"binascii", PyInit_binascii}, - {"cmath", PyInit_cmath}, - {"errno", PyInit_errno}, - {"faulthandler", PyInit_faulthandler}, - {"gc", PyInit_gc}, - {"math", PyInit_math}, - {"nt", PyInit_nt}, /* Use the NT os functions, not posix */ - {"_operator", PyInit__operator}, - {"_signal", PyInit__signal}, - {"_md5", PyInit__md5}, - {"_sha1", PyInit__sha1}, - {"_sha256", PyInit__sha256}, - {"_sha512", PyInit__sha512}, - {"_sha3", PyInit__sha3}, - {"_blake2", PyInit__blake2}, - {"time", PyInit_time}, -#ifdef WITH_THREAD - {"_thread", PyInit__thread}, -#endif -#ifdef WIN32 - {"msvcrt", PyInit_msvcrt}, - {"_locale", PyInit__locale}, -#endif - {"_tracemalloc", PyInit__tracemalloc}, - /* XXX Should _winapi go in a WIN32 block? not WIN64? */ - {"_winapi", PyInit__winapi}, - - {"_codecs", PyInit__codecs}, - {"_weakref", PyInit__weakref}, - {"_random", PyInit__random}, - {"_bisect", PyInit__bisect}, - {"_heapq", PyInit__heapq}, - {"_lsprof", PyInit__lsprof}, - {"itertools", PyInit_itertools}, - {"_collections", PyInit__collections}, - {"_symtable", PyInit__symtable}, - {"mmap", PyInit_mmap}, - {"_csv", PyInit__csv}, - {"_sre", PyInit__sre}, - {"parser", PyInit_parser}, - {"winreg", PyInit_winreg}, - {"_struct", PyInit__struct}, - {"_datetime", PyInit__datetime}, - {"_functools", PyInit__functools}, - {"_json", PyInit__json}, - - {"xxsubtype", PyInit_xxsubtype}, - {"zipimport", PyInit_zipimport}, - {"zlib", PyInit_zlib}, - - /* CJK codecs */ - {"_multibytecodec", PyInit__multibytecodec}, - {"_codecs_cn", PyInit__codecs_cn}, - {"_codecs_hk", PyInit__codecs_hk}, - {"_codecs_iso2022", PyInit__codecs_iso2022}, - {"_codecs_jp", PyInit__codecs_jp}, - {"_codecs_kr", PyInit__codecs_kr}, - {"_codecs_tw", PyInit__codecs_tw}, - -/* tools/freeze/makeconfig.py marker for additional "_inittab" entries */ -/* -- ADDMODULE MARKER 2 -- */ - - /* This module "lives in" with marshal.c */ - {"marshal", PyMarshal_Init}, - - /* This lives it with import.c */ - {"_imp", PyInit_imp}, - - /* These entries are here for sys.builtin_module_names */ - {"builtins", NULL}, - {"sys", NULL}, - {"_warnings", _PyWarnings_Init}, - {"_string", PyInit__string}, - - {"_io", PyInit__io}, - {"_pickle", PyInit__pickle}, - {"atexit", PyInit_atexit}, - {"_stat", PyInit__stat}, - {"_opcode", PyInit__opcode}, - - /* Sentinel */ - {0, 0} -}; diff --git a/third_party/python/PC/getpathp.c b/third_party/python/PC/getpathp.c index 5ee54a7d7..ca9ba321a 100644 --- a/third_party/python/PC/getpathp.c +++ b/third_party/python/PC/getpathp.c @@ -1,3 +1,4 @@ +/* clang-format off */ #include "windows.h" /* Return the initial module search path. */ @@ -79,28 +80,10 @@ ---------------------------------------------------------------- */ -#include - -#include "Python.h" -#include "osdefs.h" - #ifndef MS_WINDOWS #error getpathp.c should only be built on Windows #endif -#include -#include - -#ifdef HAVE_SYS_TYPES_H -#include -#endif /* HAVE_SYS_TYPES_H */ - -#ifdef HAVE_SYS_STAT_H -#include -#endif /* HAVE_SYS_STAT_H */ - -#include - /* Search in some common locations for the associated Python libraries. * * Py_GetPath() tries to return a sensible Python module search path. @@ -375,7 +358,7 @@ static wchar_t *getpythonregpath(HKEY keyBase, int skipcore) { */ ppPaths = PyMem_RawMalloc(sizeof(WCHAR *) * numKeys); if (ppPaths == NULL) goto done; - memset(ppPaths, 0, sizeof(WCHAR *) * numKeys); + bzero(ppPaths, sizeof(WCHAR *) * numKeys); /* Loop over all subkeys, allocating a temp sub-buffer. */ for (index = 0; index < numKeys; index++) { WCHAR keyBuf[MAX_PATH + 1]; diff --git a/third_party/python/PC/launcher.c b/third_party/python/PC/launcher.c index a577587ee..c34a58b93 100644 --- a/third_party/python/PC/launcher.c +++ b/third_party/python/PC/launcher.c @@ -632,7 +632,7 @@ run_child(wchar_t * cmdline) sizeof(info)); if (!ok) error(RC_CREATE_PROCESS, L"Job information setting failed"); - memset(&si, 0, sizeof(si)); + bzero(&si, sizeof(si)); si.cb = sizeof(si); ok = safe_duplicate_handle(GetStdHandle(STD_INPUT_HANDLE), &si.hStdInput); if (!ok) diff --git a/third_party/python/PC/winreg.c b/third_party/python/PC/winreg.c index 73ace93b4..6cd0b586c 100644 --- a/third_party/python/PC/winreg.c +++ b/third_party/python/PC/winreg.c @@ -14,6 +14,7 @@ */ #include "third_party/python/Include/Python.h" +#include "third_party/python/Include/pyerrors.h" #include "third_party/python/Include/structmember.h" static BOOL PyHKEY_AsHKEY(PyObject *ob, HKEY *pRes, BOOL bNoneOK); diff --git a/third_party/python/Parser/acceler.c b/third_party/python/Parser/acceler.c index fe22240ea..3b0c943e3 100644 --- a/third_party/python/Parser/acceler.c +++ b/third_party/python/Parser/acceler.c @@ -1,3 +1,9 @@ +#include "third_party/python/Include/grammar.h" +#include "third_party/python/Include/node.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pgenheaders.h" +#include "third_party/python/Include/token.h" +#include "third_party/python/Parser/parser.h" /* clang-format off */ /* Parser accelerator module */ @@ -10,12 +16,6 @@ are not part of the static data structure written on graminit.[ch] by the parser generator. */ -#include "third_party/python/Include/pgenheaders.h" -#include "third_party/python/Include/grammar.h" -#include "third_party/python/Include/node.h" -#include "third_party/python/Include/token.h" -#include "third_party/python/Parser/parser.h" - /* Forward references */ static void fixdfa(grammar *, dfa *); static void fixstate(grammar *, state *); diff --git a/third_party/python/Parser/bitset.c b/third_party/python/Parser/bitset.c index a820cda78..242b27d7c 100644 --- a/third_party/python/Parser/bitset.c +++ b/third_party/python/Parser/bitset.c @@ -1,10 +1,9 @@ +#include "third_party/python/Include/bitset.h" +#include "third_party/python/Include/objimpl.h" /* clang-format off */ /* Bitset primitives used by the parser generator */ -#include "third_party/python/Include/pgenheaders.h" -#include "third_party/python/Include/bitset.h" - bitset newbitset(int nbits) { diff --git a/third_party/python/Parser/firstsets.c b/third_party/python/Parser/firstsets.c index f361cb5ec..af246f85a 100644 --- a/third_party/python/Parser/firstsets.c +++ b/third_party/python/Parser/firstsets.c @@ -1,11 +1,12 @@ +#include "third_party/python/Include/bitset.h" +#include "third_party/python/Include/grammar.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pgenheaders.h" +#include "third_party/python/Include/token.h" /* clang-format off */ /* Computation of FIRST stets */ -#include "third_party/python/Include/pgenheaders.h" -#include "third_party/python/Include/grammar.h" -#include "third_party/python/Include/token.h" - extern int Py_DebugFlag; /* Forward */ diff --git a/third_party/python/Parser/grammar.c b/third_party/python/Parser/grammar.c index 18acc28e0..8055c46c0 100644 --- a/third_party/python/Parser/grammar.c +++ b/third_party/python/Parser/grammar.c @@ -1,12 +1,12 @@ +#include "third_party/python/Include/grammar.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pgenheaders.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/token.h" /* clang-format off */ /* Grammar implementation */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/pgenheaders.h" -#include "third_party/python/Include/token.h" -#include "third_party/python/Include/grammar.h" - extern int Py_DebugFlag; grammar * diff --git a/third_party/python/Parser/grammar1.c b/third_party/python/Parser/grammar1.c index 3f97b4334..6b122d5bc 100644 --- a/third_party/python/Parser/grammar1.c +++ b/third_party/python/Parser/grammar1.c @@ -1,12 +1,11 @@ +#include "libc/assert.h" +#include "third_party/python/Include/grammar.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/token.h" /* clang-format off */ /* Grammar subroutines needed by parser */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/pgenheaders.h" -#include "third_party/python/Include/grammar.h" -#include "third_party/python/Include/token.h" - /* Return the DFA for the given type */ dfa * diff --git a/third_party/python/Parser/listnode.c b/third_party/python/Parser/listnode.c index 62047af71..b4e6484bc 100644 --- a/third_party/python/Parser/listnode.c +++ b/third_party/python/Parser/listnode.c @@ -1,11 +1,11 @@ +#include "libc/stdio/stdio.h" +#include "third_party/python/Include/node.h" +#include "third_party/python/Include/pgenheaders.h" +#include "third_party/python/Include/token.h" /* clang-format off */ /* List a node on a file */ -#include "third_party/python/Include/pgenheaders.h" -#include "third_party/python/Include/token.h" -#include "third_party/python/Include/node.h" - /* Forward */ static void list1node(FILE *, node *); static void listnode(FILE *, node *); diff --git a/third_party/python/Parser/metagrammar.c b/third_party/python/Parser/metagrammar.c index 95e7172f4..bddc031ed 100644 --- a/third_party/python/Parser/metagrammar.c +++ b/third_party/python/Parser/metagrammar.c @@ -1,9 +1,8 @@ -/* clang-format off */ - -#include "third_party/python/Include/pgenheaders.h" -#include "third_party/python/Include/metagrammar.h" #include "third_party/python/Include/grammar.h" +#include "third_party/python/Include/metagrammar.h" #include "third_party/python/Include/pgen.h" +#include "third_party/python/Include/pgenheaders.h" +/* clang-format off */ static arc arcs_0_0[3] = { {2, 0}, diff --git a/third_party/python/Parser/myreadline.c b/third_party/python/Parser/myreadline.c index e91c4cba1..d3ca968a4 100644 --- a/third_party/python/Parser/myreadline.c +++ b/third_party/python/Parser/myreadline.c @@ -1,3 +1,12 @@ +#include "libc/calls/calls.h" +#include "libc/errno.h" +#include "libc/limits.h" +#include "libc/stdio/stdio.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/intrcheck.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pystate.h" /* clang-format off */ /* Readline interface for tokenizer.c and [raw_]input() in bltinmodule.c. @@ -10,8 +19,6 @@ - a malloc'ed string ending in \n normally */ -#include "third_party/python/Include/Python.h" - PyThreadState* _PyOS_ReadlineTState; #ifdef WITH_THREAD diff --git a/third_party/python/Parser/node.c b/third_party/python/Parser/node.c index 5749e856b..211628d60 100644 --- a/third_party/python/Parser/node.c +++ b/third_party/python/Parser/node.c @@ -1,12 +1,12 @@ +#include "libc/assert.h" +#include "libc/nexgen32e/bsr.h" +#include "third_party/python/Include/errcode.h" +#include "third_party/python/Include/node.h" +#include "third_party/python/Include/objimpl.h" /* clang-format off */ /* Parse tree node implementation */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/node.h" -#include "libc/nexgen32e/bsr.h" -#include "third_party/python/Include/errcode.h" - node * PyNode_New(int type) { diff --git a/third_party/python/Parser/parser.c b/third_party/python/Parser/parser.c index 99ef38f7e..88d450144 100644 --- a/third_party/python/Parser/parser.c +++ b/third_party/python/Parser/parser.c @@ -1,20 +1,17 @@ +#include "libc/assert.h" +#include "third_party/python/Include/errcode.h" +#include "third_party/python/Include/grammar.h" +#include "third_party/python/Include/node.h" +#include "third_party/python/Include/pgenheaders.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/token.h" +#include "third_party/python/Parser/parser.h" /* clang-format off */ /* Parser implementation */ - /* For a description, see the comments at end of this file */ - /* XXX To do: error recovery */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/pgenheaders.h" -#include "third_party/python/Include/token.h" -#include "third_party/python/Include/grammar.h" -#include "third_party/python/Include/node.h" -#include "third_party/python/Parser/parser.h" -#include "third_party/python/Include/errcode.h" - - #ifdef Py_DEBUG extern int Py_DebugFlag; #define D(x) if (!Py_DebugFlag); else x diff --git a/third_party/python/Parser/parser.h b/third_party/python/Parser/parser.h index 403236d1e..6ffe364e4 100644 --- a/third_party/python/Parser/parser.h +++ b/third_party/python/Parser/parser.h @@ -1,11 +1,9 @@ #ifndef Py_PARSER_H #define Py_PARSER_H -#ifdef __cplusplus -extern "C" { -#endif - - -/* Parser interface */ +#include "third_party/python/Include/grammar.h" +#include "third_party/python/Include/node.h" +COSMOPOLITAN_C_START_ +/* clang-format off */ #define MAXSTACK 1500 @@ -34,9 +32,6 @@ parser_state *PyParser_New(grammar *g, int start); void PyParser_Delete(parser_state *ps); int PyParser_AddToken(parser_state *ps, int type, char *str, int lineno, int col_offset, int *expected_ret); -void PyGrammar_AddAccelerators(grammar *g); -#ifdef __cplusplus -} -#endif +COSMOPOLITAN_C_END_ #endif /* !Py_PARSER_H */ diff --git a/third_party/python/Parser/parsetok.c b/third_party/python/Parser/parsetok.c index 03adfa267..a201c1321 100644 --- a/third_party/python/Parser/parsetok.c +++ b/third_party/python/Parser/parsetok.c @@ -1,17 +1,17 @@ +#include "third_party/python/Include/errcode.h" +#include "third_party/python/Include/graminit.h" +#include "third_party/python/Include/grammar.h" +#include "third_party/python/Include/node.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/parsetok.h" +#include "third_party/python/Include/pgenheaders.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Parser/parser.h" +#include "third_party/python/Parser/tokenizer.h" /* clang-format off */ /* Parser-tokenizer link implementation */ -#include "third_party/python/Include/pgenheaders.h" -#include "third_party/python/Parser/tokenizer.h" -#include "third_party/python/Include/node.h" -#include "third_party/python/Include/grammar.h" -#include "third_party/python/Parser/parser.h" -#include "third_party/python/Include/parsetok.h" -#include "third_party/python/Include/errcode.h" -#include "third_party/python/Include/graminit.h" - - /* Forward */ static node *parsetok(struct tok_state *, grammar *, int, perrdetail *, int *); static int initerr(perrdetail *err_ret, PyObject * filename); diff --git a/third_party/python/Parser/pgen.c b/third_party/python/Parser/pgen.c index 8b3e7a260..c3e06976c 100644 --- a/third_party/python/Parser/pgen.c +++ b/third_party/python/Parser/pgen.c @@ -1,21 +1,18 @@ +#include "third_party/python/Include/grammar.h" +#include "third_party/python/Include/metagrammar.h" +#include "third_party/python/Include/node.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pgen.h" +#include "third_party/python/Include/pgenheaders.h" +#include "third_party/python/Include/token.h" /* clang-format off */ /* Parser generator */ - /* For a description, see the comments at end of this file */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/pgenheaders.h" -#include "third_party/python/Include/token.h" -#include "third_party/python/Include/node.h" -#include "third_party/python/Include/grammar.h" -#include "third_party/python/Include/metagrammar.h" -#include "third_party/python/Include/pgen.h" - extern int Py_DebugFlag; extern int Py_IgnoreEnvironmentFlag; /* needed by Py_GETENV */ - /* PART ONE -- CONSTRUCT NFA -- Cf. Algorithm 3.2 from [Aho&Ullman 77] */ typedef struct _nfaarc { diff --git a/third_party/python/Parser/pgenmain.c b/third_party/python/Parser/pgenmain.c index 0a40b280d..f13de46d3 100644 --- a/third_party/python/Parser/pgenmain.c +++ b/third_party/python/Parser/pgenmain.c @@ -1,3 +1,13 @@ +#define PGEN +#include "libc/log/log.h" +#include "third_party/python/Include/grammar.h" +#include "third_party/python/Include/node.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/parsetok.h" +#include "third_party/python/Include/pgen.h" +#include "third_party/python/Include/pgenheaders.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymem.h" /* clang-format off */ /* Parser generator main program */ @@ -14,15 +24,6 @@ - check for duplicate definitions of names (instead of fatal err) */ -#define PGEN - -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/pgenheaders.h" -#include "third_party/python/Include/grammar.h" -#include "third_party/python/Include/node.h" -#include "third_party/python/Include/parsetok.h" -#include "third_party/python/Include/pgen.h" - int Py_DebugFlag; int Py_VerboseFlag; int Py_IgnoreEnvironmentFlag; @@ -176,9 +177,6 @@ Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj) return fgets(buf, n, stream); } - -#include - void PySys_WriteStderr(const char *format, ...) { diff --git a/third_party/python/Parser/printgrammar.c b/third_party/python/Parser/printgrammar.c index 2d697fbc5..dfb684e92 100644 --- a/third_party/python/Parser/printgrammar.c +++ b/third_party/python/Parser/printgrammar.c @@ -1,12 +1,10 @@ +#define PGEN +#include "third_party/python/Include/grammar.h" +#include "third_party/python/Include/pgenheaders.h" /* clang-format off */ /* Print a bunch of C initializers that represent a grammar */ -#define PGEN - -#include "third_party/python/Include/pgenheaders.h" -#include "third_party/python/Include/grammar.h" - /* Forward */ static void printarcs(int, dfa *, FILE *); static void printstates(grammar *, FILE *); diff --git a/third_party/python/Parser/tokenizer.c b/third_party/python/Parser/tokenizer.c index 326ffe784..b196277af 100644 --- a/third_party/python/Parser/tokenizer.c +++ b/third_party/python/Parser/tokenizer.c @@ -1,21 +1,28 @@ +#include "libc/calls/calls.h" +#include "third_party/python/Include/errcode.h" +#include "third_party/python/Include/pgenheaders.h" +#include "third_party/python/Parser/tokenizer.h" +#ifndef PGEN +#include "libc/calls/weirdtypes.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/bytearrayobject.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/codecs.h" +#include "third_party/python/Include/fileobject.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/pyctype.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/sysmodule.h" +#include "third_party/python/Include/unicodeobject.h" +#endif /* clang-format off */ /* Tokenizer implementation */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/pgenheaders.h" - -#include "third_party/python/Parser/tokenizer.h" -#include "third_party/python/Include/errcode.h" - -#ifndef PGEN -#include "third_party/python/Include/unicodeobject.h" -#include "third_party/python/Include/bytesobject.h" -#include "third_party/python/Include/fileobject.h" -#include "third_party/python/Include/codecs.h" -#include "third_party/python/Include/abstract.h" -#endif /* PGEN */ - #define is_potential_identifier_start(c) (\ (c >= 'a' && c <= 'z')\ || (c >= 'A' && c <= 'Z')\ diff --git a/third_party/python/Programs/_testembed.c b/third_party/python/Programs/_testembed.c index cbfcb79c7..9eaa4e183 100644 --- a/third_party/python/Programs/_testembed.c +++ b/third_party/python/Programs/_testembed.c @@ -1,5 +1,11 @@ -#include "libc/stdio.h" -#include "third_party/python/Include/Python.h" +#include "libc/stdio/stdio.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/patchlevel.h" +#include "third_party/python/Include/pylifecycle.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pystate.h" +#include "third_party/python/Include/pythonrun.h" #include "third_party/python/Include/pythread.h" /* clang-format off */ diff --git a/third_party/python/Programs/python.c b/third_party/python/Programs/python.c index abb074969..e5481e84f 100644 --- a/third_party/python/Programs/python.c +++ b/third_party/python/Programs/python.c @@ -1,8 +1,12 @@ -/* Minimal main program -- everything is loaded from the library */ +#include "libc/stdio/stdio.h" +#include "libc/unicode/locale.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/pylifecycle.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pyport.h" /* clang-format off */ -#include "third_party/python/Include/Python.h" -#include "libc/unicode/locale.h" +/* Minimal main program -- everything is loaded from the library */ int main(int argc, char **argv) diff --git a/third_party/python/Python/Python-ast.c b/third_party/python/Python/Python-ast.c index 87a1ae3d5..bec3305b7 100644 --- a/third_party/python/Python/Python-ast.c +++ b/third_party/python/Python/Python-ast.c @@ -1,8 +1,19 @@ -/* clang-format off */ -/* File automatically generated by Parser/asdl_c.py. */ - -#include "third_party/python/Include/Python.h" #include "third_party/python/Include/Python-ast.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pythonrun.h" +#include "third_party/python/Include/tupleobject.h" +/* clang-format off */ + +/* File automatically generated by Parser/asdl_c.py. */ static PyTypeObject AST_type; static PyTypeObject *mod_type; diff --git a/third_party/python/Python/_warnings.c b/third_party/python/Python/_warnings.c index 90da2e15b..569f288bb 100644 --- a/third_party/python/Python/_warnings.c +++ b/third_party/python/Python/_warnings.c @@ -1,6 +1,23 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/fileobject.h" #include "third_party/python/Include/frameobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyctype.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/pymacro.h" +#include "third_party/python/Include/sysmodule.h" +#include "third_party/python/Include/traceback.h" +#include "third_party/python/Include/tupleobject.h" +#include "third_party/python/Include/unicodeobject.h" +/* clang-format off */ #define MODULE_NAME "_warnings" @@ -1030,7 +1047,7 @@ PyErr_WarnEx(PyObject *category, const char *text, Py_ssize_t stack_level) #undef PyErr_Warn -PyAPI_FUNC(int) +int PyErr_Warn(PyObject *category, const char *text) { return PyErr_WarnEx(category, text, 1); diff --git a/third_party/python/Python/asdl.c b/third_party/python/Python/asdl.c index c22ce9fed..6c90bfa71 100644 --- a/third_party/python/Python/asdl.c +++ b/third_party/python/Python/asdl.c @@ -1,7 +1,6 @@ -/* clang-format off */ - -#include "third_party/python/Include/Python.h" #include "third_party/python/Include/asdl.h" +#include "third_party/python/Include/pyerrors.h" +/* clang-format off */ asdl_seq * _Py_asdl_seq_new(Py_ssize_t size, PyArena *arena) @@ -29,7 +28,7 @@ _Py_asdl_seq_new(Py_ssize_t size, PyArena *arena) PyErr_NoMemory(); return NULL; } - memset(seq, 0, n); + bzero(seq, n); seq->size = size; return seq; } @@ -60,7 +59,7 @@ _Py_asdl_int_seq_new(Py_ssize_t size, PyArena *arena) PyErr_NoMemory(); return NULL; } - memset(seq, 0, n); + bzero(seq, n); seq->size = size; return seq; } diff --git a/third_party/python/Python/ast.c b/third_party/python/Python/ast.c index a7b6133d5..4784c4050 100644 --- a/third_party/python/Python/ast.c +++ b/third_party/python/Python/ast.c @@ -1,13 +1,29 @@ #include "libc/assert.h" -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/node.h" -#include "third_party/python/Include/pyport.h" -#include "third_party/python/Include/pythonrun.h" -#include "third_party/python/Include/token.h" -/**/ +#include "libc/errno.h" +#include "libc/fmt/fmt.h" #include "third_party/python/Include/Python-ast.h" -/**/ +#include "third_party/python/Include/abstract.h" #include "third_party/python/Include/ast.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/compile.h" +#include "third_party/python/Include/complexobject.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/node.h" +#include "third_party/python/Include/pyctype.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pyport.h" +#include "third_party/python/Include/pystrtod.h" +#include "third_party/python/Include/pythonrun.h" +#include "third_party/python/Include/setobject.h" +#include "third_party/python/Include/sliceobject.h" +#include "third_party/python/Include/token.h" +#include "third_party/python/Include/tupleobject.h" +#include "third_party/python/Include/warnings.h" /* clang-format off */ static int validate_stmts(asdl_seq *); diff --git a/third_party/python/Python/bltinmodule.c b/third_party/python/Python/bltinmodule.c index 1d904ea36..c9dfa6945 100644 --- a/third_party/python/Python/bltinmodule.c +++ b/third_party/python/Python/bltinmodule.c @@ -1,14 +1,48 @@ +#include "libc/calls/calls.h" +#include "third_party/python/Include/Python-ast.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/asdl.h" +#include "third_party/python/Include/ast.h" +#include "third_party/python/Include/bltinmodule.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/bytearrayobject.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/cellobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/code.h" +#include "third_party/python/Include/compile.h" +#include "third_party/python/Include/complexobject.h" +#include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/enumobject.h" +#include "third_party/python/Include/eval.h" +#include "third_party/python/Include/fileobject.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/funcobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/iterobject.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/memoryobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/node.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pydebug.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pyfpe.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/rangeobject.h" +#include "third_party/python/Include/setobject.h" +#include "third_party/python/Include/sliceobject.h" +#include "third_party/python/Include/sysmodule.h" +#include "third_party/python/Include/tupleobject.h" +#include "third_party/python/Include/unicodeobject.h" +#include "third_party/python/Include/warnings.h" /* clang-format off */ /* Built-in functions */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/Python-ast.h" -#include "third_party/python/Include/node.h" -#include "third_party/python/Include/code.h" -#include "third_party/python/Include/asdl.h" -#include "third_party/python/Include/ast.h" - /* The default encoding used by the platform file system APIs Can remain NULL for all platforms that don't have such a concept diff --git a/third_party/python/Python/ceval.c b/third_party/python/Python/ceval.c index 6cc472286..b7577d544 100644 --- a/third_party/python/Python/ceval.c +++ b/third_party/python/Python/ceval.c @@ -1,3 +1,30 @@ +#define PY_LOCAL_AGGRESSIVE +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/cellobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/classobject.h" +#include "third_party/python/Include/code.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/eval.h" +#include "third_party/python/Include/frameobject.h" +#include "third_party/python/Include/funcobject.h" +#include "third_party/python/Include/genobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/opcode.h" +#include "third_party/python/Include/pydtrace.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/setobject.h" +#include "third_party/python/Include/sliceobject.h" +#include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/sysmodule.h" +#include "third_party/python/Include/traceback.h" +#include "third_party/python/Include/tupleobject.h" +#include "third_party/python/Include/warnings.h" /* clang-format off */ /* Execute compiled code */ @@ -7,18 +34,6 @@ XXX document it! */ -/* enable more aggressive intra-module optimizations, where available */ -#define PY_LOCAL_AGGRESSIVE - -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/code.h" -#include "third_party/python/Include/dictobject.h" -#include "third_party/python/Include/frameobject.h" -#include "third_party/python/Include/opcode.h" -#include "third_party/python/Include/pydtrace.h" -#include "third_party/python/Include/setobject.h" -#include "third_party/python/Include/structmember.h" - /* Turn this on if your compiler chokes on the big switch: */ /* #define CASE_TOO_BIG 1 */ @@ -216,7 +231,7 @@ static long main_thread = 0; /* Request for dropping the GIL */ static _Py_atomic_int gil_drop_request = {0}; -#include "third_party/python/Include/ceval_gil.inc" +#include "third_party/python/Python/ceval_gil.inc" int PyEval_ThreadsInitialized(void) diff --git a/third_party/python/Python/ceval_gil.inc b/third_party/python/Python/ceval_gil.inc index 594ed3f29..fdd69e910 100644 --- a/third_party/python/Python/ceval_gil.inc +++ b/third_party/python/Python/ceval_gil.inc @@ -1,4 +1,4 @@ -#include "third_party/python/Include/condvar.h" +#include "third_party/python/Python/condvar.h" /* clang-format off */ /* diff --git a/third_party/python/Python/clinic/bltinmodule.inc b/third_party/python/Python/clinic/bltinmodule.inc index 37ce794b2..37824993e 100644 --- a/third_party/python/Python/clinic/bltinmodule.inc +++ b/third_party/python/Python/clinic/bltinmodule.inc @@ -1,6 +1,8 @@ +/* clang-format off */ /*[clinic input] preserve [clinic start generated code]*/ +#include "third_party/python/Include/unicodeobject.h" PyDoc_STRVAR(builtin_abs__doc__, "abs($module, x, /)\n" diff --git a/third_party/python/Python/clinic/import.inc b/third_party/python/Python/clinic/import.inc index b3460b061..0b94ee096 100644 --- a/third_party/python/Python/clinic/import.inc +++ b/third_party/python/Python/clinic/import.inc @@ -1,364 +1,341 @@ +#include "third_party/python/Include/pymacro.h" /*[clinic input] preserve [clinic start generated code]*/ PyDoc_STRVAR(_imp_lock_held__doc__, -"lock_held($module, /)\n" -"--\n" -"\n" -"Return True if the import lock is currently held, else False.\n" -"\n" -"On platforms without threads, return False."); + "lock_held($module, /)\n" + "--\n" + "\n" + "Return True if the import lock is currently held, else False.\n" + "\n" + "On platforms without threads, return False."); -#define _IMP_LOCK_HELD_METHODDEF \ - {"lock_held", (PyCFunction)_imp_lock_held, METH_NOARGS, _imp_lock_held__doc__}, +#define _IMP_LOCK_HELD_METHODDEF \ + {"lock_held", (PyCFunction)_imp_lock_held, METH_NOARGS, \ + _imp_lock_held__doc__}, -static PyObject * -_imp_lock_held_impl(PyObject *module); +static PyObject *_imp_lock_held_impl(PyObject *module); -static PyObject * -_imp_lock_held(PyObject *module, PyObject *Py_UNUSED(ignored)) -{ - return _imp_lock_held_impl(module); +static PyObject *_imp_lock_held(PyObject *module, + PyObject *Py_UNUSED(ignored)) { + return _imp_lock_held_impl(module); } -PyDoc_STRVAR(_imp_acquire_lock__doc__, -"acquire_lock($module, /)\n" -"--\n" -"\n" -"Acquires the interpreter\'s import lock for the current thread.\n" -"\n" -"This lock should be used by import hooks to ensure thread-safety when importing\n" -"modules. On platforms without threads, this function does nothing."); +PyDoc_STRVAR( + _imp_acquire_lock__doc__, + "acquire_lock($module, /)\n" + "--\n" + "\n" + "Acquires the interpreter\'s import lock for the current thread.\n" + "\n" + "This lock should be used by import hooks to ensure thread-safety when " + "importing\n" + "modules. On platforms without threads, this function does nothing."); -#define _IMP_ACQUIRE_LOCK_METHODDEF \ - {"acquire_lock", (PyCFunction)_imp_acquire_lock, METH_NOARGS, _imp_acquire_lock__doc__}, +#define _IMP_ACQUIRE_LOCK_METHODDEF \ + {"acquire_lock", (PyCFunction)_imp_acquire_lock, METH_NOARGS, \ + _imp_acquire_lock__doc__}, -static PyObject * -_imp_acquire_lock_impl(PyObject *module); +static PyObject *_imp_acquire_lock_impl(PyObject *module); -static PyObject * -_imp_acquire_lock(PyObject *module, PyObject *Py_UNUSED(ignored)) -{ - return _imp_acquire_lock_impl(module); +static PyObject *_imp_acquire_lock(PyObject *module, + PyObject *Py_UNUSED(ignored)) { + return _imp_acquire_lock_impl(module); } PyDoc_STRVAR(_imp_release_lock__doc__, -"release_lock($module, /)\n" -"--\n" -"\n" -"Release the interpreter\'s import lock.\n" -"\n" -"On platforms without threads, this function does nothing."); + "release_lock($module, /)\n" + "--\n" + "\n" + "Release the interpreter\'s import lock.\n" + "\n" + "On platforms without threads, this function does nothing."); -#define _IMP_RELEASE_LOCK_METHODDEF \ - {"release_lock", (PyCFunction)_imp_release_lock, METH_NOARGS, _imp_release_lock__doc__}, +#define _IMP_RELEASE_LOCK_METHODDEF \ + {"release_lock", (PyCFunction)_imp_release_lock, METH_NOARGS, \ + _imp_release_lock__doc__}, -static PyObject * -_imp_release_lock_impl(PyObject *module); +static PyObject *_imp_release_lock_impl(PyObject *module); -static PyObject * -_imp_release_lock(PyObject *module, PyObject *Py_UNUSED(ignored)) -{ - return _imp_release_lock_impl(module); +static PyObject *_imp_release_lock(PyObject *module, + PyObject *Py_UNUSED(ignored)) { + return _imp_release_lock_impl(module); } PyDoc_STRVAR(_imp__fix_co_filename__doc__, -"_fix_co_filename($module, code, path, /)\n" -"--\n" -"\n" -"Changes code.co_filename to specify the passed-in file path.\n" -"\n" -" code\n" -" Code object to change.\n" -" path\n" -" File path to use."); + "_fix_co_filename($module, code, path, /)\n" + "--\n" + "\n" + "Changes code.co_filename to specify the passed-in file path.\n" + "\n" + " code\n" + " Code object to change.\n" + " path\n" + " File path to use."); -#define _IMP__FIX_CO_FILENAME_METHODDEF \ - {"_fix_co_filename", (PyCFunction)_imp__fix_co_filename, METH_VARARGS, _imp__fix_co_filename__doc__}, +#define _IMP__FIX_CO_FILENAME_METHODDEF \ + {"_fix_co_filename", (PyCFunction)_imp__fix_co_filename, METH_VARARGS, \ + _imp__fix_co_filename__doc__}, -static PyObject * -_imp__fix_co_filename_impl(PyObject *module, PyCodeObject *code, - PyObject *path); +static PyObject *_imp__fix_co_filename_impl(PyObject *module, + PyCodeObject *code, PyObject *path); -static PyObject * -_imp__fix_co_filename(PyObject *module, PyObject *args) -{ - PyObject *return_value = NULL; - PyCodeObject *code; - PyObject *path; +static PyObject *_imp__fix_co_filename(PyObject *module, PyObject *args) { + PyObject *return_value = NULL; + PyCodeObject *code; + PyObject *path; - if (!PyArg_ParseTuple(args, "O!U:_fix_co_filename", - &PyCode_Type, &code, &path)) { - goto exit; - } - return_value = _imp__fix_co_filename_impl(module, code, path); + if (!PyArg_ParseTuple(args, "O!U:_fix_co_filename", &PyCode_Type, &code, + &path)) { + goto exit; + } + return_value = _imp__fix_co_filename_impl(module, code, path); exit: - return return_value; + return return_value; } -PyDoc_STRVAR(_imp_create_builtin__doc__, -"create_builtin($module, spec, /)\n" -"--\n" -"\n" -"Create an extension module."); +PyDoc_STRVAR(_imp_create_builtin__doc__, "create_builtin($module, spec, /)\n" + "--\n" + "\n" + "Create an extension module."); -#define _IMP_CREATE_BUILTIN_METHODDEF \ - {"create_builtin", (PyCFunction)_imp_create_builtin, METH_O, _imp_create_builtin__doc__}, +#define _IMP_CREATE_BUILTIN_METHODDEF \ + {"create_builtin", (PyCFunction)_imp_create_builtin, METH_O, \ + _imp_create_builtin__doc__}, -PyDoc_STRVAR(_imp_extension_suffixes__doc__, -"extension_suffixes($module, /)\n" -"--\n" -"\n" -"Returns the list of file suffixes used to identify extension modules."); +PyDoc_STRVAR( + _imp_extension_suffixes__doc__, + "extension_suffixes($module, /)\n" + "--\n" + "\n" + "Returns the list of file suffixes used to identify extension modules."); -#define _IMP_EXTENSION_SUFFIXES_METHODDEF \ - {"extension_suffixes", (PyCFunction)_imp_extension_suffixes, METH_NOARGS, _imp_extension_suffixes__doc__}, +#define _IMP_EXTENSION_SUFFIXES_METHODDEF \ + {"extension_suffixes", (PyCFunction)_imp_extension_suffixes, METH_NOARGS, \ + _imp_extension_suffixes__doc__}, -static PyObject * -_imp_extension_suffixes_impl(PyObject *module); +static PyObject *_imp_extension_suffixes_impl(PyObject *module); -static PyObject * -_imp_extension_suffixes(PyObject *module, PyObject *Py_UNUSED(ignored)) -{ - return _imp_extension_suffixes_impl(module); +static PyObject *_imp_extension_suffixes(PyObject *module, + PyObject *Py_UNUSED(ignored)) { + return _imp_extension_suffixes_impl(module); } -PyDoc_STRVAR(_imp_init_frozen__doc__, -"init_frozen($module, name, /)\n" -"--\n" -"\n" -"Initializes a frozen module."); +PyDoc_STRVAR(_imp_init_frozen__doc__, "init_frozen($module, name, /)\n" + "--\n" + "\n" + "Initializes a frozen module."); -#define _IMP_INIT_FROZEN_METHODDEF \ - {"init_frozen", (PyCFunction)_imp_init_frozen, METH_O, _imp_init_frozen__doc__}, +#define _IMP_INIT_FROZEN_METHODDEF \ + {"init_frozen", (PyCFunction)_imp_init_frozen, METH_O, \ + _imp_init_frozen__doc__}, -static PyObject * -_imp_init_frozen_impl(PyObject *module, PyObject *name); +static PyObject *_imp_init_frozen_impl(PyObject *module, PyObject *name); -static PyObject * -_imp_init_frozen(PyObject *module, PyObject *arg) -{ - PyObject *return_value = NULL; - PyObject *name; +static PyObject *_imp_init_frozen(PyObject *module, PyObject *arg) { + PyObject *return_value = NULL; + PyObject *name; - if (!PyArg_Parse(arg, "U:init_frozen", &name)) { - goto exit; - } - return_value = _imp_init_frozen_impl(module, name); + if (!PyArg_Parse(arg, "U:init_frozen", &name)) { + goto exit; + } + return_value = _imp_init_frozen_impl(module, name); exit: - return return_value; + return return_value; } PyDoc_STRVAR(_imp_get_frozen_object__doc__, -"get_frozen_object($module, name, /)\n" -"--\n" -"\n" -"Create a code object for a frozen module."); + "get_frozen_object($module, name, /)\n" + "--\n" + "\n" + "Create a code object for a frozen module."); -#define _IMP_GET_FROZEN_OBJECT_METHODDEF \ - {"get_frozen_object", (PyCFunction)_imp_get_frozen_object, METH_O, _imp_get_frozen_object__doc__}, +#define _IMP_GET_FROZEN_OBJECT_METHODDEF \ + {"get_frozen_object", (PyCFunction)_imp_get_frozen_object, METH_O, \ + _imp_get_frozen_object__doc__}, -static PyObject * -_imp_get_frozen_object_impl(PyObject *module, PyObject *name); +static PyObject *_imp_get_frozen_object_impl(PyObject *module, PyObject *name); -static PyObject * -_imp_get_frozen_object(PyObject *module, PyObject *arg) -{ - PyObject *return_value = NULL; - PyObject *name; +static PyObject *_imp_get_frozen_object(PyObject *module, PyObject *arg) { + PyObject *return_value = NULL; + PyObject *name; - if (!PyArg_Parse(arg, "U:get_frozen_object", &name)) { - goto exit; - } - return_value = _imp_get_frozen_object_impl(module, name); + if (!PyArg_Parse(arg, "U:get_frozen_object", &name)) { + goto exit; + } + return_value = _imp_get_frozen_object_impl(module, name); exit: - return return_value; + return return_value; } PyDoc_STRVAR(_imp_is_frozen_package__doc__, -"is_frozen_package($module, name, /)\n" -"--\n" -"\n" -"Returns True if the module name is of a frozen package."); + "is_frozen_package($module, name, /)\n" + "--\n" + "\n" + "Returns True if the module name is of a frozen package."); -#define _IMP_IS_FROZEN_PACKAGE_METHODDEF \ - {"is_frozen_package", (PyCFunction)_imp_is_frozen_package, METH_O, _imp_is_frozen_package__doc__}, +#define _IMP_IS_FROZEN_PACKAGE_METHODDEF \ + {"is_frozen_package", (PyCFunction)_imp_is_frozen_package, METH_O, \ + _imp_is_frozen_package__doc__}, -static PyObject * -_imp_is_frozen_package_impl(PyObject *module, PyObject *name); +static PyObject *_imp_is_frozen_package_impl(PyObject *module, PyObject *name); -static PyObject * -_imp_is_frozen_package(PyObject *module, PyObject *arg) -{ - PyObject *return_value = NULL; - PyObject *name; +static PyObject *_imp_is_frozen_package(PyObject *module, PyObject *arg) { + PyObject *return_value = NULL; + PyObject *name; - if (!PyArg_Parse(arg, "U:is_frozen_package", &name)) { - goto exit; - } - return_value = _imp_is_frozen_package_impl(module, name); + if (!PyArg_Parse(arg, "U:is_frozen_package", &name)) { + goto exit; + } + return_value = _imp_is_frozen_package_impl(module, name); exit: - return return_value; + return return_value; } -PyDoc_STRVAR(_imp_is_builtin__doc__, -"is_builtin($module, name, /)\n" -"--\n" -"\n" -"Returns True if the module name corresponds to a built-in module."); +PyDoc_STRVAR( + _imp_is_builtin__doc__, + "is_builtin($module, name, /)\n" + "--\n" + "\n" + "Returns True if the module name corresponds to a built-in module."); -#define _IMP_IS_BUILTIN_METHODDEF \ - {"is_builtin", (PyCFunction)_imp_is_builtin, METH_O, _imp_is_builtin__doc__}, +#define _IMP_IS_BUILTIN_METHODDEF \ + {"is_builtin", (PyCFunction)_imp_is_builtin, METH_O, _imp_is_builtin__doc__}, -static PyObject * -_imp_is_builtin_impl(PyObject *module, PyObject *name); +static PyObject *_imp_is_builtin_impl(PyObject *module, PyObject *name); -static PyObject * -_imp_is_builtin(PyObject *module, PyObject *arg) -{ - PyObject *return_value = NULL; - PyObject *name; +static PyObject *_imp_is_builtin(PyObject *module, PyObject *arg) { + PyObject *return_value = NULL; + PyObject *name; - if (!PyArg_Parse(arg, "U:is_builtin", &name)) { - goto exit; - } - return_value = _imp_is_builtin_impl(module, name); + if (!PyArg_Parse(arg, "U:is_builtin", &name)) { + goto exit; + } + return_value = _imp_is_builtin_impl(module, name); exit: - return return_value; + return return_value; } PyDoc_STRVAR(_imp_is_frozen__doc__, -"is_frozen($module, name, /)\n" -"--\n" -"\n" -"Returns True if the module name corresponds to a frozen module."); + "is_frozen($module, name, /)\n" + "--\n" + "\n" + "Returns True if the module name corresponds to a frozen module."); -#define _IMP_IS_FROZEN_METHODDEF \ - {"is_frozen", (PyCFunction)_imp_is_frozen, METH_O, _imp_is_frozen__doc__}, +#define _IMP_IS_FROZEN_METHODDEF \ + {"is_frozen", (PyCFunction)_imp_is_frozen, METH_O, _imp_is_frozen__doc__}, -static PyObject * -_imp_is_frozen_impl(PyObject *module, PyObject *name); +static PyObject *_imp_is_frozen_impl(PyObject *module, PyObject *name); -static PyObject * -_imp_is_frozen(PyObject *module, PyObject *arg) -{ - PyObject *return_value = NULL; - PyObject *name; +static PyObject *_imp_is_frozen(PyObject *module, PyObject *arg) { + PyObject *return_value = NULL; + PyObject *name; - if (!PyArg_Parse(arg, "U:is_frozen", &name)) { - goto exit; - } - return_value = _imp_is_frozen_impl(module, name); + if (!PyArg_Parse(arg, "U:is_frozen", &name)) { + goto exit; + } + return_value = _imp_is_frozen_impl(module, name); exit: - return return_value; + return return_value; } #if defined(HAVE_DYNAMIC_LOADING) PyDoc_STRVAR(_imp_create_dynamic__doc__, -"create_dynamic($module, spec, file=None, /)\n" -"--\n" -"\n" -"Create an extension module."); + "create_dynamic($module, spec, file=None, /)\n" + "--\n" + "\n" + "Create an extension module."); -#define _IMP_CREATE_DYNAMIC_METHODDEF \ - {"create_dynamic", (PyCFunction)_imp_create_dynamic, METH_VARARGS, _imp_create_dynamic__doc__}, +#define _IMP_CREATE_DYNAMIC_METHODDEF \ + {"create_dynamic", (PyCFunction)_imp_create_dynamic, METH_VARARGS, \ + _imp_create_dynamic__doc__}, -static PyObject * -_imp_create_dynamic_impl(PyObject *module, PyObject *spec, PyObject *file); +static PyObject *_imp_create_dynamic_impl(PyObject *module, PyObject *spec, + PyObject *file); -static PyObject * -_imp_create_dynamic(PyObject *module, PyObject *args) -{ - PyObject *return_value = NULL; - PyObject *spec; - PyObject *file = NULL; +static PyObject *_imp_create_dynamic(PyObject *module, PyObject *args) { + PyObject *return_value = NULL; + PyObject *spec; + PyObject *file = NULL; - if (!PyArg_UnpackTuple(args, "create_dynamic", - 1, 2, - &spec, &file)) { - goto exit; - } - return_value = _imp_create_dynamic_impl(module, spec, file); + if (!PyArg_UnpackTuple(args, "create_dynamic", 1, 2, &spec, &file)) { + goto exit; + } + return_value = _imp_create_dynamic_impl(module, spec, file); exit: - return return_value; + return return_value; } #endif /* defined(HAVE_DYNAMIC_LOADING) */ #if defined(HAVE_DYNAMIC_LOADING) -PyDoc_STRVAR(_imp_exec_dynamic__doc__, -"exec_dynamic($module, mod, /)\n" -"--\n" -"\n" -"Initialize an extension module."); +PyDoc_STRVAR(_imp_exec_dynamic__doc__, "exec_dynamic($module, mod, /)\n" + "--\n" + "\n" + "Initialize an extension module."); -#define _IMP_EXEC_DYNAMIC_METHODDEF \ - {"exec_dynamic", (PyCFunction)_imp_exec_dynamic, METH_O, _imp_exec_dynamic__doc__}, +#define _IMP_EXEC_DYNAMIC_METHODDEF \ + {"exec_dynamic", (PyCFunction)_imp_exec_dynamic, METH_O, \ + _imp_exec_dynamic__doc__}, -static int -_imp_exec_dynamic_impl(PyObject *module, PyObject *mod); +static int _imp_exec_dynamic_impl(PyObject *module, PyObject *mod); -static PyObject * -_imp_exec_dynamic(PyObject *module, PyObject *mod) -{ - PyObject *return_value = NULL; - int _return_value; +static PyObject *_imp_exec_dynamic(PyObject *module, PyObject *mod) { + PyObject *return_value = NULL; + int _return_value; - _return_value = _imp_exec_dynamic_impl(module, mod); - if ((_return_value == -1) && PyErr_Occurred()) { - goto exit; - } - return_value = PyLong_FromLong((long)_return_value); + _return_value = _imp_exec_dynamic_impl(module, mod); + if ((_return_value == -1) && PyErr_Occurred()) { + goto exit; + } + return_value = PyLong_FromLong((long)_return_value); exit: - return return_value; + return return_value; } #endif /* defined(HAVE_DYNAMIC_LOADING) */ -PyDoc_STRVAR(_imp_exec_builtin__doc__, -"exec_builtin($module, mod, /)\n" -"--\n" -"\n" -"Initialize a built-in module."); +PyDoc_STRVAR(_imp_exec_builtin__doc__, "exec_builtin($module, mod, /)\n" + "--\n" + "\n" + "Initialize a built-in module."); -#define _IMP_EXEC_BUILTIN_METHODDEF \ - {"exec_builtin", (PyCFunction)_imp_exec_builtin, METH_O, _imp_exec_builtin__doc__}, +#define _IMP_EXEC_BUILTIN_METHODDEF \ + {"exec_builtin", (PyCFunction)_imp_exec_builtin, METH_O, \ + _imp_exec_builtin__doc__}, -static int -_imp_exec_builtin_impl(PyObject *module, PyObject *mod); +static int _imp_exec_builtin_impl(PyObject *module, PyObject *mod); -static PyObject * -_imp_exec_builtin(PyObject *module, PyObject *mod) -{ - PyObject *return_value = NULL; - int _return_value; +static PyObject *_imp_exec_builtin(PyObject *module, PyObject *mod) { + PyObject *return_value = NULL; + int _return_value; - _return_value = _imp_exec_builtin_impl(module, mod); - if ((_return_value == -1) && PyErr_Occurred()) { - goto exit; - } - return_value = PyLong_FromLong((long)_return_value); + _return_value = _imp_exec_builtin_impl(module, mod); + if ((_return_value == -1) && PyErr_Occurred()) { + goto exit; + } + return_value = PyLong_FromLong((long)_return_value); exit: - return return_value; + return return_value; } #ifndef _IMP_CREATE_DYNAMIC_METHODDEF - #define _IMP_CREATE_DYNAMIC_METHODDEF +#define _IMP_CREATE_DYNAMIC_METHODDEF #endif /* !defined(_IMP_CREATE_DYNAMIC_METHODDEF) */ #ifndef _IMP_EXEC_DYNAMIC_METHODDEF - #define _IMP_EXEC_DYNAMIC_METHODDEF +#define _IMP_EXEC_DYNAMIC_METHODDEF #endif /* !defined(_IMP_EXEC_DYNAMIC_METHODDEF) */ /*[clinic end generated code: output=d24d7f73702a907f input=a9049054013a1b77]*/ diff --git a/third_party/python/Python/codecs.c b/third_party/python/Python/codecs.c index b7e9b6f27..25e27879e 100644 --- a/third_party/python/Python/codecs.c +++ b/third_party/python/Python/codecs.c @@ -1,3 +1,18 @@ +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/pycapsule.h" +#include "third_party/python/Include/pyctype.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pystate.h" +#include "third_party/python/Include/tupleobject.h" +#include "third_party/python/Include/ucnhash.h" /* clang-format off */ /* ------------------------------------------------------------------------ @@ -10,9 +25,6 @@ Copyright (c) Corporation for National Research Initiatives. ------------------------------------------------------------------------ */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/ucnhash.h" - const char *Py_hexdigits = "0123456789abcdef"; /* --- Codec Registry ----------------------------------------------------- */ @@ -73,7 +85,7 @@ PyObject *normalizestring(const char *string) if (ch == ' ') ch = '-'; else - ch = Py_TOLOWER(Py_CHARMASK(ch)); + ch = Py_TOLOWER(ch); p[i] = ch; } p[i] = '\0'; diff --git a/third_party/python/Python/compile.c b/third_party/python/Python/compile.c index 32d7d200b..dbafa214a 100644 --- a/third_party/python/Python/compile.c +++ b/third_party/python/Python/compile.c @@ -1,3 +1,24 @@ +#include "third_party/python/Include/Python-ast.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/ast.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/code.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/node.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/opcode.h" +#include "third_party/python/Include/pycapsule.h" +#include "third_party/python/Include/pydebug.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/sliceobject.h" +#include "third_party/python/Include/symtable.h" +#include "third_party/python/Include/unicodeobject.h" +#include "third_party/python/Include/warnings.h" +#include "third_party/python/Python/wordcode_helpers.inc" /* clang-format off */ /* @@ -23,16 +44,6 @@ * objects. */ -#include "third_party/python/Include/Python.h" - -#include "third_party/python/Include/Python-ast.h" -#include "third_party/python/Include/node.h" -#include "third_party/python/Include/ast.h" -#include "third_party/python/Include/code.h" -#include "third_party/python/Include/symtable.h" -#include "third_party/python/Include/opcode.h" -#include "third_party/python/Python/wordcode_helpers.h" - #define DEFAULT_BLOCK_SIZE 16 #define DEFAULT_BLOCKS 8 #define DEFAULT_CODE_SIZE 128 @@ -290,7 +301,7 @@ _Py_Mangle(PyObject *privateobj, PyObject *ident) static int compiler_init(struct compiler *c) { - memset(c, 0, sizeof(struct compiler)); + bzero(c, sizeof(struct compiler)); c->c_stack = PyList_New(0); if (!c->c_stack) @@ -543,7 +554,7 @@ compiler_enter_scope(struct compiler *c, identifier name, PyErr_NoMemory(); return 0; } - memset(u, 0, sizeof(struct compiler_unit)); + bzero(u, sizeof(struct compiler_unit)); u->u_scope_type = scope_type; u->u_argcount = 0; u->u_kwonlyargcount = 0; @@ -764,7 +775,7 @@ compiler_new_block(struct compiler *c) PyErr_NoMemory(); return NULL; } - memset((void *)b, 0, sizeof(basicblock)); + bzero((void *)b, sizeof(basicblock)); /* Extend the singly linked list of blocks with new block. */ b->b_list = u->u_blocks; u->u_blocks = b; @@ -808,8 +819,7 @@ compiler_next_instr(struct compiler *c, basicblock *b) return -1; } b->b_ialloc = DEFAULT_BLOCK_SIZE; - memset((char *)b->b_instr, 0, - sizeof(struct instr) * DEFAULT_BLOCK_SIZE); + bzero((char *)b->b_instr, sizeof(struct instr) * DEFAULT_BLOCK_SIZE); } else if (b->b_iused == b->b_ialloc) { struct instr *tmp; @@ -834,7 +844,7 @@ compiler_next_instr(struct compiler *c, basicblock *b) return -1; } b->b_instr = tmp; - memset((char *)b->b_instr + oldsize, 0, newsize - oldsize); + bzero((char *)b->b_instr + oldsize, newsize - oldsize); } return b->b_iused++; } @@ -4871,7 +4881,7 @@ stackdepth(struct compiler *c) static int assemble_init(struct assembler *a, int nblocks, int firstlineno) { - memset(a, 0, sizeof(struct assembler)); + bzero(a, sizeof(struct assembler)); a->a_lineno = firstlineno; a->a_bytecode = PyBytes_FromStringAndSize(NULL, DEFAULT_CODE_SIZE); if (!a->a_bytecode) @@ -5324,7 +5334,7 @@ assemble(struct compiler *c, int addNone) } #undef PyAST_Compile -PyAPI_FUNC(PyCodeObject *) +PyCodeObject * PyAST_Compile(mod_ty mod, const char *filename, PyCompilerFlags *flags, PyArena *arena) { diff --git a/third_party/python/Python/condvar.h b/third_party/python/Python/condvar.h index 7be01f300..cccd81e51 100644 --- a/third_party/python/Python/condvar.h +++ b/third_party/python/Python/condvar.h @@ -1,6 +1,6 @@ #ifndef _CONDVAR_H_ #define _CONDVAR_H_ -#include "third_party/python/Include/Python.h" +#include "libc/time/time.h" /* clang-format off */ /* diff --git a/third_party/python/Python/dtoa.c b/third_party/python/Python/dtoa.c index 4568a47c2..0ccb0ff14 100644 --- a/third_party/python/Python/dtoa.c +++ b/third_party/python/Python/dtoa.c @@ -1,3 +1,8 @@ +#include "libc/assert.h" +#include "libc/errno.h" +#include "libc/math.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pyport.h" /* clang-format off */ /**************************************************************** @@ -116,9 +121,6 @@ /* Linking of Python's #defines to Gay's #defines starts here. */ -#include "third_party/python/Include/Python.h" -#include "libc/math.h" - /* if PY_NO_SHORT_FLOAT_REPR is defined, then don't even try to compile the following code */ #ifndef PY_NO_SHORT_FLOAT_REPR diff --git a/third_party/python/Python/dynload_dl.c b/third_party/python/Python/dynload_dl.c index f64ff7cdd..a42734d73 100644 --- a/third_party/python/Python/dynload_dl.c +++ b/third_party/python/Python/dynload_dl.c @@ -1,11 +1,9 @@ +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Python/importdl.h" /* clang-format off */ /* Support for dynamic loading of extension modules */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/importdl.h" - - extern char *Py_GetProgramName(void); const char *_PyImport_DynLoadFiletab[] = {".o", NULL}; diff --git a/third_party/python/Python/dynload_shlib.c b/third_party/python/Python/dynload_shlib.c index 5f24fd35b..5eb046b58 100644 --- a/third_party/python/Python/dynload_shlib.c +++ b/third_party/python/Python/dynload_shlib.c @@ -1,5 +1,9 @@ +#include "libc/calls/weirdtypes.h" #include "libc/runtime/dlfcn.h" -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pystate.h" #include "third_party/python/Python/importdl.h" /* clang-format off */ diff --git a/third_party/python/Python/dynload_stub.c b/third_party/python/Python/dynload_stub.c index 273501a55..41b7fb978 100644 --- a/third_party/python/Python/dynload_stub.c +++ b/third_party/python/Python/dynload_stub.c @@ -1,5 +1,4 @@ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/importdl.h" +#include "third_party/python/Python/importdl.h" /* clang-format off */ /* This module provides the necessary stubs for when dynamic loading is diff --git a/third_party/python/Python/dynload_win.c b/third_party/python/Python/dynload_win.c index 11b5c2959..ec4fc70fc 100644 --- a/third_party/python/Python/dynload_win.c +++ b/third_party/python/Python/dynload_win.c @@ -1,6 +1,5 @@ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/importdl.h" #include "third_party/python/Include/patchlevel.h" +#include "third_party/python/Python/importdl.h" /* clang-format off */ // "activation context" magic - see dl_nt.c... diff --git a/third_party/python/Python/errors.c b/third_party/python/Python/errors.c index 52034d0a8..a297a4c64 100644 --- a/third_party/python/Python/errors.c +++ b/third_party/python/Python/errors.c @@ -1,14 +1,21 @@ -#include "third_party/python/Include/Python.h" +#include "libc/errno.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/fileobject.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pystate.h" +#include "third_party/python/Include/sysmodule.h" +#include "third_party/python/Include/traceback.h" +#include "third_party/python/Include/tupleobject.h" /* clang-format off */ -#ifdef __cplusplus -extern "C" { -#endif - _Py_IDENTIFIER(builtins); _Py_IDENTIFIER(stderr); - void PyErr_Restore(PyObject *type, PyObject *value, PyObject *traceback) { @@ -1176,7 +1183,3 @@ PyErr_ProgramTextObject(PyObject *filename, int lineno) } return err_programtext(fp, lineno); } - -#ifdef __cplusplus -} -#endif diff --git a/third_party/python/Python/fileutils.c b/third_party/python/Python/fileutils.c index 58468433a..330a3d8d2 100644 --- a/third_party/python/Python/fileutils.c +++ b/third_party/python/Python/fileutils.c @@ -1,26 +1,29 @@ #include "libc/calls/calls.h" +#include "libc/calls/ioctl.h" +#include "libc/dce.h" +#include "libc/errno.h" +#include "libc/nt/runtime.h" +#include "libc/str/str.h" #include "libc/sysv/consts/f.h" #include "libc/sysv/consts/fd.h" +#include "libc/sysv/consts/fio.h" +#include "libc/sysv/consts/o.h" #include "libc/unicode/locale.h" -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/object.h" #include "third_party/python/Include/osdefs.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pyport.h" +#include "third_party/python/Include/unicodeobject.h" /* clang-format off */ -#if defined(__APPLE__) || defined(__ANDROID__) -extern wchar_t* _Py_DecodeUTF8_surrogateescape(const char *s, Py_ssize_t size); -#endif +wchar_t* _Py_DecodeUTF8_surrogateescape(const char *, Py_ssize_t); -#ifdef O_CLOEXEC -/* Does open() support the O_CLOEXEC flag? Possible values: - - -1: unknown - 0: open() ignores O_CLOEXEC flag, ex: Linux kernel older than 2.6.23 - 1: open() supports O_CLOEXEC flag, close-on-exec is set - - The flag is used by _Py_open(), _Py_open_noraise(), io.FileIO - and os.open(). */ -int _Py_open_cloexec_works = -1; -#endif +int _Py_open_cloexec_works = 1; PyObject * _Py_device_encoding(int fd) @@ -34,7 +37,6 @@ _Py_device_encoding(int fd) _Py_END_SUPPRESS_IPH if (!valid) Py_RETURN_NONE; - #if defined(MS_WINDOWS) if (fd == 0) cp = GetConsoleCP(); @@ -56,211 +58,16 @@ _Py_device_encoding(int fd) Py_RETURN_NONE; } -#if !defined(__APPLE__) && !defined(__ANDROID__) && !defined(MS_WINDOWS) - -#define USE_FORCE_ASCII - -extern int _Py_normalize_encoding(const char *, char *, size_t); - -/* Workaround FreeBSD and OpenIndiana locale encoding issue with the C locale. - On these operating systems, nl_langinfo(CODESET) announces an alias of the - ASCII encoding, whereas mbstowcs() and wcstombs() functions use the - ISO-8859-1 encoding. The problem is that os.fsencode() and os.fsdecode() use - locale.getpreferredencoding() codec. For example, if command line arguments - are decoded by mbstowcs() and encoded back by os.fsencode(), we get a - UnicodeEncodeError instead of retrieving the original byte string. - - The workaround is enabled if setlocale(LC_CTYPE, NULL) returns "C", - nl_langinfo(CODESET) announces "ascii" (or an alias to ASCII), and at least - one byte in range 0x80-0xff can be decoded from the locale encoding. The - workaround is also enabled on error, for example if getting the locale - failed. - - Values of force_ascii: - - 1: the workaround is used: Py_EncodeLocale() uses - encode_ascii_surrogateescape() and Py_DecodeLocale() uses - decode_ascii_surrogateescape() - 0: the workaround is not used: Py_EncodeLocale() uses wcstombs() and - Py_DecodeLocale() uses mbstowcs() - -1: unknown, need to call check_force_ascii() to get the value -*/ -static int force_ascii = -1; - -static int -check_force_ascii(void) -{ - char *loc; -#if defined(HAVE_LANGINFO_H) && defined(CODESET) - char *codeset, **alias; - char encoding[20]; /* longest name: "iso_646.irv_1991\0" */ - int is_ascii; - unsigned int i; - char* ascii_aliases[] = { - "ascii", - /* Aliases from Lib/encodings/aliases.py */ - "646", - "ansi_x3.4_1968", - "ansi_x3.4_1986", - "ansi_x3_4_1968", - "cp367", - "csascii", - "ibm367", - "iso646_us", - "iso_646.irv_1991", - "iso_ir_6", - "us", - "us_ascii", - NULL - }; -#endif - - loc = setlocale(LC_CTYPE, NULL); - if (loc == NULL) - goto error; - if (strcmp(loc, "C") != 0 && strcmp(loc, "POSIX") != 0) { - /* the LC_CTYPE locale is different than C */ - return 0; - } - -#if defined(HAVE_LANGINFO_H) && defined(CODESET) - codeset = nl_langinfo(CODESET); - if (!codeset || codeset[0] == '\0') { - /* CODESET is not set or empty */ - goto error; - } - if (!_Py_normalize_encoding(codeset, encoding, sizeof(encoding))) - goto error; - - is_ascii = 0; - for (alias=ascii_aliases; *alias != NULL; alias++) { - if (strcmp(encoding, *alias) == 0) { - is_ascii = 1; - break; - } - } - if (!is_ascii) { - /* nl_langinfo(CODESET) is not "ascii" or an alias of ASCII */ - return 0; - } - - for (i=0x80; i<0xff; i++) { - unsigned char ch; - wchar_t wch; - size_t res; - - ch = (unsigned char)i; - res = mbstowcs(&wch, (char*)&ch, 1); - if (res != (size_t)-1) { - /* decoding a non-ASCII character from the locale encoding succeed: - the locale encoding is not ASCII, force ASCII */ - return 1; - } - } - /* None of the bytes in the range 0x80-0xff can be decoded from the locale - encoding: the locale encoding is really ASCII */ - return 0; -#else - /* nl_langinfo(CODESET) is not available: always force ASCII */ - return 1; -#endif - -error: - /* if an error occurred, force the ASCII encoding */ - return 1; -} - -static char* -encode_ascii_surrogateescape(const wchar_t *text, size_t *error_pos) -{ - char *result = NULL, *out; - size_t len, i; - wchar_t ch; - - if (error_pos != NULL) - *error_pos = (size_t)-1; - - len = wcslen(text); - - result = PyMem_Malloc(len + 1); /* +1 for NUL byte */ - if (result == NULL) - return NULL; - - out = result; - for (i=0; i PY_SSIZE_T_MAX/sizeof(wchar_t)) - return NULL; - res = PyMem_RawMalloc(argsize*sizeof(wchar_t)); - if (!res) - return NULL; - - in = (unsigned char*)arg; - out = res; - while(*in) - if(*in < 128) - *out++ = *in++; - else - *out++ = 0xdc00 + *in++; - *out = 0; - if (size != NULL) - *size = out - res; - return res; -} -#endif - - static wchar_t* decode_current_locale(const char* arg, size_t *size) { wchar_t *res; size_t argsize; size_t count; -#ifdef HAVE_MBRTOWC unsigned char *in; wchar_t *out; mbstate_t mbs; -#endif - -#ifdef HAVE_BROKEN_MBSTOWCS - /* Some platforms have a broken implementation of - * mbstowcs which does not count the characters that - * would result from conversion. Use an upper bound. - */ - argsize = strlen(arg); -#else argsize = mbstowcs(NULL, arg, 0); -#endif if (argsize != (size_t)-1) { if (argsize == PY_SSIZE_T_MAX) goto oom; @@ -287,7 +94,6 @@ decode_current_locale(const char* arg, size_t *size) PyMem_RawFree(res); } /* Conversion failed. Fall back to escaping with surrogateescape. */ -#ifdef HAVE_MBRTOWC /* Try conversion with mbrtwoc (C99), and escape non-decodable bytes. */ /* Overallocate; as multi-byte characters are in the argument, the @@ -300,7 +106,7 @@ decode_current_locale(const char* arg, size_t *size) goto oom; in = (unsigned char*)arg; out = res; - memset(&mbs, 0, sizeof mbs); + bzero(&mbs, sizeof mbs); while (argsize) { size_t converted = mbrtowc(out, (char*)in, argsize, &mbs); if (converted == 0) @@ -321,7 +127,7 @@ decode_current_locale(const char* arg, size_t *size) in the initial shift state. */ *out++ = 0xdc00 + *in++; argsize--; - memset(&mbs, 0, sizeof mbs); + bzero(&mbs, sizeof mbs); continue; } if (Py_UNICODE_IS_SURROGATE(*out)) { @@ -339,31 +145,19 @@ decode_current_locale(const char* arg, size_t *size) } if (size != NULL) *size = out - res; -#else /* HAVE_MBRTOWC */ - /* Cannot use C locale for escaping; manually escape as if charset - is ASCII (i.e. escape all bytes > 128. This will still roundtrip - correctly in the locale's charset, which must be an ASCII superset. */ - res = decode_ascii_surrogateescape(arg, size); - if (res == NULL) - goto oom; -#endif /* HAVE_MBRTOWC */ return res; - oom: if (size != NULL) *size = (size_t)-1; return NULL; } - static wchar_t* decode_locale(const char* arg, size_t *size, int current_locale) { if (current_locale) { return decode_current_locale(arg, size); } - -#if defined(__APPLE__) || defined(__ANDROID__) wchar_t *wstr; wstr = _Py_DecodeUTF8_surrogateescape(arg, strlen(arg)); if (size != NULL) { @@ -373,27 +167,6 @@ decode_locale(const char* arg, size_t *size, int current_locale) *size = (size_t)-1; } return wstr; -#else - -#ifdef USE_FORCE_ASCII - if (force_ascii == -1) { - force_ascii = check_force_ascii(); - } - - if (force_ascii) { - /* force ASCII encoding to workaround mbstowcs() issue */ - wchar_t *res = decode_ascii_surrogateescape(arg, size); - if (res == NULL) { - if (size != NULL) - *size = (size_t)-1; - return NULL; - } - return res; - } -#endif - - return decode_current_locale(arg, size); -#endif /* __APPLE__ or __ANDROID__ */ } @@ -501,16 +274,12 @@ encode_locale(const wchar_t *text, size_t *error_pos, int current_locale) if (current_locale) { return encode_current_locale(text, error_pos); } - -#if defined(__APPLE__) || defined(__ANDROID__) Py_ssize_t len; PyObject *unicode, *bytes = NULL; char *cpath; - unicode = PyUnicode_FromWideChar(text, wcslen(text)); if (unicode == NULL) return NULL; - bytes = _PyUnicode_AsUTF8String(unicode, "surrogateescape"); Py_DECREF(unicode); if (bytes == NULL) { @@ -519,7 +288,6 @@ encode_locale(const wchar_t *text, size_t *error_pos, int current_locale) *error_pos = (size_t)-1; return NULL; } - len = PyBytes_GET_SIZE(bytes); cpath = PyMem_Malloc(len+1); if (cpath == NULL) { @@ -532,20 +300,6 @@ encode_locale(const wchar_t *text, size_t *error_pos, int current_locale) memcpy(cpath, PyBytes_AsString(bytes), len + 1); Py_DECREF(bytes); return cpath; -#else /* __APPLE__ */ - -#ifdef USE_FORCE_ASCII - if (force_ascii == -1) { - force_ascii = check_force_ascii(); - } - - if (force_ascii) { - return encode_ascii_surrogateescape(text, error_pos); - } -#endif - - return encode_current_locale(text, error_pos); -#endif /* __APPLE__ or __ANDROID__ */ } @@ -575,74 +329,6 @@ _Py_EncodeLocaleEx(const wchar_t *text, size_t *error_pos, int current_locale) } -#ifdef MS_WINDOWS -static __int64 secs_between_epochs = 11644473600; /* Seconds between 1.1.1601 and 1.1.1970 */ - -static void -FILE_TIME_to_time_t_nsec(FILETIME *in_ptr, time_t *time_out, int* nsec_out) -{ - /* XXX endianness. Shouldn't matter, as all Windows implementations are little-endian */ - /* Cannot simply cast and dereference in_ptr, - since it might not be aligned properly */ - __int64 in; - memcpy(&in, in_ptr, sizeof(in)); - *nsec_out = (int)(in % 10000000) * 100; /* FILETIME is in units of 100 nsec. */ - *time_out = Py_SAFE_DOWNCAST((in / 10000000) - secs_between_epochs, __int64, time_t); -} - -void -_Py_time_t_to_FILE_TIME(time_t time_in, int nsec_in, FILETIME *out_ptr) -{ - /* XXX endianness */ - __int64 out; - out = time_in + secs_between_epochs; - out = out * 10000000 + nsec_in / 100; - memcpy(out_ptr, &out, sizeof(out)); -} - -/* Below, we *know* that ugo+r is 0444 */ -#if _S_IREAD != 0400 -#error Unsupported C library -#endif -static int -attributes_to_mode(DWORD attr) -{ - int m = 0; - if (attr & FILE_ATTRIBUTE_DIRECTORY) - m |= _S_IFDIR | 0111; /* IFEXEC for user,group,other */ - else - m |= _S_IFREG; - if (attr & FILE_ATTRIBUTE_READONLY) - m |= 0444; - else - m |= 0666; - return m; -} - -void -_Py_attribute_data_to_stat(BY_HANDLE_FILE_INFORMATION *info, ULONG reparse_tag, - struct _Py_stat_struct *result) -{ - memset(result, 0, sizeof(*result)); - result->st_mode = attributes_to_mode(info->dwFileAttributes); - result->st_size = (((__int64)info->nFileSizeHigh)<<32) + info->nFileSizeLow; - result->st_dev = info->dwVolumeSerialNumber; - result->st_rdev = result->st_dev; - FILE_TIME_to_time_t_nsec(&info->ftCreationTime, &result->st_ctime, &result->st_ctime_nsec); - FILE_TIME_to_time_t_nsec(&info->ftLastWriteTime, &result->st_mtime, &result->st_mtime_nsec); - FILE_TIME_to_time_t_nsec(&info->ftLastAccessTime, &result->st_atime, &result->st_atime_nsec); - result->st_nlink = info->nNumberOfLinks; - result->st_ino = (((uint64_t)info->nFileIndexHigh) << 32) + info->nFileIndexLow; - if (reparse_tag == IO_REPARSE_TAG_SYMLINK) { - /* first clear the S_IFMT bits */ - result->st_mode ^= (result->st_mode & S_IFMT); - /* now set the bits that make this a symlink */ - result->st_mode |= S_IFLNK; - } - result->st_file_attributes = info->dwFileAttributes; -} -#endif - /* Return information about a file. On POSIX, use fstat(). @@ -658,57 +344,10 @@ _Py_attribute_data_to_stat(BY_HANDLE_FILE_INFORMATION *info, ULONG reparse_tag, int _Py_fstat_noraise(int fd, struct _Py_stat_struct *status) { -#ifdef MS_WINDOWS - BY_HANDLE_FILE_INFORMATION info; - HANDLE h; - int type; - - _Py_BEGIN_SUPPRESS_IPH - h = (HANDLE)_get_osfhandle(fd); - _Py_END_SUPPRESS_IPH - - if (h == INVALID_HANDLE_VALUE) { - /* errno is already set by _get_osfhandle, but we also set - the Win32 error for callers who expect that */ - SetLastError(ERROR_INVALID_HANDLE); - return -1; - } - memset(status, 0, sizeof(*status)); - - type = GetFileType(h); - if (type == FILE_TYPE_UNKNOWN) { - DWORD error = GetLastError(); - if (error != 0) { - errno = winerror_to_errno(error); - return -1; - } - /* else: valid but unknown file */ - } - - if (type != FILE_TYPE_DISK) { - if (type == FILE_TYPE_CHAR) - status->st_mode = _S_IFCHR; - else if (type == FILE_TYPE_PIPE) - status->st_mode = _S_IFIFO; - return 0; - } - - if (!GetFileInformationByHandle(h, &info)) { - /* The Win32 error is already set, but we also set errno for - callers who expect it */ - errno = winerror_to_errno(GetLastError()); - return -1; - } - - _Py_attribute_data_to_stat(&info, 0, status); - /* specific to fstat() */ - status->st_ino = (((uint64_t)info.nFileIndexHigh) << 32) + info.nFileIndexLow; - return 0; -#else return fstat(fd, status); -#endif } + /* Return information about a file. On POSIX, use fstat(). @@ -738,11 +377,7 @@ _Py_fstat(int fd, struct _Py_stat_struct *status) Py_END_ALLOW_THREADS if (res != 0) { -#ifdef MS_WINDOWS - PyErr_SetFromWindowsErr(0); -#else PyErr_SetFromErrno(PyExc_OSError); -#endif return -1; } return 0; @@ -757,20 +392,6 @@ _Py_fstat(int fd, struct _Py_stat_struct *status) int _Py_stat(PyObject *path, struct stat *statbuf) { -#ifdef MS_WINDOWS - int err; - struct _stat wstatbuf; - const wchar_t *wpath; - - wpath = _PyUnicode_AsUnicode(path); - if (wpath == NULL) - return -2; - - err = _wstat(wpath, &wstatbuf); - if (!err) - statbuf->st_mode = wstatbuf.st_mode; - return err; -#else int ret; PyObject *bytes; char *cpath; @@ -788,7 +409,6 @@ _Py_stat(PyObject *path, struct stat *statbuf) ret = stat(cpath, statbuf); Py_DECREF(bytes); return ret; -#endif } @@ -796,29 +416,7 @@ _Py_stat(PyObject *path, struct stat *statbuf) static int get_inheritable(int fd, int raise) { -#ifdef MS_WINDOWS - HANDLE handle; - DWORD flags; - - _Py_BEGIN_SUPPRESS_IPH - handle = (HANDLE)_get_osfhandle(fd); - _Py_END_SUPPRESS_IPH - if (handle == INVALID_HANDLE_VALUE) { - if (raise) - PyErr_SetFromErrno(PyExc_OSError); - return -1; - } - - if (!GetHandleInformation(handle, &flags)) { - if (raise) - PyErr_SetFromWindowsErr(0); - return -1; - } - - return (flags & HANDLE_FLAG_INHERIT); -#else int flags; - flags = fcntl(fd, F_GETFD, 0); if (flags == -1) { if (raise) @@ -826,7 +424,6 @@ get_inheritable(int fd, int raise) return -1; } return !(flags & FD_CLOEXEC); -#endif } /* Get the inheritable flag of the specified file descriptor. @@ -843,18 +440,8 @@ _Py_get_inheritable(int fd) static int set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works) { -#ifdef MS_WINDOWS - HANDLE handle; - DWORD flags; -#else -#if defined(HAVE_SYS_IOCTL_H) && defined(FIOCLEX) && defined(FIONCLEX) static int ioctl_works = -1; - int request; - int err; -#endif - int flags, new_flags; - int res; -#endif + int res, err, flags, new_flags; /* atomic_flag_works can only be used to make the file descriptor non-inheritable */ @@ -867,49 +454,22 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works) return -1; *atomic_flag_works = !isInheritable; } - if (*atomic_flag_works) return 0; } -#ifdef MS_WINDOWS - _Py_BEGIN_SUPPRESS_IPH - handle = (HANDLE)_get_osfhandle(fd); - _Py_END_SUPPRESS_IPH - if (handle == INVALID_HANDLE_VALUE) { - if (raise) - PyErr_SetFromErrno(PyExc_OSError); - return -1; - } - - if (inheritable) - flags = HANDLE_FLAG_INHERIT; - else - flags = 0; - if (!SetHandleInformation(handle, HANDLE_FLAG_INHERIT, flags)) { - if (raise) - PyErr_SetFromWindowsErr(0); - return -1; - } - return 0; - -#else - -#if defined(HAVE_SYS_IOCTL_H) && defined(FIOCLEX) && defined(FIONCLEX) if (ioctl_works != 0 && raise != 0) { /* fast-path: ioctl() only requires one syscall */ /* caveat: raise=0 is an indicator that we must be async-signal-safe * thus avoid using ioctl() so we skip the fast-path. */ if (inheritable) - request = FIONCLEX; + err = ioctl(fd, FIONCLEX, NULL); else - request = FIOCLEX; - err = ioctl(fd, request, NULL); + err = ioctl(fd, FIOCLEX, NULL); if (!err) { ioctl_works = 1; return 0; } - if (errno != ENOTTY && errno != EACCES) { if (raise) PyErr_SetFromErrno(PyExc_OSError); @@ -917,19 +477,18 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works) } else { /* Issue #22258: Here, ENOTTY means "Inappropriate ioctl for - device". The ioctl is declared but not supported by the kernel. - Remember that ioctl() doesn't work. It is the case on - Illumos-based OS for example. + device". The ioctl is declared but not supported by the + kernel. Remember that ioctl() doesn't work. It is the + case on Illumos-based OS for example. - Issue #27057: When SELinux policy disallows ioctl it will fail - with EACCES. While FIOCLEX is safe operation it may be - unavailable because ioctl was denied altogether. - This can be the case on Android. */ + Issue #27057: When SELinux policy disallows ioctl it will + fail with EACCES. While FIOCLEX is safe operation it may + be unavailable because ioctl was denied altogether. This + can be the case on Android. */ ioctl_works = 0; } /* fallback to fcntl() if ioctl() does not work */ } -#endif /* slow-path: fcntl() requires two syscalls */ flags = fcntl(fd, F_GETFD); @@ -958,7 +517,6 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works) return -1; } return 0; -#endif } /* Make the file descriptor non-inheritable. @@ -1005,18 +563,10 @@ _Py_open_impl(const char *pathname, int flags, int gil_held) { int fd; int async_err = 0; -#ifndef MS_WINDOWS int *atomic_flag_works; -#endif -#ifdef MS_WINDOWS - flags |= O_NOINHERIT; -#elif defined(O_CLOEXEC) atomic_flag_works = &_Py_open_cloexec_works; flags |= O_CLOEXEC; -#else - atomic_flag_works = NULL; -#endif if (gil_held) { do { @@ -1038,12 +588,10 @@ _Py_open_impl(const char *pathname, int flags, int gil_held) return -1; } -#ifndef MS_WINDOWS if (set_inheritable(fd, 0, gil_held, atomic_flag_works) < 0) { close(fd); return -1; } -#endif return fd; } @@ -1090,7 +638,6 @@ FILE * _Py_wfopen(const wchar_t *path, const wchar_t *mode) { FILE *f; -#ifndef MS_WINDOWS char *cpath; char cmode[10]; size_t r; @@ -1104,9 +651,6 @@ _Py_wfopen(const wchar_t *path, const wchar_t *mode) return NULL; f = fopen(cpath, cmode); PyMem_Free(cpath); -#else - f = _wfopen(path, mode); -#endif if (f == NULL) return NULL; if (make_non_inheritable(fileno(f)) < 0) { @@ -1152,39 +696,6 @@ _Py_fopen_obj(PyObject *path, const char *mode) { FILE *f; int async_err = 0; -#ifdef MS_WINDOWS - const wchar_t *wpath; - wchar_t wmode[10]; - int usize; - -#ifdef WITH_THREAD - assert(PyGILState_Check()); -#endif - - if (!PyUnicode_Check(path)) { - PyErr_Format(PyExc_TypeError, - "str file path expected under Windows, got %R", - Py_TYPE(path)); - return NULL; - } - wpath = _PyUnicode_AsUnicode(path); - if (wpath == NULL) - return NULL; - - usize = MultiByteToWideChar(CP_ACP, 0, mode, -1, - wmode, Py_ARRAY_LENGTH(wmode)); - if (usize == 0) { - PyErr_SetFromWindowsErr(0); - return NULL; - } - - do { - Py_BEGIN_ALLOW_THREADS - f = _wfopen(wpath, wmode); - Py_END_ALLOW_THREADS - } while (f == NULL - && errno == EINTR && !(async_err = PyErr_CheckSignals())); -#else PyObject *bytes; char *path_bytes; @@ -1204,7 +715,6 @@ _Py_fopen_obj(PyObject *path, const char *mode) && errno == EINTR && !(async_err = PyErr_CheckSignals())); Py_DECREF(bytes); -#endif if (async_err) return NULL; @@ -1257,11 +767,7 @@ _Py_read(int fd, void *buf, size_t count) do { Py_BEGIN_ALLOW_THREADS errno = 0; -#ifdef MS_WINDOWS - n = read(fd, buf, (int)count); -#else n = read(fd, buf, count); -#endif /* save/restore errno because PyErr_CheckSignals() * and PyErr_SetFromErrno() can modify it */ err = errno; @@ -1294,15 +800,13 @@ _Py_write_impl(int fd, const void *buf, size_t count, int gil_held) int async_err = 0; _Py_BEGIN_SUPPRESS_IPH -#ifdef MS_WINDOWS - if (count > 32767 && isatty(fd)) { + if (IsWindows() && count > 32767 && isatty(fd)) { /* Issue #11395: the Windows console returns an error (12: not enough space error) on writing into stdout if stdout mode is binary and the length is greater than 66,000 bytes (or less, depending on heap usage). */ count = 32767; } -#endif if (count > _PY_WRITE_MAX) { count = _PY_WRITE_MAX; } @@ -1311,11 +815,7 @@ _Py_write_impl(int fd, const void *buf, size_t count, int gil_held) do { Py_BEGIN_ALLOW_THREADS errno = 0; -#ifdef MS_WINDOWS - n = write(fd, buf, (int)count); -#else n = write(fd, buf, count); -#endif /* save/restore errno because PyErr_CheckSignals() * and PyErr_SetFromErrno() can modify it */ err = errno; @@ -1326,11 +826,7 @@ _Py_write_impl(int fd, const void *buf, size_t count, int gil_held) else { do { errno = 0; -#ifdef MS_WINDOWS - n = write(fd, buf, (int)count); -#else n = write(fd, buf, count); -#endif err = errno; } while (n < 0 && err == EINTR); } @@ -1370,12 +866,10 @@ _Py_write(int fd, const void *buf, size_t count) #ifdef WITH_THREAD assert(PyGILState_Check()); #endif - /* _Py_write() must not be called with an exception set, otherwise the * caller may think that write() was interrupted by a signal and the signal * handler raised an exception. */ assert(!PyErr_Occurred()); - return _Py_write_impl(fd, buf, count, 1); } @@ -1393,10 +887,8 @@ _Py_write_noraise(int fd, const void *buf, size_t count) } #ifdef HAVE_READLINK - /* Read value of symbolic link. Encode the path to the locale encoding, decode the result from the locale encoding. Return -1 on error. */ - int _Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t bufsiz) { @@ -1405,7 +897,6 @@ _Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t bufsiz) wchar_t *wbuf; int res; size_t r1; - cpath = Py_EncodeLocale(path, NULL); if (cpath == NULL) { errno = EINVAL; @@ -1436,12 +927,9 @@ _Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t bufsiz) } #endif -#ifdef HAVE_REALPATH - /* Return the canonicalized absolute pathname. Encode path to the locale encoding, decode the result from the locale encoding. Return NULL on error. */ - wchar_t* _Py_wrealpath(const wchar_t *path, wchar_t *resolved_path, size_t resolved_path_size) @@ -1460,7 +948,6 @@ _Py_wrealpath(const wchar_t *path, PyMem_Free(cpath); if (res == NULL) return NULL; - wresolved_path = Py_DecodeLocale(cresolved_path, &r); if (wresolved_path == NULL) { errno = EINVAL; @@ -1475,7 +962,6 @@ _Py_wrealpath(const wchar_t *path, PyMem_RawFree(wresolved_path); return resolved_path; } -#endif /* Get the current directory. size is the buffer size in wide characters including the null character. Decode the path from the locale encoding. @@ -1484,14 +970,9 @@ _Py_wrealpath(const wchar_t *path, wchar_t* _Py_wgetcwd(wchar_t *buf, size_t size) { -#ifdef MS_WINDOWS - int isize = (int)Py_MIN(size, INT_MAX); - return _wgetcwd(buf, isize); -#else char fname[MAXPATHLEN]; wchar_t *wname; size_t len; - if (getcwd(fname, Py_ARRAY_LENGTH(fname)) == NULL) return NULL; wname = Py_DecodeLocale(fname, &len); @@ -1504,7 +985,6 @@ _Py_wgetcwd(wchar_t *buf, size_t size) wcsncpy(buf, wname, size); PyMem_RawFree(wname); return buf; -#endif } /* Duplicate a file descriptor. The new file descriptor is created as @@ -1515,47 +995,9 @@ _Py_wgetcwd(wchar_t *buf, size_t size) int _Py_dup(int fd) { -#ifdef MS_WINDOWS - HANDLE handle; - DWORD ftype; -#endif - #ifdef WITH_THREAD assert(PyGILState_Check()); #endif - -#ifdef MS_WINDOWS - _Py_BEGIN_SUPPRESS_IPH - handle = (HANDLE)_get_osfhandle(fd); - _Py_END_SUPPRESS_IPH - if (handle == INVALID_HANDLE_VALUE) { - PyErr_SetFromErrno(PyExc_OSError); - return -1; - } - - /* get the file type, ignore the error if it failed */ - ftype = GetFileType(handle); - - Py_BEGIN_ALLOW_THREADS - _Py_BEGIN_SUPPRESS_IPH - fd = dup(fd); - _Py_END_SUPPRESS_IPH - Py_END_ALLOW_THREADS - if (fd < 0) { - PyErr_SetFromErrno(PyExc_OSError); - return -1; - } - - /* Character files like console cannot be make non-inheritable */ - if (ftype != FILE_TYPE_CHAR) { - if (_Py_set_inheritable(fd, 0, NULL) < 0) { - _Py_BEGIN_SUPPRESS_IPH - close(fd); - _Py_END_SUPPRESS_IPH - return -1; - } - } -#elif defined(HAVE_FCNTL_H) && defined(F_DUPFD_CLOEXEC) Py_BEGIN_ALLOW_THREADS _Py_BEGIN_SUPPRESS_IPH fd = fcntl(fd, F_DUPFD_CLOEXEC, 0); @@ -1565,29 +1007,9 @@ _Py_dup(int fd) PyErr_SetFromErrno(PyExc_OSError); return -1; } - -#else - Py_BEGIN_ALLOW_THREADS - _Py_BEGIN_SUPPRESS_IPH - fd = dup(fd); - _Py_END_SUPPRESS_IPH - Py_END_ALLOW_THREADS - if (fd < 0) { - PyErr_SetFromErrno(PyExc_OSError); - return -1; - } - - if (_Py_set_inheritable(fd, 0, NULL) < 0) { - _Py_BEGIN_SUPPRESS_IPH - close(fd); - _Py_END_SUPPRESS_IPH - return -1; - } -#endif return fd; } -#ifndef MS_WINDOWS /* Get the blocking mode of the file descriptor. Return 0 if the O_NONBLOCK flag is set, 1 if the flag is cleared, raise an exception and return -1 on error. */ @@ -1615,13 +1037,7 @@ _Py_get_blocking(int fd) int _Py_set_blocking(int fd, int blocking) { -#if defined(HAVE_SYS_IOCTL_H) && defined(FIONBIO) - int arg = !blocking; - if (ioctl(fd, FIONBIO, &arg) < 0) - goto error; -#else int flags, res; - _Py_BEGIN_SUPPRESS_IPH flags = fcntl(fd, F_GETFL, 0); if (flags >= 0) { @@ -1635,17 +1051,13 @@ _Py_set_blocking(int fd, int blocking) res = -1; } _Py_END_SUPPRESS_IPH - if (res < 0) goto error; -#endif return 0; - error: PyErr_SetFromErrno(PyExc_OSError); return -1; } -#endif int diff --git a/third_party/python/Python/formatter_unicode.c b/third_party/python/Python/formatter_unicode.c index 7c8afce89..2f2d0146e 100644 --- a/third_party/python/Python/formatter_unicode.c +++ b/third_party/python/Python/formatter_unicode.c @@ -1,12 +1,24 @@ +#include "libc/math.h" +#include "libc/unicode/locale.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/complexobject.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyctype.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pyport.h" +#include "third_party/python/Include/pystrtod.h" +#include "third_party/python/Include/unicodeobject.h" /* clang-format off */ /* implements the unicode (as opposed to string) version of the built-in formatters for string, int, float. that is, the versions of int.__float__, etc., that take and return unicode objects */ -#include "third_party/python/Include/Python.h" -#include "libc/unicode/locale.h" - /* Raises an exception about an unknown presentation type for this * type. */ diff --git a/third_party/python/Python/frozen.c b/third_party/python/Python/frozen.c index e79332dda..f9f445dff 100644 --- a/third_party/python/Python/frozen.c +++ b/third_party/python/Python/frozen.c @@ -1,9 +1,9 @@ -/* clang-format off */ -/* Dummy frozen modules initializer */ - -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Python/importlib.inc" #include "third_party/python/Python/importlib_external.inc" +/* clang-format off */ + +/* Dummy frozen modules initializer */ /* In order to test the support for frozen modules, by default we define a single frozen module, __hello__. Loading it will print diff --git a/third_party/python/Python/frozenmain.c b/third_party/python/Python/frozenmain.c index 7b6accdb3..5c2d1e18a 100644 --- a/third_party/python/Python/frozenmain.c +++ b/third_party/python/Python/frozenmain.c @@ -1,8 +1,15 @@ -/* clang-format off */ -/* Python interpreter main program for frozen scripts */ - -#include "third_party/python/Include/Python.h" +#include "libc/calls/calls.h" +#include "libc/stdio/stdio.h" #include "libc/unicode/locale.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/import.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/pythonrun.h" +#include "third_party/python/Include/sysmodule.h" +/* clang-format off */ #ifdef MS_WINDOWS extern void PyWinFreeze_ExeInit(void); @@ -10,8 +17,6 @@ extern void PyWinFreeze_ExeTerm(void); extern int PyInitFrozenExtensions(void); #endif -/* Main program */ - int Py_FrozenMain(int argc, char **argv) { diff --git a/third_party/python/Python/future.c b/third_party/python/Python/future.c index fff5a3a41..20553144e 100644 --- a/third_party/python/Python/future.c +++ b/third_party/python/Python/future.c @@ -1,12 +1,13 @@ -/* clang-format off */ - -#include "third_party/python/Include/Python.h" #include "third_party/python/Include/Python-ast.h" -#include "third_party/python/Include/node.h" -#include "third_party/python/Include/token.h" -#include "third_party/python/Include/graminit.h" #include "third_party/python/Include/code.h" +#include "third_party/python/Include/graminit.h" +#include "third_party/python/Include/node.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pyerrors.h" #include "third_party/python/Include/symtable.h" +#include "third_party/python/Include/token.h" +#include "third_party/python/Include/unicodeobject.h" +/* clang-format off */ #define UNDEFINED_FUTURE_FEATURE "future feature %.100s is not defined" #define ERR_LATE_FUTURE \ diff --git a/third_party/python/Python/getargs.c b/third_party/python/Python/getargs.c index 4359300ec..4a7793d4c 100644 --- a/third_party/python/Python/getargs.c +++ b/third_party/python/Python/getargs.c @@ -1,11 +1,21 @@ +#include "libc/assert.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/bytearrayobject.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/complexobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyctype.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" /* clang-format off */ + /* New getargs implementation */ -#include "third_party/python/Include/Python.h" - -#ifdef __cplusplus -extern "C" { -#endif int PyArg_Parse(PyObject *, const char *, ...); int PyArg_ParseTuple(PyObject *, const char *, ...); int PyArg_VaParse(PyObject *, const char *, va_list); @@ -22,20 +32,20 @@ int _PyArg_VaParseTupleAndKeywordsFast(PyObject *, PyObject *, #ifdef HAVE_DECLSPEC_DLL /* Export functions */ -PyAPI_FUNC(int) _PyArg_Parse_SizeT(PyObject *, const char *, ...); -PyAPI_FUNC(int) _PyArg_ParseStack_SizeT(PyObject **args, Py_ssize_t nargs, PyObject *kwnames, - struct _PyArg_Parser *parser, ...); -PyAPI_FUNC(int) _PyArg_ParseTuple_SizeT(PyObject *, const char *, ...); -PyAPI_FUNC(int) _PyArg_ParseTupleAndKeywords_SizeT(PyObject *, PyObject *, +int _PyArg_Parse_SizeT(PyObject *, const char *, ...); +int _PyArg_ParseStack_SizeT(PyObject **, Py_ssize_t , PyObject *, + struct _PyArg_Parser *, ...); +int _PyArg_ParseTuple_SizeT(PyObject *, const char *, ...); +int _PyArg_ParseTupleAndKeywords_SizeT(PyObject *, PyObject *, const char *, char **, ...); -PyAPI_FUNC(PyObject *) _Py_BuildValue_SizeT(const char *, ...); -PyAPI_FUNC(int) _PyArg_VaParse_SizeT(PyObject *, const char *, va_list); -PyAPI_FUNC(int) _PyArg_VaParseTupleAndKeywords_SizeT(PyObject *, PyObject *, +PyObject * _Py_BuildValue_SizeT(const char *, ...); +int _PyArg_VaParse_SizeT(PyObject *, const char *, va_list); +int _PyArg_VaParseTupleAndKeywords_SizeT(PyObject *, PyObject *, const char *, char **, va_list); -PyAPI_FUNC(int) _PyArg_ParseTupleAndKeywordsFast_SizeT(PyObject *, PyObject *, +int _PyArg_ParseTupleAndKeywordsFast_SizeT(PyObject *, PyObject *, struct _PyArg_Parser *, ...); -PyAPI_FUNC(int) _PyArg_VaParseTupleAndKeywordsFast_SizeT(PyObject *, PyObject *, +int _PyArg_VaParseTupleAndKeywordsFast_SizeT(PyObject *, PyObject *, struct _PyArg_Parser *, va_list); #endif @@ -275,7 +285,7 @@ vgetargs1(PyObject *args, const char *format, va_list *p_va, int flags) break; default: if (level == 0) { - if (Py_ISALPHA(Py_CHARMASK(c))) + if (Py_ISALPHA(c)) if (c != 'e') /* skip encoded */ max++; } @@ -368,7 +378,7 @@ vgetargs1(PyObject *args, const char *format, va_list *p_va, int flags) } } - if (*format != '\0' && !Py_ISALPHA(Py_CHARMASK(*format)) && + if (*format != '\0' && !Py_ISALPHA(*format) && *format != '(' && *format != '|' && *format != ':' && *format != ';') { PyErr_Format(PyExc_SystemError, @@ -467,7 +477,7 @@ converttuple(PyObject *arg, const char **p_format, va_list *p_va, int flags, } else if (c == ':' || c == ';' || c == '\0') break; - else if (level == 0 && Py_ISALPHA(Py_CHARMASK(c))) + else if (level == 0 && Py_ISALPHA(c)) n++; } @@ -2453,7 +2463,3 @@ _PyArg_Fini(void) } static_arg_parsers = NULL; } - -#ifdef __cplusplus -}; -#endif diff --git a/third_party/python/Python/getcompiler.c b/third_party/python/Python/getcompiler.c index 3648425c1..5eaa3bebe 100644 --- a/third_party/python/Python/getcompiler.c +++ b/third_party/python/Python/getcompiler.c @@ -1,9 +1,8 @@ +#include "third_party/python/Include/pylifecycle.h" /* clang-format off */ /* Return the compiler identification, if possible. */ -#include "third_party/python/Include/Python.h" - #ifndef COMPILER #ifdef __GNUC__ diff --git a/third_party/python/Python/getcopyright.c b/third_party/python/Python/getcopyright.c index 824e82044..ca1dee7dd 100644 --- a/third_party/python/Python/getcopyright.c +++ b/third_party/python/Python/getcopyright.c @@ -1,9 +1,8 @@ +#include "third_party/python/Include/pylifecycle.h" /* clang-format off */ /* Return the copyright string. This is updated manually. */ -#include "third_party/python/Include/Python.h" - static const char cprt[] = "\ Copyright (c) 2001-2021 Python Software Foundation.\n\ diff --git a/third_party/python/Python/getopt.c b/third_party/python/Python/getopt.c index d06f5c481..b078b7da3 100644 --- a/third_party/python/Python/getopt.c +++ b/third_party/python/Python/getopt.c @@ -1,3 +1,6 @@ +#include "libc/stdio/stdio.h" +#include "libc/str/str.h" +#include "third_party/python/Include/pygetopt.h" /* clang-format off */ /*---------------------------------------------------------------------------* * @@ -28,13 +31,6 @@ /* Modified to support --help and --version, as well as /? on Windows * by Georg Brandl. */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/pygetopt.h" - -#ifdef __cplusplus -extern "C" { -#endif - int _PyOS_opterr = 1; /* generate error messages */ int _PyOS_optind = 1; /* index into argv array */ wchar_t *_PyOS_optarg = NULL; /* optional argument */ @@ -123,7 +119,3 @@ int _PyOS_GetOpt(int argc, wchar_t **argv, wchar_t *optstring) return option; } - -#ifdef __cplusplus -} -#endif diff --git a/third_party/python/Python/getplatform.c b/third_party/python/Python/getplatform.c index 35f721598..006c70004 100644 --- a/third_party/python/Python/getplatform.c +++ b/third_party/python/Python/getplatform.c @@ -1,5 +1,4 @@ /* clang-format off */ -#include "third_party/python/Include/Python.h" #ifndef PLATFORM #define PLATFORM "unknown" diff --git a/third_party/python/Python/getversion.c b/third_party/python/Python/getversion.c index 148e58883..5879086bd 100644 --- a/third_party/python/Python/getversion.c +++ b/third_party/python/Python/getversion.c @@ -1,7 +1,9 @@ -/* clang-format off */ -/* Return the full version string. */ -#include "third_party/python/Include/Python.h" #include "third_party/python/Include/patchlevel.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pylifecycle.h" +/* clang-format off */ + +/* Return the full version string. */ const char * Py_GetVersion(void) diff --git a/third_party/python/Python/graminit.c b/third_party/python/Python/graminit.c index b5f869091..0b149ef9f 100644 --- a/third_party/python/Python/graminit.c +++ b/third_party/python/Python/graminit.c @@ -2,7 +2,7 @@ /* Generated by Parser/pgen */ #include "third_party/python/Include/pgenheaders.h" #include "third_party/python/Include/grammar.h" -PyAPI_DATA(grammar) _PyParser_Grammar; +extern grammar _PyParser_Grammar; static arc arcs_0_0[3] = { {2, 1}, {3, 1}, diff --git a/third_party/python/Python/import.c b/third_party/python/Python/import.c index 02b47a4d9..67bc63251 100644 --- a/third_party/python/Python/import.c +++ b/third_party/python/Python/import.c @@ -1,12 +1,31 @@ -#include "third_party/python/Include/Python.h" -/**/ #include "third_party/python/Include/Python-ast.h" -#undef Yield /* undefine macro conflicting with winbase.h */ +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/ceval.h" #include "third_party/python/Include/code.h" +#include "third_party/python/Include/dictobject.h" #include "third_party/python/Include/errcode.h" +#include "third_party/python/Include/eval.h" +#include "third_party/python/Include/fileutils.h" #include "third_party/python/Include/frameobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" #include "third_party/python/Include/marshal.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" #include "third_party/python/Include/osdefs.h" +#include "third_party/python/Include/pgenheaders.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/pymacro.h" +#include "third_party/python/Include/pythonrun.h" +#include "third_party/python/Include/sysmodule.h" +#include "third_party/python/Include/traceback.h" +#include "third_party/python/Include/tupleobject.h" +#include "third_party/python/Include/warnings.h" +#include "third_party/python/Include/weakrefobject.h" #include "third_party/python/Python/importdl.h" /* clang-format off */ @@ -1008,7 +1027,7 @@ get_path_importer(PyObject *path_importer_cache, PyObject *path_hooks, return importer; } -PyAPI_FUNC(PyObject *) +PyObject * PyImport_GetImporter(PyObject *path) { PyObject *importer=NULL, *path_importer_cache=NULL, *path_hooks=NULL; diff --git a/third_party/python/Python/importdl.c b/third_party/python/Python/importdl.c index ae56ce2dd..b696aaf9a 100644 --- a/third_party/python/Python/importdl.c +++ b/third_party/python/Python/importdl.c @@ -1,6 +1,14 @@ +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/moduleobject.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/unicodeobject.h" +#include "third_party/python/Python/importdl.h" /* clang-format off */ + /* Support for dynamic loading of extension modules */ -#include "third_party/python/Include/Python.h" /* ./configure sets HAVE_DYNAMIC_LOADING if dynamic loading of modules is supported on this platform. configure will then compile and link in one @@ -9,8 +17,6 @@ */ #ifdef HAVE_DYNAMIC_LOADING -#include "third_party/python/Python/importdl.h" - #ifdef MS_WINDOWS extern dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix, const char *shortname, diff --git a/third_party/python/Python/importdl.h b/third_party/python/Python/importdl.h index 65def0396..1bf83c33e 100644 --- a/third_party/python/Python/importdl.h +++ b/third_party/python/Python/importdl.h @@ -1,9 +1,7 @@ #ifndef Py_IMPORTDL_H #define Py_IMPORTDL_H - -#ifdef __cplusplus -extern "C" { -#endif +#include "third_party/python/Include/object.h" +COSMOPOLITAN_C_START_ extern const char *_PyImport_DynLoadFiletab[]; @@ -14,7 +12,5 @@ extern PyObject *_PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *); typedef void (*dl_funcptr)(void); -#ifdef __cplusplus -} -#endif +COSMOPOLITAN_C_END_ #endif /* !Py_IMPORTDL_H */ diff --git a/third_party/python/Python/marshal.c b/third_party/python/Python/marshal.c index cd4302c14..18999f4e4 100644 --- a/third_party/python/Python/marshal.c +++ b/third_party/python/Python/marshal.c @@ -1,6 +1,30 @@ +#define PY_SSIZE_T_CLEAN +#include "dsp/mpeg/video.h" +#include "libc/calls/calls.h" +#include "libc/calls/weirdtypes.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/code.h" +#include "third_party/python/Include/complexobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longintrepr.h" +#include "third_party/python/Include/marshal.h" +#include "third_party/python/Include/memoryobject.h" +#include "third_party/python/Include/methodobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pystrtod.h" +#include "third_party/python/Include/setobject.h" +#include "third_party/python/Include/sliceobject.h" +#include "third_party/python/Include/tupleobject.h" +#include "third_party/python/Modules/hashtable.h" /* clang-format off */ - /* Write Python objects to files and read them back. This is primarily intended for writing and reading compiled Python code, even though dicts, lists, sets and frozensets, not commonly seen in @@ -8,14 +32,6 @@ Version 3 of this protocol properly supports circular links and sharing. */ -#define PY_SSIZE_T_CLEAN - -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/longintrepr.h" -#include "third_party/python/Include/code.h" -#include "third_party/python/Include/marshal.h" -#include "third_party/python/Modules/hashtable.h" - /* High water mark to determine when the marshalled object is dangerously deep * and risks coring the interpreter. When the object stack gets this deep, * raise an exception instead of continuing. @@ -613,7 +629,7 @@ PyMarshal_WriteLongToFile(long x, FILE *fp, int version) { char buf[4]; WFILE wf; - memset(&wf, 0, sizeof(wf)); + bzero(&wf, sizeof(wf)); wf.fp = fp; wf.ptr = wf.buf = buf; wf.end = wf.ptr + sizeof(buf); @@ -628,7 +644,7 @@ PyMarshal_WriteObjectToFile(PyObject *x, FILE *fp, int version) { char buf[BUFSIZ]; WFILE wf; - memset(&wf, 0, sizeof(wf)); + bzero(&wf, sizeof(wf)); wf.fp = fp; wf.ptr = wf.buf = buf; wf.end = wf.ptr + sizeof(buf); @@ -1620,7 +1636,7 @@ PyMarshal_WriteObjectToString(PyObject *x, int version) { WFILE wf; - memset(&wf, 0, sizeof(wf)); + bzero(&wf, sizeof(wf)); wf.str = PyBytes_FromStringAndSize((char *)NULL, 50); if (wf.str == NULL) return NULL; diff --git a/third_party/python/Python/modsupport.c b/third_party/python/Python/modsupport.c index a0019cce0..e5c843c2b 100644 --- a/third_party/python/Python/modsupport.c +++ b/third_party/python/Python/modsupport.c @@ -1,6 +1,16 @@ +#include "libc/assert.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/complexobject.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/tupleobject.h" /* clang-format off */ + /* Module support implementation */ -#include "third_party/python/Include/Python.h" #define FLAG_SIZE_T 1 typedef double va_double; diff --git a/third_party/python/Python/mysnprintf.c b/third_party/python/Python/mysnprintf.c index 8ea401f6f..9bc535e71 100644 --- a/third_party/python/Python/mysnprintf.c +++ b/third_party/python/Python/mysnprintf.c @@ -1,7 +1,8 @@ +#include "libc/assert.h" +#include "libc/fmt/fmt.h" +#include "third_party/python/Include/pyerrors.h" /* clang-format off */ -#include "third_party/python/Include/Python.h" - /* snprintf() wrappers. If the platform has vsnprintf, we use it, else we emulate it in a half-hearted way. Even if the platform has it, we wrap it because platforms differ in what vsnprintf does in case the buffer diff --git a/third_party/python/Python/mystrtoul.c b/third_party/python/Python/mystrtoul.c index 2957ab5ae..ecab76377 100644 --- a/third_party/python/Python/mystrtoul.c +++ b/third_party/python/Python/mystrtoul.c @@ -1,9 +1,10 @@ +#include "libc/errno.h" +#include "libc/limits.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/pyctype.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/pyconfig.h" /* clang-format off */ -#include "third_party/python/Include/Python.h" - -#if defined(__sgi) && defined(WITH_THREAD) && !defined(_SGI_MP_SOURCE) -#define _SGI_MP_SOURCE -#endif /* Static overflow check values for bases 2 through 36. * smallmax[base] is the largest unsigned long i such that diff --git a/third_party/python/Python/peephole.c b/third_party/python/Python/peephole.c index b31ffe0cd..8e825cdf3 100644 --- a/third_party/python/Python/peephole.c +++ b/third_party/python/Python/peephole.c @@ -1,13 +1,23 @@ -/* clang-format off */ -/* Peephole optimizations for bytecode compiler. */ -#include "third_party/python/Include/Python.h" #include "third_party/python/Include/Python-ast.h" -#include "third_party/python/Include/node.h" +#include "third_party/python/Include/abstract.h" #include "third_party/python/Include/ast.h" +#include "third_party/python/Include/bytesobject.h" #include "third_party/python/Include/code.h" -#include "third_party/python/Include/symtable.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/node.h" #include "third_party/python/Include/opcode.h" -#include "third_party/python/Python/wordcode_helpers.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/setobject.h" +#include "third_party/python/Include/symtable.h" +#include "third_party/python/Include/tupleobject.h" +#include "third_party/python/Include/unicodeobject.h" +#include "third_party/python/Python/wordcode_helpers.inc" +#include "third_party/quickjs/internal.h" +/* clang-format off */ + +/* Peephole optimizations for bytecode compiler. */ #define UNCONDITIONAL_JUMP(op) (op==JUMP_ABSOLUTE || op==JUMP_FORWARD) #define CONDITIONAL_JUMP(op) (op==POP_JUMP_IF_FALSE || op==POP_JUMP_IF_TRUE \ @@ -490,7 +500,7 @@ markblocks(_Py_CODEUNIT *code, Py_ssize_t len) PyErr_NoMemory(); return NULL; } - memset(blocks, 0, len*sizeof(int)); + bzero(blocks, len*sizeof(int)); /* Mark labels in the first pass */ for (i = 0; i < len; i++) { diff --git a/third_party/python/Python/pyarena.c b/third_party/python/Python/pyarena.c index bfb065dc3..094214f69 100644 --- a/third_party/python/Python/pyarena.c +++ b/third_party/python/Python/pyarena.c @@ -1,5 +1,12 @@ +#include "libc/assert.h" +#include "libc/mem/mem.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyarena.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" /* clang-format off */ -#include "third_party/python/Include/Python.h" /* A simple arena block structure. diff --git a/third_party/python/Python/pyctype.c b/third_party/python/Python/pyctype.c deleted file mode 100644 index d5ee224ae..000000000 --- a/third_party/python/Python/pyctype.c +++ /dev/null @@ -1,215 +0,0 @@ -/* clang-format off */ -#include "third_party/python/Include/Python.h" - -/* Our own locale-independent ctype.h-like macros */ - -const unsigned int _Py_ctype_table[256] = { - 0, /* 0x0 '\x00' */ - 0, /* 0x1 '\x01' */ - 0, /* 0x2 '\x02' */ - 0, /* 0x3 '\x03' */ - 0, /* 0x4 '\x04' */ - 0, /* 0x5 '\x05' */ - 0, /* 0x6 '\x06' */ - 0, /* 0x7 '\x07' */ - 0, /* 0x8 '\x08' */ - PY_CTF_SPACE, /* 0x9 '\t' */ - PY_CTF_SPACE, /* 0xa '\n' */ - PY_CTF_SPACE, /* 0xb '\v' */ - PY_CTF_SPACE, /* 0xc '\f' */ - PY_CTF_SPACE, /* 0xd '\r' */ - 0, /* 0xe '\x0e' */ - 0, /* 0xf '\x0f' */ - 0, /* 0x10 '\x10' */ - 0, /* 0x11 '\x11' */ - 0, /* 0x12 '\x12' */ - 0, /* 0x13 '\x13' */ - 0, /* 0x14 '\x14' */ - 0, /* 0x15 '\x15' */ - 0, /* 0x16 '\x16' */ - 0, /* 0x17 '\x17' */ - 0, /* 0x18 '\x18' */ - 0, /* 0x19 '\x19' */ - 0, /* 0x1a '\x1a' */ - 0, /* 0x1b '\x1b' */ - 0, /* 0x1c '\x1c' */ - 0, /* 0x1d '\x1d' */ - 0, /* 0x1e '\x1e' */ - 0, /* 0x1f '\x1f' */ - PY_CTF_SPACE, /* 0x20 ' ' */ - 0, /* 0x21 '!' */ - 0, /* 0x22 '"' */ - 0, /* 0x23 '#' */ - 0, /* 0x24 '$' */ - 0, /* 0x25 '%' */ - 0, /* 0x26 '&' */ - 0, /* 0x27 "'" */ - 0, /* 0x28 '(' */ - 0, /* 0x29 ')' */ - 0, /* 0x2a '*' */ - 0, /* 0x2b '+' */ - 0, /* 0x2c ',' */ - 0, /* 0x2d '-' */ - 0, /* 0x2e '.' */ - 0, /* 0x2f '/' */ - PY_CTF_DIGIT|PY_CTF_XDIGIT, /* 0x30 '0' */ - PY_CTF_DIGIT|PY_CTF_XDIGIT, /* 0x31 '1' */ - PY_CTF_DIGIT|PY_CTF_XDIGIT, /* 0x32 '2' */ - PY_CTF_DIGIT|PY_CTF_XDIGIT, /* 0x33 '3' */ - PY_CTF_DIGIT|PY_CTF_XDIGIT, /* 0x34 '4' */ - PY_CTF_DIGIT|PY_CTF_XDIGIT, /* 0x35 '5' */ - PY_CTF_DIGIT|PY_CTF_XDIGIT, /* 0x36 '6' */ - PY_CTF_DIGIT|PY_CTF_XDIGIT, /* 0x37 '7' */ - PY_CTF_DIGIT|PY_CTF_XDIGIT, /* 0x38 '8' */ - PY_CTF_DIGIT|PY_CTF_XDIGIT, /* 0x39 '9' */ - 0, /* 0x3a ':' */ - 0, /* 0x3b ';' */ - 0, /* 0x3c '<' */ - 0, /* 0x3d '=' */ - 0, /* 0x3e '>' */ - 0, /* 0x3f '?' */ - 0, /* 0x40 '@' */ - PY_CTF_UPPER|PY_CTF_XDIGIT, /* 0x41 'A' */ - PY_CTF_UPPER|PY_CTF_XDIGIT, /* 0x42 'B' */ - PY_CTF_UPPER|PY_CTF_XDIGIT, /* 0x43 'C' */ - PY_CTF_UPPER|PY_CTF_XDIGIT, /* 0x44 'D' */ - PY_CTF_UPPER|PY_CTF_XDIGIT, /* 0x45 'E' */ - PY_CTF_UPPER|PY_CTF_XDIGIT, /* 0x46 'F' */ - PY_CTF_UPPER, /* 0x47 'G' */ - PY_CTF_UPPER, /* 0x48 'H' */ - PY_CTF_UPPER, /* 0x49 'I' */ - PY_CTF_UPPER, /* 0x4a 'J' */ - PY_CTF_UPPER, /* 0x4b 'K' */ - PY_CTF_UPPER, /* 0x4c 'L' */ - PY_CTF_UPPER, /* 0x4d 'M' */ - PY_CTF_UPPER, /* 0x4e 'N' */ - PY_CTF_UPPER, /* 0x4f 'O' */ - PY_CTF_UPPER, /* 0x50 'P' */ - PY_CTF_UPPER, /* 0x51 'Q' */ - PY_CTF_UPPER, /* 0x52 'R' */ - PY_CTF_UPPER, /* 0x53 'S' */ - PY_CTF_UPPER, /* 0x54 'T' */ - PY_CTF_UPPER, /* 0x55 'U' */ - PY_CTF_UPPER, /* 0x56 'V' */ - PY_CTF_UPPER, /* 0x57 'W' */ - PY_CTF_UPPER, /* 0x58 'X' */ - PY_CTF_UPPER, /* 0x59 'Y' */ - PY_CTF_UPPER, /* 0x5a 'Z' */ - 0, /* 0x5b '[' */ - 0, /* 0x5c '\\' */ - 0, /* 0x5d ']' */ - 0, /* 0x5e '^' */ - 0, /* 0x5f '_' */ - 0, /* 0x60 '`' */ - PY_CTF_LOWER|PY_CTF_XDIGIT, /* 0x61 'a' */ - PY_CTF_LOWER|PY_CTF_XDIGIT, /* 0x62 'b' */ - PY_CTF_LOWER|PY_CTF_XDIGIT, /* 0x63 'c' */ - PY_CTF_LOWER|PY_CTF_XDIGIT, /* 0x64 'd' */ - PY_CTF_LOWER|PY_CTF_XDIGIT, /* 0x65 'e' */ - PY_CTF_LOWER|PY_CTF_XDIGIT, /* 0x66 'f' */ - PY_CTF_LOWER, /* 0x67 'g' */ - PY_CTF_LOWER, /* 0x68 'h' */ - PY_CTF_LOWER, /* 0x69 'i' */ - PY_CTF_LOWER, /* 0x6a 'j' */ - PY_CTF_LOWER, /* 0x6b 'k' */ - PY_CTF_LOWER, /* 0x6c 'l' */ - PY_CTF_LOWER, /* 0x6d 'm' */ - PY_CTF_LOWER, /* 0x6e 'n' */ - PY_CTF_LOWER, /* 0x6f 'o' */ - PY_CTF_LOWER, /* 0x70 'p' */ - PY_CTF_LOWER, /* 0x71 'q' */ - PY_CTF_LOWER, /* 0x72 'r' */ - PY_CTF_LOWER, /* 0x73 's' */ - PY_CTF_LOWER, /* 0x74 't' */ - PY_CTF_LOWER, /* 0x75 'u' */ - PY_CTF_LOWER, /* 0x76 'v' */ - PY_CTF_LOWER, /* 0x77 'w' */ - PY_CTF_LOWER, /* 0x78 'x' */ - PY_CTF_LOWER, /* 0x79 'y' */ - PY_CTF_LOWER, /* 0x7a 'z' */ - 0, /* 0x7b '{' */ - 0, /* 0x7c '|' */ - 0, /* 0x7d '}' */ - 0, /* 0x7e '~' */ - 0, /* 0x7f '\x7f' */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -}; - - -const unsigned char _Py_ctype_tolower[256] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, - 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, - 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, - 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, - 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, - 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, - 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, - 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, - 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, - 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, - 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, - 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, - 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, - 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, - 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, -}; - -const unsigned char _Py_ctype_toupper[256] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, - 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, - 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, - 0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, - 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, - 0x58, 0x59, 0x5a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, - 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, - 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, - 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, - 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, - 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, - 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, - 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, - 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, - 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, - 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, - 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, - 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, - 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, - 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, -}; - diff --git a/third_party/python/Python/pyhash.c b/third_party/python/Python/pyhash.c index 364214f2b..995e479fb 100644 --- a/third_party/python/Python/pyhash.c +++ b/third_party/python/Python/pyhash.c @@ -1,13 +1,10 @@ +#include "third_party/python/Include/pyhash.h" /* clang-format off */ + /* Set of hash utility functions to help maintaining the invariant that if a==b then hash(a)==hash(b) All the utility functions (_Py_Hash*()) return "-1" to signify an error. */ -#include "third_party/python/Include/Python.h" - -#ifdef __cplusplus -extern "C" { -#endif _Py_HashSecret_t _Py_HashSecret; @@ -410,7 +407,3 @@ siphash24(const void *src, Py_ssize_t src_sz) { static PyHash_FuncDef PyHash_Func = {siphash24, "siphash24", 64, 128}; #endif /* Py_HASH_ALGORITHM == Py_HASH_SIPHASH24 */ - -#ifdef __cplusplus -} -#endif diff --git a/third_party/python/Python/pylifecycle.c b/third_party/python/Python/pylifecycle.c index d819bfedb..98a45d73d 100644 --- a/third_party/python/Python/pylifecycle.c +++ b/third_party/python/Python/pylifecycle.c @@ -1,20 +1,53 @@ -/* clang-format off */ -/* Python interpreter top-level routines, including init/exit */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/Python-ast.h" -#undef Yield /* undefine macro conflicting with winbase.h */ -#include "third_party/python/Include/grammar.h" -#include "third_party/python/Include/node.h" -#include "third_party/python/Include/token.h" -#include "third_party/python/Include/parsetok.h" -#include "third_party/python/Include/errcode.h" -#include "third_party/python/Include/code.h" -#include "third_party/python/Include/symtable.h" -#include "third_party/python/Include/ast.h" -#include "third_party/python/Include/marshal.h" -#include "third_party/python/Include/osdefs.h" -#include "libc/unicode/locale.h" +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Python 3 │ +│ https://docs.python.org/3/license.html │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/assert.h" +#include "libc/calls/calls.h" +#include "libc/calls/internal.h" #include "libc/calls/sigbits.h" +#include "libc/dce.h" +#include "libc/fmt/conv.h" +#include "libc/log/check.h" +#include "libc/log/log.h" +#include "libc/runtime/runtime.h" +#include "libc/stdio/stdio.h" +#include "libc/unicode/locale.h" +#include "third_party/python/Include/Python-ast.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/ast.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/code.h" +#include "third_party/python/Include/codecs.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/errcode.h" +#include "third_party/python/Include/fileobject.h" +#include "third_party/python/Include/grammar.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/intrcheck.h" +#include "third_party/python/Include/marshal.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/node.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/osdefs.h" +#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" +#include "third_party/python/Include/symtable.h" +#include "third_party/python/Include/sysmodule.h" +#include "third_party/python/Include/token.h" +#include "third_party/python/Include/traceback.h" +#include "third_party/python/Include/unicodeobject.h" +#include "third_party/python/Include/warnings.h" +/* clang-format off */ + +/* Python interpreter top-level routines, including init/exit */ _Py_IDENTIFIER(flush); _Py_IDENTIFIER(name); @@ -22,8 +55,6 @@ _Py_IDENTIFIER(stdin); _Py_IDENTIFIER(stdout); _Py_IDENTIFIER(stderr); -extern wchar_t *Py_GetPath(void); - extern grammar _PyParser_Grammar; /* From graminit.c */ /* Forward */ @@ -212,7 +243,7 @@ get_locale_encoding(void) return NULL; } return get_codec_name(codeset); -#elif 1 || defined(__ANDROID__) +#elif defined(__ANDROID__) || defined(__COSMOPOLITAN__) return get_codec_name("UTF-8"); #else PyErr_SetNone(PyExc_NotImplementedError); @@ -422,9 +453,10 @@ _Py_InitializeEx_Private(int install_sigs, int install_importlib) Py_FatalError("Py_Initialize: can't initialize tracemalloc"); initmain(interp); /* Module __main__ */ - if (initstdio() < 0) + if (initstdio() < 0) { Py_FatalError( "Py_Initialize: can't initialize sys standard streams"); + } /* Initialize warnings. */ if (PySys_HasWarnOptions()) { @@ -976,7 +1008,6 @@ initfsencoding(PyInterpreterState *interp) Py_FileSystemDefaultEncoding = get_locale_encoding(); if (Py_FileSystemDefaultEncoding == NULL) Py_FatalError("Py_Initialize: Unable to get the locale encoding"); - Py_HasFileSystemDefaultEncoding = 0; interp->fscodec_initialized = 1; return 0; @@ -1019,14 +1050,17 @@ initsite(void) static int is_valid_fd(int fd) { -#ifdef __APPLE__ - /* bpo-30225: On macOS Tiger, when stdout is redirected to a pipe - and the other side of the pipe is closed, dup(1) succeed, whereas - fstat(1, &st) fails with EBADF. Prefer fstat() over dup() to detect - such error. */ - struct stat st; - return (fstat(fd, &st) == 0); -#else + if (IsWindows()) { + return __isfdopen(fd); + } + if (IsXnu()) { + /* bpo-30225: On macOS Tiger, when stdout is redirected to a pipe + and the other side of the pipe is closed, dup(1) succeed, whereas + fstat(1, &st) fails with EBADF. Prefer fstat() over dup() to detect + such error. */ + struct stat st; + return (fstat(fd, &st) == 0); + } int fd2; if (fd < 0) return 0; @@ -1039,7 +1073,6 @@ is_valid_fd(int fd) close(fd2); _Py_END_SUPPRESS_IPH return fd2 >= 0; -#endif } /* returns Py_None if the fd is not valid */ @@ -1454,7 +1487,7 @@ exit: #if defined(MS_WINDOWS) && defined(_DEBUG) DebugBreak(); #endif - abort(); + __die(); } /* Clean up and exit */ diff --git a/third_party/python/Python/pymath.c b/third_party/python/Python/pymath.c index 457ad71d8..f9ded77a5 100644 --- a/third_party/python/Python/pymath.c +++ b/third_party/python/Python/pymath.c @@ -1,5 +1,5 @@ +#include "third_party/python/pyconfig.h" /* clang-format off */ -#include "third_party/python/Include/Python.h" #ifdef X87_DOUBLE_ROUNDING /* On x86 platforms using an x87 FPU, this function is called from the @@ -28,4 +28,6 @@ unsigned short _Py_get_387controlword(void) { void _Py_set_387controlword(unsigned short cw) { __asm__ __volatile__ ("fldcw %0" : : "m" (cw)); } +#else +#error wut #endif diff --git a/third_party/python/Python/pystate.c b/third_party/python/Python/pystate.c index 22f185caf..95a119db1 100644 --- a/third_party/python/Python/pystate.c +++ b/third_party/python/Python/pystate.c @@ -1,7 +1,16 @@ #include "libc/bits/pushpop.h" #include "libc/runtime/dlfcn.h" -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/pyatomic.h" +#include "third_party/python/Include/pydebug.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pystate.h" /* clang-format off */ + /* Thread and interpreter state structures and their interfaces */ #define ZERO(x) x = (typeof(x))pushpop(0L) diff --git a/third_party/python/Python/pystrcmp.c b/third_party/python/Python/pystrcmp.c index 271a28b70..3f9e30cd8 100644 --- a/third_party/python/Python/pystrcmp.c +++ b/third_party/python/Python/pystrcmp.c @@ -1,28 +1,27 @@ +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyctype.h" /* clang-format off */ /* Cross platform case insensitive string compare functions */ -#include "third_party/python/Include/Python.h" - int PyOS_mystrnicmp(const char *s1, const char *s2, Py_ssize_t size) { if (size == 0) return 0; while ((--size > 0) && - (tolower((unsigned)*s1) == tolower((unsigned)*s2))) { + (Py_TOLOWER(*s1) == Py_TOLOWER(*s2))) { if (!*s1++ || !*s2++) break; } - return tolower((unsigned)*s1) - tolower((unsigned)*s2); + return Py_TOLOWER(*s1) - Py_TOLOWER(*s2); } int PyOS_mystricmp(const char *s1, const char *s2) { - while (*s1 && (tolower((unsigned)*s1++) == tolower((unsigned)*s2++))) { - ; + while (*s1 && (Py_TOLOWER((unsigned)*s1++) == Py_TOLOWER((unsigned)*s2++))) { } - return (tolower((unsigned)*s1) - tolower((unsigned)*s2)); + return (Py_TOLOWER((unsigned)*s1) - Py_TOLOWER((unsigned)*s2)); } diff --git a/third_party/python/Python/pystrhex.c b/third_party/python/Python/pystrhex.c index bbe8e54bf..b044780c9 100644 --- a/third_party/python/Python/pystrhex.c +++ b/third_party/python/Python/pystrhex.c @@ -1,6 +1,13 @@ +#include "libc/assert.h" +#include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/codecs.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/unicodeobject.h" /* clang-format off */ + /* bytes to hex implementation */ -#include "third_party/python/Include/Python.h" static PyObject *_Py_strhex_impl(const char* argbuf, const Py_ssize_t arglen, int return_bytes) @@ -48,14 +55,14 @@ static PyObject *_Py_strhex_impl(const char* argbuf, const Py_ssize_t arglen, return retval; } -PyAPI_FUNC(PyObject *) _Py_strhex(const char* argbuf, const Py_ssize_t arglen) +PyObject * _Py_strhex(const char* argbuf, const Py_ssize_t arglen) { return _Py_strhex_impl(argbuf, arglen, 0); } /* Same as above but returns a bytes() instead of str() to avoid the * need to decode the str() when bytes are needed. */ -PyAPI_FUNC(PyObject *) _Py_strhex_bytes(const char* argbuf, const Py_ssize_t arglen) +PyObject * _Py_strhex_bytes(const char* argbuf, const Py_ssize_t arglen) { return _Py_strhex_impl(argbuf, arglen, 1); } diff --git a/third_party/python/Python/pystrtod.c b/third_party/python/Python/pystrtod.c index 8a7b22aac..6c8f9b514 100644 --- a/third_party/python/Python/pystrtod.c +++ b/third_party/python/Python/pystrtod.c @@ -1,7 +1,16 @@ -/* clang-format off */ -/* -*- Mode: C; c-file-style: "python" -*- */ -#include "third_party/python/Include/Python.h" +#include "libc/assert.h" +#include "libc/errno.h" +#include "libc/fmt/fmt.h" #include "libc/unicode/locale.h" +#include "third_party/python/Include/dtoa.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyctype.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pyfpe.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pyport.h" +#include "third_party/python/Include/pystrtod.h" +/* clang-format off */ /* Case-insensitive string match used for nan and inf detection; t should be lower-case. Returns 1 for a successful match, 0 otherwise. */ @@ -793,7 +802,7 @@ _PyOS_ascii_formatd(char *buffer, /* The fallback code to use if _Py_dg_dtoa is not available. */ -PyAPI_FUNC(char *) PyOS_double_to_string(double val, +char * PyOS_double_to_string(double val, char format_code, int precision, int flags, @@ -1240,7 +1249,7 @@ format_float_short(double d, char format_code, } -PyAPI_FUNC(char *) PyOS_double_to_string(double val, +char * PyOS_double_to_string(double val, char format_code, int precision, int flags, diff --git a/third_party/python/Python/pythonrun.c b/third_party/python/Python/pythonrun.c index edba0946b..7524d9cd8 100644 --- a/third_party/python/Python/pythonrun.c +++ b/third_party/python/Python/pythonrun.c @@ -1,19 +1,34 @@ -/* clang-format off */ -/* Python interpreter top-level routines, including init/exit */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/Python-ast.h" -#undef Yield /* undefine macro conflicting with winbase.h */ -#include "third_party/python/Include/grammar.h" -#include "third_party/python/Include/node.h" -#include "third_party/python/Include/token.h" -#include "third_party/python/Include/parsetok.h" -#include "third_party/python/Include/errcode.h" -#include "third_party/python/Include/code.h" -#include "third_party/python/Include/symtable.h" -#include "third_party/python/Include/ast.h" -#include "third_party/python/Include/marshal.h" -#include "third_party/python/Include/osdefs.h" #include "libc/unicode/locale.h" +#include "third_party/python/Include/Python-ast.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/ast.h" +#include "third_party/python/Include/code.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/errcode.h" +#include "third_party/python/Include/eval.h" +#include "third_party/python/Include/fileobject.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/grammar.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/marshal.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/node.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/osdefs.h" +#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/setobject.h" +#include "third_party/python/Include/symtable.h" +#include "third_party/python/Include/sysmodule.h" +#include "third_party/python/Include/token.h" +#include "third_party/python/Include/traceback.h" +#include "third_party/python/Include/unicodeobject.h" +/* clang-format off */ + +/* Python interpreter top-level routines, including init/exit */ _Py_IDENTIFIER(builtins); _Py_IDENTIFIER(excepthook); @@ -1459,56 +1474,56 @@ PyOS_CheckStack(void) /* Deprecated C API functions still provided for binary compatibility */ #undef PyParser_SimpleParseFile -PyAPI_FUNC(node *) +node * PyParser_SimpleParseFile(FILE *fp, const char *filename, int start) { return PyParser_SimpleParseFileFlags(fp, filename, start, 0); } #undef PyParser_SimpleParseString -PyAPI_FUNC(node *) +node * PyParser_SimpleParseString(const char *str, int start) { return PyParser_SimpleParseStringFlags(str, start, 0); } #undef PyRun_AnyFile -PyAPI_FUNC(int) +int PyRun_AnyFile(FILE *fp, const char *name) { return PyRun_AnyFileExFlags(fp, name, 0, NULL); } #undef PyRun_AnyFileEx -PyAPI_FUNC(int) +int PyRun_AnyFileEx(FILE *fp, const char *name, int closeit) { return PyRun_AnyFileExFlags(fp, name, closeit, NULL); } #undef PyRun_AnyFileFlags -PyAPI_FUNC(int) +int PyRun_AnyFileFlags(FILE *fp, const char *name, PyCompilerFlags *flags) { return PyRun_AnyFileExFlags(fp, name, 0, flags); } #undef PyRun_File -PyAPI_FUNC(PyObject *) +PyObject * PyRun_File(FILE *fp, const char *p, int s, PyObject *g, PyObject *l) { return PyRun_FileExFlags(fp, p, s, g, l, 0, NULL); } #undef PyRun_FileEx -PyAPI_FUNC(PyObject *) +PyObject * PyRun_FileEx(FILE *fp, const char *p, int s, PyObject *g, PyObject *l, int c) { return PyRun_FileExFlags(fp, p, s, g, l, c, NULL); } #undef PyRun_FileFlags -PyAPI_FUNC(PyObject *) +PyObject * PyRun_FileFlags(FILE *fp, const char *p, int s, PyObject *g, PyObject *l, PyCompilerFlags *flags) { @@ -1516,14 +1531,14 @@ PyRun_FileFlags(FILE *fp, const char *p, int s, PyObject *g, PyObject *l, } #undef PyRun_SimpleFile -PyAPI_FUNC(int) +int PyRun_SimpleFile(FILE *f, const char *p) { return PyRun_SimpleFileExFlags(f, p, 0, NULL); } #undef PyRun_SimpleFileEx -PyAPI_FUNC(int) +int PyRun_SimpleFileEx(FILE *f, const char *p, int c) { return PyRun_SimpleFileExFlags(f, p, c, NULL); @@ -1531,28 +1546,28 @@ PyRun_SimpleFileEx(FILE *f, const char *p, int c) #undef PyRun_String -PyAPI_FUNC(PyObject *) +PyObject * PyRun_String(const char *str, int s, PyObject *g, PyObject *l) { return PyRun_StringFlags(str, s, g, l, NULL); } #undef PyRun_SimpleString -PyAPI_FUNC(int) +int PyRun_SimpleString(const char *s) { return PyRun_SimpleStringFlags(s, NULL); } #undef Py_CompileString -PyAPI_FUNC(PyObject *) +PyObject * Py_CompileString(const char *str, const char *p, int s) { return Py_CompileStringExFlags(str, p, s, NULL, -1); } #undef Py_CompileStringFlags -PyAPI_FUNC(PyObject *) +PyObject * Py_CompileStringFlags(const char *str, const char *p, int s, PyCompilerFlags *flags) { @@ -1560,14 +1575,14 @@ Py_CompileStringFlags(const char *str, const char *p, int s, } #undef PyRun_InteractiveOne -PyAPI_FUNC(int) +int PyRun_InteractiveOne(FILE *f, const char *p) { return PyRun_InteractiveOneFlags(f, p, NULL); } #undef PyRun_InteractiveLoop -PyAPI_FUNC(int) +int PyRun_InteractiveLoop(FILE *f, const char *p) { return PyRun_InteractiveLoopFlags(f, p, NULL); diff --git a/third_party/python/Python/pytime.c b/third_party/python/Python/pytime.c index 83659bfc5..fc0e1c31a 100644 --- a/third_party/python/Python/pytime.c +++ b/third_party/python/Python/pytime.c @@ -1,5 +1,15 @@ +#include "libc/calls/weirdtypes.h" +#include "libc/math.h" +#include "libc/sysv/consts/clock.h" +#include "libc/time/time.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymath.h" +#include "third_party/python/Include/pytime.h" /* clang-format off */ -#include "third_party/python/Include/Python.h" #define _PyTime_check_mul_overflow(a, b) \ (assert(b > 0), \ diff --git a/third_party/python/Python/random.c b/third_party/python/Python/random.c index ddff6cb67..2360e50a8 100644 --- a/third_party/python/Python/random.c +++ b/third_party/python/Python/random.c @@ -1,6 +1,19 @@ -/* clang-format off */ +#include "libc/calls/calls.h" +#include "libc/calls/weirdtypes.h" +#include "libc/errno.h" +#include "libc/fmt/conv.h" +#include "libc/rand/rand.h" #include "libc/sysv/consts/grnd.h" -#include "third_party/python/Include/Python.h" +#include "libc/sysv/consts/o.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pydebug.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pyhash.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/pyconfig.h" +/* clang-format off */ #ifdef Py_DEBUG int _Py_HashSecret_Initialized = 0; @@ -8,7 +21,6 @@ int _Py_HashSecret_Initialized = 0; static int _Py_HashSecret_Initialized = 0; #endif -#if defined(HAVE_GETRANDOM) || defined(HAVE_GETRANDOM_SYSCALL) #define PY_GETRANDOM 1 /* Call getrandom() to get random bytes: @@ -41,17 +53,9 @@ py_getrandom(void *buffer, Py_ssize_t size, int blocking, int raise) flags = blocking ? 0 : GRND_NONBLOCK; dest = buffer; while (0 < size) { -#ifdef sun - /* Issue #26735: On Solaris, getrandom() is limited to returning up - to 1024 bytes. Call it multiple times if more bytes are - requested. */ - n = Py_MIN(size, 1024); -#else - n = Py_MIN(size, LONG_MAX); -#endif + n = Py_MIN(size, 256); errno = 0; -#ifdef HAVE_GETRANDOM if (raise) { Py_BEGIN_ALLOW_THREADS n = getrandom(dest, n, flags); @@ -60,24 +64,6 @@ py_getrandom(void *buffer, Py_ssize_t size, int blocking, int raise) else { n = getrandom(dest, n, flags); } -#else - /* On Linux, use the syscall() function because the GNU libc doesn't - expose the Linux getrandom() syscall yet. See: - https://sourceware.org/bugzilla/show_bug.cgi?id=17252 */ - if (raise) { - Py_BEGIN_ALLOW_THREADS - n = syscall(SYS_getrandom, dest, n, flags); - Py_END_ALLOW_THREADS - } - else { - n = syscall(SYS_getrandom, dest, n, flags); - } -# ifdef _Py_MEMORY_SANITIZER - if (n > 0) { - __msan_unpoison(dest, n); - } -# endif -#endif if (n < 0) { /* ENOSYS: the syscall is not supported by the kernel. @@ -259,7 +245,6 @@ dev_urandom_close(void) urandom_cache.fd = -1; } } -#endif /* !MS_WINDOWS */ /* Fill buffer with pseudo-random bytes generated by a linear congruent @@ -422,7 +407,7 @@ _PyRandom_Init(void) } if (seed == 0) { /* disable the randomized hash */ - memset(secret, 0, secret_size); + bzero(secret, secret_size); Py_HashRandomizationFlag = 0; } else { diff --git a/third_party/python/Python/sigcheck.c b/third_party/python/Python/sigcheck.c index cd1e29ee4..bd9438d0a 100644 --- a/third_party/python/Python/sigcheck.c +++ b/third_party/python/Python/sigcheck.c @@ -1,4 +1,5 @@ -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/intrcheck.h" +#include "third_party/python/Include/pyerrors.h" /* clang-format off */ /* Sigcheck is similar to intrcheck() but sets an exception when an diff --git a/third_party/python/Python/structmember.c b/third_party/python/Python/structmember.c index cec1e3112..1e7076aa1 100644 --- a/third_party/python/Python/structmember.c +++ b/third_party/python/Python/structmember.c @@ -1,5 +1,10 @@ -#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pyerrors.h" #include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/warnings.h" /* clang-format off */ /* Map C struct members to Python object attributes */ diff --git a/third_party/python/Python/symtable.c b/third_party/python/Python/symtable.c index 240730489..845b75509 100644 --- a/third_party/python/Python/symtable.c +++ b/third_party/python/Python/symtable.c @@ -1,7 +1,14 @@ -#include "third_party/python/Include/Python.h" -/**/ #include "third_party/python/Include/Python-ast.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/ceval.h" #include "third_party/python/Include/code.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/setobject.h" #include "third_party/python/Include/structmember.h" #include "third_party/python/Include/symtable.h" /* clang-format off */ diff --git a/third_party/python/Python/sysmodule.c b/third_party/python/Python/sysmodule.c index 8ef23698a..041f0f195 100644 --- a/third_party/python/Python/sysmodule.c +++ b/third_party/python/Python/sysmodule.c @@ -1,26 +1,41 @@ -/* clang-format off */ - -/* System module */ - -/* -Various bits of information used by the interpreter are collected in -module 'sys'. -Function member: -- exit(sts): raise SystemExit -Data members: -- stdin, stdout, stderr: standard file objects -- modules: the table of modules (dictionary) -- path: module search path (list of strings) -- argv: script arguments (list of strings) -- ps1, ps2: optional primary and secondary prompts (strings) -*/ - -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/code.h" -#include "third_party/python/Include/frameobject.h" -#include "third_party/python/Include/pythread.h" -#include "third_party/python/Include/osdefs.h" +#include "libc/calls/calls.h" +#include "libc/dce.h" +#include "libc/runtime/runtime.h" +#include "libc/sysv/consts/exit.h" #include "libc/unicode/locale.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/code.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/eval.h" +#include "third_party/python/Include/fileobject.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/frameobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/namespaceobject.h" +#include "third_party/python/Include/objimpl.h" +#include "third_party/python/Include/osdefs.h" +#include "third_party/python/Include/patchlevel.h" +#include "third_party/python/Include/pgenheaders.h" +#include "third_party/python/Include/pydebug.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pyhash.h" +#include "third_party/python/Include/pylifecycle.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pyport.h" +#include "third_party/python/Include/pythonrun.h" +#include "third_party/python/Include/pythread.h" +#include "third_party/python/Include/structseq.h" +#include "third_party/python/Include/traceback.h" +#include "third_party/python/Include/unicodeobject.h" +#include "third_party/python/Include/warnings.h" +#include "third_party/python/pyconfig.h" +/* clang-format off */ _Py_IDENTIFIER(_); _Py_IDENTIFIER(__sizeof__); @@ -2231,7 +2246,7 @@ sys_update_path(int argc, wchar_t **argv) if (p != NULL) { n = p + 1 - argv0; #if SEP == '/' /* Special case for Unix filename syntax */ - if (n > 1) + if (n > 1 && (!IsWindows() || p[-1] != ':')) n--; /* Drop trailing separator */ #endif /* Unix */ } diff --git a/third_party/python/Python/thread.c b/third_party/python/Python/thread.c index fb954a70d..9a2bd71a4 100644 --- a/third_party/python/Python/thread.c +++ b/third_party/python/Python/thread.c @@ -1,13 +1,17 @@ +#include "libc/assert.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pymacro.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pythread.h" +#include "third_party/python/Include/structseq.h" /* clang-format off */ + /* Thread package. This is intended to be usable independently from Python. - The implementation for system foobar is in a file thread_foobar.h + The implementation for system foobar is in a file thread_foobar.inc which is included by this file dependent on config settings. Stuff shared by all thread_*.h files is collected here. */ -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/pythread.h" - #ifndef _POSIX_THREADS /* Check if we're running on HP-UX and _SC_THREADS is defined. If so, then @@ -67,18 +71,18 @@ static size_t _pythread_stacksize = 0; #ifdef _POSIX_THREADS #define PYTHREAD_NAME "pthread" -#include "thread_pthread.h" +#include "thread_pthread.inc" #endif #ifdef NT_THREADS #define PYTHREAD_NAME "nt" -#include "thread_nt.h" +#include "thread_nt.inc" #endif /* #ifdef FOOBAR_THREADS -#include "thread_foobar.h" +#include "thread_foobar.inc" #endif */ diff --git a/third_party/python/Python/thread_foobar.h b/third_party/python/Python/thread_foobar.h index ea96f9c9d..f1a7991c3 100644 --- a/third_party/python/Python/thread_foobar.h +++ b/third_party/python/Python/thread_foobar.h @@ -1,3 +1,6 @@ +#include "libc/calls/calls.h" +/* clang-format off */ + /* * Initialization. */ diff --git a/third_party/python/Python/thread_nt.h b/third_party/python/Python/thread_nt.inc similarity index 99% rename from third_party/python/Python/thread_nt.h rename to third_party/python/Python/thread_nt.inc index 026de2994..cc7f093c3 100644 --- a/third_party/python/Python/thread_nt.h +++ b/third_party/python/Python/thread_nt.inc @@ -16,7 +16,7 @@ #if _PY_USE_CV_LOCKS -#include "third_party/python/Include/condvar.h" +#include "third_party/python/Python/condvar.h" typedef struct _NRMUTEX { diff --git a/third_party/python/Python/thread_pthread.h b/third_party/python/Python/thread_pthread.inc similarity index 100% rename from third_party/python/Python/thread_pthread.h rename to third_party/python/Python/thread_pthread.inc diff --git a/third_party/python/Python/traceback.c b/third_party/python/Python/traceback.c index 88222b06f..633b727f1 100644 --- a/third_party/python/Python/traceback.c +++ b/third_party/python/Python/traceback.c @@ -1,8 +1,23 @@ -#include "third_party/python/Include/Python.h" +#include "libc/calls/calls.h" +#include "libc/calls/weirdtypes.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/bytesobject.h" #include "third_party/python/Include/code.h" +#include "third_party/python/Include/codecs.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/fileobject.h" +#include "third_party/python/Include/fileutils.h" #include "third_party/python/Include/frameobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/longobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/objimpl.h" #include "third_party/python/Include/osdefs.h" +#include "third_party/python/Include/pyerrors.h" #include "third_party/python/Include/structmember.h" +#include "third_party/python/Include/sysmodule.h" +#include "third_party/python/Include/traceback.h" /* clang-format off */ #define OFF(x) offsetof(PyTracebackObject, x) diff --git a/third_party/python/Python/wordcode_helpers.h b/third_party/python/Python/wordcode_helpers.inc similarity index 94% rename from third_party/python/Python/wordcode_helpers.h rename to third_party/python/Python/wordcode_helpers.inc index cce81c1d2..cfa3eb36e 100644 --- a/third_party/python/Python/wordcode_helpers.h +++ b/third_party/python/Python/wordcode_helpers.inc @@ -1,3 +1,6 @@ +#include "third_party/python/Include/code.h" +/* clang-format off */ + /* This file contains code shared by the compiler and the peephole optimizer. */ diff --git a/third_party/python/Tools/demo/hanoi.py b/third_party/python/Tools/demo/hanoi.py deleted file mode 100755 index dad02342a..000000000 --- a/third_party/python/Tools/demo/hanoi.py +++ /dev/null @@ -1,154 +0,0 @@ -#!/usr/bin/env python3 - -""" -Animated Towers of Hanoi using Tk with optional bitmap file in background. - -Usage: hanoi.py [n [bitmapfile]] - -n is the number of pieces to animate; default is 4, maximum 15. - -The bitmap file can be any X11 bitmap file (look in /usr/include/X11/bitmaps for -samples); it is displayed as the background of the animation. Default is no -bitmap. -""" - -from tkinter import Tk, Canvas - -# Basic Towers-of-Hanoi algorithm: move n pieces from a to b, using c -# as temporary. For each move, call report() -def hanoi(n, a, b, c, report): - if n <= 0: return - hanoi(n-1, a, c, b, report) - report(n, a, b) - hanoi(n-1, c, b, a, report) - - -# The graphical interface -class Tkhanoi: - - # Create our objects - def __init__(self, n, bitmap = None): - self.n = n - self.tk = tk = Tk() - self.canvas = c = Canvas(tk) - c.pack() - width, height = tk.getint(c['width']), tk.getint(c['height']) - - # Add background bitmap - if bitmap: - self.bitmap = c.create_bitmap(width//2, height//2, - bitmap=bitmap, - foreground='blue') - - # Generate pegs - pegwidth = 10 - pegheight = height//2 - pegdist = width//3 - x1, y1 = (pegdist-pegwidth)//2, height*1//3 - x2, y2 = x1+pegwidth, y1+pegheight - self.pegs = [] - p = c.create_rectangle(x1, y1, x2, y2, fill='black') - self.pegs.append(p) - x1, x2 = x1+pegdist, x2+pegdist - p = c.create_rectangle(x1, y1, x2, y2, fill='black') - self.pegs.append(p) - x1, x2 = x1+pegdist, x2+pegdist - p = c.create_rectangle(x1, y1, x2, y2, fill='black') - self.pegs.append(p) - self.tk.update() - - # Generate pieces - pieceheight = pegheight//16 - maxpiecewidth = pegdist*2//3 - minpiecewidth = 2*pegwidth - self.pegstate = [[], [], []] - self.pieces = {} - x1, y1 = (pegdist-maxpiecewidth)//2, y2-pieceheight-2 - x2, y2 = x1+maxpiecewidth, y1+pieceheight - dx = (maxpiecewidth-minpiecewidth) // (2*max(1, n-1)) - for i in range(n, 0, -1): - p = c.create_rectangle(x1, y1, x2, y2, fill='red') - self.pieces[i] = p - self.pegstate[0].append(i) - x1, x2 = x1 + dx, x2-dx - y1, y2 = y1 - pieceheight-2, y2-pieceheight-2 - self.tk.update() - self.tk.after(25) - - # Run -- never returns - def run(self): - while 1: - hanoi(self.n, 0, 1, 2, self.report) - hanoi(self.n, 1, 2, 0, self.report) - hanoi(self.n, 2, 0, 1, self.report) - hanoi(self.n, 0, 2, 1, self.report) - hanoi(self.n, 2, 1, 0, self.report) - hanoi(self.n, 1, 0, 2, self.report) - - # Reporting callback for the actual hanoi function - def report(self, i, a, b): - if self.pegstate[a][-1] != i: raise RuntimeError # Assertion - del self.pegstate[a][-1] - p = self.pieces[i] - c = self.canvas - - # Lift the piece above peg a - ax1, ay1, ax2, ay2 = c.bbox(self.pegs[a]) - while 1: - x1, y1, x2, y2 = c.bbox(p) - if y2 < ay1: break - c.move(p, 0, -1) - self.tk.update() - - # Move it towards peg b - bx1, by1, bx2, by2 = c.bbox(self.pegs[b]) - newcenter = (bx1+bx2)//2 - while 1: - x1, y1, x2, y2 = c.bbox(p) - center = (x1+x2)//2 - if center == newcenter: break - if center > newcenter: c.move(p, -1, 0) - else: c.move(p, 1, 0) - self.tk.update() - - # Move it down on top of the previous piece - pieceheight = y2-y1 - newbottom = by2 - pieceheight*len(self.pegstate[b]) - 2 - while 1: - x1, y1, x2, y2 = c.bbox(p) - if y2 >= newbottom: break - c.move(p, 0, 1) - self.tk.update() - - # Update peg state - self.pegstate[b].append(i) - - -def main(): - import sys - - # First argument is number of pegs, default 4 - if sys.argv[1:]: - n = int(sys.argv[1]) - else: - n = 4 - - # Second argument is bitmap file, default none - if sys.argv[2:]: - bitmap = sys.argv[2] - # Reverse meaning of leading '@' compared to Tk - if bitmap[0] == '@': bitmap = bitmap[1:] - else: bitmap = '@' + bitmap - else: - bitmap = None - - # Create the graphical objects... - h = Tkhanoi(n, bitmap) - - # ...and run! - h.run() - - -# Call main when run as script -if __name__ == '__main__': - main() diff --git a/third_party/python/Tools/demo/life.py b/third_party/python/Tools/demo/life.py deleted file mode 100755 index fc4cb4952..000000000 --- a/third_party/python/Tools/demo/life.py +++ /dev/null @@ -1,262 +0,0 @@ -#!/usr/bin/env python3 - -""" -A curses-based version of Conway's Game of Life. - -An empty board will be displayed, and the following commands are available: - E : Erase the board - R : Fill the board randomly - S : Step for a single generation - C : Update continuously until a key is struck - Q : Quit - Cursor keys : Move the cursor around the board - Space or Enter : Toggle the contents of the cursor's position - -Contributed by Andrew Kuchling, Mouse support and color by Dafydd Crosby. -""" - -import curses -import random - - -class LifeBoard: - """Encapsulates a Life board - - Attributes: - X,Y : horizontal and vertical size of the board - state : dictionary mapping (x,y) to 0 or 1 - - Methods: - display(update_board) -- If update_board is true, compute the - next generation. Then display the state - of the board and refresh the screen. - erase() -- clear the entire board - make_random() -- fill the board randomly - set(y,x) -- set the given cell to Live; doesn't refresh the screen - toggle(y,x) -- change the given cell from live to dead, or vice - versa, and refresh the screen display - - """ - def __init__(self, scr, char=ord('*')): - """Create a new LifeBoard instance. - - scr -- curses screen object to use for display - char -- character used to render live cells (default: '*') - """ - self.state = {} - self.scr = scr - Y, X = self.scr.getmaxyx() - self.X, self.Y = X - 2, Y - 2 - 1 - self.char = char - self.scr.clear() - - # Draw a border around the board - border_line = '+' + (self.X * '-') + '+' - self.scr.addstr(0, 0, border_line) - self.scr.addstr(self.Y + 1, 0, border_line) - for y in range(0, self.Y): - self.scr.addstr(1 + y, 0, '|') - self.scr.addstr(1 + y, self.X + 1, '|') - self.scr.refresh() - - def set(self, y, x): - """Set a cell to the live state""" - if x < 0 or self.X <= x or y < 0 or self.Y <= y: - raise ValueError("Coordinates out of range %i,%i" % (y, x)) - self.state[x, y] = 1 - - def toggle(self, y, x): - """Toggle a cell's state between live and dead""" - if x < 0 or self.X <= x or y < 0 or self.Y <= y: - raise ValueError("Coordinates out of range %i,%i" % (y, x)) - if (x, y) in self.state: - del self.state[x, y] - self.scr.addch(y + 1, x + 1, ' ') - else: - self.state[x, y] = 1 - if curses.has_colors(): - # Let's pick a random color! - self.scr.attrset(curses.color_pair(random.randrange(1, 7))) - self.scr.addch(y + 1, x + 1, self.char) - self.scr.attrset(0) - self.scr.refresh() - - def erase(self): - """Clear the entire board and update the board display""" - self.state = {} - self.display(update_board=False) - - def display(self, update_board=True): - """Display the whole board, optionally computing one generation""" - M, N = self.X, self.Y - if not update_board: - for i in range(0, M): - for j in range(0, N): - if (i, j) in self.state: - self.scr.addch(j + 1, i + 1, self.char) - else: - self.scr.addch(j + 1, i + 1, ' ') - self.scr.refresh() - return - - d = {} - self.boring = 1 - for i in range(0, M): - L = range(max(0, i - 1), min(M, i + 2)) - for j in range(0, N): - s = 0 - live = (i, j) in self.state - for k in range(max(0, j - 1), min(N, j + 2)): - for l in L: - if (l, k) in self.state: - s += 1 - s -= live - if s == 3: - # Birth - d[i, j] = 1 - if curses.has_colors(): - # Let's pick a random color! - self.scr.attrset(curses.color_pair( - random.randrange(1, 7))) - self.scr.addch(j + 1, i + 1, self.char) - self.scr.attrset(0) - if not live: - self.boring = 0 - elif s == 2 and live: - # Survival - d[i, j] = 1 - elif live: - # Death - self.scr.addch(j + 1, i + 1, ' ') - self.boring = 0 - self.state = d - self.scr.refresh() - - def make_random(self): - "Fill the board with a random pattern" - self.state = {} - for i in range(0, self.X): - for j in range(0, self.Y): - if random.random() > 0.5: - self.set(j, i) - - -def erase_menu(stdscr, menu_y): - "Clear the space where the menu resides" - stdscr.move(menu_y, 0) - stdscr.clrtoeol() - stdscr.move(menu_y + 1, 0) - stdscr.clrtoeol() - - -def display_menu(stdscr, menu_y): - "Display the menu of possible keystroke commands" - erase_menu(stdscr, menu_y) - - # If color, then light the menu up :-) - if curses.has_colors(): - stdscr.attrset(curses.color_pair(1)) - stdscr.addstr(menu_y, 4, - 'Use the cursor keys to move, and space or Enter to toggle a cell.') - stdscr.addstr(menu_y + 1, 4, - 'E)rase the board, R)andom fill, S)tep once or C)ontinuously, Q)uit') - stdscr.attrset(0) - - -def keyloop(stdscr): - # Clear the screen and display the menu of keys - stdscr.clear() - stdscr_y, stdscr_x = stdscr.getmaxyx() - menu_y = (stdscr_y - 3) - 1 - display_menu(stdscr, menu_y) - - # If color, then initialize the color pairs - if curses.has_colors(): - curses.init_pair(1, curses.COLOR_BLUE, 0) - curses.init_pair(2, curses.COLOR_CYAN, 0) - curses.init_pair(3, curses.COLOR_GREEN, 0) - curses.init_pair(4, curses.COLOR_MAGENTA, 0) - curses.init_pair(5, curses.COLOR_RED, 0) - curses.init_pair(6, curses.COLOR_YELLOW, 0) - curses.init_pair(7, curses.COLOR_WHITE, 0) - - # Set up the mask to listen for mouse events - curses.mousemask(curses.BUTTON1_CLICKED) - - # Allocate a subwindow for the Life board and create the board object - subwin = stdscr.subwin(stdscr_y - 3, stdscr_x, 0, 0) - board = LifeBoard(subwin, char=ord('*')) - board.display(update_board=False) - - # xpos, ypos are the cursor's position - xpos, ypos = board.X // 2, board.Y // 2 - - # Main loop: - while True: - stdscr.move(1 + ypos, 1 + xpos) # Move the cursor - c = stdscr.getch() # Get a keystroke - if 0 < c < 256: - c = chr(c) - if c in ' \n': - board.toggle(ypos, xpos) - elif c in 'Cc': - erase_menu(stdscr, menu_y) - stdscr.addstr(menu_y, 6, ' Hit any key to stop continuously ' - 'updating the screen.') - stdscr.refresh() - # Activate nodelay mode; getch() will return -1 - # if no keystroke is available, instead of waiting. - stdscr.nodelay(1) - while True: - c = stdscr.getch() - if c != -1: - break - stdscr.addstr(0, 0, '/') - stdscr.refresh() - board.display() - stdscr.addstr(0, 0, '+') - stdscr.refresh() - - stdscr.nodelay(0) # Disable nodelay mode - display_menu(stdscr, menu_y) - - elif c in 'Ee': - board.erase() - elif c in 'Qq': - break - elif c in 'Rr': - board.make_random() - board.display(update_board=False) - elif c in 'Ss': - board.display() - else: - # Ignore incorrect keys - pass - elif c == curses.KEY_UP and ypos > 0: - ypos -= 1 - elif c == curses.KEY_DOWN and ypos + 1 < board.Y: - ypos += 1 - elif c == curses.KEY_LEFT and xpos > 0: - xpos -= 1 - elif c == curses.KEY_RIGHT and xpos + 1 < board.X: - xpos += 1 - elif c == curses.KEY_MOUSE: - mouse_id, mouse_x, mouse_y, mouse_z, button_state = curses.getmouse() - if (mouse_x > 0 and mouse_x < board.X + 1 and - mouse_y > 0 and mouse_y < board.Y + 1): - xpos = mouse_x - 1 - ypos = mouse_y - 1 - board.toggle(ypos, xpos) - else: - # They've clicked outside the board - curses.flash() - else: - # Ignore incorrect keys - pass - - -def main(stdscr): - keyloop(stdscr) # Enter the main loop - -if __name__ == '__main__': - curses.wrapper(main) diff --git a/third_party/python/Tools/demo/redemo.py b/third_party/python/Tools/demo/redemo.py deleted file mode 100755 index 256a63e0a..000000000 --- a/third_party/python/Tools/demo/redemo.py +++ /dev/null @@ -1,172 +0,0 @@ -#!/usr/bin/env python3 - -"""Basic regular expression demonstration facility (Perl style syntax).""" - -from tkinter import * -import re - -class ReDemo: - - def __init__(self, master): - self.master = master - - self.promptdisplay = Label(self.master, anchor=W, - text="Enter a Perl-style regular expression:") - self.promptdisplay.pack(side=TOP, fill=X) - - self.regexdisplay = Entry(self.master) - self.regexdisplay.pack(fill=X) - self.regexdisplay.focus_set() - - self.addoptions() - - self.statusdisplay = Label(self.master, text="", anchor=W) - self.statusdisplay.pack(side=TOP, fill=X) - - self.labeldisplay = Label(self.master, anchor=W, - text="Enter a string to search:") - self.labeldisplay.pack(fill=X) - self.labeldisplay.pack(fill=X) - - self.showframe = Frame(master) - self.showframe.pack(fill=X, anchor=W) - - self.showvar = StringVar(master) - self.showvar.set("first") - - self.showfirstradio = Radiobutton(self.showframe, - text="Highlight first match", - variable=self.showvar, - value="first", - command=self.recompile) - self.showfirstradio.pack(side=LEFT) - - self.showallradio = Radiobutton(self.showframe, - text="Highlight all matches", - variable=self.showvar, - value="all", - command=self.recompile) - self.showallradio.pack(side=LEFT) - - self.stringdisplay = Text(self.master, width=60, height=4) - self.stringdisplay.pack(fill=BOTH, expand=1) - self.stringdisplay.tag_configure("hit", background="yellow") - - self.grouplabel = Label(self.master, text="Groups:", anchor=W) - self.grouplabel.pack(fill=X) - - self.grouplist = Listbox(self.master) - self.grouplist.pack(expand=1, fill=BOTH) - - self.regexdisplay.bind('', self.recompile) - self.stringdisplay.bind('', self.reevaluate) - - self.compiled = None - self.recompile() - - btags = self.regexdisplay.bindtags() - self.regexdisplay.bindtags(btags[1:] + btags[:1]) - - btags = self.stringdisplay.bindtags() - self.stringdisplay.bindtags(btags[1:] + btags[:1]) - - def addoptions(self): - self.frames = [] - self.boxes = [] - self.vars = [] - for name in ('IGNORECASE', - 'MULTILINE', - 'DOTALL', - 'VERBOSE'): - if len(self.boxes) % 3 == 0: - frame = Frame(self.master) - frame.pack(fill=X) - self.frames.append(frame) - val = getattr(re, name).value - var = IntVar() - box = Checkbutton(frame, - variable=var, text=name, - offvalue=0, onvalue=val, - command=self.recompile) - box.pack(side=LEFT) - self.boxes.append(box) - self.vars.append(var) - - def getflags(self): - flags = 0 - for var in self.vars: - flags = flags | var.get() - flags = flags - return flags - - def recompile(self, event=None): - try: - self.compiled = re.compile(self.regexdisplay.get(), - self.getflags()) - bg = self.promptdisplay['background'] - self.statusdisplay.config(text="", background=bg) - except re.error as msg: - self.compiled = None - self.statusdisplay.config( - text="re.error: %s" % str(msg), - background="red") - self.reevaluate() - - def reevaluate(self, event=None): - try: - self.stringdisplay.tag_remove("hit", "1.0", END) - except TclError: - pass - try: - self.stringdisplay.tag_remove("hit0", "1.0", END) - except TclError: - pass - self.grouplist.delete(0, END) - if not self.compiled: - return - self.stringdisplay.tag_configure("hit", background="yellow") - self.stringdisplay.tag_configure("hit0", background="orange") - text = self.stringdisplay.get("1.0", END) - last = 0 - nmatches = 0 - while last <= len(text): - m = self.compiled.search(text, last) - if m is None: - break - first, last = m.span() - if last == first: - last = first+1 - tag = "hit0" - else: - tag = "hit" - pfirst = "1.0 + %d chars" % first - plast = "1.0 + %d chars" % last - self.stringdisplay.tag_add(tag, pfirst, plast) - if nmatches == 0: - self.stringdisplay.yview_pickplace(pfirst) - groups = list(m.groups()) - groups.insert(0, m.group()) - for i in range(len(groups)): - g = "%2d: %r" % (i, groups[i]) - self.grouplist.insert(END, g) - nmatches = nmatches + 1 - if self.showvar.get() == "first": - break - - if nmatches == 0: - self.statusdisplay.config(text="(no match)", - background="yellow") - else: - self.statusdisplay.config(text="") - - -# Main function, run when invoked as a stand-alone Python program. - -def main(): - root = Tk() - demo = ReDemo(root) - root.protocol('WM_DELETE_WINDOW', root.quit) - root.mainloop() - -if __name__ == '__main__': - main() diff --git a/third_party/python/Tools/demo/sortvisu.py b/third_party/python/Tools/demo/sortvisu.py deleted file mode 100755 index 8447bc757..000000000 --- a/third_party/python/Tools/demo/sortvisu.py +++ /dev/null @@ -1,635 +0,0 @@ -#!/usr/bin/env python3 - -""" -Sorting algorithms visualizer using Tkinter. - -This module is comprised of three ``components'': - -- an array visualizer with methods that implement basic sorting -operations (compare, swap) as well as methods for ``annotating'' the -sorting algorithm (e.g. to show the pivot element); - -- a number of sorting algorithms (currently quicksort, insertion sort, -selection sort and bubble sort, as well as a randomization function), -all using the array visualizer for its basic operations and with calls -to its annotation methods; - -- and a ``driver'' class which can be used as a Grail applet or as a -stand-alone application. -""" - -from tkinter import * -import random - -XGRID = 10 -YGRID = 10 -WIDTH = 6 - - -class Array: - - class Cancelled(BaseException): - pass - - def __init__(self, master, data=None): - self.master = master - self.frame = Frame(self.master) - self.frame.pack(fill=X) - self.label = Label(self.frame) - self.label.pack() - self.canvas = Canvas(self.frame) - self.canvas.pack() - self.report = Label(self.frame) - self.report.pack() - self.left = self.canvas.create_line(0, 0, 0, 0) - self.right = self.canvas.create_line(0, 0, 0, 0) - self.pivot = self.canvas.create_line(0, 0, 0, 0) - self.items = [] - self.size = self.maxvalue = 0 - if data: - self.setdata(data) - - def setdata(self, data): - olditems = self.items - self.items = [] - for item in olditems: - item.delete() - self.size = len(data) - self.maxvalue = max(data) - self.canvas.config(width=(self.size+1)*XGRID, - height=(self.maxvalue+1)*YGRID) - for i in range(self.size): - self.items.append(ArrayItem(self, i, data[i])) - self.reset("Sort demo, size %d" % self.size) - - speed = "normal" - - def setspeed(self, speed): - self.speed = speed - - def destroy(self): - self.frame.destroy() - - in_mainloop = 0 - stop_mainloop = 0 - - def cancel(self): - self.stop_mainloop = 1 - if self.in_mainloop: - self.master.quit() - - def step(self): - if self.in_mainloop: - self.master.quit() - - def wait(self, msecs): - if self.speed == "fastest": - msecs = 0 - elif self.speed == "fast": - msecs = msecs//10 - elif self.speed == "single-step": - msecs = 1000000000 - if not self.stop_mainloop: - self.master.update() - id = self.master.after(msecs, self.master.quit) - self.in_mainloop = 1 - self.master.mainloop() - self.master.after_cancel(id) - self.in_mainloop = 0 - if self.stop_mainloop: - self.stop_mainloop = 0 - self.message("Cancelled") - raise Array.Cancelled - - def getsize(self): - return self.size - - def show_partition(self, first, last): - for i in range(self.size): - item = self.items[i] - if first <= i < last: - self.canvas.itemconfig(item, fill='red') - else: - self.canvas.itemconfig(item, fill='orange') - self.hide_left_right_pivot() - - def hide_partition(self): - for i in range(self.size): - item = self.items[i] - self.canvas.itemconfig(item, fill='red') - self.hide_left_right_pivot() - - def show_left(self, left): - if not 0 <= left < self.size: - self.hide_left() - return - x1, y1, x2, y2 = self.items[left].position() -## top, bot = HIRO - self.canvas.coords(self.left, (x1 - 2, 0, x1 - 2, 9999)) - self.master.update() - - def show_right(self, right): - if not 0 <= right < self.size: - self.hide_right() - return - x1, y1, x2, y2 = self.items[right].position() - self.canvas.coords(self.right, (x2 + 2, 0, x2 + 2, 9999)) - self.master.update() - - def hide_left_right_pivot(self): - self.hide_left() - self.hide_right() - self.hide_pivot() - - def hide_left(self): - self.canvas.coords(self.left, (0, 0, 0, 0)) - - def hide_right(self): - self.canvas.coords(self.right, (0, 0, 0, 0)) - - def show_pivot(self, pivot): - x1, y1, x2, y2 = self.items[pivot].position() - self.canvas.coords(self.pivot, (0, y1 - 2, 9999, y1 - 2)) - - def hide_pivot(self): - self.canvas.coords(self.pivot, (0, 0, 0, 0)) - - def swap(self, i, j): - if i == j: return - self.countswap() - item = self.items[i] - other = self.items[j] - self.items[i], self.items[j] = other, item - item.swapwith(other) - - def compare(self, i, j): - self.countcompare() - item = self.items[i] - other = self.items[j] - return item.compareto(other) - - def reset(self, msg): - self.ncompares = 0 - self.nswaps = 0 - self.message(msg) - self.updatereport() - self.hide_partition() - - def message(self, msg): - self.label.config(text=msg) - - def countswap(self): - self.nswaps = self.nswaps + 1 - self.updatereport() - - def countcompare(self): - self.ncompares = self.ncompares + 1 - self.updatereport() - - def updatereport(self): - text = "%d cmps, %d swaps" % (self.ncompares, self.nswaps) - self.report.config(text=text) - - -class ArrayItem: - - def __init__(self, array, index, value): - self.array = array - self.index = index - self.value = value - self.canvas = array.canvas - x1, y1, x2, y2 = self.position() - self.item_id = array.canvas.create_rectangle(x1, y1, x2, y2, - fill='red', outline='black', width=1) - self.canvas.tag_bind(self.item_id, '', self.mouse_down) - self.canvas.tag_bind(self.item_id, '', self.mouse_move) - self.canvas.tag_bind(self.item_id, '', self.mouse_up) - - def delete(self): - item_id = self.item_id - self.array = None - self.item_id = None - self.canvas.delete(item_id) - - def mouse_down(self, event): - self.lastx = event.x - self.lasty = event.y - self.origx = event.x - self.origy = event.y - self.canvas.tag_raise(self.item_id) - - def mouse_move(self, event): - self.canvas.move(self.item_id, - event.x - self.lastx, event.y - self.lasty) - self.lastx = event.x - self.lasty = event.y - - def mouse_up(self, event): - i = self.nearestindex(event.x) - if i >= self.array.getsize(): - i = self.array.getsize() - 1 - if i < 0: - i = 0 - other = self.array.items[i] - here = self.index - self.array.items[here], self.array.items[i] = other, self - self.index = i - x1, y1, x2, y2 = self.position() - self.canvas.coords(self.item_id, (x1, y1, x2, y2)) - other.setindex(here) - - def setindex(self, index): - nsteps = steps(self.index, index) - if not nsteps: return - if self.array.speed == "fastest": - nsteps = 0 - oldpts = self.position() - self.index = index - newpts = self.position() - trajectory = interpolate(oldpts, newpts, nsteps) - self.canvas.tag_raise(self.item_id) - for pts in trajectory: - self.canvas.coords(self.item_id, pts) - self.array.wait(50) - - def swapwith(self, other): - nsteps = steps(self.index, other.index) - if not nsteps: return - if self.array.speed == "fastest": - nsteps = 0 - myoldpts = self.position() - otheroldpts = other.position() - self.index, other.index = other.index, self.index - mynewpts = self.position() - othernewpts = other.position() - myfill = self.canvas.itemcget(self.item_id, 'fill') - otherfill = self.canvas.itemcget(other.item_id, 'fill') - self.canvas.itemconfig(self.item_id, fill='green') - self.canvas.itemconfig(other.item_id, fill='yellow') - self.array.master.update() - if self.array.speed == "single-step": - self.canvas.coords(self.item_id, mynewpts) - self.canvas.coords(other.item_id, othernewpts) - self.array.master.update() - self.canvas.itemconfig(self.item_id, fill=myfill) - self.canvas.itemconfig(other.item_id, fill=otherfill) - self.array.wait(0) - return - mytrajectory = interpolate(myoldpts, mynewpts, nsteps) - othertrajectory = interpolate(otheroldpts, othernewpts, nsteps) - if self.value > other.value: - self.canvas.tag_raise(self.item_id) - self.canvas.tag_raise(other.item_id) - else: - self.canvas.tag_raise(other.item_id) - self.canvas.tag_raise(self.item_id) - try: - for i in range(len(mytrajectory)): - mypts = mytrajectory[i] - otherpts = othertrajectory[i] - self.canvas.coords(self.item_id, mypts) - self.canvas.coords(other.item_id, otherpts) - self.array.wait(50) - finally: - mypts = mytrajectory[-1] - otherpts = othertrajectory[-1] - self.canvas.coords(self.item_id, mypts) - self.canvas.coords(other.item_id, otherpts) - self.canvas.itemconfig(self.item_id, fill=myfill) - self.canvas.itemconfig(other.item_id, fill=otherfill) - - def compareto(self, other): - myfill = self.canvas.itemcget(self.item_id, 'fill') - otherfill = self.canvas.itemcget(other.item_id, 'fill') - if self.value < other.value: - myflash = 'white' - otherflash = 'black' - outcome = -1 - elif self.value > other.value: - myflash = 'black' - otherflash = 'white' - outcome = 1 - else: - myflash = otherflash = 'grey' - outcome = 0 - try: - self.canvas.itemconfig(self.item_id, fill=myflash) - self.canvas.itemconfig(other.item_id, fill=otherflash) - self.array.wait(500) - finally: - self.canvas.itemconfig(self.item_id, fill=myfill) - self.canvas.itemconfig(other.item_id, fill=otherfill) - return outcome - - def position(self): - x1 = (self.index+1)*XGRID - WIDTH//2 - x2 = x1+WIDTH - y2 = (self.array.maxvalue+1)*YGRID - y1 = y2 - (self.value)*YGRID - return x1, y1, x2, y2 - - def nearestindex(self, x): - return int(round(float(x)/XGRID)) - 1 - - -# Subroutines that don't need an object - -def steps(here, there): - nsteps = abs(here - there) - if nsteps <= 3: - nsteps = nsteps * 3 - elif nsteps <= 5: - nsteps = nsteps * 2 - elif nsteps > 10: - nsteps = 10 - return nsteps - -def interpolate(oldpts, newpts, n): - if len(oldpts) != len(newpts): - raise ValueError("can't interpolate arrays of different length") - pts = [0]*len(oldpts) - res = [tuple(oldpts)] - for i in range(1, n): - for k in range(len(pts)): - pts[k] = oldpts[k] + (newpts[k] - oldpts[k])*i//n - res.append(tuple(pts)) - res.append(tuple(newpts)) - return res - - -# Various (un)sorting algorithms - -def uniform(array): - size = array.getsize() - array.setdata([(size+1)//2] * size) - array.reset("Uniform data, size %d" % size) - -def distinct(array): - size = array.getsize() - array.setdata(range(1, size+1)) - array.reset("Distinct data, size %d" % size) - -def randomize(array): - array.reset("Randomizing") - n = array.getsize() - for i in range(n): - j = random.randint(0, n-1) - array.swap(i, j) - array.message("Randomized") - -def insertionsort(array): - size = array.getsize() - array.reset("Insertion sort") - for i in range(1, size): - j = i-1 - while j >= 0: - if array.compare(j, j+1) <= 0: - break - array.swap(j, j+1) - j = j-1 - array.message("Sorted") - -def selectionsort(array): - size = array.getsize() - array.reset("Selection sort") - try: - for i in range(size): - array.show_partition(i, size) - for j in range(i+1, size): - if array.compare(i, j) > 0: - array.swap(i, j) - array.message("Sorted") - finally: - array.hide_partition() - -def bubblesort(array): - size = array.getsize() - array.reset("Bubble sort") - for i in range(size): - for j in range(1, size): - if array.compare(j-1, j) > 0: - array.swap(j-1, j) - array.message("Sorted") - -def quicksort(array): - size = array.getsize() - array.reset("Quicksort") - try: - stack = [(0, size)] - while stack: - first, last = stack[-1] - del stack[-1] - array.show_partition(first, last) - if last-first < 5: - array.message("Insertion sort") - for i in range(first+1, last): - j = i-1 - while j >= first: - if array.compare(j, j+1) <= 0: - break - array.swap(j, j+1) - j = j-1 - continue - array.message("Choosing pivot") - j, i, k = first, (first+last) // 2, last-1 - if array.compare(k, i) < 0: - array.swap(k, i) - if array.compare(k, j) < 0: - array.swap(k, j) - if array.compare(j, i) < 0: - array.swap(j, i) - pivot = j - array.show_pivot(pivot) - array.message("Pivot at left of partition") - array.wait(1000) - left = first - right = last - while 1: - array.message("Sweep right pointer") - right = right-1 - array.show_right(right) - while right > first and array.compare(right, pivot) >= 0: - right = right-1 - array.show_right(right) - array.message("Sweep left pointer") - left = left+1 - array.show_left(left) - while left < last and array.compare(left, pivot) <= 0: - left = left+1 - array.show_left(left) - if left > right: - array.message("End of partition") - break - array.message("Swap items") - array.swap(left, right) - array.message("Swap pivot back") - array.swap(pivot, right) - n1 = right-first - n2 = last-left - if n1 > 1: stack.append((first, right)) - if n2 > 1: stack.append((left, last)) - array.message("Sorted") - finally: - array.hide_partition() - -def demosort(array): - while 1: - for alg in [quicksort, insertionsort, selectionsort, bubblesort]: - randomize(array) - alg(array) - - -# Sort demo class -- usable as a Grail applet - -class SortDemo: - - def __init__(self, master, size=15): - self.master = master - self.size = size - self.busy = 0 - self.array = Array(self.master) - - self.botframe = Frame(master) - self.botframe.pack(side=BOTTOM) - self.botleftframe = Frame(self.botframe) - self.botleftframe.pack(side=LEFT, fill=Y) - self.botrightframe = Frame(self.botframe) - self.botrightframe.pack(side=RIGHT, fill=Y) - - self.b_qsort = Button(self.botleftframe, - text="Quicksort", command=self.c_qsort) - self.b_qsort.pack(fill=X) - self.b_isort = Button(self.botleftframe, - text="Insertion sort", command=self.c_isort) - self.b_isort.pack(fill=X) - self.b_ssort = Button(self.botleftframe, - text="Selection sort", command=self.c_ssort) - self.b_ssort.pack(fill=X) - self.b_bsort = Button(self.botleftframe, - text="Bubble sort", command=self.c_bsort) - self.b_bsort.pack(fill=X) - - # Terrible hack to overcome limitation of OptionMenu... - class MyIntVar(IntVar): - def __init__(self, master, demo): - self.demo = demo - IntVar.__init__(self, master) - def set(self, value): - IntVar.set(self, value) - if str(value) != '0': - self.demo.resize(value) - - self.v_size = MyIntVar(self.master, self) - self.v_size.set(size) - sizes = [1, 2, 3, 4] + list(range(5, 55, 5)) - if self.size not in sizes: - sizes.append(self.size) - sizes.sort() - self.m_size = OptionMenu(self.botleftframe, self.v_size, *sizes) - self.m_size.pack(fill=X) - - self.v_speed = StringVar(self.master) - self.v_speed.set("normal") - self.m_speed = OptionMenu(self.botleftframe, self.v_speed, - "single-step", "normal", "fast", "fastest") - self.m_speed.pack(fill=X) - - self.b_step = Button(self.botleftframe, - text="Step", command=self.c_step) - self.b_step.pack(fill=X) - - self.b_randomize = Button(self.botrightframe, - text="Randomize", command=self.c_randomize) - self.b_randomize.pack(fill=X) - self.b_uniform = Button(self.botrightframe, - text="Uniform", command=self.c_uniform) - self.b_uniform.pack(fill=X) - self.b_distinct = Button(self.botrightframe, - text="Distinct", command=self.c_distinct) - self.b_distinct.pack(fill=X) - self.b_demo = Button(self.botrightframe, - text="Demo", command=self.c_demo) - self.b_demo.pack(fill=X) - self.b_cancel = Button(self.botrightframe, - text="Cancel", command=self.c_cancel) - self.b_cancel.pack(fill=X) - self.b_cancel.config(state=DISABLED) - self.b_quit = Button(self.botrightframe, - text="Quit", command=self.c_quit) - self.b_quit.pack(fill=X) - - def resize(self, newsize): - if self.busy: - self.master.bell() - return - self.size = newsize - self.array.setdata(range(1, self.size+1)) - - def c_qsort(self): - self.run(quicksort) - - def c_isort(self): - self.run(insertionsort) - - def c_ssort(self): - self.run(selectionsort) - - def c_bsort(self): - self.run(bubblesort) - - def c_demo(self): - self.run(demosort) - - def c_randomize(self): - self.run(randomize) - - def c_uniform(self): - self.run(uniform) - - def c_distinct(self): - self.run(distinct) - - def run(self, func): - if self.busy: - self.master.bell() - return - self.busy = 1 - self.array.setspeed(self.v_speed.get()) - self.b_cancel.config(state=NORMAL) - try: - func(self.array) - except Array.Cancelled: - pass - self.b_cancel.config(state=DISABLED) - self.busy = 0 - - def c_cancel(self): - if not self.busy: - self.master.bell() - return - self.array.cancel() - - def c_step(self): - if not self.busy: - self.master.bell() - return - self.v_speed.set("single-step") - self.array.setspeed("single-step") - self.array.step() - - def c_quit(self): - if self.busy: - self.array.cancel() - self.master.after_idle(self.master.quit) - - -# Main program -- for stand-alone operation outside Grail - -def main(): - root = Tk() - demo = SortDemo(root) - root.protocol('WM_DELETE_WINDOW', demo.c_quit) - root.mainloop() - -if __name__ == '__main__': - main() diff --git a/third_party/python/Tools/demo/ss1.py b/third_party/python/Tools/demo/ss1.py deleted file mode 100755 index bf88820dc..000000000 --- a/third_party/python/Tools/demo/ss1.py +++ /dev/null @@ -1,829 +0,0 @@ -#!/usr/bin/env python3 - -""" -SS1 -- a spreadsheet-like application. -""" - -import os -import re -import sys -from xml.parsers import expat -from xml.sax.saxutils import escape - -LEFT, CENTER, RIGHT = "LEFT", "CENTER", "RIGHT" - -def ljust(x, n): - return x.ljust(n) -def center(x, n): - return x.center(n) -def rjust(x, n): - return x.rjust(n) -align2action = {LEFT: ljust, CENTER: center, RIGHT: rjust} - -align2xml = {LEFT: "left", CENTER: "center", RIGHT: "right"} -xml2align = {"left": LEFT, "center": CENTER, "right": RIGHT} - -align2anchor = {LEFT: "w", CENTER: "center", RIGHT: "e"} - -def sum(seq): - total = 0 - for x in seq: - if x is not None: - total += x - return total - -class Sheet: - - def __init__(self): - self.cells = {} # {(x, y): cell, ...} - self.ns = dict( - cell = self.cellvalue, - cells = self.multicellvalue, - sum = sum, - ) - - def cellvalue(self, x, y): - cell = self.getcell(x, y) - if hasattr(cell, 'recalc'): - return cell.recalc(self.ns) - else: - return cell - - def multicellvalue(self, x1, y1, x2, y2): - if x1 > x2: - x1, x2 = x2, x1 - if y1 > y2: - y1, y2 = y2, y1 - seq = [] - for y in range(y1, y2+1): - for x in range(x1, x2+1): - seq.append(self.cellvalue(x, y)) - return seq - - def getcell(self, x, y): - return self.cells.get((x, y)) - - def setcell(self, x, y, cell): - assert x > 0 and y > 0 - assert isinstance(cell, BaseCell) - self.cells[x, y] = cell - - def clearcell(self, x, y): - try: - del self.cells[x, y] - except KeyError: - pass - - def clearcells(self, x1, y1, x2, y2): - for xy in self.selectcells(x1, y1, x2, y2): - del self.cells[xy] - - def clearrows(self, y1, y2): - self.clearcells(0, y1, sys.maxsize, y2) - - def clearcolumns(self, x1, x2): - self.clearcells(x1, 0, x2, sys.maxsize) - - def selectcells(self, x1, y1, x2, y2): - if x1 > x2: - x1, x2 = x2, x1 - if y1 > y2: - y1, y2 = y2, y1 - return [(x, y) for x, y in self.cells - if x1 <= x <= x2 and y1 <= y <= y2] - - def movecells(self, x1, y1, x2, y2, dx, dy): - if dx == 0 and dy == 0: - return - if x1 > x2: - x1, x2 = x2, x1 - if y1 > y2: - y1, y2 = y2, y1 - assert x1+dx > 0 and y1+dy > 0 - new = {} - for x, y in self.cells: - cell = self.cells[x, y] - if hasattr(cell, 'renumber'): - cell = cell.renumber(x1, y1, x2, y2, dx, dy) - if x1 <= x <= x2 and y1 <= y <= y2: - x += dx - y += dy - new[x, y] = cell - self.cells = new - - def insertrows(self, y, n): - assert n > 0 - self.movecells(0, y, sys.maxsize, sys.maxsize, 0, n) - - def deleterows(self, y1, y2): - if y1 > y2: - y1, y2 = y2, y1 - self.clearrows(y1, y2) - self.movecells(0, y2+1, sys.maxsize, sys.maxsize, 0, y1-y2-1) - - def insertcolumns(self, x, n): - assert n > 0 - self.movecells(x, 0, sys.maxsize, sys.maxsize, n, 0) - - def deletecolumns(self, x1, x2): - if x1 > x2: - x1, x2 = x2, x1 - self.clearcells(x1, x2) - self.movecells(x2+1, 0, sys.maxsize, sys.maxsize, x1-x2-1, 0) - - def getsize(self): - maxx = maxy = 0 - for x, y in self.cells: - maxx = max(maxx, x) - maxy = max(maxy, y) - return maxx, maxy - - def reset(self): - for cell in self.cells.values(): - if hasattr(cell, 'reset'): - cell.reset() - - def recalc(self): - self.reset() - for cell in self.cells.values(): - if hasattr(cell, 'recalc'): - cell.recalc(self.ns) - - def display(self): - maxx, maxy = self.getsize() - width, height = maxx+1, maxy+1 - colwidth = [1] * width - full = {} - # Add column heading labels in row 0 - for x in range(1, width): - full[x, 0] = text, alignment = colnum2name(x), RIGHT - colwidth[x] = max(colwidth[x], len(text)) - # Add row labels in column 0 - for y in range(1, height): - full[0, y] = text, alignment = str(y), RIGHT - colwidth[0] = max(colwidth[0], len(text)) - # Add sheet cells in columns with x>0 and y>0 - for (x, y), cell in self.cells.items(): - if x <= 0 or y <= 0: - continue - if hasattr(cell, 'recalc'): - cell.recalc(self.ns) - if hasattr(cell, 'format'): - text, alignment = cell.format() - assert isinstance(text, str) - assert alignment in (LEFT, CENTER, RIGHT) - else: - text = str(cell) - if isinstance(cell, str): - alignment = LEFT - else: - alignment = RIGHT - full[x, y] = (text, alignment) - colwidth[x] = max(colwidth[x], len(text)) - # Calculate the horizontal separator line (dashes and dots) - sep = "" - for x in range(width): - if sep: - sep += "+" - sep += "-"*colwidth[x] - # Now print The full grid - for y in range(height): - line = "" - for x in range(width): - text, alignment = full.get((x, y)) or ("", LEFT) - text = align2action[alignment](text, colwidth[x]) - if line: - line += '|' - line += text - print(line) - if y == 0: - print(sep) - - def xml(self): - out = [''] - for (x, y), cell in self.cells.items(): - if hasattr(cell, 'xml'): - cellxml = cell.xml() - else: - cellxml = '%s' % escape(cell) - out.append('\n %s\n' % - (y, x, cellxml)) - out.append('') - return '\n'.join(out) - - def save(self, filename): - text = self.xml() - with open(filename, "w", encoding='utf-8') as f: - f.write(text) - if text and not text.endswith('\n'): - f.write('\n') - - def load(self, filename): - with open(filename, 'rb') as f: - SheetParser(self).parsefile(f) - -class SheetParser: - - def __init__(self, sheet): - self.sheet = sheet - - def parsefile(self, f): - parser = expat.ParserCreate() - parser.StartElementHandler = self.startelement - parser.EndElementHandler = self.endelement - parser.CharacterDataHandler = self.data - parser.ParseFile(f) - - def startelement(self, tag, attrs): - method = getattr(self, 'start_'+tag, None) - if method: - method(attrs) - self.texts = [] - - def data(self, text): - self.texts.append(text) - - def endelement(self, tag): - method = getattr(self, 'end_'+tag, None) - if method: - method("".join(self.texts)) - - def start_cell(self, attrs): - self.y = int(attrs.get("row")) - self.x = int(attrs.get("col")) - - def start_value(self, attrs): - self.fmt = attrs.get('format') - self.alignment = xml2align.get(attrs.get('align')) - - start_formula = start_value - - def end_int(self, text): - try: - self.value = int(text) - except (TypeError, ValueError): - self.value = None - - end_long = end_int - - def end_double(self, text): - try: - self.value = float(text) - except (TypeError, ValueError): - self.value = None - - def end_complex(self, text): - try: - self.value = complex(text) - except (TypeError, ValueError): - self.value = None - - def end_string(self, text): - self.value = text - - def end_value(self, text): - if isinstance(self.value, BaseCell): - self.cell = self.value - elif isinstance(self.value, str): - self.cell = StringCell(self.value, - self.fmt or "%s", - self.alignment or LEFT) - else: - self.cell = NumericCell(self.value, - self.fmt or "%s", - self.alignment or RIGHT) - - def end_formula(self, text): - self.cell = FormulaCell(text, - self.fmt or "%s", - self.alignment or RIGHT) - - def end_cell(self, text): - self.sheet.setcell(self.x, self.y, self.cell) - -class BaseCell: - __init__ = None # Must provide - """Abstract base class for sheet cells. - - Subclasses may but needn't provide the following APIs: - - cell.reset() -- prepare for recalculation - cell.recalc(ns) -> value -- recalculate formula - cell.format() -> (value, alignment) -- return formatted value - cell.xml() -> string -- return XML - """ - -class NumericCell(BaseCell): - - def __init__(self, value, fmt="%s", alignment=RIGHT): - assert isinstance(value, (int, float, complex)) - assert alignment in (LEFT, CENTER, RIGHT) - self.value = value - self.fmt = fmt - self.alignment = alignment - - def recalc(self, ns): - return self.value - - def format(self): - try: - text = self.fmt % self.value - except: - text = str(self.value) - return text, self.alignment - - def xml(self): - method = getattr(self, '_xml_' + type(self.value).__name__) - return '%s' % ( - align2xml[self.alignment], - self.fmt, - method()) - - def _xml_int(self): - if -2**31 <= self.value < 2**31: - return '%s' % self.value - else: - return '%s' % self.value - - def _xml_float(self): - return '%r' % self.value - - def _xml_complex(self): - return '%r' % self.value - -class StringCell(BaseCell): - - def __init__(self, text, fmt="%s", alignment=LEFT): - assert isinstance(text, str) - assert alignment in (LEFT, CENTER, RIGHT) - self.text = text - self.fmt = fmt - self.alignment = alignment - - def recalc(self, ns): - return self.text - - def format(self): - return self.text, self.alignment - - def xml(self): - s = '%s' - return s % ( - align2xml[self.alignment], - self.fmt, - escape(self.text)) - -class FormulaCell(BaseCell): - - def __init__(self, formula, fmt="%s", alignment=RIGHT): - assert alignment in (LEFT, CENTER, RIGHT) - self.formula = formula - self.translated = translate(self.formula) - self.fmt = fmt - self.alignment = alignment - self.reset() - - def reset(self): - self.value = None - - def recalc(self, ns): - if self.value is None: - try: - self.value = eval(self.translated, ns) - except: - exc = sys.exc_info()[0] - if hasattr(exc, "__name__"): - self.value = exc.__name__ - else: - self.value = str(exc) - return self.value - - def format(self): - try: - text = self.fmt % self.value - except: - text = str(self.value) - return text, self.alignment - - def xml(self): - return '%s' % ( - align2xml[self.alignment], - self.fmt, - escape(self.formula)) - - def renumber(self, x1, y1, x2, y2, dx, dy): - out = [] - for part in re.split(r'(\w+)', self.formula): - m = re.match('^([A-Z]+)([1-9][0-9]*)$', part) - if m is not None: - sx, sy = m.groups() - x = colname2num(sx) - y = int(sy) - if x1 <= x <= x2 and y1 <= y <= y2: - part = cellname(x+dx, y+dy) - out.append(part) - return FormulaCell("".join(out), self.fmt, self.alignment) - -def translate(formula): - """Translate a formula containing fancy cell names to valid Python code. - - Examples: - B4 -> cell(2, 4) - B4:Z100 -> cells(2, 4, 26, 100) - """ - out = [] - for part in re.split(r"(\w+(?::\w+)?)", formula): - m = re.match(r"^([A-Z]+)([1-9][0-9]*)(?::([A-Z]+)([1-9][0-9]*))?$", part) - if m is None: - out.append(part) - else: - x1, y1, x2, y2 = m.groups() - x1 = colname2num(x1) - if x2 is None: - s = "cell(%s, %s)" % (x1, y1) - else: - x2 = colname2num(x2) - s = "cells(%s, %s, %s, %s)" % (x1, y1, x2, y2) - out.append(s) - return "".join(out) - -def cellname(x, y): - "Translate a cell coordinate to a fancy cell name (e.g. (1, 1)->'A1')." - assert x > 0 # Column 0 has an empty name, so can't use that - return colnum2name(x) + str(y) - -def colname2num(s): - "Translate a column name to number (e.g. 'A'->1, 'Z'->26, 'AA'->27)." - s = s.upper() - n = 0 - for c in s: - assert 'A' <= c <= 'Z' - n = n*26 + ord(c) - ord('A') + 1 - return n - -def colnum2name(n): - "Translate a column number to name (e.g. 1->'A', etc.)." - assert n > 0 - s = "" - while n: - n, m = divmod(n-1, 26) - s = chr(m+ord('A')) + s - return s - -import tkinter as Tk - -class SheetGUI: - - """Beginnings of a GUI for a spreadsheet. - - TO DO: - - clear multiple cells - - Insert, clear, remove rows or columns - - Show new contents while typing - - Scroll bars - - Grow grid when window is grown - - Proper menus - - Undo, redo - - Cut, copy and paste - - Formatting and alignment - """ - - def __init__(self, filename="sheet1.xml", rows=10, columns=5): - """Constructor. - - Load the sheet from the filename argument. - Set up the Tk widget tree. - """ - # Create and load the sheet - self.filename = filename - self.sheet = Sheet() - if os.path.isfile(filename): - self.sheet.load(filename) - # Calculate the needed grid size - maxx, maxy = self.sheet.getsize() - rows = max(rows, maxy) - columns = max(columns, maxx) - # Create the widgets - self.root = Tk.Tk() - self.root.wm_title("Spreadsheet: %s" % self.filename) - self.beacon = Tk.Label(self.root, text="A1", - font=('helvetica', 16, 'bold')) - self.entry = Tk.Entry(self.root) - self.savebutton = Tk.Button(self.root, text="Save", - command=self.save) - self.cellgrid = Tk.Frame(self.root) - # Configure the widget lay-out - self.cellgrid.pack(side="bottom", expand=1, fill="both") - self.beacon.pack(side="left") - self.savebutton.pack(side="right") - self.entry.pack(side="left", expand=1, fill="x") - # Bind some events - self.entry.bind("", self.return_event) - self.entry.bind("", self.shift_return_event) - self.entry.bind("", self.tab_event) - self.entry.bind("", self.shift_tab_event) - self.entry.bind("", self.delete_event) - self.entry.bind("", self.escape_event) - # Now create the cell grid - self.makegrid(rows, columns) - # Select the top-left cell - self.currentxy = None - self.cornerxy = None - self.setcurrent(1, 1) - # Copy the sheet cells to the GUI cells - self.sync() - - def delete_event(self, event): - if self.cornerxy != self.currentxy and self.cornerxy is not None: - self.sheet.clearcells(*(self.currentxy + self.cornerxy)) - else: - self.sheet.clearcell(*self.currentxy) - self.sync() - self.entry.delete(0, 'end') - return "break" - - def escape_event(self, event): - x, y = self.currentxy - self.load_entry(x, y) - - def load_entry(self, x, y): - cell = self.sheet.getcell(x, y) - if cell is None: - text = "" - elif isinstance(cell, FormulaCell): - text = '=' + cell.formula - else: - text, alignment = cell.format() - self.entry.delete(0, 'end') - self.entry.insert(0, text) - self.entry.selection_range(0, 'end') - - def makegrid(self, rows, columns): - """Helper to create the grid of GUI cells. - - The edge (x==0 or y==0) is filled with labels; the rest is real cells. - """ - self.rows = rows - self.columns = columns - self.gridcells = {} - # Create the top left corner cell (which selects all) - cell = Tk.Label(self.cellgrid, relief='raised') - cell.grid_configure(column=0, row=0, sticky='NSWE') - cell.bind("", self.selectall) - # Create the top row of labels, and configure the grid columns - for x in range(1, columns+1): - self.cellgrid.grid_columnconfigure(x, minsize=64) - cell = Tk.Label(self.cellgrid, text=colnum2name(x), relief='raised') - cell.grid_configure(column=x, row=0, sticky='WE') - self.gridcells[x, 0] = cell - cell.__x = x - cell.__y = 0 - cell.bind("", self.selectcolumn) - cell.bind("", self.extendcolumn) - cell.bind("", self.extendcolumn) - cell.bind("", self.extendcolumn) - # Create the leftmost column of labels - for y in range(1, rows+1): - cell = Tk.Label(self.cellgrid, text=str(y), relief='raised') - cell.grid_configure(column=0, row=y, sticky='WE') - self.gridcells[0, y] = cell - cell.__x = 0 - cell.__y = y - cell.bind("", self.selectrow) - cell.bind("", self.extendrow) - cell.bind("", self.extendrow) - cell.bind("", self.extendrow) - # Create the real cells - for x in range(1, columns+1): - for y in range(1, rows+1): - cell = Tk.Label(self.cellgrid, relief='sunken', - bg='white', fg='black') - cell.grid_configure(column=x, row=y, sticky='NSWE') - self.gridcells[x, y] = cell - cell.__x = x - cell.__y = y - # Bind mouse events - cell.bind("", self.press) - cell.bind("", self.motion) - cell.bind("", self.release) - cell.bind("", self.release) - - def selectall(self, event): - self.setcurrent(1, 1) - self.setcorner(sys.maxsize, sys.maxsize) - - def selectcolumn(self, event): - x, y = self.whichxy(event) - self.setcurrent(x, 1) - self.setcorner(x, sys.maxsize) - - def extendcolumn(self, event): - x, y = self.whichxy(event) - if x > 0: - self.setcurrent(self.currentxy[0], 1) - self.setcorner(x, sys.maxsize) - - def selectrow(self, event): - x, y = self.whichxy(event) - self.setcurrent(1, y) - self.setcorner(sys.maxsize, y) - - def extendrow(self, event): - x, y = self.whichxy(event) - if y > 0: - self.setcurrent(1, self.currentxy[1]) - self.setcorner(sys.maxsize, y) - - def press(self, event): - x, y = self.whichxy(event) - if x > 0 and y > 0: - self.setcurrent(x, y) - - def motion(self, event): - x, y = self.whichxy(event) - if x > 0 and y > 0: - self.setcorner(x, y) - - release = motion - - def whichxy(self, event): - w = self.cellgrid.winfo_containing(event.x_root, event.y_root) - if w is not None and isinstance(w, Tk.Label): - try: - return w.__x, w.__y - except AttributeError: - pass - return 0, 0 - - def save(self): - self.sheet.save(self.filename) - - def setcurrent(self, x, y): - "Make (x, y) the current cell." - if self.currentxy is not None: - self.change_cell() - self.clearfocus() - self.beacon['text'] = cellname(x, y) - self.load_entry(x, y) - self.entry.focus_set() - self.currentxy = x, y - self.cornerxy = None - gridcell = self.gridcells.get(self.currentxy) - if gridcell is not None: - gridcell['bg'] = 'yellow' - - def setcorner(self, x, y): - if self.currentxy is None or self.currentxy == (x, y): - self.setcurrent(x, y) - return - self.clearfocus() - self.cornerxy = x, y - x1, y1 = self.currentxy - x2, y2 = self.cornerxy or self.currentxy - if x1 > x2: - x1, x2 = x2, x1 - if y1 > y2: - y1, y2 = y2, y1 - for (x, y), cell in self.gridcells.items(): - if x1 <= x <= x2 and y1 <= y <= y2: - cell['bg'] = 'lightBlue' - gridcell = self.gridcells.get(self.currentxy) - if gridcell is not None: - gridcell['bg'] = 'yellow' - self.setbeacon(x1, y1, x2, y2) - - def setbeacon(self, x1, y1, x2, y2): - if x1 == y1 == 1 and x2 == y2 == sys.maxsize: - name = ":" - elif (x1, x2) == (1, sys.maxsize): - if y1 == y2: - name = "%d" % y1 - else: - name = "%d:%d" % (y1, y2) - elif (y1, y2) == (1, sys.maxsize): - if x1 == x2: - name = "%s" % colnum2name(x1) - else: - name = "%s:%s" % (colnum2name(x1), colnum2name(x2)) - else: - name1 = cellname(*self.currentxy) - name2 = cellname(*self.cornerxy) - name = "%s:%s" % (name1, name2) - self.beacon['text'] = name - - - def clearfocus(self): - if self.currentxy is not None: - x1, y1 = self.currentxy - x2, y2 = self.cornerxy or self.currentxy - if x1 > x2: - x1, x2 = x2, x1 - if y1 > y2: - y1, y2 = y2, y1 - for (x, y), cell in self.gridcells.items(): - if x1 <= x <= x2 and y1 <= y <= y2: - cell['bg'] = 'white' - - def return_event(self, event): - "Callback for the Return key." - self.change_cell() - x, y = self.currentxy - self.setcurrent(x, y+1) - return "break" - - def shift_return_event(self, event): - "Callback for the Return key with Shift modifier." - self.change_cell() - x, y = self.currentxy - self.setcurrent(x, max(1, y-1)) - return "break" - - def tab_event(self, event): - "Callback for the Tab key." - self.change_cell() - x, y = self.currentxy - self.setcurrent(x+1, y) - return "break" - - def shift_tab_event(self, event): - "Callback for the Tab key with Shift modifier." - self.change_cell() - x, y = self.currentxy - self.setcurrent(max(1, x-1), y) - return "break" - - def change_cell(self): - "Set the current cell from the entry widget." - x, y = self.currentxy - text = self.entry.get() - cell = None - if text.startswith('='): - cell = FormulaCell(text[1:]) - else: - for cls in int, float, complex: - try: - value = cls(text) - except (TypeError, ValueError): - continue - else: - cell = NumericCell(value) - break - if cell is None and text: - cell = StringCell(text) - if cell is None: - self.sheet.clearcell(x, y) - else: - self.sheet.setcell(x, y, cell) - self.sync() - - def sync(self): - "Fill the GUI cells from the sheet cells." - self.sheet.recalc() - for (x, y), gridcell in self.gridcells.items(): - if x == 0 or y == 0: - continue - cell = self.sheet.getcell(x, y) - if cell is None: - gridcell['text'] = "" - else: - if hasattr(cell, 'format'): - text, alignment = cell.format() - else: - text, alignment = str(cell), LEFT - gridcell['text'] = text - gridcell['anchor'] = align2anchor[alignment] - - -def test_basic(): - "Basic non-gui self-test." - a = Sheet() - for x in range(1, 11): - for y in range(1, 11): - if x == 1: - cell = NumericCell(y) - elif y == 1: - cell = NumericCell(x) - else: - c1 = cellname(x, 1) - c2 = cellname(1, y) - formula = "%s*%s" % (c1, c2) - cell = FormulaCell(formula) - a.setcell(x, y, cell) -## if os.path.isfile("sheet1.xml"): -## print "Loading from sheet1.xml" -## a.load("sheet1.xml") - a.display() - a.save("sheet1.xml") - -def test_gui(): - "GUI test." - if sys.argv[1:]: - filename = sys.argv[1] - else: - filename = "sheet1.xml" - g = SheetGUI(filename) - g.root.mainloop() - -if __name__ == '__main__': - #test_basic() - test_gui() diff --git a/third_party/python/Tools/freeze/checkextensions_win32.py b/third_party/python/Tools/freeze/checkextensions_win32.py index c9cb576ae..df67f4a41 100644 --- a/third_party/python/Tools/freeze/checkextensions_win32.py +++ b/third_party/python/Tools/freeze/checkextensions_win32.py @@ -163,7 +163,7 @@ def write_extension_table(fname, modules): ext_src_header = """\ -#include "Python.h" +#include "third_party/python/Include/Python.h" """ ext_tab_header = """\ diff --git a/third_party/python/Tools/freeze/makefreeze.py b/third_party/python/Tools/freeze/makefreeze.py index 64e3e6bf7..7c7f8ca40 100644 --- a/third_party/python/Tools/freeze/makefreeze.py +++ b/third_party/python/Tools/freeze/makefreeze.py @@ -5,7 +5,7 @@ import bkfile # Write a file containing frozen code for the modules in the dictionary. header = """ -#include "Python.h" +#include "third_party/python/Include/Python.h" static struct _frozen _PyImport_FrozenModules[] = { """ diff --git a/third_party/python/Tools/msi/README.txt b/third_party/python/Tools/msi/README.txt deleted file mode 100644 index 741b67c79..000000000 --- a/third_party/python/Tools/msi/README.txt +++ /dev/null @@ -1,543 +0,0 @@ -Quick Build Info -================ - -For testing, the installer should be built with the Tools/msi/build.bat -script: - - build.bat [-x86] [-x64] [--doc] - -For an official release, the installer should be built with the -Tools/msi/buildrelease.bat script and environment variables: - - set PYTHON= - set SPHINXBUILD= - set PATH=; - ;%PATH% - - buildrelease.bat [-x86] [-x64] [-D] [-B] - [-o ] [-c ] - -See the Building the Installer section for more information. - -Overview -======== - -Python is distributed on Windows as an installer that will configure the -user's system. This allows users to have a functioning copy of Python -without having to build it themselves. - -The main tasks of the installer are: - -* copy required files into the expected layout -* configure system settings so the installation can be located by - other programs -* add entry points for modifying, repairing and uninstalling Python -* make it easy to launch Python, its documentation, and IDLE - -Each of these is discussed in a later section of this document. - -Structure of the Installer -========================== - -The installer is structured as a 'layout', which consists of a number of -CAB and MSI files and a single EXE. - -The EXE is the main entry point into the installer. It contains the UI -and command-line logic, as well as the ability to locate and optionally -download other parts of the layout. - -Each MSI contains the logic required to install a component or feature -of Python. These MSIs should not be launched directly by users. MSIs can -be embedded into the EXE or automatically downloaded as needed. - -Each CAB contains the files making up a Python installation. CABs are -embedded into their associated MSI and are never seen by users. - -MSIs are only required when the related feature or component is being -installed. When components are not selected for installation, the -associated MSI is not downloaded. This allows the installer to offer -options to install debugging symbols and binaries without increasing -the initial download size by separating them into their own MSIs. - -Building the Installer -====================== - -Before building the installer, download extra build dependencies using -Tools\msi\get_externals.bat. (Note that this is in addition to the -similarly named file in PCBuild.) - -One of the dependencies used in builds is WiX, a toolset that lets developers -create installers for Windows Installer, the Windows installation engine. WiX -has a dependency on the Microsoft .NET Framework Version 3.5 (which may not be -configured on recent versions of Windows, such as Windows 10). If you are -building on a recent Windows version, use the Control Panel (Programs | Programs -and Features | Turn Windows Features on or off) and ensure that the entry -".NET Framework 3.5 (includes .NET 2.0 and 3.0)" is enabled. - -For testing, the installer should be built with the Tools/msi/build.bat -script: - - build.bat [-x86] [-x64] [--doc] [--test-marker] [--pack] - -This script will build the required configurations of Python and -generate an installer layout in PCBuild/(win32|amd64)/en-us. - -Specify -x86 and/or -x64 to build for each platform. If neither is -specified, both platforms will be built. Currently, both the debug and -release versions of Python are required for the installer. - -Specify --doc to build the documentation (.chm) file. If the file is not -available, it will simply be excluded from the installer. Ensure -%PYTHON% and %SPHINXBUILD% are set when passing this option. You may -also set %HTMLHELP% to the Html Help Compiler (hhc.exe), or put HHC on -your PATH or in externals/. - -Specify --test-marker to build an installer that works side-by-side with -an official Python release. All registry keys and install locations will -include an extra marker to avoid overwriting files. This marker is -currently an 'x' prefix, but may change at any time. - -Specify --pack to build an installer that does not require all MSIs to -be available alongside. This takes longer, but is easier to share. - - -For an official release, the installer should be built with the -Tools/msi/buildrelease.bat script: - - set PYTHON= - set SPHINXBUILD= - set PATH=; - ;%PATH% - - buildrelease.bat [-x86] [-x64] [-D] [-B] - [-o ] [-c ] - -Specify -x86 and/or -x64 to build for each platform. If neither is -specified, both platforms will be built. Currently, both the debug and -release versions of Python are required for the installer. - -Specify -D to skip rebuilding the documentation. The documentation is -required for a release and the build will fail if it is not available. - -Specify -B to skip rebuilding Python. This is useful to only rebuild the -installer layout after a previous call to buildrelease.bat. - -Specify -o to set an output directory. The installer layouts will be -copied to platform-specific subdirectories of this path. - -Specify -c to choose a code-signing certificate to be used for all the -signable binaries in Python as well as each file making up the -installer. Official releases of Python must be signed. - -Ensure %PYTHON% and %SPHINXBUILD% are set when passing this option. You -may also set %HTMLHELP% to the Html Help Compiler (hhc.exe), or put HHC -on your PATH or in externals/. You will also need Mercurial (hg.exe) on -your PATH. - -If WiX is not found on your system, it will be automatically downloaded -and extracted to the externals/ directory. - -To manually build layouts of the installer, build one of the projects in -the bundle folder. - - msbuild bundle\snapshot.wixproj - msbuild bundle\releaseweb.wixproj - msbuild bundle\releaselocal.wixproj - msbuild bundle\full.wixproj - -snapshot.wixproj produces a test installer versioned based on the date. - -releaseweb.wixproj produces a release installer that does not embed any -of the layout. - -releaselocal.wixproj produces a release installer that embeds the files -required for a default installation. - -full.wixproj produces a test installer that embeds the entire layout. - -The following properties may be passed when building these projects. - - /p:BuildForRelease=(true|false) - When true, adds extra verification to ensure a complete installer is - produced. For example, binutils is required when building for a release - to generate MinGW-compatible libraries, and the build will be aborted if - this fails. Defaults to false. - - /p:ReleaseUri=(any URI) - Used to generate unique IDs for the installers to allow side-by-side - installation. Forks of Python can use the same installer infrastructure - by providing a unique URI for this property. It does not need to be an - active internet address. Defaults to $(ComputerName). - - Official releases use http://www.python.org/(architecture name) - - /p:DownloadUrlBase=(any URI) - Specifies the base of a URL where missing parts of the installer layout - can be downloaded from. The build version and architecture will be - appended to create the full address. If omitted, missing components will - not be automatically downloaded. - - /p:DownloadUrl=(any URI) - Specifies the full URL where missing parts of the installer layout can - be downloaded from. Should normally include '{2}', which will be - substituted for the filename. If omitted, missing components will not be - automatically downloaded. If specified, this value overrides - DownloadUrlBase. - - /p:SigningCertificate=(certificate name) - Specifies the certificate to sign the installer layout with. If omitted, - the layout will not be signed. - - /p:RebuildAll=(true|false) - When true, rebuilds all of the MSIs making up the layout. Defaults to - true. - -Uploading the Installer -======================= - -For official releases, the uploadrelease.bat script should be used. - -You will require PuTTY so that plink.exe and pscp.exe can be used, and your -SSH key can be activated in pageant.exe. PuTTY should be either on your path -or in %ProgramFiles(x86)%\PuTTY. - -To include signatures for each uploaded file, you will need gpg2.exe on your -path or have run get_externals.bat. You may also need to "gpg2.exe --import" -your key before running the upload script. - - uploadrelease.bat --host --user [--dry-run] [--no-gpg] - -The host is the URL to the server. This can be provided by the Release -Manager. You should be able to SSH to this address. - -The username is your own username, which you have permission to SSH into -the server containing downloads. - -Use --dry-run to display the generated upload commands without executing -them. Signatures for each file will be generated but not uploaded unless ---no-gpg is also passed. - -Use --no-gpg to suppress signature generation and upload. - -The default target directory (which appears in uploadrelease.proj) is -correct for official Python releases, but may be overridden with ---target for other purposes. This path should generally not include -any version specifier, as that will be added automatically. - -Modifying the Installer -======================= - -The code for the installer is divided into three main groups: packages, -the bundle and the bootstrap application. - -Packages --------- - -Packages appear as subdirectories of Tools/msi (other than the bundle/ -directory). The project file is a .wixproj and the build output is a -single MSI. Packages are built with the WiX Toolset. Some project files -share source files and use preprocessor directives to enable particular -features. These are typically used to keep the sources close when the -files are related, but produce multiple independent packages. - -A package is the smallest element that may be independently installed or -uninstalled (as used in this installer). For example, the test suite has -its own package, as users can choose to add or remove it after the -initial installation. - -All the files installed by a single package should be related, though -some packages may not install any files. For example, the pip package -executes the ensurepip package, but does not add or remove any of its -own files. (It is represented as a package because of its -installed/uninstalled nature, as opposed to the "precompile standard -library" option, for example.) Dependencies between packages are handled -by the bundle, but packages should detect when dependencies are missing -and raise an error. - -Packages that include a lot of files may use an InstallFiles element in -the .wixproj file to generate sources. See lib/lib.wixproj for an -example, and msi.targets and csv_to_wxs.py for the implementation. This -element is also responsible for generating the code for cleaning up and -removing __pycache__ folders in any directory containing .py files. - -All packages are built with the Tools/msi/common.wxs file, and so any -directory or property in this file may be referenced. Of particular -interest: - - REGISTRYKEY (property) - The registry key for the current installation. - - InstallDirectory (directory) - The root install directory for the current installation. Subdirectories - are also specified in this file (DLLs, Lib, etc.) - - MenuDir (directory) - The Start Menu folder for the current installation. - - UpgradeTable (property) - Every package should reference this property to include upgrade - information. - - OptionalFeature (Component) - Packages that may be enabled or disabled should reference this component - and have an OPTIONAL_FEATURES entry in the bootstrap application to - properly handle Modify and Upgrade. - -The .wxl_template file is specially handled by the build system for this -project to perform {{substitutions}} as defined in msi.targets. They -should be included in projects as items, where .wxl files -are normally included as items. - -Bundle ------- - -The bundle is compiled to the main EXE entry point that for most users -will represent the Python installer. It is built from Tools/msi/bundle -with packages references in Tools/msi/bundle/packagegroups. - -Build logic for the bundle is in bundle.targets, but should be invoked -through one of the .wixproj files as described in Building the -Installer. - -The UI is separated between Default.thm (UI layout), Default.wxl -(strings), bundle.wxs (properties) and the bootstrap application. -Bundle.wxs also contains the chain, which is the list of packages to -install and the order they should be installed in. These refer to named -package groups in bundle/packagegroups. - -Each package group specifies one or more packages to install. Most -packages require two separate entries to support both per-user and -all-users installations. Because these reuse the same package, it does -not increase the overall size of the package. - -Package groups refer to payload groups, which allow better control over -embedding and downloading files than the default settings. Whether files -are embedded and where they are downloaded from depends on settings -created by the project files. - -Package references can include install conditions that determine when to -install the package. When a package is a dependency for others, the -condition should be crafted to ensure it is installed. - -MSI packages are installed or uninstalled based on their current state -and the install condition. This makes them most suitable for features -that are clearly present or absent from the user's machine. - -EXE packages are executed based on a customisable condition that can be -omitted. This makes them suitable for pre- or post-install tasks that -need to run regardless of whether features have been added or removed. - -Bootstrap Application ---------------------- - -The bootstrap application is a C++ application that controls the UI and -installation. While it does not directly compile into the main EXE of -the installer, it forms the main active component. Most of the -installation functionality is provided by WiX, and so the bootstrap -application is predominantly responsible for the code behind the UI that -is defined in the Default.thm file. The bootstrap application code is in -bundle/bootstrap and is built automatically when building the bundle. - -Installation Layout -=================== - -There are two installation layouts for Python on Windows, with the only -differences being supporting files. A layout is selected implicitly -based on whether the install is for all users of the machine or just for -the user performing the installation. - -The default installation location when installing for all users is -"%ProgramFiles%\Python3X" for the 64-bit interpreter and -"%ProgramFiles(x86)%\Python3X-32" for the 32-bit interpreter. (Note that -the latter path is equivalent to "%ProgramFiles%\Python3X-32" when -running a 32-bit version of Windows.) This location requires -administrative privileges to install or later modify the installation. - -The default installation location when installing for the current user -is "%LocalAppData%\Programs\Python\Python3X" for the 64-bit interpreter -and "%LocalAppData%\Programs\Python\Python3X-32" for the 32-bit -interpreter. Only the current user can access this location. This -provides a suitable level of protection against malicious modification -of Python's files. - -(Default installation locations are set in Tools\msi\bundle\bundle.wxs.) - -Within this install directory is the following approximate layout: - -.\python[w].exe The core executable files -.\DLLs Stdlib extensions (*.pyd) and dependencies -.\Doc Documentation (*.chm) -.\include Development headers (*.h) -.\Lib Standard library -.\Lib\test Test suite -.\libs Development libraries (*.lib) -.\Scripts Launcher scripts (*.exe, *.py) -.\tcl Tcl dependencies (*.dll, *.tcl and others) -.\Tools Tool scripts (*.py) - -When installed for all users, the following files are installed to -either "%SystemRoot%\System32" or "%SystemRoot%\SysWOW64" as -appropriate. For the current user, they are installed in the Python -install directory. - -.\python3x.dll The core interpreter -.\python3.dll The stable ABI reference - -When installed for all users, the following files are installed to -"%SystemRoot%" (typically "C:\Windows") to ensure they are always -available on PATH. (See Launching Python below.) For the current user, -they are installed in "%LocalAppData%\Programs\Python\PyLauncher". - -.\py[w].exe PEP 397 launcher - -System Settings -=============== - -On installation, registry keys are created so that other applications -can locate and identify installations of Python. The locations of these -keys vary based on the install type. - -For 64-bit interpreters installed for all users, the root key is: - HKEY_LOCAL_MACHINE\Software\Python\PythonCore\3.X - -For 32-bit interpreters installed for all users on a 64-bit operating -system, the root key is: - HKEY_LOCAL_MACHINE\Software\Wow6432Node\Python\PythonCore\3.X-32 - -For 32-bit interpreters installed for all users on a 32-bit operating -system, the root key is: - HKEY_LOCAL_MACHINE\Software\Python\PythonCore\3.X-32 - -For 64-bit interpreters installed for the current user: - HKEY_CURRENT_USER\Software\Python\PythonCore\3.X - -For 32-bit interpreters installed for the current user: - HKEY_CURRENT_USER\Software\Python\PythonCore\3.X-32 - -When the core Python executables are installed, a key "InstallPath" is -created within the root key with its default value set to the -executable's install directory. A value named "ExecutablePath" is added -with the full path to the main Python interpreter, and a key -"InstallGroup" is created with its default value set to the product -name "Python 3.X". - -When the Python standard library is installed, a key "PythonPath" is -created within the root key with its default value set to the full path -to the Lib folder followed by the path to the DLLs folder, separated by -a semicolon. - -When the documentation is installed, a key "Help" is created within the -root key, with a subkey "Main Python Documentation" with its default -value set to the full path to the installed CHM file. - - -The py.exe launcher is installed as part of a regular Python install, -but using a separate mechanism that allows it to more easily span -versions of Python. As a result, it has different root keys for its -registry entries: - -When installed for all users on a 64-bit operating system, the -launcher's root key is: - HKEY_LOCAL_MACHINE\Software\Wow6432Node\Python\Launcher - -When installed for all users on a 32-bit operating system, the -launcher's root key is: - HKEY_LOCAL_MACHINE\Software\Python\Launcher - -When installed for the current user: - HKEY_CURRENT_USER\Software\Python\Launcher - -When the launcher is installed, a key "InstallPath" is created within -its root key with its default value set to the launcher's install -directory. File associations are also created for .py, .pyw, .pyc and -.pyo files. - -Launching Python -================ - -When a feature offering user entry points in the Start Menu is -installed, a folder "Python 3.X" is created. Every shortcut should be -created within this folder, and each shortcut should include the version -and platform to allow users to identify the shortcut in a search results -page. - -The core Python executables creates a shortcut "Python 3.X (32-bit)" or -"Python 3.X (64-bit)" depending on the interpreter. - -The documentation creates a shortcut "Python 3.X 32-bit Manuals" or -"Python 3.X 64-bit Manuals". The documentation is identical for all -platforms, but the shortcuts need to be separate to avoid uninstallation -conflicts. - -Installing IDLE creates a shortcut "IDLE (Python 3.X 32-bit)" or "IDLE -(Python 3.X 64-bit)" depending on the interpreter. - - -For users who often launch Python from a Command Prompt, an option is -provided to add the directory containing python.exe to the user or -system PATH variable. If the option is selected, the install directory -and the Scripts directory will be added at the start of the system PATH -for an all users install and the user PATH for a per-user install. - -When the user only has one version of Python installed, this will behave -as expected. However, because Windows searches the system PATH before -the user PATH, users cannot override a system-wide installation of -Python on their PATH. Further, because the installer can only prepend to -the path, later installations of Python will take precedence over -earlier installations, regardless of interpreter version. - -Because it is not possible to automatically create a sensible PATH -configuration, users are recommended to use the py.exe launcher and -manually modify their PATH variable to add Scripts directories in their -preferred order. System-wide installations of Python should consider not -modifying PATH, or using an alternative technology to modify their -users' PATH variables. - - -The py.exe launcher is recommended because it uses a consistent and -sensible search order for Python installations. User installations are -preferred over system-wide installs, and later versions are preferred -regardless of installation order (with the exception that py.exe -currently prefers 2.x versions over 3.x versions without the -3 command -line argument). - -For both 32-bit and 64-bit interpreters, the 32-bit version of the -launcher is installed. This ensures that the search order is always -consistent (as the 64-bit launcher is subtly different from the 32-bit -launcher) and also avoids the need to install it multiple times. Future -versions of Python will upgrade the launcher in-place, using Windows -Installer's upgrade functionality to avoid conflicts with earlier -installed versions. - -When installed, file associations are created for .py, .pyc and .pyo -files to launch with py.exe and .pyw files to launch with pyw.exe. This -makes Python files respect shebang lines by default and also avoids -conflicts between multiple Python installations. - - -Repair, Modify and Uninstall -============================ - -After installation, Python may be modified, repaired or uninstalled by -running the original EXE again or via the Programs and Features applet -(formerly known as Add or Remove Programs). - -Modifications allow features to be added or removed. The install -directory and kind (all users/single user) cannot be modified. Because -Windows Installer caches installation packages, removing features will -not require internet access unless the package cache has been corrupted -or deleted. Adding features that were not previously installed and are -not embedded or otherwise available will require internet access. - -Repairing will rerun the installation for all currently installed -features, restoring files and registry keys that have been modified or -removed. This operation generally will not redownload any files unless -the cached packages have been corrupted or deleted. - -Removing Python will clean up all the files and registry keys that were -created by the installer, as well as __pycache__ folders that are -explicitly handled by the installer. Python packages installed later -using a tool like pip will not be removed. Some components may be -installed by other installers and these will not be removed if another -product has a dependency on them. - diff --git a/third_party/python/Tools/msi/build.bat b/third_party/python/Tools/msi/build.bat deleted file mode 100644 index f720ea9a8..000000000 --- a/third_party/python/Tools/msi/build.bat +++ /dev/null @@ -1,79 +0,0 @@ -@echo off -setlocal -set D=%~dp0 -set PCBUILD=%D%..\..\PCBuild\ - -set BUILDX86= -set BUILDX64= -set BUILDDOC= -set BUILDTEST=--test-marker -set BUILDPACK= -set REBUILD= - -:CheckOpts -if "%~1" EQU "-h" goto Help -if "%~1" EQU "-x86" (set BUILDX86=1) && shift && goto CheckOpts -if "%~1" EQU "-x64" (set BUILDX64=1) && shift && goto CheckOpts -if "%~1" EQU "--doc" (set BUILDDOC=1) && shift && goto CheckOpts -if "%~1" EQU "--no-test-marker" (set BUILDTEST=) && shift && goto CheckOpts -if "%~1" EQU "--pack" (set BUILDPACK=1) && shift && goto CheckOpts -if "%~1" EQU "-r" (set REBUILD=-r) && shift && goto CheckOpts - -if not defined BUILDX86 if not defined BUILDX64 (set BUILDX86=1) && (set BUILDX64=1) - -call "%D%get_externals.bat" -call "%PCBUILD%find_msbuild.bat" %MSBUILD% -if ERRORLEVEL 1 (echo Cannot locate MSBuild.exe on PATH or as MSBUILD variable & exit /b 2) - -if defined BUILDX86 ( - call "%PCBUILD%build.bat" -d -e %REBUILD% %BUILDTEST% - if errorlevel 1 goto :eof - call "%PCBUILD%build.bat" -e %REBUILD% %BUILDTEST% - if errorlevel 1 goto :eof -) -if defined BUILDX64 ( - call "%PCBUILD%build.bat" -p x64 -d -e %REBUILD% %BUILDTEST% - if errorlevel 1 goto :eof - call "%PCBUILD%build.bat" -p x64 -e %REBUILD% %BUILDTEST% - if errorlevel 1 goto :eof -) - -if defined BUILDDOC ( - call "%PCBUILD%..\Doc\make.bat" htmlhelp - if errorlevel 1 goto :eof -) - -rem Build the launcher MSI separately -%MSBUILD% "%D%launcher\launcher.wixproj" /p:Platform=x86 - -set BUILD_CMD="%D%bundle\snapshot.wixproj" -if defined BUILDTEST ( - set BUILD_CMD=%BUILD_CMD% /p:UseTestMarker=true -) -if defined BUILDPACK ( - set BUILD_CMD=%BUILD_CMD% /p:Pack=true -) -if defined REBUILD ( - set BUILD_CMD=%BUILD_CMD% /t:Rebuild -) - -if defined BUILDX86 ( - %MSBUILD% %BUILD_CMD% - if errorlevel 1 goto :eof -) -if defined BUILDX64 ( - %MSBUILD% /p:Platform=x64 %BUILD_CMD% - if errorlevel 1 goto :eof -) - -exit /B 0 - -:Help -echo build.bat [-x86] [-x64] [--doc] [-h] [--no-test-marker] [--pack] [-r] -echo. -echo -x86 Build x86 installers -echo -x64 Build x64 installers -echo --doc Build CHM documentation -echo --no-test-marker Build without test markers -echo --pack Embed core MSIs into installer -echo -r Rebuild rather than incremental build diff --git a/third_party/python/Tools/msi/buildrelease.bat b/third_party/python/Tools/msi/buildrelease.bat deleted file mode 100644 index d19950b65..000000000 --- a/third_party/python/Tools/msi/buildrelease.bat +++ /dev/null @@ -1,234 +0,0 @@ -@setlocal -@echo off - -rem This script is intended for building official releases of Python. -rem To use it to build alternative releases, you should clone this file -rem and modify the following three URIs. - -rem These two will ensure that your release can be installed -rem alongside an official Python release, by modifying the GUIDs used -rem for all components. -rem -rem The following substitutions will be applied to the release URI: -rem Variable Description Example -rem {arch} architecture amd64, win32 -set RELEASE_URI=http://www.python.org/{arch} - -rem This is the URL that will be used to download installation files. -rem The files available from the default URL *will* conflict with your -rem installer. Trust me, you don't want them, even if it seems like a -rem good idea. -rem -rem The following substitutions will be applied to the download URL: -rem Variable Description Example -rem {version} version number 3.5.0 -rem {arch} architecture amd64, win32 -rem {releasename} release name a1, b2, rc3 (or blank for final) -rem {msi} MSI filename core.msi -set DOWNLOAD_URL=https://www.python.org/ftp/python/{version}/{arch}{releasename}/{msi} - -set D=%~dp0 -set PCBUILD=%D%..\..\PCBuild\ -if "%Py_OutDir%"=="" set Py_OutDir=%PCBUILD% -set EXTERNALS=%D%..\..\externals\windows-installer\ - -set BUILDX86= -set BUILDX64= -set TARGET=Rebuild -set TESTTARGETDIR= -set PGO=-m test -q --pgo -set BUILDNUGET=1 -set BUILDZIP=1 - - -:CheckOpts -if "%1" EQU "-h" goto Help -if "%1" EQU "-c" (set CERTNAME=%~2) && shift && shift && goto CheckOpts -if "%1" EQU "--certificate" (set CERTNAME=%~2) && shift && shift && goto CheckOpts -if "%1" EQU "-o" (set OUTDIR=%~2) && shift && shift && goto CheckOpts -if "%1" EQU "--out" (set OUTDIR=%~2) && shift && shift && goto CheckOpts -if "%1" EQU "-D" (set SKIPDOC=1) && shift && goto CheckOpts -if "%1" EQU "--skip-doc" (set SKIPDOC=1) && shift && goto CheckOpts -if "%1" EQU "-B" (set SKIPBUILD=1) && shift && goto CheckOpts -if "%1" EQU "--skip-build" (set SKIPBUILD=1) && shift && goto CheckOpts -if "%1" EQU "--download" (set DOWNLOAD_URL=%~2) && shift && shift && goto CheckOpts -if "%1" EQU "--test" (set TESTTARGETDIR=%~2) && shift && shift && goto CheckOpts -if "%1" EQU "-b" (set TARGET=Build) && shift && goto CheckOpts -if "%1" EQU "--build" (set TARGET=Build) && shift && goto CheckOpts -if "%1" EQU "-x86" (set BUILDX86=1) && shift && goto CheckOpts -if "%1" EQU "-x64" (set BUILDX64=1) && shift && goto CheckOpts -if "%1" EQU "--pgo" (set PGO=%~2) && shift && shift && goto CheckOpts -if "%1" EQU "--skip-pgo" (set PGO=) && shift && goto CheckOpts -if "%1" EQU "--skip-nuget" (set BUILDNUGET=) && shift && goto CheckOpts -if "%1" EQU "--skip-zip" (set BUILDZIP=) && shift && goto CheckOpts - -if "%1" NEQ "" echo Invalid option: "%1" && exit /B 1 - -if not defined BUILDX86 if not defined BUILDX64 (set BUILDX86=1) && (set BUILDX64=1) - -if not exist "%GIT%" where git > "%TEMP%\git.loc" 2> nul && set /P GIT= < "%TEMP%\git.loc" & del "%TEMP%\git.loc" -if not exist "%GIT%" echo Cannot find Git on PATH && exit /B 1 - -call "%D%get_externals.bat" -call "%PCBUILD%find_msbuild.bat" %MSBUILD% -if ERRORLEVEL 1 (echo Cannot locate MSBuild.exe on PATH or as MSBUILD variable & exit /b 2) - -:builddoc -if "%SKIPBUILD%" EQU "1" goto skipdoc -if "%SKIPDOC%" EQU "1" goto skipdoc - -call "%D%..\..\doc\make.bat" htmlhelp -if errorlevel 1 goto :eof -:skipdoc - -where dlltool /q && goto skipdlltoolsearch -set _DLLTOOL_PATH= -where /R "%EXTERNALS%\" dlltool > "%TEMP%\dlltool.loc" 2> nul && set /P _DLLTOOL_PATH= < "%TEMP%\dlltool.loc" & del "%TEMP%\dlltool.loc" -if not exist "%_DLLTOOL_PATH%" echo Cannot find binutils on PATH or in external && exit /B 1 -for %%f in (%_DLLTOOL_PATH%) do set PATH=%PATH%;%%~dpf -set _DLLTOOL_PATH= -:skipdlltoolsearch - -if defined BUILDX86 ( - call :build x86 - if errorlevel 1 exit /B -) - -if defined BUILDX64 ( - call :build x64 "%PGO%" - if errorlevel 1 exit /B -) - -if defined TESTTARGETDIR ( - call "%D%testrelease.bat" -t "%TESTTARGETDIR%" -) - -exit /B 0 - -:build -@setlocal -@echo off - -if "%1" EQU "x86" ( - set PGO= - set BUILD=%Py_OutDir%win32\ - set BUILD_PLAT=Win32 - set OUTDIR_PLAT=win32 - set OBJDIR_PLAT=x86 -) else ( - set BUILD=%Py_OutDir%amd64\ - set PGO=%~2 - set BUILD_PLAT=x64 - set OUTDIR_PLAT=amd64 - set OBJDIR_PLAT=x64 -) - -if exist "%BUILD%en-us" ( - echo Deleting %BUILD%en-us - rmdir /q/s "%BUILD%en-us" - if errorlevel 1 exit /B -) - -if exist "%D%obj\Debug_%OBJDIR_PLAT%" ( - echo Deleting "%D%obj\Debug_%OBJDIR_PLAT%" - rmdir /q/s "%D%obj\Debug_%OBJDIR_PLAT%" - if errorlevel 1 exit /B -) - -if exist "%D%obj\Release_%OBJDIR_PLAT%" ( - echo Deleting "%D%obj\Release_%OBJDIR_PLAT%" - rmdir /q/s "%D%obj\Release_%OBJDIR_PLAT%" - if errorlevel 1 exit /B -) - -if not "%CERTNAME%" EQU "" ( - set CERTOPTS="/p:SigningCertificate=%CERTNAME%" -) else ( - set CERTOPTS= -) -if not "%PGO%" EQU "" ( - set PGOOPTS=--pgo-job "%PGO%" -) else ( - set PGOOPTS= -) -if not "%SKIPBUILD%" EQU "1" ( - @echo call "%PCBUILD%build.bat" -e -p %BUILD_PLAT% -t %TARGET% %PGOOPTS% %CERTOPTS% - @call "%PCBUILD%build.bat" -e -p %BUILD_PLAT% -t %TARGET% %PGOOPTS% %CERTOPTS% - @if errorlevel 1 exit /B - @rem build.bat turns echo back on, so we disable it again - @echo off - - @echo call "%PCBUILD%build.bat" -d -e -p %BUILD_PLAT% -t %TARGET% - @call "%PCBUILD%build.bat" -d -e -p %BUILD_PLAT% -t %TARGET% - @if errorlevel 1 exit /B - @rem build.bat turns echo back on, so we disable it again - @echo off -) - -if "%OUTDIR_PLAT%" EQU "win32" ( - %MSBUILD% "%D%launcher\launcher.wixproj" /p:Platform=x86 %CERTOPTS% /p:ReleaseUri=%RELEASE_URI% - if errorlevel 1 exit /B -) else if not exist "%Py_OutDir%win32\en-us\launcher.msi" ( - %MSBUILD% "%D%launcher\launcher.wixproj" /p:Platform=x86 %CERTOPTS% /p:ReleaseUri=%RELEASE_URI% - if errorlevel 1 exit /B -) - -set BUILDOPTS=/p:Platform=%1 /p:BuildForRelease=true /p:DownloadUrl=%DOWNLOAD_URL% /p:DownloadUrlBase=%DOWNLOAD_URL_BASE% /p:ReleaseUri=%RELEASE_URI% -%MSBUILD% "%D%bundle\releaselocal.wixproj" /t:Rebuild %BUILDOPTS% %CERTOPTS% /p:RebuildAll=true -if errorlevel 1 exit /B -%MSBUILD% "%D%bundle\releaseweb.wixproj" /t:Rebuild %BUILDOPTS% %CERTOPTS% /p:RebuildAll=false -if errorlevel 1 exit /B - -if defined BUILDZIP ( - %MSBUILD% "%D%make_zip.proj" /t:Build %BUILDOPTS% %CERTOPTS% /p:OutputPath="%BUILD%en-us" - if errorlevel 1 exit /B -) - -if defined BUILDNUGET ( - %MSBUILD% "%D%..\nuget\make_pkg.proj" /t:Build /p:Configuration=Release /p:Platform=%1 /p:OutputPath="%BUILD%en-us" - if errorlevel 1 exit /B -) - -if not "%OUTDIR%" EQU "" ( - mkdir "%OUTDIR%\%OUTDIR_PLAT%" - mkdir "%OUTDIR%\%OUTDIR_PLAT%\binaries" - mkdir "%OUTDIR%\%OUTDIR_PLAT%\symbols" - robocopy "%BUILD%en-us" "%OUTDIR%\%OUTDIR_PLAT%" /XF "*.wixpdb" - robocopy "%BUILD%\" "%OUTDIR%\%OUTDIR_PLAT%\binaries" *.exe *.dll *.pyd /XF "_test*" /XF "*_d.*" /XF "_freeze*" /XF "tcl*" /XF "tk*" /XF "*_test.*" - robocopy "%BUILD%\" "%OUTDIR%\%OUTDIR_PLAT%\symbols" *.pdb /XF "_test*" /XF "*_d.*" /XF "_freeze*" /XF "tcl*" /XF "tk*" /XF "*_test.*" -) - -exit /B 0 - -:Help -echo buildrelease.bat [--out DIR] [-x86] [-x64] [--certificate CERTNAME] [--build] [--pgo COMMAND] -echo [--skip-build] [--skip-doc] [--skip-nuget] [--skip-zip] [--skip-pgo] -echo [--download DOWNLOAD URL] [--test TARGETDIR] -echo [-h] -echo. -echo --out (-o) Specify an additional output directory for installers -echo -x86 Build x86 installers -echo -x64 Build x64 installers -echo --build (-b) Incrementally build Python rather than rebuilding -echo --skip-build (-B) Do not build Python (just do the installers) -echo --skip-doc (-D) Do not build documentation -echo --pgo Specify PGO command for x64 installers -echo --skip-pgo Build x64 installers without using PGO -echo --skip-nuget Do not build Nuget packages -echo --skip-zip Do not build embeddable package -echo --download Specify the full download URL for MSIs -echo --test Specify the test directory to run the installer tests -echo -h Display this help information -echo. -echo If no architecture is specified, all architectures will be built. -echo If --test is not specified, the installer tests are not run. -echo. -echo For the --pgo option, any Python command line can be used, or 'default' to -echo use the default task (-m test --pgo). -echo. -echo The following substitutions will be applied to the download URL: -echo Variable Description Example -echo {version} version number 3.5.0 -echo {arch} architecture amd64, win32 -echo {releasename} release name a1, b2, rc3 (or blank for final) -echo {msi} MSI filename core.msi diff --git a/third_party/python/Tools/msi/bundle/Default.thm b/third_party/python/Tools/msi/bundle/Default.thm deleted file mode 100644 index 1c0bd08ee..000000000 --- a/third_party/python/Tools/msi/bundle/Default.thm +++ /dev/null @@ -1,137 +0,0 @@ - - - #(loc.Caption) - Segoe UI - Segoe UI - Segoe UI - Segoe UI - Segoe UI - Segoe UI - - - #(loc.HelpHeader) - - - #(loc.HelpText) - - - - #(loc.InstallHeader) - - - #(loc.InstallMessage) - - - - - #(loc.ShortInstallLauncherAllUsersLabel) - #(loc.ShortPrependPathLabel) - - - - - #(loc.InstallUpgradeHeader) - - - #(loc.InstallUpgradeMessage) - - - - - - - - #(loc.InstallHeader) - - - - - - - - #(loc.Custom1Header) - - - #(loc.Include_docLabel) - #(loc.Include_docHelpLabel) - - #(loc.Include_pipLabel) - #(loc.Include_pipHelpLabel) - - #(loc.Include_tcltkLabel) - #(loc.Include_tcltkHelpLabel) - - #(loc.Include_testLabel) - #(loc.Include_testHelpLabel) - - #(loc.Include_launcherLabel) - #(loc.InstallLauncherAllUsersLabel) - - - - - - - - #(loc.Custom2Header) - - - #(loc.InstallAllUsersLabel) - #(loc.AssociateFilesLabel) - #(loc.ShortcutsLabel) - #(loc.PrependPathLabel) - #(loc.PrecompileLabel) - #(loc.Include_symbolsLabel) - #(loc.Include_debugLabel) - - #(loc.CustomLocationLabel) - - - #(loc.CustomLocationHelpLabel) - - - - - - - #(loc.ProgressHeader) - - - #(loc.ProgressLabel) - #(loc.OverallProgressPackageText) - - - - - #(loc.ModifyHeader) - - - - - - - - - - #(loc.SuccessHeader) - - - - - - - #(loc.SuccessRestartText) - - - - - #(loc.FailureHeader) - - - #(loc.FailureHyperlinkLogText) - - #(loc.FailureRestartText) - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/bundle/Default.wxl b/third_party/python/Tools/msi/bundle/Default.wxl deleted file mode 100644 index 43506d610..000000000 --- a/third_party/python/Tools/msi/bundle/Default.wxl +++ /dev/null @@ -1,148 +0,0 @@ - - - [WixBundleName] Setup - [WixBundleName] - Installing - Setup - Updating - Modify - Repairing - Repair - Removing - Uninstall - - You will be prompted for Administrator privileges to install a C Runtime Library update (KB2999226). - - -Continue? - - &Cancel - &Close - Install [WixBundleName] - Select Install Now to install Python with default settings, or choose Customize to enable or disable features. - Version [WixBundleVersion] - Upgrade to [WixBundleName] - Select Upgrade Now to keep your current settings, or choose Customize to enable or disable features. - Are you sure you want to cancel? - Previous version - Setup Help - Visit <a href="http://docs.python.org/[ShortVersion]/using/windows.html">docs.python.org/[ShortVersion]/using/windows.html</a> for the full list of options, including the ability to enable and disable specific features. - -"/passive" to display progress without requiring user interaction - -"/quiet" to install/uninstall without displaying any UI - -"/simple" to prevent user customization - -"/uninstall" to remove Python (without confirmation) - -"/layout [\[]directory[\]]" to pre-download all components - -"/log [\[]filename[\]]" to specify log files location - [WixBundleName] <a href="#">license terms</a>. - I &agree to the license terms and conditions - &Install Now - [TargetDir] - -Includes IDLE, pip and documentation -Creates shortcuts and file associations - C&ustomize installation - Choose location and features - &Install - Use settings preselected by your administrator - -[SimpleInstallDescription] - Up&grade Now - [TargetDir] - -Replaces your existing installation without changing settings. -Select Customize to review current options. - C&ustomize installation - Choose location and features - Optional Features - Advanced Options - Customize install location - You will require write permissions for the selected location. - &Install - &Next - &Back - B&rowse - &Documentation - Installs the Python documentation file. - &pip - Installs pip, which can download and install other Python packages. - tcl/tk and &IDLE - Installs tkinter and the IDLE development environment. - Python &test suite - Installs the standard library test suite. - py &launcher - Installs the global 'py' launcher to make it easier to start Python. - Use Programs and Features to remove the 'py' launcher. - Upgrades the global 'py' launcher from the previous version. - - Associate &files with Python (requires the py launcher) - Create shortcuts for installed applications - Add Python to &environment variables - Add &Python [ShortVersion] to PATH - Install for &all users - for &all users (requires elevation) - Install &launcher for all users (recommended) - &Precompile standard library - Download debugging &symbols - Download debu&g binaries (requires VS 2015 or later) - - [ActionLikeInstallation] Progress - [ActionLikeInstalling]: - Initializing... - Modify Setup - &Modify - Add or remove individual features. - &Repair - Ensure all current features are correctly installed. - &Uninstall - Remove the entire [WixBundleName] installation. - [ActionLikeInstallation] was successful - &Launch - You may need to restart your computer to finish updating files. - &Restart - Special thanks to Mark Hammond, without whose years of freely shared Windows expertise, Python for Windows would still be Python for DOS. - -New to Python? Start with the <a href="https://docs.python.org/[ShortVersion]/tutorial/index.html">online tutorial</a> and <a href="https://docs.python.org/[ShortVersion]/index.html">documentation</a>. - -See <a href="https://docs.python.org/[ShortVersion]/whatsnew/[ShortVersion].html">what's new</a> in this release. - Thank you for using [WixBundleName]. - Thank you for using [WixBundleName]. - -Feel free to email <a href="mailto:python-list@python.org">python-list@python.org</a> if you continue to encounter issues. - Thank you for using [WixBundleName]. - -Feel free to email <a href="mailto:python-list@python.org">python-list@python.org</a> if you encountered problems. - Setup failed - One or more issues caused the setup to fail. Please fix the issues and then retry setup. For more information see the <a href="#">log file</a>. - You must restart your computer to complete the rollback of the software. - &Restart - Unable to install [WixBundleName] due to an existing install. Use Programs and Features to modify, repair or remove [WixBundleName]. - - Windows 7 Service Pack 1 and all applicable updates are required to install [WixBundleName]. - -Please <a href="https://www.bing.com/search?q=how%20to%20install%20windows%207%20service%20pack%201">update your machine</a> and then restart the installation. - Windows Vista Service Pack 2 and all applicable updates are required to install [WixBundleName]. - -Please <a href="https://www.bing.com/search?q=how%20to%20install%20windows%20vista%20service%20pack%202">update your machine</a> and then restart the installation. - Windows Vista or later is required to install and use [WixBundleName]. - -Visit <a href="https://www.python.org/">python.org</a> to download Python 3.4. - - Windows Server 2008 R2 Service Pack 1 and all applicable updates are required to install [WixBundleName]. - -Please <a href="https://www.bing.com/search?q=how%20to%20install%20windows%20server%202008%20r2%20service%20pack%201">update your machine</a> and then restart the installation. - Windows Server 2008 Service Pack 2 and all applicable updates are required to install [WixBundleName]. - -Please <a href="https://www.bing.com/search?q=how%20to%20install%20windows%20server%202008%20service%20pack%202">update your machine</a> and then restart the installation. - Windows Server 2008 SP2 or later is required to install and use [WixBundleName]. - -Visit <a href="https://www.python.org/">python.org</a> to download Python 3.4. - - Disable path length limit - Changes your machine configuration to allow programs, including Python, to bypass the 260 character "MAX_PATH" limitation. - diff --git a/third_party/python/Tools/msi/bundle/SideBar.png b/third_party/python/Tools/msi/bundle/SideBar.png deleted file mode 100644 index a23ce5e14..000000000 Binary files a/third_party/python/Tools/msi/bundle/SideBar.png and /dev/null differ diff --git a/third_party/python/Tools/msi/bundle/bootstrap/LICENSE.txt b/third_party/python/Tools/msi/bundle/bootstrap/LICENSE.txt deleted file mode 100644 index 5791a7e81..000000000 --- a/third_party/python/Tools/msi/bundle/bootstrap/LICENSE.txt +++ /dev/null @@ -1,25 +0,0 @@ -This license applies to the bootstrapper application that is embedded within the installer. It has no impact on the licensing for the rest of the installer or Python itself, as no code covered by this license exists in any other part of the product. - ---- - -Microsoft Reciprocal License (MS-RL) - -This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software. - -1. Definitions - The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law. - A "contribution" is the original software, or any additions or changes to the software. - A "contributor" is any person that distributes its contribution under this license. - "Licensed patents" are a contributor's patent claims that read directly on its contribution. - -2. Grant of Rights - (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create. - (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software. - -3. Conditions and Limitations - (A) Reciprocal Grants- For any file you distribute that contains code from the software (in source code or binary format), you must provide recipients the source code to that file along with a copy of this license, which license will govern that file. You may license other files that are entirely your own work and do not contain code from the software under any terms you choose. - (B) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. - (C) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically. - (D) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software. - (E) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license. - (F) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement. diff --git a/third_party/python/Tools/msi/bundle/bootstrap/PythonBootstrapperApplication.cpp b/third_party/python/Tools/msi/bundle/bootstrap/PythonBootstrapperApplication.cpp deleted file mode 100644 index d14aeff19..000000000 --- a/third_party/python/Tools/msi/bundle/bootstrap/PythonBootstrapperApplication.cpp +++ /dev/null @@ -1,3273 +0,0 @@ -//------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2004, Outercurve Foundation. -// This software is released under Microsoft Reciprocal License (MS-RL). -// The license and further copyright text can be found in the file -// LICENSE.TXT at the root directory of the distribution. -// -//------------------------------------------------------------------------------------------------- - - -#include "pch.h" - -static const LPCWSTR PYBA_WINDOW_CLASS = L"PythonBA"; -static const DWORD PYBA_ACQUIRE_PERCENTAGE = 30; -static const LPCWSTR PYBA_VARIABLE_BUNDLE_FILE_VERSION = L"WixBundleFileVersion"; - -enum PYBA_STATE { - PYBA_STATE_INITIALIZING, - PYBA_STATE_INITIALIZED, - PYBA_STATE_HELP, - PYBA_STATE_DETECTING, - PYBA_STATE_DETECTED, - PYBA_STATE_PLANNING, - PYBA_STATE_PLANNED, - PYBA_STATE_APPLYING, - PYBA_STATE_CACHING, - PYBA_STATE_CACHED, - PYBA_STATE_EXECUTING, - PYBA_STATE_EXECUTED, - PYBA_STATE_APPLIED, - PYBA_STATE_FAILED, -}; - -static const int WM_PYBA_SHOW_HELP = WM_APP + 100; -static const int WM_PYBA_DETECT_PACKAGES = WM_APP + 101; -static const int WM_PYBA_PLAN_PACKAGES = WM_APP + 102; -static const int WM_PYBA_APPLY_PACKAGES = WM_APP + 103; -static const int WM_PYBA_CHANGE_STATE = WM_APP + 104; -static const int WM_PYBA_SHOW_FAILURE = WM_APP + 105; - -// This enum must be kept in the same order as the PAGE_NAMES array. -enum PAGE { - PAGE_LOADING, - PAGE_HELP, - PAGE_INSTALL, - PAGE_UPGRADE, - PAGE_SIMPLE_INSTALL, - PAGE_CUSTOM1, - PAGE_CUSTOM2, - PAGE_MODIFY, - PAGE_PROGRESS, - PAGE_PROGRESS_PASSIVE, - PAGE_SUCCESS, - PAGE_FAILURE, - COUNT_PAGE, -}; - -// This array must be kept in the same order as the PAGE enum. -static LPCWSTR PAGE_NAMES[] = { - L"Loading", - L"Help", - L"Install", - L"Upgrade", - L"SimpleInstall", - L"Custom1", - L"Custom2", - L"Modify", - L"Progress", - L"ProgressPassive", - L"Success", - L"Failure", -}; - -enum CONTROL_ID { - // Non-paged controls - ID_CLOSE_BUTTON = THEME_FIRST_ASSIGN_CONTROL_ID, - ID_MINIMIZE_BUTTON, - - // Welcome page - ID_INSTALL_BUTTON, - ID_INSTALL_CUSTOM_BUTTON, - ID_INSTALL_SIMPLE_BUTTON, - ID_INSTALL_UPGRADE_BUTTON, - ID_INSTALL_UPGRADE_CUSTOM_BUTTON, - ID_INSTALL_CANCEL_BUTTON, - ID_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX, - - // Customize Page - ID_TARGETDIR_EDITBOX, - ID_CUSTOM_ASSOCIATE_FILES_CHECKBOX, - ID_CUSTOM_INSTALL_ALL_USERS_CHECKBOX, - ID_CUSTOM_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX, - ID_CUSTOM_INCLUDE_LAUNCHER_HELP_LABEL, - ID_CUSTOM_COMPILE_ALL_CHECKBOX, - ID_CUSTOM_BROWSE_BUTTON, - ID_CUSTOM_BROWSE_BUTTON_LABEL, - ID_CUSTOM_INSTALL_BUTTON, - ID_CUSTOM_NEXT_BUTTON, - ID_CUSTOM1_BACK_BUTTON, - ID_CUSTOM2_BACK_BUTTON, - ID_CUSTOM1_CANCEL_BUTTON, - ID_CUSTOM2_CANCEL_BUTTON, - - // Modify page - ID_MODIFY_BUTTON, - ID_REPAIR_BUTTON, - ID_UNINSTALL_BUTTON, - ID_MODIFY_CANCEL_BUTTON, - - // Progress page - ID_CACHE_PROGRESS_PACKAGE_TEXT, - ID_CACHE_PROGRESS_BAR, - ID_CACHE_PROGRESS_TEXT, - - ID_EXECUTE_PROGRESS_PACKAGE_TEXT, - ID_EXECUTE_PROGRESS_BAR, - ID_EXECUTE_PROGRESS_TEXT, - ID_EXECUTE_PROGRESS_ACTIONDATA_TEXT, - - ID_OVERALL_PROGRESS_PACKAGE_TEXT, - ID_OVERALL_PROGRESS_BAR, - ID_OVERALL_CALCULATED_PROGRESS_BAR, - ID_OVERALL_PROGRESS_TEXT, - - ID_PROGRESS_CANCEL_BUTTON, - - // Success page - ID_SUCCESS_TEXT, - ID_SUCCESS_RESTART_TEXT, - ID_SUCCESS_RESTART_BUTTON, - ID_SUCCESS_CANCEL_BUTTON, - ID_SUCCESS_MAX_PATH_BUTTON, - - // Failure page - ID_FAILURE_LOGFILE_LINK, - ID_FAILURE_MESSAGE_TEXT, - ID_FAILURE_RESTART_TEXT, - ID_FAILURE_RESTART_BUTTON, - ID_FAILURE_CANCEL_BUTTON -}; - -static THEME_ASSIGN_CONTROL_ID CONTROL_ID_NAMES[] = { - { ID_CLOSE_BUTTON, L"CloseButton" }, - { ID_MINIMIZE_BUTTON, L"MinimizeButton" }, - - { ID_INSTALL_BUTTON, L"InstallButton" }, - { ID_INSTALL_CUSTOM_BUTTON, L"InstallCustomButton" }, - { ID_INSTALL_SIMPLE_BUTTON, L"InstallSimpleButton" }, - { ID_INSTALL_UPGRADE_BUTTON, L"InstallUpgradeButton" }, - { ID_INSTALL_UPGRADE_CUSTOM_BUTTON, L"InstallUpgradeCustomButton" }, - { ID_INSTALL_CANCEL_BUTTON, L"InstallCancelButton" }, - { ID_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX, L"InstallLauncherAllUsers" }, - - { ID_TARGETDIR_EDITBOX, L"TargetDir" }, - { ID_CUSTOM_ASSOCIATE_FILES_CHECKBOX, L"AssociateFiles" }, - { ID_CUSTOM_INSTALL_ALL_USERS_CHECKBOX, L"InstallAllUsers" }, - { ID_CUSTOM_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX, L"CustomInstallLauncherAllUsers" }, - { ID_CUSTOM_INCLUDE_LAUNCHER_HELP_LABEL, L"Include_launcherHelp" }, - { ID_CUSTOM_COMPILE_ALL_CHECKBOX, L"CompileAll" }, - { ID_CUSTOM_BROWSE_BUTTON, L"CustomBrowseButton" }, - { ID_CUSTOM_BROWSE_BUTTON_LABEL, L"CustomBrowseButtonLabel" }, - { ID_CUSTOM_INSTALL_BUTTON, L"CustomInstallButton" }, - { ID_CUSTOM_NEXT_BUTTON, L"CustomNextButton" }, - { ID_CUSTOM1_BACK_BUTTON, L"Custom1BackButton" }, - { ID_CUSTOM2_BACK_BUTTON, L"Custom2BackButton" }, - { ID_CUSTOM1_CANCEL_BUTTON, L"Custom1CancelButton" }, - { ID_CUSTOM2_CANCEL_BUTTON, L"Custom2CancelButton" }, - - { ID_MODIFY_BUTTON, L"ModifyButton" }, - { ID_REPAIR_BUTTON, L"RepairButton" }, - { ID_UNINSTALL_BUTTON, L"UninstallButton" }, - { ID_MODIFY_CANCEL_BUTTON, L"ModifyCancelButton" }, - - { ID_CACHE_PROGRESS_PACKAGE_TEXT, L"CacheProgressPackageText" }, - { ID_CACHE_PROGRESS_BAR, L"CacheProgressbar" }, - { ID_CACHE_PROGRESS_TEXT, L"CacheProgressText" }, - { ID_EXECUTE_PROGRESS_PACKAGE_TEXT, L"ExecuteProgressPackageText" }, - { ID_EXECUTE_PROGRESS_BAR, L"ExecuteProgressbar" }, - { ID_EXECUTE_PROGRESS_TEXT, L"ExecuteProgressText" }, - { ID_EXECUTE_PROGRESS_ACTIONDATA_TEXT, L"ExecuteProgressActionDataText" }, - { ID_OVERALL_PROGRESS_PACKAGE_TEXT, L"OverallProgressPackageText" }, - { ID_OVERALL_PROGRESS_BAR, L"OverallProgressbar" }, - { ID_OVERALL_CALCULATED_PROGRESS_BAR, L"OverallCalculatedProgressbar" }, - { ID_OVERALL_PROGRESS_TEXT, L"OverallProgressText" }, - { ID_PROGRESS_CANCEL_BUTTON, L"ProgressCancelButton" }, - - { ID_SUCCESS_TEXT, L"SuccessText" }, - { ID_SUCCESS_RESTART_TEXT, L"SuccessRestartText" }, - { ID_SUCCESS_RESTART_BUTTON, L"SuccessRestartButton" }, - { ID_SUCCESS_CANCEL_BUTTON, L"SuccessCancelButton" }, - { ID_SUCCESS_MAX_PATH_BUTTON, L"SuccessMaxPathButton" }, - - { ID_FAILURE_LOGFILE_LINK, L"FailureLogFileLink" }, - { ID_FAILURE_MESSAGE_TEXT, L"FailureMessageText" }, - { ID_FAILURE_RESTART_TEXT, L"FailureRestartText" }, - { ID_FAILURE_RESTART_BUTTON, L"FailureRestartButton" }, - { ID_FAILURE_CANCEL_BUTTON, L"FailureCancelButton" }, -}; - -static struct { LPCWSTR regName; LPCWSTR variableName; } OPTIONAL_FEATURES[] = { - { L"core_d", L"Include_debug" }, - { L"core_pdb", L"Include_symbols" }, - { L"dev", L"Include_dev" }, - { L"doc", L"Include_doc" }, - { L"exe", L"Include_exe" }, - { L"lib", L"Include_lib" }, - { L"path", L"PrependPath" }, - { L"pip", L"Include_pip" }, - { L"tcltk", L"Include_tcltk" }, - { L"test", L"Include_test" }, - { L"tools", L"Include_tools" }, - { L"Shortcuts", L"Shortcuts" }, - // Include_launcher and AssociateFiles are handled separately and so do - // not need to be included in this list. - { nullptr, nullptr } -}; - - - -class PythonBootstrapperApplication : public CBalBaseBootstrapperApplication { - void ShowPage(DWORD newPageId) { - // Process each control for special handling in the new page. - ProcessPageControls(ThemeGetPage(_theme, newPageId)); - - // Enable disable controls per-page. - if (_pageIds[PAGE_INSTALL] == newPageId || - _pageIds[PAGE_SIMPLE_INSTALL] == newPageId || - _pageIds[PAGE_UPGRADE] == newPageId) { - InstallPage_Show(); - } else if (_pageIds[PAGE_CUSTOM1] == newPageId) { - Custom1Page_Show(); - } else if (_pageIds[PAGE_CUSTOM2] == newPageId) { - Custom2Page_Show(); - } else if (_pageIds[PAGE_MODIFY] == newPageId) { - ModifyPage_Show(); - } else if (_pageIds[PAGE_SUCCESS] == newPageId) { - SuccessPage_Show(); - } else if (_pageIds[PAGE_FAILURE] == newPageId) { - FailurePage_Show(); - } - - // Prevent repainting while switching page to avoid ugly flickering - _suppressPaint = TRUE; - ThemeShowPage(_theme, newPageId, SW_SHOW); - ThemeShowPage(_theme, _visiblePageId, SW_HIDE); - _suppressPaint = FALSE; - InvalidateRect(_theme->hwndParent, nullptr, TRUE); - _visiblePageId = newPageId; - - // On the install page set the focus to the install button or - // the next enabled control if install is disabled - if (_pageIds[PAGE_INSTALL] == newPageId) { - ThemeSetFocus(_theme, ID_INSTALL_BUTTON); - } else if (_pageIds[PAGE_SIMPLE_INSTALL] == newPageId) { - ThemeSetFocus(_theme, ID_INSTALL_SIMPLE_BUTTON); - } - } - - // - // Handles control clicks - // - void OnCommand(CONTROL_ID id) { - LPWSTR defaultDir = nullptr; - LPWSTR targetDir = nullptr; - LONGLONG elevated, crtInstalled, installAllUsers; - BOOL checked, launcherChecked; - WCHAR wzPath[MAX_PATH] = { }; - BROWSEINFOW browseInfo = { }; - PIDLIST_ABSOLUTE pidl = nullptr; - DWORD pageId; - HRESULT hr = S_OK; - - switch(id) { - case ID_CLOSE_BUTTON: - OnClickCloseButton(); - break; - - // Install commands - case ID_INSTALL_SIMPLE_BUTTON: __fallthrough; - case ID_INSTALL_UPGRADE_BUTTON: __fallthrough; - case ID_INSTALL_BUTTON: - SavePageSettings(); - - if (!WillElevate() && !QueryElevateForCrtInstall()) { - break; - } - - hr = BalGetNumericVariable(L"InstallAllUsers", &installAllUsers); - ExitOnFailure(hr, L"Failed to get install scope"); - - hr = _engine->SetVariableNumeric(L"CompileAll", installAllUsers); - ExitOnFailure(hr, L"Failed to update CompileAll"); - - hr = EnsureTargetDir(); - ExitOnFailure(hr, L"Failed to set TargetDir"); - - OnPlan(BOOTSTRAPPER_ACTION_INSTALL); - break; - - case ID_CUSTOM1_BACK_BUTTON: - SavePageSettings(); - if (_modifying) { - GoToPage(PAGE_MODIFY); - } else if (_upgrading) { - GoToPage(PAGE_UPGRADE); - } else { - GoToPage(PAGE_INSTALL); - } - break; - - case ID_INSTALL_CUSTOM_BUTTON: __fallthrough; - case ID_INSTALL_UPGRADE_CUSTOM_BUTTON: __fallthrough; - case ID_CUSTOM2_BACK_BUTTON: - SavePageSettings(); - GoToPage(PAGE_CUSTOM1); - break; - - case ID_CUSTOM_NEXT_BUTTON: - SavePageSettings(); - GoToPage(PAGE_CUSTOM2); - break; - - case ID_CUSTOM_INSTALL_BUTTON: - SavePageSettings(); - - hr = EnsureTargetDir(); - ExitOnFailure(hr, L"Failed to set TargetDir"); - - hr = BalGetStringVariable(L"TargetDir", &targetDir); - if (SUCCEEDED(hr)) { - // TODO: Check whether directory exists and contains another installation - ReleaseStr(targetDir); - } - - if (!WillElevate() && !QueryElevateForCrtInstall()) { - break; - } - - OnPlan(_command.action); - break; - - case ID_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX: - checked = ThemeIsControlChecked(_theme, ID_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX); - _engine->SetVariableNumeric(L"InstallLauncherAllUsers", checked); - - ThemeControlElevates(_theme, ID_INSTALL_BUTTON, WillElevate()); - break; - - case ID_CUSTOM_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX: - checked = ThemeIsControlChecked(_theme, ID_CUSTOM_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX); - _engine->SetVariableNumeric(L"InstallLauncherAllUsers", checked); - - ThemeControlElevates(_theme, ID_CUSTOM_INSTALL_BUTTON, WillElevate()); - break; - - case ID_CUSTOM_INSTALL_ALL_USERS_CHECKBOX: - checked = ThemeIsControlChecked(_theme, ID_CUSTOM_INSTALL_ALL_USERS_CHECKBOX); - _engine->SetVariableNumeric(L"InstallAllUsers", checked); - - ThemeControlElevates(_theme, ID_CUSTOM_INSTALL_BUTTON, WillElevate()); - ThemeControlEnable(_theme, ID_CUSTOM_BROWSE_BUTTON_LABEL, !checked); - if (checked) { - _engine->SetVariableNumeric(L"CompileAll", 1); - ThemeSendControlMessage(_theme, ID_CUSTOM_COMPILE_ALL_CHECKBOX, BM_SETCHECK, BST_CHECKED, 0); - } - ThemeGetTextControl(_theme, ID_TARGETDIR_EDITBOX, &targetDir); - if (targetDir) { - // Check the current value against the default to see - // if we should switch it automatically. - hr = BalGetStringVariable( - checked ? L"DefaultJustForMeTargetDir" : L"DefaultAllUsersTargetDir", - &defaultDir - ); - - if (SUCCEEDED(hr) && defaultDir) { - LPWSTR formatted = nullptr; - if (defaultDir[0] && SUCCEEDED(BalFormatString(defaultDir, &formatted))) { - if (wcscmp(formatted, targetDir) == 0) { - ReleaseStr(defaultDir); - defaultDir = nullptr; - ReleaseStr(formatted); - formatted = nullptr; - - hr = BalGetStringVariable( - checked ? L"DefaultAllUsersTargetDir" : L"DefaultJustForMeTargetDir", - &defaultDir - ); - if (SUCCEEDED(hr) && defaultDir && defaultDir[0] && SUCCEEDED(BalFormatString(defaultDir, &formatted))) { - ThemeSetTextControl(_theme, ID_TARGETDIR_EDITBOX, formatted); - ReleaseStr(formatted); - } - } else { - ReleaseStr(formatted); - } - } - - ReleaseStr(defaultDir); - } - } - break; - - case ID_CUSTOM_BROWSE_BUTTON: - browseInfo.hwndOwner = _hWnd; - browseInfo.pszDisplayName = wzPath; - browseInfo.lpszTitle = _theme->sczCaption; - browseInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI; - pidl = ::SHBrowseForFolderW(&browseInfo); - if (pidl && ::SHGetPathFromIDListW(pidl, wzPath)) { - ThemeSetTextControl(_theme, ID_TARGETDIR_EDITBOX, wzPath); - } - - if (pidl) { - ::CoTaskMemFree(pidl); - } - break; - - // Modify commands - case ID_MODIFY_BUTTON: - // Some variables cannot be modified - _engine->SetVariableString(L"InstallAllUsersState", L"disable"); - _engine->SetVariableString(L"InstallLauncherAllUsersState", L"disable"); - _engine->SetVariableString(L"TargetDirState", L"disable"); - _engine->SetVariableString(L"CustomBrowseButtonState", L"disable"); - _modifying = TRUE; - GoToPage(PAGE_CUSTOM1); - break; - - case ID_REPAIR_BUTTON: - OnPlan(BOOTSTRAPPER_ACTION_REPAIR); - break; - - case ID_UNINSTALL_BUTTON: - OnPlan(BOOTSTRAPPER_ACTION_UNINSTALL); - break; - - case ID_SUCCESS_MAX_PATH_BUTTON: - EnableMaxPathSupport(); - ThemeControlEnable(_theme, ID_SUCCESS_MAX_PATH_BUTTON, FALSE); - break; - } - - LExit: - return; - } - - void InstallPage_Show() { - // Ensure the All Users install button has a UAC shield - BOOL elevated = WillElevate(); - ThemeControlElevates(_theme, ID_INSTALL_BUTTON, elevated); - ThemeControlElevates(_theme, ID_INSTALL_SIMPLE_BUTTON, elevated); - ThemeControlElevates(_theme, ID_INSTALL_UPGRADE_BUTTON, elevated); - } - - void Custom1Page_Show() { - LONGLONG installLauncherAllUsers; - - if (FAILED(BalGetNumericVariable(L"InstallLauncherAllUsers", &installLauncherAllUsers))) { - installLauncherAllUsers = 0; - } - - ThemeSendControlMessage(_theme, ID_CUSTOM_INSTALL_LAUNCHER_ALL_USERS_CHECKBOX, BM_SETCHECK, - installLauncherAllUsers ? BST_CHECKED : BST_UNCHECKED, 0); - - LOC_STRING *pLocString = nullptr; - LPCWSTR locKey = L"#(loc.Include_launcherHelp)"; - LONGLONG detectedLauncher; - - if (SUCCEEDED(BalGetNumericVariable(L"DetectedLauncher", &detectedLauncher)) && detectedLauncher) { - locKey = L"#(loc.Include_launcherRemove)"; - } else if (SUCCEEDED(BalGetNumericVariable(L"DetectedOldLauncher", &detectedLauncher)) && detectedLauncher) { - locKey = L"#(loc.Include_launcherUpgrade)"; - } - - if (SUCCEEDED(LocGetString(_wixLoc, locKey, &pLocString)) && pLocString) { - ThemeSetTextControl(_theme, ID_CUSTOM_INCLUDE_LAUNCHER_HELP_LABEL, pLocString->wzText); - } - } - - void Custom2Page_Show() { - HRESULT hr; - LONGLONG installAll, includeLauncher; - - if (FAILED(BalGetNumericVariable(L"InstallAllUsers", &installAll))) { - installAll = 0; - } - - if (WillElevate()) { - ThemeControlElevates(_theme, ID_CUSTOM_INSTALL_BUTTON, TRUE); - ThemeShowControl(_theme, ID_CUSTOM_BROWSE_BUTTON_LABEL, SW_HIDE); - } else { - ThemeControlElevates(_theme, ID_CUSTOM_INSTALL_BUTTON, FALSE); - ThemeShowControl(_theme, ID_CUSTOM_BROWSE_BUTTON_LABEL, SW_SHOW); - } - - if (SUCCEEDED(BalGetNumericVariable(L"Include_launcher", &includeLauncher)) && includeLauncher) { - ThemeControlEnable(_theme, ID_CUSTOM_ASSOCIATE_FILES_CHECKBOX, TRUE); - } else { - ThemeSendControlMessage(_theme, ID_CUSTOM_ASSOCIATE_FILES_CHECKBOX, BM_SETCHECK, BST_UNCHECKED, 0); - ThemeControlEnable(_theme, ID_CUSTOM_ASSOCIATE_FILES_CHECKBOX, FALSE); - } - - LPWSTR targetDir = nullptr; - hr = BalGetStringVariable(L"TargetDir", &targetDir); - if (SUCCEEDED(hr) && targetDir && targetDir[0]) { - ThemeSetTextControl(_theme, ID_TARGETDIR_EDITBOX, targetDir); - StrFree(targetDir); - } else if (SUCCEEDED(hr)) { - StrFree(targetDir); - targetDir = nullptr; - - LPWSTR defaultTargetDir = nullptr; - hr = BalGetStringVariable(L"DefaultCustomTargetDir", &defaultTargetDir); - if (SUCCEEDED(hr) && defaultTargetDir && !defaultTargetDir[0]) { - StrFree(defaultTargetDir); - defaultTargetDir = nullptr; - - hr = BalGetStringVariable( - installAll ? L"DefaultAllUsersTargetDir" : L"DefaultJustForMeTargetDir", - &defaultTargetDir - ); - } - if (SUCCEEDED(hr) && defaultTargetDir) { - if (defaultTargetDir[0] && SUCCEEDED(BalFormatString(defaultTargetDir, &targetDir))) { - ThemeSetTextControl(_theme, ID_TARGETDIR_EDITBOX, targetDir); - StrFree(targetDir); - } - StrFree(defaultTargetDir); - } - } - } - - void ModifyPage_Show() { - ThemeControlEnable(_theme, ID_REPAIR_BUTTON, !_suppressRepair); - } - - void SuccessPage_Show() { - // on the "Success" page, check if the restart button should be enabled. - BOOL showRestartButton = FALSE; - LOC_STRING *successText = nullptr; - HRESULT hr = S_OK; - - if (_restartRequired) { - if (BOOTSTRAPPER_RESTART_PROMPT == _command.restart) { - showRestartButton = TRUE; - } - } - - switch (_plannedAction) { - case BOOTSTRAPPER_ACTION_INSTALL: - hr = LocGetString(_wixLoc, L"#(loc.SuccessInstallMessage)", &successText); - break; - case BOOTSTRAPPER_ACTION_MODIFY: - hr = LocGetString(_wixLoc, L"#(loc.SuccessModifyMessage)", &successText); - break; - case BOOTSTRAPPER_ACTION_REPAIR: - hr = LocGetString(_wixLoc, L"#(loc.SuccessRepairMessage)", &successText); - break; - case BOOTSTRAPPER_ACTION_UNINSTALL: - hr = LocGetString(_wixLoc, L"#(loc.SuccessRemoveMessage)", &successText); - break; - } - - if (successText) { - LPWSTR formattedString = nullptr; - BalFormatString(successText->wzText, &formattedString); - if (formattedString) { - ThemeSetTextControl(_theme, ID_SUCCESS_TEXT, formattedString); - StrFree(formattedString); - } - } - - ThemeControlEnable(_theme, ID_SUCCESS_RESTART_TEXT, showRestartButton); - ThemeControlEnable(_theme, ID_SUCCESS_RESTART_BUTTON, showRestartButton); - - if (_command.action != BOOTSTRAPPER_ACTION_INSTALL || - !IsWindowsVersionOrGreater(10, 0, 0)) { - ThemeControlEnable(_theme, ID_SUCCESS_MAX_PATH_BUTTON, FALSE); - } else { - DWORD dataType = 0, buffer = 0, bufferLen = sizeof(buffer); - HKEY hKey; - LRESULT res = RegOpenKeyExW( - HKEY_LOCAL_MACHINE, - L"SYSTEM\\CurrentControlSet\\Control\\FileSystem", - 0, - KEY_READ, - &hKey - ); - if (res == ERROR_SUCCESS) { - res = RegQueryValueExW(hKey, L"LongPathsEnabled", nullptr, &dataType, - (LPBYTE)&buffer, &bufferLen); - RegCloseKey(hKey); - } - else { - BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Failed to open SYSTEM\\CurrentControlSet\\Control\\FileSystem: error code %d", res); - } - if (res == ERROR_SUCCESS && dataType == REG_DWORD && buffer == 0) { - ThemeControlElevates(_theme, ID_SUCCESS_MAX_PATH_BUTTON, TRUE); - } - else { - if (res == ERROR_SUCCESS) - BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Failed to read LongPathsEnabled value: error code %d", res); - else - BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Hiding MAX_PATH button because it is already enabled"); - ThemeControlEnable(_theme, ID_SUCCESS_MAX_PATH_BUTTON, FALSE); - } - } - } - - void FailurePage_Show() { - // on the "Failure" page, show error message and check if the restart button should be enabled. - - // if there is a log file variable then we'll assume the log file exists. - BOOL showLogLink = (_bundle.sczLogVariable && *_bundle.sczLogVariable); - BOOL showErrorMessage = FALSE; - BOOL showRestartButton = FALSE; - - if (FAILED(_hrFinal)) { - LPWSTR unformattedText = nullptr; - LPWSTR text = nullptr; - - // If we know the failure message, use that. - if (_failedMessage && *_failedMessage) { - StrAllocString(&unformattedText, _failedMessage, 0); - } else { - // try to get the error message from the error code. - StrAllocFromError(&unformattedText, _hrFinal, nullptr); - if (!unformattedText || !*unformattedText) { - StrAllocFromError(&unformattedText, E_FAIL, nullptr); - } - } - - if (E_WIXSTDBA_CONDITION_FAILED == _hrFinal) { - if (unformattedText) { - StrAllocString(&text, unformattedText, 0); - } - } else { - StrAllocFormatted(&text, L"0x%08x - %ls", _hrFinal, unformattedText); - } - - if (text) { - ThemeSetTextControl(_theme, ID_FAILURE_MESSAGE_TEXT, text); - showErrorMessage = TRUE; - } - - ReleaseStr(text); - ReleaseStr(unformattedText); - } - - if (_restartRequired && BOOTSTRAPPER_RESTART_PROMPT == _command.restart) { - showRestartButton = TRUE; - } - - ThemeControlEnable(_theme, ID_FAILURE_LOGFILE_LINK, showLogLink); - ThemeControlEnable(_theme, ID_FAILURE_MESSAGE_TEXT, showErrorMessage); - ThemeControlEnable(_theme, ID_FAILURE_RESTART_TEXT, showRestartButton); - ThemeControlEnable(_theme, ID_FAILURE_RESTART_BUTTON, showRestartButton); - } - - static void EnableMaxPathSupport() { - LPWSTR targetDir = nullptr, defaultDir = nullptr; - HRESULT hr = BalGetStringVariable(L"TargetDir", &targetDir); - if (FAILED(hr) || !targetDir || !targetDir[0]) { - BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Failed to get TargetDir"); - return; - } - - LPWSTR pythonw = nullptr; - StrAllocFormatted(&pythonw, L"%ls\\pythonw.exe", targetDir); - if (!pythonw || !pythonw[0]) { - BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Failed to construct pythonw.exe path"); - return; - } - - LPCWSTR arguments = L"-c \"import winreg; " - "winreg.SetValueEx(" - "winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, " - "r'SYSTEM\\CurrentControlSet\\Control\\FileSystem'), " - "'LongPathsEnabled', " - "None, " - "winreg.REG_DWORD, " - "1" - ")\""; - BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Executing %ls %ls", pythonw, arguments); - HINSTANCE res = ShellExecuteW(0, L"runas", pythonw, arguments, NULL, SW_HIDE); - BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "return code 0x%08x", res); - } - -public: // IBootstrapperApplication - virtual STDMETHODIMP OnStartup() { - HRESULT hr = S_OK; - DWORD dwUIThreadId = 0; - - // create UI thread - _hUiThread = ::CreateThread(nullptr, 0, UiThreadProc, this, 0, &dwUIThreadId); - if (!_hUiThread) { - ExitWithLastError(hr, "Failed to create UI thread."); - } - - LExit: - return hr; - } - - - virtual STDMETHODIMP_(int) OnShutdown() { - int nResult = IDNOACTION; - - // wait for UI thread to terminate - if (_hUiThread) { - ::WaitForSingleObject(_hUiThread, INFINITE); - ReleaseHandle(_hUiThread); - } - - // If a restart was required. - if (_restartRequired && _allowRestart) { - nResult = IDRESTART; - } - - return nResult; - } - - virtual STDMETHODIMP_(int) OnDetectRelatedMsiPackage( - __in_z LPCWSTR wzPackageId, - __in_z LPCWSTR /*wzProductCode*/, - __in BOOL fPerMachine, - __in DWORD64 /*dw64Version*/, - __in BOOTSTRAPPER_RELATED_OPERATION operation - ) { - if (BOOTSTRAPPER_RELATED_OPERATION_MAJOR_UPGRADE == operation && - (CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, wzPackageId, -1, L"launcher_AllUsers", -1) || - CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, wzPackageId, -1, L"launcher_JustForMe", -1))) { - auto hr = LoadAssociateFilesStateFromKey(_engine, fPerMachine ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER); - if (hr == S_OK) { - _engine->SetVariableNumeric(L"AssociateFiles", 1); - } else if (FAILED(hr)) { - BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Failed to load AssociateFiles state: error code 0x%08X", hr); - } - - _engine->SetVariableNumeric(L"Include_launcher", 1); - _engine->SetVariableNumeric(L"DetectedOldLauncher", 1); - _engine->SetVariableNumeric(L"InstallLauncherAllUsers", fPerMachine ? 1 : 0); - } - return CheckCanceled() ? IDCANCEL : IDNOACTION; - } - - virtual STDMETHODIMP_(int) OnDetectRelatedBundle( - __in LPCWSTR wzBundleId, - __in BOOTSTRAPPER_RELATION_TYPE relationType, - __in LPCWSTR /*wzBundleTag*/, - __in BOOL fPerMachine, - __in DWORD64 /*dw64Version*/, - __in BOOTSTRAPPER_RELATED_OPERATION operation - ) { - BalInfoAddRelatedBundleAsPackage(&_bundle.packages, wzBundleId, relationType, fPerMachine); - - // Remember when our bundle would cause a downgrade. - if (BOOTSTRAPPER_RELATED_OPERATION_DOWNGRADE == operation) { - _downgradingOtherVersion = TRUE; - } else if (BOOTSTRAPPER_RELATED_OPERATION_MAJOR_UPGRADE == operation) { - BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Detected previous version - planning upgrade"); - _upgrading = TRUE; - - LoadOptionalFeatureStates(_engine); - } else if (BOOTSTRAPPER_RELATED_OPERATION_NONE == operation) { - if (_command.action == BOOTSTRAPPER_ACTION_INSTALL) { - LOC_STRING *pLocString = nullptr; - if (SUCCEEDED(LocGetString(_wixLoc, L"#(loc.FailureExistingInstall)", &pLocString)) && pLocString) { - BalFormatString(pLocString->wzText, &_failedMessage); - } else { - BalFormatString(L"Cannot install [WixBundleName] because it is already installed.", &_failedMessage); - } - BalLog( - BOOTSTRAPPER_LOG_LEVEL_ERROR, - "Related bundle %ls is preventing install", - wzBundleId - ); - SetState(PYBA_STATE_FAILED, E_WIXSTDBA_CONDITION_FAILED); - } - } - - return CheckCanceled() ? IDCANCEL : IDOK; - } - - - virtual STDMETHODIMP_(void) OnDetectPackageComplete( - __in LPCWSTR wzPackageId, - __in HRESULT hrStatus, - __in BOOTSTRAPPER_PACKAGE_STATE state - ) { - if (FAILED(hrStatus)) { - return; - } - - BOOL detectedLauncher = FALSE; - HKEY hkey = HKEY_LOCAL_MACHINE; - if (CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, wzPackageId, -1, L"launcher_AllUsers", -1)) { - if (BOOTSTRAPPER_PACKAGE_STATE_PRESENT == state || BOOTSTRAPPER_PACKAGE_STATE_OBSOLETE == state) { - detectedLauncher = TRUE; - _engine->SetVariableNumeric(L"InstallLauncherAllUsers", 1); - } - } else if (CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, wzPackageId, -1, L"launcher_JustForMe", -1)) { - if (BOOTSTRAPPER_PACKAGE_STATE_PRESENT == state || BOOTSTRAPPER_PACKAGE_STATE_OBSOLETE == state) { - detectedLauncher = TRUE; - _engine->SetVariableNumeric(L"InstallLauncherAllUsers", 0); - } - } - - if (detectedLauncher) { - /* When we detect the current version of the launcher. */ - _engine->SetVariableNumeric(L"Include_launcher", 1); - _engine->SetVariableNumeric(L"DetectedLauncher", 1); - _engine->SetVariableString(L"Include_launcherState", L"disable"); - _engine->SetVariableString(L"InstallLauncherAllUsersState", L"disable"); - - auto hr = LoadAssociateFilesStateFromKey(_engine, hkey); - if (hr == S_OK) { - _engine->SetVariableNumeric(L"AssociateFiles", 1); - } else if (FAILED(hr)) { - BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Failed to load AssociateFiles state: error code 0x%08X", hr); - } - } - } - - - virtual STDMETHODIMP_(void) OnDetectComplete(__in HRESULT hrStatus) { - if (SUCCEEDED(hrStatus) && _baFunction) { - BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Running detect complete BA function"); - _baFunction->OnDetectComplete(); - } - - if (SUCCEEDED(hrStatus)) { - hrStatus = EvaluateConditions(); - } - - if (SUCCEEDED(hrStatus)) { - // Ensure the default path has been set - hrStatus = EnsureTargetDir(); - } - - SetState(PYBA_STATE_DETECTED, hrStatus); - - // If we're not interacting with the user or we're doing a layout or we're just after a force restart - // then automatically start planning. - if (BOOTSTRAPPER_DISPLAY_FULL > _command.display || - BOOTSTRAPPER_ACTION_LAYOUT == _command.action || - BOOTSTRAPPER_ACTION_UNINSTALL == _command.action || - BOOTSTRAPPER_RESUME_TYPE_REBOOT == _command.resumeType) { - if (SUCCEEDED(hrStatus)) { - ::PostMessageW(_hWnd, WM_PYBA_PLAN_PACKAGES, 0, _command.action); - } - } - } - - - virtual STDMETHODIMP_(int) OnPlanRelatedBundle( - __in_z LPCWSTR /*wzBundleId*/, - __inout_z BOOTSTRAPPER_REQUEST_STATE* pRequestedState - ) { - return CheckCanceled() ? IDCANCEL : IDOK; - } - - - virtual STDMETHODIMP_(int) OnPlanPackageBegin( - __in_z LPCWSTR wzPackageId, - __inout BOOTSTRAPPER_REQUEST_STATE *pRequestState - ) { - HRESULT hr = S_OK; - BAL_INFO_PACKAGE* pPackage = nullptr; - - if (_nextPackageAfterRestart) { - // After restart we need to finish the dependency registration for our package so allow the package - // to go present. - if (CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, wzPackageId, -1, _nextPackageAfterRestart, -1)) { - // Do not allow a repair because that could put us in a perpetual restart loop. - if (BOOTSTRAPPER_REQUEST_STATE_REPAIR == *pRequestState) { - *pRequestState = BOOTSTRAPPER_REQUEST_STATE_PRESENT; - } - - ReleaseNullStr(_nextPackageAfterRestart); // no more skipping now. - } else { - // not the matching package, so skip it. - BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Skipping package: %ls, after restart because it was applied before the restart.", wzPackageId); - - *pRequestState = BOOTSTRAPPER_REQUEST_STATE_NONE; - } - } else if ((_plannedAction == BOOTSTRAPPER_ACTION_INSTALL || _plannedAction == BOOTSTRAPPER_ACTION_MODIFY) && - SUCCEEDED(BalInfoFindPackageById(&_bundle.packages, wzPackageId, &pPackage))) { - BOOL f = FALSE; - if (SUCCEEDED(_engine->EvaluateCondition(pPackage->sczInstallCondition, &f)) && f) { - *pRequestState = BOOTSTRAPPER_REQUEST_STATE_PRESENT; - } - } - - return CheckCanceled() ? IDCANCEL : IDOK; - } - - virtual STDMETHODIMP_(int) OnPlanMsiFeature( - __in_z LPCWSTR wzPackageId, - __in_z LPCWSTR wzFeatureId, - __inout BOOTSTRAPPER_FEATURE_STATE* pRequestedState - ) { - LONGLONG install; - - if (wcscmp(wzFeatureId, L"AssociateFiles") == 0 || wcscmp(wzFeatureId, L"Shortcuts") == 0) { - if (SUCCEEDED(_engine->GetVariableNumeric(wzFeatureId, &install)) && install) { - *pRequestedState = BOOTSTRAPPER_FEATURE_STATE_LOCAL; - } else { - *pRequestedState = BOOTSTRAPPER_FEATURE_STATE_ABSENT; - } - } else { - *pRequestedState = BOOTSTRAPPER_FEATURE_STATE_LOCAL; - } - return CheckCanceled() ? IDCANCEL : IDNOACTION; - } - - virtual STDMETHODIMP_(void) OnPlanComplete(__in HRESULT hrStatus) { - if (SUCCEEDED(hrStatus) && _baFunction) { - BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Running plan complete BA function"); - _baFunction->OnPlanComplete(); - } - - SetState(PYBA_STATE_PLANNED, hrStatus); - - if (SUCCEEDED(hrStatus)) { - ::PostMessageW(_hWnd, WM_PYBA_APPLY_PACKAGES, 0, 0); - } - - _startedExecution = FALSE; - _calculatedCacheProgress = 0; - _calculatedExecuteProgress = 0; - } - - - virtual STDMETHODIMP_(int) OnCachePackageBegin( - __in_z LPCWSTR wzPackageId, - __in DWORD cCachePayloads, - __in DWORD64 dw64PackageCacheSize - ) { - if (wzPackageId && *wzPackageId) { - BAL_INFO_PACKAGE* pPackage = nullptr; - HRESULT hr = BalInfoFindPackageById(&_bundle.packages, wzPackageId, &pPackage); - LPCWSTR wz = (SUCCEEDED(hr) && pPackage->sczDisplayName) ? pPackage->sczDisplayName : wzPackageId; - - ThemeSetTextControl(_theme, ID_CACHE_PROGRESS_PACKAGE_TEXT, wz); - - // If something started executing, leave it in the overall progress text. - if (!_startedExecution) { - ThemeSetTextControl(_theme, ID_OVERALL_PROGRESS_PACKAGE_TEXT, wz); - } - } - - return __super::OnCachePackageBegin(wzPackageId, cCachePayloads, dw64PackageCacheSize); - } - - - virtual STDMETHODIMP_(int) OnCacheAcquireProgress( - __in_z LPCWSTR wzPackageOrContainerId, - __in_z_opt LPCWSTR wzPayloadId, - __in DWORD64 dw64Progress, - __in DWORD64 dw64Total, - __in DWORD dwOverallPercentage - ) { - WCHAR wzProgress[5] = { }; - -#ifdef DEBUG - BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "PYBA: OnCacheAcquireProgress() - container/package: %ls, payload: %ls, progress: %I64u, total: %I64u, overall progress: %u%%", wzPackageOrContainerId, wzPayloadId, dw64Progress, dw64Total, dwOverallPercentage); -#endif - - ::StringCchPrintfW(wzProgress, countof(wzProgress), L"%u%%", dwOverallPercentage); - ThemeSetTextControl(_theme, ID_CACHE_PROGRESS_TEXT, wzProgress); - - ThemeSetProgressControl(_theme, ID_CACHE_PROGRESS_BAR, dwOverallPercentage); - - _calculatedCacheProgress = dwOverallPercentage * PYBA_ACQUIRE_PERCENTAGE / 100; - ThemeSetProgressControl(_theme, ID_OVERALL_CALCULATED_PROGRESS_BAR, _calculatedCacheProgress + _calculatedExecuteProgress); - - SetTaskbarButtonProgress(_calculatedCacheProgress + _calculatedExecuteProgress); - - return __super::OnCacheAcquireProgress(wzPackageOrContainerId, wzPayloadId, dw64Progress, dw64Total, dwOverallPercentage); - } - - - virtual STDMETHODIMP_(int) OnCacheAcquireComplete( - __in_z LPCWSTR wzPackageOrContainerId, - __in_z_opt LPCWSTR wzPayloadId, - __in HRESULT hrStatus, - __in int nRecommendation - ) { - SetProgressState(hrStatus); - return __super::OnCacheAcquireComplete(wzPackageOrContainerId, wzPayloadId, hrStatus, nRecommendation); - } - - - virtual STDMETHODIMP_(int) OnCacheVerifyComplete( - __in_z LPCWSTR wzPackageId, - __in_z LPCWSTR wzPayloadId, - __in HRESULT hrStatus, - __in int nRecommendation - ) { - SetProgressState(hrStatus); - return __super::OnCacheVerifyComplete(wzPackageId, wzPayloadId, hrStatus, nRecommendation); - } - - - virtual STDMETHODIMP_(void) OnCacheComplete(__in HRESULT /*hrStatus*/) { - ThemeSetTextControl(_theme, ID_CACHE_PROGRESS_PACKAGE_TEXT, L""); - SetState(PYBA_STATE_CACHED, S_OK); // we always return success here and let OnApplyComplete() deal with the error. - } - - - virtual STDMETHODIMP_(int) OnError( - __in BOOTSTRAPPER_ERROR_TYPE errorType, - __in LPCWSTR wzPackageId, - __in DWORD dwCode, - __in_z LPCWSTR wzError, - __in DWORD dwUIHint, - __in DWORD /*cData*/, - __in_ecount_z_opt(cData) LPCWSTR* /*rgwzData*/, - __in int nRecommendation - ) { - int nResult = nRecommendation; - LPWSTR sczError = nullptr; - - if (BOOTSTRAPPER_DISPLAY_EMBEDDED == _command.display) { - HRESULT hr = _engine->SendEmbeddedError(dwCode, wzError, dwUIHint, &nResult); - if (FAILED(hr)) { - nResult = IDERROR; - } - } else if (BOOTSTRAPPER_DISPLAY_FULL == _command.display) { - // If this is an authentication failure, let the engine try to handle it for us. - if (BOOTSTRAPPER_ERROR_TYPE_HTTP_AUTH_SERVER == errorType || BOOTSTRAPPER_ERROR_TYPE_HTTP_AUTH_PROXY == errorType) { - nResult = IDTRYAGAIN; - } else // show a generic error message box. - { - BalRetryErrorOccurred(wzPackageId, dwCode); - - if (!_showingInternalUIThisPackage) { - // If no error message was provided, use the error code to try and get an error message. - if (!wzError || !*wzError || BOOTSTRAPPER_ERROR_TYPE_WINDOWS_INSTALLER != errorType) { - HRESULT hr = StrAllocFromError(&sczError, dwCode, nullptr); - if (FAILED(hr) || !sczError || !*sczError) { - StrAllocFormatted(&sczError, L"0x%x", dwCode); - } - } - - nResult = ::MessageBoxW(_hWnd, sczError ? sczError : wzError, _theme->sczCaption, dwUIHint); - } - } - - SetProgressState(HRESULT_FROM_WIN32(dwCode)); - } else { - // just take note of the error code and let things continue. - BalRetryErrorOccurred(wzPackageId, dwCode); - } - - ReleaseStr(sczError); - return nResult; - } - - - virtual STDMETHODIMP_(int) OnExecuteMsiMessage( - __in_z LPCWSTR wzPackageId, - __in INSTALLMESSAGE mt, - __in UINT uiFlags, - __in_z LPCWSTR wzMessage, - __in DWORD cData, - __in_ecount_z_opt(cData) LPCWSTR* rgwzData, - __in int nRecommendation - ) { -#ifdef DEBUG - BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "PYBA: OnExecuteMsiMessage() - package: %ls, message: %ls", wzPackageId, wzMessage); -#endif - if (BOOTSTRAPPER_DISPLAY_FULL == _command.display && (INSTALLMESSAGE_WARNING == mt || INSTALLMESSAGE_USER == mt)) { - int nResult = ::MessageBoxW(_hWnd, wzMessage, _theme->sczCaption, uiFlags); - return nResult; - } - - if (INSTALLMESSAGE_ACTIONSTART == mt) { - ThemeSetTextControl(_theme, ID_EXECUTE_PROGRESS_ACTIONDATA_TEXT, wzMessage); - } - - return __super::OnExecuteMsiMessage(wzPackageId, mt, uiFlags, wzMessage, cData, rgwzData, nRecommendation); - } - - - virtual STDMETHODIMP_(int) OnProgress(__in DWORD dwProgressPercentage, __in DWORD dwOverallProgressPercentage) { - WCHAR wzProgress[5] = { }; - -#ifdef DEBUG - BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "PYBA: OnProgress() - progress: %u%%, overall progress: %u%%", dwProgressPercentage, dwOverallProgressPercentage); -#endif - - ::StringCchPrintfW(wzProgress, countof(wzProgress), L"%u%%", dwOverallProgressPercentage); - ThemeSetTextControl(_theme, ID_OVERALL_PROGRESS_TEXT, wzProgress); - - ThemeSetProgressControl(_theme, ID_OVERALL_PROGRESS_BAR, dwOverallProgressPercentage); - SetTaskbarButtonProgress(dwOverallProgressPercentage); - - return __super::OnProgress(dwProgressPercentage, dwOverallProgressPercentage); - } - - - virtual STDMETHODIMP_(int) OnExecutePackageBegin(__in_z LPCWSTR wzPackageId, __in BOOL fExecute) { - LPWSTR sczFormattedString = nullptr; - - _startedExecution = TRUE; - - if (wzPackageId && *wzPackageId) { - BAL_INFO_PACKAGE* pPackage = nullptr; - BalInfoFindPackageById(&_bundle.packages, wzPackageId, &pPackage); - - LPCWSTR wz = wzPackageId; - if (pPackage) { - LOC_STRING* pLocString = nullptr; - - switch (pPackage->type) { - case BAL_INFO_PACKAGE_TYPE_BUNDLE_ADDON: - LocGetString(_wixLoc, L"#(loc.ExecuteAddonRelatedBundleMessage)", &pLocString); - break; - - case BAL_INFO_PACKAGE_TYPE_BUNDLE_PATCH: - LocGetString(_wixLoc, L"#(loc.ExecutePatchRelatedBundleMessage)", &pLocString); - break; - - case BAL_INFO_PACKAGE_TYPE_BUNDLE_UPGRADE: - LocGetString(_wixLoc, L"#(loc.ExecuteUpgradeRelatedBundleMessage)", &pLocString); - break; - } - - if (pLocString) { - // If the wix developer is showing a hidden variable in the UI, then obviously they don't care about keeping it safe - // so don't go down the rabbit hole of making sure that this is securely freed. - BalFormatString(pLocString->wzText, &sczFormattedString); - } - - wz = sczFormattedString ? sczFormattedString : pPackage->sczDisplayName ? pPackage->sczDisplayName : wzPackageId; - } - - _showingInternalUIThisPackage = pPackage && pPackage->fDisplayInternalUI; - - ThemeSetTextControl(_theme, ID_EXECUTE_PROGRESS_PACKAGE_TEXT, wz); - ThemeSetTextControl(_theme, ID_OVERALL_PROGRESS_PACKAGE_TEXT, wz); - } else { - _showingInternalUIThisPackage = FALSE; - } - - ReleaseStr(sczFormattedString); - return __super::OnExecutePackageBegin(wzPackageId, fExecute); - } - - - virtual int __stdcall OnExecuteProgress( - __in_z LPCWSTR wzPackageId, - __in DWORD dwProgressPercentage, - __in DWORD dwOverallProgressPercentage - ) { - WCHAR wzProgress[8] = { }; - -#ifdef DEBUG - BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "PYBA: OnExecuteProgress() - package: %ls, progress: %u%%, overall progress: %u%%", wzPackageId, dwProgressPercentage, dwOverallProgressPercentage); -#endif - - ::StringCchPrintfW(wzProgress, countof(wzProgress), L"%u%%", dwOverallProgressPercentage); - ThemeSetTextControl(_theme, ID_EXECUTE_PROGRESS_TEXT, wzProgress); - - ThemeSetProgressControl(_theme, ID_EXECUTE_PROGRESS_BAR, dwOverallProgressPercentage); - - _calculatedExecuteProgress = dwOverallProgressPercentage * (100 - PYBA_ACQUIRE_PERCENTAGE) / 100; - ThemeSetProgressControl(_theme, ID_OVERALL_CALCULATED_PROGRESS_BAR, _calculatedCacheProgress + _calculatedExecuteProgress); - - SetTaskbarButtonProgress(_calculatedCacheProgress + _calculatedExecuteProgress); - - return __super::OnExecuteProgress(wzPackageId, dwProgressPercentage, dwOverallProgressPercentage); - } - - - virtual STDMETHODIMP_(int) OnExecutePackageComplete( - __in_z LPCWSTR wzPackageId, - __in HRESULT hrExitCode, - __in BOOTSTRAPPER_APPLY_RESTART restart, - __in int nRecommendation - ) { - SetProgressState(hrExitCode); - - if (_wcsnicmp(wzPackageId, L"path_", 5) == 0 && SUCCEEDED(hrExitCode)) { - SendMessageTimeoutW( - HWND_BROADCAST, - WM_SETTINGCHANGE, - 0, - reinterpret_cast(L"Environment"), - SMTO_ABORTIFHUNG, - 1000, - nullptr - ); - } - - int nResult = __super::OnExecutePackageComplete(wzPackageId, hrExitCode, restart, nRecommendation); - - return nResult; - } - - - virtual STDMETHODIMP_(void) OnExecuteComplete(__in HRESULT hrStatus) { - ThemeSetTextControl(_theme, ID_EXECUTE_PROGRESS_PACKAGE_TEXT, L""); - ThemeSetTextControl(_theme, ID_EXECUTE_PROGRESS_ACTIONDATA_TEXT, L""); - ThemeSetTextControl(_theme, ID_OVERALL_PROGRESS_PACKAGE_TEXT, L""); - ThemeControlEnable(_theme, ID_PROGRESS_CANCEL_BUTTON, FALSE); // no more cancel. - - SetState(PYBA_STATE_EXECUTED, S_OK); // we always return success here and let OnApplyComplete() deal with the error. - SetProgressState(hrStatus); - } - - - virtual STDMETHODIMP_(int) OnResolveSource( - __in_z LPCWSTR wzPackageOrContainerId, - __in_z_opt LPCWSTR wzPayloadId, - __in_z LPCWSTR wzLocalSource, - __in_z_opt LPCWSTR wzDownloadSource - ) { - int nResult = IDERROR; // assume we won't resolve source and that is unexpected. - - if (BOOTSTRAPPER_DISPLAY_FULL == _command.display) { - if (wzDownloadSource) { - nResult = IDDOWNLOAD; - } else { - // prompt to change the source location. - OPENFILENAMEW ofn = { }; - WCHAR wzFile[MAX_PATH] = { }; - - ::StringCchCopyW(wzFile, countof(wzFile), wzLocalSource); - - ofn.lStructSize = sizeof(ofn); - ofn.hwndOwner = _hWnd; - ofn.lpstrFile = wzFile; - ofn.nMaxFile = countof(wzFile); - ofn.lpstrFilter = L"All Files\0*.*\0"; - ofn.nFilterIndex = 1; - ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; - ofn.lpstrTitle = _theme->sczCaption; - - if (::GetOpenFileNameW(&ofn)) { - HRESULT hr = _engine->SetLocalSource(wzPackageOrContainerId, wzPayloadId, ofn.lpstrFile); - nResult = SUCCEEDED(hr) ? IDRETRY : IDERROR; - } else { - nResult = IDCANCEL; - } - } - } else if (wzDownloadSource) { - // If doing a non-interactive install and download source is available, let's try downloading the package silently - nResult = IDDOWNLOAD; - } - // else there's nothing more we can do in non-interactive mode - - return CheckCanceled() ? IDCANCEL : nResult; - } - - - virtual STDMETHODIMP_(int) OnApplyComplete(__in HRESULT hrStatus, __in BOOTSTRAPPER_APPLY_RESTART restart) { - _restartResult = restart; // remember the restart result so we return the correct error code no matter what the user chooses to do in the UI. - - // If a restart was encountered and we are not suppressing restarts, then restart is required. - _restartRequired = (BOOTSTRAPPER_APPLY_RESTART_NONE != restart && BOOTSTRAPPER_RESTART_NEVER < _command.restart); - // If a restart is required and we're not displaying a UI or we are not supposed to prompt for restart then allow the restart. - _allowRestart = _restartRequired && (BOOTSTRAPPER_DISPLAY_FULL > _command.display || BOOTSTRAPPER_RESTART_PROMPT < _command.restart); - - // If we are showing UI, wait a beat before moving to the final screen. - if (BOOTSTRAPPER_DISPLAY_NONE < _command.display) { - ::Sleep(250); - } - - SetState(PYBA_STATE_APPLIED, hrStatus); - SetTaskbarButtonProgress(100); // show full progress bar, green, yellow, or red - - return IDNOACTION; - } - - virtual STDMETHODIMP_(void) OnLaunchApprovedExeComplete(__in HRESULT hrStatus, __in DWORD /*processId*/) { - } - - -private: - // - // UiThreadProc - entrypoint for UI thread. - // - static DWORD WINAPI UiThreadProc(__in LPVOID pvContext) { - HRESULT hr = S_OK; - PythonBootstrapperApplication* pThis = (PythonBootstrapperApplication*)pvContext; - BOOL comInitialized = FALSE; - BOOL ret = FALSE; - MSG msg = { }; - - // Initialize COM and theme. - hr = ::CoInitialize(nullptr); - BalExitOnFailure(hr, "Failed to initialize COM."); - comInitialized = TRUE; - - hr = ThemeInitialize(pThis->_hModule); - BalExitOnFailure(hr, "Failed to initialize theme manager."); - - hr = pThis->InitializeData(); - BalExitOnFailure(hr, "Failed to initialize data in bootstrapper application."); - - // Create main window. - pThis->InitializeTaskbarButton(); - hr = pThis->CreateMainWindow(); - BalExitOnFailure(hr, "Failed to create main window."); - - pThis->ValidateOperatingSystem(); - - if (FAILED(pThis->_hrFinal)) { - pThis->SetState(PYBA_STATE_FAILED, hr); - ::PostMessageW(pThis->_hWnd, WM_PYBA_SHOW_FAILURE, 0, 0); - } else { - // Okay, we're ready for packages now. - pThis->SetState(PYBA_STATE_INITIALIZED, hr); - ::PostMessageW(pThis->_hWnd, BOOTSTRAPPER_ACTION_HELP == pThis->_command.action ? WM_PYBA_SHOW_HELP : WM_PYBA_DETECT_PACKAGES, 0, 0); - } - - // message pump - while (0 != (ret = ::GetMessageW(&msg, nullptr, 0, 0))) { - if (-1 == ret) { - hr = E_UNEXPECTED; - BalExitOnFailure(hr, "Unexpected return value from message pump."); - } else if (!ThemeHandleKeyboardMessage(pThis->_theme, msg.hwnd, &msg)) { - ::TranslateMessage(&msg); - ::DispatchMessageW(&msg); - } - } - - // Succeeded thus far, check to see if anything went wrong while actually - // executing changes. - if (FAILED(pThis->_hrFinal)) { - hr = pThis->_hrFinal; - } else if (pThis->CheckCanceled()) { - hr = HRESULT_FROM_WIN32(ERROR_INSTALL_USEREXIT); - } - - LExit: - // destroy main window - pThis->DestroyMainWindow(); - - // initiate engine shutdown - DWORD dwQuit = HRESULT_CODE(hr); - if (BOOTSTRAPPER_APPLY_RESTART_INITIATED == pThis->_restartResult) { - dwQuit = ERROR_SUCCESS_REBOOT_INITIATED; - } else if (BOOTSTRAPPER_APPLY_RESTART_REQUIRED == pThis->_restartResult) { - dwQuit = ERROR_SUCCESS_REBOOT_REQUIRED; - } - pThis->_engine->Quit(dwQuit); - - ReleaseTheme(pThis->_theme); - ThemeUninitialize(); - - // uninitialize COM - if (comInitialized) { - ::CoUninitialize(); - } - - return hr; - } - - // - // ParseVariablesFromUnattendXml - reads options from unattend.xml if it - // exists - // - HRESULT ParseVariablesFromUnattendXml() { - HRESULT hr = S_OK; - LPWSTR sczUnattendXmlPath = nullptr; - IXMLDOMDocument *pixdUnattend = nullptr; - IXMLDOMNodeList *pNodes = nullptr; - IXMLDOMNode *pNode = nullptr; - long cNodes; - DWORD dwAttr; - LPWSTR scz = nullptr; - BOOL bValue; - int iValue; - BOOL tryConvert; - BSTR bstrValue = nullptr; - - hr = BalFormatString(L"[WixBundleOriginalSourceFolder]unattend.xml", &sczUnattendXmlPath); - BalExitOnFailure(hr, "Failed to calculate path to unattend.xml"); - - if (!FileExistsEx(sczUnattendXmlPath, &dwAttr)) { - BalLog(BOOTSTRAPPER_LOG_LEVEL_VERBOSE, "Did not find %ls", sczUnattendXmlPath); - hr = S_FALSE; - goto LExit; - } - - hr = XmlLoadDocumentFromFile(sczUnattendXmlPath, &pixdUnattend); - BalExitOnFailure1(hr, "Failed to read %ls", sczUnattendXmlPath); - - // get the list of variables users have overridden - hr = XmlSelectNodes(pixdUnattend, L"/Options/Option", &pNodes); - if (S_FALSE == hr) { - ExitFunction1(hr = S_OK); - } - BalExitOnFailure(hr, "Failed to select option nodes."); - - hr = pNodes->get_length((long*)&cNodes); - BalExitOnFailure(hr, "Failed to get option node count."); - - BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Reading settings from %ls", sczUnattendXmlPath); - - for (DWORD i = 0; i < cNodes; ++i) { - hr = XmlNextElement(pNodes, &pNode, nullptr); - BalExitOnFailure(hr, "Failed to get next node."); - - // @Name - hr = XmlGetAttributeEx(pNode, L"Name", &scz); - BalExitOnFailure(hr, "Failed to get @Name."); - - tryConvert = TRUE; - hr = XmlGetAttribute(pNode, L"Value", &bstrValue); - if (FAILED(hr) || !bstrValue || !*bstrValue) { - hr = XmlGetText(pNode, &bstrValue); - tryConvert = FALSE; - } - BalExitOnFailure(hr, "Failed to get @Value."); - - if (tryConvert && - CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, bstrValue, -1, L"yes", -1)) { - _engine->SetVariableNumeric(scz, 1); - } else if (tryConvert && - CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, bstrValue, -1, L"no", -1)) { - _engine->SetVariableNumeric(scz, 0); - } else if (tryConvert && ::StrToIntExW(bstrValue, STIF_DEFAULT, &iValue)) { - _engine->SetVariableNumeric(scz, iValue); - } else { - _engine->SetVariableString(scz, bstrValue); - } - - ReleaseNullBSTR(bstrValue); - ReleaseNullStr(scz); - ReleaseNullObject(pNode); - } - - BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Finished reading from %ls", sczUnattendXmlPath); - - LExit: - ReleaseObject(pNode); - ReleaseObject(pNodes); - ReleaseObject(pixdUnattend); - ReleaseStr(sczUnattendXmlPath); - - return hr; - } - - - // - // InitializeData - initializes all the package information. - // - HRESULT InitializeData() { - HRESULT hr = S_OK; - LPWSTR sczModulePath = nullptr; - IXMLDOMDocument *pixdManifest = nullptr; - - hr = BalManifestLoad(_hModule, &pixdManifest); - BalExitOnFailure(hr, "Failed to load bootstrapper application manifest."); - - hr = ParseOverridableVariablesFromXml(pixdManifest); - BalExitOnFailure(hr, "Failed to read overridable variables."); - - hr = ParseVariablesFromUnattendXml(); - ExitOnFailure(hr, "Failed to read unattend.ini file."); - - hr = ProcessCommandLine(&_language); - ExitOnFailure(hr, "Unknown commandline parameters."); - - hr = PathRelativeToModule(&sczModulePath, nullptr, _hModule); - BalExitOnFailure(hr, "Failed to get module path."); - - hr = LoadLocalization(sczModulePath, _language); - ExitOnFailure(hr, "Failed to load localization."); - - hr = LoadTheme(sczModulePath, _language); - ExitOnFailure(hr, "Failed to load theme."); - - hr = BalInfoParseFromXml(&_bundle, pixdManifest); - BalExitOnFailure(hr, "Failed to load bundle information."); - - hr = BalConditionsParseFromXml(&_conditions, pixdManifest, _wixLoc); - BalExitOnFailure(hr, "Failed to load conditions from XML."); - - hr = LoadBootstrapperBAFunctions(); - BalExitOnFailure(hr, "Failed to load bootstrapper functions."); - - hr = UpdateUIStrings(_command.action); - BalExitOnFailure(hr, "Failed to load UI strings."); - - if (_command.action == BOOTSTRAPPER_ACTION_MODIFY) { - LoadOptionalFeatureStates(_engine); - } - - GetBundleFileVersion(); - // don't fail if we couldn't get the version info; best-effort only - LExit: - ReleaseObject(pixdManifest); - ReleaseStr(sczModulePath); - - return hr; - } - - - // - // ProcessCommandLine - process the provided command line arguments. - // - HRESULT ProcessCommandLine(__inout LPWSTR* psczLanguage) { - HRESULT hr = S_OK; - int argc = 0; - LPWSTR* argv = nullptr; - LPWSTR sczVariableName = nullptr; - LPWSTR sczVariableValue = nullptr; - - if (_command.wzCommandLine && *_command.wzCommandLine) { - argv = ::CommandLineToArgvW(_command.wzCommandLine, &argc); - ExitOnNullWithLastError(argv, hr, "Failed to get command line."); - - for (int i = 0; i < argc; ++i) { - if (argv[i][0] == L'-' || argv[i][0] == L'/') { - if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, &argv[i][1], -1, L"lang", -1)) { - if (i + 1 >= argc) { - hr = E_INVALIDARG; - BalExitOnFailure(hr, "Must specify a language."); - } - - ++i; - - hr = StrAllocString(psczLanguage, &argv[i][0], 0); - BalExitOnFailure(hr, "Failed to copy language."); - } else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, &argv[i][1], -1, L"simple", -1)) { - _engine->SetVariableNumeric(L"SimpleInstall", 1); - } - } else if (_overridableVariables) { - int value; - const wchar_t* pwc = wcschr(argv[i], L'='); - if (pwc) { - hr = StrAllocString(&sczVariableName, argv[i], pwc - argv[i]); - BalExitOnFailure(hr, "Failed to copy variable name."); - - hr = DictKeyExists(_overridableVariables, sczVariableName); - if (E_NOTFOUND == hr) { - BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Ignoring attempt to set non-overridable variable: '%ls'.", sczVariableName); - hr = S_OK; - continue; - } - ExitOnFailure(hr, "Failed to check the dictionary of overridable variables."); - - hr = StrAllocString(&sczVariableValue, ++pwc, 0); - BalExitOnFailure(hr, "Failed to copy variable value."); - - if (::StrToIntEx(sczVariableValue, STIF_DEFAULT, &value)) { - hr = _engine->SetVariableNumeric(sczVariableName, value); - } else { - hr = _engine->SetVariableString(sczVariableName, sczVariableValue); - } - BalExitOnFailure(hr, "Failed to set variable."); - } else { - BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Ignoring unknown argument: %ls", argv[i]); - } - } - } - } - - LExit: - if (argv) { - ::LocalFree(argv); - } - - ReleaseStr(sczVariableName); - ReleaseStr(sczVariableValue); - - return hr; - } - - HRESULT LoadLocalization(__in_z LPCWSTR wzModulePath, __in_z_opt LPCWSTR wzLanguage) { - HRESULT hr = S_OK; - LPWSTR sczLocPath = nullptr; - LPCWSTR wzLocFileName = L"Default.wxl"; - - hr = LocProbeForFile(wzModulePath, wzLocFileName, wzLanguage, &sczLocPath); - BalExitOnFailure2(hr, "Failed to probe for loc file: %ls in path: %ls", wzLocFileName, wzModulePath); - - hr = LocLoadFromFile(sczLocPath, &_wixLoc); - BalExitOnFailure1(hr, "Failed to load loc file from path: %ls", sczLocPath); - - if (WIX_LOCALIZATION_LANGUAGE_NOT_SET != _wixLoc->dwLangId) { - ::SetThreadLocale(_wixLoc->dwLangId); - } - - hr = StrAllocString(&_confirmCloseMessage, L"#(loc.ConfirmCancelMessage)", 0); - ExitOnFailure(hr, "Failed to initialize confirm message loc identifier."); - - hr = LocLocalizeString(_wixLoc, &_confirmCloseMessage); - BalExitOnFailure1(hr, "Failed to localize confirm close message: %ls", _confirmCloseMessage); - - LExit: - ReleaseStr(sczLocPath); - - return hr; - } - - - HRESULT LoadTheme(__in_z LPCWSTR wzModulePath, __in_z_opt LPCWSTR wzLanguage) { - HRESULT hr = S_OK; - LPWSTR sczThemePath = nullptr; - LPCWSTR wzThemeFileName = L"Default.thm"; - LPWSTR sczCaption = nullptr; - - hr = LocProbeForFile(wzModulePath, wzThemeFileName, wzLanguage, &sczThemePath); - BalExitOnFailure2(hr, "Failed to probe for theme file: %ls in path: %ls", wzThemeFileName, wzModulePath); - - hr = ThemeLoadFromFile(sczThemePath, &_theme); - BalExitOnFailure1(hr, "Failed to load theme from path: %ls", sczThemePath); - - hr = ThemeLocalize(_theme, _wixLoc); - BalExitOnFailure1(hr, "Failed to localize theme: %ls", sczThemePath); - - // Update the caption if there are any formatted strings in it. - // If the wix developer is showing a hidden variable in the UI, then - // obviously they don't care about keeping it safe so don't go down the - // rabbit hole of making sure that this is securely freed. - hr = BalFormatString(_theme->sczCaption, &sczCaption); - if (SUCCEEDED(hr)) { - ThemeUpdateCaption(_theme, sczCaption); - } - - LExit: - ReleaseStr(sczCaption); - ReleaseStr(sczThemePath); - - return hr; - } - - - HRESULT ParseOverridableVariablesFromXml(__in IXMLDOMDocument* pixdManifest) { - HRESULT hr = S_OK; - IXMLDOMNode* pNode = nullptr; - IXMLDOMNodeList* pNodes = nullptr; - DWORD cNodes = 0; - LPWSTR scz = nullptr; - BOOL hidden = FALSE; - - // get the list of variables users can override on the command line - hr = XmlSelectNodes(pixdManifest, L"/BootstrapperApplicationData/WixStdbaOverridableVariable", &pNodes); - if (S_FALSE == hr) { - ExitFunction1(hr = S_OK); - } - ExitOnFailure(hr, "Failed to select overridable variable nodes."); - - hr = pNodes->get_length((long*)&cNodes); - ExitOnFailure(hr, "Failed to get overridable variable node count."); - - if (cNodes) { - hr = DictCreateStringList(&_overridableVariables, 32, DICT_FLAG_NONE); - ExitOnFailure(hr, "Failed to create the string dictionary."); - - for (DWORD i = 0; i < cNodes; ++i) { - hr = XmlNextElement(pNodes, &pNode, nullptr); - ExitOnFailure(hr, "Failed to get next node."); - - // @Name - hr = XmlGetAttributeEx(pNode, L"Name", &scz); - ExitOnFailure(hr, "Failed to get @Name."); - - hr = XmlGetYesNoAttribute(pNode, L"Hidden", &hidden); - - if (!hidden) { - hr = DictAddKey(_overridableVariables, scz); - ExitOnFailure1(hr, "Failed to add \"%ls\" to the string dictionary.", scz); - } - - // prepare next iteration - ReleaseNullObject(pNode); - } - } - - LExit: - ReleaseObject(pNode); - ReleaseObject(pNodes); - ReleaseStr(scz); - return hr; - } - - - // - // Get the file version of the bootstrapper and record in bootstrapper log file - // - HRESULT GetBundleFileVersion() { - HRESULT hr = S_OK; - ULARGE_INTEGER uliVersion = { }; - LPWSTR sczCurrentPath = nullptr; - - hr = PathForCurrentProcess(&sczCurrentPath, nullptr); - BalExitOnFailure(hr, "Failed to get bundle path."); - - hr = FileVersion(sczCurrentPath, &uliVersion.HighPart, &uliVersion.LowPart); - BalExitOnFailure(hr, "Failed to get bundle file version."); - - hr = _engine->SetVariableVersion(PYBA_VARIABLE_BUNDLE_FILE_VERSION, uliVersion.QuadPart); - BalExitOnFailure(hr, "Failed to set WixBundleFileVersion variable."); - - LExit: - ReleaseStr(sczCurrentPath); - - return hr; - } - - - // - // CreateMainWindow - creates the main install window. - // - HRESULT CreateMainWindow() { - HRESULT hr = S_OK; - HICON hIcon = reinterpret_cast(_theme->hIcon); - WNDCLASSW wc = { }; - DWORD dwWindowStyle = 0; - int x = CW_USEDEFAULT; - int y = CW_USEDEFAULT; - POINT ptCursor = { }; - HMONITOR hMonitor = nullptr; - MONITORINFO mi = { }; - COLORREF fg, bg; - HBRUSH bgBrush; - - // If the theme did not provide an icon, try using the icon from the bundle engine. - if (!hIcon) { - HMODULE hBootstrapperEngine = ::GetModuleHandleW(nullptr); - if (hBootstrapperEngine) { - hIcon = ::LoadIconW(hBootstrapperEngine, MAKEINTRESOURCEW(1)); - } - } - - fg = RGB(0, 0, 0); - bg = RGB(255, 255, 255); - bgBrush = (HBRUSH)(COLOR_WINDOW+1); - if (_theme->dwFontId < _theme->cFonts) { - THEME_FONT *font = &_theme->rgFonts[_theme->dwFontId]; - fg = font->crForeground; - bg = font->crBackground; - bgBrush = font->hBackground; - RemapColor(&fg, &bg, &bgBrush); - } - - // Register the window class and create the window. - wc.lpfnWndProc = PythonBootstrapperApplication::WndProc; - wc.hInstance = _hModule; - wc.hIcon = hIcon; - wc.hCursor = ::LoadCursorW(nullptr, (LPCWSTR)IDC_ARROW); - wc.hbrBackground = bgBrush; - wc.lpszMenuName = nullptr; - wc.lpszClassName = PYBA_WINDOW_CLASS; - if (!::RegisterClassW(&wc)) { - ExitWithLastError(hr, "Failed to register window."); - } - - _registered = TRUE; - - // Calculate the window style based on the theme style and command display value. - dwWindowStyle = _theme->dwStyle; - if (BOOTSTRAPPER_DISPLAY_NONE >= _command.display) { - dwWindowStyle &= ~WS_VISIBLE; - } - - // Don't show the window if there is a splash screen (it will be made visible when the splash screen is hidden) - if (::IsWindow(_command.hwndSplashScreen)) { - dwWindowStyle &= ~WS_VISIBLE; - } - - // Center the window on the monitor with the mouse. - if (::GetCursorPos(&ptCursor)) { - hMonitor = ::MonitorFromPoint(ptCursor, MONITOR_DEFAULTTONEAREST); - if (hMonitor) { - mi.cbSize = sizeof(mi); - if (::GetMonitorInfoW(hMonitor, &mi)) { - x = mi.rcWork.left + (mi.rcWork.right - mi.rcWork.left - _theme->nWidth) / 2; - y = mi.rcWork.top + (mi.rcWork.bottom - mi.rcWork.top - _theme->nHeight) / 2; - } - } - } - - _hWnd = ::CreateWindowExW( - 0, - wc.lpszClassName, - _theme->sczCaption, - dwWindowStyle, - x, - y, - _theme->nWidth, - _theme->nHeight, - HWND_DESKTOP, - nullptr, - _hModule, - this - ); - ExitOnNullWithLastError(_hWnd, hr, "Failed to create window."); - - hr = S_OK; - - LExit: - return hr; - } - - - // - // InitializeTaskbarButton - initializes taskbar button for progress. - // - void InitializeTaskbarButton() { - HRESULT hr = S_OK; - - hr = ::CoCreateInstance(CLSID_TaskbarList, nullptr, CLSCTX_ALL, __uuidof(ITaskbarList3), reinterpret_cast(&_taskbarList)); - if (REGDB_E_CLASSNOTREG == hr) { - // not supported before Windows 7 - ExitFunction1(hr = S_OK); - } - BalExitOnFailure(hr, "Failed to create ITaskbarList3. Continuing."); - - _taskbarButtonCreatedMessage = ::RegisterWindowMessageW(L"TaskbarButtonCreated"); - BalExitOnNullWithLastError(_taskbarButtonCreatedMessage, hr, "Failed to get TaskbarButtonCreated message. Continuing."); - - LExit: - return; - } - - // - // DestroyMainWindow - clean up all the window registration. - // - void DestroyMainWindow() { - if (::IsWindow(_hWnd)) { - ::DestroyWindow(_hWnd); - _hWnd = nullptr; - _taskbarButtonOK = FALSE; - } - - if (_registered) { - ::UnregisterClassW(PYBA_WINDOW_CLASS, _hModule); - _registered = FALSE; - } - } - - - // - // WndProc - standard windows message handler. - // - static LRESULT CALLBACK WndProc( - __in HWND hWnd, - __in UINT uMsg, - __in WPARAM wParam, - __in LPARAM lParam - ) { -#pragma warning(suppress:4312) - auto pBA = reinterpret_cast(::GetWindowLongPtrW(hWnd, GWLP_USERDATA)); - - switch (uMsg) { - case WM_NCCREATE: { - LPCREATESTRUCT lpcs = reinterpret_cast(lParam); - pBA = reinterpret_cast(lpcs->lpCreateParams); -#pragma warning(suppress:4244) - ::SetWindowLongPtrW(hWnd, GWLP_USERDATA, reinterpret_cast(pBA)); - break; - } - - case WM_NCDESTROY: { - LRESULT lres = ThemeDefWindowProc(pBA ? pBA->_theme : nullptr, hWnd, uMsg, wParam, lParam); - ::SetWindowLongPtrW(hWnd, GWLP_USERDATA, 0); - return lres; - } - - case WM_CREATE: - if (!pBA->OnCreate(hWnd)) { - return -1; - } - break; - - case WM_QUERYENDSESSION: - return IDCANCEL != pBA->OnSystemShutdown(static_cast(lParam), IDCANCEL); - - case WM_CLOSE: - // If the user chose not to close, do *not* let the default window proc handle the message. - if (!pBA->OnClose()) { - return 0; - } - break; - - case WM_DESTROY: - ::PostQuitMessage(0); - break; - - case WM_PAINT: __fallthrough; - case WM_ERASEBKGND: - if (pBA && pBA->_suppressPaint) { - return TRUE; - } - break; - - case WM_PYBA_SHOW_HELP: - pBA->OnShowHelp(); - return 0; - - case WM_PYBA_DETECT_PACKAGES: - pBA->OnDetect(); - return 0; - - case WM_PYBA_PLAN_PACKAGES: - pBA->OnPlan(static_cast(lParam)); - return 0; - - case WM_PYBA_APPLY_PACKAGES: - pBA->OnApply(); - return 0; - - case WM_PYBA_CHANGE_STATE: - pBA->OnChangeState(static_cast(lParam)); - return 0; - - case WM_PYBA_SHOW_FAILURE: - pBA->OnShowFailure(); - return 0; - - case WM_COMMAND: - switch (LOWORD(wParam)) { - // Customize commands - // Success/failure commands - case ID_SUCCESS_RESTART_BUTTON: __fallthrough; - case ID_FAILURE_RESTART_BUTTON: - pBA->OnClickRestartButton(); - return 0; - - case IDCANCEL: __fallthrough; - case ID_INSTALL_CANCEL_BUTTON: __fallthrough; - case ID_CUSTOM1_CANCEL_BUTTON: __fallthrough; - case ID_CUSTOM2_CANCEL_BUTTON: __fallthrough; - case ID_MODIFY_CANCEL_BUTTON: __fallthrough; - case ID_PROGRESS_CANCEL_BUTTON: __fallthrough; - case ID_SUCCESS_CANCEL_BUTTON: __fallthrough; - case ID_FAILURE_CANCEL_BUTTON: __fallthrough; - case ID_CLOSE_BUTTON: - pBA->OnCommand(ID_CLOSE_BUTTON); - return 0; - - default: - pBA->OnCommand((CONTROL_ID)LOWORD(wParam)); - } - break; - - case WM_NOTIFY: - if (lParam) { - LPNMHDR pnmhdr = reinterpret_cast(lParam); - switch (pnmhdr->code) { - case NM_CLICK: __fallthrough; - case NM_RETURN: - switch (static_cast(pnmhdr->idFrom)) { - case ID_FAILURE_LOGFILE_LINK: - pBA->OnClickLogFileLink(); - return 1; - } - } - } - break; - - case WM_CTLCOLORSTATIC: - case WM_CTLCOLORBTN: - if (pBA) { - HBRUSH brush = nullptr; - if (pBA->SetControlColor((HWND)lParam, (HDC)wParam, &brush)) { - return (LRESULT)brush; - } - } - break; - } - - if (pBA && pBA->_taskbarList && uMsg == pBA->_taskbarButtonCreatedMessage) { - pBA->_taskbarButtonOK = TRUE; - return 0; - } - - return ThemeDefWindowProc(pBA ? pBA->_theme : nullptr, hWnd, uMsg, wParam, lParam); - } - - // - // OnCreate - finishes loading the theme. - // - BOOL OnCreate(__in HWND hWnd) { - HRESULT hr = S_OK; - - hr = ThemeLoadControls(_theme, hWnd, CONTROL_ID_NAMES, countof(CONTROL_ID_NAMES)); - BalExitOnFailure(hr, "Failed to load theme controls."); - - C_ASSERT(COUNT_PAGE == countof(PAGE_NAMES)); - C_ASSERT(countof(_pageIds) == countof(PAGE_NAMES)); - - ThemeGetPageIds(_theme, PAGE_NAMES, _pageIds, countof(_pageIds)); - - // Initialize the text on all "application" (non-page) controls. - for (DWORD i = 0; i < _theme->cControls; ++i) { - THEME_CONTROL* pControl = _theme->rgControls + i; - LPWSTR text = nullptr; - - if (!pControl->wPageId && pControl->sczText && *pControl->sczText) { - HRESULT hrFormat; - - // If the wix developer is showing a hidden variable in the UI, - // then obviously they don't care about keeping it safe so don't - // go down the rabbit hole of making sure that this is securely - // freed. - hrFormat = BalFormatString(pControl->sczText, &text); - if (SUCCEEDED(hrFormat)) { - ThemeSetTextControl(_theme, pControl->wId, text); - ReleaseStr(text); - } - } - } - - LExit: - return SUCCEEDED(hr); - } - - void RemapColor(COLORREF *fg, COLORREF *bg, HBRUSH *bgBrush) { - if (*fg == RGB(0, 0, 0)) { - *fg = GetSysColor(COLOR_WINDOWTEXT); - } else if (*fg == RGB(128, 128, 128)) { - *fg = GetSysColor(COLOR_GRAYTEXT); - } - if (*bgBrush && *bg == RGB(255, 255, 255)) { - *bg = GetSysColor(COLOR_WINDOW); - *bgBrush = GetSysColorBrush(COLOR_WINDOW); - } - } - - BOOL SetControlColor(HWND hWnd, HDC hDC, HBRUSH *brush) { - for (int i = 0; i < _theme->cControls; ++i) { - if (_theme->rgControls[i].hWnd != hWnd) { - continue; - } - - DWORD fontId = _theme->rgControls[i].dwFontId; - if (fontId > _theme->cFonts) { - fontId = 0; - } - THEME_FONT *fnt = &_theme->rgFonts[fontId]; - - COLORREF fg = fnt->crForeground, bg = fnt->crBackground; - *brush = fnt->hBackground; - RemapColor(&fg, &bg, brush); - ::SetTextColor(hDC, fg); - ::SetBkColor(hDC, bg); - - return TRUE; - } - return FALSE; - } - - // - // OnShowFailure - display the failure page. - // - void OnShowFailure() { - SetState(PYBA_STATE_FAILED, S_OK); - - // If the UI should be visible, display it now and hide the splash screen - if (BOOTSTRAPPER_DISPLAY_NONE < _command.display) { - ::ShowWindow(_theme->hwndParent, SW_SHOW); - } - - _engine->CloseSplashScreen(); - - return; - } - - - // - // OnShowHelp - display the help page. - // - void OnShowHelp() { - SetState(PYBA_STATE_HELP, S_OK); - - // If the UI should be visible, display it now and hide the splash screen - if (BOOTSTRAPPER_DISPLAY_NONE < _command.display) { - ::ShowWindow(_theme->hwndParent, SW_SHOW); - } - - _engine->CloseSplashScreen(); - - return; - } - - - // - // OnDetect - start the processing of packages. - // - void OnDetect() { - HRESULT hr = S_OK; - - if (_baFunction) { - BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Running detect BA function"); - hr = _baFunction->OnDetect(); - BalExitOnFailure(hr, "Failed calling detect BA function."); - } - - SetState(PYBA_STATE_DETECTING, hr); - - // If the UI should be visible, display it now and hide the splash screen - if (BOOTSTRAPPER_DISPLAY_NONE < _command.display) { - ::ShowWindow(_theme->hwndParent, SW_SHOW); - } - - _engine->CloseSplashScreen(); - - // Tell the core we're ready for the packages to be processed now. - hr = _engine->Detect(); - BalExitOnFailure(hr, "Failed to start detecting chain."); - - LExit: - if (FAILED(hr)) { - SetState(PYBA_STATE_DETECTING, hr); - } - - return; - } - - HRESULT UpdateUIStrings(__in BOOTSTRAPPER_ACTION action) { - HRESULT hr = S_OK; - LPCWSTR likeInstalling = nullptr; - LPCWSTR likeInstallation = nullptr; - switch (action) { - case BOOTSTRAPPER_ACTION_INSTALL: - likeInstalling = L"Installing"; - likeInstallation = L"Installation"; - break; - case BOOTSTRAPPER_ACTION_MODIFY: - // For modify, we actually want to pass INSTALL - action = BOOTSTRAPPER_ACTION_INSTALL; - likeInstalling = L"Modifying"; - likeInstallation = L"Modification"; - break; - case BOOTSTRAPPER_ACTION_REPAIR: - likeInstalling = L"Repairing"; - likeInstallation = L"Repair"; - break; - case BOOTSTRAPPER_ACTION_UNINSTALL: - likeInstalling = L"Uninstalling"; - likeInstallation = L"Uninstallation"; - break; - } - - if (likeInstalling) { - LPWSTR locName = nullptr; - LOC_STRING *locText = nullptr; - hr = StrAllocFormatted(&locName, L"#(loc.%ls)", likeInstalling); - if (SUCCEEDED(hr)) { - hr = LocGetString(_wixLoc, locName, &locText); - ReleaseStr(locName); - } - _engine->SetVariableString( - L"ActionLikeInstalling", - SUCCEEDED(hr) && locText ? locText->wzText : likeInstalling - ); - } - - if (likeInstallation) { - LPWSTR locName = nullptr; - LOC_STRING *locText = nullptr; - hr = StrAllocFormatted(&locName, L"#(loc.%ls)", likeInstallation); - if (SUCCEEDED(hr)) { - hr = LocGetString(_wixLoc, locName, &locText); - ReleaseStr(locName); - } - _engine->SetVariableString( - L"ActionLikeInstallation", - SUCCEEDED(hr) && locText ? locText->wzText : likeInstallation - ); - } - return hr; - } - - // - // OnPlan - plan the detected changes. - // - void OnPlan(__in BOOTSTRAPPER_ACTION action) { - HRESULT hr = S_OK; - - _plannedAction = action; - - hr = UpdateUIStrings(action); - BalExitOnFailure(hr, "Failed to update strings"); - - // If we are going to apply a downgrade, bail. - if (_downgradingOtherVersion && BOOTSTRAPPER_ACTION_UNINSTALL < action) { - if (_suppressDowngradeFailure) { - BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "A newer version of this product is installed but downgrade failure has been suppressed; continuing..."); - } else { - hr = HRESULT_FROM_WIN32(ERROR_PRODUCT_VERSION); - BalExitOnFailure(hr, "Cannot install a product when a newer version is installed."); - } - } - - SetState(PYBA_STATE_PLANNING, hr); - - if (_baFunction) { - BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Running plan BA function"); - _baFunction->OnPlan(); - } - - hr = _engine->Plan(action); - BalExitOnFailure(hr, "Failed to start planning packages."); - - LExit: - if (FAILED(hr)) { - SetState(PYBA_STATE_PLANNING, hr); - } - - return; - } - - - // - // OnApply - apply the packages. - // - void OnApply() { - HRESULT hr = S_OK; - - SetState(PYBA_STATE_APPLYING, hr); - SetProgressState(hr); - SetTaskbarButtonProgress(0); - - hr = _engine->Apply(_hWnd); - BalExitOnFailure(hr, "Failed to start applying packages."); - - ThemeControlEnable(_theme, ID_PROGRESS_CANCEL_BUTTON, TRUE); // ensure the cancel button is enabled before starting. - - LExit: - if (FAILED(hr)) { - SetState(PYBA_STATE_APPLYING, hr); - } - - return; - } - - - // - // OnChangeState - change state. - // - void OnChangeState(__in PYBA_STATE state) { - LPWSTR unformattedText = nullptr; - - _state = state; - - // If our install is at the end (success or failure) and we're not showing full UI - // then exit (prompt for restart if required). - if ((PYBA_STATE_APPLIED <= _state && BOOTSTRAPPER_DISPLAY_FULL > _command.display)) { - // If a restart was required but we were not automatically allowed to - // accept the reboot then do the prompt. - if (_restartRequired && !_allowRestart) { - StrAllocFromError(&unformattedText, HRESULT_FROM_WIN32(ERROR_SUCCESS_REBOOT_REQUIRED), nullptr); - - _allowRestart = IDOK == ::MessageBoxW( - _hWnd, - unformattedText ? unformattedText : L"The requested operation is successful. Changes will not be effective until the system is rebooted.", - _theme->sczCaption, - MB_ICONEXCLAMATION | MB_OKCANCEL - ); - } - - // Quietly exit. - ::PostMessageW(_hWnd, WM_CLOSE, 0, 0); - } else { // try to change the pages. - DWORD newPageId = 0; - DeterminePageId(_state, &newPageId); - - if (_visiblePageId != newPageId) { - ShowPage(newPageId); - } - } - - ReleaseStr(unformattedText); - } - - // - // Called before showing a page to handle all controls. - // - void ProcessPageControls(THEME_PAGE *pPage) { - if (!pPage) { - return; - } - - for (DWORD i = 0; i < pPage->cControlIndices; ++i) { - THEME_CONTROL* pControl = _theme->rgControls + pPage->rgdwControlIndices[i]; - BOOL enableControl = TRUE; - - // If this is a named control, try to set its default state. - if (pControl->sczName && *pControl->sczName) { - // If this is a checkable control, try to set its default state - // to the state of a matching named Burn variable. - if (IsCheckable(pControl)) { - LONGLONG llValue = 0; - HRESULT hr = BalGetNumericVariable(pControl->sczName, &llValue); - - // If the control value isn't set then disable it. - if (!SUCCEEDED(hr)) { - enableControl = FALSE; - } else { - ThemeSendControlMessage( - _theme, - pControl->wId, - BM_SETCHECK, - SUCCEEDED(hr) && llValue ? BST_CHECKED : BST_UNCHECKED, - 0 - ); - } - } - - // Hide or disable controls based on the control name with 'State' appended - LPWSTR controlName = nullptr; - HRESULT hr = StrAllocFormatted(&controlName, L"%lsState", pControl->sczName); - if (SUCCEEDED(hr)) { - LPWSTR controlState = nullptr; - hr = BalGetStringVariable(controlName, &controlState); - if (SUCCEEDED(hr) && controlState && *controlState) { - if (controlState[0] == '[') { - LPWSTR formatted = nullptr; - if (SUCCEEDED(BalFormatString(controlState, &formatted))) { - StrFree(controlState); - controlState = formatted; - } - } - - if (CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, controlState, -1, L"disable", -1)) { - BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Disable control %ls", pControl->sczName); - enableControl = FALSE; - } else if (CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, controlState, -1, L"hide", -1)) { - BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Hide control %ls", pControl->sczName); - // TODO: This doesn't work - ThemeShowControl(_theme, pControl->wId, SW_HIDE); - } else { - // An explicit state can override the lack of a - // backing variable. - enableControl = TRUE; - } - } - StrFree(controlState); - } - StrFree(controlName); - controlName = nullptr; - - - // If a command link has a note, then add it. - if ((pControl->dwStyle & BS_TYPEMASK) == BS_COMMANDLINK || - (pControl->dwStyle & BS_TYPEMASK) == BS_DEFCOMMANDLINK) { - hr = StrAllocFormatted(&controlName, L"#(loc.%lsNote)", pControl->sczName); - if (SUCCEEDED(hr)) { - LOC_STRING *locText = nullptr; - hr = LocGetString(_wixLoc, controlName, &locText); - if (SUCCEEDED(hr) && locText && locText->wzText && locText->wzText[0]) { - LPWSTR text = nullptr; - hr = BalFormatString(locText->wzText, &text); - if (SUCCEEDED(hr) && text && text[0]) { - ThemeSendControlMessage(_theme, pControl->wId, BCM_SETNOTE, 0, (LPARAM)text); - ReleaseStr(text); - text = nullptr; - } - } - ReleaseStr(controlName); - controlName = nullptr; - } - hr = S_OK; - } - } - - ThemeControlEnable(_theme, pControl->wId, enableControl); - - // Format the text in each of the new page's controls - if (pControl->sczText && *pControl->sczText) { - // If the wix developer is showing a hidden variable - // in the UI, then obviously they don't care about - // keeping it safe so don't go down the rabbit hole - // of making sure that this is securely freed. - LPWSTR text = nullptr; - HRESULT hr = BalFormatString(pControl->sczText, &text); - if (SUCCEEDED(hr)) { - ThemeSetTextControl(_theme, pControl->wId, text); - } - } - } - } - - // - // OnClose - called when the window is trying to be closed. - // - BOOL OnClose() { - BOOL close = FALSE; - - // If we've already succeeded or failed or showing the help page, just close (prompts are annoying if the bootstrapper is done). - if (PYBA_STATE_APPLIED <= _state || PYBA_STATE_HELP == _state) { - close = TRUE; - } else { - // prompt the user or force the cancel if there is no UI. - close = PromptCancel( - _hWnd, - BOOTSTRAPPER_DISPLAY_FULL != _command.display, - _confirmCloseMessage ? _confirmCloseMessage : L"Are you sure you want to cancel?", - _theme->sczCaption - ); - } - - // If we're doing progress then we never close, we just cancel to let rollback occur. - if (PYBA_STATE_APPLYING <= _state && PYBA_STATE_APPLIED > _state) { - // If we canceled disable cancel button since clicking it again is silly. - if (close) { - ThemeControlEnable(_theme, ID_PROGRESS_CANCEL_BUTTON, FALSE); - } - - close = FALSE; - } - - return close; - } - - // - // OnClickCloseButton - close the application. - // - void OnClickCloseButton() { - ::SendMessageW(_hWnd, WM_CLOSE, 0, 0); - } - - - - // - // OnClickRestartButton - allows the restart and closes the app. - // - void OnClickRestartButton() { - AssertSz(_restartRequired, "Restart must be requested to be able to click on the restart button."); - - _allowRestart = TRUE; - ::SendMessageW(_hWnd, WM_CLOSE, 0, 0); - - return; - } - - - // - // OnClickLogFileLink - show the log file. - // - void OnClickLogFileLink() { - HRESULT hr = S_OK; - LPWSTR sczLogFile = nullptr; - - hr = BalGetStringVariable(_bundle.sczLogVariable, &sczLogFile); - BalExitOnFailure1(hr, "Failed to get log file variable '%ls'.", _bundle.sczLogVariable); - - hr = ShelExec(L"notepad.exe", sczLogFile, L"open", nullptr, SW_SHOWDEFAULT, _hWnd, nullptr); - BalExitOnFailure1(hr, "Failed to open log file target: %ls", sczLogFile); - - LExit: - ReleaseStr(sczLogFile); - - return; - } - - - // - // SetState - // - void SetState(__in PYBA_STATE state, __in HRESULT hrStatus) { - if (FAILED(hrStatus)) { - _hrFinal = hrStatus; - } - - if (FAILED(_hrFinal)) { - state = PYBA_STATE_FAILED; - } - - if (_state != state) { - ::PostMessageW(_hWnd, WM_PYBA_CHANGE_STATE, 0, state); - } - } - - // - // GoToPage - // - void GoToPage(__in PAGE page) { - _installPage = page; - ::PostMessageW(_hWnd, WM_PYBA_CHANGE_STATE, 0, _state); - } - - void DeterminePageId(__in PYBA_STATE state, __out DWORD* pdwPageId) { - LONGLONG simple; - - if (BOOTSTRAPPER_DISPLAY_PASSIVE == _command.display) { - switch (state) { - case PYBA_STATE_INITIALIZED: - *pdwPageId = BOOTSTRAPPER_ACTION_HELP == _command.action - ? _pageIds[PAGE_HELP] - : _pageIds[PAGE_LOADING]; - break; - - case PYBA_STATE_HELP: - *pdwPageId = _pageIds[PAGE_HELP]; - break; - - case PYBA_STATE_DETECTING: - *pdwPageId = _pageIds[PAGE_LOADING] - ? _pageIds[PAGE_LOADING] - : _pageIds[PAGE_PROGRESS_PASSIVE] - ? _pageIds[PAGE_PROGRESS_PASSIVE] - : _pageIds[PAGE_PROGRESS]; - break; - - case PYBA_STATE_DETECTED: __fallthrough; - case PYBA_STATE_PLANNING: __fallthrough; - case PYBA_STATE_PLANNED: __fallthrough; - case PYBA_STATE_APPLYING: __fallthrough; - case PYBA_STATE_CACHING: __fallthrough; - case PYBA_STATE_CACHED: __fallthrough; - case PYBA_STATE_EXECUTING: __fallthrough; - case PYBA_STATE_EXECUTED: - *pdwPageId = _pageIds[PAGE_PROGRESS_PASSIVE] - ? _pageIds[PAGE_PROGRESS_PASSIVE] - : _pageIds[PAGE_PROGRESS]; - break; - - default: - *pdwPageId = 0; - break; - } - } else if (BOOTSTRAPPER_DISPLAY_FULL == _command.display) { - switch (state) { - case PYBA_STATE_INITIALIZING: - *pdwPageId = 0; - break; - - case PYBA_STATE_INITIALIZED: - *pdwPageId = BOOTSTRAPPER_ACTION_HELP == _command.action - ? _pageIds[PAGE_HELP] - : _pageIds[PAGE_LOADING]; - break; - - case PYBA_STATE_HELP: - *pdwPageId = _pageIds[PAGE_HELP]; - break; - - case PYBA_STATE_DETECTING: - *pdwPageId = _pageIds[PAGE_LOADING]; - break; - - case PYBA_STATE_DETECTED: - if (_installPage == PAGE_LOADING) { - switch (_command.action) { - case BOOTSTRAPPER_ACTION_INSTALL: - if (_upgrading) { - _installPage = PAGE_UPGRADE; - } else if (SUCCEEDED(BalGetNumericVariable(L"SimpleInstall", &simple)) && simple) { - _installPage = PAGE_SIMPLE_INSTALL; - } else { - _installPage = PAGE_INSTALL; - } - break; - - case BOOTSTRAPPER_ACTION_MODIFY: __fallthrough; - case BOOTSTRAPPER_ACTION_REPAIR: __fallthrough; - case BOOTSTRAPPER_ACTION_UNINSTALL: - _installPage = PAGE_MODIFY; - break; - } - } - *pdwPageId = _pageIds[_installPage]; - break; - - case PYBA_STATE_PLANNING: __fallthrough; - case PYBA_STATE_PLANNED: __fallthrough; - case PYBA_STATE_APPLYING: __fallthrough; - case PYBA_STATE_CACHING: __fallthrough; - case PYBA_STATE_CACHED: __fallthrough; - case PYBA_STATE_EXECUTING: __fallthrough; - case PYBA_STATE_EXECUTED: - *pdwPageId = _pageIds[PAGE_PROGRESS]; - break; - - case PYBA_STATE_APPLIED: - *pdwPageId = _pageIds[PAGE_SUCCESS]; - break; - - case PYBA_STATE_FAILED: - *pdwPageId = _pageIds[PAGE_FAILURE]; - break; - } - } - } - - BOOL WillElevate() { - static BAL_CONDITION WILL_ELEVATE_CONDITION = { - L"not WixBundleElevated and (" - /*Elevate when installing for all users*/ - L"InstallAllUsers or " - /*Elevate when installing the launcher for all users and it was not detected*/ - L"(Include_launcher and InstallLauncherAllUsers and not DetectedLauncher)" - L")", - L"" - }; - BOOL result; - - return SUCCEEDED(BalConditionEvaluate(&WILL_ELEVATE_CONDITION, _engine, &result, nullptr)) && result; - } - - BOOL IsCrtInstalled() { - if (_crtInstalledToken > 0) { - return TRUE; - } else if (_crtInstalledToken == 0) { - return FALSE; - } - - // Check whether at least CRT v10.0.10137.0 is available. - // It should only be installed as a Windows Update package, which means - // we don't need to worry about 32-bit/64-bit. - LPCWSTR crtFile = L"ucrtbase.dll"; - - DWORD cbVer = GetFileVersionInfoSizeW(crtFile, nullptr); - if (!cbVer) { - _crtInstalledToken = 0; - return FALSE; - } - - void *pData = malloc(cbVer); - if (!pData) { - _crtInstalledToken = 0; - return FALSE; - } - - if (!GetFileVersionInfoW(crtFile, 0, cbVer, pData)) { - free(pData); - _crtInstalledToken = 0; - return FALSE; - } - - VS_FIXEDFILEINFO *ffi; - UINT cb; - BOOL result = FALSE; - - if (VerQueryValueW(pData, L"\\", (LPVOID*)&ffi, &cb) && - ffi->dwFileVersionMS == 0x000A0000 && ffi->dwFileVersionLS >= 0x27990000) { - result = TRUE; - } - - free(pData); - _crtInstalledToken = result ? 1 : 0; - return result; - } - - BOOL QueryElevateForCrtInstall() { - // Called to prompt the user that even though they think they won't need - // to elevate, they actually will because of the CRT install. - if (IsCrtInstalled()) { - // CRT is already installed - no need to prompt - return TRUE; - } - - LONGLONG elevated; - HRESULT hr = BalGetNumericVariable(L"WixBundleElevated", &elevated); - if (SUCCEEDED(hr) && elevated) { - // Already elevated - no need to prompt - return TRUE; - } - - LOC_STRING *locStr; - hr = LocGetString(_wixLoc, L"#(loc.ElevateForCRTInstall)", &locStr); - if (FAILED(hr)) { - BalLogError(hr, "Failed to get ElevateForCRTInstall string"); - return FALSE; - } - return ::MessageBoxW(_hWnd, locStr->wzText, _theme->sczCaption, MB_YESNO) != IDNO; - } - - HRESULT EvaluateConditions() { - HRESULT hr = S_OK; - BOOL result = FALSE; - - for (DWORD i = 0; i < _conditions.cConditions; ++i) { - BAL_CONDITION* pCondition = _conditions.rgConditions + i; - - hr = BalConditionEvaluate(pCondition, _engine, &result, &_failedMessage); - BalExitOnFailure(hr, "Failed to evaluate condition."); - - if (!result) { - // Hope they didn't have hidden variables in their message, because it's going in the log in plaintext. - BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "%ls", _failedMessage); - - hr = E_WIXSTDBA_CONDITION_FAILED; - // todo: remove in WiX v4, in case people are relying on v3.x logging behavior - BalExitOnFailure1(hr, "Bundle condition evaluated to false: %ls", pCondition->sczCondition); - } - } - - ReleaseNullStrSecure(_failedMessage); - - LExit: - return hr; - } - - - void SetTaskbarButtonProgress(__in DWORD dwOverallPercentage) { - HRESULT hr = S_OK; - - if (_taskbarButtonOK) { - hr = _taskbarList->SetProgressValue(_hWnd, dwOverallPercentage, 100UL); - BalExitOnFailure1(hr, "Failed to set taskbar button progress to: %d%%.", dwOverallPercentage); - } - - LExit: - return; - } - - - void SetTaskbarButtonState(__in TBPFLAG tbpFlags) { - HRESULT hr = S_OK; - - if (_taskbarButtonOK) { - hr = _taskbarList->SetProgressState(_hWnd, tbpFlags); - BalExitOnFailure1(hr, "Failed to set taskbar button state.", tbpFlags); - } - - LExit: - return; - } - - - void SetProgressState(__in HRESULT hrStatus) { - TBPFLAG flag = TBPF_NORMAL; - - if (IsCanceled() || HRESULT_FROM_WIN32(ERROR_INSTALL_USEREXIT) == hrStatus) { - flag = TBPF_PAUSED; - } else if (IsRollingBack() || FAILED(hrStatus)) { - flag = TBPF_ERROR; - } - - SetTaskbarButtonState(flag); - } - - - HRESULT LoadBootstrapperBAFunctions() { - HRESULT hr = S_OK; - LPWSTR sczBafPath = nullptr; - - hr = PathRelativeToModule(&sczBafPath, L"bafunctions.dll", _hModule); - BalExitOnFailure(hr, "Failed to get path to BA function DLL."); - -#ifdef DEBUG - BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "PYBA: LoadBootstrapperBAFunctions() - BA function DLL %ls", sczBafPath); -#endif - - _hBAFModule = ::LoadLibraryW(sczBafPath); - if (_hBAFModule) { - auto pfnBAFunctionCreate = reinterpret_cast(::GetProcAddress(_hBAFModule, "CreateBootstrapperBAFunction")); - BalExitOnNullWithLastError1(pfnBAFunctionCreate, hr, "Failed to get CreateBootstrapperBAFunction entry-point from: %ls", sczBafPath); - - hr = pfnBAFunctionCreate(_engine, _hBAFModule, &_baFunction); - BalExitOnFailure(hr, "Failed to create BA function."); - } -#ifdef DEBUG - else { - BalLogError(HRESULT_FROM_WIN32(::GetLastError()), "PYBA: LoadBootstrapperBAFunctions() - Failed to load DLL %ls", sczBafPath); - } -#endif - - LExit: - if (_hBAFModule && !_baFunction) { - ::FreeLibrary(_hBAFModule); - _hBAFModule = nullptr; - } - ReleaseStr(sczBafPath); - - return hr; - } - - BOOL IsCheckable(THEME_CONTROL* pControl) { - if (!pControl->sczName || !pControl->sczName[0]) { - return FALSE; - } - - if (pControl->type == THEME_CONTROL_TYPE_CHECKBOX) { - return TRUE; - } - - if (pControl->type == THEME_CONTROL_TYPE_BUTTON) { - if ((pControl->dwStyle & BS_TYPEMASK) == BS_AUTORADIOBUTTON) { - return TRUE; - } - } - - return FALSE; - } - - void SavePageSettings() { - DWORD pageId = 0; - THEME_PAGE* pPage = nullptr; - - DeterminePageId(_state, &pageId); - pPage = ThemeGetPage(_theme, pageId); - if (!pPage) { - return; - } - - for (DWORD i = 0; i < pPage->cControlIndices; ++i) { - // Loop through all the checkable controls and set a Burn variable - // with that name to true or false. - THEME_CONTROL* pControl = _theme->rgControls + pPage->rgdwControlIndices[i]; - if (IsCheckable(pControl) && ThemeControlEnabled(_theme, pControl->wId)) { - BOOL checked = ThemeIsControlChecked(_theme, pControl->wId); - _engine->SetVariableNumeric(pControl->sczName, checked ? 1 : 0); - } - - // Loop through all the editbox controls with names and set a - // Burn variable with that name to the contents. - if (THEME_CONTROL_TYPE_EDITBOX == pControl->type && pControl->sczName && *pControl->sczName) { - LPWSTR sczValue = nullptr; - ThemeGetTextControl(_theme, pControl->wId, &sczValue); - _engine->SetVariableString(pControl->sczName, sczValue); - } - } - } - - static bool IsTargetPlatformx64(__in IBootstrapperEngine* pEngine) { - WCHAR platform[8]; - DWORD platformLen = 8; - - if (FAILED(pEngine->GetVariableString(L"TargetPlatform", platform, &platformLen))) { - return S_FALSE; - } - - return ::CompareStringW(LOCALE_NEUTRAL, 0, platform, -1, L"x64", -1) == CSTR_EQUAL; - } - - static HRESULT LoadOptionalFeatureStatesFromKey( - __in IBootstrapperEngine* pEngine, - __in HKEY hkHive, - __in LPCWSTR subkey - ) { - HKEY hKey; - LRESULT res; - - if (IsTargetPlatformx64(pEngine)) { - res = RegOpenKeyExW(hkHive, subkey, 0, KEY_READ | KEY_WOW64_64KEY, &hKey); - } else { - res = RegOpenKeyExW(hkHive, subkey, 0, KEY_READ | KEY_WOW64_32KEY, &hKey); - } - if (res == ERROR_FILE_NOT_FOUND) { - return S_FALSE; - } - if (res != ERROR_SUCCESS) { - return HRESULT_FROM_WIN32(res); - } - - for (auto p = OPTIONAL_FEATURES; p->regName; ++p) { - res = RegQueryValueExW(hKey, p->regName, nullptr, nullptr, nullptr, nullptr); - if (res == ERROR_FILE_NOT_FOUND) { - pEngine->SetVariableNumeric(p->variableName, 0); - } else if (res == ERROR_SUCCESS) { - pEngine->SetVariableNumeric(p->variableName, 1); - } else { - RegCloseKey(hKey); - return HRESULT_FROM_WIN32(res); - } - } - - RegCloseKey(hKey); - return S_OK; - } - - static HRESULT LoadTargetDirFromKey( - __in IBootstrapperEngine* pEngine, - __in HKEY hkHive, - __in LPCWSTR subkey - ) { - HKEY hKey; - LRESULT res; - DWORD dataType; - BYTE buffer[1024]; - DWORD bufferLen = sizeof(buffer); - - if (IsTargetPlatformx64(pEngine)) { - res = RegOpenKeyExW(hkHive, subkey, 0, KEY_READ | KEY_WOW64_64KEY, &hKey); - } else { - res = RegOpenKeyExW(hkHive, subkey, 0, KEY_READ | KEY_WOW64_32KEY, &hKey); - } - if (res == ERROR_FILE_NOT_FOUND) { - return S_FALSE; - } - if (res != ERROR_SUCCESS) { - return HRESULT_FROM_WIN32(res); - } - - res = RegQueryValueExW(hKey, nullptr, nullptr, &dataType, buffer, &bufferLen); - if (res == ERROR_SUCCESS && dataType == REG_SZ && bufferLen < sizeof(buffer)) { - pEngine->SetVariableString(L"TargetDir", reinterpret_cast(buffer)); - } - RegCloseKey(hKey); - return HRESULT_FROM_WIN32(res); - } - - static HRESULT LoadAssociateFilesStateFromKey( - __in IBootstrapperEngine* pEngine, - __in HKEY hkHive - ) { - const LPCWSTR subkey = L"Software\\Python\\PyLauncher"; - HKEY hKey; - LRESULT res; - HRESULT hr; - - res = RegOpenKeyExW(hkHive, subkey, 0, KEY_READ | KEY_WOW64_32KEY, &hKey); - - if (res == ERROR_FILE_NOT_FOUND) { - return S_FALSE; - } - if (res != ERROR_SUCCESS) { - return HRESULT_FROM_WIN32(res); - } - - res = RegQueryValueExW(hKey, L"AssociateFiles", nullptr, nullptr, nullptr, nullptr); - if (res == ERROR_FILE_NOT_FOUND) { - hr = S_FALSE; - } else if (res == ERROR_SUCCESS) { - hr = S_OK; - } else { - hr = HRESULT_FROM_WIN32(res); - } - - RegCloseKey(hKey); - return hr; - } - - static void LoadOptionalFeatureStates(__in IBootstrapperEngine* pEngine) { - WCHAR subkeyFmt[256]; - WCHAR subkey[256]; - DWORD subkeyLen; - HRESULT hr; - HKEY hkHive; - - // The launcher installation is separate from the Python install, so we - // check its state later. For now, assume we don't want the launcher or - // file associations, and if they have already been installed then - // loading the state will reactivate these settings. - pEngine->SetVariableNumeric(L"Include_launcher", 0); - pEngine->SetVariableNumeric(L"AssociateFiles", 0); - - // Get the registry key from the bundle, to save having to duplicate it - // in multiple places. - subkeyLen = sizeof(subkeyFmt) / sizeof(subkeyFmt[0]); - hr = pEngine->GetVariableString(L"OptionalFeaturesRegistryKey", subkeyFmt, &subkeyLen); - BalExitOnFailure(hr, "Failed to locate registry key"); - subkeyLen = sizeof(subkey) / sizeof(subkey[0]); - hr = pEngine->FormatString(subkeyFmt, subkey, &subkeyLen); - BalExitOnFailure1(hr, "Failed to format %ls", subkeyFmt); - - // Check the current user's registry for existing features - hkHive = HKEY_CURRENT_USER; - hr = LoadOptionalFeatureStatesFromKey(pEngine, hkHive, subkey); - BalExitOnFailure1(hr, "Failed to read from HKCU\\%ls", subkey); - if (hr == S_FALSE) { - // Now check the local machine registry - hkHive = HKEY_LOCAL_MACHINE; - hr = LoadOptionalFeatureStatesFromKey(pEngine, hkHive, subkey); - BalExitOnFailure1(hr, "Failed to read from HKLM\\%ls", subkey); - if (hr == S_OK) { - // Found a system-wide install, so enable these settings. - pEngine->SetVariableNumeric(L"InstallAllUsers", 1); - pEngine->SetVariableNumeric(L"CompileAll", 1); - } - } - - if (hr == S_OK) { - // Cannot change InstallAllUsersState when upgrading. While there's - // no good reason to not allow installing a per-user and an all-user - // version simultaneously, Burn can't handle the state management - // and will need to uninstall the old one. - pEngine->SetVariableString(L"InstallAllUsersState", L"disable"); - - // Get the previous install directory. This can be changed by the - // user. - subkeyLen = sizeof(subkeyFmt) / sizeof(subkeyFmt[0]); - hr = pEngine->GetVariableString(L"TargetDirRegistryKey", subkeyFmt, &subkeyLen); - BalExitOnFailure(hr, "Failed to locate registry key"); - subkeyLen = sizeof(subkey) / sizeof(subkey[0]); - hr = pEngine->FormatString(subkeyFmt, subkey, &subkeyLen); - BalExitOnFailure1(hr, "Failed to format %ls", subkeyFmt); - LoadTargetDirFromKey(pEngine, hkHive, subkey); - } - - LExit: - return; - } - - HRESULT EnsureTargetDir() { - LONGLONG installAllUsers; - LPWSTR targetDir = nullptr, defaultDir = nullptr; - HRESULT hr = BalGetStringVariable(L"TargetDir", &targetDir); - if (FAILED(hr) || !targetDir || !targetDir[0]) { - ReleaseStr(targetDir); - targetDir = nullptr; - - hr = BalGetNumericVariable(L"InstallAllUsers", &installAllUsers); - ExitOnFailure(hr, L"Failed to get install scope"); - - hr = BalGetStringVariable( - installAllUsers ? L"DefaultAllUsersTargetDir" : L"DefaultJustForMeTargetDir", - &defaultDir - ); - BalExitOnFailure(hr, "Failed to get the default install directory"); - - if (!defaultDir || !defaultDir[0]) { - BalLogError(E_INVALIDARG, "Default install directory is blank"); - } - - hr = BalFormatString(defaultDir, &targetDir); - BalExitOnFailure1(hr, "Failed to format '%ls'", defaultDir); - - hr = _engine->SetVariableString(L"TargetDir", targetDir); - BalExitOnFailure(hr, "Failed to set install target directory"); - } - LExit: - ReleaseStr(defaultDir); - ReleaseStr(targetDir); - return hr; - } - - void ValidateOperatingSystem() { - LOC_STRING *pLocString = nullptr; - - if (IsWindowsServer()) { - if (IsWindowsVersionOrGreater(6, 1, 1)) { - BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Target OS is Windows Server 2008 R2 or later"); - return; - } else if (IsWindowsVersionOrGreater(6, 1, 0)) { - BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Detected Windows Server 2008 R2"); - BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Service Pack 1 is required to continue installation"); - LocGetString(_wixLoc, L"#(loc.FailureWS2K8R2MissingSP1)", &pLocString); - } else if (IsWindowsVersionOrGreater(6, 0, 2)) { - BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Target OS is Windows Server 2008 SP2 or later"); - return; - } else if (IsWindowsVersionOrGreater(6, 0, 0)) { - BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Detected Windows Server 2008"); - BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Service Pack 2 is required to continue installation"); - LocGetString(_wixLoc, L"#(loc.FailureWS2K8MissingSP2)", &pLocString); - } else { - BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Detected Windows Server 2003 or earlier"); - BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Windows Server 2008 SP2 or later is required to continue installation"); - LocGetString(_wixLoc, L"#(loc.FailureWS2K3OrEarlier)", &pLocString); - } - } else { - if (IsWindows7SP1OrGreater()) { - HMODULE hKernel32 = GetModuleHandleW(L"kernel32"); - if (hKernel32 && !GetProcAddress(hKernel32, "AddDllDirectory")) { - BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Detected Windows 7 SP1 without KB2533623"); - BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "KB2533623 update is required to continue."); - /* The "MissingSP1" error also specifies updates are required */ - LocGetString(_wixLoc, L"#(loc.FailureWin7MissingSP1)", &pLocString); - } else { - BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Target OS is Windows 7 SP1 or later"); - return; - } - } else if (IsWindows7OrGreater()) { - BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Detected Windows 7 RTM"); - BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Service Pack 1 is required to continue installation"); - LocGetString(_wixLoc, L"#(loc.FailureWin7MissingSP1)", &pLocString); - } else if (IsWindowsVistaSP2OrGreater()) { - BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Target OS is Windows Vista SP2"); - return; - } else if (IsWindowsVistaOrGreater()) { - BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Detected Windows Vista RTM or SP1"); - BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Service Pack 2 is required to continue installation"); - LocGetString(_wixLoc, L"#(loc.FailureVistaMissingSP2)", &pLocString); - } else { - BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Detected Windows XP or earlier"); - BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Windows Vista SP2 or later is required to continue installation"); - LocGetString(_wixLoc, L"#(loc.FailureXPOrEarlier)", &pLocString); - } - } - - if (pLocString && pLocString->wzText) { - BalFormatString(pLocString->wzText, &_failedMessage); - } - - _hrFinal = E_WIXSTDBA_CONDITION_FAILED; - } - -public: - // - // Constructor - initialize member variables. - // - PythonBootstrapperApplication( - __in HMODULE hModule, - __in BOOL fPrereq, - __in HRESULT hrHostInitialization, - __in IBootstrapperEngine* pEngine, - __in const BOOTSTRAPPER_COMMAND* pCommand - ) : CBalBaseBootstrapperApplication(pEngine, pCommand, 3, 3000) { - _hModule = hModule; - memcpy_s(&_command, sizeof(_command), pCommand, sizeof(BOOTSTRAPPER_COMMAND)); - - LONGLONG llInstalled = 0; - HRESULT hr = BalGetNumericVariable(L"WixBundleInstalled", &llInstalled); - if (SUCCEEDED(hr) && BOOTSTRAPPER_RESUME_TYPE_REBOOT != _command.resumeType && 0 < llInstalled && BOOTSTRAPPER_ACTION_INSTALL == _command.action) { - _command.action = BOOTSTRAPPER_ACTION_MODIFY; - } else if (0 == llInstalled && (BOOTSTRAPPER_ACTION_MODIFY == _command.action || BOOTSTRAPPER_ACTION_REPAIR == _command.action)) { - _command.action = BOOTSTRAPPER_ACTION_INSTALL; - } - - _plannedAction = BOOTSTRAPPER_ACTION_UNKNOWN; - - - // When resuming from restart doing some install-like operation, try to find the package that forced the - // restart. We'll use this information during planning. - _nextPackageAfterRestart = nullptr; - - if (BOOTSTRAPPER_RESUME_TYPE_REBOOT == _command.resumeType && BOOTSTRAPPER_ACTION_UNINSTALL < _command.action) { - // Ensure the forced restart package variable is null when it is an empty string. - HRESULT hr = BalGetStringVariable(L"WixBundleForcedRestartPackage", &_nextPackageAfterRestart); - if (FAILED(hr) || !_nextPackageAfterRestart || !*_nextPackageAfterRestart) { - ReleaseNullStr(_nextPackageAfterRestart); - } - } - - _crtInstalledToken = -1; - pEngine->SetVariableNumeric(L"CRTInstalled", IsCrtInstalled() ? 1 : 0); - - _wixLoc = nullptr; - memset(&_bundle, 0, sizeof(_bundle)); - memset(&_conditions, 0, sizeof(_conditions)); - _confirmCloseMessage = nullptr; - _failedMessage = nullptr; - - _language = nullptr; - _theme = nullptr; - memset(_pageIds, 0, sizeof(_pageIds)); - _hUiThread = nullptr; - _registered = FALSE; - _hWnd = nullptr; - - _state = PYBA_STATE_INITIALIZING; - _visiblePageId = 0; - _installPage = PAGE_LOADING; - _hrFinal = hrHostInitialization; - - _downgradingOtherVersion = FALSE; - _restartResult = BOOTSTRAPPER_APPLY_RESTART_NONE; - _restartRequired = FALSE; - _allowRestart = FALSE; - - _suppressDowngradeFailure = FALSE; - _suppressRepair = FALSE; - _modifying = FALSE; - _upgrading = FALSE; - - _overridableVariables = nullptr; - _taskbarList = nullptr; - _taskbarButtonCreatedMessage = UINT_MAX; - _taskbarButtonOK = FALSE; - _showingInternalUIThisPackage = FALSE; - - _suppressPaint = FALSE; - - pEngine->AddRef(); - _engine = pEngine; - - _hBAFModule = nullptr; - _baFunction = nullptr; - } - - - // - // Destructor - release member variables. - // - ~PythonBootstrapperApplication() { - AssertSz(!::IsWindow(_hWnd), "Window should have been destroyed before destructor."); - AssertSz(!_theme, "Theme should have been released before destructor."); - - ReleaseObject(_taskbarList); - ReleaseDict(_overridableVariables); - ReleaseStr(_failedMessage); - ReleaseStr(_confirmCloseMessage); - BalConditionsUninitialize(&_conditions); - BalInfoUninitialize(&_bundle); - LocFree(_wixLoc); - - ReleaseStr(_language); - ReleaseStr(_nextPackageAfterRestart); - ReleaseNullObject(_engine); - - if (_hBAFModule) { - ::FreeLibrary(_hBAFModule); - _hBAFModule = nullptr; - } - } - -private: - HMODULE _hModule; - BOOTSTRAPPER_COMMAND _command; - IBootstrapperEngine* _engine; - BOOTSTRAPPER_ACTION _plannedAction; - - LPWSTR _nextPackageAfterRestart; - - WIX_LOCALIZATION* _wixLoc; - BAL_INFO_BUNDLE _bundle; - BAL_CONDITIONS _conditions; - LPWSTR _failedMessage; - LPWSTR _confirmCloseMessage; - - LPWSTR _language; - THEME* _theme; - DWORD _pageIds[countof(PAGE_NAMES)]; - HANDLE _hUiThread; - BOOL _registered; - HWND _hWnd; - - PYBA_STATE _state; - HRESULT _hrFinal; - DWORD _visiblePageId; - PAGE _installPage; - - BOOL _startedExecution; - DWORD _calculatedCacheProgress; - DWORD _calculatedExecuteProgress; - - BOOL _downgradingOtherVersion; - BOOTSTRAPPER_APPLY_RESTART _restartResult; - BOOL _restartRequired; - BOOL _allowRestart; - - BOOL _suppressDowngradeFailure; - BOOL _suppressRepair; - BOOL _modifying; - BOOL _upgrading; - - int _crtInstalledToken; - - STRINGDICT_HANDLE _overridableVariables; - - ITaskbarList3* _taskbarList; - UINT _taskbarButtonCreatedMessage; - BOOL _taskbarButtonOK; - BOOL _showingInternalUIThisPackage; - - BOOL _suppressPaint; - - HMODULE _hBAFModule; - IBootstrapperBAFunction* _baFunction; -}; - -// -// CreateBootstrapperApplication - creates a new IBootstrapperApplication object. -// -HRESULT CreateBootstrapperApplication( - __in HMODULE hModule, - __in BOOL fPrereq, - __in HRESULT hrHostInitialization, - __in IBootstrapperEngine* pEngine, - __in const BOOTSTRAPPER_COMMAND* pCommand, - __out IBootstrapperApplication** ppApplication - ) { - HRESULT hr = S_OK; - - if (fPrereq) { - hr = E_INVALIDARG; - ExitWithLastError(hr, "Failed to create UI thread."); - } - - PythonBootstrapperApplication* pApplication = nullptr; - - pApplication = new PythonBootstrapperApplication(hModule, fPrereq, hrHostInitialization, pEngine, pCommand); - ExitOnNull(pApplication, hr, E_OUTOFMEMORY, "Failed to create new standard bootstrapper application object."); - - *ppApplication = pApplication; - pApplication = nullptr; - -LExit: - ReleaseObject(pApplication); - return hr; -} diff --git a/third_party/python/Tools/msi/bundle/bootstrap/pch.cpp b/third_party/python/Tools/msi/bundle/bootstrap/pch.cpp deleted file mode 100644 index 1d9f38c57..000000000 --- a/third_party/python/Tools/msi/bundle/bootstrap/pch.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "pch.h" diff --git a/third_party/python/Tools/msi/bundle/bootstrap/pch.h b/third_party/python/Tools/msi/bundle/bootstrap/pch.h deleted file mode 100644 index 6a66fa5a5..000000000 --- a/third_party/python/Tools/msi/bundle/bootstrap/pch.h +++ /dev/null @@ -1,60 +0,0 @@ -//------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2004, Outercurve Foundation. -// This software is released under Microsoft Reciprocal License (MS-RL). -// The license and further copyright text can be found in the file -// LICENSE.TXT at the root directory of the distribution. -// -// -// -// Precompiled header for standard bootstrapper application. -// -//------------------------------------------------------------------------------------------------- - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "dutil.h" -#include "memutil.h" -#include "dictutil.h" -#include "dirutil.h" -#include "fileutil.h" -#include "locutil.h" -#include "logutil.h" -#include "pathutil.h" -#include "resrutil.h" -#include "shelutil.h" -#include "strutil.h" -#include "thmutil.h" -#include "uriutil.h" -#include "xmlutil.h" - -#include "IBootstrapperEngine.h" -#include "IBootstrapperApplication.h" - -#include "BalBaseBootstrapperApplication.h" -#include "balinfo.h" -#include "balcondition.h" - -HRESULT CreateBootstrapperApplication( - __in HMODULE hModule, - __in BOOL fPrereq, - __in HRESULT hrHostInitialization, - __in IBootstrapperEngine* pEngine, - __in const BOOTSTRAPPER_COMMAND* pCommand, - __out IBootstrapperApplication** ppApplication -); - -#include "IBootstrapperBAFunction.h" - diff --git a/third_party/python/Tools/msi/bundle/bootstrap/pythonba.cpp b/third_party/python/Tools/msi/bundle/bootstrap/pythonba.cpp deleted file mode 100644 index 0ce45ad31..000000000 --- a/third_party/python/Tools/msi/bundle/bootstrap/pythonba.cpp +++ /dev/null @@ -1,76 +0,0 @@ -//------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2004, Outercurve Foundation. -// This software is released under Microsoft Reciprocal License (MS-RL). -// The license and further copyright text can be found in the file -// LICENSE.TXT at the root directory of the distribution. -// -// -// -// Setup chainer/bootstrapper standard UI for WiX toolset. -// -//------------------------------------------------------------------------------------------------- - -#include "pch.h" - -static HINSTANCE vhInstance = NULL; - -extern "C" BOOL WINAPI DllMain( - IN HINSTANCE hInstance, - IN DWORD dwReason, - IN LPVOID /* pvReserved */ - ) -{ - switch(dwReason) - { - case DLL_PROCESS_ATTACH: - ::DisableThreadLibraryCalls(hInstance); - vhInstance = hInstance; - break; - - case DLL_PROCESS_DETACH: - vhInstance = NULL; - break; - } - - return TRUE; -} - - -extern "C" HRESULT WINAPI BootstrapperApplicationCreate( - __in IBootstrapperEngine* pEngine, - __in const BOOTSTRAPPER_COMMAND* pCommand, - __out IBootstrapperApplication** ppApplication - ) -{ - HRESULT hr = S_OK; - - BalInitialize(pEngine); - - hr = CreateBootstrapperApplication(vhInstance, FALSE, S_OK, pEngine, pCommand, ppApplication); - BalExitOnFailure(hr, "Failed to create bootstrapper application interface."); - -LExit: - return hr; -} - - -extern "C" void WINAPI BootstrapperApplicationDestroy() -{ - BalUninitialize(); -} - - -extern "C" HRESULT WINAPI MbaPrereqBootstrapperApplicationCreate( - __in HRESULT hrHostInitialization, - __in IBootstrapperEngine* pEngine, - __in const BOOTSTRAPPER_COMMAND* pCommand, - __out IBootstrapperApplication** ppApplication - ) -{ - return E_NOTIMPL; -} - - -extern "C" void WINAPI MbaPrereqBootstrapperApplicationDestroy() -{ } diff --git a/third_party/python/Tools/msi/bundle/bootstrap/pythonba.def b/third_party/python/Tools/msi/bundle/bootstrap/pythonba.def deleted file mode 100644 index 29b3fa50d..000000000 --- a/third_party/python/Tools/msi/bundle/bootstrap/pythonba.def +++ /dev/null @@ -1,18 +0,0 @@ -;------------------------------------------------------------------------------------------------- -; -; Copyright (c) 2004, Outercurve Foundation. -; This software is released under Microsoft Reciprocal License (MS-RL). -; The license and further copyright text can be found in the file -; LICENSE.TXT at the root directory of the distribution. -; -; -; -; WiX Standard Bootstrapper Application DLL entry points. -; -;------------------------------------------------------------------------------------------------- - -EXPORTS - BootstrapperApplicationCreate - BootstrapperApplicationDestroy - MbaPrereqBootstrapperApplicationCreate - MbaPrereqBootstrapperApplicationDestroy diff --git a/third_party/python/Tools/msi/bundle/bootstrap/pythonba.sln b/third_party/python/Tools/msi/bundle/bootstrap/pythonba.sln deleted file mode 100644 index bf43fed90..000000000 --- a/third_party/python/Tools/msi/bundle/bootstrap/pythonba.sln +++ /dev/null @@ -1,22 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.30501.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pythonba", "pythonba.vcxproj", "{7A09B132-B3EE-499B-A700-A4B2157FEA3D}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {7A09B132-B3EE-499B-A700-A4B2157FEA3D}.Debug|Win32.ActiveCfg = Debug|Win32 - {7A09B132-B3EE-499B-A700-A4B2157FEA3D}.Debug|Win32.Build.0 = Debug|Win32 - {7A09B132-B3EE-499B-A700-A4B2157FEA3D}.Release|Win32.ActiveCfg = Release|Win32 - {7A09B132-B3EE-499B-A700-A4B2157FEA3D}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/third_party/python/Tools/msi/bundle/bootstrap/pythonba.vcxproj b/third_party/python/Tools/msi/bundle/bootstrap/pythonba.vcxproj deleted file mode 100644 index 75aad442a..000000000 --- a/third_party/python/Tools/msi/bundle/bootstrap/pythonba.vcxproj +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - Debug - Win32 - - - Release - Win32 - - - - Release - Win32 - v140 - v120 - {7A09B132-B3EE-499B-A700-A4B2157FEA3D} - PythonBA - - - - - DynamicLibrary - Unicode - $(PySourcePath)PCbuild\obj\ - $(Py_IntDir)\$(MajorVersionNumber)$(MinorVersionNumber)$(ArchName)_$(Configuration)\msi_$(ProjectName)\ - $(IntDir.Replace(`\\`, `\`)) - $(IntDir) - - - - - _CRT_STDIO_LEGACY_WIDE_SPECIFIERS=1;%(PreprocessorDefinitions) - $(WixInstallPath)sdk\inc - Use - pch.h - MultiThreaded - - - comctl32.lib;gdiplus.lib;msimg32.lib;shlwapi.lib;wininet.lib;dutil.lib;balutil.lib;version.lib;uxtheme.lib;%(AdditionalDependencies) - $(WixInstallPath)sdk\vs2015\lib\x86 - $(WixInstallPath)sdk\vs2013\lib\x86 - pythonba.def - true - - - - - - - Create - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/bundle/bootstrap/resource.h b/third_party/python/Tools/msi/bundle/bootstrap/resource.h deleted file mode 100644 index 53c03c319..000000000 --- a/third_party/python/Tools/msi/bundle/bootstrap/resource.h +++ /dev/null @@ -1,25 +0,0 @@ -//------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2004, Outercurve Foundation. -// This software is released under Microsoft Reciprocal License (MS-RL). -// The license and further copyright text can be found in the file -// LICENSE.TXT at the root directory of the distribution. -// -//------------------------------------------------------------------------------------------------- - -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// -#define IDC_STATIC -1 - - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 102 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1003 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/third_party/python/Tools/msi/bundle/bundle.targets b/third_party/python/Tools/msi/bundle/bundle.targets deleted file mode 100644 index e0dae2120..000000000 --- a/third_party/python/Tools/msi/bundle/bundle.targets +++ /dev/null @@ -1,106 +0,0 @@ - - - - 2.0 - Bundle - - Release - 1132;1135;1140 - $(OutputName)-$(PythonVersion) - $(OutputName)-$(MajorVersionNumber).$(MinorVersionNumber).$(MicroVersionNumber).$(RevisionNumber) - $(OutputName)-amd64 - $(OutputName)-$(OutputSuffix) - $(OutputName)-d - $(OutputName) - - $(OutputPath)en-us\ - $(OutputPath) - - - $(DownloadUrlBase.TrimEnd(`/`))/{version}/{arch}{releasename}/{msi} - $(DefineConstants);DownloadUrl=$(DownloadUrl.Replace(`{version}`, `$(MajorVersionNumber).$(MinorVersionNumber).$(MicroVersionNumber)`).Replace(`{arch}`, `$(ArchName)`).Replace(`{releasename}`, `$(ReleaseLevelName)`).Replace(`{msi}`, `{2}`)) - $(DefineConstants);DownloadUrl={2} - - - - - WixUtilExtension - WixUtilExtension - - - WixDependencyExtension - WixDependencyExtension - - - WixBalExtension - WixBalExtension - - - - - - - - - - - - - - - - - - - - - - - - BuildForRelease=$(BuildForRelease) - - - - - - - - - - - - - - - - - Build - - - - - Rebuild - - - - - - - - - - - - - - - - $(DefineConstants);BootstrapApp=$(BootstrapAppPath) - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/bundle/bundle.wxl b/third_party/python/Tools/msi/bundle/bundle.wxl deleted file mode 100644 index d7a65c48d..000000000 --- a/third_party/python/Tools/msi/bundle/bundle.wxl +++ /dev/null @@ -1,7 +0,0 @@ - - - C Runtime Update (KB2999226) - Precompiling standard library - Precompiling standard library (-O) - Precompiling standard library (-OO) - diff --git a/third_party/python/Tools/msi/bundle/bundle.wxs b/third_party/python/Tools/msi/bundle/bundle.wxs deleted file mode 100644 index f6cff6fc3..000000000 --- a/third_party/python/Tools/msi/bundle/bundle.wxs +++ /dev/null @@ -1,112 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/bundle/full.wixproj b/third_party/python/Tools/msi/bundle/full.wixproj deleted file mode 100644 index bdbdd8e17..000000000 --- a/third_party/python/Tools/msi/bundle/full.wixproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - {3E204ADD-238D-4D10-852C-4F859325C839} - python - full - - - - - - - $(DefineConstants); - CompressMSI=yes; - CompressPDB=yes; - CompressMSI_D=yes; - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/bundle/packagegroups/core.wxs b/third_party/python/Tools/msi/bundle/packagegroups/core.wxs deleted file mode 100644 index eb3d0b773..000000000 --- a/third_party/python/Tools/msi/bundle/packagegroups/core.wxs +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/bundle/packagegroups/crt.wxs b/third_party/python/Tools/msi/bundle/packagegroups/crt.wxs deleted file mode 100644 index dc4047590..000000000 --- a/third_party/python/Tools/msi/bundle/packagegroups/crt.wxs +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/bundle/packagegroups/dev.wxs b/third_party/python/Tools/msi/bundle/packagegroups/dev.wxs deleted file mode 100644 index 4284dba2c..000000000 --- a/third_party/python/Tools/msi/bundle/packagegroups/dev.wxs +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/bundle/packagegroups/doc.wxs b/third_party/python/Tools/msi/bundle/packagegroups/doc.wxs deleted file mode 100644 index 6639ff5c2..000000000 --- a/third_party/python/Tools/msi/bundle/packagegroups/doc.wxs +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/bundle/packagegroups/exe.wxs b/third_party/python/Tools/msi/bundle/packagegroups/exe.wxs deleted file mode 100644 index 79464c4ac..000000000 --- a/third_party/python/Tools/msi/bundle/packagegroups/exe.wxs +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/bundle/packagegroups/launcher.wxs b/third_party/python/Tools/msi/bundle/packagegroups/launcher.wxs deleted file mode 100644 index 7dae8ca7a..000000000 --- a/third_party/python/Tools/msi/bundle/packagegroups/launcher.wxs +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/bundle/packagegroups/lib.wxs b/third_party/python/Tools/msi/bundle/packagegroups/lib.wxs deleted file mode 100644 index 0b3fbc00c..000000000 --- a/third_party/python/Tools/msi/bundle/packagegroups/lib.wxs +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/bundle/packagegroups/packageinstall.wxs b/third_party/python/Tools/msi/bundle/packagegroups/packageinstall.wxs deleted file mode 100644 index e5e7d4d1a..000000000 --- a/third_party/python/Tools/msi/bundle/packagegroups/packageinstall.wxs +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/bundle/packagegroups/pip.wxs b/third_party/python/Tools/msi/bundle/packagegroups/pip.wxs deleted file mode 100644 index 201a6c445..000000000 --- a/third_party/python/Tools/msi/bundle/packagegroups/pip.wxs +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/bundle/packagegroups/postinstall.wxs b/third_party/python/Tools/msi/bundle/packagegroups/postinstall.wxs deleted file mode 100644 index 11ab67390..000000000 --- a/third_party/python/Tools/msi/bundle/packagegroups/postinstall.wxs +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/bundle/packagegroups/tcltk.wxs b/third_party/python/Tools/msi/bundle/packagegroups/tcltk.wxs deleted file mode 100644 index 0d029a90c..000000000 --- a/third_party/python/Tools/msi/bundle/packagegroups/tcltk.wxs +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/bundle/packagegroups/test.wxs b/third_party/python/Tools/msi/bundle/packagegroups/test.wxs deleted file mode 100644 index 32acaef64..000000000 --- a/third_party/python/Tools/msi/bundle/packagegroups/test.wxs +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/bundle/packagegroups/tools.wxs b/third_party/python/Tools/msi/bundle/packagegroups/tools.wxs deleted file mode 100644 index 1d9ab19f3..000000000 --- a/third_party/python/Tools/msi/bundle/packagegroups/tools.wxs +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/bundle/releaselocal.wixproj b/third_party/python/Tools/msi/bundle/releaselocal.wixproj deleted file mode 100644 index 0c3dee7ad..000000000 --- a/third_party/python/Tools/msi/bundle/releaselocal.wixproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - {FCD43AC9-969F-49A1-8AC5-EDC27599D1EB} - python - - - - - - - - $(DefineConstants); - CompressMSI=yes; - CompressPDB=no; - CompressMSI_D=no - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/bundle/releaseweb.wixproj b/third_party/python/Tools/msi/bundle/releaseweb.wixproj deleted file mode 100644 index 350c73587..000000000 --- a/third_party/python/Tools/msi/bundle/releaseweb.wixproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - {71CDE213-CB39-4BD9-B89D-BBB878689144} - python - webinstall - - - - - - - $(DefineConstants); - CompressMSI=no; - CompressPDB=no; - CompressMSI_D=no - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/bundle/snapshot.wixproj b/third_party/python/Tools/msi/bundle/snapshot.wixproj deleted file mode 100644 index cc4504329..000000000 --- a/third_party/python/Tools/msi/bundle/snapshot.wixproj +++ /dev/null @@ -1,26 +0,0 @@ - - - - {8A4A1162-4BF9-4FF6-9A98-315F01E44932} - python - - - - - - - - $(DefineConstants);CompressMSI=no; - - - $(DefineConstants);CompressMSI=yes; - - - $(DefineConstants); - CompressPDB=no; - CompressMSI_D=no; - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/common.wxs b/third_party/python/Tools/msi/common.wxs deleted file mode 100644 index 398d94a24..000000000 --- a/third_party/python/Tools/msi/common.wxs +++ /dev/null @@ -1,122 +0,0 @@ - - - - - - - - - - - - - OPTIONALFEATURESREGISTRYKEY - - - - - - - - - - - - - - - - - - - - - - Installed OR NOT MISSING_CORE - - - - Installed OR NOT DOWNGRADE - Installed OR TARGETDIR OR Suppress_TARGETDIR_Check - - - UPGRADE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/common_en-US.wxl_template b/third_party/python/Tools/msi/common_en-US.wxl_template deleted file mode 100644 index c95c271c2..000000000 --- a/third_party/python/Tools/msi/common_en-US.wxl_template +++ /dev/null @@ -1,18 +0,0 @@ - - - 1033 - en-us - Python {{ShortVersion}} - Python {{LongVersion}} ({{Bitness}}) - Python {{LongVersion}} !(loc.Descriptor) ({{Bitness}}) - Python {{LongVersion}} !(loc.Descriptor) ({{Bitness}}) - Python {{LongVersion}} !(loc.Descriptor) ({{Bitness}} symbols) - Python {{LongVersion}} !(loc.Descriptor) ({{Bitness}} symbols) - Python {{LongVersion}} !(loc.Descriptor) ({{Bitness}} debug) - Python {{LongVersion}} !(loc.Descriptor) ({{Bitness}} debug) - Python Software Foundation - A newer version of !(loc.ProductName) is already installed. - An incorrect version of a prerequisite package is installed. Please uninstall any other versions of !(loc.ProductName) and try installing this again. - The TARGETDIR variable must be provided when invoking this installer. - http://www.python.org/ - diff --git a/third_party/python/Tools/msi/csv_to_wxs.py b/third_party/python/Tools/msi/csv_to_wxs.py deleted file mode 100644 index 235c8f8b0..000000000 --- a/third_party/python/Tools/msi/csv_to_wxs.py +++ /dev/null @@ -1,127 +0,0 @@ -''' -Processes a CSV file containing a list of files into a WXS file with -components for each listed file. - -The CSV columns are: - source of file, target for file, group name - -Usage:: - py txt_to_wxs.py [path to file list .csv] [path to destination .wxs] - -This is necessary to handle structures where some directories only -contain other directories. MSBuild is not able to generate the -Directory entries in the WXS file correctly, as it operates on files. -Python, however, can easily fill in the gap. -''' - -__author__ = "Steve Dower " - -import csv -import re -import sys - -from collections import defaultdict -from itertools import chain, zip_longest -from pathlib import PureWindowsPath -from uuid import uuid1 - -ID_CHAR_SUBS = { - '-': '_', - '+': '_P', -} - -def make_id(path): - return re.sub( - r'[^A-Za-z0-9_.]', - lambda m: ID_CHAR_SUBS.get(m.group(0), '_'), - str(path).rstrip('/\\'), - flags=re.I - ) - -DIRECTORIES = set() - -def main(file_source, install_target): - with open(file_source, 'r', newline='') as f: - files = list(csv.reader(f)) - - assert len(files) == len(set(make_id(f[1]) for f in files)), "Duplicate file IDs exist" - - directories = defaultdict(set) - cache_directories = defaultdict(set) - groups = defaultdict(list) - for source, target, group, disk_id, condition in files: - target = PureWindowsPath(target) - groups[group].append((source, target, disk_id, condition)) - - if target.suffix.lower() in {".py", ".pyw"}: - cache_directories[group].add(target.parent) - - for dirname in target.parents: - parent = make_id(dirname.parent) - if parent and parent != '.': - directories[parent].add(dirname.name) - - lines = [ - '', - ' ', - ] - for dir_parent in sorted(directories): - lines.append(' '.format(dir_parent)) - for dir_name in sorted(directories[dir_parent]): - lines.append(' '.format(dir_parent, make_id(dir_name), dir_name)) - lines.append(' ') - for dir_parent in (make_id(d) for group in cache_directories.values() for d in group): - lines.append(' '.format(dir_parent)) - lines.append(' '.format(dir_parent)) - lines.append(' ') - lines.append(' ') - - for group in sorted(groups): - lines.extend([ - ' ', - ' '.format(group), - ]) - for source, target, disk_id, condition in groups[group]: - lines.append(' '.format(make_id(target), make_id(target.parent))) - if condition: - lines.append(' {}'.format(condition)) - - if disk_id: - lines.append(' '.format(make_id(target), target.name, source, disk_id)) - else: - lines.append(' '.format(make_id(target), target.name, source)) - lines.append(' ') - - create_folders = {make_id(p) + "___pycache__" for p in cache_directories[group]} - remove_folders = {make_id(p2) for p1 in cache_directories[group] for p2 in chain((p1,), p1.parents)} - create_folders.discard(".") - remove_folders.discard(".") - if create_folders or remove_folders: - lines.append(' '.format(group, uuid1())) - lines.extend(' '.format(p) for p in create_folders) - lines.extend(' '.format(p) for p in create_folders) - lines.extend(' '.format(p) for p in create_folders | remove_folders) - lines.append(' ') - - lines.extend([ - ' ', - ' ', - ]) - lines.append('') - - # Check if the file matches. If so, we don't want to touch it so - # that we can skip rebuilding. - try: - with open(install_target, 'r') as f: - if all(x.rstrip('\r\n') == y for x, y in zip_longest(f, lines)): - print('File is up to date') - return - except IOError: - pass - - with open(install_target, 'w') as f: - f.writelines(line + '\n' for line in lines) - print('Wrote {} lines to {}'.format(len(lines), install_target)) - -if __name__ == '__main__': - main(sys.argv[1], sys.argv[2]) diff --git a/third_party/python/Tools/msi/dev/dev.wixproj b/third_party/python/Tools/msi/dev/dev.wixproj deleted file mode 100644 index 682b66031..000000000 --- a/third_party/python/Tools/msi/dev/dev.wixproj +++ /dev/null @@ -1,49 +0,0 @@ - - - - {5F23F608-D74B-4259-A0CE-8DC65CC7FE53} - 2.0 - dev - Package - - - - - $(DefineConstants); - IncludeMinGWLib=1; - - - - - - - - - - - - $(PySourcePath) - !(bindpath.src) - $(PySourcePath) - - dev_include - - - - - - - <_DllToolOpts>-m i386 --as-flags=--32 - <_DllToolOpts Condition="$(Platform) == 'x64'">-m i386:x86-64 - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/dev/dev.wxs b/third_party/python/Tools/msi/dev/dev.wxs deleted file mode 100644 index a09e139c4..000000000 --- a/third_party/python/Tools/msi/dev/dev.wxs +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/dev/dev_d.wixproj b/third_party/python/Tools/msi/dev/dev_d.wixproj deleted file mode 100644 index b3b05326d..000000000 --- a/third_party/python/Tools/msi/dev/dev_d.wixproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - {C11B4945-76BD-4137-B2E3-649460117A77} - 2.0 - dev_d - Package - - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/dev/dev_d.wxs b/third_party/python/Tools/msi/dev/dev_d.wxs deleted file mode 100644 index c467aac57..000000000 --- a/third_party/python/Tools/msi/dev/dev_d.wxs +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/dev/dev_en-US.wxl b/third_party/python/Tools/msi/dev/dev_en-US.wxl deleted file mode 100644 index 2546e13e4..000000000 --- a/third_party/python/Tools/msi/dev/dev_en-US.wxl +++ /dev/null @@ -1,5 +0,0 @@ - - - Development Libraries - dev - diff --git a/third_party/python/Tools/msi/dev/dev_files.wxs b/third_party/python/Tools/msi/dev/dev_files.wxs deleted file mode 100644 index 9654d2e3e..000000000 --- a/third_party/python/Tools/msi/dev/dev_files.wxs +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/distutils.command.bdist_wininst.py b/third_party/python/Tools/msi/distutils.command.bdist_wininst.py deleted file mode 100644 index 548fdd0cc..000000000 --- a/third_party/python/Tools/msi/distutils.command.bdist_wininst.py +++ /dev/null @@ -1,23 +0,0 @@ -"""distutils.command.bdist_wininst - -Suppresses the 'bdist_wininst' command, while still allowing -setuptools to import it without breaking.""" - -from distutils.core import Command -from distutils.errors import DistutilsPlatformError - -class bdist_wininst(Command): - description = "create an executable installer for MS Windows" - - # Marker for tests that we have the unsupported bdist_wininst - _unsupported = True - - def initialize_options(self): - pass - - def finalize_options(self): - pass - - def run(self): - raise DistutilsPlatformError("bdist_wininst is not supported " - "in this Python distribution") diff --git a/third_party/python/Tools/msi/doc/doc.wixproj b/third_party/python/Tools/msi/doc/doc.wixproj deleted file mode 100644 index ea9929acd..000000000 --- a/third_party/python/Tools/msi/doc/doc.wixproj +++ /dev/null @@ -1,30 +0,0 @@ - - - - {0D62A2BB-5F71-4447-8C8C-9708407B3674} - 2.0 - doc - Package - - ICE43 - - - - python$(MajorVersionNumber)$(MinorVersionNumber)$(MicroVersionNumber)$(ReleaseLevelName).chm - false - true - - - $(DefineConstants);DocFilename=$(DocFilename); - - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/doc/doc.wxs b/third_party/python/Tools/msi/doc/doc.wxs deleted file mode 100644 index 306fb11dc..000000000 --- a/third_party/python/Tools/msi/doc/doc.wxs +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - 1 - - - - - - - - - - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/doc/doc_en-US.wxl_template b/third_party/python/Tools/msi/doc/doc_en-US.wxl_template deleted file mode 100644 index 809556e29..000000000 --- a/third_party/python/Tools/msi/doc/doc_en-US.wxl_template +++ /dev/null @@ -1,7 +0,0 @@ - - - doc - Documentation - Python {{ShortVersion}} Manuals ({{Bitness}}) - View the !(loc.ProductName) documentation. - diff --git a/third_party/python/Tools/msi/doc/doc_files.wxs b/third_party/python/Tools/msi/doc/doc_files.wxs deleted file mode 100644 index fe09afe4d..000000000 --- a/third_party/python/Tools/msi/doc/doc_files.wxs +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/doc/doc_no_files.wxs b/third_party/python/Tools/msi/doc/doc_no_files.wxs deleted file mode 100644 index 7ab7c2690..000000000 --- a/third_party/python/Tools/msi/doc/doc_no_files.wxs +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/exe/crtlicense.txt b/third_party/python/Tools/msi/exe/crtlicense.txt deleted file mode 100644 index f86841f26..000000000 --- a/third_party/python/Tools/msi/exe/crtlicense.txt +++ /dev/null @@ -1,41 +0,0 @@ - - -Additional Conditions for this Windows binary build ---------------------------------------------------- - -This program is linked with and uses Microsoft Distributable Code, -copyrighted by Microsoft Corporation. The Microsoft Distributable Code -is embedded in each .exe, .dll and .pyd file as a result of running -the code through a linker. - -If you further distribute programs that include the Microsoft -Distributable Code, you must comply with the restrictions on -distribution specified by Microsoft. In particular, you must require -distributors and external end users to agree to terms that protect the -Microsoft Distributable Code at least as much as Microsoft's own -requirements for the Distributable Code. See Microsoft's documentation -(included in its developer tools and on its website at microsoft.com) -for specific details. - -Redistribution of the Windows binary build of the Python interpreter -complies with this agreement, provided that you do not: - -- alter any copyright, trademark or patent notice in Microsoft's -Distributable Code; - -- use Microsoft's trademarks in your programs' names or in a way that -suggests your programs come from or are endorsed by Microsoft; - -- distribute Microsoft's Distributable Code to run on a platform other -than Microsoft operating systems, run-time technologies or application -platforms; or - -- include Microsoft Distributable Code in malicious, deceptive or -unlawful programs. - -These restrictions apply only to the Microsoft Distributable Code as -defined above, not to Python itself or any programs running on the -Python interpreter. The redistribution of the Python interpreter and -libraries is governed by the Python Software License included with this -file, or by other licenses as marked. - diff --git a/third_party/python/Tools/msi/exe/exe.wixproj b/third_party/python/Tools/msi/exe/exe.wixproj deleted file mode 100644 index 16ef6ac5b..000000000 --- a/third_party/python/Tools/msi/exe/exe.wixproj +++ /dev/null @@ -1,66 +0,0 @@ - - - - {6BD53305-B03E-49DC-85FB-5551B8CCC843} - 2.0 - exe - Package - - - - ICE43 - - - - - - - - - - - - - - - - <_LicenseFiles Include="@(LicenseFiles)"> - $([System.IO.File]::ReadAllText(%(FullPath))) - - - - - - - - - - - - - - - - - - - - - - @(HostPython) - $(HostPython.Remove($(HostPython.IndexOf(';')))) - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/exe/exe.wxs b/third_party/python/Tools/msi/exe/exe.wxs deleted file mode 100644 index 03d43c603..000000000 --- a/third_party/python/Tools/msi/exe/exe.wxs +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/exe/exe_d.wixproj b/third_party/python/Tools/msi/exe/exe_d.wixproj deleted file mode 100644 index cf085bed4..000000000 --- a/third_party/python/Tools/msi/exe/exe_d.wixproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - {B1CA739C-8DB0-403B-9010-D79507507CE9} - 2.0 - exe_d - Package - - - - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/exe/exe_d.wxs b/third_party/python/Tools/msi/exe/exe_d.wxs deleted file mode 100644 index eedb6bb64..000000000 --- a/third_party/python/Tools/msi/exe/exe_d.wxs +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/exe/exe_en-US.wxl_template b/third_party/python/Tools/msi/exe/exe_en-US.wxl_template deleted file mode 100644 index 1f9e29039..000000000 --- a/third_party/python/Tools/msi/exe/exe_en-US.wxl_template +++ /dev/null @@ -1,8 +0,0 @@ - - - Executables - executable - Python {{ShortVersion}} ({{Bitness}}) - Launches the !(loc.ProductName) interpreter. - http://www.python.org/ - diff --git a/third_party/python/Tools/msi/exe/exe_files.wxs b/third_party/python/Tools/msi/exe/exe_files.wxs deleted file mode 100644 index 394b4de47..000000000 --- a/third_party/python/Tools/msi/exe/exe_files.wxs +++ /dev/null @@ -1,79 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/exe/exe_pdb.wixproj b/third_party/python/Tools/msi/exe/exe_pdb.wixproj deleted file mode 100644 index bf1213e9d..000000000 --- a/third_party/python/Tools/msi/exe/exe_pdb.wixproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - {4A1F7045-8EE2-4276-ABB8-5E0C40E5F38B} - 2.0 - exe_pdb - Package - - - - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/exe/exe_pdb.wxs b/third_party/python/Tools/msi/exe/exe_pdb.wxs deleted file mode 100644 index f25094f82..000000000 --- a/third_party/python/Tools/msi/exe/exe_pdb.wxs +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/exe/exe_reg.wxs b/third_party/python/Tools/msi/exe/exe_reg.wxs deleted file mode 100644 index 4443c2155..000000000 --- a/third_party/python/Tools/msi/exe/exe_reg.wxs +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/generate_md5.py b/third_party/python/Tools/msi/generate_md5.py deleted file mode 100644 index 9e4c14731..000000000 --- a/third_party/python/Tools/msi/generate_md5.py +++ /dev/null @@ -1,27 +0,0 @@ -import hashlib -import os -import sys - -def main(): - filenames, hashes, sizes = [], [], [] - - for file in sys.argv[1:]: - if not os.path.isfile(file): - continue - - with open(file, 'rb') as f: - data = f.read() - md5 = hashlib.md5() - md5.update(data) - filenames.append(os.path.split(file)[1]) - hashes.append(md5.hexdigest()) - sizes.append(str(len(data))) - - print('{:40s} {:<32s} {:<9s}'.format('File', 'MD5', 'Size')) - for f, h, s in zip(filenames, hashes, sizes): - print('{:40s} {:>32s} {:>9s}'.format(f, h, s)) - - - -if __name__ == "__main__": - sys.exit(int(main() or 0)) diff --git a/third_party/python/Tools/msi/get_externals.bat b/third_party/python/Tools/msi/get_externals.bat deleted file mode 100644 index 913512a77..000000000 --- a/third_party/python/Tools/msi/get_externals.bat +++ /dev/null @@ -1,91 +0,0 @@ -@echo off -setlocal -rem Simple script to fetch source for external libraries - -set HERE=%~dp0 -if "%PCBUILD%"=="" (set PCBUILD=%HERE%..\..\PCbuild\) -if "%EXTERNALS_DIR%"=="" (set EXTERNALS_DIR=%HERE%..\..\externals\windows-installer) -if "%NUGET%"=="" (set NUGET=%EXTERNALS_DIR%\..\nuget.exe) -if "%NUGET_URL%"=="" (set NUGET_URL=https://aka.ms/nugetclidl) - -set DO_FETCH=true -set DO_CLEAN=false - -:CheckOpts -if "%~1"=="--python" (set PYTHON=%2) & shift & shift & goto CheckOpts -if "%~1"=="--organization" (set ORG=%2) & shift & shift & goto CheckOpts -if "%~1"=="-c" (set DO_CLEAN=true) & shift & goto CheckOpts -if "%~1"=="--clean" (set DO_CLEAN=true) & shift & goto CheckOpts -if "%~1"=="--clean-only" (set DO_FETCH=false) & goto clean -if "x%~1" NEQ "x" goto usage - -if "%DO_CLEAN%"=="false" goto fetch -:clean -echo.Cleaning up external libraries. -if exist "%EXTERNALS_DIR%" ( - rem Sometimes this fails the first time; try it twice - rmdir /s /q "%EXTERNALS_DIR%" || rmdir /s /q "%EXTERNALS_DIR%" -) - -if "%DO_FETCH%"=="false" goto end -:fetch - -if "%ORG%"=="" (set ORG=python) - -call "%PCBUILD%\find_python.bat" "%PYTHON%" - -echo.Fetching external libraries... - -set libraries= - -for %%e in (%libraries%) do ( - if exist "%EXTERNALS_DIR%\%%e" ( - echo.%%e already exists, skipping. - ) else ( - echo.Fetching %%e... - %PYTHON% "%PCBUILD%get_external.py" -e "%EXTERNALS_DIR%" -O %ORG% %%e - ) -) - -echo.Fetching external tools... - -set binaries= -rem We always use whatever's latest in the repo for these -set binaries=%binaries% binutils -set binaries=%binaries% gpg -set binaries=%binaries% htmlhelp -set binaries=%binaries% nuget -set binaries=%binaries% redist -set binaries=%binaries% wix - -for %%b in (%binaries%) do ( - if exist "%EXTERNALS_DIR%\%%b" ( - echo.%%b already exists, skipping. - ) else ( - echo.Fetching %%b... - %PYTHON% "%PCBUILD%get_external.py" -e "%EXTERNALS_DIR%" -b -O %ORG% %%b - ) -) - -echo Finished. -goto end - -:usage -echo.Valid options: -c, --clean, --clean-only, --organization, --python, -echo.--no-tkinter, --no-openssl -echo. -echo.Pull all sources and binaries necessary for compiling optional extension -echo.modules that rely on external libraries. -echo. -echo.The --organization option determines which github organization to download -echo.from, the --python option determines which Python 3.6+ interpreter to use -echo.with PCbuild\get_external.py. -echo. -echo.Use the -c or --clean option to remove the entire externals directory. -echo. -echo.Use the --clean-only option to do the same cleaning, without pulling in -echo.anything new. -echo. -exit /b -1 - -:end diff --git a/third_party/python/Tools/msi/launcher/launcher.wixproj b/third_party/python/Tools/msi/launcher/launcher.wixproj deleted file mode 100644 index 8935ce88a..000000000 --- a/third_party/python/Tools/msi/launcher/launcher.wixproj +++ /dev/null @@ -1,36 +0,0 @@ - - - - {921CF0E6-AEBC-4376-BA1D-CD46EBFE6DA5} - 2.0 - launcher - Package - UpgradeCode=1B68A0EC-4DD3-5134-840E-73854B0863F1;SuppressUpgradeTable=1;$(DefineConstants) - true - ICE80 - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/launcher/launcher.wxs b/third_party/python/Tools/msi/launcher/launcher.wxs deleted file mode 100644 index 7de131a3e..000000000 --- a/third_party/python/Tools/msi/launcher/launcher.wxs +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - NOT Installed AND NOT ALLUSERS=1 - NOT Installed AND ALLUSERS=1 - - UPGRADE or REMOVE_350_LAUNCHER or REMOVE_360A1_LAUNCHER - - - - - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/launcher/launcher_en-US.wxl b/third_party/python/Tools/msi/launcher/launcher_en-US.wxl deleted file mode 100644 index a7e3827c5..000000000 --- a/third_party/python/Tools/msi/launcher/launcher_en-US.wxl +++ /dev/null @@ -1,17 +0,0 @@ - - - 1033 - en-us - Python Launcher - Python Launcher - Python Launcher - Python Software Foundation - A newer version of the Python launcher is already installed. - The TARGETDIR variable must be provided when invoking this installer. - Python File - Python File (no console) - Compiled Python File - Python Extension Module - Python Zip Application File - Python Zip Application File (no console) - diff --git a/third_party/python/Tools/msi/launcher/launcher_files.wxs b/third_party/python/Tools/msi/launcher/launcher_files.wxs deleted file mode 100644 index 5b79d76bd..000000000 --- a/third_party/python/Tools/msi/launcher/launcher_files.wxs +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - NOT ALLUSERS=1 - - - - - - ALLUSERS=1 - - - - - VersionNT64 - - - - - - NOT VersionNT64 - - - - - - - diff --git a/third_party/python/Tools/msi/launcher/launcher_reg.wxs b/third_party/python/Tools/msi/launcher/launcher_reg.wxs deleted file mode 100644 index dace97ee5..000000000 --- a/third_party/python/Tools/msi/launcher/launcher_reg.wxs +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/lib/lib.wixproj b/third_party/python/Tools/msi/lib/lib.wixproj deleted file mode 100644 index 26311ea32..000000000 --- a/third_party/python/Tools/msi/lib/lib.wixproj +++ /dev/null @@ -1,35 +0,0 @@ - - - - {11367E76-3337-4602-8F1E-77DB4F370D7E} - 2.0 - lib - Package - - - - - - - - - - - - - $(PySourcePath)Lib - !(bindpath.src)Lib\ - $(PySourcePath)Lib - Lib\ - lib_py - true - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/lib/lib.wxs b/third_party/python/Tools/msi/lib/lib.wxs deleted file mode 100644 index 2a3b9ecfe..000000000 --- a/third_party/python/Tools/msi/lib/lib.wxs +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/lib/lib_d.wixproj b/third_party/python/Tools/msi/lib/lib_d.wixproj deleted file mode 100644 index 587a82c19..000000000 --- a/third_party/python/Tools/msi/lib/lib_d.wixproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - {6C443CD3-8258-4335-BA03-49DA9C34CE4D} - 2.0 - lib_d - Package - - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/lib/lib_d.wxs b/third_party/python/Tools/msi/lib/lib_d.wxs deleted file mode 100644 index 8a8a530d4..000000000 --- a/third_party/python/Tools/msi/lib/lib_d.wxs +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/lib/lib_en-US.wxl b/third_party/python/Tools/msi/lib/lib_en-US.wxl deleted file mode 100644 index 305bcc73a..000000000 --- a/third_party/python/Tools/msi/lib/lib_en-US.wxl +++ /dev/null @@ -1,5 +0,0 @@ - - - Standard Library - lib - diff --git a/third_party/python/Tools/msi/lib/lib_files.wxs b/third_party/python/Tools/msi/lib/lib_files.wxs deleted file mode 100644 index 6f19006df..000000000 --- a/third_party/python/Tools/msi/lib/lib_files.wxs +++ /dev/null @@ -1,79 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/lib/lib_pdb.wixproj b/third_party/python/Tools/msi/lib/lib_pdb.wixproj deleted file mode 100644 index db1b5bb31..000000000 --- a/third_party/python/Tools/msi/lib/lib_pdb.wixproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - {5E0BCE93-D1AC-4591-BBCB-3A2BE5A4B3D1} - 2.0 - lib_pdb - Package - - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/lib/lib_pdb.wxs b/third_party/python/Tools/msi/lib/lib_pdb.wxs deleted file mode 100644 index 8839e8a42..000000000 --- a/third_party/python/Tools/msi/lib/lib_pdb.wxs +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/make_zip.proj b/third_party/python/Tools/msi/make_zip.proj deleted file mode 100644 index 214111734..000000000 --- a/third_party/python/Tools/msi/make_zip.proj +++ /dev/null @@ -1,39 +0,0 @@ - - - - {10487945-15D1-4092-A214-338395C4116B} - python - - false - - - - - - false - python-$(PythonVersion)-embed-$(ArchName) - .zip - $(OutputPath)\$(TargetName)$(TargetExt) - rmdir /q/s "$(IntermediateOutputPath)\zip_$(ArchName)" - "$(PythonExe)" "$(MSBuildThisFileDirectory)\make_zip.py" - $(Arguments) -e -o "$(TargetPath)" -t "$(IntermediateOutputPath)\zip_$(ArchName)" -b "$(BuildPath.TrimEnd(`\`))" - set DOC_FILENAME=python$(PythonVersion).chm - $(Environment)%0D%0Aset PYTHONPATH=$(PySourcePath)Lib - $(Environment)%0D%0Aset VCREDIST_PATH=$(CRTRedist)\$(Platform) - - - - - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/make_zip.py b/third_party/python/Tools/msi/make_zip.py deleted file mode 100644 index 0698c1407..000000000 --- a/third_party/python/Tools/msi/make_zip.py +++ /dev/null @@ -1,252 +0,0 @@ -import argparse -import py_compile -import re -import sys -import shutil -import stat -import os -import tempfile - -from itertools import chain -from pathlib import Path -from zipfile import ZipFile, ZIP_DEFLATED -import subprocess - -TKTCL_RE = re.compile(r'^(_?tk|tcl).+\.(pyd|dll)', re.IGNORECASE) -DEBUG_RE = re.compile(r'_d\.(pyd|dll|exe|pdb|lib)$', re.IGNORECASE) -PYTHON_DLL_RE = re.compile(r'python\d\d?\.dll$', re.IGNORECASE) - -DEBUG_FILES = { - '_ctypes_test', - '_testbuffer', - '_testcapi', - '_testconsole', - '_testimportmultiple', - '_testmultiphase', - 'xxlimited', - 'python3_dstub', -} - -EXCLUDE_FROM_LIBRARY = { - '__pycache__', - 'idlelib', - 'pydoc_data', - 'site-packages', - 'tkinter', - 'turtledemo', -} - -EXCLUDE_FROM_EMBEDDABLE_LIBRARY = { - 'ensurepip', - 'venv', -} - -EXCLUDE_FILE_FROM_LIBRARY = { - 'bdist_wininst.py', -} - -EXCLUDE_FILE_FROM_LIBS = { - 'liblzma', - 'ssleay', - 'libeay', - 'python3stub', -} - -EXCLUDED_FILES = { - 'pyshellext', -} - -def is_not_debug(p): - if DEBUG_RE.search(p.name): - return False - - if TKTCL_RE.search(p.name): - return False - - return p.stem.lower() not in DEBUG_FILES and p.stem.lower() not in EXCLUDED_FILES - -def is_not_debug_or_python(p): - return is_not_debug(p) and not PYTHON_DLL_RE.search(p.name) - -def include_in_lib(p): - name = p.name.lower() - if p.is_dir(): - if name in EXCLUDE_FROM_LIBRARY: - return False - if name == 'test' and p.parts[-2].lower() == 'lib': - return False - if name in {'test', 'tests'} and p.parts[-3].lower() == 'lib': - return False - return True - - if name in EXCLUDE_FILE_FROM_LIBRARY: - return False - - suffix = p.suffix.lower() - return suffix not in {'.pyc', '.pyo', '.exe'} - -def include_in_embeddable_lib(p): - if p.is_dir() and p.name.lower() in EXCLUDE_FROM_EMBEDDABLE_LIBRARY: - return False - - return include_in_lib(p) - -def include_in_libs(p): - if not is_not_debug(p): - return False - - return p.stem.lower() not in EXCLUDE_FILE_FROM_LIBS - -def include_in_tools(p): - if p.is_dir() and p.name.lower() in {'scripts', 'i18n', 'pynche', 'demo', 'parser'}: - return True - - return p.suffix.lower() in {'.py', '.pyw', '.txt'} - -BASE_NAME = 'python{0.major}{0.minor}'.format(sys.version_info) - -FULL_LAYOUT = [ - ('/', '$build', 'python.exe', is_not_debug), - ('/', '$build', 'pythonw.exe', is_not_debug), - ('/', '$build', 'python{}.dll'.format(sys.version_info.major), is_not_debug), - ('/', '$build', '{}.dll'.format(BASE_NAME), is_not_debug), - ('DLLs/', '$build', '*.pyd', is_not_debug), - ('DLLs/', '$build', '*.dll', is_not_debug_or_python), - ('include/', 'include', '*.h', None), - ('include/', 'PC', 'pyconfig.h', None), - ('Lib/', 'Lib', '**/*', include_in_lib), - ('libs/', '$build', '*.lib', include_in_libs), - ('Tools/', 'Tools', '**/*', include_in_tools), -] - -EMBED_LAYOUT = [ - ('/', '$build', 'python*.exe', is_not_debug), - ('/', '$build', '*.pyd', is_not_debug), - ('/', '$build', '*.dll', is_not_debug), - ('{}.zip'.format(BASE_NAME), 'Lib', '**/*', include_in_embeddable_lib), -] - -if os.getenv('DOC_FILENAME'): - FULL_LAYOUT.append(('Doc/', 'Doc/build/htmlhelp', os.getenv('DOC_FILENAME'), None)) -if os.getenv('VCREDIST_PATH'): - FULL_LAYOUT.append(('/', os.getenv('VCREDIST_PATH'), 'vcruntime*.dll', None)) - EMBED_LAYOUT.append(('/', os.getenv('VCREDIST_PATH'), 'vcruntime*.dll', None)) - -def copy_to_layout(target, rel_sources): - count = 0 - - if target.suffix.lower() == '.zip': - if target.exists(): - target.unlink() - - with ZipFile(str(target), 'w', ZIP_DEFLATED) as f: - with tempfile.TemporaryDirectory() as tmpdir: - for s, rel in rel_sources: - if rel.suffix.lower() == '.py': - pyc = Path(tmpdir) / rel.with_suffix('.pyc').name - try: - py_compile.compile(str(s), str(pyc), str(rel), doraise=True, optimize=2) - except py_compile.PyCompileError: - f.write(str(s), str(rel)) - else: - f.write(str(pyc), str(rel.with_suffix('.pyc'))) - else: - f.write(str(s), str(rel)) - count += 1 - - else: - for s, rel in rel_sources: - dest = target / rel - try: - dest.parent.mkdir(parents=True) - except FileExistsError: - pass - if dest.is_file(): - dest.chmod(stat.S_IWRITE) - shutil.copy(str(s), str(dest)) - if dest.is_file(): - dest.chmod(stat.S_IWRITE) - count += 1 - - return count - -def rglob(root, pattern, condition): - dirs = [root] - recurse = pattern[:3] in {'**/', '**\\'} - while dirs: - d = dirs.pop(0) - for f in d.glob(pattern[3:] if recurse else pattern): - if recurse and f.is_dir() and (not condition or condition(f)): - dirs.append(f) - elif f.is_file() and (not condition or condition(f)): - yield f, f.relative_to(root) - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument('-s', '--source', metavar='dir', help='The directory containing the repository root', type=Path) - parser.add_argument('-o', '--out', metavar='file', help='The name of the output archive', type=Path, default=None) - parser.add_argument('-t', '--temp', metavar='dir', help='A directory to temporarily extract files into', type=Path, default=None) - parser.add_argument('-e', '--embed', help='Create an embedding layout', action='store_true', default=False) - parser.add_argument('-b', '--build', help='Specify the build directory', type=Path, default=None) - ns = parser.parse_args() - - source = ns.source or (Path(__file__).resolve().parent.parent.parent) - out = ns.out - build = ns.build or Path(sys.exec_prefix) - assert isinstance(source, Path) - assert not out or isinstance(out, Path) - assert isinstance(build, Path) - - if ns.temp: - temp = ns.temp - delete_temp = False - else: - temp = Path(tempfile.mkdtemp()) - delete_temp = True - - if out: - try: - out.parent.mkdir(parents=True) - except FileExistsError: - pass - try: - temp.mkdir(parents=True) - except FileExistsError: - pass - - layout = EMBED_LAYOUT if ns.embed else FULL_LAYOUT - - try: - for t, s, p, c in layout: - if s == '$build': - fs = build - else: - fs = source / s - files = rglob(fs, p, c) - extra_files = [] - if s == 'Lib' and p == '**/*': - extra_files.append(( - source / 'tools' / 'msi' / 'distutils.command.bdist_wininst.py', - Path('distutils') / 'command' / 'bdist_wininst.py' - )) - copied = copy_to_layout(temp / t.rstrip('/'), chain(files, extra_files)) - print('Copied {} files'.format(copied)) - - if ns.embed: - with open(str(temp / (BASE_NAME + '._pth')), 'w') as f: - print(BASE_NAME + '.zip', file=f) - print('.', file=f) - print('', file=f) - print('# Uncomment to run site.main() automatically', file=f) - print('#import site', file=f) - - if out: - total = copy_to_layout(out, rglob(temp, '**/*', None)) - print('Wrote {} files to {}'.format(total, out)) - finally: - if delete_temp: - shutil.rmtree(temp, True) - - -if __name__ == "__main__": - sys.exit(int(main() or 0)) diff --git a/third_party/python/Tools/msi/msi.props b/third_party/python/Tools/msi/msi.props deleted file mode 100644 index 610959910..000000000 --- a/third_party/python/Tools/msi/msi.props +++ /dev/null @@ -1,188 +0,0 @@ - - - - $(OutputName) - false - false - $(SuppressIces);ICE03;ICE57;ICE61 - 1026 - false - true - Release - x86 - perUser - <_MakeCatCommand Condition="'$(_MakeCatCommand)' == ''">makecat - - - - - - - - $(ComputerName)/$(ArchName)/ - $(ReleaseUri)/ - - - - - - - - WixUtilExtension - WixUtilExtension - - - - - $(Py_IntDir)\$(MajorVersionNumber)$(MinorVersionNumber)$(ArchName)_$(Configuration)\msi_$(OutputName) - $(IntermediateOutputPath)_$(OutputSuffix) - $(BuildPath) - $(OutputPath)\ - $(OutputPath) - true - $(ExternalsDir)\windows-installer\redist - - python$(MajorVersionNumber)$(MinorVersionNumber)$(MicroVersionNumber)$(ReleaseLevelName).chm - - $(MajorVersionNumber).$(MinorVersionNumber).$(Field3Value).0 - - - - $([System.Math]::Floor($([System.DateTime]::Now.Subtract($([System.DateTime]::new(2001, 1, 1))).TotalDays))) - $(MajorVersionNumber).$(MinorVersionNumber).$(MicroVersionNumber)dev$(RevisionNumber) - $(MajorVersionNumber).$(MinorVersionNumber).$(RevisionNumber).0 - - - - 32-bit - 64-bit - 32bit - 64bit - - $(DefineConstants); - Version=$(InstallerVersion); - ShortVersion=$(MajorVersionNumber).$(MinorVersionNumber); - LongVersion=$(PythonVersion); - MajorVersionNumber=$(MajorVersionNumber); - MinorVersionNumber=$(MinorVersionNumber); - UpgradeMinimumVersion=$(MajorVersionNumber).$(MinorVersionNumber).0.0; - NextMajorVersionNumber=$(MajorVersionNumber).$([msbuild]::Add($(MinorVersionNumber), 1)).0.0; - Bitness=$(Bitness); - PlatformArchitecture=$(PlatformArchitecture); - PyDebugExt=$(PyDebugExt); - PyArchExt=$(PyArchExt); - PyTestExt=$(PyTestExt); - OptionalFeatureName=$(OutputName); - - - $(DefineConstants);CRTRedist=$(CRTRedist); - - - $(DefineConstants);Suffix32=-32; - - - $(DefineConstants);Suffix32=; - - - - - - generated_filelist - - - false - - - false - - - - - - - - - - - src - - - tcltk - - - redist - - - redist - - - build32 - - - build64 - - - - - - - - - <_Uuid Include="CoreUpgradeCode"> - upgradecode - - <_Uuid Include="UpgradeCode"> - upgradecode/$(OutputName) - - <_Uuid Include="InstallDirectoryGuidSeed"> - installdirectoryseed - - <_Uuid Include="PythonExeComponentGuid"> - python.exe - - <_Uuid Include="PythonwExeComponentGuid"> - pythonw.exe - - <_Uuid Include="RemoveLib2to3PickleComponentGuid"> - lib2to3/pickles - - <_Uuid Include="CommonPythonRegComponentGuid"> - registry - - <_Uuid Include="PythonRegComponentGuid"> - registry/$(OutputName) - - - - - <_Uuids>@(_Uuid->'("%(Identity)", "$(MajorVersionNumber).$(MinorVersionNumber)/%(Uri)")',',') - <_GenerateCommand>import uuid; print('\n'.join('{}={}'.format(i, uuid.uuid5(uuid.UUID('c8d9733e-a70c-43ff-ab0c-e26456f11083'), '$(ReleaseUri.Replace(`{arch}`, `$(ArchName)`))' + j)) for i,j in [$(_Uuids.Replace(`"`,`'`))])) - - - - - - - - - - $(DefineConstants);@(_UuidValue,';'); - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/msi.targets b/third_party/python/Tools/msi/msi.targets deleted file mode 100644 index 9283a1ed6..000000000 --- a/third_party/python/Tools/msi/msi.targets +++ /dev/null @@ -1,93 +0,0 @@ - - - - - - <_FileListTarget>$(IntermediateOutputPath)$(MSBuildProjectName).g.csv - <_InstallFilesTarget>$(IntermediateOutputPath)$(MSBuildProjectName).g.wxs - - - - - <_Source>%(Source)$([msbuild]::MakeRelative(%(SourceBase), %(FullPath))) - <_Target>%(Target_)$([msbuild]::MakeRelative(%(TargetBase), %(FullPath))) - - - <_CatalogFiles Include="@(InstallFiles)" Condition="%(InstallFiles.IncludeInCat) and ''!=$([System.IO.File]::ReadAllText(%(InstallFiles.FullPath)))" /> - - - - - - - - - - - - - - <_CatFileSourceTarget>$(IntermediateOutputPath)$(MSBuildProjectName).cdf - <_CatFileTarget>$(IntermediateOutputPath)python_$(MSBuildProjectName).cat - <_CatFile>[CatalogHeader] -Name=$([System.IO.Path]::GetFileName($(_CatFileTarget))) -ResultDir=$([System.IO.Path]::GetDirectoryName($(_CatFileTarget))) -PublicVersion=1 -CatalogVersion=2 -HashAlgorithms=SHA256 -PageHashes=false -EncodingType= - -[CatalogFiles] -@(_CatalogFiles->'<HASH>%(Filename)%(Extension)=%(FullPath)',' -') - - - - - - - - - - - - - - - <_Content>$([System.IO.File]::ReadAllText(%(WxlTemplate.FullPath)).Replace(`{{ShortVersion}}`, `$(MajorVersionNumber).$(MinorVersionNumber)$(PyTestExt)`).Replace(`{{LongVersion}}`, `$(PythonVersion)$(PyTestExt)`).Replace(`{{Bitness}}`, `$(Bitness)`)) - <_ExistingContent Condition="Exists('$(IntermediateOutputPath)%(WxlTemplate.Filename).wxl')">$([System.IO.File]::ReadAllText($(IntermediateOutputPath)%(WxlTemplate.Filename).wxl)) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/path/path.wixproj b/third_party/python/Tools/msi/path/path.wixproj deleted file mode 100644 index 2792e1466..000000000 --- a/third_party/python/Tools/msi/path/path.wixproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - {91C99298-8E2E-4422-A5AF-CC4FFF9A58D3} - 2.0 - path - Package - ICE71 - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/path/path.wxs b/third_party/python/Tools/msi/path/path.wxs deleted file mode 100644 index 8b37936cc..000000000 --- a/third_party/python/Tools/msi/path/path.wxs +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - NOT ALLUSERS=1 - - - - - - - - - - - - ALLUSERS=1 - - - - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/path/path_en-US.wxl b/third_party/python/Tools/msi/path/path_en-US.wxl deleted file mode 100644 index 33a7886fe..000000000 --- a/third_party/python/Tools/msi/path/path_en-US.wxl +++ /dev/null @@ -1,6 +0,0 @@ - - - Add to Path - Path - No !(loc.ProductName) installation was detected. - diff --git a/third_party/python/Tools/msi/pip/pip.wixproj b/third_party/python/Tools/msi/pip/pip.wixproj deleted file mode 100644 index 718c02c03..000000000 --- a/third_party/python/Tools/msi/pip/pip.wixproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - {91C99298-8E2E-4422-A5AF-CC4FFF9A58D3} - 2.0 - pip - Package - ICE71 - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/pip/pip.wxs b/third_party/python/Tools/msi/pip/pip.wxs deleted file mode 100644 index 19e9f5fd2..000000000 --- a/third_party/python/Tools/msi/pip/pip.wxs +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - PYTHON_EXE - - - - - - - - - - - - - - - - - (&DefaultFeature=3) AND NOT (!DefaultFeature=3) - (&DefaultFeature=2) AND (!DefaultFeature=3) - - UpdatePip - - - - diff --git a/third_party/python/Tools/msi/pip/pip_en-US.wxl b/third_party/python/Tools/msi/pip/pip_en-US.wxl deleted file mode 100644 index cd0d9edf3..000000000 --- a/third_party/python/Tools/msi/pip/pip_en-US.wxl +++ /dev/null @@ -1,6 +0,0 @@ - - - pip Bootstrap - pip - No !(loc.ProductName) installation was detected. - diff --git a/third_party/python/Tools/msi/purge.py b/third_party/python/Tools/msi/purge.py deleted file mode 100644 index 24fdae243..000000000 --- a/third_party/python/Tools/msi/purge.py +++ /dev/null @@ -1,74 +0,0 @@ -# Purges the Fastly cache for Windows download files -# -# Usage: -# py -3 purge.py 3.5.1rc1 -# - -__author__ = 'Steve Dower ' -__version__ = '1.0.0' - -import re -import sys - -from urllib.request import * - -VERSION_RE = re.compile(r'(\d+\.\d+\.\d+)(\w+\d+)?$') - -try: - m = VERSION_RE.match(sys.argv[1]) - if not m: - print('Invalid version:', sys.argv[1]) - print('Expected something like "3.5.1rc1"') - sys.exit(1) -except LookupError: - print('Missing version argument. Expected something like "3.5.1rc1"') - sys.exit(1) - -URL = "https://www.python.org/ftp/python/{}/".format(m.group(1)) -REL = m.group(2) or '' - -FILES = [ - "core.msi", - "core_d.msi", - "core_pdb.msi", - "dev.msi", - "dev_d.msi", - "doc.msi", - "exe.msi", - "exe_d.msi", - "exe_pdb.msi", - "launcher.msi", - "lib.msi", - "lib_d.msi", - "lib_pdb.msi", - "path.msi", - "pip.msi", - "tcltk.msi", - "tcltk_d.msi", - "tcltk_pdb.msi", - "test.msi", - "test_d.msi", - "test_pdb.msi", - "tools.msi", - "Windows6.0-KB2999226-x64.msu", - "Windows6.0-KB2999226-x86.msu", - "Windows6.1-KB2999226-x64.msu", - "Windows6.1-KB2999226-x86.msu", - "Windows8.1-KB2999226-x64.msu", - "Windows8.1-KB2999226-x86.msu", - "Windows8-RT-KB2999226-x64.msu", - "Windows8-RT-KB2999226-x86.msu", -] -PATHS = [ - "python-{}.exe".format(m.group(0)), - "python-{}-webinstall.exe".format(m.group(0)), - "python-{}-amd64.exe".format(m.group(0)), - "python-{}-amd64-webinstall.exe".format(m.group(0)), -] + ["win32{}/{}".format(REL, f) for f in FILES] + ["amd64{}/{}".format(REL, f) for f in FILES] - -print('Purged:') -for n in PATHS: - u = URL + n - with urlopen(Request(u, method='PURGE', headers={'Fastly-Soft-Purge': 1})) as r: - r.read() - print(' ', u) diff --git a/third_party/python/Tools/msi/tcltk/tcltk.wixproj b/third_party/python/Tools/msi/tcltk/tcltk.wixproj deleted file mode 100644 index f66fc1498..000000000 --- a/third_party/python/Tools/msi/tcltk/tcltk.wixproj +++ /dev/null @@ -1,50 +0,0 @@ - - - - {DB350600-186C-4E52-BA98-26A7CECB067F} - 2.0 - tcltk - Package - - - - ICE43 - - - - - - - - - - - - - $(tcltkDir) - !(bindpath.tcltk) - $(tcltkDir)bin - DLLs\ - tcltk_dlls - - - - $(tcltkDir) - !(bindpath.tcltk) - $(tcltkDir)lib - tcl\ - tcltk_lib - - - - $(PySourcePath) - !(bindpath.src) - $(PySourcePath) - - tkinter_lib - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/tcltk/tcltk.wxs b/third_party/python/Tools/msi/tcltk/tcltk.wxs deleted file mode 100644 index eeae8e8b0..000000000 --- a/third_party/python/Tools/msi/tcltk/tcltk.wxs +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - PYTHON_EXE and PYTHONW_EXE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/tcltk/tcltk_d.wixproj b/third_party/python/Tools/msi/tcltk/tcltk_d.wixproj deleted file mode 100644 index 3266190da..000000000 --- a/third_party/python/Tools/msi/tcltk/tcltk_d.wixproj +++ /dev/null @@ -1,28 +0,0 @@ - - - - {EDA1FA5A-E2AA-4EAF-B49B-87D981CD0F16} - 2.0 - tcltk_d - Package - - - - - - - - - - - - $(tcltkDir) - !(bindpath.tcltk) - $(tcltkDir)bin - DLLs\ - tcltk_dlls_d - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/tcltk/tcltk_d.wxs b/third_party/python/Tools/msi/tcltk/tcltk_d.wxs deleted file mode 100644 index 01d0d2439..000000000 --- a/third_party/python/Tools/msi/tcltk/tcltk_d.wxs +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/tcltk/tcltk_en-US.wxl_template b/third_party/python/Tools/msi/tcltk/tcltk_en-US.wxl_template deleted file mode 100644 index f40fd6239..000000000 --- a/third_party/python/Tools/msi/tcltk/tcltk_en-US.wxl_template +++ /dev/null @@ -1,12 +0,0 @@ - - - Tcl/Tk Support - tcltk - No !(loc.ProductName) installation was detected. - IDLE (Python {{ShortVersion}} {{Bitness}}) - Launches IDLE, the interactive environment for !(loc.ProductName). - Python {{ShortVersion}} Module Docs ({{Bitness}}) - Start the !(loc.ProductName) documentation server. - &Edit with IDLE - Edit with IDLE {{ShortVersion}} ({{Bitness}}) - diff --git a/third_party/python/Tools/msi/tcltk/tcltk_files.wxs b/third_party/python/Tools/msi/tcltk/tcltk_files.wxs deleted file mode 100644 index 0d1b4a93a..000000000 --- a/third_party/python/Tools/msi/tcltk/tcltk_files.wxs +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/tcltk/tcltk_pdb.wixproj b/third_party/python/Tools/msi/tcltk/tcltk_pdb.wixproj deleted file mode 100644 index 3370798a0..000000000 --- a/third_party/python/Tools/msi/tcltk/tcltk_pdb.wixproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - {02053AFA-1831-499A-B3EA-D8B223D3C40D} - 2.0 - tcltk_pdb - Package - - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/tcltk/tcltk_pdb.wxs b/third_party/python/Tools/msi/tcltk/tcltk_pdb.wxs deleted file mode 100644 index 04454f384..000000000 --- a/third_party/python/Tools/msi/tcltk/tcltk_pdb.wxs +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/tcltk/tcltk_reg.wxs b/third_party/python/Tools/msi/tcltk/tcltk_reg.wxs deleted file mode 100644 index 2778bcc80..000000000 --- a/third_party/python/Tools/msi/tcltk/tcltk_reg.wxs +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - VersionNT > 600 - - - - - VersionNT > 600 - - - - - - VersionNT > 600 - - - - - - - VersionNT > 600 - - - - - - - - VersionNT = 600 - - - - - - - VersionNT = 600 - - - - - - - - diff --git a/third_party/python/Tools/msi/test/test.wixproj b/third_party/python/Tools/msi/test/test.wixproj deleted file mode 100644 index 8347e3f1d..000000000 --- a/third_party/python/Tools/msi/test/test.wixproj +++ /dev/null @@ -1,29 +0,0 @@ - - - - {DE0B7CC2-4358-4131-B3F4-C31C7F2CD468} - 2.0 - test - Package - - - - - - - - - - - - $(PySourcePath) - !(bindpath.src) - $(PySourcePath) - - test_py - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/test/test.wxs b/third_party/python/Tools/msi/test/test.wxs deleted file mode 100644 index f2ed64f07..000000000 --- a/third_party/python/Tools/msi/test/test.wxs +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/test/test_d.wixproj b/third_party/python/Tools/msi/test/test_d.wixproj deleted file mode 100644 index 33b04be1f..000000000 --- a/third_party/python/Tools/msi/test/test_d.wixproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - {41F5AE8D-24CD-4D03-BE75-AA6F7FAB4097} - 2.0 - test_d - Package - - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/test/test_d.wxs b/third_party/python/Tools/msi/test/test_d.wxs deleted file mode 100644 index a95487675..000000000 --- a/third_party/python/Tools/msi/test/test_d.wxs +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/test/test_en-US.wxl b/third_party/python/Tools/msi/test/test_en-US.wxl deleted file mode 100644 index e615c7a6b..000000000 --- a/third_party/python/Tools/msi/test/test_en-US.wxl +++ /dev/null @@ -1,7 +0,0 @@ - - - Test Suite - test - !(loc.FullProductName) native libtest - !(loc.ProductName) Native Test Modules - diff --git a/third_party/python/Tools/msi/test/test_files.wxs b/third_party/python/Tools/msi/test/test_files.wxs deleted file mode 100644 index 82a9115f7..000000000 --- a/third_party/python/Tools/msi/test/test_files.wxs +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/test/test_pdb.wixproj b/third_party/python/Tools/msi/test/test_pdb.wixproj deleted file mode 100644 index 965f0edd9..000000000 --- a/third_party/python/Tools/msi/test/test_pdb.wixproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - {7CF48ADD-CFAA-499F-9A05-BA18440A3344} - 2.0 - test_pdb - Package - - - - - - - - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/test/test_pdb.wxs b/third_party/python/Tools/msi/test/test_pdb.wxs deleted file mode 100644 index de634a390..000000000 --- a/third_party/python/Tools/msi/test/test_pdb.wxs +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/testrelease.bat b/third_party/python/Tools/msi/testrelease.bat deleted file mode 100644 index 96fdf5eb8..000000000 --- a/third_party/python/Tools/msi/testrelease.bat +++ /dev/null @@ -1,117 +0,0 @@ -@setlocal enableextensions -@echo off - -set D=%~dp0 -set PCBUILD=%D%..\..\PCBuild\ - -set TARGETDIR=%TEMP% -set TESTX86= -set TESTX64= -set TESTALLUSER= -set TESTPERUSER= - -:CheckOpts -if "%1" EQU "-h" goto Help -if "%1" EQU "-x86" (set TESTX86=1) && shift && goto CheckOpts -if "%1" EQU "-x64" (set TESTX64=1) && shift && goto CheckOpts -if "%1" EQU "-t" (set TARGETDIR=%~2) && shift && shift && goto CheckOpts -if "%1" EQU "--target" (set TARGETDIR=%~2) && shift && shift && goto CheckOpts -if "%1" EQU "-a" (set TESTALLUSER=1) && shift && goto CheckOpts -if "%1" EQU "--alluser" (set TESTALLUSER=1) && shift && goto CheckOpts -if "%1" EQU "-p" (set TESTPERUSER=1) && shift && goto CheckOpts -if "%1" EQU "--peruser" (set TESTPERUSER=1) && shift && goto CheckOpts - -if not defined TESTX86 if not defined TESTX64 (set TESTX86=1) && (set TESTX64=1) -if not defined TESTALLUSER if not defined TESTPERUSER (set TESTALLUSER=1) && (set TESTPERUSER=1) - - -if defined TESTX86 ( - for %%f in ("%PCBUILD%win32\en-us\*.exe") do ( - if defined TESTALLUSER call :test "%%~ff" "%TARGETDIR%\%%~nf-alluser" "InstallAllUsers=1 CompileAll=1" - if errorlevel 1 exit /B - if defined TESTPERUSER call :test "%%~ff" "%TARGETDIR%\%%~nf-peruser" "InstallAllUsers=0 CompileAll=0" - if errorlevel 1 exit /B - ) -) - -if defined TESTX64 ( - for %%f in ("%PCBUILD%amd64\en-us\*.exe") do ( - if defined TESTALLUSER call :test "%%~ff" "%TARGETDIR%\%%~nf-alluser" "InstallAllUsers=1 CompileAll=1" - if errorlevel 1 exit /B - if defined TESTPERUSER call :test "%%~ff" "%TARGETDIR%\%%~nf-peruser" "InstallAllUsers=0 CompileAll=0" - if errorlevel 1 exit /B - ) -) - -exit /B 0 - -:test -@setlocal -@echo on - -@if not exist "%~1" exit /B 1 - -@set EXE=%~1 -@if not "%EXE:embed=%"=="%EXE%" exit /B 0 - -@set EXITCODE=0 -@echo Installing %1 into %2 -"%~1" /passive /log "%~2\install\log.txt" TargetDir="%~2\Python" Include_debug=1 Include_symbols=1 %~3 - -@if not errorlevel 1 ( - @echo Printing version - "%~2\Python\python.exe" -c "import sys; print(sys.version)" > "%~2\version.txt" 2>&1 -) - -@if not errorlevel 1 ( - @echo Capturing Start Menu - @dir /s/b "%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs" | findstr /ic:"python" > "%~2\startmenu.txt" 2>&1 - @dir /s/b "%APPDATA%\Microsoft\Windows\Start Menu\Programs" | findstr /ic:"python" >> "%~2\startmenu.txt" 2>&1 - - @echo Capturing registry - @for /F "usebackq" %%f in (`reg query HKCR /s /f python /k`) do @( - echo %%f >> "%~2\hkcr.txt" - reg query "%%f" /s >> "%~2\hkcr.txt" 2>&1 - ) - @reg query HKCU\Software\Python /s > "%~2\hkcu.txt" 2>&1 - @reg query HKLM\Software\Python /reg:32 /s > "%~2\hklm.txt" 2>&1 - @reg query HKLM\Software\Python /reg:64 /s >> "%~2\hklm.txt" 2>&1 - cmd /k exit 0 -) - -@if not errorlevel 1 ( - @echo Installing package - "%~2\Python\python.exe" -m pip install "azure<0.10" > "%~2\pip.txt" 2>&1 - @if not errorlevel 1 ( - "%~2\Python\python.exe" -m pip uninstall -y azure python-dateutil six >> "%~2\pip.txt" 2>&1 - ) -) -@if not errorlevel 1 ( - @echo Testing Tcl/tk - @set TCL_LIBRARY=%~2\Python\tcl\tcl8.6 - "%~2\Python\python.exe" -m test -uall -v test_ttk_guionly test_tk test_idle > "%~2\tcltk.txt" 2>&1 - @set TCL_LIBRARY= -) - -@set EXITCODE=%ERRORLEVEL% - -@echo Result was %EXITCODE% -@echo Removing %1 -"%~1" /passive /uninstall /log "%~2\uninstall\log.txt" - -@echo off -exit /B %EXITCODE% - -:Help -echo testrelease.bat [--target TARGET] [-x86] [-x64] [--alluser] [--peruser] [-h] -echo. -echo --target (-t) Specify the target directory for installs and logs -echo -x86 Run tests for x86 installers -echo -x64 Run tests for x64 installers -echo --alluser (-a) Run tests for all-user installs (requires Administrator) -echo --peruser (-p) Run tests for per-user installs -echo -h Display this help information -echo. -echo If no test architecture is specified, all architectures will be tested. -echo If no install type is selected, all install types will be tested. -echo. diff --git a/third_party/python/Tools/msi/tools/tools.wixproj b/third_party/python/Tools/msi/tools/tools.wixproj deleted file mode 100644 index b7fc41ee9..000000000 --- a/third_party/python/Tools/msi/tools/tools.wixproj +++ /dev/null @@ -1,44 +0,0 @@ - - - - {24CBEB95-BC1E-4EA9-AEA9-33834BCCD0EC} - 2.0 - tools - Package - - - - - - - - - - - - - - - $(PySourcePath) - !(bindpath.src) - $(PySourcePath) - - tools_py - true - - - - - \ No newline at end of file diff --git a/third_party/python/Tools/msi/tools/tools.wxs b/third_party/python/Tools/msi/tools/tools.wxs deleted file mode 100644 index 7a805d061..000000000 --- a/third_party/python/Tools/msi/tools/tools.wxs +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/tools/tools_en-US.wxl b/third_party/python/Tools/msi/tools/tools_en-US.wxl deleted file mode 100644 index a1384177e..000000000 --- a/third_party/python/Tools/msi/tools/tools_en-US.wxl +++ /dev/null @@ -1,5 +0,0 @@ - - - Utility Scripts - tools - diff --git a/third_party/python/Tools/msi/tools/tools_files.wxs b/third_party/python/Tools/msi/tools/tools_files.wxs deleted file mode 100644 index 9c76b1b44..000000000 --- a/third_party/python/Tools/msi/tools/tools_files.wxs +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/uploadrelease.bat b/third_party/python/Tools/msi/uploadrelease.bat deleted file mode 100644 index d9dcc7a09..000000000 --- a/third_party/python/Tools/msi/uploadrelease.bat +++ /dev/null @@ -1,105 +0,0 @@ -@setlocal -@echo off - -set D=%~dp0 -set PCBUILD=%D%..\..\PCBuild\ - -set HOST= -set USER= -set TARGET= -set DRYRUN=false -set NOUPLOAD= -set NOGPG= -set NOPURGE= -set NOTEST= - -:CheckOpts -if "%1" EQU "-h" goto Help -if "%1" EQU "-o" (set HOST=%~2) && shift && shift && goto CheckOpts -if "%1" EQU "--host" (set HOST=%~2) && shift && shift && goto CheckOpts -if "%1" EQU "-u" (set USER=%~2) && shift && shift && goto CheckOpts -if "%1" EQU "--user" (set USER=%~2) && shift && shift && goto CheckOpts -if "%1" EQU "-t" (set TARGET=%~2) && shift && shift && goto CheckOpts -if "%1" EQU "--target" (set TARGET=%~2) && shift && shift && goto CheckOpts -if "%1" EQU "--dry-run" (set DRYRUN=true) && shift && goto CheckOpts -if "%1" EQU "--skip-upload" (set NOUPLOAD=true) && shift && goto CheckOpts -if "%1" EQU "--skip-gpg" (set NOGPG=true) && shift && goto CheckOpts -if "%1" EQU "--skip-purge" (set NOPURGE=true) && shift && goto CheckOpts -if "%1" EQU "--skip-test" (set NOTEST=true) && shift && goto CheckOpts -if "%1" EQU "-T" (set NOTEST=true) && shift && goto CheckOpts -if "%1" NEQ "" echo Unexpected argument "%1" & exit /B 1 - -if not defined PLINK where plink > "%TEMP%\plink.loc" 2> nul && set /P PLINK= < "%TEMP%\plink.loc" & del "%TEMP%\plink.loc" -if not defined PLINK where /R "%ProgramFiles(x86)%\PuTTY" plink > "%TEMP%\plink.loc" 2> nul && set /P PLINK= < "%TEMP%\plink.loc" & del "%TEMP%\plink.loc" -if not defined PLINK where /R "%ProgramFiles(x86)%" plink > "%TEMP%\plink.loc" 2> nul && set /P PLINK= < "%TEMP%\plink.loc" & del "%TEMP%\plink.loc" -if not defined PLINK echo Cannot locate plink.exe & exit /B 1 -echo Found plink.exe at %PLINK% - -if not defined PSCP where pscp > "%TEMP%\pscp.loc" 2> nul && set /P pscp= < "%TEMP%\pscp.loc" & del "%TEMP%\pscp.loc" -if not defined PSCP where /R "%ProgramFiles(x86)%\PuTTY" pscp > "%TEMP%\pscp.loc" 2> nul && set /P pscp= < "%TEMP%\pscp.loc" & del "%TEMP%\pscp.loc" -if not defined PSCP where /R "%ProgramFiles(x86)%" pscp > "%TEMP%\pscp.loc" 2> nul && set /P pscp= < "%TEMP%\pscp.loc" & del "%TEMP%\pscp.loc" -if not defined PSCP echo Cannot locate pscp.exe & exit /B 1 -echo Found pscp.exe at %PSCP% - -if defined NOGPG ( - set GPG= - echo Skipping GPG signature generation because of --skip-gpg -) else ( - if not defined GPG where gpg2 > "%TEMP%\gpg.loc" 2> nul && set /P GPG= < "%TEMP%\gpg.loc" & del "%TEMP%\gpg.loc" - if not defined GPG where /R "%PCBUILD%..\externals\windows-installer" gpg2 > "%TEMP%\gpg.loc" 2> nul && set /P GPG= < "%TEMP%\gpg.loc" & del "%TEMP%\gpg.loc" - if not defined GPG echo Cannot locate gpg2.exe. Signatures will not be uploaded & pause - echo Found gpg2.exe at %GPG% -) - -call "%PCBUILD%find_msbuild.bat" %MSBUILD% -if ERRORLEVEL 1 (echo Cannot locate MSBuild.exe on PATH or as MSBUILD variable & exit /b 2) -pushd "%D%" -if not defined NOUPLOAD ( - %MSBUILD% /v:m /nologo uploadrelease.proj /t:Upload /p:Platform=x86 - if errorlevel 1 goto :failed - %MSBUILD% /v:m /nologo uploadrelease.proj /t:Upload /p:Platform=x64 /p:IncludeDoc=false - if errorlevel 1 goto :failed -) -if not defined NOPURGE ( - %MSBUILD% /v:m /nologo uploadrelease.proj /t:Purge -) -if not defined NOTEST ( - call :test x86 - if errorlevel 1 goto :failed - call :test x64 - if errorlevel 1 goto :failed -) -%MSBUILD% /v:m /nologo uploadrelease.proj /t:ShowHashes /p:Platform=x86 -if errorlevel 1 goto :failed -%MSBUILD% /v:m /nologo uploadrelease.proj /t:ShowHashes /p:Platform=x64 /p:IncludeDoc=false -if errorlevel 1 goto :failed - -popd -exit /B 0 - -:test -%MSBUILD% /v:m /nologo uploadrelease.proj /t:Test /p:Platform=%1 -if errorlevel 1 ( - echo Test failed - purging and retrying - %MSBUILD% /v:m /nologo uploadrelease.proj /t:Purge - if errorlevel 1 exit /B - %MSBUILD% /v:m /nologo uploadrelease.proj /t:Test /p:Platform=%1 -) -exit /B - -:failed -popd -exit /B - -:Help -echo uploadrelease.bat --host HOST --user USERNAME [--target TARGET] [--dry-run] [-h] -echo. -echo --host (-o) Specify the upload host (required) -echo --user (-u) Specify the user on the host (required) -echo --target (-t) Specify the target directory on the host -echo --dry-run Display commands and filenames without executing them -echo --skip-gpg Does not generate GPG signatures before uploading -echo --skip-purge Does not perform CDN purge after uploading -echo --skip-test (-T) Does not perform post-upload tests -echo -h Display this help information -echo. diff --git a/third_party/python/Tools/msi/uploadrelease.proj b/third_party/python/Tools/msi/uploadrelease.proj deleted file mode 100644 index 96b99a4ff..000000000 --- a/third_party/python/Tools/msi/uploadrelease.proj +++ /dev/null @@ -1,113 +0,0 @@ - - - - {2D69F2AB-D5D0-4344-84B5-EF6DB34A9BC9} - python - - - $(TARGET) - /srv/www.python.org/ftp/python - true - true - false - - - - - - - $(DownloadUrlBase.TrimEnd(`/`))/$(MajorVersionNumber).$(MinorVersionNumber).$(MicroVersionNumber) - $(DownloadUrl.Replace(`{version}`, `$(MajorVersionNumber).$(MinorVersionNumber).$(MicroVersionNumber)`).Replace(`{arch}`, `$(ArchName)`).Replace(`{releasename}`, `$(ReleaseLevelName)`).Replace(`{msi}`, ``).TrimEnd(`/`)) - - - - - $(MSITarget) - - - $(EXETarget) - - - $(EXETarget) - - - - - - - - - - - - - - - - - %(File.CopyTo) - - - - - - - - - - - - - - - - - - - - - $(TEMP)\%(Filename)_source - $(TEMP)\%(Filename)_source\%(Filename)%(Extension) - $(TEMP)\%(Filename)_layout - $(OutputPath)\%(Filename)_layoutlog - $(OutputPath)\%(Filename)_layoutlog\%(Filename).log - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/third_party/python/Tools/msi/wix.props b/third_party/python/Tools/msi/wix.props deleted file mode 100644 index fbb2d1020..000000000 --- a/third_party/python/Tools/msi/wix.props +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - $(MSBuildThisFileDirectory)\Wix\ - $(ExternalsDir)\windows-installer\wix\ - $(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Installer XML\3.10@InstallRoot) - $(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows Installer XML\3.10@InstallRoot) - $(WixInstallPath)\Wix.targets - - \ No newline at end of file diff --git a/third_party/python/Tools/nuget/build.bat b/third_party/python/Tools/nuget/build.bat deleted file mode 100644 index 0b4f622e0..000000000 --- a/third_party/python/Tools/nuget/build.bat +++ /dev/null @@ -1,57 +0,0 @@ -@echo off -setlocal -set D=%~dp0 -set PCBUILD=%D%..\..\PCBuild\ -if "%Py_OutDir%"=="" set Py_OutDir=%PCBUILD% - -set BUILDX86= -set BUILDX64= -set REBUILD= -set OUTPUT= -set PACKAGES= - -:CheckOpts -if "%~1" EQU "-h" goto Help -if "%~1" EQU "-x86" (set BUILDX86=1) && shift && goto CheckOpts -if "%~1" EQU "-x64" (set BUILDX64=1) && shift && goto CheckOpts -if "%~1" EQU "-r" (set REBUILD=-r) && shift && goto CheckOpts -if "%~1" EQU "-o" (set OUTPUT="/p:OutputPath=%~2") && shift && shift && goto CheckOpts -if "%~1" EQU "--out" (set OUTPUT="/p:OutputPath=%~2") && shift && shift && goto CheckOpts -if "%~1" EQU "-p" (set PACKAGES=%PACKAGES% %~2) && shift && shift && goto CheckOpts - -if not defined BUILDX86 if not defined BUILDX64 (set BUILDX86=1) && (set BUILDX64=1) - -call "%D%..\msi\get_externals.bat" -call "%PCBUILD%find_msbuild.bat" %MSBUILD% -if ERRORLEVEL 1 (echo Cannot locate MSBuild.exe on PATH or as MSBUILD variable & exit /b 2) - -if defined PACKAGES set PACKAGES="/p:Packages=%PACKAGES%" - -if defined BUILDX86 ( - if defined REBUILD ( call "%PCBUILD%build.bat" -e -r - ) else if not exist "%Py_OutDir%win32\python.exe" call "%PCBUILD%build.bat" -e - if errorlevel 1 goto :eof - - %MSBUILD% "%D%make_pkg.proj" /p:Configuration=Release /p:Platform=x86 %OUTPUT% %PACKAGES% - if errorlevel 1 goto :eof -) - -if defined BUILDX64 ( - if defined REBUILD ( call "%PCBUILD%build.bat" -p x64 -e -r - ) else if not exist "%Py_OutDir%amd64\python.exe" call "%PCBUILD%build.bat" -p x64 -e - if errorlevel 1 goto :eof - - %MSBUILD% "%D%make_pkg.proj" /p:Configuration=Release /p:Platform=x64 %OUTPUT% %PACKAGES% - if errorlevel 1 goto :eof -) - -exit /B 0 - -:Help -echo build.bat [-x86] [-x64] [--out DIR] [-r] [-h] -echo. -echo -x86 Build x86 installers -echo -x64 Build x64 installers -echo -r Rebuild rather than incremental build -echo --out [DIR] Override output directory -echo -h Show usage diff --git a/third_party/python/Tools/nuget/make_pkg.proj b/third_party/python/Tools/nuget/make_pkg.proj deleted file mode 100644 index 9843bc97c..000000000 --- a/third_party/python/Tools/nuget/make_pkg.proj +++ /dev/null @@ -1,74 +0,0 @@ - - - - {10487945-15D1-4092-A214-338395C4116B} - python - $(OutputName)x86 - $(OutputName)daily - - false - true - - - - - - $(ExternalsDir)\windows-installer\nuget\nuget.exe - $(MajorVersionNumber).$(MinorVersionNumber).$(MicroVersionNumber) - $(NuspecVersion)-$(ReleaseLevelName) - $(MajorVersionNumber).$(MinorVersionNumber).$(DailyBuildVersion) - false - $(OutputName).$(NuspecVersion) - .nupkg - $(IntermediateOutputPath)\nuget_$(ArchName) - - rmdir /q/s "$(IntermediateOutputPath)" - - "$(PythonExe)" "$(MSBuildThisFileDirectory)\..\msi\make_zip.py" - $(PythonArguments) -t "$(IntermediateOutputPath)" -b "$(BuildPath.TrimEnd(`\`))" - - "$(IntermediateOutputPath)\python.exe" -B -c "import sys; sys.path.append(r'$(PySourcePath)\Lib'); import ensurepip; ensurepip._main()" - "$(IntermediateOutputPath)\python.exe" -B -m pip install -U $(Packages) - - "$(Nuget)" pack "$(MSBuildThisFileDirectory)\$(OutputName).nuspec" -BasePath "$(IntermediateOutputPath)" - "$(Nuget)" pack "$(MSBuildThisFileDirectory)\$(OutputName).symbols.nuspec" -BasePath "$(BuildPath.TrimEnd(`\`))" - $(NugetArguments) -OutputDirectory "$(OutputPath.Trim(`\`))" - $(NugetArguments) -Version "$(NuspecVersion)" - $(NugetArguments) -NoPackageAnalysis -NonInteractive - - set DOC_FILENAME=python$(PythonVersion).chm - $(Environment)%0D%0Aset PYTHONPATH=$(PySourcePath)Lib - $(Environment)%0D%0Aset VCREDIST_PATH=$(CRTRedist)\$(Platform) - $(Environment)%0D%0Amkdir "$(OutputPath.Trim(`\`))" >nul 2>nul - - - - - - - - - - - - - - <_PropsContents>$([System.IO.File]::ReadAllText('python.props')) - <_PropsContents>$(_PropsContents.Replace('$$PYTHON_TAG$$', '$(MajorVersionNumber).$(MinorVersionNumber)')) - <_PropsContents>$(_PropsContents.Replace('$$PYTHON_VERSION$$', '$(NuspecVersion)')) - <_PropsContents Condition="$(Platform) == 'x86'">$(_PropsContents.Replace('$$PYTHON_PLATFORM$$', 'Win32')) - <_PropsContents Condition="$(Platform) != 'x86'">$(_PropsContents.Replace('$$PYTHON_PLATFORM$$', '$(Platform)')) - <_PropsContents>$(_PropsContents.Replace('$$PYTHON_TARGET$$', '_GetPythonRuntimeFilesDependsOn$(MajorVersionNumber)$(MinorVersionNumber)_$(Platform)')) - <_ExistingContents Condition="Exists('$(IntermediateOutputPath)\python.props')">$([System.IO.File]::ReadAllText('$(IntermediateOutputPath)\python.props')) - - - - - - - - - - diff --git a/third_party/python/Tools/nuget/python.nuspec b/third_party/python/Tools/nuget/python.nuspec deleted file mode 100644 index d5f3e6324..000000000 --- a/third_party/python/Tools/nuget/python.nuspec +++ /dev/null @@ -1,19 +0,0 @@ - - - - python - Python - 0.0.0.0 - Python Software Foundation - https://docs.python.org/3/license.html - https://www.python.org/ - false - Installs 64-bit Python for use in build scenarios. - https://www.python.org/static/favicon.ico - python - - - - - - diff --git a/third_party/python/Tools/nuget/python.props b/third_party/python/Tools/nuget/python.props deleted file mode 100644 index 4cc70083e..000000000 --- a/third_party/python/Tools/nuget/python.props +++ /dev/null @@ -1,56 +0,0 @@ - - - - $(MSBuildThisFileDirectory)\..\..\tools - $(PythonHome)\include - $(PythonHome)\libs - $$PYTHON_TAG$$ - $$PYTHON_VERSION$$ - - true - false - false - false - - $$PYTHON_TARGET$$;$(GetPythonRuntimeFilesDependsOn) - - - - - $(PythonInclude);%(AdditionalIncludeDirectories) - MultiThreadedDLL - - - $(PythonLibs);%(AdditionalLibraryDirectories) - - - - - - - - <_PythonRuntimeExe Include="$(PythonHome)\python*.dll" /> - <_PythonRuntimeExe Include="$(PythonHome)\vcruntime140.dll" /> - <_PythonRuntimeExe Include="$(PythonHome)\python*.exe" Condition="$(IncludePythonExe) == 'true'" /> - <_PythonRuntimeExe> - %(Filename)%(Extension) - - <_PythonRuntimeDlls Include="$(PythonHome)\DLLs\*.pyd" /> - <_PythonRuntimeDlls Include="$(PythonHome)\DLLs\*.dll" /> - <_PythonRuntimeDlls> - DLLs\%(Filename)%(Extension) - - <_PythonRuntimeLib Include="$(PythonHome)\Lib\**\*" Exclude="$(PythonHome)\Lib\**\*.pyc;$(PythonHome)\Lib\site-packages\**\*" /> - <_PythonRuntimeLib Remove="$(PythonHome)\Lib\distutils\**\*" Condition="$(IncludeDistutils) != 'true'" /> - <_PythonRuntimeLib Remove="$(PythonHome)\Lib\lib2to3\**\*" Condition="$(IncludeLib2To3) != 'true'" /> - <_PythonRuntimeLib Remove="$(PythonHome)\Lib\ensurepip\**\*" Condition="$(IncludeVEnv) != 'true'" /> - <_PythonRuntimeLib Remove="$(PythonHome)\Lib\venv\**\*" Condition="$(IncludeVEnv) != 'true'" /> - <_PythonRuntimeLib> - Lib\%(RecursiveDir)%(Filename)%(Extension) - - - - - - - diff --git a/third_party/python/Tools/nuget/pythondaily.nuspec b/third_party/python/Tools/nuget/pythondaily.nuspec deleted file mode 100644 index ee3343bbb..000000000 --- a/third_party/python/Tools/nuget/pythondaily.nuspec +++ /dev/null @@ -1,19 +0,0 @@ - - - - pythondaily - Python (Daily build) - 0.0.0.0 - Python Software Foundation - https://docs.python.org/3/license.html - https://www.python.org/ - false - Installs an unsigned, untested build of Python for test purposes only. - https://www.python.org/static/favicon.ico - python - - - - - - diff --git a/third_party/python/Tools/nuget/pythonx86.nuspec b/third_party/python/Tools/nuget/pythonx86.nuspec deleted file mode 100644 index ebfcd6c92..000000000 --- a/third_party/python/Tools/nuget/pythonx86.nuspec +++ /dev/null @@ -1,19 +0,0 @@ - - - - pythonx86 - Python (32-bit) - Python Software Foundation - 0.0.0.0 - https://docs.python.org/3/license.html - https://www.python.org/ - false - Installs 32-bit Python for use in build scenarios. - https://www.python.org/static/favicon.ico - python - - - - - - diff --git a/third_party/python/Tools/scripts/patchcheck.py b/third_party/python/Tools/scripts/patchcheck.py deleted file mode 100755 index e5214abf6..000000000 --- a/third_party/python/Tools/scripts/patchcheck.py +++ /dev/null @@ -1,286 +0,0 @@ -#!/usr/bin/env python3 -"""Check proposed changes for common issues.""" -import re -import sys -import shutil -import os.path -import subprocess -import sysconfig - -import reindent -import untabify - - -# Excluded directories which are copies of external libraries: -# don't check their coding style -EXCLUDE_DIRS = [os.path.join('Modules', '_ctypes', 'libffi'), - os.path.join('Modules', '_ctypes', 'libffi_osx'), - os.path.join('Modules', '_ctypes', 'libffi_msvc'), - os.path.join('Modules', '_decimal', 'libmpdec'), - os.path.join('Modules', 'expat'), - os.path.join('Modules', 'zlib')] -SRCDIR = sysconfig.get_config_var('srcdir') - - -def n_files_str(count): - """Return 'N file(s)' with the proper plurality on 'file'.""" - return "{} file{}".format(count, "s" if count != 1 else "") - - -def status(message, modal=False, info=None): - """Decorator to output status info to stdout.""" - def decorated_fxn(fxn): - def call_fxn(*args, **kwargs): - sys.stdout.write(message + ' ... ') - sys.stdout.flush() - result = fxn(*args, **kwargs) - if not modal and not info: - print("done") - elif info: - print(info(result)) - else: - print("yes" if result else "NO") - return result - return call_fxn - return decorated_fxn - - -def get_git_branch(): - """Get the symbolic name for the current git branch""" - cmd = "git rev-parse --abbrev-ref HEAD".split() - try: - return subprocess.check_output(cmd, - stderr=subprocess.DEVNULL, - cwd=SRCDIR) - except subprocess.CalledProcessError: - return None - - -def get_git_upstream_remote(): - """Get the remote name to use for upstream branches - - Uses "upstream" if it exists, "origin" otherwise - """ - cmd = "git remote get-url upstream".split() - try: - subprocess.check_output(cmd, - stderr=subprocess.DEVNULL, - cwd=SRCDIR) - except subprocess.CalledProcessError: - return "origin" - return "upstream" - - -@status("Getting base branch for PR", - info=lambda x: x if x is not None else "not a PR branch") -def get_base_branch(): - if not os.path.exists(os.path.join(SRCDIR, '.git')): - # Not a git checkout, so there's no base branch - return None - version = sys.version_info - if version.releaselevel == 'alpha': - base_branch = "master" - else: - base_branch = "{0.major}.{0.minor}".format(version) - this_branch = get_git_branch() - if this_branch is None or this_branch == base_branch: - # Not on a git PR branch, so there's no base branch - return None - upstream_remote = get_git_upstream_remote() - return upstream_remote + "/" + base_branch - - -@status("Getting the list of files that have been added/changed", - info=lambda x: n_files_str(len(x))) -def changed_files(base_branch=None): - """Get the list of changed or added files from git.""" - if os.path.exists(os.path.join(SRCDIR, '.git')): - # We just use an existence check here as: - # directory = normal git checkout/clone - # file = git worktree directory - if base_branch: - cmd = 'git diff --name-status ' + base_branch - else: - cmd = 'git status --porcelain' - filenames = [] - with subprocess.Popen(cmd.split(), - stdout=subprocess.PIPE, - cwd=SRCDIR) as st: - for line in st.stdout: - line = line.decode().rstrip() - status_text, filename = line.split(maxsplit=1) - status = set(status_text) - # modified, added or unmerged files - if not status.intersection('MAU'): - continue - if ' -> ' in filename: - # file is renamed - filename = filename.split(' -> ', 2)[1].strip() - filenames.append(filename) - else: - sys.exit('need a git checkout to get modified files') - - filenames2 = [] - for filename in filenames: - # Normalize the path to be able to match using .startswith() - filename = os.path.normpath(filename) - if any(filename.startswith(path) for path in EXCLUDE_DIRS): - # Exclude the file - continue - filenames2.append(filename) - - return filenames2 - - -def report_modified_files(file_paths): - count = len(file_paths) - if count == 0: - return n_files_str(count) - else: - lines = ["{}:".format(n_files_str(count))] - for path in file_paths: - lines.append(" {}".format(path)) - return "\n".join(lines) - - -@status("Fixing Python file whitespace", info=report_modified_files) -def normalize_whitespace(file_paths): - """Make sure that the whitespace for .py files have been normalized.""" - reindent.makebackup = False # No need to create backups. - fixed = [path for path in file_paths if path.endswith('.py') and - reindent.check(os.path.join(SRCDIR, path))] - return fixed - - -@status("Fixing C file whitespace", info=report_modified_files) -def normalize_c_whitespace(file_paths): - """Report if any C files """ - fixed = [] - for path in file_paths: - abspath = os.path.join(SRCDIR, path) - with open(abspath, 'r') as f: - if '\t' not in f.read(): - continue - untabify.process(abspath, 8, verbose=False) - fixed.append(path) - return fixed - - -ws_re = re.compile(br'\s+(\r?\n)$') - -@status("Fixing docs whitespace", info=report_modified_files) -def normalize_docs_whitespace(file_paths): - fixed = [] - for path in file_paths: - abspath = os.path.join(SRCDIR, path) - try: - with open(abspath, 'rb') as f: - lines = f.readlines() - new_lines = [ws_re.sub(br'\1', line) for line in lines] - if new_lines != lines: - shutil.copyfile(abspath, abspath + '.bak') - with open(abspath, 'wb') as f: - f.writelines(new_lines) - fixed.append(path) - except Exception as err: - print('Cannot fix %s: %s' % (path, err)) - return fixed - - -@status("Docs modified", modal=True) -def docs_modified(file_paths): - """Report if any file in the Doc directory has been changed.""" - return bool(file_paths) - - -@status("Misc/ACKS updated", modal=True) -def credit_given(file_paths): - """Check if Misc/ACKS has been changed.""" - return os.path.join('Misc', 'ACKS') in file_paths - - -@status("Misc/NEWS.d updated with `blurb`", modal=True) -def reported_news(file_paths): - """Check if Misc/NEWS.d has been changed.""" - return any(p.startswith(os.path.join('Misc', 'NEWS.d', 'next')) - for p in file_paths) - -@status("configure regenerated", modal=True, info=str) -def regenerated_configure(file_paths): - """Check if configure has been regenerated.""" - if 'configure.ac' in file_paths: - return "yes" if 'configure' in file_paths else "no" - else: - return "not needed" - -@status("pyconfig.h.in regenerated", modal=True, info=str) -def regenerated_pyconfig_h_in(file_paths): - """Check if pyconfig.h.in has been regenerated.""" - if 'configure.ac' in file_paths: - return "yes" if 'pyconfig.h.in' in file_paths else "no" - else: - return "not needed" - -def travis(pull_request): - if pull_request == 'false': - print('Not a pull request; skipping') - return - base_branch = get_base_branch() - file_paths = changed_files(base_branch) - python_files = [fn for fn in file_paths if fn.endswith('.py')] - c_files = [fn for fn in file_paths if fn.endswith(('.c', '.h'))] - doc_files = [fn for fn in file_paths if fn.startswith('Doc') and - fn.endswith(('.rst', '.inc'))] - fixed = [] - fixed.extend(normalize_whitespace(python_files)) - fixed.extend(normalize_c_whitespace(c_files)) - fixed.extend(normalize_docs_whitespace(doc_files)) - if not fixed: - print('No whitespace issues found') - else: - print(f'Please fix the {len(fixed)} file(s) with whitespace issues') - print('(on UNIX you can run `make patchcheck` to make the fixes)') - sys.exit(1) - -def main(): - base_branch = get_base_branch() - file_paths = changed_files(base_branch) - python_files = [fn for fn in file_paths if fn.endswith('.py')] - c_files = [fn for fn in file_paths if fn.endswith(('.c', '.h'))] - doc_files = [fn for fn in file_paths if fn.startswith('Doc') and - fn.endswith(('.rst', '.inc'))] - misc_files = {p for p in file_paths if p.startswith('Misc')} - # PEP 8 whitespace rules enforcement. - normalize_whitespace(python_files) - # C rules enforcement. - normalize_c_whitespace(c_files) - # Doc whitespace enforcement. - normalize_docs_whitespace(doc_files) - # Docs updated. - docs_modified(doc_files) - # Misc/ACKS changed. - credit_given(misc_files) - # Misc/NEWS changed. - reported_news(misc_files) - # Regenerated configure, if necessary. - regenerated_configure(file_paths) - # Regenerated pyconfig.h.in, if necessary. - regenerated_pyconfig_h_in(file_paths) - - # Test suite run and passed. - if python_files or c_files: - end = " and check for refleaks?" if c_files else "?" - print() - print("Did you run the test suite" + end) - - -if __name__ == '__main__': - import argparse - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument('--travis', - help='Perform pass/fail checks') - args = parser.parse_args() - if args.travis: - travis(args.travis) - else: - main() diff --git a/third_party/python/Tools/unicode/genwincodec.py b/third_party/python/Tools/unicode/genwincodec.py deleted file mode 100644 index 7a1ef5eda..000000000 --- a/third_party/python/Tools/unicode/genwincodec.py +++ /dev/null @@ -1,61 +0,0 @@ -"""This script generates a Python codec module from a Windows Code Page. - -It uses the function MultiByteToWideChar to generate a decoding table. -""" - -import ctypes -from ctypes import wintypes -from gencodec import codegen -import unicodedata - -def genwinmap(codepage): - MultiByteToWideChar = ctypes.windll.kernel32.MultiByteToWideChar - MultiByteToWideChar.argtypes = [wintypes.UINT, wintypes.DWORD, - wintypes.LPCSTR, ctypes.c_int, - wintypes.LPWSTR, ctypes.c_int] - MultiByteToWideChar.restype = ctypes.c_int - - enc2uni = {} - - for i in list(range(32)) + [127]: - enc2uni[i] = (i, 'CONTROL CHARACTER') - - for i in range(256): - buf = ctypes.create_unicode_buffer(2) - ret = MultiByteToWideChar( - codepage, 0, - bytes([i]), 1, - buf, 2) - assert ret == 1, "invalid code page" - assert buf[1] == '\x00' - try: - name = unicodedata.name(buf[0]) - except ValueError: - try: - name = enc2uni[i][1] - except KeyError: - name = '' - - enc2uni[i] = (ord(buf[0]), name) - - return enc2uni - -def genwincodec(codepage): - import platform - map = genwinmap(codepage) - encodingname = 'cp%d' % codepage - code = codegen("", map, encodingname) - # Replace first lines with our own docstring - code = '''\ -"""Python Character Mapping Codec %s generated on Windows: -%s with the command: - python Tools/unicode/genwincodec.py %s -"""#" -''' % (encodingname, ' '.join(platform.win32_ver()), codepage - ) + code.split('"""#"', 1)[1] - - print(code) - -if __name__ == '__main__': - import sys - genwincodec(int(sys.argv[1])) diff --git a/third_party/python/Tools/unicode/makeunicodedata.py b/third_party/python/Tools/unicode/makeunicodedata.py index 5d8014a5d..bb6ba1c94 100644 --- a/third_party/python/Tools/unicode/makeunicodedata.py +++ b/third_party/python/Tools/unicode/makeunicodedata.py @@ -595,7 +595,7 @@ def makeunicodetype(unicode, trace): def makeunicodename(unicode, trace): - FILE = "Modules/unicodename_db.h" + FILE = "third_party/python/Modules/unicodename_db.h" print("--- Preparing", FILE, "...") diff --git a/third_party/python/pyconfig.h b/third_party/python/pyconfig.h index 7549ded6c..08ba30883 100644 --- a/third_party/python/pyconfig.h +++ b/third_party/python/pyconfig.h @@ -1,5 +1,6 @@ #ifndef Py_PYCONFIG_H #define Py_PYCONFIG_H +#include "third_party/zlib/zlib.h" /* Define if building universal (internal helper macro) */ /* #undef AC_APPLE_UNIVERSAL_BUILD */ @@ -51,9 +52,6 @@ /* Define if aligned memory access is required */ /* #undef HAVE_ALIGNED_REQUIRED */ -/* Define to 1 if you have the header file. */ -#define HAVE_ALLOCA_H 1 - /* Define this if your time.h defines altzone. */ /* #undef HAVE_ALTZONE */ @@ -130,15 +128,9 @@ /* Define to 1 if you have the `confstr' function. */ /* #undef HAVE_CONFSTR */ -/* Define to 1 if you have the header file. */ -/* #undef HAVE_CONIO_H */ - /* Define to 1 if you have the `copysign' function. */ #define HAVE_COPYSIGN 1 -/* Define to 1 if you have the header file. */ -/* #undef HAVE_CRYPT_H */ - /* Define to 1 if you have the `ctermid' function. */ /* #undef HAVE_CTERMID */ @@ -148,9 +140,6 @@ /* Define if you have the 'filter' function. */ #define HAVE_CURSES_FILTER 1 -/* Define to 1 if you have the header file. */ -#define HAVE_CURSES_H 1 - /* Define if you have the 'has_key' function. */ #define HAVE_CURSES_HAS_KEY 1 @@ -234,22 +223,12 @@ /* Define to 1 if you have the /dev/ptmx device file. */ #define HAVE_DEV_PTMX 1 -/* Define to 1 if you have the header file. */ -/* #undef HAVE_DIRECT_H */ - /* Define to 1 if the dirent structure has a d_type field */ #define HAVE_DIRENT_D_TYPE 1 -/* Define to 1 if you have the header file, and it defines `DIR'. - */ -#define HAVE_DIRENT_H 1 - /* Define if you have the 'dirfd' function or macro. */ #define HAVE_DIRFD 1 -/* Define to 1 if you have the header file. */ -#define HAVE_DLFCN_H 1 - /* Define to 1 if you have the `dlopen' function. */ #define HAVE_DLOPEN 1 @@ -262,14 +241,11 @@ /* Defined when any dynamic module loading is enabled. */ #define HAVE_DYNAMIC_LOADING 1 -/* Define to 1 if you have the header file. */ -/* #undef HAVE_ENDIAN_H */ - /* Define if you have the 'epoll' functions. */ -#define HAVE_EPOLL 1 +/* #define HAVE_EPOLL 1 */ /* Define if you have the 'epoll_create1' function. */ -#define HAVE_EPOLL_CREATE1 1 +/* #define HAVE_EPOLL_CREATE1 1 */ /* Define to 1 if you have the `erf' function. */ #define HAVE_ERF 1 @@ -277,9 +253,6 @@ /* Define to 1 if you have the `erfc' function. */ #define HAVE_ERFC 1 -/* Define to 1 if you have the header file. */ -#define HAVE_ERRNO_H 1 - /* Define to 1 if you have the `execv' function. */ #define HAVE_EXECV 1 @@ -389,8 +362,8 @@ /* Define if you have the getaddrinfo function. */ #define HAVE_GETADDRINFO 1 -/* Define this if you have flockfile(), getc_unlocked(), and funlockfile() */ -#define HAVE_GETC_UNLOCKED 1 +/* In Cosmopolitan the unlocked functions are slower. */ +/* #undef HAVE_GETC_UNLOCKED */ /* Define to 1 if you have the `getentropy' function. */ #define HAVE_GETENTROPY 1 @@ -453,7 +426,7 @@ #define HAVE_GETRANDOM 1 /* Define to 1 if the Linux getrandom() syscall is available */ -/* #undef HAVE_GETRANDOM_SYSCALL */ +/* #define HAVE_GETRANDOM_SYSCALL */ /* Define to 1 if you have the `getresgid' function. */ /* #undef HAVE_GETRESGID */ @@ -637,7 +610,7 @@ #define HAVE_MKFIFO 1 /* Define to 1 if you have the `mkfifoat' function. */ -/* #undef HAVE_MKFIFOAT */ +#define HAVE_MKFIFOAT 1 /* Define to 1 if you have the `mknod' function. */ #define HAVE_MKNOD 1 @@ -690,9 +663,6 @@ /* Define to 1 if you have the `poll' function. */ #define HAVE_POLL 1 -/* Define to 1 if you have the header file. */ -#define HAVE_POLL_H 1 - /* Define to 1 if you have the `posix_fadvise' function. */ #define HAVE_POSIX_FADVISE 1 @@ -708,18 +678,12 @@ /* Define to 1 if you have the header file. */ /* #undef HAVE_PROCESS_H */ -/* Define if your compiler supports function prototype */ -#define HAVE_PROTOTYPES 1 - /* Define to 1 if you have the `pthread_atfork' function. */ /* #undef HAVE_PTHREAD_ATFORK */ /* Defined for Solaris 2.6 bug in pthread header. */ /* #undef HAVE_PTHREAD_DESTRUCTOR */ -/* Define to 1 if you have the header file. */ -#define HAVE_PTHREAD_H 1 - /* Define to 1 if you have the `pthread_init' function. */ /* #undef HAVE_PTHREAD_INIT */ @@ -738,11 +702,9 @@ /* Define to 1 if you have the `pwrite' function. */ #define HAVE_PWRITE 1 -/* Define to 1 if you have the `readlink' function. */ -#define HAVE_READLINK 1 - -/* Define to 1 if you have the `readlinkat' function. */ -#define HAVE_READLINKAT 1 +/* won't support readlink() because it's frequently abused */ +/* #define HAVE_READLINK 1 */ +/* #define HAVE_READLINKAT 1 */ /* Define to 1 if you have the `readv' function. */ #define HAVE_READV 1 @@ -753,6 +715,8 @@ /* Define to 1 if you have the `renameat' function. */ #define HAVE_RENAMEAT 1 +#define HAVE_DIRENT_H 1 + /* Define if readline supports append_history */ /* #undef HAVE_RL_APPEND_HISTORY */ @@ -1224,7 +1188,7 @@ #define HAVE_WRITEV 1 /* Define if the zlib library has inflateCopy */ -/* #undef HAVE_ZLIB_COPY */ +#define HAVE_ZLIB_COPY 1 /* Define to 1 if you have the `_getpty' function. */ /* #undef HAVE__GETPTY */ @@ -1289,9 +1253,6 @@ /* Define if setpgrp() must be called as setpgrp(0, 0). */ /* #undef SETPGRP_HAVE_ARG */ -/* Define if i>>j for signed int i does not extend the sign bit when i < 0 */ -/* #undef SIGNED_RIGHT_SHIFT_ZERO_FILLS */ - /* The size of `double', as computed by sizeof. */ #define SIZEOF_DOUBLE 8 @@ -1368,27 +1329,6 @@ /* Define to use the C99 inline keyword. */ #define USE_INLINE 1 -/* Enable extensions on AIX 3, Interix. */ -#ifndef _ALL_SOURCE -#define _ALL_SOURCE 1 -#endif -/* Enable GNU extensions on systems that have them. */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif -/* Enable threading extensions on Solaris. */ -#ifndef _POSIX_PTHREAD_SEMANTICS -#define _POSIX_PTHREAD_SEMANTICS 1 -#endif -/* Enable extensions on HP NonStop. */ -#ifndef _TANDEM_SOURCE -#define _TANDEM_SOURCE 1 -#endif -/* Enable general extensions on Solaris. */ -#ifndef __EXTENSIONS__ -#define __EXTENSIONS__ 1 -#endif - /* Define if you want SIGFPE handled (see Include/pyfpe.h). */ /* #undef WANT_SIGFPE_HANDLER */ @@ -1536,9 +1476,8 @@ /* Define to empty if the keyword does not work. */ /* #undef volatile */ -/* Define the macros needed if on a UnixWare 7.x system. */ -#if defined(__USLC__) && defined(__SCO_VERSION__) -#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */ -#endif +/* #define _Py_MEMORY_SANITIZER */ + +#define Py_NSIG 32 #endif /*Py_PYCONFIG_H*/ diff --git a/third_party/python/python-modules.mk b/third_party/python/python-modules.mk index 15bc080a0..a135f5741 100644 --- a/third_party/python/python-modules.mk +++ b/third_party/python/python-modules.mk @@ -6,8 +6,8 @@ # the list of modules are also provided in Modules/config.c # so any changes here must be reflected there as well - -# these modules are always required +################################################################################ +# REQUIRED MODULES # _elementtree EXTMODULE_ELEMENTTREE_SRCS = \ @@ -53,41 +53,39 @@ EXTMODULE_BASE_INDEP_SRCS = \ $(EXTMODULE_TRACEMALLOC_SRCS) \ $(EXTMODULE_ELEMENTTREE_SRCS) - # these modules require POSIX-compliant libs EXTMODULE_BASE_POSIX_SRCS = \ - third_party/python/Modules/main.c \ - third_party/python/Modules/posixmodule.c \ - third_party/python/Modules/errnomodule.c \ - third_party/python/Modules/pwdmodule.c \ - third_party/python/Modules/_sre.c \ third_party/python/Modules/_codecsmodule.c \ - third_party/python/Modules/_functoolsmodule.c \ - third_party/python/Modules/_operator.c \ third_party/python/Modules/_collectionsmodule.c \ - third_party/python/Modules/itertoolsmodule.c \ - third_party/python/Modules/atexitmodule.c \ - third_party/python/Modules/signalmodule.c \ + third_party/python/Modules/_csv.c \ + third_party/python/Modules/_functoolsmodule.c \ + third_party/python/Modules/_localemodule.c \ + third_party/python/Modules/_operator.c \ + third_party/python/Modules/_sre.c \ third_party/python/Modules/_stat.c \ - third_party/python/Modules/timemodule.c \ - third_party/python/Modules/zipimport.c \ + third_party/python/Modules/atexitmodule.c \ + third_party/python/Modules/errnomodule.c \ third_party/python/Modules/faulthandler.c \ - third_party/python/Modules/symtablemodule.c \ third_party/python/Modules/fcntlmodule.c \ third_party/python/Modules/grpmodule.c \ - third_party/python/Modules/selectmodule.c \ + third_party/python/Modules/itertoolsmodule.c \ + third_party/python/Modules/main.c \ third_party/python/Modules/mmapmodule.c \ - third_party/python/Modules/_csv.c \ - third_party/python/Modules/_localemodule.c \ + third_party/python/Modules/posixmodule.c \ + third_party/python/Modules/pwdmodule.c \ + third_party/python/Modules/selectmodule.c \ + third_party/python/Modules/signalmodule.c \ + third_party/python/Modules/symtablemodule.c \ + third_party/python/Modules/timemodule.c \ + third_party/python/Modules/zipimport.c \ $(EXTMODULE_IO_SRCS) -# optional modules +################################################################################ +# OPTIONAL MODULES -# _blake -EXTMODULE_BLAKE_SRCS = \ - third_party/python/Modules/_blake2/blake2b_impl.c \ - third_party/python/Modules/_blake2/blake2module.c \ - third_party/python/Modules/_blake2/blake2s_impl.c +# CJK codecs +EXTMODULE_MISC_SRCS = \ + third_party/python/Modules/audioop.c EXTMODULE_BLAKE_OBJS = \ $(EXTMODULE_BLAKE_SRCS:%.c=o/$(MODE)/%.o) @@ -123,13 +121,10 @@ EXTMODULE_CJKCODECS_SRCS = \ # readline -# ctypes - # _ssl # _hashlib - # _decimal module (w/libmpdec) EXTMODULE_DECIMAL_SRCS = \ third_party/python/Modules/_decimal/libmpdec/basearith.c \ @@ -163,8 +158,9 @@ EXTMODULE_OPT_SRCS = \ third_party/python/Modules/sha1module.c \ third_party/python/Modules/sha256module.c \ third_party/python/Modules/sha512module.c \ - third_party/python/Modules/_sha3/sha3module.c \ + third_party/python/Modules/_sha3.c \ third_party/python/Modules/resource.c \ + third_party/python/Modules/termios.c \ third_party/python/Modules/_posixsubprocess.c \ third_party/python/Modules/syslogmodule.c \ third_party/python/Modules/binascii.c \ @@ -175,7 +171,6 @@ EXTMODULE_OPT_SRCS = \ third_party/python/Modules/_json.c \ third_party/python/Modules/_opcode.c - # add all of the module source files together to use in python.mk THIRD_PARTY_PYTHON_MODULES_SRCS = \ third_party/python/Modules/config.c \ @@ -183,12 +178,12 @@ THIRD_PARTY_PYTHON_MODULES_SRCS = \ third_party/python/Modules/getpath.c \ $(EXTMODULE_BASE_INDEP_SRCS) \ $(EXTMODULE_BASE_POSIX_SRCS) \ + $(EXTMODULE_MISC_SRCS) \ $(EXTMODULE_OPT_SRCS) THIRD_PARTY_PYTHON_MODULES_OBJS = \ $(THIRD_PARTY_PYTHON_MODULES_SRCS:%.c=o/$(MODE)/%.o) - THIRD_PARTY_PYTHON_MODULES_DIRECTDEPS = \ THIRD_PARTY_ZLIB # add sqlite if needed here @@ -214,11 +209,6 @@ $(EXTMODULE_PYEXPAT_OBJS): \ -DHAVE_EXPAT_CONFIG_H \ -DUSE_PYEXPAT_CAPI -$(EXTMODULE_DECIMAL_OBJS): \ - OVERRIDE_CFLAGS += \ - -DASM=1 \ - -DCONFIG_64=1 - o/$(MODE)/third_party/python/Modules/_decimal/libmpdec/transpose.o: \ OVERRIDE_CFLAGS += \ -DSTACK_FRAME_UNLIMITED diff --git a/third_party/python/python-stdlib.mk b/third_party/python/python-stdlib.mk index f1db3ccad..d3faa3a4f 100644 --- a/third_party/python/python-stdlib.mk +++ b/third_party/python/python-stdlib.mk @@ -5,516 +5,554 @@ # to the ZIP store in the APE # (can remove this if find command is usable) -THIRD_PARTY_PYTHON_STDLIB_PY = \ - third_party/python/Lib/__future__.py \ - third_party/python/Lib/__phello__.foo.py \ - third_party/python/Lib/_bootlocale.py \ - third_party/python/Lib/_collections_abc.py \ - third_party/python/Lib/_compat_pickle.py \ - third_party/python/Lib/_compression.py \ - third_party/python/Lib/_dummy_thread.py \ - third_party/python/Lib/_markupbase.py \ - third_party/python/Lib/_osx_support.py \ - third_party/python/Lib/_pyio.py \ - third_party/python/Lib/_sitebuiltins.py \ - third_party/python/Lib/_strptime.py \ +THIRD_PARTY_PYTHON_STDLIB_PY = \ + third_party/python/Lib/ \ + third_party/python/Lib/collections/ \ + third_party/python/Lib/dbm/ \ + third_party/python/Lib/email/ \ + third_party/python/Lib/email/mime/ \ + third_party/python/Lib/encodings/ \ + third_party/python/Lib/html/ \ + third_party/python/Lib/http/ \ + third_party/python/Lib/importlib/ \ + third_party/python/Lib/json/ \ + third_party/python/Lib/lib2to3/ \ + third_party/python/Lib/lib2to3/fixes/ \ + third_party/python/Lib/lib2to3/pgen2/ \ + third_party/python/Lib/logging/ \ + third_party/python/Lib/msilib/ \ + third_party/python/Lib/multiprocessing/ \ + third_party/python/Lib/multiprocessing/dummy/ \ + third_party/python/Lib/sqlite3/ \ + third_party/python/Lib/unittest/ \ + third_party/python/Lib/urllib/ \ + third_party/python/Lib/venv/ \ + third_party/python/Lib/venv/scripts/common/ \ + third_party/python/Lib/venv/scripts/nt/ \ + third_party/python/Lib/venv/scripts/posix/ \ + third_party/python/Lib/wsgiref/ \ + third_party/python/Lib/xml/ \ + third_party/python/Lib/xml/dom/ \ + third_party/python/Lib/xml/etree/ \ + third_party/python/Lib/xml/parsers/ \ + third_party/python/Lib/xml/sax/ \ + third_party/python/Lib/xmlrpc/ \ + third_party/python/Lib/__future__.py \ + third_party/python/Lib/_bootlocale.py \ + third_party/python/Lib/_collections_abc.py \ + third_party/python/Lib/_compat_pickle.py \ + third_party/python/Lib/_compression.py \ + third_party/python/Lib/_dummy_thread.py \ + third_party/python/Lib/_markupbase.py \ + third_party/python/Lib/_osx_support.py \ + third_party/python/Lib/_pyio.py \ + third_party/python/Lib/_sitebuiltins.py \ + third_party/python/Lib/_strptime.py \ third_party/python/Lib/_sysconfigdata_m_cosmo_x86_64-cosmo.py \ - third_party/python/Lib/_threading_local.py \ - third_party/python/Lib/_weakrefset.py \ - third_party/python/Lib/abc.py \ - third_party/python/Lib/aifc.py \ - third_party/python/Lib/antigravity.py \ - third_party/python/Lib/argparse.py \ - third_party/python/Lib/ast.py \ - third_party/python/Lib/base64.py \ - third_party/python/Lib/bdb.py \ - third_party/python/Lib/binhex.py \ - third_party/python/Lib/bisect.py \ - third_party/python/Lib/bz2.py \ - third_party/python/Lib/cProfile.py \ - third_party/python/Lib/calendar.py \ - third_party/python/Lib/cgi.py \ - third_party/python/Lib/cgitb.py \ - third_party/python/Lib/chunk.py \ - third_party/python/Lib/cmd.py \ - third_party/python/Lib/code.py \ - third_party/python/Lib/codecs.py \ - third_party/python/Lib/codeop.py \ - third_party/python/Lib/collections/__init__.py \ - third_party/python/Lib/collections/abc.py \ - third_party/python/Lib/colorsys.py \ - third_party/python/Lib/compileall.py \ - third_party/python/Lib/configparser.py \ - third_party/python/Lib/contextlib.py \ - third_party/python/Lib/copy.py \ - third_party/python/Lib/copyreg.py \ - third_party/python/Lib/crypt.py \ - third_party/python/Lib/csv.py \ - third_party/python/Lib/datetime.py \ - third_party/python/Lib/dbm/__init__.py \ - third_party/python/Lib/dbm/dumb.py \ - third_party/python/Lib/dbm/gnu.py \ - third_party/python/Lib/dbm/ndbm.py \ - third_party/python/Lib/decimal.py \ - third_party/python/Lib/difflib.py \ - third_party/python/Lib/dis.py \ - third_party/python/Lib/doctest.py \ - third_party/python/Lib/dummy_threading.py \ - third_party/python/Lib/email/__init__.py \ - third_party/python/Lib/email/_encoded_words.py \ - third_party/python/Lib/email/_header_value_parser.py \ - third_party/python/Lib/email/_parseaddr.py \ - third_party/python/Lib/email/_policybase.py \ - third_party/python/Lib/email/architecture.rst \ - third_party/python/Lib/email/base64mime.py \ - third_party/python/Lib/email/charset.py \ - third_party/python/Lib/email/contentmanager.py \ - third_party/python/Lib/email/encoders.py \ - third_party/python/Lib/email/errors.py \ - third_party/python/Lib/email/feedparser.py \ - third_party/python/Lib/email/generator.py \ - third_party/python/Lib/email/header.py \ - third_party/python/Lib/email/headerregistry.py \ - third_party/python/Lib/email/iterators.py \ - third_party/python/Lib/email/message.py \ - third_party/python/Lib/email/mime/__init__.py \ - third_party/python/Lib/email/mime/application.py \ - third_party/python/Lib/email/mime/audio.py \ - third_party/python/Lib/email/mime/base.py \ - third_party/python/Lib/email/mime/image.py \ - third_party/python/Lib/email/mime/message.py \ - third_party/python/Lib/email/mime/multipart.py \ - third_party/python/Lib/email/mime/nonmultipart.py \ - third_party/python/Lib/email/mime/text.py \ - third_party/python/Lib/email/parser.py \ - third_party/python/Lib/email/policy.py \ - third_party/python/Lib/email/quoprimime.py \ - third_party/python/Lib/email/utils.py \ - third_party/python/Lib/encodings/__init__.py \ - third_party/python/Lib/encodings/aliases.py \ - third_party/python/Lib/encodings/ascii.py \ - third_party/python/Lib/encodings/base64_codec.py \ - third_party/python/Lib/encodings/big5.py \ - third_party/python/Lib/encodings/big5hkscs.py \ - third_party/python/Lib/encodings/bz2_codec.py \ - third_party/python/Lib/encodings/charmap.py \ - third_party/python/Lib/encodings/cp037.py \ - third_party/python/Lib/encodings/cp1006.py \ - third_party/python/Lib/encodings/cp1026.py \ - third_party/python/Lib/encodings/cp1125.py \ - third_party/python/Lib/encodings/cp1140.py \ - third_party/python/Lib/encodings/cp1250.py \ - third_party/python/Lib/encodings/cp1251.py \ - third_party/python/Lib/encodings/cp1252.py \ - third_party/python/Lib/encodings/cp1253.py \ - third_party/python/Lib/encodings/cp1254.py \ - third_party/python/Lib/encodings/cp1255.py \ - third_party/python/Lib/encodings/cp1256.py \ - third_party/python/Lib/encodings/cp1257.py \ - third_party/python/Lib/encodings/cp1258.py \ - third_party/python/Lib/encodings/cp273.py \ - third_party/python/Lib/encodings/cp424.py \ - third_party/python/Lib/encodings/cp437.py \ - third_party/python/Lib/encodings/cp500.py \ - third_party/python/Lib/encodings/cp65001.py \ - third_party/python/Lib/encodings/cp720.py \ - third_party/python/Lib/encodings/cp737.py \ - third_party/python/Lib/encodings/cp775.py \ - third_party/python/Lib/encodings/cp850.py \ - third_party/python/Lib/encodings/cp852.py \ - third_party/python/Lib/encodings/cp855.py \ - third_party/python/Lib/encodings/cp856.py \ - third_party/python/Lib/encodings/cp857.py \ - third_party/python/Lib/encodings/cp858.py \ - third_party/python/Lib/encodings/cp860.py \ - third_party/python/Lib/encodings/cp861.py \ - third_party/python/Lib/encodings/cp862.py \ - third_party/python/Lib/encodings/cp863.py \ - third_party/python/Lib/encodings/cp864.py \ - third_party/python/Lib/encodings/cp865.py \ - third_party/python/Lib/encodings/cp866.py \ - third_party/python/Lib/encodings/cp869.py \ - third_party/python/Lib/encodings/cp874.py \ - third_party/python/Lib/encodings/cp875.py \ - third_party/python/Lib/encodings/cp932.py \ - third_party/python/Lib/encodings/cp949.py \ - third_party/python/Lib/encodings/cp950.py \ - third_party/python/Lib/encodings/euc_jis_2004.py \ - third_party/python/Lib/encodings/euc_jisx0213.py \ - third_party/python/Lib/encodings/euc_jp.py \ - third_party/python/Lib/encodings/euc_kr.py \ - third_party/python/Lib/encodings/gb18030.py \ - third_party/python/Lib/encodings/gb2312.py \ - third_party/python/Lib/encodings/gbk.py \ - third_party/python/Lib/encodings/hex_codec.py \ - third_party/python/Lib/encodings/hp_roman8.py \ - third_party/python/Lib/encodings/hz.py \ - third_party/python/Lib/encodings/idna.py \ - third_party/python/Lib/encodings/iso2022_jp.py \ - third_party/python/Lib/encodings/iso2022_jp_1.py \ - third_party/python/Lib/encodings/iso2022_jp_2.py \ - third_party/python/Lib/encodings/iso2022_jp_2004.py \ - third_party/python/Lib/encodings/iso2022_jp_3.py \ - third_party/python/Lib/encodings/iso2022_jp_ext.py \ - third_party/python/Lib/encodings/iso2022_kr.py \ - third_party/python/Lib/encodings/iso8859_1.py \ - third_party/python/Lib/encodings/iso8859_10.py \ - third_party/python/Lib/encodings/iso8859_11.py \ - third_party/python/Lib/encodings/iso8859_13.py \ - third_party/python/Lib/encodings/iso8859_14.py \ - third_party/python/Lib/encodings/iso8859_15.py \ - third_party/python/Lib/encodings/iso8859_16.py \ - third_party/python/Lib/encodings/iso8859_2.py \ - third_party/python/Lib/encodings/iso8859_3.py \ - third_party/python/Lib/encodings/iso8859_4.py \ - third_party/python/Lib/encodings/iso8859_5.py \ - third_party/python/Lib/encodings/iso8859_6.py \ - third_party/python/Lib/encodings/iso8859_7.py \ - third_party/python/Lib/encodings/iso8859_8.py \ - third_party/python/Lib/encodings/iso8859_9.py \ - third_party/python/Lib/encodings/johab.py \ - third_party/python/Lib/encodings/koi8_r.py \ - third_party/python/Lib/encodings/koi8_t.py \ - third_party/python/Lib/encodings/koi8_u.py \ - third_party/python/Lib/encodings/kz1048.py \ - third_party/python/Lib/encodings/latin_1.py \ - third_party/python/Lib/encodings/mac_arabic.py \ - third_party/python/Lib/encodings/mac_centeuro.py \ - third_party/python/Lib/encodings/mac_croatian.py \ - third_party/python/Lib/encodings/mac_cyrillic.py \ - third_party/python/Lib/encodings/mac_farsi.py \ - third_party/python/Lib/encodings/mac_greek.py \ - third_party/python/Lib/encodings/mac_iceland.py \ - third_party/python/Lib/encodings/mac_latin2.py \ - third_party/python/Lib/encodings/mac_roman.py \ - third_party/python/Lib/encodings/mac_romanian.py \ - third_party/python/Lib/encodings/mac_turkish.py \ - third_party/python/Lib/encodings/mbcs.py \ - third_party/python/Lib/encodings/oem.py \ - third_party/python/Lib/encodings/palmos.py \ - third_party/python/Lib/encodings/ptcp154.py \ - third_party/python/Lib/encodings/punycode.py \ - third_party/python/Lib/encodings/quopri_codec.py \ - third_party/python/Lib/encodings/raw_unicode_escape.py \ - third_party/python/Lib/encodings/rot_13.py \ - third_party/python/Lib/encodings/shift_jis.py \ - third_party/python/Lib/encodings/shift_jis_2004.py \ - third_party/python/Lib/encodings/shift_jisx0213.py \ - third_party/python/Lib/encodings/tis_620.py \ - third_party/python/Lib/encodings/undefined.py \ - third_party/python/Lib/encodings/unicode_escape.py \ - third_party/python/Lib/encodings/unicode_internal.py \ - third_party/python/Lib/encodings/utf_16.py \ - third_party/python/Lib/encodings/utf_16_be.py \ - third_party/python/Lib/encodings/utf_16_le.py \ - third_party/python/Lib/encodings/utf_32.py \ - third_party/python/Lib/encodings/utf_32_be.py \ - third_party/python/Lib/encodings/utf_32_le.py \ - third_party/python/Lib/encodings/utf_7.py \ - third_party/python/Lib/encodings/utf_8.py \ - third_party/python/Lib/encodings/utf_8_sig.py \ - third_party/python/Lib/encodings/uu_codec.py \ - third_party/python/Lib/encodings/zlib_codec.py \ - third_party/python/Lib/enum.py \ - third_party/python/Lib/filecmp.py \ - third_party/python/Lib/fileinput.py \ - third_party/python/Lib/fnmatch.py \ - third_party/python/Lib/formatter.py \ - third_party/python/Lib/fractions.py \ - third_party/python/Lib/ftplib.py \ - third_party/python/Lib/functools.py \ - third_party/python/Lib/genericpath.py \ - third_party/python/Lib/getopt.py \ - third_party/python/Lib/getpass.py \ - third_party/python/Lib/gettext.py \ - third_party/python/Lib/glob.py \ - third_party/python/Lib/gzip.py \ - third_party/python/Lib/hashlib.py \ - third_party/python/Lib/heapq.py \ - third_party/python/Lib/hmac.py \ - third_party/python/Lib/html/__init__.py \ - third_party/python/Lib/html/entities.py \ - third_party/python/Lib/html/parser.py \ - third_party/python/Lib/http/__init__.py \ - third_party/python/Lib/http/client.py \ - third_party/python/Lib/http/cookiejar.py \ - third_party/python/Lib/http/cookies.py \ - third_party/python/Lib/http/server.py \ - third_party/python/Lib/imaplib.py \ - third_party/python/Lib/imghdr.py \ - third_party/python/Lib/imp.py \ - third_party/python/Lib/importlib/__init__.py \ - third_party/python/Lib/importlib/_bootstrap.py \ - third_party/python/Lib/importlib/_bootstrap_external.py \ - third_party/python/Lib/importlib/abc.py \ - third_party/python/Lib/importlib/machinery.py \ - third_party/python/Lib/importlib/util.py \ - third_party/python/Lib/inspect.py \ - third_party/python/Lib/io.py \ - third_party/python/Lib/ipaddress.py \ - third_party/python/Lib/json/__init__.py \ - third_party/python/Lib/json/decoder.py \ - third_party/python/Lib/json/encoder.py \ - third_party/python/Lib/json/scanner.py \ - third_party/python/Lib/json/tool.py \ - third_party/python/Lib/keyword.py \ - third_party/python/Lib/lib2to3/Grammar.txt \ - third_party/python/Lib/lib2to3/PatternGrammar.txt \ - third_party/python/Lib/lib2to3/__init__.py \ - third_party/python/Lib/lib2to3/__main__.py \ - third_party/python/Lib/lib2to3/btm_matcher.py \ - third_party/python/Lib/lib2to3/btm_utils.py \ - third_party/python/Lib/lib2to3/fixer_base.py \ - third_party/python/Lib/lib2to3/fixer_util.py \ - third_party/python/Lib/lib2to3/fixes/__init__.py \ - third_party/python/Lib/lib2to3/fixes/fix_apply.py \ - third_party/python/Lib/lib2to3/fixes/fix_asserts.py \ - third_party/python/Lib/lib2to3/fixes/fix_basestring.py \ - third_party/python/Lib/lib2to3/fixes/fix_buffer.py \ - third_party/python/Lib/lib2to3/fixes/fix_dict.py \ - third_party/python/Lib/lib2to3/fixes/fix_except.py \ - third_party/python/Lib/lib2to3/fixes/fix_exec.py \ - third_party/python/Lib/lib2to3/fixes/fix_execfile.py \ - third_party/python/Lib/lib2to3/fixes/fix_exitfunc.py \ - third_party/python/Lib/lib2to3/fixes/fix_filter.py \ - third_party/python/Lib/lib2to3/fixes/fix_funcattrs.py \ - third_party/python/Lib/lib2to3/fixes/fix_future.py \ - third_party/python/Lib/lib2to3/fixes/fix_getcwdu.py \ - third_party/python/Lib/lib2to3/fixes/fix_has_key.py \ - third_party/python/Lib/lib2to3/fixes/fix_idioms.py \ - third_party/python/Lib/lib2to3/fixes/fix_import.py \ - third_party/python/Lib/lib2to3/fixes/fix_imports.py \ - third_party/python/Lib/lib2to3/fixes/fix_imports2.py \ - third_party/python/Lib/lib2to3/fixes/fix_input.py \ - third_party/python/Lib/lib2to3/fixes/fix_intern.py \ - third_party/python/Lib/lib2to3/fixes/fix_isinstance.py \ - third_party/python/Lib/lib2to3/fixes/fix_itertools.py \ - third_party/python/Lib/lib2to3/fixes/fix_itertools_imports.py \ - third_party/python/Lib/lib2to3/fixes/fix_long.py \ - third_party/python/Lib/lib2to3/fixes/fix_map.py \ - third_party/python/Lib/lib2to3/fixes/fix_metaclass.py \ - third_party/python/Lib/lib2to3/fixes/fix_methodattrs.py \ - third_party/python/Lib/lib2to3/fixes/fix_ne.py \ - third_party/python/Lib/lib2to3/fixes/fix_next.py \ - third_party/python/Lib/lib2to3/fixes/fix_nonzero.py \ - third_party/python/Lib/lib2to3/fixes/fix_numliterals.py \ - third_party/python/Lib/lib2to3/fixes/fix_operator.py \ - third_party/python/Lib/lib2to3/fixes/fix_paren.py \ - third_party/python/Lib/lib2to3/fixes/fix_print.py \ - third_party/python/Lib/lib2to3/fixes/fix_raise.py \ - third_party/python/Lib/lib2to3/fixes/fix_raw_input.py \ - third_party/python/Lib/lib2to3/fixes/fix_reduce.py \ - third_party/python/Lib/lib2to3/fixes/fix_reload.py \ - third_party/python/Lib/lib2to3/fixes/fix_renames.py \ - third_party/python/Lib/lib2to3/fixes/fix_repr.py \ - third_party/python/Lib/lib2to3/fixes/fix_set_literal.py \ - third_party/python/Lib/lib2to3/fixes/fix_standarderror.py \ - third_party/python/Lib/lib2to3/fixes/fix_sys_exc.py \ - third_party/python/Lib/lib2to3/fixes/fix_throw.py \ - third_party/python/Lib/lib2to3/fixes/fix_tuple_params.py \ - third_party/python/Lib/lib2to3/fixes/fix_types.py \ - third_party/python/Lib/lib2to3/fixes/fix_unicode.py \ - third_party/python/Lib/lib2to3/fixes/fix_urllib.py \ - third_party/python/Lib/lib2to3/fixes/fix_ws_comma.py \ - third_party/python/Lib/lib2to3/fixes/fix_xrange.py \ - third_party/python/Lib/lib2to3/fixes/fix_xreadlines.py \ - third_party/python/Lib/lib2to3/fixes/fix_zip.py \ - third_party/python/Lib/lib2to3/main.py \ - third_party/python/Lib/lib2to3/patcomp.py \ - third_party/python/Lib/lib2to3/pgen2/__init__.py \ - third_party/python/Lib/lib2to3/pgen2/conv.py \ - third_party/python/Lib/lib2to3/pgen2/driver.py \ - third_party/python/Lib/lib2to3/pgen2/grammar.py \ - third_party/python/Lib/lib2to3/pgen2/literals.py \ - third_party/python/Lib/lib2to3/pgen2/parse.py \ - third_party/python/Lib/lib2to3/pgen2/pgen.py \ - third_party/python/Lib/lib2to3/pgen2/token.py \ - third_party/python/Lib/lib2to3/pgen2/tokenize.py \ - third_party/python/Lib/lib2to3/pygram.py \ - third_party/python/Lib/lib2to3/pytree.py \ - third_party/python/Lib/lib2to3/refactor.py \ - third_party/python/Lib/linecache.py \ - third_party/python/Lib/locale.py \ - third_party/python/Lib/logging/__init__.py \ - third_party/python/Lib/logging/config.py \ - third_party/python/Lib/logging/handlers.py \ - third_party/python/Lib/lzma.py \ - third_party/python/Lib/macpath.py \ - third_party/python/Lib/macurl2path.py \ - third_party/python/Lib/mailbox.py \ - third_party/python/Lib/mailcap.py \ - third_party/python/Lib/mimetypes.py \ - third_party/python/Lib/modulefinder.py \ - third_party/python/Lib/msilib/__init__.py \ - third_party/python/Lib/msilib/schema.py \ - third_party/python/Lib/msilib/sequence.py \ - third_party/python/Lib/msilib/text.py \ - third_party/python/Lib/multiprocessing/__init__.py \ - third_party/python/Lib/multiprocessing/connection.py \ - third_party/python/Lib/multiprocessing/context.py \ - third_party/python/Lib/multiprocessing/dummy/__init__.py \ - third_party/python/Lib/multiprocessing/dummy/connection.py \ - third_party/python/Lib/multiprocessing/forkserver.py \ - third_party/python/Lib/multiprocessing/heap.py \ - third_party/python/Lib/multiprocessing/managers.py \ - third_party/python/Lib/multiprocessing/pool.py \ - third_party/python/Lib/multiprocessing/popen_fork.py \ - third_party/python/Lib/multiprocessing/popen_forkserver.py \ - third_party/python/Lib/multiprocessing/popen_spawn_posix.py \ - third_party/python/Lib/multiprocessing/popen_spawn_win32.py \ - third_party/python/Lib/multiprocessing/process.py \ - third_party/python/Lib/multiprocessing/queues.py \ - third_party/python/Lib/multiprocessing/reduction.py \ - third_party/python/Lib/multiprocessing/resource_sharer.py \ - third_party/python/Lib/multiprocessing/semaphore_tracker.py \ - third_party/python/Lib/multiprocessing/sharedctypes.py \ - third_party/python/Lib/multiprocessing/spawn.py \ - third_party/python/Lib/multiprocessing/synchronize.py \ - third_party/python/Lib/multiprocessing/util.py \ - third_party/python/Lib/netrc.py \ - third_party/python/Lib/nntplib.py \ - third_party/python/Lib/ntpath.py \ - third_party/python/Lib/nturl2path.py \ - third_party/python/Lib/numbers.py \ - third_party/python/Lib/opcode.py \ - third_party/python/Lib/operator.py \ - third_party/python/Lib/optparse.py \ - third_party/python/Lib/os.py \ - third_party/python/Lib/pathlib.py \ - third_party/python/Lib/pdb.py \ - third_party/python/Lib/pickle.py \ - third_party/python/Lib/pickletools.py \ - third_party/python/Lib/pipes.py \ - third_party/python/Lib/pkgutil.py \ - third_party/python/Lib/platform.py \ - third_party/python/Lib/plistlib.py \ - third_party/python/Lib/poplib.py \ - third_party/python/Lib/posixpath.py \ - third_party/python/Lib/pprint.py \ - third_party/python/Lib/profile.py \ - third_party/python/Lib/pstats.py \ - third_party/python/Lib/pty.py \ - third_party/python/Lib/py_compile.py \ - third_party/python/Lib/pyclbr.py \ - third_party/python/Lib/pydoc.py \ - third_party/python/Lib/queue.py \ - third_party/python/Lib/quopri.py \ - third_party/python/Lib/random.py \ - third_party/python/Lib/re.py \ - third_party/python/Lib/reprlib.py \ - third_party/python/Lib/rlcompleter.py \ - third_party/python/Lib/runpy.py \ - third_party/python/Lib/sched.py \ - third_party/python/Lib/secrets.py \ - third_party/python/Lib/selectors.py \ - third_party/python/Lib/shelve.py \ - third_party/python/Lib/shlex.py \ - third_party/python/Lib/shutil.py \ - third_party/python/Lib/signal.py \ - third_party/python/Lib/site.py \ - third_party/python/Lib/smtpd.py \ - third_party/python/Lib/smtplib.py \ - third_party/python/Lib/sndhdr.py \ - third_party/python/Lib/socket.py \ - third_party/python/Lib/socketserver.py \ - third_party/python/Lib/sqlite3/__init__.py \ - third_party/python/Lib/sqlite3/dbapi2.py \ - third_party/python/Lib/sqlite3/dump.py \ - third_party/python/Lib/sre_compile.py \ - third_party/python/Lib/sre_constants.py \ - third_party/python/Lib/sre_parse.py \ - third_party/python/Lib/ssl.py \ - third_party/python/Lib/stat.py \ - third_party/python/Lib/statistics.py \ - third_party/python/Lib/string.py \ - third_party/python/Lib/stringprep.py \ - third_party/python/Lib/struct.py \ - third_party/python/Lib/subprocess.py \ - third_party/python/Lib/sunau.py \ - third_party/python/Lib/symbol.py \ - third_party/python/Lib/symtable.py \ - third_party/python/Lib/sysconfig.py \ - third_party/python/Lib/tabnanny.py \ - third_party/python/Lib/tarfile.py \ - third_party/python/Lib/telnetlib.py \ - third_party/python/Lib/tempfile.py \ - third_party/python/Lib/textwrap.py \ - third_party/python/Lib/this.py \ - third_party/python/Lib/threading.py \ - third_party/python/Lib/timeit.py \ - third_party/python/Lib/token.py \ - third_party/python/Lib/tokenize.py \ - third_party/python/Lib/trace.py \ - third_party/python/Lib/traceback.py \ - third_party/python/Lib/tracemalloc.py \ - third_party/python/Lib/tty.py \ - third_party/python/Lib/types.py \ - third_party/python/Lib/typing.py \ - third_party/python/Lib/unittest/__init__.py \ - third_party/python/Lib/unittest/__main__.py \ - third_party/python/Lib/unittest/case.py \ - third_party/python/Lib/unittest/loader.py \ - third_party/python/Lib/unittest/main.py \ - third_party/python/Lib/unittest/mock.py \ - third_party/python/Lib/unittest/result.py \ - third_party/python/Lib/unittest/runner.py \ - third_party/python/Lib/unittest/signals.py \ - third_party/python/Lib/unittest/suite.py \ - third_party/python/Lib/unittest/util.py \ - third_party/python/Lib/urllib/__init__.py \ - third_party/python/Lib/urllib/error.py \ - third_party/python/Lib/urllib/parse.py \ - third_party/python/Lib/urllib/request.py \ - third_party/python/Lib/urllib/response.py \ - third_party/python/Lib/urllib/robotparser.py \ - third_party/python/Lib/uu.py \ - third_party/python/Lib/uuid.py \ - third_party/python/Lib/venv/__init__.py \ - third_party/python/Lib/venv/__main__.py \ - third_party/python/Lib/venv/scripts/common/activate \ - third_party/python/Lib/venv/scripts/nt/Activate.ps1 \ - third_party/python/Lib/venv/scripts/nt/activate.bat \ - third_party/python/Lib/venv/scripts/nt/deactivate.bat \ - third_party/python/Lib/venv/scripts/posix/activate.csh \ - third_party/python/Lib/venv/scripts/posix/activate.fish \ - third_party/python/Lib/warnings.py \ - third_party/python/Lib/wave.py \ - third_party/python/Lib/weakref.py \ - third_party/python/Lib/webbrowser.py \ - third_party/python/Lib/wsgiref/__init__.py \ - third_party/python/Lib/wsgiref/handlers.py \ - third_party/python/Lib/wsgiref/headers.py \ - third_party/python/Lib/wsgiref/simple_server.py \ - third_party/python/Lib/wsgiref/util.py \ - third_party/python/Lib/wsgiref/validate.py \ - third_party/python/Lib/xdrlib.py \ - third_party/python/Lib/xml/__init__.py \ - third_party/python/Lib/xml/dom/NodeFilter.py \ - third_party/python/Lib/xml/dom/__init__.py \ - third_party/python/Lib/xml/dom/domreg.py \ - third_party/python/Lib/xml/dom/expatbuilder.py \ - third_party/python/Lib/xml/dom/minicompat.py \ - third_party/python/Lib/xml/dom/minidom.py \ - third_party/python/Lib/xml/dom/pulldom.py \ - third_party/python/Lib/xml/dom/xmlbuilder.py \ - third_party/python/Lib/xml/etree/ElementInclude.py \ - third_party/python/Lib/xml/etree/ElementPath.py \ - third_party/python/Lib/xml/etree/ElementTree.py \ - third_party/python/Lib/xml/etree/__init__.py \ - third_party/python/Lib/xml/etree/cElementTree.py \ - third_party/python/Lib/xml/parsers/__init__.py \ - third_party/python/Lib/xml/parsers/expat.py \ - third_party/python/Lib/xml/sax/__init__.py \ - third_party/python/Lib/xml/sax/_exceptions.py \ - third_party/python/Lib/xml/sax/expatreader.py \ - third_party/python/Lib/xml/sax/handler.py \ - third_party/python/Lib/xml/sax/saxutils.py \ - third_party/python/Lib/xml/sax/xmlreader.py \ - third_party/python/Lib/xmlrpc/__init__.py \ - third_party/python/Lib/xmlrpc/client.py \ - third_party/python/Lib/xmlrpc/server.py \ - third_party/python/Lib/zipapp.py \ + third_party/python/Lib/_threading_local.py \ + third_party/python/Lib/_weakrefset.py \ + third_party/python/Lib/abc.py \ + third_party/python/Lib/aifc.py \ + third_party/python/Lib/antigravity.py \ + third_party/python/Lib/argparse.py \ + third_party/python/Lib/ast.py \ + third_party/python/Lib/base64.py \ + third_party/python/Lib/bdb.py \ + third_party/python/Lib/binhex.py \ + third_party/python/Lib/bisect.py \ + third_party/python/Lib/bz2.py \ + third_party/python/Lib/cProfile.py \ + third_party/python/Lib/calendar.py \ + third_party/python/Lib/cgi.py \ + third_party/python/Lib/cgitb.py \ + third_party/python/Lib/chunk.py \ + third_party/python/Lib/cmd.py \ + third_party/python/Lib/code.py \ + third_party/python/Lib/codecs.py \ + third_party/python/Lib/codeop.py \ + third_party/python/Lib/collections/__init__.py \ + third_party/python/Lib/collections/abc.py \ + third_party/python/Lib/colorsys.py \ + third_party/python/Lib/compileall.py \ + third_party/python/Lib/configparser.py \ + third_party/python/Lib/contextlib.py \ + third_party/python/Lib/copy.py \ + third_party/python/Lib/copyreg.py \ + third_party/python/Lib/crypt.py \ + third_party/python/Lib/csv.py \ + third_party/python/Lib/datetime.py \ + third_party/python/Lib/dbm/__init__.py \ + third_party/python/Lib/dbm/dumb.py \ + third_party/python/Lib/dbm/gnu.py \ + third_party/python/Lib/dbm/ndbm.py \ + third_party/python/Lib/decimal.py \ + third_party/python/Lib/difflib.py \ + third_party/python/Lib/dis.py \ + third_party/python/Lib/doctest.py \ + third_party/python/Lib/dummy_threading.py \ + third_party/python/Lib/email/__init__.py \ + third_party/python/Lib/email/_encoded_words.py \ + third_party/python/Lib/email/_header_value_parser.py \ + third_party/python/Lib/email/_parseaddr.py \ + third_party/python/Lib/email/_policybase.py \ + third_party/python/Lib/email/architecture.rst \ + third_party/python/Lib/email/base64mime.py \ + third_party/python/Lib/email/charset.py \ + third_party/python/Lib/email/contentmanager.py \ + third_party/python/Lib/email/encoders.py \ + third_party/python/Lib/email/errors.py \ + third_party/python/Lib/email/feedparser.py \ + third_party/python/Lib/email/generator.py \ + third_party/python/Lib/email/header.py \ + third_party/python/Lib/email/headerregistry.py \ + third_party/python/Lib/email/iterators.py \ + third_party/python/Lib/email/message.py \ + third_party/python/Lib/email/mime/__init__.py \ + third_party/python/Lib/email/mime/application.py \ + third_party/python/Lib/email/mime/audio.py \ + third_party/python/Lib/email/mime/base.py \ + third_party/python/Lib/email/mime/image.py \ + third_party/python/Lib/email/mime/message.py \ + third_party/python/Lib/email/mime/multipart.py \ + third_party/python/Lib/email/mime/nonmultipart.py \ + third_party/python/Lib/email/mime/text.py \ + third_party/python/Lib/email/parser.py \ + third_party/python/Lib/email/policy.py \ + third_party/python/Lib/email/quoprimime.py \ + third_party/python/Lib/email/utils.py \ + third_party/python/Lib/encodings/__init__.py \ + third_party/python/Lib/encodings/aliases.py \ + third_party/python/Lib/encodings/ascii.py \ + third_party/python/Lib/encodings/base64_codec.py \ + third_party/python/Lib/encodings/big5.py \ + third_party/python/Lib/encodings/big5hkscs.py \ + third_party/python/Lib/encodings/bz2_codec.py \ + third_party/python/Lib/encodings/charmap.py \ + third_party/python/Lib/encodings/cp037.py \ + third_party/python/Lib/encodings/cp1006.py \ + third_party/python/Lib/encodings/cp1026.py \ + third_party/python/Lib/encodings/cp1125.py \ + third_party/python/Lib/encodings/cp1140.py \ + third_party/python/Lib/encodings/cp1250.py \ + third_party/python/Lib/encodings/cp1251.py \ + third_party/python/Lib/encodings/cp1252.py \ + third_party/python/Lib/encodings/cp1253.py \ + third_party/python/Lib/encodings/cp1254.py \ + third_party/python/Lib/encodings/cp1255.py \ + third_party/python/Lib/encodings/cp1256.py \ + third_party/python/Lib/encodings/cp1257.py \ + third_party/python/Lib/encodings/cp1258.py \ + third_party/python/Lib/encodings/cp273.py \ + third_party/python/Lib/encodings/cp424.py \ + third_party/python/Lib/encodings/cp437.py \ + third_party/python/Lib/encodings/cp500.py \ + third_party/python/Lib/encodings/cp65001.py \ + third_party/python/Lib/encodings/cp720.py \ + third_party/python/Lib/encodings/cp737.py \ + third_party/python/Lib/encodings/cp775.py \ + third_party/python/Lib/encodings/cp850.py \ + third_party/python/Lib/encodings/cp852.py \ + third_party/python/Lib/encodings/cp855.py \ + third_party/python/Lib/encodings/cp856.py \ + third_party/python/Lib/encodings/cp857.py \ + third_party/python/Lib/encodings/cp858.py \ + third_party/python/Lib/encodings/cp860.py \ + third_party/python/Lib/encodings/cp861.py \ + third_party/python/Lib/encodings/cp862.py \ + third_party/python/Lib/encodings/cp863.py \ + third_party/python/Lib/encodings/cp864.py \ + third_party/python/Lib/encodings/cp865.py \ + third_party/python/Lib/encodings/cp866.py \ + third_party/python/Lib/encodings/cp869.py \ + third_party/python/Lib/encodings/cp874.py \ + third_party/python/Lib/encodings/cp875.py \ + third_party/python/Lib/encodings/cp932.py \ + third_party/python/Lib/encodings/cp949.py \ + third_party/python/Lib/encodings/cp950.py \ + third_party/python/Lib/encodings/euc_jis_2004.py \ + third_party/python/Lib/encodings/euc_jisx0213.py \ + third_party/python/Lib/encodings/euc_jp.py \ + third_party/python/Lib/encodings/euc_kr.py \ + third_party/python/Lib/encodings/gb18030.py \ + third_party/python/Lib/encodings/gb2312.py \ + third_party/python/Lib/encodings/gbk.py \ + third_party/python/Lib/encodings/hex_codec.py \ + third_party/python/Lib/encodings/hp_roman8.py \ + third_party/python/Lib/encodings/hz.py \ + third_party/python/Lib/encodings/idna.py \ + third_party/python/Lib/encodings/iso2022_jp.py \ + third_party/python/Lib/encodings/iso2022_jp_1.py \ + third_party/python/Lib/encodings/iso2022_jp_2.py \ + third_party/python/Lib/encodings/iso2022_jp_2004.py \ + third_party/python/Lib/encodings/iso2022_jp_3.py \ + third_party/python/Lib/encodings/iso2022_jp_ext.py \ + third_party/python/Lib/encodings/iso2022_kr.py \ + third_party/python/Lib/encodings/iso8859_1.py \ + third_party/python/Lib/encodings/iso8859_10.py \ + third_party/python/Lib/encodings/iso8859_11.py \ + third_party/python/Lib/encodings/iso8859_13.py \ + third_party/python/Lib/encodings/iso8859_14.py \ + third_party/python/Lib/encodings/iso8859_15.py \ + third_party/python/Lib/encodings/iso8859_16.py \ + third_party/python/Lib/encodings/iso8859_2.py \ + third_party/python/Lib/encodings/iso8859_3.py \ + third_party/python/Lib/encodings/iso8859_4.py \ + third_party/python/Lib/encodings/iso8859_5.py \ + third_party/python/Lib/encodings/iso8859_6.py \ + third_party/python/Lib/encodings/iso8859_7.py \ + third_party/python/Lib/encodings/iso8859_8.py \ + third_party/python/Lib/encodings/iso8859_9.py \ + third_party/python/Lib/encodings/johab.py \ + third_party/python/Lib/encodings/koi8_r.py \ + third_party/python/Lib/encodings/koi8_t.py \ + third_party/python/Lib/encodings/koi8_u.py \ + third_party/python/Lib/encodings/kz1048.py \ + third_party/python/Lib/encodings/latin_1.py \ + third_party/python/Lib/encodings/mac_arabic.py \ + third_party/python/Lib/encodings/mac_centeuro.py \ + third_party/python/Lib/encodings/mac_croatian.py \ + third_party/python/Lib/encodings/mac_cyrillic.py \ + third_party/python/Lib/encodings/mac_farsi.py \ + third_party/python/Lib/encodings/mac_greek.py \ + third_party/python/Lib/encodings/mac_iceland.py \ + third_party/python/Lib/encodings/mac_latin2.py \ + third_party/python/Lib/encodings/mac_roman.py \ + third_party/python/Lib/encodings/mac_romanian.py \ + third_party/python/Lib/encodings/mac_turkish.py \ + third_party/python/Lib/encodings/mbcs.py \ + third_party/python/Lib/encodings/oem.py \ + third_party/python/Lib/encodings/palmos.py \ + third_party/python/Lib/encodings/ptcp154.py \ + third_party/python/Lib/encodings/punycode.py \ + third_party/python/Lib/encodings/quopri_codec.py \ + third_party/python/Lib/encodings/raw_unicode_escape.py \ + third_party/python/Lib/encodings/rot_13.py \ + third_party/python/Lib/encodings/shift_jis.py \ + third_party/python/Lib/encodings/shift_jis_2004.py \ + third_party/python/Lib/encodings/shift_jisx0213.py \ + third_party/python/Lib/encodings/tis_620.py \ + third_party/python/Lib/encodings/undefined.py \ + third_party/python/Lib/encodings/unicode_escape.py \ + third_party/python/Lib/encodings/unicode_internal.py \ + third_party/python/Lib/encodings/utf_16.py \ + third_party/python/Lib/encodings/utf_16_be.py \ + third_party/python/Lib/encodings/utf_16_le.py \ + third_party/python/Lib/encodings/utf_32.py \ + third_party/python/Lib/encodings/utf_32_be.py \ + third_party/python/Lib/encodings/utf_32_le.py \ + third_party/python/Lib/encodings/utf_7.py \ + third_party/python/Lib/encodings/utf_8.py \ + third_party/python/Lib/encodings/utf_8_sig.py \ + third_party/python/Lib/encodings/uu_codec.py \ + third_party/python/Lib/encodings/zlib_codec.py \ + third_party/python/Lib/enum.py \ + third_party/python/Lib/filecmp.py \ + third_party/python/Lib/fileinput.py \ + third_party/python/Lib/fnmatch.py \ + third_party/python/Lib/formatter.py \ + third_party/python/Lib/fractions.py \ + third_party/python/Lib/ftplib.py \ + third_party/python/Lib/functools.py \ + third_party/python/Lib/genericpath.py \ + third_party/python/Lib/getopt.py \ + third_party/python/Lib/getpass.py \ + third_party/python/Lib/gettext.py \ + third_party/python/Lib/glob.py \ + third_party/python/Lib/gzip.py \ + third_party/python/Lib/hashlib.py \ + third_party/python/Lib/heapq.py \ + third_party/python/Lib/hmac.py \ + third_party/python/Lib/html/__init__.py \ + third_party/python/Lib/html/entities.py \ + third_party/python/Lib/html/parser.py \ + third_party/python/Lib/http/__init__.py \ + third_party/python/Lib/http/client.py \ + third_party/python/Lib/http/cookiejar.py \ + third_party/python/Lib/http/cookies.py \ + third_party/python/Lib/http/server.py \ + third_party/python/Lib/imaplib.py \ + third_party/python/Lib/imghdr.py \ + third_party/python/Lib/imp.py \ + third_party/python/Lib/importlib/__init__.py \ + third_party/python/Lib/importlib/_bootstrap.py \ + third_party/python/Lib/importlib/_bootstrap_external.py \ + third_party/python/Lib/importlib/abc.py \ + third_party/python/Lib/importlib/machinery.py \ + third_party/python/Lib/importlib/util.py \ + third_party/python/Lib/inspect.py \ + third_party/python/Lib/io.py \ + third_party/python/Lib/ipaddress.py \ + third_party/python/Lib/json/__init__.py \ + third_party/python/Lib/json/decoder.py \ + third_party/python/Lib/json/encoder.py \ + third_party/python/Lib/json/scanner.py \ + third_party/python/Lib/json/tool.py \ + third_party/python/Lib/keyword.py \ + third_party/python/Lib/lib2to3/Grammar.txt \ + third_party/python/Lib/lib2to3/PatternGrammar.txt \ + third_party/python/Lib/lib2to3/__init__.py \ + third_party/python/Lib/lib2to3/__main__.py \ + third_party/python/Lib/lib2to3/btm_matcher.py \ + third_party/python/Lib/lib2to3/btm_utils.py \ + third_party/python/Lib/lib2to3/fixer_base.py \ + third_party/python/Lib/lib2to3/fixer_util.py \ + third_party/python/Lib/lib2to3/fixes/__init__.py \ + third_party/python/Lib/lib2to3/fixes/fix_apply.py \ + third_party/python/Lib/lib2to3/fixes/fix_asserts.py \ + third_party/python/Lib/lib2to3/fixes/fix_basestring.py \ + third_party/python/Lib/lib2to3/fixes/fix_buffer.py \ + third_party/python/Lib/lib2to3/fixes/fix_dict.py \ + third_party/python/Lib/lib2to3/fixes/fix_except.py \ + third_party/python/Lib/lib2to3/fixes/fix_exec.py \ + third_party/python/Lib/lib2to3/fixes/fix_execfile.py \ + third_party/python/Lib/lib2to3/fixes/fix_exitfunc.py \ + third_party/python/Lib/lib2to3/fixes/fix_filter.py \ + third_party/python/Lib/lib2to3/fixes/fix_funcattrs.py \ + third_party/python/Lib/lib2to3/fixes/fix_future.py \ + third_party/python/Lib/lib2to3/fixes/fix_getcwdu.py \ + third_party/python/Lib/lib2to3/fixes/fix_has_key.py \ + third_party/python/Lib/lib2to3/fixes/fix_idioms.py \ + third_party/python/Lib/lib2to3/fixes/fix_import.py \ + third_party/python/Lib/lib2to3/fixes/fix_imports.py \ + third_party/python/Lib/lib2to3/fixes/fix_imports2.py \ + third_party/python/Lib/lib2to3/fixes/fix_input.py \ + third_party/python/Lib/lib2to3/fixes/fix_intern.py \ + third_party/python/Lib/lib2to3/fixes/fix_isinstance.py \ + third_party/python/Lib/lib2to3/fixes/fix_itertools.py \ + third_party/python/Lib/lib2to3/fixes/fix_itertools_imports.py \ + third_party/python/Lib/lib2to3/fixes/fix_long.py \ + third_party/python/Lib/lib2to3/fixes/fix_map.py \ + third_party/python/Lib/lib2to3/fixes/fix_metaclass.py \ + third_party/python/Lib/lib2to3/fixes/fix_methodattrs.py \ + third_party/python/Lib/lib2to3/fixes/fix_ne.py \ + third_party/python/Lib/lib2to3/fixes/fix_next.py \ + third_party/python/Lib/lib2to3/fixes/fix_nonzero.py \ + third_party/python/Lib/lib2to3/fixes/fix_numliterals.py \ + third_party/python/Lib/lib2to3/fixes/fix_operator.py \ + third_party/python/Lib/lib2to3/fixes/fix_paren.py \ + third_party/python/Lib/lib2to3/fixes/fix_print.py \ + third_party/python/Lib/lib2to3/fixes/fix_raise.py \ + third_party/python/Lib/lib2to3/fixes/fix_raw_input.py \ + third_party/python/Lib/lib2to3/fixes/fix_reduce.py \ + third_party/python/Lib/lib2to3/fixes/fix_reload.py \ + third_party/python/Lib/lib2to3/fixes/fix_renames.py \ + third_party/python/Lib/lib2to3/fixes/fix_repr.py \ + third_party/python/Lib/lib2to3/fixes/fix_set_literal.py \ + third_party/python/Lib/lib2to3/fixes/fix_standarderror.py \ + third_party/python/Lib/lib2to3/fixes/fix_sys_exc.py \ + third_party/python/Lib/lib2to3/fixes/fix_throw.py \ + third_party/python/Lib/lib2to3/fixes/fix_tuple_params.py \ + third_party/python/Lib/lib2to3/fixes/fix_types.py \ + third_party/python/Lib/lib2to3/fixes/fix_unicode.py \ + third_party/python/Lib/lib2to3/fixes/fix_urllib.py \ + third_party/python/Lib/lib2to3/fixes/fix_ws_comma.py \ + third_party/python/Lib/lib2to3/fixes/fix_xrange.py \ + third_party/python/Lib/lib2to3/fixes/fix_xreadlines.py \ + third_party/python/Lib/lib2to3/fixes/fix_zip.py \ + third_party/python/Lib/lib2to3/main.py \ + third_party/python/Lib/lib2to3/patcomp.py \ + third_party/python/Lib/lib2to3/pgen2/__init__.py \ + third_party/python/Lib/lib2to3/pgen2/conv.py \ + third_party/python/Lib/lib2to3/pgen2/driver.py \ + third_party/python/Lib/lib2to3/pgen2/grammar.py \ + third_party/python/Lib/lib2to3/pgen2/literals.py \ + third_party/python/Lib/lib2to3/pgen2/parse.py \ + third_party/python/Lib/lib2to3/pgen2/pgen.py \ + third_party/python/Lib/lib2to3/pgen2/token.py \ + third_party/python/Lib/lib2to3/pgen2/tokenize.py \ + third_party/python/Lib/lib2to3/pygram.py \ + third_party/python/Lib/lib2to3/pytree.py \ + third_party/python/Lib/lib2to3/refactor.py \ + third_party/python/Lib/linecache.py \ + third_party/python/Lib/locale.py \ + third_party/python/Lib/logging/__init__.py \ + third_party/python/Lib/logging/config.py \ + third_party/python/Lib/logging/handlers.py \ + third_party/python/Lib/lzma.py \ + third_party/python/Lib/macpath.py \ + third_party/python/Lib/macurl2path.py \ + third_party/python/Lib/mailbox.py \ + third_party/python/Lib/mailcap.py \ + third_party/python/Lib/mimetypes.py \ + third_party/python/Lib/modulefinder.py \ + third_party/python/Lib/msilib/__init__.py \ + third_party/python/Lib/msilib/schema.py \ + third_party/python/Lib/msilib/sequence.py \ + third_party/python/Lib/msilib/text.py \ + third_party/python/Lib/multiprocessing/__init__.py \ + third_party/python/Lib/multiprocessing/connection.py \ + third_party/python/Lib/multiprocessing/context.py \ + third_party/python/Lib/multiprocessing/dummy/__init__.py \ + third_party/python/Lib/multiprocessing/dummy/connection.py \ + third_party/python/Lib/multiprocessing/forkserver.py \ + third_party/python/Lib/multiprocessing/heap.py \ + third_party/python/Lib/multiprocessing/managers.py \ + third_party/python/Lib/multiprocessing/pool.py \ + third_party/python/Lib/multiprocessing/popen_fork.py \ + third_party/python/Lib/multiprocessing/popen_forkserver.py \ + third_party/python/Lib/multiprocessing/popen_spawn_posix.py \ + third_party/python/Lib/multiprocessing/popen_spawn_win32.py \ + third_party/python/Lib/multiprocessing/process.py \ + third_party/python/Lib/multiprocessing/queues.py \ + third_party/python/Lib/multiprocessing/reduction.py \ + third_party/python/Lib/multiprocessing/resource_sharer.py \ + third_party/python/Lib/multiprocessing/semaphore_tracker.py \ + third_party/python/Lib/multiprocessing/sharedctypes.py \ + third_party/python/Lib/multiprocessing/spawn.py \ + third_party/python/Lib/multiprocessing/synchronize.py \ + third_party/python/Lib/multiprocessing/util.py \ + third_party/python/Lib/netrc.py \ + third_party/python/Lib/nntplib.py \ + third_party/python/Lib/ntpath.py \ + third_party/python/Lib/nturl2path.py \ + third_party/python/Lib/numbers.py \ + third_party/python/Lib/opcode.py \ + third_party/python/Lib/operator.py \ + third_party/python/Lib/optparse.py \ + third_party/python/Lib/os.py \ + third_party/python/Lib/pathlib.py \ + third_party/python/Lib/pdb.py \ + third_party/python/Lib/pickle.py \ + third_party/python/Lib/pickletools.py \ + third_party/python/Lib/pipes.py \ + third_party/python/Lib/pkgutil.py \ + third_party/python/Lib/platform.py \ + third_party/python/Lib/plistlib.py \ + third_party/python/Lib/poplib.py \ + third_party/python/Lib/posixpath.py \ + third_party/python/Lib/pprint.py \ + third_party/python/Lib/profile.py \ + third_party/python/Lib/pstats.py \ + third_party/python/Lib/pty.py \ + third_party/python/Lib/py_compile.py \ + third_party/python/Lib/pyclbr.py \ + third_party/python/Lib/pydoc.py \ + third_party/python/Lib/queue.py \ + third_party/python/Lib/quopri.py \ + third_party/python/Lib/random.py \ + third_party/python/Lib/re.py \ + third_party/python/Lib/reprlib.py \ + third_party/python/Lib/rlcompleter.py \ + third_party/python/Lib/runpy.py \ + third_party/python/Lib/sched.py \ + third_party/python/Lib/secrets.py \ + third_party/python/Lib/selectors.py \ + third_party/python/Lib/shelve.py \ + third_party/python/Lib/shlex.py \ + third_party/python/Lib/shutil.py \ + third_party/python/Lib/signal.py \ + third_party/python/Lib/site.py \ + third_party/python/Lib/smtpd.py \ + third_party/python/Lib/smtplib.py \ + third_party/python/Lib/sndhdr.py \ + third_party/python/Lib/socket.py \ + third_party/python/Lib/socketserver.py \ + third_party/python/Lib/sqlite3/__init__.py \ + third_party/python/Lib/sqlite3/dbapi2.py \ + third_party/python/Lib/sqlite3/dump.py \ + third_party/python/Lib/sre_compile.py \ + third_party/python/Lib/sre_constants.py \ + third_party/python/Lib/sre_parse.py \ + third_party/python/Lib/ssl.py \ + third_party/python/Lib/stat.py \ + third_party/python/Lib/statistics.py \ + third_party/python/Lib/string.py \ + third_party/python/Lib/stringprep.py \ + third_party/python/Lib/struct.py \ + third_party/python/Lib/subprocess.py \ + third_party/python/Lib/sunau.py \ + third_party/python/Lib/symbol.py \ + third_party/python/Lib/symtable.py \ + third_party/python/Lib/sysconfig.py \ + third_party/python/Lib/tabnanny.py \ + third_party/python/Lib/tarfile.py \ + third_party/python/Lib/telnetlib.py \ + third_party/python/Lib/tempfile.py \ + third_party/python/Lib/textwrap.py \ + third_party/python/Lib/this.py \ + third_party/python/Lib/threading.py \ + third_party/python/Lib/timeit.py \ + third_party/python/Lib/token.py \ + third_party/python/Lib/tokenize.py \ + third_party/python/Lib/trace.py \ + third_party/python/Lib/traceback.py \ + third_party/python/Lib/tracemalloc.py \ + third_party/python/Lib/tty.py \ + third_party/python/Lib/types.py \ + third_party/python/Lib/typing.py \ + third_party/python/Lib/unittest/__init__.py \ + third_party/python/Lib/unittest/__main__.py \ + third_party/python/Lib/unittest/case.py \ + third_party/python/Lib/unittest/loader.py \ + third_party/python/Lib/unittest/main.py \ + third_party/python/Lib/unittest/mock.py \ + third_party/python/Lib/unittest/result.py \ + third_party/python/Lib/unittest/runner.py \ + third_party/python/Lib/unittest/signals.py \ + third_party/python/Lib/unittest/suite.py \ + third_party/python/Lib/unittest/util.py \ + third_party/python/Lib/urllib/__init__.py \ + third_party/python/Lib/urllib/error.py \ + third_party/python/Lib/urllib/parse.py \ + third_party/python/Lib/urllib/request.py \ + third_party/python/Lib/urllib/response.py \ + third_party/python/Lib/urllib/robotparser.py \ + third_party/python/Lib/uu.py \ + third_party/python/Lib/uuid.py \ + third_party/python/Lib/venv/__init__.py \ + third_party/python/Lib/venv/__main__.py \ + third_party/python/Lib/venv/scripts/common/activate \ + third_party/python/Lib/venv/scripts/nt/Activate.ps1 \ + third_party/python/Lib/venv/scripts/nt/activate.bat \ + third_party/python/Lib/venv/scripts/nt/deactivate.bat \ + third_party/python/Lib/venv/scripts/posix/activate.csh \ + third_party/python/Lib/venv/scripts/posix/activate.fish \ + third_party/python/Lib/warnings.py \ + third_party/python/Lib/wave.py \ + third_party/python/Lib/weakref.py \ + third_party/python/Lib/webbrowser.py \ + third_party/python/Lib/wsgiref/__init__.py \ + third_party/python/Lib/wsgiref/handlers.py \ + third_party/python/Lib/wsgiref/headers.py \ + third_party/python/Lib/wsgiref/simple_server.py \ + third_party/python/Lib/wsgiref/util.py \ + third_party/python/Lib/wsgiref/validate.py \ + third_party/python/Lib/xdrlib.py \ + third_party/python/Lib/xml/__init__.py \ + third_party/python/Lib/xml/dom/NodeFilter.py \ + third_party/python/Lib/xml/dom/__init__.py \ + third_party/python/Lib/xml/dom/domreg.py \ + third_party/python/Lib/xml/dom/expatbuilder.py \ + third_party/python/Lib/xml/dom/minicompat.py \ + third_party/python/Lib/xml/dom/minidom.py \ + third_party/python/Lib/xml/dom/pulldom.py \ + third_party/python/Lib/xml/dom/xmlbuilder.py \ + third_party/python/Lib/xml/etree/ElementInclude.py \ + third_party/python/Lib/xml/etree/ElementPath.py \ + third_party/python/Lib/xml/etree/ElementTree.py \ + third_party/python/Lib/xml/etree/__init__.py \ + third_party/python/Lib/xml/etree/cElementTree.py \ + third_party/python/Lib/xml/parsers/__init__.py \ + third_party/python/Lib/xml/parsers/expat.py \ + third_party/python/Lib/xml/sax/__init__.py \ + third_party/python/Lib/xml/sax/_exceptions.py \ + third_party/python/Lib/xml/sax/expatreader.py \ + third_party/python/Lib/xml/sax/handler.py \ + third_party/python/Lib/xml/sax/saxutils.py \ + third_party/python/Lib/xml/sax/xmlreader.py \ + third_party/python/Lib/xmlrpc/__init__.py \ + third_party/python/Lib/xmlrpc/client.py \ + third_party/python/Lib/xmlrpc/server.py \ + third_party/python/Lib/zipapp.py \ third_party/python/Lib/zipfile.py -THIRD_PARTY_PYTHON_STDLIB_PY_OBJS = \ +THIRD_PARTY_PYTHON_STDLIB_PY_OBJS = \ $(THIRD_PARTY_PYTHON_STDLIB_PY:%=o/$(MODE)/%.zip.o) + +$(THIRD_PARTY_PYTHON_STDLIB_PY_OBJS): \ + third_party/python/python-stdlib.mk + +#o/$(MODE)/third_party/python/Lib/%.py.zip.o: \ + ZIPOBJ_FLAGS += \ + -P.python \ + -C3 diff --git a/third_party/python/python.mk b/third_party/python/python.mk index 6b97e4312..e6dbbed38 100644 --- a/third_party/python/python.mk +++ b/third_party/python/python.mk @@ -10,214 +10,481 @@ THIRD_PARTY_PYTHON_A = o/$(MODE)/third_party/python/libpython3.6m.a include third_party/python/python-modules.mk include third_party/python/python-stdlib.mk -THIRD_PARTY_PYTHON_OBJECT_SRCS = \ - third_party/python/Objects/abstract.c \ - third_party/python/Objects/accu.c \ - third_party/python/Objects/boolobject.c \ - third_party/python/Objects/bytearrayobject.c \ - third_party/python/Objects/bytes_methods.c \ - third_party/python/Objects/bytesobject.c \ - third_party/python/Objects/capsule.c \ - third_party/python/Objects/cellobject.c \ - third_party/python/Objects/classobject.c \ - third_party/python/Objects/codeobject.c \ - third_party/python/Objects/complexobject.c \ - third_party/python/Objects/descrobject.c \ - third_party/python/Objects/dictobject.c \ - third_party/python/Objects/enumobject.c \ - third_party/python/Objects/exceptions.c \ - third_party/python/Objects/fileobject.c \ - third_party/python/Objects/floatobject.c \ - third_party/python/Objects/frameobject.c \ - third_party/python/Objects/funcobject.c \ - third_party/python/Objects/genobject.c \ - third_party/python/Objects/iterobject.c \ - third_party/python/Objects/listobject.c \ - third_party/python/Objects/longobject.c \ - third_party/python/Objects/memoryobject.c \ - third_party/python/Objects/methodobject.c \ - third_party/python/Objects/moduleobject.c \ - third_party/python/Objects/namespaceobject.c \ - third_party/python/Objects/object.c \ - third_party/python/Objects/obmalloc.c \ - third_party/python/Objects/odictobject.c \ - third_party/python/Objects/rangeobject.c \ - third_party/python/Objects/setobject.c \ - third_party/python/Objects/sliceobject.c \ - third_party/python/Objects/structseq.c \ - third_party/python/Objects/tupleobject.c \ - third_party/python/Objects/typeobject.c \ - third_party/python/Objects/unicodectype.c \ - third_party/python/Objects/unicodeobject.c \ +THIRD_PARTY_PYTHON_A_HDRS = \ + third_party/python/Include/object.h \ + third_party/python/Include/Python-ast.h \ + third_party/python/Include/Python.h \ + third_party/python/Include/abstract.h \ + third_party/python/Include/accu.h \ + third_party/python/Include/asdl.h \ + third_party/python/Include/ast.h \ + third_party/python/Include/bitset.h \ + third_party/python/Include/bltinmodule.h \ + third_party/python/Include/boolobject.h \ + third_party/python/Include/bytearrayobject.h \ + third_party/python/Include/bytes_methods.h \ + third_party/python/Include/bytesobject.h \ + third_party/python/Include/cellobject.h \ + third_party/python/Include/ceval.h \ + third_party/python/Include/classobject.h \ + third_party/python/Include/code.h \ + third_party/python/Include/codecs.h \ + third_party/python/Include/compile.h \ + third_party/python/Include/complexobject.h \ + third_party/python/Include/datetime.h \ + third_party/python/Include/descrobject.h \ + third_party/python/Include/dictobject.h \ + third_party/python/Include/dtoa.h \ + third_party/python/Include/dynamic_annotations.h \ + third_party/python/Include/enumobject.h \ + third_party/python/Include/errcode.h \ + third_party/python/Include/eval.h \ + third_party/python/Include/fileobject.h \ + third_party/python/Include/fileutils.h \ + third_party/python/Include/floatobject.h \ + third_party/python/Include/frameobject.h \ + third_party/python/Include/funcobject.h \ + third_party/python/Include/genobject.h \ + third_party/python/Include/graminit.h \ + third_party/python/Include/grammar.h \ + third_party/python/Include/import.h \ + third_party/python/Include/intrcheck.h \ + third_party/python/Include/iterobject.h \ + third_party/python/Include/listobject.h \ + third_party/python/Include/longintrepr.h \ + third_party/python/Include/longobject.h \ + third_party/python/Include/marshal.h \ + third_party/python/Include/memoryobject.h \ + third_party/python/Include/metagrammar.h \ + third_party/python/Include/methodobject.h \ + third_party/python/Include/modsupport.h \ + third_party/python/Include/moduleobject.h \ + third_party/python/Include/namespaceobject.h \ + third_party/python/Include/node.h \ + third_party/python/Include/objimpl.h \ + third_party/python/Include/odictobject.h \ + third_party/python/Include/op.h \ + third_party/python/Include/opcode.h \ + third_party/python/Include/osdefs.h \ + third_party/python/Include/osmodule.h \ + third_party/python/Include/parsetok.h \ + third_party/python/Include/patchlevel.h \ + third_party/python/Include/pgen.h \ + third_party/python/Include/pgenheaders.h \ + third_party/python/Include/pyarena.h \ + third_party/python/Include/pyatomic.h \ + third_party/python/Include/pycapsule.h \ + third_party/python/Include/pyctype.h \ + third_party/python/Include/pydebug.h \ + third_party/python/Include/pydtrace.h \ + third_party/python/Include/pyerrors.h \ + third_party/python/Include/pyexpat.h \ + third_party/python/Include/pyfpe.h \ + third_party/python/Include/pygetopt.h \ + third_party/python/Include/pyhash.h \ + third_party/python/Include/pylifecycle.h \ + third_party/python/Include/pymacro.h \ + third_party/python/Include/pymath.h \ + third_party/python/Include/pymem.h \ + third_party/python/Include/pyport.h \ + third_party/python/Include/pystate.h \ + third_party/python/Include/pystrcmp.h \ + third_party/python/Include/pystrhex.h \ + third_party/python/Include/pystrtod.h \ + third_party/python/Include/pythonrun.h \ + third_party/python/Include/pythread.h \ + third_party/python/Include/pytime.h \ + third_party/python/Include/rangeobject.h \ + third_party/python/Include/setobject.h \ + third_party/python/Include/sliceobject.h \ + third_party/python/Include/structmember.h \ + third_party/python/Include/structseq.h \ + third_party/python/Include/symtable.h \ + third_party/python/Include/sysmodule.h \ + third_party/python/Include/token.h \ + third_party/python/Include/traceback.h \ + third_party/python/Include/tupleobject.h \ + third_party/python/Include/typeslots.h \ + third_party/python/Include/ucnhash.h \ + third_party/python/Include/unicodeobject.h \ + third_party/python/Include/warnings.h \ + third_party/python/Include/weakrefobject.h \ + third_party/python/Modules/_decimal/docstrings.h \ + third_party/python/Modules/_decimal/libmpdec/basearith.h \ + third_party/python/Modules/_decimal/libmpdec/bits.h \ + third_party/python/Modules/_decimal/libmpdec/constants.h \ + third_party/python/Modules/_decimal/libmpdec/convolute.h \ + third_party/python/Modules/_decimal/libmpdec/crt.h \ + third_party/python/Modules/_decimal/libmpdec/difradix2.h \ + third_party/python/Modules/_decimal/libmpdec/fnt.h \ + third_party/python/Modules/_decimal/libmpdec/fourstep.h \ + third_party/python/Modules/_decimal/libmpdec/io.h \ + third_party/python/Modules/_decimal/libmpdec/mpalloc.h \ + third_party/python/Modules/_decimal/libmpdec/mpdecimal.h \ + third_party/python/Modules/_decimal/libmpdec/numbertheory.h \ + third_party/python/Modules/_decimal/libmpdec/sixstep.h \ + third_party/python/Modules/_decimal/libmpdec/transpose.h \ + third_party/python/Modules/_decimal/libmpdec/typearith.h \ + third_party/python/Modules/_decimal/libmpdec/umodarith.h \ + third_party/python/Modules/_io/_iomodule.h \ + third_party/python/Modules/_math.h \ + third_party/python/Modules/_multiprocessing/multiprocessing.h \ + third_party/python/Modules/_sqlite/cache.h \ + third_party/python/Modules/_sqlite/connection.h \ + third_party/python/Modules/_sqlite/cursor.h \ + third_party/python/Modules/_sqlite/microprotocols.h \ + third_party/python/Modules/_sqlite/module.h \ + third_party/python/Modules/_sqlite/prepare_protocol.h \ + third_party/python/Modules/_sqlite/row.h \ + third_party/python/Modules/_sqlite/statement.h \ + third_party/python/Modules/_sqlite/util.h \ + third_party/python/Modules/cjkcodecs/cjkcodecs.h \ + third_party/python/Modules/cjkcodecs/multibytecodec.h \ + third_party/python/Modules/expat/expat.h \ + third_party/python/Modules/expat/expat_config.h \ + third_party/python/Modules/expat/expat_external.h \ + third_party/python/Modules/expat/pyexpatns.h \ + third_party/python/Modules/expat/xmlrole.h \ + third_party/python/Modules/expat/xmltok.h \ + third_party/python/Modules/hashlib.h \ + third_party/python/Modules/hashtable.h \ + third_party/python/Modules/posixmodule.h \ + third_party/python/Modules/rotatingtree.h \ + third_party/python/Modules/socketmodule.h \ + third_party/python/Modules/sre.h \ + third_party/python/Modules/sre_constants.h \ + third_party/python/Modules/tkinter.h \ + third_party/python/Modules/winreparse.h \ + third_party/python/Objects/dict-common.h \ + third_party/python/Parser/parser.h \ + third_party/python/Parser/tokenizer.h \ + third_party/python/Python/condvar.h \ + third_party/python/Python/importdl.h \ + third_party/python/pyconfig.h + +THIRD_PARTY_PYTHON_A_INCS = \ + third_party/python/Objects/stringlib/localeutil.inc \ + third_party/python/Objects/stringlib/unicodedefs.inc \ + third_party/python/Objects/stringlib/replace.inc \ + third_party/python/Objects/stringlib/unicode_format.inc \ + third_party/python/Objects/stringlib/find_max_char.inc \ + third_party/python/Objects/stringlib/find.inc \ + third_party/python/Objects/stringlib/split.inc \ + third_party/python/Objects/stringlib/transmogrify.inc \ + third_party/python/Objects/stringlib/ucs1lib.inc \ + third_party/python/Objects/stringlib/count.inc \ + third_party/python/Objects/stringlib/undef.inc \ + third_party/python/Objects/stringlib/partition.inc \ + third_party/python/Objects/stringlib/ucs4lib.inc \ + third_party/python/Objects/stringlib/asciilib.inc \ + third_party/python/Objects/stringlib/eq.inc \ + third_party/python/Objects/stringlib/ucs2lib.inc \ + third_party/python/Objects/stringlib/join.inc \ + third_party/python/Objects/stringlib/fastsearch.inc \ + third_party/python/Objects/stringlib/ctype.inc \ + third_party/python/Objects/stringlib/codecs.inc \ + third_party/python/Objects/stringlib/stringdefs.inc \ + third_party/python/Objects/unicodetype_db.inc \ + third_party/python/Objects/clinic/bytearrayobject.inc \ + third_party/python/Objects/clinic/unicodeobject.inc \ + third_party/python/Objects/clinic/dictobject.inc \ + third_party/python/Objects/clinic/bytesobject.inc \ + third_party/python/Objects/typeslots.inc \ + third_party/python/Python/thread_pthread.inc \ + third_party/python/Python/opcode_targets.inc \ + third_party/python/Python/wordcode_helpers.inc \ + third_party/python/Python/ceval_gil.inc \ + third_party/python/Python/thread_nt.inc \ + third_party/python/Python/importlib_external.inc \ + third_party/python/Python/importlib.inc \ + third_party/python/Python/clinic/import.inc \ + third_party/python/Python/clinic/bltinmodule.inc \ + third_party/python/Modules/expat/asciitab.inc \ + third_party/python/Modules/expat/nametab.inc \ + third_party/python/Modules/expat/utf8tab.inc \ + third_party/python/Modules/expat/internal.inc \ + third_party/python/Modules/expat/ascii.inc \ + third_party/python/Modules/expat/xmltok_ns.inc \ + third_party/python/Modules/expat/xmltok_impl.inc \ + third_party/python/Modules/expat/siphash.inc \ + third_party/python/Modules/expat/latin1tab.inc \ + third_party/python/Modules/expat/xmltok_impl.h.inc \ + third_party/python/Modules/expat/iasciitab.inc \ + third_party/python/Modules/_ssl_data.inc \ + third_party/python/Modules/cjkcodecs/emu_jisx0213_2000.inc \ + third_party/python/Modules/cjkcodecs/alg_jisx0201.inc \ + third_party/python/Modules/cjkcodecs/mappings_hk.inc \ + third_party/python/Modules/cjkcodecs/mappings_cn.inc \ + third_party/python/Modules/cjkcodecs/mappings_jisx0213_pair.inc \ + third_party/python/Modules/cjkcodecs/mappings_kr.inc \ + third_party/python/Modules/cjkcodecs/mappings_jp.inc \ + third_party/python/Modules/cjkcodecs/mappings_tw.inc \ + third_party/python/Modules/cjkcodecs/clinic/multibytecodec.inc \ + third_party/python/Modules/sre_lib.inc \ + third_party/python/Modules/unicodename_db.inc \ + third_party/python/Modules/testcapi_long.inc \ + third_party/python/Modules/_io/clinic/bufferedio.inc \ + third_party/python/Modules/_io/clinic/bytesio.inc \ + third_party/python/Modules/_io/clinic/iobase.inc \ + third_party/python/Modules/_io/clinic/textio.inc \ + third_party/python/Modules/_io/clinic/fileio.inc \ + third_party/python/Modules/_io/clinic/stringio.inc \ + third_party/python/Modules/_io/clinic/winconsoleio.inc \ + third_party/python/Modules/_io/clinic/_iomodule.inc \ + third_party/python/Modules/clinic/arraymodule.inc \ + third_party/python/Modules/clinic/_datetimemodule.inc \ + third_party/python/Modules/clinic/_lzmamodule.inc \ + third_party/python/Modules/clinic/_weakref.inc \ + third_party/python/Modules/clinic/posixmodule.inc \ + third_party/python/Modules/clinic/_hashopenssl.inc \ + third_party/python/Modules/clinic/zlibmodule.inc \ + third_party/python/Modules/clinic/binascii.inc \ + third_party/python/Modules/clinic/_bz2module.inc \ + third_party/python/Modules/clinic/pyexpat.inc \ + third_party/python/Modules/clinic/_opcode.inc \ + third_party/python/Modules/clinic/_asynciomodule.inc \ + third_party/python/Modules/clinic/_ssl.inc \ + third_party/python/Modules/clinic/_codecsmodule.inc \ + third_party/python/Modules/clinic/unicodedata.inc \ + third_party/python/Modules/clinic/grpmodule.inc \ + third_party/python/Modules/clinic/sha512module.inc \ + third_party/python/Modules/clinic/spwdmodule.inc \ + third_party/python/Modules/clinic/signalmodule.inc \ + third_party/python/Modules/clinic/_cryptmodule.inc \ + third_party/python/Modules/clinic/fcntlmodule.inc \ + third_party/python/Modules/clinic/_dbmmodule.inc \ + third_party/python/Modules/clinic/sha1module.inc \ + third_party/python/Modules/clinic/_sre.inc \ + third_party/python/Modules/clinic/md5module.inc \ + third_party/python/Modules/clinic/_cursesmodule.inc \ + third_party/python/Modules/clinic/_winapi.inc \ + third_party/python/Modules/clinic/_gdbmmodule.inc \ + third_party/python/Modules/clinic/_pickle.inc \ + third_party/python/Modules/clinic/cmathmodule.inc \ + third_party/python/Modules/clinic/_elementtree.inc \ + third_party/python/Modules/clinic/pwdmodule.inc \ + third_party/python/Modules/clinic/audioop.inc \ + third_party/python/Modules/clinic/_tkinter.inc \ + third_party/python/Modules/clinic/sha256module.inc \ + third_party/python/Modules/unicodedata_db.inc + +THIRD_PARTY_PYTHON_OBJECTS_SRCS = \ + third_party/python/Objects/abstract.c \ + third_party/python/Objects/accu.c \ + third_party/python/Objects/boolobject.c \ + third_party/python/Objects/bytearrayobject.c \ + third_party/python/Objects/bytes_methods.c \ + third_party/python/Objects/bytesobject.c \ + third_party/python/Objects/capsule.c \ + third_party/python/Objects/cellobject.c \ + third_party/python/Objects/classobject.c \ + third_party/python/Objects/codeobject.c \ + third_party/python/Objects/complexobject.c \ + third_party/python/Objects/descrobject.c \ + third_party/python/Objects/dictobject.c \ + third_party/python/Objects/enumobject.c \ + third_party/python/Objects/exceptions.c \ + third_party/python/Objects/fileobject.c \ + third_party/python/Objects/floatobject.c \ + third_party/python/Objects/frameobject.c \ + third_party/python/Objects/funcobject.c \ + third_party/python/Objects/genobject.c \ + third_party/python/Objects/iterobject.c \ + third_party/python/Objects/listobject.c \ + third_party/python/Objects/longobject.c \ + third_party/python/Objects/memoryobject.c \ + third_party/python/Objects/methodobject.c \ + third_party/python/Objects/moduleobject.c \ + third_party/python/Objects/namespaceobject.c \ + third_party/python/Objects/object.c \ + third_party/python/Objects/obmalloc.c \ + third_party/python/Objects/odictobject.c \ + third_party/python/Objects/rangeobject.c \ + third_party/python/Objects/setobject.c \ + third_party/python/Objects/sliceobject.c \ + third_party/python/Objects/structseq.c \ + third_party/python/Objects/tupleobject.c \ + third_party/python/Objects/typeobject.c \ + third_party/python/Objects/unicodectype.c \ + third_party/python/Objects/unicodeobject.c \ third_party/python/Objects/weakrefobject.c -THIRD_PARTY_PYTHON_PARSER_SRCS = \ - third_party/python/Parser/acceler.c \ - third_party/python/Parser/bitset.c \ - third_party/python/Parser/firstsets.c \ - third_party/python/Parser/grammar.c \ - third_party/python/Parser/grammar1.c \ - third_party/python/Parser/listnode.c \ - third_party/python/Parser/metagrammar.c \ - third_party/python/Parser/myreadline.c \ - third_party/python/Parser/node.c \ - third_party/python/Parser/parser.c \ - third_party/python/Parser/parsetok.c \ - third_party/python/Parser/pgen.c \ +THIRD_PARTY_PYTHON_PARSER_SRCS = \ + third_party/python/Parser/acceler.c \ + third_party/python/Parser/bitset.c \ + third_party/python/Parser/firstsets.c \ + third_party/python/Parser/grammar.c \ + third_party/python/Parser/grammar1.c \ + third_party/python/Parser/listnode.c \ + third_party/python/Parser/metagrammar.c \ + third_party/python/Parser/myreadline.c \ + third_party/python/Parser/node.c \ + third_party/python/Parser/parser.c \ + third_party/python/Parser/parsetok.c \ + third_party/python/Parser/pgen.c \ third_party/python/Parser/tokenizer.c -THIRD_PARTY_PYTHON_CORE_SRCS = \ - third_party/python/Python/Python-ast.c \ - third_party/python/Python/_warnings.c \ - third_party/python/Python/asdl.c \ - third_party/python/Python/ast.c \ - third_party/python/Python/bltinmodule.c \ - third_party/python/Python/ceval.c \ - third_party/python/Python/codecs.c \ - third_party/python/Python/compile.c \ - third_party/python/Python/dtoa.c \ - third_party/python/Python/dynamic_annotations.c \ - third_party/python/Python/dynload_shlib.c \ - third_party/python/Python/errors.c \ - third_party/python/Python/fileutils.c \ - third_party/python/Python/formatter_unicode.c \ - third_party/python/Python/frozen.c \ - third_party/python/Python/frozenmain.c \ - third_party/python/Python/future.c \ - third_party/python/Python/getargs.c \ - third_party/python/Python/getcompiler.c \ - third_party/python/Python/getcopyright.c \ - third_party/python/Python/getopt.c \ - third_party/python/Python/getplatform.c \ - third_party/python/Python/getversion.c \ - third_party/python/Python/graminit.c \ - third_party/python/Python/import.c \ - third_party/python/Python/importdl.c \ - third_party/python/Python/marshal.c \ - third_party/python/Python/modsupport.c \ - third_party/python/Python/mysnprintf.c \ - third_party/python/Python/mystrtoul.c \ - third_party/python/Python/peephole.c \ - third_party/python/Python/pyarena.c \ - third_party/python/Python/pyctype.c \ - third_party/python/Python/pyfpe.c \ - third_party/python/Python/pyhash.c \ - third_party/python/Python/pylifecycle.c \ - third_party/python/Python/pymath.c \ - third_party/python/Python/pystate.c \ - third_party/python/Python/pystrcmp.c \ - third_party/python/Python/pystrhex.c \ - third_party/python/Python/pystrtod.c \ - third_party/python/Python/pythonrun.c \ - third_party/python/Python/pytime.c \ - third_party/python/Python/random.c \ - third_party/python/Python/sigcheck.c \ - third_party/python/Python/structmember.c \ - third_party/python/Python/symtable.c \ - third_party/python/Python/sysmodule.c \ +THIRD_PARTY_PYTHON_CORE_SRCS = \ + third_party/python/Python/Python-ast.c \ + third_party/python/Python/_warnings.c \ + third_party/python/Python/asdl.c \ + third_party/python/Python/ast.c \ + third_party/python/Python/bltinmodule.c \ + third_party/python/Python/ceval.c \ + third_party/python/Python/codecs.c \ + third_party/python/Python/compile.c \ + third_party/python/Python/dtoa.c \ + third_party/python/Python/dynamic_annotations.c \ + third_party/python/Python/dynload_shlib.c \ + third_party/python/Python/errors.c \ + third_party/python/Python/fileutils.c \ + third_party/python/Python/formatter_unicode.c \ + third_party/python/Python/frozen.c \ + third_party/python/Python/frozenmain.c \ + third_party/python/Python/future.c \ + third_party/python/Python/getargs.c \ + third_party/python/Python/getcompiler.c \ + third_party/python/Python/getcopyright.c \ + third_party/python/Python/getopt.c \ + third_party/python/Python/getplatform.c \ + third_party/python/Python/getversion.c \ + third_party/python/Python/graminit.c \ + third_party/python/Python/import.c \ + third_party/python/Python/importdl.c \ + third_party/python/Python/marshal.c \ + third_party/python/Python/modsupport.c \ + third_party/python/Python/mysnprintf.c \ + third_party/python/Python/mystrtoul.c \ + third_party/python/Python/peephole.c \ + third_party/python/Python/pyarena.c \ + third_party/python/Python/pyfpe.c \ + third_party/python/Python/pyhash.c \ + third_party/python/Python/pylifecycle.c \ + third_party/python/Python/pymath.c \ + third_party/python/Python/pystate.c \ + third_party/python/Python/pystrcmp.c \ + third_party/python/Python/pystrhex.c \ + third_party/python/Python/pystrtod.c \ + third_party/python/Python/pythonrun.c \ + third_party/python/Python/pytime.c \ + third_party/python/Python/random.c \ + third_party/python/Python/sigcheck.c \ + third_party/python/Python/structmember.c \ + third_party/python/Python/symtable.c \ + third_party/python/Python/sysmodule.c \ third_party/python/Python/traceback.c -THIRD_PARTY_PYTHON_SRCS_C = \ - third_party/python/Programs/python.c \ - $(THIRD_PARTY_PYTHON_OBJECT_SRCS) \ - $(THIRD_PARTY_PYTHON_PARSER_SRCS) \ - $(THIRD_PARTY_PYTHON_CORE_SRCS) \ +THIRD_PARTY_PYTHON_A_SRCS = \ + third_party/python/Programs/python.c \ + $(THIRD_PARTY_PYTHON_OBJECTS_SRCS) \ + $(THIRD_PARTY_PYTHON_PARSER_SRCS) \ + $(THIRD_PARTY_PYTHON_CORE_SRCS) \ $(THIRD_PARTY_PYTHON_MODULES_SRCS) -THIRD_PARTY_PYTHON_OBJS = \ - $(THIRD_PARTY_PYTHON_SRCS_C:%.c=o/$(MODE)/%.o) -THIRD_PARTY_PYTHON_A_OBJS = \ - $(filter-out o/$(MODE)/third_party/python/Programs/python.o,$(THIRD_PARTY_PYTHON_OBJS)) +THIRD_PARTY_PYTHON_A_OBJS = \ + $(THIRD_PARTY_PYTHON_A_SRCS:%.c=o/$(MODE)/%.o) -THIRD_PARTY_PYTHON_BINS = \ +THIRD_PARTY_PYTHON_BINS = \ $(THIRD_PARTY_PYTHON_COMS) $(THIRD_PARTY_PYTHON_COMS:%=%.dbg) -THIRD_PARTY_PYTHON_COMS = \ +THIRD_PARTY_PYTHON_COMS = \ o/$(MODE)/third_party/python/python.com -THIRD_PARTY_PYTHON_A_CHECKS = \ - $(THIRD_PARTY_PYTHON_A).pkg -# add .h.ok check here +THIRD_PARTY_PYTHON_A_CHECKS = \ + $(THIRD_PARTY_PYTHON_A).pkg \ + $(THIRD_PARTY_PYTHON_A_HDRS:%=o/$(MODE)/%.ok) -THIRD_PARTY_PYTHON_A_DIRECTDEPS0 = \ - $(THIRD_PARTY_PYTHON_MODULES_DIRECTDEPS) \ - LIBC_ALG \ - LIBC_BITS \ - LIBC_CALLS \ - LIBC_FMT \ - LIBC_INTRIN \ - LIBC_LOG \ - LIBC_MEM \ - LIBC_NEXGEN32E \ - LIBC_RAND \ - LIBC_RUNTIME \ - LIBC_SOCK \ - LIBC_DNS \ - LIBC_STDIO \ - LIBC_STR \ - LIBC_STUBS \ - LIBC_SYSV \ - LIBC_SYSV_CALLS \ - LIBC_TIME \ - LIBC_TINYMATH \ - LIBC_UNICODE \ - LIBC_ZIPOS \ - THIRD_PARTY_GDTOA \ - THIRD_PARTY_GETOPT \ - THIRD_PARTY_MUSL \ +THIRD_PARTY_PYTHON_A_DIRECTDEPS0 = \ + $(THIRD_PARTY_PYTHON_MODULES_DIRECTDEPS) \ + LIBC_ALG \ + LIBC_BITS \ + LIBC_CALLS \ + LIBC_FMT \ + LIBC_INTRIN \ + LIBC_LOG \ + LIBC_MEM \ + LIBC_NEXGEN32E \ + LIBC_RAND \ + LIBC_RUNTIME \ + LIBC_SOCK \ + LIBC_DNS \ + LIBC_STDIO \ + LIBC_STR \ + LIBC_STUBS \ + LIBC_SYSV \ + LIBC_SYSV_CALLS \ + LIBC_TIME \ + LIBC_TINYMATH \ + LIBC_UNICODE \ + LIBC_ZIPOS \ + THIRD_PARTY_GDTOA \ + THIRD_PARTY_GETOPT \ + THIRD_PARTY_MUSL \ THIRD_PARTY_ZLIB -THIRD_PARTY_PYTHON_A_DIRECTDEPS = \ +THIRD_PARTY_PYTHON_A_DIRECTDEPS = \ $(call uniq,$(THIRD_PARTY_PYTHON_A_DIRECTDEPS0)) -THIRD_PARTY_PYTHON_A_DEPS = \ +THIRD_PARTY_PYTHON_A_DEPS = \ $(call uniq,$(foreach x,$(THIRD_PARTY_PYTHON_A_DIRECTDEPS),$($(x)))) -o/$(MODE)/third_party/python/python.com.dbg: \ - $(THIRD_PARTY_PYTHON_A_DEPS) \ - $(THIRD_PARTY_PYTHON_A) \ - $(THIRD_PARTY_PYTHON_STDLIB_PY_OBJS) \ - o/$(MODE)/third_party/python/Programs/python.o \ - $(CRT) \ +o/$(MODE)/third_party/python/python.com.dbg: \ + $(THIRD_PARTY_PYTHON_A_DEPS) \ + $(THIRD_PARTY_PYTHON_A) \ + $(THIRD_PARTY_PYTHON_STDLIB_PY_OBJS) \ + o/$(MODE)/third_party/python/Programs/python.o \ + $(CRT) \ $(APE) -@$(APELINK) -$(THIRD_PARTY_PYTHON_A): \ - third_party/python \ - $(THIRD_PARTY_PYTHON_A).pkg \ +$(THIRD_PARTY_PYTHON_A): \ + third_party/python \ + $(THIRD_PARTY_PYTHON_A).pkg \ $(THIRD_PARTY_PYTHON_A_OBJS) -$(THIRD_PARTY_PYTHON_A).pkg: \ - $(THIRD_PARTY_PYTHON_A_OBJS) \ +$(THIRD_PARTY_PYTHON_A).pkg: \ + $(THIRD_PARTY_PYTHON_A_OBJS) \ $(foreach x,$(THIRD_PARTY_PYTHON_A_DIRECTDEPS),$($(x)_A).pkg) -$(THIRD_PARTY_PYTHON_OBJS): \ - OVERRIDE_CFLAGS += \ - -DNDEBUG \ - -DPy_BUILD_CORE \ - -DPLATFORM='"cosmo"' \ +$(THIRD_PARTY_PYTHON_A_OBJS): \ + OVERRIDE_CFLAGS += \ + -DNDEBUG \ + -DPy_BUILD_CORE \ + -DPLATFORM='"cosmo"' \ -DMULTIARCH='"x86_64-cosmo"' -o/$(MODE)/third_party/python/Programs/python.o \ -o/$(MODE)/third_party/python/Python/marshal.o \ -o/$(MODE)/third_party/python/Python/sysmodule.o \ -o/$(MODE)/third_party/python/Modules/selectmodule.o \ -o/$(MODE)/third_party/python/Modules/getpath.o \ -o/$(MODE)/third_party/python/Objects/listobject.o: \ - OVERRIDE_CFLAGS += \ +o/$(MODE)/third_party/python/Programs/python.o \ +o/$(MODE)/third_party/python/Python/marshal.o \ +o/$(MODE)/third_party/python/Python/sysmodule.o \ +o/$(MODE)/third_party/python/Modules/selectmodule.o \ +o/$(MODE)/third_party/python/Modules/getpath.o \ +o/$(MODE)/third_party/python/Objects/listobject.o: \ + OVERRIDE_CFLAGS += \ -DSTACK_FRAME_UNLIMITED -o/$(MODE)/third_party/python/Python/dynload_shlib.o: \ - OVERRIDE_CFLAGS += \ - -DSOABI='"cpython36m-x86_64-cosmopolitan"' +o/$(MODE)/third_party/python/Python/dynload_shlib.o: \ + OVERRIDE_CFLAGS += \ + -DSOABI='"cpython36m-x86_64-cosmo"' -o/$(MODE)/third_party/python/Python/sysmodule.o: \ - OVERRIDE_CFLAGS += \ +o/$(MODE)/third_party/python/Python/sysmodule.o: \ + OVERRIDE_CFLAGS += \ -DABIFLAGS='"m"' -$(THIRD_PARTY_PYTHON_OBJS): \ - third_party/python/python.mk \ +$(THIRD_PARTY_PYTHON_A_OBJS): \ + OVERRIDE_CFLAGS += \ + -ffunction-sections \ + -fdata-sections + +$(THIRD_PARTY_PYTHON_A_OBJS): \ + third_party/python/python.mk \ third_party/python/python-modules.mk +THIRD_PARTY_PYTHON_LIBS = $(foreach x,$(THIRD_PARTY_PYTHON_ARTIFACTS),$($(x))) +THIRD_PARTY_PYTHON_SRCS = $(foreach x,$(THIRD_PARTY_PYTHON_ARTIFACTS),$($(x)_SRCS)) +THIRD_PARTY_PYTHON_INCS = $(foreach x,$(THIRD_PARTY_PYTHON_ARTIFACTS),$($(x)_INCS)) +THIRD_PARTY_PYTHON_HDRS = $(foreach x,$(THIRD_PARTY_PYTHON_ARTIFACTS),$($(x)_HDRS)) +THIRD_PARTY_PYTHON_CHECKS = $(foreach x,$(THIRD_PARTY_PYTHON_ARTIFACTS),$($(x)_CHECKS)) +THIRD_PARTY_PYTHON_OBJS = $(foreach x,$(THIRD_PARTY_PYTHON_ARTIFACTS),$($(x)_OBJS)) + .PHONY: o/$(MODE)/third_party/python -o/$(MODE)/third_party/python: \ - $(THIRD_PARTY_PYTHON_BINS) \ +o/$(MODE)/third_party/python: \ + $(THIRD_PARTY_PYTHON_BINS) \ $(THIRD_PARTY_PYTHON_CHECKS) diff --git a/third_party/python/setup.py b/third_party/python/setup.py deleted file mode 100644 index e2c189825..000000000 --- a/third_party/python/setup.py +++ /dev/null @@ -1,2403 +0,0 @@ -# Autodetecting setup.py script for building the Python extensions -# - -import sys, os, importlib.machinery, re, optparse -from glob import glob -import importlib._bootstrap -import importlib.util -import sysconfig - -from distutils import log -from distutils.errors import * -from distutils.core import Extension, setup -from distutils.command.build_ext import build_ext -from distutils.command.install import install -from distutils.command.install_lib import install_lib -from distutils.command.build_scripts import build_scripts -from distutils.spawn import find_executable - -cross_compiling = "_PYTHON_HOST_PLATFORM" in os.environ - -# Set common compiler and linker flags derived from the Makefile, -# reserved for building the interpreter and the stdlib modules. -# See bpo-21121 and bpo-35257 -def set_compiler_flags(compiler_flags, compiler_py_flags_nodist): - flags = sysconfig.get_config_var(compiler_flags) - py_flags_nodist = sysconfig.get_config_var(compiler_py_flags_nodist) - sysconfig.get_config_vars()[compiler_flags] = flags + ' ' + py_flags_nodist - -set_compiler_flags('CFLAGS', 'PY_CFLAGS_NODIST') -set_compiler_flags('LDFLAGS', 'PY_LDFLAGS_NODIST') - -class Dummy: - """Hack for parallel build""" - ProcessPoolExecutor = None -sys.modules['concurrent.futures.process'] = Dummy - -def get_platform(): - # cross build - if "_PYTHON_HOST_PLATFORM" in os.environ: - return os.environ["_PYTHON_HOST_PLATFORM"] - # Get value of sys.platform - if sys.platform.startswith('osf1'): - return 'osf1' - return sys.platform -host_platform = get_platform() - -# Were we compiled --with-pydebug or with #define Py_DEBUG? -COMPILED_WITH_PYDEBUG = ('--with-pydebug' in sysconfig.get_config_var("CONFIG_ARGS")) - -# This global variable is used to hold the list of modules to be disabled. -disabled_module_list = [] - -def add_dir_to_list(dirlist, dir): - """Add the directory 'dir' to the list 'dirlist' (after any relative - directories) if: - - 1) 'dir' is not already in 'dirlist' - 2) 'dir' actually exists, and is a directory. - """ - if dir is None or not os.path.isdir(dir) or dir in dirlist: - return - for i, path in enumerate(dirlist): - if not os.path.isabs(path): - dirlist.insert(i + 1, dir) - return - dirlist.insert(0, dir) - -def sysroot_paths(make_vars, subdirs): - """Get the paths of sysroot sub-directories. - - * make_vars: a sequence of names of variables of the Makefile where - sysroot may be set. - * subdirs: a sequence of names of subdirectories used as the location for - headers or libraries. - """ - - dirs = [] - for var_name in make_vars: - var = sysconfig.get_config_var(var_name) - if var is not None: - m = re.search(r'--sysroot=([^"]\S*|"[^"]+")', var) - if m is not None: - sysroot = m.group(1).strip('"') - for subdir in subdirs: - if os.path.isabs(subdir): - subdir = subdir[1:] - path = os.path.join(sysroot, subdir) - if os.path.isdir(path): - dirs.append(path) - break - return dirs - -def macosx_sdk_root(): - """ - Return the directory of the current OSX SDK, - or '/' if no SDK was specified. - """ - cflags = sysconfig.get_config_var('CFLAGS') - m = re.search(r'-isysroot\s+(\S+)', cflags) - if m is None: - sysroot = '/' - else: - sysroot = m.group(1) - return sysroot - -def is_macosx_sdk_path(path): - """ - Returns True if 'path' can be located in an OSX SDK - """ - return ( (path.startswith('/usr/') and not path.startswith('/usr/local')) - or path.startswith('/System/') - or path.startswith('/Library/') ) - -def find_file(filename, std_dirs, paths): - """Searches for the directory where a given file is located, - and returns a possibly-empty list of additional directories, or None - if the file couldn't be found at all. - - 'filename' is the name of a file, such as readline.h or libcrypto.a. - 'std_dirs' is the list of standard system directories; if the - file is found in one of them, no additional directives are needed. - 'paths' is a list of additional locations to check; if the file is - found in one of them, the resulting list will contain the directory. - """ - if host_platform == 'darwin': - # Honor the MacOSX SDK setting when one was specified. - # An SDK is a directory with the same structure as a real - # system, but with only header files and libraries. - sysroot = macosx_sdk_root() - - # Check the standard locations - for dir in std_dirs: - f = os.path.join(dir, filename) - - if host_platform == 'darwin' and is_macosx_sdk_path(dir): - f = os.path.join(sysroot, dir[1:], filename) - - if os.path.exists(f): return [] - - # Check the additional directories - for dir in paths: - f = os.path.join(dir, filename) - - if host_platform == 'darwin' and is_macosx_sdk_path(dir): - f = os.path.join(sysroot, dir[1:], filename) - - if os.path.exists(f): - return [dir] - - # Not found anywhere - return None - -def find_library_file(compiler, libname, std_dirs, paths): - result = compiler.find_library_file(std_dirs + paths, libname) - if result is None: - return None - - if host_platform == 'darwin': - sysroot = macosx_sdk_root() - - # Check whether the found file is in one of the standard directories - dirname = os.path.dirname(result) - for p in std_dirs: - # Ensure path doesn't end with path separator - p = p.rstrip(os.sep) - - if host_platform == 'darwin' and is_macosx_sdk_path(p): - # Note that, as of Xcode 7, Apple SDKs may contain textual stub - # libraries with .tbd extensions rather than the normal .dylib - # shared libraries installed in /. The Apple compiler tool - # chain handles this transparently but it can cause problems - # for programs that are being built with an SDK and searching - # for specific libraries. Distutils find_library_file() now - # knows to also search for and return .tbd files. But callers - # of find_library_file need to keep in mind that the base filename - # of the returned SDK library file might have a different extension - # from that of the library file installed on the running system, - # for example: - # /Applications/Xcode.app/Contents/Developer/Platforms/ - # MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/ - # usr/lib/libedit.tbd - # vs - # /usr/lib/libedit.dylib - if os.path.join(sysroot, p[1:]) == dirname: - return [ ] - - if p == dirname: - return [ ] - - # Otherwise, it must have been in one of the additional directories, - # so we have to figure out which one. - for p in paths: - # Ensure path doesn't end with path separator - p = p.rstrip(os.sep) - - if host_platform == 'darwin' and is_macosx_sdk_path(p): - if os.path.join(sysroot, p[1:]) == dirname: - return [ p ] - - if p == dirname: - return [p] - else: - assert False, "Internal error: Path not found in std_dirs or paths" - -def module_enabled(extlist, modname): - """Returns whether the module 'modname' is present in the list - of extensions 'extlist'.""" - extlist = [ext for ext in extlist if ext.name == modname] - return len(extlist) - -def find_module_file(module, dirlist): - """Find a module in a set of possible folders. If it is not found - return the unadorned filename""" - list = find_file(module, [], dirlist) - if not list: - return module - if len(list) > 1: - log.info("WARNING: multiple copies of %s found", module) - return os.path.join(list[0], module) - -class PyBuildExt(build_ext): - - def __init__(self, dist): - build_ext.__init__(self, dist) - self.failed = [] - self.failed_on_import = [] - if '-j' in os.environ.get('MAKEFLAGS', ''): - self.parallel = True - - def build_extensions(self): - - # Detect which modules should be compiled - missing = self.detect_modules() - - # Remove modules that are present on the disabled list - extensions = [ext for ext in self.extensions - if ext.name not in disabled_module_list] - # move ctypes to the end, it depends on other modules - ext_map = dict((ext.name, i) for i, ext in enumerate(extensions)) - if "_ctypes" in ext_map: - ctypes = extensions.pop(ext_map["_ctypes"]) - extensions.append(ctypes) - self.extensions = extensions - - # Fix up the autodetected modules, prefixing all the source files - # with Modules/. - srcdir = sysconfig.get_config_var('srcdir') - if not srcdir: - # Maybe running on Windows but not using CYGWIN? - raise ValueError("No source directory; cannot proceed.") - srcdir = os.path.abspath(srcdir) - moddirlist = [os.path.join(srcdir, 'Modules')] - - # Fix up the paths for scripts, too - self.distribution.scripts = [os.path.join(srcdir, filename) - for filename in self.distribution.scripts] - - # Python header files - headers = [sysconfig.get_config_h_filename()] - headers += glob(os.path.join(sysconfig.get_path('include'), "*.h")) - - # The sysconfig variable built by makesetup, listing the already - # built modules as configured by the Setup files. - modnames = sysconfig.get_config_var('MODNAMES').split() - - removed_modules = [] - for ext in self.extensions: - ext.sources = [ find_module_file(filename, moddirlist) - for filename in ext.sources ] - if ext.depends is not None: - ext.depends = [find_module_file(filename, moddirlist) - for filename in ext.depends] - else: - ext.depends = [] - # re-compile extensions if a header file has been changed - ext.depends.extend(headers) - - # If a module has already been built by the Makefile, - # don't build it here. - if ext.name in modnames: - removed_modules.append(ext) - - if removed_modules: - self.extensions = [x for x in self.extensions if x not in - removed_modules] - - # When you run "make CC=altcc" or something similar, you really want - # those environment variables passed into the setup.py phase. Here's - # a small set of useful ones. - compiler = os.environ.get('CC') - args = {} - # unfortunately, distutils doesn't let us provide separate C and C++ - # compilers - if compiler is not None: - (ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS') - args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags - self.compiler.set_executables(**args) - - build_ext.build_extensions(self) - - for ext in self.extensions: - self.check_extension_import(ext) - - longest = max([len(e.name) for e in self.extensions], default=0) - if self.failed or self.failed_on_import: - all_failed = self.failed + self.failed_on_import - longest = max(longest, max([len(name) for name in all_failed])) - - def print_three_column(lst): - lst.sort(key=str.lower) - # guarantee zip() doesn't drop anything - while len(lst) % 3: - lst.append("") - for e, f, g in zip(lst[::3], lst[1::3], lst[2::3]): - print("%-*s %-*s %-*s" % (longest, e, longest, f, - longest, g)) - - if missing: - print() - print("Python build finished successfully!") - print("The necessary bits to build these optional modules were not " - "found:") - print_three_column(missing) - print("To find the necessary bits, look in setup.py in" - " detect_modules() for the module's name.") - print() - - if removed_modules: - print("The following modules found by detect_modules() in" - " setup.py, have been") - print("built by the Makefile instead, as configured by the" - " Setup files:") - print_three_column([ext.name for ext in removed_modules]) - - if self.failed: - failed = self.failed[:] - print() - print("Failed to build these modules:") - print_three_column(failed) - print() - - if self.failed_on_import: - failed = self.failed_on_import[:] - print() - print("Following modules built successfully" - " but were removed because they could not be imported:") - print_three_column(failed) - print() - - def build_extension(self, ext): - - if ext.name == '_ctypes': - if not self.configure_ctypes(ext): - return - - try: - build_ext.build_extension(self, ext) - except (CCompilerError, DistutilsError) as why: - self.announce('WARNING: building of extension "%s" failed: %s' % - (ext.name, sys.exc_info()[1])) - self.failed.append(ext.name) - return - - def check_extension_import(self, ext): - # Don't try to import an extension that has failed to compile - if ext.name in self.failed: - self.announce( - 'WARNING: skipping import check for failed build "%s"' % - ext.name, level=1) - return - - # Workaround for Mac OS X: The Carbon-based modules cannot be - # reliably imported into a command-line Python - if 'Carbon' in ext.extra_link_args: - self.announce( - 'WARNING: skipping import check for Carbon-based "%s"' % - ext.name) - return - - if host_platform == 'darwin' and ( - sys.maxsize > 2**32 and '-arch' in ext.extra_link_args): - # Don't bother doing an import check when an extension was - # build with an explicit '-arch' flag on OSX. That's currently - # only used to build 32-bit only extensions in a 4-way - # universal build and loading 32-bit code into a 64-bit - # process will fail. - self.announce( - 'WARNING: skipping import check for "%s"' % - ext.name) - return - - # Workaround for Cygwin: Cygwin currently has fork issues when many - # modules have been imported - if host_platform == 'cygwin': - self.announce('WARNING: skipping import check for Cygwin-based "%s"' - % ext.name) - return - ext_filename = os.path.join( - self.build_lib, - self.get_ext_filename(self.get_ext_fullname(ext.name))) - - # If the build directory didn't exist when setup.py was - # started, sys.path_importer_cache has a negative result - # cached. Clear that cache before trying to import. - sys.path_importer_cache.clear() - - # Don't try to load extensions for cross builds - if cross_compiling: - return - - loader = importlib.machinery.ExtensionFileLoader(ext.name, ext_filename) - spec = importlib.util.spec_from_file_location(ext.name, ext_filename, - loader=loader) - try: - importlib._bootstrap._load(spec) - except ImportError as why: - self.failed_on_import.append(ext.name) - self.announce('*** WARNING: renaming "%s" since importing it' - ' failed: %s' % (ext.name, why), level=3) - assert not self.inplace - basename, tail = os.path.splitext(ext_filename) - newname = basename + "_failed" + tail - if os.path.exists(newname): - os.remove(newname) - os.rename(ext_filename, newname) - - except: - exc_type, why, tb = sys.exc_info() - self.announce('*** WARNING: importing extension "%s" ' - 'failed with %s: %s' % (ext.name, exc_type, why), - level=3) - self.failed.append(ext.name) - - def add_multiarch_paths(self): - # Debian/Ubuntu multiarch support. - # https://wiki.ubuntu.com/MultiarchSpec - cc = sysconfig.get_config_var('CC') - tmpfile = os.path.join(self.build_temp, 'multiarch') - if not os.path.exists(self.build_temp): - os.makedirs(self.build_temp) - ret = os.system( - '%s -print-multiarch > %s 2> /dev/null' % (cc, tmpfile)) - multiarch_path_component = '' - try: - if ret >> 8 == 0: - with open(tmpfile) as fp: - multiarch_path_component = fp.readline().strip() - finally: - os.unlink(tmpfile) - - if multiarch_path_component != '': - add_dir_to_list(self.compiler.library_dirs, - '/usr/lib/' + multiarch_path_component) - add_dir_to_list(self.compiler.include_dirs, - '/usr/include/' + multiarch_path_component) - return - - if not find_executable('dpkg-architecture'): - return - opt = '' - if cross_compiling: - opt = '-t' + sysconfig.get_config_var('HOST_GNU_TYPE') - tmpfile = os.path.join(self.build_temp, 'multiarch') - if not os.path.exists(self.build_temp): - os.makedirs(self.build_temp) - ret = os.system( - 'dpkg-architecture %s -qDEB_HOST_MULTIARCH > %s 2> /dev/null' % - (opt, tmpfile)) - try: - if ret >> 8 == 0: - with open(tmpfile) as fp: - multiarch_path_component = fp.readline().strip() - add_dir_to_list(self.compiler.library_dirs, - '/usr/lib/' + multiarch_path_component) - add_dir_to_list(self.compiler.include_dirs, - '/usr/include/' + multiarch_path_component) - finally: - os.unlink(tmpfile) - - def add_gcc_paths(self): - gcc = sysconfig.get_config_var('CC') - tmpfile = os.path.join(self.build_temp, 'gccpaths') - if not os.path.exists(self.build_temp): - os.makedirs(self.build_temp) - ret = os.system('%s -E -v - %s 1>/dev/null' % (gcc, tmpfile)) - is_gcc = False - in_incdirs = False - inc_dirs = [] - lib_dirs = [] - try: - if ret >> 8 == 0: - with open(tmpfile) as fp: - for line in fp.readlines(): - if line.startswith("gcc version"): - is_gcc = True - elif line.startswith("#include <...>"): - in_incdirs = True - elif line.startswith("End of search list"): - in_incdirs = False - elif is_gcc and line.startswith("LIBRARY_PATH"): - for d in line.strip().split("=")[1].split(":"): - d = os.path.normpath(d) - if '/gcc/' not in d: - add_dir_to_list(self.compiler.library_dirs, - d) - elif is_gcc and in_incdirs and '/gcc/' not in line: - add_dir_to_list(self.compiler.include_dirs, - line.strip()) - finally: - os.unlink(tmpfile) - - def detect_math_libs(self): - # Check for MacOS X, which doesn't need libm.a at all - if host_platform == 'darwin': - return [] - else: - return ['m'] - - def detect_modules(self): - # Ensure that /usr/local is always used, but the local build - # directories (i.e. '.' and 'Include') must be first. See issue - # 10520. - if not cross_compiling: - add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') - add_dir_to_list(self.compiler.include_dirs, '/usr/local/include') - # only change this for cross builds for 3.3, issues on Mageia - if cross_compiling: - self.add_gcc_paths() - self.add_multiarch_paths() - - # Add paths specified in the environment variables LDFLAGS and - # CPPFLAGS for header and library files. - # We must get the values from the Makefile and not the environment - # directly since an inconsistently reproducible issue comes up where - # the environment variable is not set even though the value were passed - # into configure and stored in the Makefile (issue found on OS X 10.3). - for env_var, arg_name, dir_list in ( - ('LDFLAGS', '-R', self.compiler.runtime_library_dirs), - ('LDFLAGS', '-L', self.compiler.library_dirs), - ('CPPFLAGS', '-I', self.compiler.include_dirs)): - env_val = sysconfig.get_config_var(env_var) - if env_val: - # To prevent optparse from raising an exception about any - # options in env_val that it doesn't know about we strip out - # all double dashes and any dashes followed by a character - # that is not for the option we are dealing with. - # - # Please note that order of the regex is important! We must - # strip out double-dashes first so that we don't end up with - # substituting "--Long" to "-Long" and thus lead to "ong" being - # used for a library directory. - env_val = re.sub(r'(^|\s+)-(-|(?!%s))' % arg_name[1], - ' ', env_val) - parser = optparse.OptionParser() - # Make sure that allowing args interspersed with options is - # allowed - parser.allow_interspersed_args = True - parser.error = lambda msg: None - parser.add_option(arg_name, dest="dirs", action="append") - options = parser.parse_args(env_val.split())[0] - if options.dirs: - for directory in reversed(options.dirs): - add_dir_to_list(dir_list, directory) - - if (not cross_compiling and - os.path.normpath(sys.base_prefix) != '/usr' and - not sysconfig.get_config_var('PYTHONFRAMEWORK')): - # OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework - # (PYTHONFRAMEWORK is set) to avoid # linking problems when - # building a framework with different architectures than - # the one that is currently installed (issue #7473) - add_dir_to_list(self.compiler.library_dirs, - sysconfig.get_config_var("LIBDIR")) - add_dir_to_list(self.compiler.include_dirs, - sysconfig.get_config_var("INCLUDEDIR")) - - system_lib_dirs = ['/lib64', '/usr/lib64', '/lib', '/usr/lib'] - system_include_dirs = ['/usr/include'] - # lib_dirs and inc_dirs are used to search for files; - # if a file is found in one of those directories, it can - # be assumed that no additional -I,-L directives are needed. - if not cross_compiling: - lib_dirs = self.compiler.library_dirs + system_lib_dirs - inc_dirs = self.compiler.include_dirs + system_include_dirs - else: - # Add the sysroot paths. 'sysroot' is a compiler option used to - # set the logical path of the standard system headers and - # libraries. - lib_dirs = (self.compiler.library_dirs + - sysroot_paths(('LDFLAGS', 'CC'), system_lib_dirs)) - inc_dirs = (self.compiler.include_dirs + - sysroot_paths(('CPPFLAGS', 'CFLAGS', 'CC'), - system_include_dirs)) - exts = [] - missing = [] - - config_h = sysconfig.get_config_h_filename() - with open(config_h) as file: - config_h_vars = sysconfig.parse_config_h(file) - - srcdir = sysconfig.get_config_var('srcdir') - - # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb) - if host_platform in ['osf1', 'unixware7', 'openunix8']: - lib_dirs += ['/usr/ccs/lib'] - - # HP-UX11iv3 keeps files in lib/hpux folders. - if host_platform == 'hp-ux11': - lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32'] - - if host_platform == 'darwin': - # This should work on any unixy platform ;-) - # If the user has bothered specifying additional -I and -L flags - # in OPT and LDFLAGS we might as well use them here. - # - # NOTE: using shlex.split would technically be more correct, but - # also gives a bootstrap problem. Let's hope nobody uses - # directories with whitespace in the name to store libraries. - cflags, ldflags = sysconfig.get_config_vars( - 'CFLAGS', 'LDFLAGS') - for item in cflags.split(): - if item.startswith('-I'): - inc_dirs.append(item[2:]) - - for item in ldflags.split(): - if item.startswith('-L'): - lib_dirs.append(item[2:]) - - math_libs = self.detect_math_libs() - - # XXX Omitted modules: gl, pure, dl, SGI-specific modules - - # - # The following modules are all pretty straightforward, and compile - # on pretty much any POSIXish platform. - # - - # array objects - exts.append( Extension('array', ['arraymodule.c']) ) - - shared_math = 'Modules/_math.o' - # complex math library functions - exts.append( Extension('cmath', ['cmathmodule.c'], - extra_objects=[shared_math], - depends=['_math.h', shared_math], - libraries=math_libs) ) - # math library functions, e.g. sin() - exts.append( Extension('math', ['mathmodule.c'], - extra_objects=[shared_math], - depends=['_math.h', shared_math], - libraries=math_libs) ) - - # time libraries: librt may be needed for clock_gettime() - time_libs = [] - lib = sysconfig.get_config_var('TIMEMODULE_LIB') - if lib: - time_libs.append(lib) - - # time operations and variables - exts.append( Extension('time', ['timemodule.c'], - libraries=time_libs) ) - # math_libs is needed by delta_new() that uses round() and by accum() - # that uses modf(). - exts.append( Extension('_datetime', ['_datetimemodule.c'], - libraries=math_libs) ) - # random number generator implemented in C - exts.append( Extension("_random", ["_randommodule.c"]) ) - # bisect - exts.append( Extension("_bisect", ["_bisectmodule.c"]) ) - # heapq - exts.append( Extension("_heapq", ["_heapqmodule.c"]) ) - # C-optimized pickle replacement - exts.append( Extension("_pickle", ["_pickle.c"]) ) - # atexit - exts.append( Extension("atexit", ["atexitmodule.c"]) ) - # _json speedups - exts.append( Extension("_json", ["_json.c"]) ) - # Python C API test module - exts.append( Extension('_testcapi', ['_testcapimodule.c'], - depends=['testcapi_long.h']) ) - # Python PEP-3118 (buffer protocol) test module - exts.append( Extension('_testbuffer', ['_testbuffer.c']) ) - # Test loading multiple modules from one compiled file (http://bugs.python.org/issue16421) - exts.append( Extension('_testimportmultiple', ['_testimportmultiple.c']) ) - # Test multi-phase extension module init (PEP 489) - exts.append( Extension('_testmultiphase', ['_testmultiphase.c']) ) - # profiler (_lsprof is for cProfile.py) - exts.append( Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']) ) - # static Unicode character database - exts.append( Extension('unicodedata', ['unicodedata.c'], - depends=['unicodedata_db.h', 'unicodename_db.h']) ) - # _opcode module - exts.append( Extension('_opcode', ['_opcode.c']) ) - # asyncio speedups - exts.append( Extension("_asyncio", ["_asynciomodule.c"]) ) - - # Modules with some UNIX dependencies -- on by default: - # (If you have a really backward UNIX, select and socket may not be - # supported...) - - # fcntl(2) and ioctl(2) - libs = [] - if (config_h_vars.get('FLOCK_NEEDS_LIBBSD', False)): - # May be necessary on AIX for flock function - libs = ['bsd'] - exts.append( Extension('fcntl', ['fcntlmodule.c'], libraries=libs) ) - # pwd(3) - exts.append( Extension('pwd', ['pwdmodule.c']) ) - # grp(3) - exts.append( Extension('grp', ['grpmodule.c']) ) - # spwd, shadow passwords - if (config_h_vars.get('HAVE_GETSPNAM', False) or - config_h_vars.get('HAVE_GETSPENT', False)): - exts.append( Extension('spwd', ['spwdmodule.c']) ) - else: - missing.append('spwd') - - # select(2); not on ancient System V - exts.append( Extension('select', ['selectmodule.c']) ) - - # Fred Drake's interface to the Python parser - exts.append( Extension('parser', ['parsermodule.c']) ) - - # Memory-mapped files (also works on Win32). - exts.append( Extension('mmap', ['mmapmodule.c']) ) - - # Lance Ellinghaus's syslog module - # syslog daemon interface - exts.append( Extension('syslog', ['syslogmodule.c']) ) - - # - # Here ends the simple stuff. From here on, modules need certain - # libraries, are platform-specific, or present other surprises. - # - - # Multimedia modules - # These don't work for 64-bit platforms!!! - # These represent audio samples or images as strings: - # - # Operations on audio samples - # According to #993173, this one should actually work fine on - # 64-bit platforms. - # - # audioop needs math_libs for floor() in multiple functions. - exts.append( Extension('audioop', ['audioop.c'], - libraries=math_libs) ) - - # readline - do_readline = self.compiler.find_library_file(lib_dirs, 'readline') - readline_termcap_library = "" - curses_library = "" - # Cannot use os.popen here in py3k. - tmpfile = os.path.join(self.build_temp, 'readline_termcap_lib') - if not os.path.exists(self.build_temp): - os.makedirs(self.build_temp) - # Determine if readline is already linked against curses or tinfo. - if do_readline: - if cross_compiling: - ret = os.system("%s -d %s | grep '(NEEDED)' > %s" \ - % (sysconfig.get_config_var('READELF'), - do_readline, tmpfile)) - elif find_executable('ldd'): - ret = os.system("ldd %s > %s" % (do_readline, tmpfile)) - else: - ret = 256 - if ret >> 8 == 0: - with open(tmpfile) as fp: - for ln in fp: - if 'curses' in ln: - readline_termcap_library = re.sub( - r'.*lib(n?cursesw?)\.so.*', r'\1', ln - ).rstrip() - break - # termcap interface split out from ncurses - if 'tinfo' in ln: - readline_termcap_library = 'tinfo' - break - if os.path.exists(tmpfile): - os.unlink(tmpfile) - # Issue 7384: If readline is already linked against curses, - # use the same library for the readline and curses modules. - if 'curses' in readline_termcap_library: - curses_library = readline_termcap_library - elif self.compiler.find_library_file(lib_dirs, 'ncursesw'): - curses_library = 'ncursesw' - elif self.compiler.find_library_file(lib_dirs, 'ncurses'): - curses_library = 'ncurses' - elif self.compiler.find_library_file(lib_dirs, 'curses'): - curses_library = 'curses' - - if host_platform == 'darwin': - os_release = int(os.uname()[2].split('.')[0]) - dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') - if (dep_target and - (tuple(int(n) for n in dep_target.split('.')[0:2]) - < (10, 5) ) ): - os_release = 8 - if os_release < 9: - # MacOSX 10.4 has a broken readline. Don't try to build - # the readline module unless the user has installed a fixed - # readline package - if find_file('readline/rlconf.h', inc_dirs, []) is None: - do_readline = False - if do_readline: - if host_platform == 'darwin' and os_release < 9: - # In every directory on the search path search for a dynamic - # library and then a static library, instead of first looking - # for dynamic libraries on the entire path. - # This way a statically linked custom readline gets picked up - # before the (possibly broken) dynamic library in /usr/lib. - readline_extra_link_args = ('-Wl,-search_paths_first',) - else: - readline_extra_link_args = () - - readline_libs = ['readline'] - if readline_termcap_library: - pass # Issue 7384: Already linked against curses or tinfo. - elif curses_library: - readline_libs.append(curses_library) - elif self.compiler.find_library_file(lib_dirs + - ['/usr/lib/termcap'], - 'termcap'): - readline_libs.append('termcap') - exts.append( Extension('readline', ['readline.c'], - library_dirs=['/usr/lib/termcap'], - extra_link_args=readline_extra_link_args, - libraries=readline_libs) ) - else: - missing.append('readline') - - # crypt module. - - if self.compiler.find_library_file(lib_dirs, 'crypt'): - libs = ['crypt'] - else: - libs = [] - exts.append( Extension('_crypt', ['_cryptmodule.c'], libraries=libs) ) - - # CSV files - exts.append( Extension('_csv', ['_csv.c']) ) - - # POSIX subprocess module helper. - exts.append( Extension('_posixsubprocess', ['_posixsubprocess.c']) ) - - # socket(2) - exts.append( Extension('_socket', ['socketmodule.c'], - depends = ['socketmodule.h']) ) - # Detect SSL support for the socket module (via _ssl) - search_for_ssl_incs_in = [ - '/usr/local/ssl/include', - '/usr/contrib/ssl/include/' - ] - ssl_incs = find_file('openssl/ssl.h', inc_dirs, - search_for_ssl_incs_in - ) - if ssl_incs is not None: - krb5_h = find_file('krb5.h', inc_dirs, - ['/usr/kerberos/include']) - if krb5_h: - ssl_incs += krb5_h - ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs, - ['/usr/local/ssl/lib', - '/usr/contrib/ssl/lib/' - ] ) - - if (ssl_incs is not None and - ssl_libs is not None): - exts.append( Extension('_ssl', ['_ssl.c'], - include_dirs = ssl_incs, - library_dirs = ssl_libs, - libraries = ['ssl', 'crypto'], - depends = ['socketmodule.h']), ) - else: - missing.append('_ssl') - - # find out which version of OpenSSL we have - openssl_ver = 0 - openssl_ver_re = re.compile( - r'^\s*#\s*define\s+OPENSSL_VERSION_NUMBER\s+(0x[0-9a-fA-F]+)' ) - - # look for the openssl version header on the compiler search path. - opensslv_h = find_file('openssl/opensslv.h', [], - inc_dirs + search_for_ssl_incs_in) - if opensslv_h: - name = os.path.join(opensslv_h[0], 'openssl/opensslv.h') - if host_platform == 'darwin' and is_macosx_sdk_path(name): - name = os.path.join(macosx_sdk_root(), name[1:]) - try: - with open(name, 'r') as incfile: - for line in incfile: - m = openssl_ver_re.match(line) - if m: - openssl_ver = int(m.group(1), 16) - break - except IOError as msg: - print("IOError while reading opensshv.h:", msg) - - #print('openssl_ver = 0x%08x' % openssl_ver) - min_openssl_ver = 0x00907000 - have_any_openssl = ssl_incs is not None and ssl_libs is not None - have_usable_openssl = (have_any_openssl and - openssl_ver >= min_openssl_ver) - - if have_any_openssl: - if have_usable_openssl: - # The _hashlib module wraps optimized implementations - # of hash functions from the OpenSSL library. - exts.append( Extension('_hashlib', ['_hashopenssl.c'], - depends = ['hashlib.h'], - include_dirs = ssl_incs, - library_dirs = ssl_libs, - libraries = ['ssl', 'crypto']) ) - else: - print("warning: openssl 0x%08x is too old for _hashlib" % - openssl_ver) - missing.append('_hashlib') - - # We always compile these even when OpenSSL is available (issue #14693). - # It's harmless and the object code is tiny (40-50 KB per module, - # only loaded when actually used). - exts.append( Extension('_sha256', ['sha256module.c'], - depends=['hashlib.h']) ) - exts.append( Extension('_sha512', ['sha512module.c'], - depends=['hashlib.h']) ) - exts.append( Extension('_md5', ['md5module.c'], - depends=['hashlib.h']) ) - exts.append( Extension('_sha1', ['sha1module.c'], - depends=['hashlib.h']) ) - - blake2_deps = glob(os.path.join(os.getcwd(), srcdir, - 'Modules/_blake2/impl/*')) - blake2_deps.append('hashlib.h') - - blake2_macros = [] - if (not cross_compiling and - os.uname().machine == "x86_64" and - sys.maxsize > 2**32): - # Every x86_64 machine has at least SSE2. Check for sys.maxsize - # in case that kernel is 64-bit but userspace is 32-bit. - blake2_macros.append(('BLAKE2_USE_SSE', '1')) - - exts.append( Extension('_blake2', - ['_blake2/blake2module.c', - '_blake2/blake2b_impl.c', - '_blake2/blake2s_impl.c'], - define_macros=blake2_macros, - depends=blake2_deps) ) - - sha3_deps = glob(os.path.join(os.getcwd(), srcdir, - 'Modules/_sha3/kcp/*')) - sha3_deps.append('hashlib.h') - exts.append( Extension('_sha3', - ['_sha3/sha3module.c'], - depends=sha3_deps)) - - # Modules that provide persistent dictionary-like semantics. You will - # probably want to arrange for at least one of them to be available on - # your machine, though none are defined by default because of library - # dependencies. The Python module dbm/__init__.py provides an - # implementation independent wrapper for these; dbm/dumb.py provides - # similar functionality (but slower of course) implemented in Python. - - # Sleepycat^WOracle Berkeley DB interface. - # http://www.oracle.com/database/berkeley-db/db/index.html - # - # This requires the Sleepycat^WOracle DB code. The supported versions - # are set below. Visit the URL above to download - # a release. Most open source OSes come with one or more - # versions of BerkeleyDB already installed. - - max_db_ver = (5, 3) - min_db_ver = (3, 3) - db_setup_debug = False # verbose debug prints from this script? - - def allow_db_ver(db_ver): - """Returns a boolean if the given BerkeleyDB version is acceptable. - - Args: - db_ver: A tuple of the version to verify. - """ - if not (min_db_ver <= db_ver <= max_db_ver): - return False - return True - - def gen_db_minor_ver_nums(major): - if major == 4: - for x in range(max_db_ver[1]+1): - if allow_db_ver((4, x)): - yield x - elif major == 3: - for x in (3,): - if allow_db_ver((3, x)): - yield x - else: - raise ValueError("unknown major BerkeleyDB version", major) - - # construct a list of paths to look for the header file in on - # top of the normal inc_dirs. - db_inc_paths = [ - '/usr/include/db4', - '/usr/local/include/db4', - '/opt/sfw/include/db4', - '/usr/include/db3', - '/usr/local/include/db3', - '/opt/sfw/include/db3', - # Fink defaults (http://fink.sourceforge.net/) - '/sw/include/db4', - '/sw/include/db3', - ] - # 4.x minor number specific paths - for x in gen_db_minor_ver_nums(4): - db_inc_paths.append('/usr/include/db4%d' % x) - db_inc_paths.append('/usr/include/db4.%d' % x) - db_inc_paths.append('/usr/local/BerkeleyDB.4.%d/include' % x) - db_inc_paths.append('/usr/local/include/db4%d' % x) - db_inc_paths.append('/pkg/db-4.%d/include' % x) - db_inc_paths.append('/opt/db-4.%d/include' % x) - # MacPorts default (http://www.macports.org/) - db_inc_paths.append('/opt/local/include/db4%d' % x) - # 3.x minor number specific paths - for x in gen_db_minor_ver_nums(3): - db_inc_paths.append('/usr/include/db3%d' % x) - db_inc_paths.append('/usr/local/BerkeleyDB.3.%d/include' % x) - db_inc_paths.append('/usr/local/include/db3%d' % x) - db_inc_paths.append('/pkg/db-3.%d/include' % x) - db_inc_paths.append('/opt/db-3.%d/include' % x) - - if cross_compiling: - db_inc_paths = [] - - # Add some common subdirectories for Sleepycat DB to the list, - # based on the standard include directories. This way DB3/4 gets - # picked up when it is installed in a non-standard prefix and - # the user has added that prefix into inc_dirs. - std_variants = [] - for dn in inc_dirs: - std_variants.append(os.path.join(dn, 'db3')) - std_variants.append(os.path.join(dn, 'db4')) - for x in gen_db_minor_ver_nums(4): - std_variants.append(os.path.join(dn, "db4%d"%x)) - std_variants.append(os.path.join(dn, "db4.%d"%x)) - for x in gen_db_minor_ver_nums(3): - std_variants.append(os.path.join(dn, "db3%d"%x)) - std_variants.append(os.path.join(dn, "db3.%d"%x)) - - db_inc_paths = std_variants + db_inc_paths - db_inc_paths = [p for p in db_inc_paths if os.path.exists(p)] - - db_ver_inc_map = {} - - if host_platform == 'darwin': - sysroot = macosx_sdk_root() - - class db_found(Exception): pass - try: - # See whether there is a Sleepycat header in the standard - # search path. - for d in inc_dirs + db_inc_paths: - f = os.path.join(d, "db.h") - if host_platform == 'darwin' and is_macosx_sdk_path(d): - f = os.path.join(sysroot, d[1:], "db.h") - - if db_setup_debug: print("db: looking for db.h in", f) - if os.path.exists(f): - with open(f, 'rb') as file: - f = file.read() - m = re.search(br"#define\WDB_VERSION_MAJOR\W(\d+)", f) - if m: - db_major = int(m.group(1)) - m = re.search(br"#define\WDB_VERSION_MINOR\W(\d+)", f) - db_minor = int(m.group(1)) - db_ver = (db_major, db_minor) - - # Avoid 4.6 prior to 4.6.21 due to a BerkeleyDB bug - if db_ver == (4, 6): - m = re.search(br"#define\WDB_VERSION_PATCH\W(\d+)", f) - db_patch = int(m.group(1)) - if db_patch < 21: - print("db.h:", db_ver, "patch", db_patch, - "being ignored (4.6.x must be >= 4.6.21)") - continue - - if ( (db_ver not in db_ver_inc_map) and - allow_db_ver(db_ver) ): - # save the include directory with the db.h version - # (first occurrence only) - db_ver_inc_map[db_ver] = d - if db_setup_debug: - print("db.h: found", db_ver, "in", d) - else: - # we already found a header for this library version - if db_setup_debug: print("db.h: ignoring", d) - else: - # ignore this header, it didn't contain a version number - if db_setup_debug: - print("db.h: no version number version in", d) - - db_found_vers = list(db_ver_inc_map.keys()) - db_found_vers.sort() - - while db_found_vers: - db_ver = db_found_vers.pop() - db_incdir = db_ver_inc_map[db_ver] - - # check lib directories parallel to the location of the header - db_dirs_to_check = [ - db_incdir.replace("include", 'lib64'), - db_incdir.replace("include", 'lib'), - ] - - if host_platform != 'darwin': - db_dirs_to_check = list(filter(os.path.isdir, db_dirs_to_check)) - - else: - # Same as other branch, but takes OSX SDK into account - tmp = [] - for dn in db_dirs_to_check: - if is_macosx_sdk_path(dn): - if os.path.isdir(os.path.join(sysroot, dn[1:])): - tmp.append(dn) - else: - if os.path.isdir(dn): - tmp.append(dn) - db_dirs_to_check = tmp - - db_dirs_to_check = tmp - - # Look for a version specific db-X.Y before an ambiguous dbX - # XXX should we -ever- look for a dbX name? Do any - # systems really not name their library by version and - # symlink to more general names? - for dblib in (('db-%d.%d' % db_ver), - ('db%d%d' % db_ver), - ('db%d' % db_ver[0])): - dblib_file = self.compiler.find_library_file( - db_dirs_to_check + lib_dirs, dblib ) - if dblib_file: - dblib_dir = [ os.path.abspath(os.path.dirname(dblib_file)) ] - raise db_found - else: - if db_setup_debug: print("db lib: ", dblib, "not found") - - except db_found: - if db_setup_debug: - print("bsddb using BerkeleyDB lib:", db_ver, dblib) - print("bsddb lib dir:", dblib_dir, " inc dir:", db_incdir) - dblibs = [dblib] - # Only add the found library and include directories if they aren't - # already being searched. This avoids an explicit runtime library - # dependency. - if db_incdir in inc_dirs: - db_incs = None - else: - db_incs = [db_incdir] - if dblib_dir[0] in lib_dirs: - dblib_dir = None - else: - if db_setup_debug: print("db: no appropriate library found") - db_incs = None - dblibs = [] - dblib_dir = None - - # The sqlite interface - sqlite_setup_debug = False # verbose debug prints from this script? - - # We hunt for #define SQLITE_VERSION "n.n.n" - # We need to find >= sqlite version 3.0.8 - sqlite_incdir = sqlite_libdir = None - sqlite_inc_paths = [ '/usr/include', - '/usr/include/sqlite', - '/usr/include/sqlite3', - '/usr/local/include', - '/usr/local/include/sqlite', - '/usr/local/include/sqlite3', - ] - if cross_compiling: - sqlite_inc_paths = [] - MIN_SQLITE_VERSION_NUMBER = (3, 0, 8) - MIN_SQLITE_VERSION = ".".join([str(x) - for x in MIN_SQLITE_VERSION_NUMBER]) - - # Scan the default include directories before the SQLite specific - # ones. This allows one to override the copy of sqlite on OSX, - # where /usr/include contains an old version of sqlite. - if host_platform == 'darwin': - sysroot = macosx_sdk_root() - - for d_ in inc_dirs + sqlite_inc_paths: - d = d_ - if host_platform == 'darwin' and is_macosx_sdk_path(d): - d = os.path.join(sysroot, d[1:]) - - f = os.path.join(d, "sqlite3.h") - if os.path.exists(f): - if sqlite_setup_debug: print("sqlite: found %s"%f) - with open(f) as file: - incf = file.read() - m = re.search( - r'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"([\d\.]*)"', incf) - if m: - sqlite_version = m.group(1) - sqlite_version_tuple = tuple([int(x) - for x in sqlite_version.split(".")]) - if sqlite_version_tuple >= MIN_SQLITE_VERSION_NUMBER: - # we win! - if sqlite_setup_debug: - print("%s/sqlite3.h: version %s"%(d, sqlite_version)) - sqlite_incdir = d - break - else: - if sqlite_setup_debug: - print("%s: version %d is too old, need >= %s"%(d, - sqlite_version, MIN_SQLITE_VERSION)) - elif sqlite_setup_debug: - print("sqlite: %s had no SQLITE_VERSION"%(f,)) - - if sqlite_incdir: - sqlite_dirs_to_check = [ - os.path.join(sqlite_incdir, '..', 'lib64'), - os.path.join(sqlite_incdir, '..', 'lib'), - os.path.join(sqlite_incdir, '..', '..', 'lib64'), - os.path.join(sqlite_incdir, '..', '..', 'lib'), - ] - sqlite_libfile = self.compiler.find_library_file( - sqlite_dirs_to_check + lib_dirs, 'sqlite3') - if sqlite_libfile: - sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))] - - if sqlite_incdir and sqlite_libdir: - sqlite_srcs = ['_sqlite/cache.c', - '_sqlite/connection.c', - '_sqlite/cursor.c', - '_sqlite/microprotocols.c', - '_sqlite/module.c', - '_sqlite/prepare_protocol.c', - '_sqlite/row.c', - '_sqlite/statement.c', - '_sqlite/util.c', ] - - sqlite_defines = [] - if host_platform != "win32": - sqlite_defines.append(('MODULE_NAME', '"sqlite3"')) - else: - sqlite_defines.append(('MODULE_NAME', '\\"sqlite3\\"')) - - # Enable support for loadable extensions in the sqlite3 module - # if --enable-loadable-sqlite-extensions configure option is used. - if '--enable-loadable-sqlite-extensions' not in sysconfig.get_config_var("CONFIG_ARGS"): - sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1")) - - if host_platform == 'darwin': - # In every directory on the search path search for a dynamic - # library and then a static library, instead of first looking - # for dynamic libraries on the entire path. - # This way a statically linked custom sqlite gets picked up - # before the dynamic library in /usr/lib. - sqlite_extra_link_args = ('-Wl,-search_paths_first',) - else: - sqlite_extra_link_args = () - - include_dirs = ["Modules/_sqlite"] - # Only include the directory where sqlite was found if it does - # not already exist in set include directories, otherwise you - # can end up with a bad search path order. - if sqlite_incdir not in self.compiler.include_dirs: - include_dirs.append(sqlite_incdir) - # avoid a runtime library path for a system library dir - if sqlite_libdir and sqlite_libdir[0] in lib_dirs: - sqlite_libdir = None - exts.append(Extension('_sqlite3', sqlite_srcs, - define_macros=sqlite_defines, - include_dirs=include_dirs, - library_dirs=sqlite_libdir, - extra_link_args=sqlite_extra_link_args, - libraries=["sqlite3",])) - else: - missing.append('_sqlite3') - - dbm_setup_debug = False # verbose debug prints from this script? - dbm_order = ['gdbm'] - # The standard Unix dbm module: - if host_platform not in ['cygwin']: - config_args = [arg.strip("'") - for arg in sysconfig.get_config_var("CONFIG_ARGS").split()] - dbm_args = [arg for arg in config_args - if arg.startswith('--with-dbmliborder=')] - if dbm_args: - dbm_order = [arg.split('=')[-1] for arg in dbm_args][-1].split(":") - else: - dbm_order = "ndbm:gdbm:bdb".split(":") - dbmext = None - for cand in dbm_order: - if cand == "ndbm": - if find_file("ndbm.h", inc_dirs, []) is not None: - # Some systems have -lndbm, others have -lgdbm_compat, - # others don't have either - if self.compiler.find_library_file(lib_dirs, - 'ndbm'): - ndbm_libs = ['ndbm'] - elif self.compiler.find_library_file(lib_dirs, - 'gdbm_compat'): - ndbm_libs = ['gdbm_compat'] - else: - ndbm_libs = [] - if dbm_setup_debug: print("building dbm using ndbm") - dbmext = Extension('_dbm', ['_dbmmodule.c'], - define_macros=[ - ('HAVE_NDBM_H',None), - ], - libraries=ndbm_libs) - break - - elif cand == "gdbm": - if self.compiler.find_library_file(lib_dirs, 'gdbm'): - gdbm_libs = ['gdbm'] - if self.compiler.find_library_file(lib_dirs, - 'gdbm_compat'): - gdbm_libs.append('gdbm_compat') - if find_file("gdbm/ndbm.h", inc_dirs, []) is not None: - if dbm_setup_debug: print("building dbm using gdbm") - dbmext = Extension( - '_dbm', ['_dbmmodule.c'], - define_macros=[ - ('HAVE_GDBM_NDBM_H', None), - ], - libraries = gdbm_libs) - break - if find_file("gdbm-ndbm.h", inc_dirs, []) is not None: - if dbm_setup_debug: print("building dbm using gdbm") - dbmext = Extension( - '_dbm', ['_dbmmodule.c'], - define_macros=[ - ('HAVE_GDBM_DASH_NDBM_H', None), - ], - libraries = gdbm_libs) - break - elif cand == "bdb": - if dblibs: - if dbm_setup_debug: print("building dbm using bdb") - dbmext = Extension('_dbm', ['_dbmmodule.c'], - library_dirs=dblib_dir, - runtime_library_dirs=dblib_dir, - include_dirs=db_incs, - define_macros=[ - ('HAVE_BERKDB_H', None), - ('DB_DBM_HSEARCH', None), - ], - libraries=dblibs) - break - if dbmext is not None: - exts.append(dbmext) - else: - missing.append('_dbm') - - # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm: - if ('gdbm' in dbm_order and - self.compiler.find_library_file(lib_dirs, 'gdbm')): - exts.append( Extension('_gdbm', ['_gdbmmodule.c'], - libraries = ['gdbm'] ) ) - else: - missing.append('_gdbm') - - # Unix-only modules - if host_platform != 'win32': - # Steen Lumholt's termios module - exts.append( Extension('termios', ['termios.c']) ) - # Jeremy Hylton's rlimit interface - exts.append( Extension('resource', ['resource.c']) ) - else: - missing.extend(['resource', 'termios']) - - nis = self._detect_nis(inc_dirs, lib_dirs) - if nis is not None: - exts.append(nis) - else: - missing.append('nis') - - # Curses support, requiring the System V version of curses, often - # provided by the ncurses library. - curses_defines = [] - curses_includes = [] - panel_library = 'panel' - if curses_library == 'ncursesw': - curses_defines.append(('HAVE_NCURSESW', '1')) - if not cross_compiling: - curses_includes.append('/usr/include/ncursesw') - # Bug 1464056: If _curses.so links with ncursesw, - # _curses_panel.so must link with panelw. - panel_library = 'panelw' - if host_platform == 'darwin': - # On OS X, there is no separate /usr/lib/libncursesw nor - # libpanelw. If we are here, we found a locally-supplied - # version of libncursesw. There should also be a - # libpanelw. _XOPEN_SOURCE defines are usually excluded - # for OS X but we need _XOPEN_SOURCE_EXTENDED here for - # ncurses wide char support - curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1')) - elif host_platform == 'darwin' and curses_library == 'ncurses': - # Building with the system-suppied combined libncurses/libpanel - curses_defines.append(('HAVE_NCURSESW', '1')) - curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1')) - - if curses_library.startswith('ncurses'): - curses_libs = [curses_library] - exts.append( Extension('_curses', ['_cursesmodule.c'], - include_dirs=curses_includes, - define_macros=curses_defines, - libraries = curses_libs) ) - elif curses_library == 'curses' and host_platform != 'darwin': - # OSX has an old Berkeley curses, not good enough for - # the _curses module. - if (self.compiler.find_library_file(lib_dirs, 'terminfo')): - curses_libs = ['curses', 'terminfo'] - elif (self.compiler.find_library_file(lib_dirs, 'termcap')): - curses_libs = ['curses', 'termcap'] - else: - curses_libs = ['curses'] - - exts.append( Extension('_curses', ['_cursesmodule.c'], - define_macros=curses_defines, - libraries = curses_libs) ) - else: - missing.append('_curses') - - # If the curses module is enabled, check for the panel module - if (module_enabled(exts, '_curses') and - self.compiler.find_library_file(lib_dirs, panel_library)): - exts.append( Extension('_curses_panel', ['_curses_panel.c'], - include_dirs=curses_includes, - define_macros=curses_defines, - libraries = [panel_library] + curses_libs) ) - else: - missing.append('_curses_panel') - - # Andrew Kuchling's zlib module. Note that some versions of zlib - # 1.1.3 have security problems. See CERT Advisory CA-2002-07: - # http://www.cert.org/advisories/CA-2002-07.html - # - # zlib 1.1.4 is fixed, but at least one vendor (RedHat) has decided to - # patch its zlib 1.1.3 package instead of upgrading to 1.1.4. For - # now, we still accept 1.1.3, because we think it's difficult to - # exploit this in Python, and we'd rather make it RedHat's problem - # than our problem . - # - # You can upgrade zlib to version 1.1.4 yourself by going to - # http://www.gzip.org/zlib/ - zlib_inc = find_file('zlib.h', [], inc_dirs) - have_zlib = False - if zlib_inc is not None: - zlib_h = zlib_inc[0] + '/zlib.h' - version = '"0.0.0"' - version_req = '"1.1.3"' - if host_platform == 'darwin' and is_macosx_sdk_path(zlib_h): - zlib_h = os.path.join(macosx_sdk_root(), zlib_h[1:]) - with open(zlib_h) as fp: - while 1: - line = fp.readline() - if not line: - break - if line.startswith('#define ZLIB_VERSION'): - version = line.split()[2] - break - if version >= version_req: - if (self.compiler.find_library_file(lib_dirs, 'z')): - if host_platform == "darwin": - zlib_extra_link_args = ('-Wl,-search_paths_first',) - else: - zlib_extra_link_args = () - exts.append( Extension('zlib', ['zlibmodule.c'], - libraries = ['z'], - extra_link_args = zlib_extra_link_args)) - have_zlib = True - else: - missing.append('zlib') - else: - missing.append('zlib') - else: - missing.append('zlib') - - # Helper module for various ascii-encoders. Uses zlib for an optimized - # crc32 if we have it. Otherwise binascii uses its own. - if have_zlib: - extra_compile_args = ['-DUSE_ZLIB_CRC32'] - libraries = ['z'] - extra_link_args = zlib_extra_link_args - else: - extra_compile_args = [] - libraries = [] - extra_link_args = [] - exts.append( Extension('binascii', ['binascii.c'], - extra_compile_args = extra_compile_args, - libraries = libraries, - extra_link_args = extra_link_args) ) - - # Gustavo Niemeyer's bz2 module. - if (self.compiler.find_library_file(lib_dirs, 'bz2')): - if host_platform == "darwin": - bz2_extra_link_args = ('-Wl,-search_paths_first',) - else: - bz2_extra_link_args = () - exts.append( Extension('_bz2', ['_bz2module.c'], - libraries = ['bz2'], - extra_link_args = bz2_extra_link_args) ) - else: - missing.append('_bz2') - - # LZMA compression support. - if self.compiler.find_library_file(lib_dirs, 'lzma'): - exts.append( Extension('_lzma', ['_lzmamodule.c'], - libraries = ['lzma']) ) - else: - missing.append('_lzma') - - # Interface to the Expat XML parser - # - # Expat was written by James Clark and is now maintained by a group of - # developers on SourceForge; see www.libexpat.org for more information. - # The pyexpat module was written by Paul Prescod after a prototype by - # Jack Jansen. The Expat source is included in Modules/expat/. Usage - # of a system shared libexpat.so is possible with --with-system-expat - # configure option. - # - # More information on Expat can be found at www.libexpat.org. - # - if '--with-system-expat' in sysconfig.get_config_var("CONFIG_ARGS"): - expat_inc = [] - define_macros = [] - extra_compile_args = [] - expat_lib = ['expat'] - expat_sources = [] - expat_depends = [] - else: - expat_inc = [os.path.join(os.getcwd(), srcdir, 'Modules', 'expat')] - define_macros = [ - ('HAVE_EXPAT_CONFIG_H', '1'), - # bpo-30947: Python uses best available entropy sources to - # call XML_SetHashSalt(), expat entropy sources are not needed - ('XML_POOR_ENTROPY', '1'), - ] - extra_compile_args = [] - expat_lib = [] - expat_sources = ['expat/xmlparse.c', - 'expat/xmlrole.c', - 'expat/xmltok.c'] - expat_depends = ['expat/ascii.h', - 'expat/asciitab.h', - 'expat/expat.h', - 'expat/expat_config.h', - 'expat/expat_external.h', - 'expat/internal.h', - 'expat/latin1tab.h', - 'expat/utf8tab.h', - 'expat/xmlrole.h', - 'expat/xmltok.h', - 'expat/xmltok_impl.h' - ] - - cc = sysconfig.get_config_var('CC').split()[0] - ret = os.system( - '"%s" -Werror -Wno-unreachable-code -E -xc /dev/null >/dev/null 2>&1' % cc) - if ret >> 8 == 0: - extra_compile_args.append('-Wno-unreachable-code') - - exts.append(Extension('pyexpat', - define_macros = define_macros, - extra_compile_args = extra_compile_args, - include_dirs = expat_inc, - libraries = expat_lib, - sources = ['pyexpat.c'] + expat_sources, - depends = expat_depends, - )) - - # Fredrik Lundh's cElementTree module. Note that this also - # uses expat (via the CAPI hook in pyexpat). - - if os.path.isfile(os.path.join(srcdir, 'Modules', '_elementtree.c')): - define_macros.append(('USE_PYEXPAT_CAPI', None)) - exts.append(Extension('_elementtree', - define_macros = define_macros, - include_dirs = expat_inc, - libraries = expat_lib, - sources = ['_elementtree.c'], - depends = ['pyexpat.c'] + expat_sources + - expat_depends, - )) - else: - missing.append('_elementtree') - - # Hye-Shik Chang's CJKCodecs modules. - exts.append(Extension('_multibytecodec', - ['cjkcodecs/multibytecodec.c'])) - for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'): - exts.append(Extension('_codecs_%s' % loc, - ['cjkcodecs/_codecs_%s.c' % loc])) - - # Stefan Krah's _decimal module - exts.append(self._decimal_ext()) - - # Thomas Heller's _ctypes module - self.detect_ctypes(inc_dirs, lib_dirs) - - # Richard Oudkerk's multiprocessing module - if host_platform == 'win32': # Windows - macros = dict() - libraries = ['ws2_32'] - - elif host_platform == 'darwin': # Mac OSX - macros = dict() - libraries = [] - - elif host_platform == 'cygwin': # Cygwin - macros = dict() - libraries = [] - - elif host_platform in ('freebsd4', 'freebsd5', 'freebsd6', 'freebsd7', 'freebsd8'): - # FreeBSD's P1003.1b semaphore support is very experimental - # and has many known problems. (as of June 2008) - macros = dict() - libraries = [] - - elif host_platform.startswith('openbsd'): - macros = dict() - libraries = [] - - elif host_platform.startswith('netbsd'): - macros = dict() - libraries = [] - - else: # Linux and other unices - macros = dict() - libraries = ['rt'] - - if host_platform == 'win32': - multiprocessing_srcs = [ '_multiprocessing/multiprocessing.c', - '_multiprocessing/semaphore.c', - ] - - else: - multiprocessing_srcs = [ '_multiprocessing/multiprocessing.c', - ] - if (sysconfig.get_config_var('HAVE_SEM_OPEN') and not - sysconfig.get_config_var('POSIX_SEMAPHORES_NOT_ENABLED')): - multiprocessing_srcs.append('_multiprocessing/semaphore.c') - - if sysconfig.get_config_var('WITH_THREAD'): - exts.append ( Extension('_multiprocessing', multiprocessing_srcs, - define_macros=list(macros.items()), - include_dirs=["Modules/_multiprocessing"])) - else: - missing.append('_multiprocessing') - # End multiprocessing - - # Platform-specific libraries - if host_platform.startswith(('linux', 'freebsd', 'gnukfreebsd')): - exts.append( Extension('ossaudiodev', ['ossaudiodev.c']) ) - else: - missing.append('ossaudiodev') - - if host_platform == 'darwin': - exts.append( - Extension('_scproxy', ['_scproxy.c'], - extra_link_args=[ - '-framework', 'SystemConfiguration', - '-framework', 'CoreFoundation', - ])) - - self.extensions.extend(exts) - - # Call the method for detecting whether _tkinter can be compiled - self.detect_tkinter(inc_dirs, lib_dirs) - - if '_tkinter' not in [e.name for e in self.extensions]: - missing.append('_tkinter') - -## # Uncomment these lines if you want to play with xxmodule.c -## ext = Extension('xx', ['xxmodule.c']) -## self.extensions.append(ext) - - if 'd' not in sysconfig.get_config_var('ABIFLAGS'): - ext = Extension('xxlimited', ['xxlimited.c'], - define_macros=[('Py_LIMITED_API', '0x03050000')]) - self.extensions.append(ext) - - return missing - - def detect_tkinter_explicitly(self): - # Build _tkinter using explicit locations for Tcl/Tk. - # - # This is enabled when both arguments are given to ./configure: - # - # --with-tcltk-includes="-I/path/to/tclincludes \ - # -I/path/to/tkincludes" - # --with-tcltk-libs="-L/path/to/tcllibs -ltclm.n \ - # -L/path/to/tklibs -ltkm.n" - # - # These values can also be specified or overridden via make: - # make TCLTK_INCLUDES="..." TCLTK_LIBS="..." - # - # This can be useful for building and testing tkinter with multiple - # versions of Tcl/Tk. Note that a build of Tk depends on a particular - # build of Tcl so you need to specify both arguments and use care when - # overriding. - - # The _TCLTK variables are created in the Makefile sharedmods target. - tcltk_includes = os.environ.get('_TCLTK_INCLUDES') - tcltk_libs = os.environ.get('_TCLTK_LIBS') - if not (tcltk_includes and tcltk_libs): - # Resume default configuration search. - return 0 - - extra_compile_args = tcltk_includes.split() - extra_link_args = tcltk_libs.split() - ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'], - define_macros=[('WITH_APPINIT', 1)], - extra_compile_args = extra_compile_args, - extra_link_args = extra_link_args, - ) - self.extensions.append(ext) - return 1 - - def detect_tkinter_darwin(self, inc_dirs, lib_dirs): - # The _tkinter module, using frameworks. Since frameworks are quite - # different the UNIX search logic is not sharable. - from os.path import join, exists - framework_dirs = [ - '/Library/Frameworks', - '/System/Library/Frameworks/', - join(os.getenv('HOME'), '/Library/Frameworks') - ] - - sysroot = macosx_sdk_root() - - # Find the directory that contains the Tcl.framework and Tk.framework - # bundles. - # XXX distutils should support -F! - for F in framework_dirs: - # both Tcl.framework and Tk.framework should be present - - - for fw in 'Tcl', 'Tk': - if is_macosx_sdk_path(F): - if not exists(join(sysroot, F[1:], fw + '.framework')): - break - else: - if not exists(join(F, fw + '.framework')): - break - else: - # ok, F is now directory with both frameworks. Continure - # building - break - else: - # Tk and Tcl frameworks not found. Normal "unix" tkinter search - # will now resume. - return 0 - - # For 8.4a2, we must add -I options that point inside the Tcl and Tk - # frameworks. In later release we should hopefully be able to pass - # the -F option to gcc, which specifies a framework lookup path. - # - include_dirs = [ - join(F, fw + '.framework', H) - for fw in ('Tcl', 'Tk') - for H in ('Headers', 'Versions/Current/PrivateHeaders') - ] - - # For 8.4a2, the X11 headers are not included. Rather than include a - # complicated search, this is a hard-coded path. It could bail out - # if X11 libs are not found... - include_dirs.append('/usr/X11R6/include') - frameworks = ['-framework', 'Tcl', '-framework', 'Tk'] - - # All existing framework builds of Tcl/Tk don't support 64-bit - # architectures. - cflags = sysconfig.get_config_vars('CFLAGS')[0] - archs = re.findall(r'-arch\s+(\w+)', cflags) - - tmpfile = os.path.join(self.build_temp, 'tk.arch') - if not os.path.exists(self.build_temp): - os.makedirs(self.build_temp) - - # Note: cannot use os.popen or subprocess here, that - # requires extensions that are not available here. - if is_macosx_sdk_path(F): - os.system("file %s/Tk.framework/Tk | grep 'for architecture' > %s"%(os.path.join(sysroot, F[1:]), tmpfile)) - else: - os.system("file %s/Tk.framework/Tk | grep 'for architecture' > %s"%(F, tmpfile)) - - with open(tmpfile) as fp: - detected_archs = [] - for ln in fp: - a = ln.split()[-1] - if a in archs: - detected_archs.append(ln.split()[-1]) - os.unlink(tmpfile) - - for a in detected_archs: - frameworks.append('-arch') - frameworks.append(a) - - ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'], - define_macros=[('WITH_APPINIT', 1)], - include_dirs = include_dirs, - libraries = [], - extra_compile_args = frameworks[2:], - extra_link_args = frameworks, - ) - self.extensions.append(ext) - return 1 - - def detect_tkinter(self, inc_dirs, lib_dirs): - # The _tkinter module. - - # Check whether --with-tcltk-includes and --with-tcltk-libs were - # configured or passed into the make target. If so, use these values - # to build tkinter and bypass the searches for Tcl and TK in standard - # locations. - if self.detect_tkinter_explicitly(): - return - - # Rather than complicate the code below, detecting and building - # AquaTk is a separate method. Only one Tkinter will be built on - # Darwin - either AquaTk, if it is found, or X11 based Tk. - if (host_platform == 'darwin' and - self.detect_tkinter_darwin(inc_dirs, lib_dirs)): - return - - # Assume we haven't found any of the libraries or include files - # The versions with dots are used on Unix, and the versions without - # dots on Windows, for detection by cygwin. - tcllib = tklib = tcl_includes = tk_includes = None - for version in ['8.6', '86', '8.5', '85', '8.4', '84', '8.3', '83', - '8.2', '82', '8.1', '81', '8.0', '80']: - tklib = self.compiler.find_library_file(lib_dirs, - 'tk' + version) - tcllib = self.compiler.find_library_file(lib_dirs, - 'tcl' + version) - if tklib and tcllib: - # Exit the loop when we've found the Tcl/Tk libraries - break - - # Now check for the header files - if tklib and tcllib: - # Check for the include files on Debian and {Free,Open}BSD, where - # they're put in /usr/include/{tcl,tk}X.Y - dotversion = version - if '.' not in dotversion and "bsd" in host_platform.lower(): - # OpenBSD and FreeBSD use Tcl/Tk library names like libtcl83.a, - # but the include subdirs are named like .../include/tcl8.3. - dotversion = dotversion[:-1] + '.' + dotversion[-1] - tcl_include_sub = [] - tk_include_sub = [] - for dir in inc_dirs: - tcl_include_sub += [dir + os.sep + "tcl" + dotversion] - tk_include_sub += [dir + os.sep + "tk" + dotversion] - tk_include_sub += tcl_include_sub - tcl_includes = find_file('tcl.h', inc_dirs, tcl_include_sub) - tk_includes = find_file('tk.h', inc_dirs, tk_include_sub) - - if (tcllib is None or tklib is None or - tcl_includes is None or tk_includes is None): - self.announce("INFO: Can't locate Tcl/Tk libs and/or headers", 2) - return - - # OK... everything seems to be present for Tcl/Tk. - - include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = [] - for dir in tcl_includes + tk_includes: - if dir not in include_dirs: - include_dirs.append(dir) - - # Check for various platform-specific directories - if host_platform == 'sunos5': - include_dirs.append('/usr/openwin/include') - added_lib_dirs.append('/usr/openwin/lib') - elif os.path.exists('/usr/X11R6/include'): - include_dirs.append('/usr/X11R6/include') - added_lib_dirs.append('/usr/X11R6/lib64') - added_lib_dirs.append('/usr/X11R6/lib') - elif os.path.exists('/usr/X11R5/include'): - include_dirs.append('/usr/X11R5/include') - added_lib_dirs.append('/usr/X11R5/lib') - else: - # Assume default location for X11 - include_dirs.append('/usr/X11/include') - added_lib_dirs.append('/usr/X11/lib') - - # If Cygwin, then verify that X is installed before proceeding - if host_platform == 'cygwin': - x11_inc = find_file('X11/Xlib.h', [], include_dirs) - if x11_inc is None: - return - - # Check for BLT extension - if self.compiler.find_library_file(lib_dirs + added_lib_dirs, - 'BLT8.0'): - defs.append( ('WITH_BLT', 1) ) - libs.append('BLT8.0') - elif self.compiler.find_library_file(lib_dirs + added_lib_dirs, - 'BLT'): - defs.append( ('WITH_BLT', 1) ) - libs.append('BLT') - - # Add the Tcl/Tk libraries - libs.append('tk'+ version) - libs.append('tcl'+ version) - - if host_platform in ['aix3', 'aix4']: - libs.append('ld') - - # Finally, link with the X11 libraries (not appropriate on cygwin) - if host_platform != "cygwin": - libs.append('X11') - - ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'], - define_macros=[('WITH_APPINIT', 1)] + defs, - include_dirs = include_dirs, - libraries = libs, - library_dirs = added_lib_dirs, - ) - self.extensions.append(ext) - - # XXX handle these, but how to detect? - # *** Uncomment and edit for PIL (TkImaging) extension only: - # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \ - # *** Uncomment and edit for TOGL extension only: - # -DWITH_TOGL togl.c \ - # *** Uncomment these for TOGL extension only: - # -lGL -lGLU -lXext -lXmu \ - - def configure_ctypes_darwin(self, ext): - # Darwin (OS X) uses preconfigured files, in - # the Modules/_ctypes/libffi_osx directory. - srcdir = sysconfig.get_config_var('srcdir') - ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules', - '_ctypes', 'libffi_osx')) - sources = [os.path.join(ffi_srcdir, p) - for p in ['ffi.c', - 'x86/darwin64.S', - 'x86/x86-darwin.S', - 'x86/x86-ffi_darwin.c', - 'x86/x86-ffi64.c', - 'powerpc/ppc-darwin.S', - 'powerpc/ppc-darwin_closure.S', - 'powerpc/ppc-ffi_darwin.c', - 'powerpc/ppc64-darwin_closure.S', - ]] - - # Add .S (preprocessed assembly) to C compiler source extensions. - self.compiler.src_extensions.append('.S') - - include_dirs = [os.path.join(ffi_srcdir, 'include'), - os.path.join(ffi_srcdir, 'powerpc')] - ext.include_dirs.extend(include_dirs) - ext.sources.extend(sources) - return True - - def configure_ctypes(self, ext): - if not self.use_system_libffi: - if host_platform == 'darwin': - return self.configure_ctypes_darwin(ext) - - print('warning: building with the bundled copy of libffi is' - ' deprecated on this platform. It will not be' - ' distributed with Python 3.7') - srcdir = sysconfig.get_config_var('srcdir') - ffi_builddir = os.path.join(self.build_temp, 'libffi') - ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules', - '_ctypes', 'libffi')) - ffi_configfile = os.path.join(ffi_builddir, 'fficonfig.py') - - from distutils.dep_util import newer_group - - config_sources = [os.path.join(ffi_srcdir, fname) - for fname in os.listdir(ffi_srcdir) - if os.path.isfile(os.path.join(ffi_srcdir, fname))] - if self.force or newer_group(config_sources, - ffi_configfile): - from distutils.dir_util import mkpath - mkpath(ffi_builddir) - config_args = [arg for arg in sysconfig.get_config_var("CONFIG_ARGS").split() - if (('--host=' in arg) or ('--build=' in arg))] - if not self.verbose: - config_args.append("-q") - - # Pass empty CFLAGS because we'll just append the resulting - # CFLAGS to Python's; -g or -O2 is to be avoided. - cmd = "cd %s && env CFLAGS='' '%s/configure' %s" \ - % (ffi_builddir, ffi_srcdir, " ".join(config_args)) - - res = os.system(cmd) - if res or not os.path.exists(ffi_configfile): - print("Failed to configure _ctypes module") - return False - - fficonfig = {} - with open(ffi_configfile) as f: - exec(f.read(), globals(), fficonfig) - - # Add .S (preprocessed assembly) to C compiler source extensions. - self.compiler.src_extensions.append('.S') - - include_dirs = [os.path.join(ffi_builddir, 'include'), - ffi_builddir, - os.path.join(ffi_srcdir, 'src')] - extra_compile_args = fficonfig['ffi_cflags'].split() - - ext.sources.extend(os.path.join(ffi_srcdir, f) for f in - fficonfig['ffi_sources']) - ext.include_dirs.extend(include_dirs) - ext.extra_compile_args.extend(extra_compile_args) - return True - - def detect_ctypes(self, inc_dirs, lib_dirs): - self.use_system_libffi = False - include_dirs = [] - extra_compile_args = [] - extra_link_args = [] - sources = ['_ctypes/_ctypes.c', - '_ctypes/callbacks.c', - '_ctypes/callproc.c', - '_ctypes/stgdict.c', - '_ctypes/cfield.c'] - depends = ['_ctypes/ctypes.h'] - math_libs = self.detect_math_libs() - - if host_platform == 'darwin': - sources.append('_ctypes/malloc_closure.c') - sources.append('_ctypes/darwin/dlfcn_simple.c') - extra_compile_args.append('-DMACOSX') - include_dirs.append('_ctypes/darwin') -# XXX Is this still needed? -## extra_link_args.extend(['-read_only_relocs', 'warning']) - - elif host_platform == 'sunos5': - # XXX This shouldn't be necessary; it appears that some - # of the assembler code is non-PIC (i.e. it has relocations - # when it shouldn't. The proper fix would be to rewrite - # the assembler code to be PIC. - # This only works with GCC; the Sun compiler likely refuses - # this option. If you want to compile ctypes with the Sun - # compiler, please research a proper solution, instead of - # finding some -z option for the Sun compiler. - extra_link_args.append('-mimpure-text') - - elif host_platform.startswith('hp-ux'): - extra_link_args.append('-fPIC') - - ext = Extension('_ctypes', - include_dirs=include_dirs, - extra_compile_args=extra_compile_args, - extra_link_args=extra_link_args, - libraries=[], - sources=sources, - depends=depends) - # function my_sqrt() needs math library for sqrt() - ext_test = Extension('_ctypes_test', - sources=['_ctypes/_ctypes_test.c'], - libraries=math_libs) - self.extensions.extend([ext, ext_test]) - - if host_platform == 'darwin': - if '--with-system-ffi' not in sysconfig.get_config_var("CONFIG_ARGS"): - return - # OS X 10.5 comes with libffi.dylib; the include files are - # in /usr/include/ffi - inc_dirs.append('/usr/include/ffi') - elif '--without-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS"): - return - - ffi_inc = [sysconfig.get_config_var("LIBFFI_INCLUDEDIR")] - if not ffi_inc or ffi_inc[0] == '': - ffi_inc = find_file('ffi.h', [], inc_dirs) - if ffi_inc is not None: - ffi_h = ffi_inc[0] + '/ffi.h' - with open(ffi_h) as f: - for line in f: - line = line.strip() - if line.startswith(('#define LIBFFI_H', - '#define ffi_wrapper_h')): - break - else: - ffi_inc = None - print('Header file {} does not define LIBFFI_H or ' - 'ffi_wrapper_h'.format(ffi_h)) - ffi_lib = None - if ffi_inc is not None: - for lib_name in ('ffi', 'ffi_pic'): - if (self.compiler.find_library_file(lib_dirs, lib_name)): - ffi_lib = lib_name - break - - if ffi_inc and ffi_lib: - ext.include_dirs.extend(ffi_inc) - ext.libraries.append(ffi_lib) - self.use_system_libffi = True - - if sysconfig.get_config_var('HAVE_LIBDL'): - # for dlopen, see bpo-32647 - ext.libraries.append('dl') - - def _decimal_ext(self): - extra_compile_args = [] - undef_macros = [] - if '--with-system-libmpdec' in sysconfig.get_config_var("CONFIG_ARGS"): - include_dirs = [] - libraries = [':libmpdec.so.2'] - sources = ['_decimal/_decimal.c'] - depends = ['_decimal/docstrings.h'] - else: - srcdir = sysconfig.get_config_var('srcdir') - include_dirs = [os.path.abspath(os.path.join(srcdir, - 'Modules', - '_decimal', - 'libmpdec'))] - libraries = self.detect_math_libs() - sources = [ - '_decimal/_decimal.c', - '_decimal/libmpdec/basearith.c', - '_decimal/libmpdec/constants.c', - '_decimal/libmpdec/context.c', - '_decimal/libmpdec/convolute.c', - '_decimal/libmpdec/crt.c', - '_decimal/libmpdec/difradix2.c', - '_decimal/libmpdec/fnt.c', - '_decimal/libmpdec/fourstep.c', - '_decimal/libmpdec/io.c', - '_decimal/libmpdec/memory.c', - '_decimal/libmpdec/mpdecimal.c', - '_decimal/libmpdec/numbertheory.c', - '_decimal/libmpdec/sixstep.c', - '_decimal/libmpdec/transpose.c', - ] - depends = [ - '_decimal/docstrings.h', - '_decimal/libmpdec/basearith.h', - '_decimal/libmpdec/bits.h', - '_decimal/libmpdec/constants.h', - '_decimal/libmpdec/convolute.h', - '_decimal/libmpdec/crt.h', - '_decimal/libmpdec/difradix2.h', - '_decimal/libmpdec/fnt.h', - '_decimal/libmpdec/fourstep.h', - '_decimal/libmpdec/io.h', - '_decimal/libmpdec/mpalloc.h', - '_decimal/libmpdec/mpdecimal.h', - '_decimal/libmpdec/numbertheory.h', - '_decimal/libmpdec/sixstep.h', - '_decimal/libmpdec/transpose.h', - '_decimal/libmpdec/typearith.h', - '_decimal/libmpdec/umodarith.h', - ] - - config = { - 'x64': [('CONFIG_64','1'), ('ASM','1')], - 'uint128': [('CONFIG_64','1'), ('ANSI','1'), ('HAVE_UINT128_T','1')], - 'ansi64': [('CONFIG_64','1'), ('ANSI','1')], - 'ppro': [('CONFIG_32','1'), ('PPRO','1'), ('ASM','1')], - 'ansi32': [('CONFIG_32','1'), ('ANSI','1')], - 'ansi-legacy': [('CONFIG_32','1'), ('ANSI','1'), - ('LEGACY_COMPILER','1')], - 'universal': [('UNIVERSAL','1')] - } - - cc = sysconfig.get_config_var('CC') - sizeof_size_t = sysconfig.get_config_var('SIZEOF_SIZE_T') - machine = os.environ.get('PYTHON_DECIMAL_WITH_MACHINE') - - if machine: - # Override automatic configuration to facilitate testing. - define_macros = config[machine] - elif host_platform == 'darwin': - # Universal here means: build with the same options Python - # was built with. - define_macros = config['universal'] - elif sizeof_size_t == 8: - if sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X64'): - define_macros = config['x64'] - elif sysconfig.get_config_var('HAVE_GCC_UINT128_T'): - define_macros = config['uint128'] - else: - define_macros = config['ansi64'] - elif sizeof_size_t == 4: - ppro = sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X87') - if ppro and ('gcc' in cc or 'clang' in cc) and \ - not 'sunos' in host_platform: - # solaris: problems with register allocation. - # icc >= 11.0 works as well. - define_macros = config['ppro'] - extra_compile_args.append('-Wno-unknown-pragmas') - else: - define_macros = config['ansi32'] - else: - raise DistutilsError("_decimal: unsupported architecture") - - # Workarounds for toolchain bugs: - if sysconfig.get_config_var('HAVE_IPA_PURE_CONST_BUG'): - # Some versions of gcc miscompile inline asm: - # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491 - # http://gcc.gnu.org/ml/gcc/2010-11/msg00366.html - extra_compile_args.append('-fno-ipa-pure-const') - if sysconfig.get_config_var('HAVE_GLIBC_MEMMOVE_BUG'): - # _FORTIFY_SOURCE wrappers for memmove and bcopy are incorrect: - # http://sourceware.org/ml/libc-alpha/2010-12/msg00009.html - undef_macros.append('_FORTIFY_SOURCE') - - # Faster version without thread local contexts: - if not sysconfig.get_config_var('WITH_THREAD'): - define_macros.append(('WITHOUT_THREADS', 1)) - - # Uncomment for extra functionality: - #define_macros.append(('EXTRA_FUNCTIONALITY', 1)) - ext = Extension ( - '_decimal', - include_dirs=include_dirs, - libraries=libraries, - define_macros=define_macros, - undef_macros=undef_macros, - extra_compile_args=extra_compile_args, - sources=sources, - depends=depends - ) - return ext - - def _detect_nis(self, inc_dirs, lib_dirs): - if host_platform in {'win32', 'cygwin', 'qnx6'}: - return None - - libs = [] - library_dirs = [] - includes_dirs = [] - - # bpo-32521: glibc has deprecated Sun RPC for some time. Fedora 28 - # moved headers and libraries to libtirpc and libnsl. The headers - # are in tircp and nsl sub directories. - rpcsvc_inc = find_file( - 'rpcsvc/yp_prot.h', inc_dirs, - [os.path.join(inc_dir, 'nsl') for inc_dir in inc_dirs] - ) - rpc_inc = find_file( - 'rpc/rpc.h', inc_dirs, - [os.path.join(inc_dir, 'tirpc') for inc_dir in inc_dirs] - ) - if rpcsvc_inc is None or rpc_inc is None: - # not found - return None - includes_dirs.extend(rpcsvc_inc) - includes_dirs.extend(rpc_inc) - - if self.compiler.find_library_file(lib_dirs, 'nsl'): - libs.append('nsl') - else: - # libnsl-devel: check for libnsl in nsl/ subdirectory - nsl_dirs = [os.path.join(lib_dir, 'nsl') for lib_dir in lib_dirs] - libnsl = self.compiler.find_library_file(nsl_dirs, 'nsl') - if libnsl is not None: - library_dirs.append(os.path.dirname(libnsl)) - libs.append('nsl') - - if self.compiler.find_library_file(lib_dirs, 'tirpc'): - libs.append('tirpc') - - return Extension( - 'nis', ['nismodule.c'], - libraries=libs, - library_dirs=library_dirs, - include_dirs=includes_dirs - ) - - -class PyBuildInstall(install): - # Suppress the warning about installation into the lib_dynload - # directory, which is not in sys.path when running Python during - # installation: - def initialize_options (self): - install.initialize_options(self) - self.warn_dir=0 - - # Customize subcommands to not install an egg-info file for Python - sub_commands = [('install_lib', install.has_lib), - ('install_headers', install.has_headers), - ('install_scripts', install.has_scripts), - ('install_data', install.has_data)] - - -class PyBuildInstallLib(install_lib): - # Do exactly what install_lib does but make sure correct access modes get - # set on installed directories and files. All installed files with get - # mode 644 unless they are a shared library in which case they will get - # mode 755. All installed directories will get mode 755. - - # this is works for EXT_SUFFIX too, which ends with SHLIB_SUFFIX - shlib_suffix = sysconfig.get_config_var("SHLIB_SUFFIX") - - def install(self): - outfiles = install_lib.install(self) - self.set_file_modes(outfiles, 0o644, 0o755) - self.set_dir_modes(self.install_dir, 0o755) - return outfiles - - def set_file_modes(self, files, defaultMode, sharedLibMode): - if not self.is_chmod_supported(): return - if not files: return - - for filename in files: - if os.path.islink(filename): continue - mode = defaultMode - if filename.endswith(self.shlib_suffix): mode = sharedLibMode - log.info("changing mode of %s to %o", filename, mode) - if not self.dry_run: os.chmod(filename, mode) - - def set_dir_modes(self, dirname, mode): - if not self.is_chmod_supported(): return - for dirpath, dirnames, fnames in os.walk(dirname): - if os.path.islink(dirpath): - continue - log.info("changing mode of %s to %o", dirpath, mode) - if not self.dry_run: os.chmod(dirpath, mode) - - def is_chmod_supported(self): - return hasattr(os, 'chmod') - -class PyBuildScripts(build_scripts): - def copy_scripts(self): - outfiles, updated_files = build_scripts.copy_scripts(self) - fullversion = '-{0[0]}.{0[1]}'.format(sys.version_info) - minoronly = '.{0[1]}'.format(sys.version_info) - newoutfiles = [] - newupdated_files = [] - for filename in outfiles: - if filename.endswith(('2to3', 'pyvenv')): - newfilename = filename + fullversion - else: - newfilename = filename + minoronly - log.info('renaming %s to %s', filename, newfilename) - os.rename(filename, newfilename) - newoutfiles.append(newfilename) - if filename in updated_files: - newupdated_files.append(newfilename) - return newoutfiles, newupdated_files - -SUMMARY = """ -Python is an interpreted, interactive, object-oriented programming -language. It is often compared to Tcl, Perl, Scheme or Java. - -Python combines remarkable power with very clear syntax. It has -modules, classes, exceptions, very high level dynamic data types, and -dynamic typing. There are interfaces to many system calls and -libraries, as well as to various windowing systems (X11, Motif, Tk, -Mac, MFC). New built-in modules are easily written in C or C++. Python -is also usable as an extension language for applications that need a -programmable interface. - -The Python implementation is portable: it runs on many brands of UNIX, -on Windows, DOS, Mac, Amiga... If your favorite system isn't -listed here, it may still be supported, if there's a C compiler for -it. Ask around on comp.lang.python -- or just try compiling Python -yourself. -""" - -CLASSIFIERS = """ -Development Status :: 6 - Mature -License :: OSI Approved :: Python Software Foundation License -Natural Language :: English -Programming Language :: C -Programming Language :: Python -Topic :: Software Development -""" - -def main(): - # turn off warnings when deprecated modules are imported - import warnings - warnings.filterwarnings("ignore",category=DeprecationWarning) - setup(# PyPI Metadata (PEP 301) - name = "Python", - version = sys.version.split()[0], - url = "http://www.python.org/%d.%d" % sys.version_info[:2], - maintainer = "Guido van Rossum and the Python community", - maintainer_email = "python-dev@python.org", - description = "A high-level object-oriented programming language", - long_description = SUMMARY.strip(), - license = "PSF license", - classifiers = [x for x in CLASSIFIERS.split("\n") if x], - platforms = ["Many"], - - # Build info - cmdclass = {'build_ext': PyBuildExt, - 'build_scripts': PyBuildScripts, - 'install': PyBuildInstall, - 'install_lib': PyBuildInstallLib}, - # The struct module is defined here, because build_ext won't be - # called unless there's at least one extension module defined. - ext_modules=[Extension('_struct', ['_struct.c'])], - - # If you change the scripts installed here, you also need to - # check the PyBuildScripts command above, and change the links - # created by the bininstall target in Makefile.pre.in - scripts = ["Tools/scripts/pydoc3", "Tools/scripts/idle3", - "Tools/scripts/2to3", "Tools/scripts/pyvenv"] - ) - -# --install-platlib -if __name__ == '__main__': - main() diff --git a/tool/build/ar.c b/tool/build/ar.c index 487d6ef8a..750f8f10f 100644 --- a/tool/build/ar.c +++ b/tool/build/ar.c @@ -125,6 +125,8 @@ int main(int argc, char *argv[]) { int *offsets, *modes, *sizes, *names; int i, j, fd, err, name, outfd, tablebufsize; + if (argc == 2 && !strcmp(argv[1], "-n")) exit(0); + if (!(argc > 2 && strcmp(argv[1], "rcsD") == 0)) { fprintf(stderr, "%s%s%s\n", "Usage: ", argv[0], " rcsD ARCHIVE FILE..."); return 1; diff --git a/tool/build/build.mk b/tool/build/build.mk index d5820a54a..4ef7a41cf 100644 --- a/tool/build/build.mk +++ b/tool/build/build.mk @@ -79,6 +79,46 @@ o/$(MODE)/tool/build/%.com.dbg: \ $(APE) -@$(APELINK) +o/$(MODE)/tool/build/ar.com.dbg: \ + $(TOOL_BUILD_DEPS) \ + o/$(MODE)/tool/build/build.pkg \ + o/$(MODE)/tool/build/ar.o \ + $(CRT) \ + $(APE_BUILDSAFE) + -@$(APELINK) + +o/$(MODE)/tool/build/package.com.dbg: \ + $(TOOL_BUILD_DEPS) \ + o/$(MODE)/tool/build/build.pkg \ + o/$(MODE)/tool/build/package.o \ + $(CRT) \ + $(APE_BUILDSAFE) + -@$(APELINK) + +o/$(MODE)/tool/build/mkdeps.com.dbg: \ + $(TOOL_BUILD_DEPS) \ + o/$(MODE)/tool/build/build.pkg \ + o/$(MODE)/tool/build/mkdeps.o \ + $(CRT) \ + $(APE_BUILDSAFE) + -@$(APELINK) + +o/$(MODE)/tool/build/compile.com.dbg: \ + $(TOOL_BUILD_DEPS) \ + o/$(MODE)/tool/build/build.pkg \ + o/$(MODE)/tool/build/compile.o \ + $(CRT) \ + $(APE_BUILDSAFE) + -@$(APELINK) + +o/$(MODE)/tool/build/zipobj.com.dbg: \ + $(TOOL_BUILD_DEPS) \ + o/$(MODE)/tool/build/build.pkg \ + o/$(MODE)/tool/build/zipobj.o \ + $(CRT) \ + $(APE_BUILDSAFE) + -@$(APELINK) + o/$(MODE)/tool/build/emulator.o: \ OVERRIDE_COPTS += \ -fno-sanitize=pointer-overflow diff --git a/tool/build/lib/isnocompressext.c b/tool/build/lib/isnocompressext.c new file mode 100644 index 000000000..7311d5daf --- /dev/null +++ b/tool/build/lib/isnocompressext.c @@ -0,0 +1,71 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/bits/bits.h" +#include "libc/bits/bswap.h" +#include "libc/macros.internal.h" +#include "libc/str/str.h" +#include "tool/build/lib/isnocompressext.h" + +static const char kNoCompressExts[][8] = { + "bz2", // + "gif", // + "gz", // + "jpg", // + "lz4", // + "mp4", // + "mpeg", // + "mpg", // + "png", // + "webp", // + "xz", // + "zip", // +}; + +static bool BisectNoCompressExts(uint64_t ext) { + int c, m, l, r; + l = 0; + r = ARRAYLEN(kNoCompressExts) - 1; + while (l <= r) { + m = (l + r) >> 1; + if (READ64BE(kNoCompressExts[m]) < ext) { + l = m + 1; + } else if (READ64BE(kNoCompressExts[m]) > ext) { + r = m - 1; + } else { + return true; + } + } + return false; +} + +bool IsNoCompressExt(const char *p, size_t n) { + int c; + uint64_t w; + if (n == -1) n = p ? strlen(p) : 0; + if (n) { + for (w = 0; n--;) { + c = p[n] & 255; + if (c == '.') break; + w <<= 8; + w |= kToLower[c]; + } + return BisectNoCompressExts(bswap_64(w)); + } + return false; +} diff --git a/tool/build/lib/isnocompressext.h b/tool/build/lib/isnocompressext.h new file mode 100644 index 000000000..be7bb4b7f --- /dev/null +++ b/tool/build/lib/isnocompressext.h @@ -0,0 +1,10 @@ +#ifndef COSMOPOLITAN_TOOL_BUILD_LIB_ISNOCOMPRESSEXT_H_ +#define COSMOPOLITAN_TOOL_BUILD_LIB_ISNOCOMPRESSEXT_H_ +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +bool IsNoCompressExt(const char *, size_t); + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_TOOL_BUILD_LIB_ISNOCOMPRESSEXT_H_ */ diff --git a/tool/build/lib/stripcomponents.c b/tool/build/lib/stripcomponents.c new file mode 100644 index 000000000..eac7e7bb0 --- /dev/null +++ b/tool/build/lib/stripcomponents.c @@ -0,0 +1,38 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "tool/build/lib/stripcomponents.h" + +/** + * Strips leading directory components. + * + * The basename is never stripped. + */ +char *StripComponents(const char *path, int n) { + const char *p; + while (n-- > 0) { + while (*path == '/') ++path; + for (p = path; *p; ++p) { + if (*p == '/') { + path = p + 1; + break; + } + } + } + return (char *)path; +} diff --git a/tool/build/lib/stripcomponents.h b/tool/build/lib/stripcomponents.h new file mode 100644 index 000000000..32bed1326 --- /dev/null +++ b/tool/build/lib/stripcomponents.h @@ -0,0 +1,10 @@ +#ifndef COSMOPOLITAN_TOOL_BUILD_LIB_STRIPCOMPONENTS_H_ +#define COSMOPOLITAN_TOOL_BUILD_LIB_STRIPCOMPONENTS_H_ +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +char *StripComponents(const char *, int); + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_TOOL_BUILD_LIB_STRIPCOMPONENTS_H_ */ diff --git a/tool/build/lib/syscall.c b/tool/build/lib/syscall.c index 9ffd239f8..5d2c61838 100644 --- a/tool/build/lib/syscall.c +++ b/tool/build/lib/syscall.c @@ -102,7 +102,7 @@ const struct MachineFdCb kMachineFdCbHost = { .close = close, .readv = readv, .writev = writev, - .ioctl = ioctl, + .ioctl = (void *)ioctl, }; static int XlatSignal(int sig) { diff --git a/tool/build/mkdeps.c b/tool/build/mkdeps.c index b91da3889..c93dcd76f 100644 --- a/tool/build/mkdeps.c +++ b/tool/build/mkdeps.c @@ -369,6 +369,7 @@ int main(int argc, char *argv[]) { bool needprefix; size_t i, bitmaplen; const char *path, *prefix; + if (argc == 2 && !strcmp(argv[1], "-n")) exit(0); showcrashreports(); out = "/dev/stdout"; GetOpts(argc, argv); diff --git a/tool/build/package.c b/tool/build/package.c index a6c1f8184..8a925dc5c 100644 --- a/tool/build/package.c +++ b/tool/build/package.c @@ -679,6 +679,7 @@ void Package(int argc, char *argv[], struct Package *pkg, int main(int argc, char *argv[]) { struct Package pkg; struct Packages deps; + if (argc == 2 && !strcmp(argv[1], "-n")) exit(0); showcrashreports(); memset(&pkg, 0, sizeof(pkg)); memset(&deps, 0, sizeof(deps)); diff --git a/tool/build/zipobj.c b/tool/build/zipobj.c index 52669dfcc..1271b2891 100644 --- a/tool/build/zipobj.c +++ b/tool/build/zipobj.c @@ -18,6 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/alg/arraylist.internal.h" #include "libc/bits/bits.h" +#include "libc/bits/bswap.h" #include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" @@ -33,6 +34,7 @@ #include "libc/nexgen32e/crc32.h" #include "libc/nt/enum/fileflagandattributes.h" #include "libc/nt/struct/imageauxsymbolex.internal.h" +#include "libc/rand/rand.h" #include "libc/runtime/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/runtime/symbols.internal.h" @@ -52,23 +54,26 @@ #include "third_party/getopt/getopt.h" #include "third_party/zlib/zlib.h" #include "tool/build/lib/elfwriter.h" +#include "tool/build/lib/isnocompressext.h" +#include "tool/build/lib/stripcomponents.h" #define ZIP_LOCALFILE_SECTION ".zip.2." #define ZIP_DIRECTORY_SECTION ".zip.4." +char *name_; +char *yoink_; char *symbol_; char *outpath_; -char *yoink_; +bool nocompress_; +bool basenamify_; int64_t image_base_; - -const size_t kMinCompressSize = 32; -const char kNoCompressExts[][8] = {".gz", ".xz", ".jpg", ".png", - ".gif", ".zip", ".bz2", ".mpg", - ".mp4", ".lz4", ".webp", ".mpeg"}; +int strip_components_; +const char *path_prefix_; wontreturn void PrintUsage(int rc, FILE *f) { fprintf(f, "%s%s%s\n", "Usage: ", program_invocation_name, - " [-o FILE] [-s SYMBOL] [-y YOINK] [FILE...]\n"); + " [-n] [-B] [-C INT] [-P PREFIX] [-o FILE] [-s SYMBOL] [-y YOINK] " + "[FILE...]\n"); exit(rc); } @@ -76,20 +81,37 @@ void GetOpts(int *argc, char ***argv) { int opt; yoink_ = "__zip_start"; image_base_ = IMAGE_BASE_VIRTUAL; - while ((opt = getopt(*argc, *argv, "?ho:s:y:b:")) != -1) { + while ((opt = getopt(*argc, *argv, "?0nhBN:C:P:o:s:y:b:")) != -1) { switch (opt) { case 'o': outpath_ = optarg; break; + case 'n': + exit(0); case 's': symbol_ = optarg; break; case 'y': yoink_ = optarg; break; + case 'N': + name_ = optarg; + break; + case 'P': + path_prefix_ = optarg; + break; + case 'C': + strip_components_ = atoi(optarg); + break; + case 'B': + basenamify_ = true; + break; case 'b': image_base_ = strtol(optarg, NULL, 0); break; + case '0': + nocompress_ = true; + break; case '?': case 'h': PrintUsage(EXIT_SUCCESS, stdout); @@ -105,8 +127,8 @@ void GetOpts(int *argc, char ***argv) { bool IsUtf8(const void *data, size_t size) { const unsigned char *p, *pe; for (p = data, pe = p + size; p + 2 <= pe; ++p) { - if (*p >= 0300) { - if (*p >= 0200 && *p < 0300) { + if (p[0] >= 0300) { + if (p[1] >= 0200 && p[1] < 0300) { return true; } else { return false; @@ -126,16 +148,10 @@ bool IsText(const void *data, size_t size) { return true; } -bool ShouldCompress(const char *name, size_t size) { - size_t i; - char key[8]; - const char *p; - if (!(p = memrchr(name, '.', size))) return true; - strncpy(key, p, sizeof(key)); - for (i = 0; i < ARRAYLEN(kNoCompressExts); ++i) { - if (memcmp(key, kNoCompressExts[i], sizeof(key)) == 0) return false; - } - return true; +bool ShouldCompress(const char *name, size_t namesize, + const unsigned char *data, size_t datasize) { + return !nocompress_ && datasize >= 64 && !IsNoCompressExt(name, namesize) && + (datasize < 1000 || MeasureEntropy((void *)data, 1000) < 6); } void GetDosLocalTime(int64_t utcunixts, uint16_t *out_time, @@ -242,10 +258,12 @@ void EmitZip(struct ElfWriter *elf, const char *name, size_t namesize, crc = crc32_z(0, data, uncompsize); GetDosLocalTime(st->st_mtim.tv_sec, &mtime, &mdate); if (IsUtf8(name, namesize)) gflags |= kZipGflagUtf8; - if (IsText(data, st->st_size)) iattrs |= kZipIattrText; + if (S_ISREG(st->st_mode) && IsText(data, st->st_size)) { + iattrs |= kZipIattrText; + } commentsize = kZipCdirHdrLinkableSize - (CFILE_HDR_SIZE + namesize); dosmode = !(st->st_mode & 0200) ? kNtFileAttributeReadonly : 0; - method = (st->st_size >= kMinCompressSize && ShouldCompress(name, namesize)) + method = ShouldCompress(name, namesize, data, st->st_size) ? kZipCompressionDeflate : kZipCompressionNone; @@ -310,20 +328,34 @@ void ProcessFile(struct ElfWriter *elf, const char *path) { void *map; size_t pathlen; struct stat st; - pathlen = strlen(path); + const char *name; CHECK_NE(-1, (fd = open(path, O_RDONLY))); CHECK_NE(-1, fstat(fd, &st)); - if (st.st_size) { + if (S_ISDIR(st.st_mode)) { + map = ""; + st.st_size = 0; + } else if (st.st_size) { CHECK_NE(MAP_FAILED, (map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0))); - CHECK_NE(-1, close(fd)); } else { map = NULL; } - EmitZip(elf, path, pathlen, map, &st); - if (st.st_size) { - CHECK_NE(-1, munmap(map, st.st_size)); + if (name_) { + name = name_; + } else { + name = path; + if (basenamify_) name = basename(name); + name = StripComponents(name, strip_components_); + if (path_prefix_) name = gc(xjoinpaths(path_prefix_, name)); } + if (S_ISDIR(st.st_mode)) { + if (!endswith(name, "/")) { + name = gc(xasprintf("%s/", name)); + } + } + EmitZip(elf, name, strlen(name), map, &st); + if (st.st_size) CHECK_NE(-1, munmap(map, st.st_size)); + close(fd); } void PullEndOfCentralDirectoryIntoLinkage(struct ElfWriter *elf) { diff --git a/tool/emacs/cosmo-platform-constants.el b/tool/emacs/cosmo-platform-constants.el index 2003457d8..8c078a353 100644 --- a/tool/emacs/cosmo-platform-constants.el +++ b/tool/emacs/cosmo-platform-constants.el @@ -74,6 +74,7 @@ (cosmo '("__COSMOPOLITAN__" + "__ANDROID__" "__LINKER__")) ) diff --git a/tool/net/net.mk b/tool/net/net.mk index 354e3de2f..47e92dff4 100644 --- a/tool/net/net.mk +++ b/tool/net/net.mk @@ -7,73 +7,73 @@ TOOL_NET_FILES := $(wildcard tool/net/*) TOOL_NET_SRCS = $(filter %.c,$(TOOL_NET_FILES)) TOOL_NET_HDRS = $(filter %.h,$(TOOL_NET_FILES)) -TOOL_NET_OBJS = \ +TOOL_NET_OBJS = \ $(TOOL_NET_SRCS:%.c=o/$(MODE)/%.o) -TOOL_NET_BINS = \ - $(TOOL_NET_COMS) \ +TOOL_NET_BINS = \ + $(TOOL_NET_COMS) \ $(TOOL_NET_COMS:%=%.dbg) -TOOL_NET_COMS = \ - o/$(MODE)/tool/net/dig.com \ - o/$(MODE)/tool/net/echoserver.com \ - o/$(MODE)/tool/net/redbean.com \ - o/$(MODE)/tool/net/redbean-demo.com \ - o/$(MODE)/tool/net/redbean-static.com \ - o/$(MODE)/tool/net/redbean-unsecure.com \ - o/$(MODE)/tool/net/redbean-original.com \ - o/$(MODE)/tool/net/echoserver.com \ +TOOL_NET_COMS = \ + o/$(MODE)/tool/net/dig.com \ + o/$(MODE)/tool/net/echoserver.com \ + o/$(MODE)/tool/net/redbean.com \ + o/$(MODE)/tool/net/redbean-demo.com \ + o/$(MODE)/tool/net/redbean-static.com \ + o/$(MODE)/tool/net/redbean-unsecure.com \ + o/$(MODE)/tool/net/redbean-original.com \ + o/$(MODE)/tool/net/echoserver.com \ o/$(MODE)/tool/net/wb.com -TOOL_NET_DIRECTDEPS = \ - LIBC_ALG \ - LIBC_BITS \ - LIBC_CALLS \ - LIBC_DNS \ - LIBC_FMT \ - LIBC_INTRIN \ - LIBC_LOG \ - LIBC_MEM \ - LIBC_NEXGEN32E \ - LIBC_NT_IPHLPAPI \ - LIBC_NT_KERNEL32 \ - LIBC_RAND \ - LIBC_RUNTIME \ - LIBC_SOCK \ - LIBC_STDIO \ - LIBC_STR \ - LIBC_STUBS \ - LIBC_SYSV \ - LIBC_SYSV_CALLS \ - LIBC_TIME \ - LIBC_TINYMATH \ - LIBC_UNICODE \ - LIBC_X \ - LIBC_ZIPOS \ - NET_HTTP \ - NET_HTTPS \ - TOOL_BUILD_LIB \ - THIRD_PARTY_GDTOA \ - THIRD_PARTY_GETOPT \ - THIRD_PARTY_LUA \ - THIRD_PARTY_MBEDTLS \ - THIRD_PARTY_REGEX \ - THIRD_PARTY_SQLITE3 \ - THIRD_PARTY_ZLIB \ +TOOL_NET_DIRECTDEPS = \ + LIBC_ALG \ + LIBC_BITS \ + LIBC_CALLS \ + LIBC_DNS \ + LIBC_FMT \ + LIBC_INTRIN \ + LIBC_LOG \ + LIBC_MEM \ + LIBC_NEXGEN32E \ + LIBC_NT_IPHLPAPI \ + LIBC_NT_KERNEL32 \ + LIBC_RAND \ + LIBC_RUNTIME \ + LIBC_SOCK \ + LIBC_STDIO \ + LIBC_STR \ + LIBC_STUBS \ + LIBC_SYSV \ + LIBC_SYSV_CALLS \ + LIBC_TIME \ + LIBC_TINYMATH \ + LIBC_UNICODE \ + LIBC_X \ + LIBC_ZIPOS \ + NET_HTTP \ + NET_HTTPS \ + TOOL_BUILD_LIB \ + THIRD_PARTY_GDTOA \ + THIRD_PARTY_GETOPT \ + THIRD_PARTY_LUA \ + THIRD_PARTY_MBEDTLS \ + THIRD_PARTY_REGEX \ + THIRD_PARTY_SQLITE3 \ + THIRD_PARTY_ZLIB \ TOOL_DECODE_LIB -TOOL_NET_DEPS := \ +TOOL_NET_DEPS := \ $(call uniq,$(foreach x,$(TOOL_NET_DIRECTDEPS),$($(x)))) -o/$(MODE)/tool/net/net.pkg: \ - $(TOOL_NET_OBJS) \ +o/$(MODE)/tool/net/net.pkg: \ + $(TOOL_NET_OBJS) \ $(foreach x,$(TOOL_NET_DIRECTDEPS),$($(x)_A).pkg) -o/$(MODE)/tool/net/%.com.dbg: \ - $(TOOL_NET_DEPS) \ - o/$(MODE)/tool/net/%.o \ - o/$(MODE)/tool/net/net.pkg \ - $(CRT) \ +o/$(MODE)/tool/net/%.com.dbg: \ + $(TOOL_NET_DEPS) \ + o/$(MODE)/tool/net/%.o \ + o/$(MODE)/tool/net/net.pkg \ + $(CRT) \ $(APE) @$(APELINK) @@ -81,22 +81,22 @@ o/$(MODE)/tool/net/%.com.dbg: \ # # The little web server that could! -o/$(MODE)/tool/net/redbean.com.dbg: \ - $(TOOL_NET_DEPS) \ - o/$(MODE)/tool/net/redbean.o \ - o/$(MODE)/tool/net/lsqlite3.o \ - o/$(MODE)/tool/net/net.pkg \ - $(CRT) \ +o/$(MODE)/tool/net/redbean.com.dbg: \ + $(TOOL_NET_DEPS) \ + o/$(MODE)/tool/net/redbean.o \ + o/$(MODE)/tool/net/lsqlite3.o \ + o/$(MODE)/tool/net/net.pkg \ + $(CRT) \ $(APE) @$(APELINK) -o/$(MODE)/tool/net/redbean.com: \ - o/$(MODE)/tool/net/redbean.com.dbg \ - o/$(MODE)/host/third_party/infozip/zip.com \ - tool/net/net.mk \ - tool/net/help.txt \ - tool/net/.init.lua \ - tool/net/favicon.ico \ +o/$(MODE)/tool/net/redbean.com: \ + o/$(MODE)/tool/net/redbean.com.dbg \ + o/$(MODE)/host/third_party/infozip/zip.com \ + tool/net/net.mk \ + tool/net/help.txt \ + tool/net/.init.lua \ + tool/net/favicon.ico \ tool/net/redbean.png @$(COMPILE) -AOBJCOPY -T$@ $(OBJCOPY) -S -O binary $< $@ @$(COMPILE) -ADD -T$@ dd if=$@ of=o/$(MODE)/tool/net/.ape bs=64 count=11 conv=notrunc 2>/dev/null @@ -108,80 +108,93 @@ o/$(MODE)/tool/net/redbean.com: \ # bundles a bunch of example code and there's a live of it available # online at http://redbean.justine.lol/ -o/$(MODE)/tool/net/redbean-demo.com.dbg: \ - o/$(MODE)/tool/net/redbean.com.dbg - @$(COMPILE) -ACP -T$@ cp $< $@ +o/$(MODE)/tool/net/demo/.init.lua.zip.o \ +o/$(MODE)/tool/net/demo/.reload.lua.zip.o \ +o/$(MODE)/tool/net/demo/sql.lua.zip.o \ +o/$(MODE)/tool/net/demo/fetch.lua.zip.o \ +o/$(MODE)/tool/net/demo/hello.lua.zip.o \ +o/$(MODE)/tool/net/demo/redbean.lua.zip.o \ +o/$(MODE)/tool/net/demo/opensource.lua.zip.o \ +o/$(MODE)/tool/net/demo/closedsource.lua.zip.o \ +o/$(MODE)/tool/net/demo/printpayload.lua.zip.o \ +o/$(MODE)/tool/net/demo/redbean-form.lua.zip.o \ +o/$(MODE)/tool/net/demo/redbean-xhr.lua.zip.o \ +o/$(MODE)/tool/net/redbean.png.zip.o \ +o/$(MODE)/tool/net/favicon.ico.zip.o \ +o/$(MODE)/tool/net/demo/404.html.zip.o: \ + ZIPOBJ_FLAGS += \ + -B -o/$(MODE)/tool/net/redbean-demo.com: \ - o/$(MODE)/tool/net/redbean-demo.com.dbg \ - o/$(MODE)/host/third_party/infozip/zip.com \ - tool/net/net.mk \ - tool/net/favicon.ico \ - tool/net/redbean.png \ - tool/net/help.txt \ - tool/net/demo/.init.lua \ - tool/net/demo/.reload.lua \ - tool/net/demo/.lua/mymodule.lua \ - tool/net/demo/sql.lua \ - tool/net/demo/404.html \ - tool/net/demo/hello.lua \ - tool/net/demo/index.html \ - tool/net/demo/redbean.css \ - tool/net/demo/redbean.lua \ - tool/net/demo/redbean-form.lua \ - tool/net/demo/redbean-xhr.lua \ - tool/net/demo/seekable.txt \ - tool/net/demo/virtualbean.html \ - tool/net/demo/printpayload.lua \ - tool/net/demo/opensource.lua \ - o/$(MODE)/tool/net/demo/closedsource.lua \ - tool/net/demo/fetch.lua \ - tool/net/redbean.c \ - net/http/parsehttpmessage.c \ - net/http/parseurl.c \ - net/http/encodeurl.c \ - test/net/http/parsehttpmessage_test.c \ - test/net/http/parseurl_test.c +o/$(MODE)/tool/net/demo/.lua/mymodule.lua.zip.o: \ + ZIPOBJ_FLAGS += \ + -C3 + +o/$(MODE)/tool/net/demo/seekable.txt.zip.o: \ + ZIPOBJ_FLAGS += \ + -B \ + -0 + +o/$(MODE)/tool/net/demo/virtualbean.html.zip.o: \ + ZIPOBJ_FLAGS += \ + -Predbean.justine.lol \ + -B + +o/$(MODE)/tool/net/redbean-demo.com.dbg: \ + $(TOOL_NET_DEPS) \ + o/$(MODE)/tool/net/redbean.o \ + o/$(MODE)/tool/net/lsqlite3.o \ + o/$(MODE)/tool/net/net.pkg \ + o/$(MODE)/tool/net/demo/sql.lua.zip.o \ + o/$(MODE)/tool/net/demo/fetch.lua.zip.o \ + o/$(MODE)/tool/net/demo/hello.lua.zip.o \ + o/$(MODE)/tool/net/demo/redbean.lua.zip.o \ + o/$(MODE)/tool/net/demo/opensource.lua.zip.o \ + o/$(MODE)/tool/net/demo/closedsource.lua.zip.o \ + o/$(MODE)/tool/net/demo/printpayload.lua.zip.o \ + o/$(MODE)/tool/net/demo/redbean-form.lua.zip.o \ + o/$(MODE)/tool/net/demo/redbean-xhr.lua.zip.o \ + o/$(MODE)/tool/net/demo/index.html.zip.o \ + o/$(MODE)/tool/net/demo/redbean.css.zip.o \ + o/$(MODE)/tool/net/redbean.png.zip.o \ + o/$(MODE)/tool/net/favicon.ico.zip.o \ + o/$(MODE)/tool/net/demo/404.html.zip.o \ + o/$(MODE)/tool/net/demo/seekable.txt.zip.o \ + o/$(MODE)/tool/net/demo/virtualbean.html.zip.o \ + o/$(MODE)/tool/net/demo/.lua/mymodule.lua.zip.o \ + o/$(MODE)/tool/net/demo/.reload.lua.zip.o \ + o/$(MODE)/tool/net/demo/.init.lua.zip.o \ + $(CRT) \ + $(APE) + @$(APELINK) + +o/$(MODE)/tool/net/redbean-demo.com: \ + o/$(MODE)/tool/net/redbean-demo.com.dbg @$(COMPILE) -AOBJCOPY -T$@ $(OBJCOPY) -S -O binary $< $@ @$(COMPILE) -AMKDIR -T$@ mkdir -p o/$(MODE)/tool/net/.redbean-demo @$(COMPILE) -ADD -T$@ dd if=$@ of=o/$(MODE)/tool/net/.redbean-demo/.ape bs=64 count=11 conv=notrunc 2>/dev/null - @$(COMPILE) -AZIP -T$@ o/$(MODE)/host/third_party/infozip/zip.com -qj $@ o/$(MODE)/tool/net/.redbean-demo/.ape tool/net/help.txt tool/net/demo/.init.lua tool/net/demo/.reload.lua - @$(COMPILE) -ARM -T$@ rm -rf o/$(MODE)/tool/net/.lua - @$(COMPILE) -ACP -T$@ cp -R tool/net/demo/.lua o/$(MODE)/tool/net/ - @(cd o/$(MODE)/tool/net && ../../host/third_party/infozip/zip.com -qr redbean-demo.com .lua) - @$(COMPILE) -AZIP -T$@ o/$(MODE)/host/third_party/infozip/zip.com -qj $@ tool/net/demo/hello.lua tool/net/demo/sql.lua - @echo "<-- check out this lua server page" | $(COMPILE) -AZIP -T$@ o/$(MODE)/host/third_party/infozip/zip.com -cqj $@ tool/net/demo/redbean.lua - @$(COMPILE) -AZIP -T$@ o/$(MODE)/host/third_party/infozip/zip.com -qj $@ tool/net/demo/404.html tool/net/favicon.ico tool/net/redbean.png tool/net/demo/redbean-form.lua tool/net/demo/redbean-xhr.lua tool/net/demo/printpayload.lua tool/net/demo/fetch.lua o/$(MODE)/tool/net/demo/closedsource.lua tool/net/demo/opensource.lua - @echo Uncompressed for HTTP Range requests | $(COMPILE) -AZIP -T$@ o/$(MODE)/host/third_party/infozip/zip.com -cqj0 $@ tool/net/demo/seekable.txt - @$(COMPILE) -AZIP -T$@ o/$(MODE)/host/third_party/infozip/zip.com -q $@ tool/net/ tool/net/demo/ tool/net/demo/index.html tool/net/demo/redbean.css tool/net/redbean.c net/http/parsehttpmessage.c net/http/parseurl.c net/http/encodeurl.c test/net/http/parsehttpmessage_test.c test/net/http/parseurl_test.c - @$(COMPILE) -AMKDIR -T$@ mkdir -p o/$(MODE)/tool/net/virtualbean.justine.lol/ - @$(COMPILE) -ACP -T$@ cp tool/net/redbean.png o/$(MODE)/tool/net/virtualbean.justine.lol/redbean.png - @$(COMPILE) -ACP -T$@ cp tool/net/demo/virtualbean.html o/$(MODE)/tool/net/virtualbean.justine.lol/index.html - @(cd o/$(MODE)/tool/net && ../../host/third_party/infozip/zip.com -q redbean-demo.com virtualbean.justine.lol/) - @(cd o/$(MODE)/tool/net && echo 'Go to http://virtualbean.justine.lol' | ../../host/third_party/infozip/zip.com -cq redbean-demo.com virtualbean.justine.lol/index.html) - @(cd o/$(MODE)/tool/net && ../../host/third_party/infozip/zip.com -q redbean-demo.com virtualbean.justine.lol/redbean.png) + @$(COMPILE) -AZIP -T$@ o/$(MODE)/host/third_party/infozip/zip.com -qj $@ o/$(MODE)/tool/net/.redbean-demo/.ape # REDBEAN-STATIC.COM # # Passing the -DSTATIC causes Lua and SQLite to be removed. This reduces # the binary size from roughly 1500 kb to 500 kb. It still supports SSL. -o/$(MODE)/tool/net/redbean-static.com: \ - o/$(MODE)/tool/net/redbean-static.com.dbg \ - o/$(MODE)/host/third_party/infozip/zip.com \ - tool/net/help.txt \ - tool/net/favicon.ico \ +o/$(MODE)/tool/net/redbean-static.com: \ + o/$(MODE)/tool/net/redbean-static.com.dbg \ + o/$(MODE)/host/third_party/infozip/zip.com \ + tool/net/help.txt \ + tool/net/favicon.ico \ tool/net/redbean.png @$(COMPILE) -AOBJCOPY -T$@ $(OBJCOPY) -S -O binary $< $@ @$(COMPILE) -AMKDIR -T$@ mkdir -p o/$(MODE)/tool/net/.redbean-static @$(COMPILE) -ADD -T$@ dd if=$@ of=o/$(MODE)/tool/net/.redbean-static/.ape bs=64 count=11 conv=notrunc 2>/dev/null @$(COMPILE) -AZIP -T$@ o/$(MODE)/host/third_party/infozip/zip.com -qj $@ o/$(MODE)/tool/net/.redbean-static/.ape tool/net/help.txt tool/net/favicon.ico tool/net/redbean.png -o/$(MODE)/tool/net/redbean-static.com.dbg: \ - $(TOOL_NET_DEPS) \ - o/$(MODE)/tool/net/redbean-static.o \ - o/$(MODE)/tool/net/net.pkg \ - $(CRT) \ +o/$(MODE)/tool/net/redbean-static.com.dbg: \ + $(TOOL_NET_DEPS) \ + o/$(MODE)/tool/net/redbean-static.o \ + o/$(MODE)/tool/net/net.pkg \ + $(CRT) \ $(APE) @$(APELINK) @@ -194,23 +207,23 @@ o/$(MODE)/tool/net/redbean-static.o: tool/net/redbean.c # That doesn't mean redbean becomes insecure. It just reduces complexity # in situations where you'd rather have SSL be handled in an edge proxy. -o/$(MODE)/tool/net/redbean-unsecure.com: \ - o/$(MODE)/tool/net/redbean-unsecure.com.dbg \ - o/$(MODE)/host/third_party/infozip/zip.com \ - tool/net/help.txt \ - tool/net/favicon.ico \ +o/$(MODE)/tool/net/redbean-unsecure.com: \ + o/$(MODE)/tool/net/redbean-unsecure.com.dbg \ + o/$(MODE)/host/third_party/infozip/zip.com \ + tool/net/help.txt \ + tool/net/favicon.ico \ tool/net/redbean.png @$(COMPILE) -AOBJCOPY -T$@ $(OBJCOPY) -S -O binary $< $@ @$(COMPILE) -AMKDIR -T$@ mkdir -p o/$(MODE)/tool/net/.redbean-unsecure @$(COMPILE) -ADD -T$@ dd if=$@ of=o/$(MODE)/tool/net/.redbean-unsecure/.ape bs=64 count=11 conv=notrunc 2>/dev/null @$(COMPILE) -AZIP -T$@ o/$(MODE)/host/third_party/infozip/zip.com -qj $@ o/$(MODE)/tool/net/.redbean-unsecure/.ape tool/net/help.txt tool/net/favicon.ico tool/net/redbean.png -o/$(MODE)/tool/net/redbean-unsecure.com.dbg: \ - $(TOOL_NET_DEPS) \ - o/$(MODE)/tool/net/redbean-unsecure.o \ - o/$(MODE)/tool/net/lsqlite3.o \ - o/$(MODE)/tool/net/net.pkg \ - $(CRT) \ +o/$(MODE)/tool/net/redbean-unsecure.com.dbg: \ + $(TOOL_NET_DEPS) \ + o/$(MODE)/tool/net/redbean-unsecure.o \ + o/$(MODE)/tool/net/lsqlite3.o \ + o/$(MODE)/tool/net/net.pkg \ + $(CRT) \ $(APE) @$(APELINK) @@ -223,23 +236,23 @@ o/$(MODE)/tool/net/redbean-unsecure.o: tool/net/redbean.c # produce 200kb binary that's very similar to redbean as it existed on # Hacker News the day it went viral. -o/$(MODE)/tool/net/redbean-original.com: \ - o/$(MODE)/tool/net/redbean-original.com.dbg \ - o/$(MODE)/host/third_party/infozip/zip.com \ - tool/net/help.txt \ - tool/net/favicon.ico \ +o/$(MODE)/tool/net/redbean-original.com: \ + o/$(MODE)/tool/net/redbean-original.com.dbg \ + o/$(MODE)/host/third_party/infozip/zip.com \ + tool/net/help.txt \ + tool/net/favicon.ico \ tool/net/redbean.png @$(COMPILE) -AOBJCOPY -T$@ $(OBJCOPY) -S -O binary $< $@ @$(COMPILE) -AMKDIR -T$@ mkdir -p o/$(MODE)/tool/net/.redbean-original @$(COMPILE) -ADD -T$@ dd if=$@ of=o/$(MODE)/tool/net/.redbean-original/.ape bs=64 count=11 conv=notrunc 2>/dev/null @$(COMPILE) -AZIP -T$@ o/$(MODE)/host/third_party/infozip/zip.com -qj $@ o/$(MODE)/tool/net/.redbean-original/.ape tool/net/help.txt tool/net/favicon.ico tool/net/redbean.png -o/$(MODE)/tool/net/redbean-original.com.dbg: \ - $(TOOL_NET_DEPS) \ - o/$(MODE)/tool/net/redbean-original.o \ - o/$(MODE)/tool/net/lsqlite3.o \ - o/$(MODE)/tool/net/net.pkg \ - $(CRT) \ +o/$(MODE)/tool/net/redbean-original.com.dbg: \ + $(TOOL_NET_DEPS) \ + o/$(MODE)/tool/net/redbean-original.o \ + o/$(MODE)/tool/net/lsqlite3.o \ + o/$(MODE)/tool/net/net.pkg \ + $(CRT) \ $(APE) @$(APELINK) @@ -247,6 +260,6 @@ o/$(MODE)/tool/net/redbean-original.o: tool/net/redbean.c @$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.c) -DSTATIC -DUNSECURE -DREDBEAN=\"redbean-original\" $(OUTPUT_OPTION) $< .PHONY: o/$(MODE)/tool/net -o/$(MODE)/tool/net: \ - $(TOOL_NET_BINS) \ +o/$(MODE)/tool/net: \ + $(TOOL_NET_BINS) \ $(TOOL_NET_CHECKS) diff --git a/tool/net/redbean.c b/tool/net/redbean.c index 2974e153d..bd33d399d 100644 --- a/tool/net/redbean.c +++ b/tool/net/redbean.c @@ -114,7 +114,6 @@ #include "third_party/mbedtls/sha1.h" #include "third_party/mbedtls/ssl.h" #include "third_party/mbedtls/ssl_ticket.h" -#include "third_party/mbedtls/traceme.h" #include "third_party/mbedtls/x509.h" #include "third_party/mbedtls/x509_crt.h" #include "third_party/regex/regex.h" @@ -1069,7 +1068,7 @@ static int LuaCallWithTrace(lua_State *L, int nargs, int nres) { // pop the coroutine, so that the function is at the top lua_pop(L, 1); // move the function (and arguments) to the top of the coro stack - lua_xmove(L, co, nargs+1); + lua_xmove(L, co, nargs + 1); // resume the coroutine thus executing the function status = lua_resume(co, L, nargs, &nresults); if (status != LUA_OK && status != LUA_YIELD) { @@ -1077,16 +1076,15 @@ static int LuaCallWithTrace(lua_State *L, int nargs, int nres) { lua_xmove(co, L, 1); // replace the error with the traceback on failure luaL_traceback(L, co, lua_tostring(L, -1), 0); - lua_remove(L, -2); // remove the error message + lua_remove(L, -2); // remove the error message } else { // move results to the main stack lua_xmove(co, L, nresults); // grow the stack in case returned fewer results // than the caller expects, as lua_resume // doesn't adjust the stack for needed results - for (; nresults < nres; nresults++) - lua_pushnil(L); - status = LUA_OK; // treat LUA_YIELD the same as LUA_OK + for (; nresults < nres; nresults++) lua_pushnil(L); + status = LUA_OK; // treat LUA_YIELD the same as LUA_OK } return status; } @@ -2533,7 +2531,8 @@ static char *CommitOutput(char *p) { return p; } -static char *ServeDefaultErrorPage(char *p, unsigned code, const char *reason, const char *details) { +static char *ServeDefaultErrorPage(char *p, unsigned code, const char *reason, + const char *details) { p = AppendContentType(p, "text/html; charset=ISO-8859-1"); reason = FreeLater(EscapeHtml(reason, -1, 0)); appends(&outbuf, "\ @@ -2551,13 +2550,15 @@ img { vertical-align: middle; }\r\n\ appendf(&outbuf, "%d %s\r\n", code, reason); appends(&outbuf, "\r\n"); if (details) { - appendf(&outbuf, "
%s
\r\n", FreeLater(EscapeHtml(details, -1, 0))); + appendf(&outbuf, "
%s
\r\n", + FreeLater(EscapeHtml(details, -1, 0))); } UseOutput(); return p; } -static char *ServeErrorImpl(unsigned code, const char *reason, const char *details) { +static char *ServeErrorImpl(unsigned code, const char *reason, + const char *details) { size_t n; char *p, *s; struct Asset *a; @@ -2593,7 +2594,8 @@ static char *ServeErrorImpl(unsigned code, const char *reason, const char *detai } } -static char *ServeErrorWithDetail(unsigned code, const char *reason, const char *details) { +static char *ServeErrorWithDetail(unsigned code, const char *reason, + const char *details) { LOGF("ERROR %d %s", code, reason); return ServeErrorImpl(code, reason, details); } @@ -3186,8 +3188,9 @@ static char *LuaOnHttpRequest(void) { } else { char *error; WARNF("%s", lua_tostring(L, -1)); - error = ServeErrorWithDetail(500, "Internal Server Error", - IsLoopbackClient() ? lua_tostring(L, -1) : NULL); + error = + ServeErrorWithDetail(500, "Internal Server Error", + IsLoopbackClient() ? lua_tostring(L, -1) : NULL); lua_pop(L, 1); return error; } @@ -3200,15 +3203,17 @@ static char *ServeLua(struct Asset *a, const char *s, size_t n) { effectivepath.p = s; effectivepath.n = n; if ((code = FreeLater(LoadAsset(a, &codelen)))) { - int status = luaL_loadbuffer(L, code, codelen, - FreeLater(xasprintf("@%s", FreeLater(strndup(s, n))))); + int status = + luaL_loadbuffer(L, code, codelen, + FreeLater(xasprintf("@%s", FreeLater(strndup(s, n))))); if (status == LUA_OK && LuaCallWithTrace(L, 0, 0) == LUA_OK) { return CommitOutput(GetLuaResponse()); } else { char *error; WARNF("failed to run lua code: %s", lua_tostring(L, -1)); - error = ServeErrorWithDetail(500, "Internal Server Error", - IsLoopbackClient() ? lua_tostring(L, -1) : NULL); + error = + ServeErrorWithDetail(500, "Internal Server Error", + IsLoopbackClient() ? lua_tostring(L, -1) : NULL); lua_pop(L, 1); return error; } @@ -5454,8 +5459,8 @@ static bool LuaRun(const char *path, bool mandatory) { effectivepath.p = path; effectivepath.n = pathlen; DEBUGF("LuaRun(%`'s)", path); - status = luaL_loadbuffer(L, code, codelen, - FreeLater(xasprintf("@%s", path))); + status = + luaL_loadbuffer(L, code, codelen, FreeLater(xasprintf("@%s", path))); if (status != LUA_OK || LuaCallWithTrace(L, 0, 0) != LUA_OK) { WARNF("script failed to run: %s", lua_tostring(L, -1)); lua_pop(L, 1); @@ -6616,7 +6621,6 @@ static void HandleConnection(size_t i) { if (funtrace && !IsTiny()) { ftrace_install(); } - ++traceme; if (hasonworkerstart) { CallSimpleHook("OnWorkerStart"); }