Commit graph

1869 commits

Author SHA1 Message Date
Matheus Afonso Martins Moreira
2daad6ede8 vcscanf: buffer the ')' of "nan(whatever)"
For some reason I thought the do while (c = BUFFER ...) loop
already did it for me. Apparently not!
2023-11-02 20:36:58 -03:00
Matheus Afonso Martins Moreira
c78ae967f8 vcscanf: buffer the last 'y' of "infinity"
I don't know why I thought this wasn't necessary.
2023-11-02 20:34:04 -03:00
Matheus Afonso Martins Moreira
ded97bf5af vcscanf: add curly braces around another else
Makes the goto statement easier to read.
Also consistent with the rest of the codebase.
2023-11-02 20:05:41 -03:00
Matheus Afonso Martins Moreira
c38aec9949 test: add sscanf floating point parser tests
Test that floating point numbers are correctly parsed from strings.
2023-11-02 19:30:06 -03:00
Matheus Afonso Martins Moreira
cc79f6233d vcscanf: add curly braces around else clause
Makes the goto statement easier to read.
Also consistent with the rest of the codebase.
2023-11-02 08:03:16 -03:00
Matheus Afonso Martins Moreira
bb0d4c2c15 vcscanf: fix formatting errors
Somehow I ended up introducing mixed tabs and spaces into the file.
2023-11-02 08:00:54 -03:00
Matheus Afonso Martins Moreira
90f19ed448 vcscanf: ensure buf is NULL after string decoding
The presence of a pointer in buf could result in double free bugs
when execution reaches the end of the function and it is freed.
2023-11-02 06:47:45 -03:00
Matheus Afonso Martins Moreira
758cdb72da examples: add a parsefloat example
Essentially an expanded version of the basic test case
posted in GitHub issue #456. Also includes examples from documentation.

References:

https://github.com/jart/cosmopolitan/issues/456
https://en.cppreference.com/w/c/string/byte/strtof
2023-11-02 06:42:28 -03:00
Matheus Afonso Martins Moreira
99c5006ea9 vcscanf: parse floating point numbers
The vcscanf function attempts to recognize the floating point number
and then uses the strtod function to calculate its numeric value.
It begins by recognizing an optional plus or minus sign, followed by
either hexadecimal notation or NaN and infinity constants.
Then it looks for an optional integer part, a point or comma,
a fractional part, and an optional exponent symbol.
If it finds an exponent, it recognizes the optional sign and digits.

Every time a character is accepted, it is also buffered.
The accumulated buffer is passed to strtod when recognition is finished
and the output is assigned to the output pointer of appropriate length.
This only happens if not in discard mode.
Finally, the buffer is freed and its state is reset.

References:

https://en.cppreference.com/w/c/string/byte/strtof
2023-11-02 06:29:15 -03:00
Matheus Afonso Martins Moreira
a2225a2d85 vcscanf: include the gdtoa library
The parsing of floating point numbers is quite complex.
Reuse available libraries to accomplish the task.
2023-11-02 06:26:44 -03:00
Matheus Afonso Martins Moreira
ec2b2720f5 vcscanf: add floating point number scanner case
Handle all the documented format specifiers.
Exit with error if given a length modifier other than "l".
Skip spaces, initialize the buffer and then begin parsing.

References:

https://en.cppreference.com/w/c/io/fscanfî1;129A
2023-11-02 06:25:51 -03:00
Matheus Afonso Martins Moreira
c8e941bb79 vcscanf: define floating point result variable
Holds the parsed floating point value.
2023-11-02 06:18:28 -03:00
Matheus Afonso Martins Moreira
0e7c6aa5e1 vcscanf: free buf before returning if not NULL
This condition indicates that the floating point parser exited early.
2023-11-02 06:16:20 -03:00
Matheus Afonso Martins Moreira
c16171349c vcscanf: define BUFFER macro
This is similar to the READ macro.
READs a character and places it in the buffer.
Automatically maintains the NUL terminator.
If the end is reached, reallocate the buffer.
2023-11-02 06:15:27 -03:00
Matheus Afonso Martins Moreira
44cb3056bc vcscanf: add buffer cursor variable
Keeps track of current buffer position.
2023-11-02 06:07:13 -03:00
Matheus Afonso Martins Moreira
3403b6c604 vcscanf: change buf type to unsigned char *
The data it points to will be accessed directly.
Also remove casts which are now unnecessary.
2023-11-02 06:05:37 -03:00
Matheus Afonso Martins Moreira
64c883a320 vcscanf: move buffer variables to top of function
This buffer is currently used only when decoding strings.
Place it at the top level so other code can also use it.
Ensure it is initialized to NULL.
2023-11-02 06:01:05 -03:00
Justine Tunney
6ca5ab4680
Mention cosmocc-0.0.16 in Makefile 2023-11-01 12:08:50 -07:00
Justine Tunney
55d5d6bbc0
Release Cosmopolitan v3.0.1 2023-11-01 09:23:43 -07:00
Justine Tunney
d259e573b6
Remove *NSYNC WIN32 semaphores
This implementation doesn't work as well as WIN32 futexes. This code
path was only added back when we were having issues with set context
however that's been solved so we can go back to the much better code
2023-11-01 07:18:58 -07:00
Justine Tunney
7b284f6bda
Fix bugs and regressions in the pledge command
This change gets the pledge (formerly pledge.com) command back in tip
top shape for a 3.0.1 cosmos release. It now runs on all platforms, even
though it's mostly a no-op on ones that lack the kernel security stuff.
The binary footprint is now smaller, since it no longer needs to link
malloc. It's also now able to be built as a fat binary.
2023-11-01 06:08:58 -07:00
Justine Tunney
b0e3d89942
Work around qemu-aarch64 bug
Qemu appears to define O_LARGEFILE as having its x86-64 value, which is
an easy mistake to make since this is one of the few magic numbers that
Linux special-cases for AARCH64.
2023-11-01 00:24:48 -07:00
Justine Tunney
0b1acce680
Introduce shm_open() and shm_unlink() 2023-10-31 23:57:52 -07:00
Justine Tunney
fadb64a2bf
Introduce pthread_rwlock_try{rd,wr}lock
This also changes recursive mutexes to favor cpu over scheduler yield.
2023-10-31 22:13:08 -07:00
Justine Tunney
a1e1e821cb
Introduce GNU/BSD timeval macros 2023-10-31 21:58:49 -07:00
Justine Tunney
2af7c802b6
Stub out getutline and pututline 2023-10-31 21:58:39 -07:00
Justine Tunney
3b791d2f44
Introduce lgammal, tgammal, erfl, and erfcl
git://git.musl-libc.org/musl
79bdacff83a6bd5b70ff5ae5eb8b6de82c2f7c30
2023-10-31 21:58:29 -07:00
Justine Tunney
b4084dd6c6
Introduce libcxx <shared_mutex>
git@github.com:llvm-mirror/libcxx.git
78d6a7767ed57b50122a161b91f59f19c9bd0d19
2023-10-31 21:57:28 -07:00
Justine Tunney
ee82f90bba
Introduce __cxa_thread_atexit() 2023-10-31 20:04:31 -07:00
Justine Tunney
a699cda5c8
Make cosmocc -Wl,--version do the right thing
Our `cosmocc` wrapper script will now report the linker version, the
same way as the `cc` command. The `fatcosmocc` command won't do this
because we wouldn't want programs to parse out the path of the amd64
linker command and use it explicitly.

Fixes #917
2023-10-31 18:20:28 -07:00
Justine Tunney
f86ffa1a25
Fix aarch64 build breakage caused by ed17d3008 2023-10-31 18:17:32 -07:00
Justine Tunney
a09f62141d
Fix bug in login_tty() 2023-10-31 18:03:13 -07:00
tkchia
ed17d3008b
[metal] Add a uprintf() routine, for non-emergency boot logging (#905)
* [metal] Add a uprintf() routine, for non-emergency boot logging
* [metal] _Really_ push forward timing of VGA TTY initialization
* [metal] Do something useful with uprintf()
* [metal] Locate some ACPI tables, for later hardware detection

Specifically the code now tries to find the ACPI RSDP,
RSDT/XSDT, FADT, & MADT tables, whether in legacy BIOS
bootup mode or in a UEFI bootup.  These are useful for
figuring out how to (re)enable asynchronous interrupts
in legacy 8259 PIC mode.
2023-10-25 14:32:20 -07:00
Justine Tunney
062b2d776e
Mention cosmocc v0.0.14 in Makefile
https://justine.lol/cosmocc-0.0.14.zip
https://github.com/ahgamut/superconfigure/releases/tag/z0.0.14
2023-10-16 00:07:33 -07:00
Justine Tunney
4ae5223eae
Release Cosmopolitan v3.0 2023-10-15 23:53:36 -07:00
Justine Tunney
8f82a5f968
Fix the build 2023-10-15 20:36:12 -07:00
Justine Tunney
d1300623d2
Add tree command to third_party 2023-10-15 19:46:40 -07:00
Justine Tunney
7b8024d088
Supplement _GNU_SOURCE with _COSMO_SOURCE 2023-10-15 16:59:27 -07:00
Gautham
e6b59bced2
Add tsearch from Musl Libc (#912)
https://git.musl-libc.org/cgit/musl/snapshot/musl-1.2.4.tar.gz
2023-10-15 16:50:54 -07:00
Justine Tunney
c9fecf3a55
Make improvements
- You can now run `make -j8 toolchain` on Windows
- You can now run `make -j` on MacOS ARM64 and BSD OSes
- You can now use our Emacs dev environment on MacOS/Windows
- Fix bug where the x16 register was being corrupted by --ftrace
- The programs under build/bootstrap/ are updated as fat binaries
- The Makefile now explains how to download cosmocc-0.0.12 toolchain
- The build scripts under bin/ now support "cosmo" branded toolchains
- stat() now goes faster on Windows (shaves 100ms off `make` latency)
- Code cleanup and added review on the Windows signal checking code
- posix_spawnattr_setrlimit() now works around MacOS ARM64 bugs
- Landlock Make now favors posix_spawn() on non-Linux/OpenBSD
- posix_spawn() now has better --strace logging on Windows
- fstatat() can now avoid EACCES in more cases on Windows
- fchmod() can now change the readonly bit on Windows
2023-10-15 16:45:00 -07:00
Justine Tunney
06c6baaf50
Fix copy/paste issue in Windows console 2023-10-14 16:14:50 -07:00
Justine Tunney
bd48e6c666
Fix the Landlock Make build 2023-10-14 10:40:05 -07:00
Justine Tunney
cdf556e7d2
Implement signal handler tail recursion
GNU Make on Windows now appears to be working reliably. This change also
fixes a bug where, after fork the Windows thread handle wasn't reset and
that caused undefined behavior using SetThreadContext() with our signals
2023-10-14 10:38:15 -07:00
Justine Tunney
a657f3e878
Delete old wcwidth() implementation
This shaves away 144kb of bss memory from every binary linking printf at
the expense of slightly increased binary footprint. Kudos for Byron Lai.
2023-10-14 03:15:05 -07:00
Justine Tunney
2db2f40a98
Rewrite special file handling on Windows
This change gets GNU grep working. What caused it to not work, is it
wouldn't write to an output file descriptor when its dev/ino equaled
/dev/null's. So now we invent special dev/ino values for these files
2023-10-14 02:53:34 -07:00
Justine Tunney
aca2261cda
Don't preempt WIN32 libraries
This change refactors our POSIX signals emulation for Windows so that it
performs some additional safety checks before calling SetThreadContext()
which needs to be locked and must never ever interrupt Microsoft's code.
Kudos to the the Go developers for figuring out how to do this properly.
2023-10-13 13:59:39 -07:00
Justine Tunney
d1a283a588
Fix redbean LaunchBrowser() 2023-10-13 11:39:00 -07:00
Justine Tunney
3851025b77
Fix SQLite regressions caused by 3b086af91 2023-10-13 11:00:39 -07:00
Justine Tunney
bdc453b22d
Fix redbean "-1 workers remain" blemish 2023-10-13 08:33:09 -07:00
Justine Tunney
0e0398cd5d
Fix MODE=tinylinux build 2023-10-13 08:30:18 -07:00