mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-31 09:42:27 +00:00
Document __demangle() and fix a const func ptr bug
This commit is contained in:
parent
c67faf61df
commit
9aa353d88b
7 changed files with 618 additions and 670 deletions
67
test/libc/intrin/demangle_test.c
Normal file
67
test/libc/intrin/demangle_test.c
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2024 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 "demangle_cases.inc"
|
||||
#include "libc/cosmo.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
char got[19500];
|
||||
|
||||
static void regenerate_cases(void) {
|
||||
FILE *f = fopen("demangle_cases.inc", "w");
|
||||
fprintf(f, "const char* demangle_cases[][2] = {\n");
|
||||
for (int i = 0; i < ARRAYLEN(demangle_cases); ++i) {
|
||||
const char *input = demangle_cases[i][0];
|
||||
const char *want = demangle_cases[i][1];
|
||||
if (__demangle(got, input, sizeof(got)) == -1) {
|
||||
fprintf(f, "\n // {%`'s,\n // %`'s},\n // got error\n\n", input,
|
||||
want);
|
||||
} else if (!strcmp(want, got)) {
|
||||
fprintf(f, " {%`'s, %`'s},\n", input, got);
|
||||
} else {
|
||||
fprintf(f,
|
||||
"\n // {%`'s,\n // %`'s},\n // %`'s was returned\n\n",
|
||||
input, want, got);
|
||||
}
|
||||
fflush(f);
|
||||
}
|
||||
fprintf(f, "};\n");
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
int main() {
|
||||
for (int i = 0; i < ARRAYLEN(demangle_cases); ++i) {
|
||||
const char *input = demangle_cases[i][0];
|
||||
const char *want = demangle_cases[i][1];
|
||||
if (__demangle(got, input, sizeof(got)) == -1) {
|
||||
fprintf(stderr, "%s:%d: error: demangle failed\n", __FILE__, __LINE__);
|
||||
fprintf(stderr, "\tinput %`'s\n", input);
|
||||
fprintf(stderr, "\t want %`'s\n", want);
|
||||
return 1;
|
||||
}
|
||||
if (strcmp(want, got)) {
|
||||
fprintf(stderr, "%s:%d: error: demangle incorrect\n", __FILE__, __LINE__);
|
||||
fprintf(stderr, "\tinput %`'s\n", input);
|
||||
fprintf(stderr, "\t want %`'s\n", want);
|
||||
fprintf(stderr, "\t got %`'s\n", got);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue