2021-08-13 10:20:45 +00:00
|
|
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
|
|
|
|
│ vi: set et ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi │
|
|
|
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
|
|
|
│ Python 3 │
|
|
|
|
│ https://docs.python.org/3/license.html │
|
|
|
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
2021-08-12 07:42:14 +00:00
|
|
|
#include "libc/stdio/stdio.h"
|
|
|
|
#include "libc/str/str.h"
|
|
|
|
#include "third_party/python/Include/pygetopt.h"
|
2021-08-13 10:20:45 +00:00
|
|
|
|
Release Cosmopolitan v3.3
This change upgrades to GCC 12.3 and GNU binutils 2.42. The GNU linker
appears to have changed things so that only a single de-duplicated str
table is present in the binary, and it gets placed wherever the linker
wants, regardless of what the linker script says. To cope with that we
need to stop using .ident to embed licenses. As such, this change does
significant work to revamp how third party licenses are defined in the
codebase, using `.section .notice,"aR",@progbits`.
This new GCC 12.3 toolchain has support for GNU indirect functions. It
lets us support __target_clones__ for the first time. This is used for
optimizing the performance of libc string functions such as strlen and
friends so far on x86, by ensuring AVX systems favor a second codepath
that uses VEX encoding. It shaves some latency off certain operations.
It's a useful feature to have for scientific computing for the reasons
explained by the test/libcxx/openmp_test.cc example which compiles for
fifteen different microarchitectures. Thanks to the upgrades, it's now
also possible to use newer instruction sets, such as AVX512FP16, VNNI.
Cosmo now uses the %gs register on x86 by default for TLS. Doing it is
helpful for any program that links `cosmo_dlopen()`. Such programs had
to recompile their binaries at startup to change the TLS instructions.
That's not great, since it means every page in the executable needs to
be faulted. The work of rewriting TLS-related x86 opcodes, is moved to
fixupobj.com instead. This is great news for MacOS x86 users, since we
previously needed to morph the binary every time for that platform but
now that's no longer necessary. The only platforms where we need fixup
of TLS x86 opcodes at runtime are now Windows, OpenBSD, and NetBSD. On
Windows we morph TLS to point deeper into the TIB, based on a TlsAlloc
assignment, and on OpenBSD/NetBSD we morph %gs back into %fs since the
kernels do not allow us to specify a value for the %gs register.
OpenBSD users are now required to use APE Loader to run Cosmo binaries
and assimilation is no longer possible. OpenBSD kernel needs to change
to allow programs to specify a value for the %gs register, or it needs
to stop marking executable pages loaded by the kernel as mimmutable().
This release fixes __constructor__, .ctor, .init_array, and lastly the
.preinit_array so they behave the exact same way as glibc.
We no longer use hex constants to define math.h symbols like M_PI.
2024-02-20 19:12:09 +00:00
|
|
|
__notice(python_getopt_notice, "\
|
|
|
|
python getopt (isc license)\n\
|
|
|
|
Copyright 1992-1994 David Gottner");
|
2021-09-28 05:58:51 +00:00
|
|
|
|
2021-08-08 04:08:33 +00:00
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* <RCS keywords>
|
|
|
|
*
|
|
|
|
* C++ Library
|
|
|
|
*
|
|
|
|
* Copyright 1992-1994, David Gottner
|
|
|
|
*
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software and its
|
|
|
|
* documentation for any purpose and without fee is hereby granted,
|
|
|
|
* provided that the above copyright notice, this permission notice and
|
|
|
|
* the following disclaimer notice appear unmodified in all copies.
|
|
|
|
*
|
|
|
|
* I DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL I
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Nevertheless, I would like to know about bugs in this library or
|
|
|
|
* suggestions for improvment. Send bug reports and feedback to
|
|
|
|
* davegottner@delphi.com.
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* Modified to support --help and --version, as well as /? on Windows
|
|
|
|
* by Georg Brandl. */
|
|
|
|
|
|
|
|
int _PyOS_opterr = 1; /* generate error messages */
|
|
|
|
int _PyOS_optind = 1; /* index into argv array */
|
|
|
|
wchar_t *_PyOS_optarg = NULL; /* optional argument */
|
|
|
|
|
|
|
|
static wchar_t *opt_ptr = L"";
|
|
|
|
|
|
|
|
void _PyOS_ResetGetOpt(void)
|
|
|
|
{
|
|
|
|
_PyOS_opterr = 1;
|
|
|
|
_PyOS_optind = 1;
|
|
|
|
_PyOS_optarg = NULL;
|
|
|
|
opt_ptr = L"";
|
|
|
|
}
|
|
|
|
|
|
|
|
int _PyOS_GetOpt(int argc, wchar_t **argv, wchar_t *optstring)
|
|
|
|
{
|
|
|
|
wchar_t *ptr;
|
|
|
|
wchar_t option;
|
|
|
|
if (*opt_ptr == '\0') {
|
|
|
|
if (_PyOS_optind >= argc)
|
|
|
|
return -1;
|
|
|
|
#ifdef MS_WINDOWS
|
|
|
|
else if (wcscmp(argv[_PyOS_optind], L"/?") == 0) {
|
|
|
|
++_PyOS_optind;
|
|
|
|
return 'h';
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else if (argv[_PyOS_optind][0] != L'-' ||
|
|
|
|
argv[_PyOS_optind][1] == L'\0' /* lone dash */ )
|
|
|
|
return -1;
|
|
|
|
else if (wcscmp(argv[_PyOS_optind], L"--") == 0) {
|
|
|
|
++_PyOS_optind;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else if (wcscmp(argv[_PyOS_optind], L"--help") == 0) {
|
|
|
|
++_PyOS_optind;
|
|
|
|
return 'h';
|
|
|
|
}
|
|
|
|
else if (wcscmp(argv[_PyOS_optind], L"--version") == 0) {
|
|
|
|
++_PyOS_optind;
|
|
|
|
return 'V';
|
|
|
|
}
|
|
|
|
opt_ptr = &argv[_PyOS_optind++][1];
|
|
|
|
}
|
|
|
|
if ((option = *opt_ptr++) == L'\0')
|
|
|
|
return -1;
|
|
|
|
if (option == 'J') {
|
|
|
|
if (_PyOS_opterr)
|
|
|
|
fprintf(stderr, "-J is reserved for Jython\n");
|
|
|
|
return '_';
|
|
|
|
}
|
|
|
|
if ((ptr = wcschr(optstring, option)) == NULL) {
|
|
|
|
if (_PyOS_opterr)
|
|
|
|
fprintf(stderr, "Unknown option: -%c\n", (char)option);
|
|
|
|
return '_';
|
|
|
|
}
|
|
|
|
if (*(ptr + 1) == L':') {
|
|
|
|
if (*opt_ptr != L'\0') {
|
|
|
|
_PyOS_optarg = opt_ptr;
|
|
|
|
opt_ptr = L"";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (_PyOS_optind >= argc) {
|
|
|
|
if (_PyOS_opterr)
|
|
|
|
fprintf(stderr,
|
|
|
|
"Argument expected for the -%c option\n", (char)option);
|
|
|
|
return '_';
|
|
|
|
}
|
|
|
|
_PyOS_optarg = argv[_PyOS_optind++];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return option;
|
|
|
|
}
|