-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
builtin.inc: fix build with -Woverlength-strings #2979
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a109028
Makefile.am: hide some mkdir -p commands
emanuele6 ff83706
builtin.c: move macos-specific quirks to a separate math-macos.h header
emanuele6 8f458fd
main.c: move win32 main() quirks to main-win32.h
emanuele6 ca71287
builtin.inc: fix build with -Woverlength-strings
emanuele6 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#include "main-win32.h" | ||
#include "math-macos.h" | ||
|
||
static uint_least8_t index = 0; | ||
|
||
static bool indentation(void) { | ||
if (index == 0 && fputs(" ", stdout) == EOF) { | ||
perror("fputs"); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
static bool separator(void) { | ||
if (putchar(index < 10 ? ' ' : '\n') == EOF) { | ||
perror("putchar"); | ||
return false; | ||
} | ||
index = (index + 1) % 11; | ||
return true; | ||
} | ||
|
||
static bool gen_char(char const ch) { | ||
if (!indentation()) | ||
return false; | ||
if (printf("%.4o,", (unsigned)ch) == EOF) | ||
return false; | ||
return separator(); | ||
} | ||
|
||
static bool gen_string(char const *const string) | ||
{ | ||
for (char const *ch = string; *ch; ++ch) { | ||
if (!gen_char(*ch)) | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
static bool gen_file(FILE *const fp) { | ||
for (int ch; (ch = getc(fp)) != EOF;) { | ||
if (!gen_char(ch)) | ||
return false; | ||
} | ||
if (ferror(fp)) { | ||
perror("getc"); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
DEFINE_MAIN(int argc, char *const argv[]) { | ||
/* argv[1] must be the path to "src/builtin.jq" */ | ||
if (argc != 2) { | ||
static char const err[] = | ||
"gen_builtin_inc: Wrong number of arguments.\n"; | ||
if (fputs(err, stderr) == EOF) | ||
perror("fputs"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
if (puts("{") == EOF) { | ||
perror("puts"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
FILE *const builtin_jq = fopen(argv[1], "r"); | ||
if (!builtin_jq) { | ||
perror("fopen"); | ||
return EXIT_FAILURE; | ||
} | ||
if (!gen_file(builtin_jq)) | ||
return EXIT_FAILURE; | ||
|
||
#define GEN_STRING(string) \ | ||
do { \ | ||
if (!gen_string(string)) \ | ||
return EXIT_FAILURE; \ | ||
} while (0) | ||
|
||
/* Unsupported math functions */ | ||
#define LIBM_DD(name) | ||
#define LIBM_DDD(name) | ||
#define LIBM_DDDD(name) | ||
#define LIBM_DD_NO(name) \ | ||
gen_string( \ | ||
"def " #name ":" \ | ||
"\"Error: " #name "/0 not found at build time\"|error;"); | ||
#define LIBM_DDD_NO(name) \ | ||
gen_string( \ | ||
"def " #name "(a;b):" \ | ||
"\"Error: " #name "/2 not found at build time\"|error;"); | ||
#define LIBM_DDDD_NO(name) \ | ||
gen_string("def " #name "(a;b;c):" \ | ||
"\"Error: " #name "/3 not found at build time\"|error;"); | ||
#include "libm.h" | ||
#undef LIBM_DD | ||
#undef LIBM_DDD | ||
#undef LIBM_DDDD | ||
#undef LIBM_DD_NO | ||
#undef LIBM_DDD_NO | ||
#undef LIBM_DDDD_NO | ||
|
||
#ifndef HAVE_FREXP | ||
GEN_STRING( | ||
"def frexp:" | ||
"\"Error: frexp/0 not found at build time\"|error;"); | ||
#endif | ||
#ifndef HAVE_MODF | ||
GEN_STRING( | ||
"def modf:" | ||
"\"Error: modf/0 not found at build time\"|error;"); | ||
#endif | ||
#ifndef HAVE_LGAMMA_R | ||
GEN_STRING( | ||
"def lgamma_r:" | ||
"\"Error: lgamma_r/0 not found at build time\"|error;"); | ||
#endif | ||
|
||
#undef GEN_STRING | ||
|
||
if (puts("'\\0',\n}") == EOF) { | ||
perror("puts"); | ||
return EXIT_FAILURE; | ||
} | ||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef MAIN_WIN32_H | ||
#define MAIN_WIN32_H | ||
|
||
#ifdef WIN32 | ||
#include <stringapiset.h> | ||
#include <wchar.h> | ||
|
||
#define DEFINE_MAIN(ARGC, ARGV) \ | ||
int umain(ARGC, ARGV); \ | ||
int wmain(int argc, wchar_t* wargv[]) { \ | ||
size_t arg_sz; \ | ||
char **argv = alloca(argc * sizeof(wchar_t*)); \ | ||
for (int i = 0; i < argc; i++) { \ | ||
argv[i] = alloca((arg_sz = WideCharToMultiByte(CP_UTF8, \ | ||
0, \ | ||
wargv[i], \ | ||
-1, 0, 0, 0, 0))); \ | ||
WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, argv[i], arg_sz, 0, 0); \ | ||
} \ | ||
return umain(argc, argv); \ | ||
} \ | ||
int umain(ARGC, ARGV) | ||
#else | ||
#define DEFINE_MAIN(ARGC, ARGV) \ | ||
int main(ARGC, ARGV) | ||
#endif | ||
|
||
#endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't notice this code before. Is this used when building native for windows, not via emulation layers like msys2 or cygwin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, when you compile with
-municode
on windows,wmain()
is called instead ofmain()
as entry point withwchar_t*
strings instead ofchar*
strings; then that code inwmain()
converts thewchar_t*
strings tochar*
strings encoding with utf-8.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume it is probably an hack to make the program get the correct utf-8 encoding on unicode characters you pass through
cmd.exe
because windows encodings are weird.For example, recently, I added a test to
curl
that verifies that utf-8 bytes get correctly encoded to JSON; and I had to modify my test to get the utf-8 string from a file instead of from command line arguemnts because the windows CI was not passing the right bytes tocurl
. :/curl/curl#12434