mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 13:52:28 +00:00
Fix PFLINK mechanism for uppercase float conversion specifiers (#796)
_PFLINK is supposed to automatically pull in required functions for specific conversion specifiers. However, it fails to do so for the F, G and E conversion specifiers. This means that, for example, the following program: #include <stdio.h> int main() { printf("%F %G %E\n", .0, .0, .0); } fails to run correctly, printing "? ? ?" instead of "0.000000 0 0.000000E+00". This patch fixes this.
This commit is contained in:
parent
669b4c5f19
commit
36f52ea687
4 changed files with 137 additions and 13 deletions
|
@ -14,7 +14,7 @@
|
||||||
#define PFLINK(...) _PFLINK(__VA_ARGS__)
|
#define PFLINK(...) _PFLINK(__VA_ARGS__)
|
||||||
#define _PFLINK(FMT, ...) \
|
#define _PFLINK(FMT, ...) \
|
||||||
({ \
|
({ \
|
||||||
if (___PFLINK(FMT, strpbrk, "faAeg")) STATIC_YOINK("__fmt_dtoa"); \
|
if (___PFLINK(FMT, strpbrk, "fFaAeEgG")) STATIC_YOINK("__fmt_dtoa"); \
|
||||||
if (___PFLINK(FMT, strpbrk, "cmrqs")) { \
|
if (___PFLINK(FMT, strpbrk, "cmrqs")) { \
|
||||||
if (___PFLINK(FMT, strstr, "%m")) STATIC_YOINK("strerror"); \
|
if (___PFLINK(FMT, strstr, "%m")) STATIC_YOINK("strerror"); \
|
||||||
if (___PFLINK(FMT, strstr, "%*") || \
|
if (___PFLINK(FMT, strstr, "%*") || \
|
||||||
|
|
42
test/libc/fmt/printf_uppercase_e_static_yoink_test.c
Normal file
42
test/libc/fmt/printf_uppercase_e_static_yoink_test.c
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
/*-*- 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 2023 Gabriel Ravier │
|
||||||
|
│ │
|
||||||
|
│ 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/fmt/fmt.h"
|
||||||
|
#include "libc/intrin/kprintf.h"
|
||||||
|
#include "libc/runtime/runtime.h"
|
||||||
|
#include "libc/str/str.h"
|
||||||
|
|
||||||
|
// We specifically avoid the test framework because otherwise __fmt_dtoa is
|
||||||
|
// always automatically pulled in from code in there - and this is what we're
|
||||||
|
// testing for here
|
||||||
|
int main() {
|
||||||
|
char buffer[30];
|
||||||
|
|
||||||
|
int snprintf_result = snprintf(buffer, sizeof(buffer), "%E", .0);
|
||||||
|
if (strcmp(buffer, "0.000000E+00")) {
|
||||||
|
kprintf(
|
||||||
|
"error: snprintf gave us '%s' instead of the expected '0.000000E+00'\n",
|
||||||
|
buffer);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
if (snprintf_result != 12) {
|
||||||
|
kprintf("error: snprintf returned %d instead of 12\n", snprintf_result);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
41
test/libc/fmt/printf_uppercase_f_static_yoink_test.c
Normal file
41
test/libc/fmt/printf_uppercase_f_static_yoink_test.c
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
/*-*- 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 2023 Gabriel Ravier │
|
||||||
|
│ │
|
||||||
|
│ 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/fmt/fmt.h"
|
||||||
|
#include "libc/intrin/kprintf.h"
|
||||||
|
#include "libc/runtime/runtime.h"
|
||||||
|
#include "libc/str/str.h"
|
||||||
|
|
||||||
|
// We specifically avoid the test framework because otherwise __fmt_dtoa is
|
||||||
|
// always automatically pulled in from code in there - and this is what we're
|
||||||
|
// testing for here
|
||||||
|
int main() {
|
||||||
|
char buffer[30];
|
||||||
|
|
||||||
|
int snprintf_result = snprintf(buffer, sizeof(buffer), "%F", .0);
|
||||||
|
if (strcmp(buffer, "0.000000")) {
|
||||||
|
kprintf("error: snprintf gave us '%s' instead of the expected '0.000000'\n",
|
||||||
|
buffer);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
if (snprintf_result != 8) {
|
||||||
|
kprintf("error: snprintf returned %d instead of 8\n", snprintf_result);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
41
test/libc/fmt/printf_uppercase_g_static_yoink_test.c
Normal file
41
test/libc/fmt/printf_uppercase_g_static_yoink_test.c
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
/*-*- 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 2023 Gabriel Ravier │
|
||||||
|
│ │
|
||||||
|
│ 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/fmt/fmt.h"
|
||||||
|
#include "libc/intrin/kprintf.h"
|
||||||
|
#include "libc/runtime/runtime.h"
|
||||||
|
#include "libc/str/str.h"
|
||||||
|
|
||||||
|
// We specifically avoid the test framework because otherwise __fmt_dtoa is
|
||||||
|
// always automatically pulled in from code in there - and this is what we're
|
||||||
|
// testing for here
|
||||||
|
int main() {
|
||||||
|
char buffer[30];
|
||||||
|
|
||||||
|
int snprintf_result = snprintf(buffer, sizeof(buffer), "%G", .0);
|
||||||
|
if (strcmp(buffer, "0")) {
|
||||||
|
kprintf("error: snprintf gave us '%s' instead of the expected '0'\n",
|
||||||
|
buffer);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
if (snprintf_result != 1) {
|
||||||
|
kprintf("error: snprintf returned %d instead of 1\n", snprintf_result);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue