Skip to content

show_help: static string improvements #13178

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

Merged

Conversation

jsquyres
Copy link
Member

@jsquyres jsquyres commented Apr 6, 2025

Fix warnings from older C compilers that do not like literal strings that are over 4095 characters long. Admittedly do this by hueristic: make each line in a show_help INI help file be its own string (rather than joining all the lines in a given [section] together). I.e., assume that each individual line is less than 4095 characters.

Also make a few other improvements:

  • Remove an unused string in show_help.c
  • Fixed a problem where leading spaces were trimmed from the help text files in the resulting C strings.
  • Fixed a problem where blank lines were snipped from the help text files in the resulting C strings.
  • Simplify the Python generation script by statically initialzing one large struct named help_files (vs. initializing a struct per help file, and then initializing a 2nd struct to map the filenames to all the individual per-file structs).
    • Also use C99-style name-specified initializers, making the resulting code mode human-readable.
    • Also add comments at the end of each INI section and filename to make the resulting code more human readable.
    • Use C99-style "{0}" to mark empty / end-of-array sentinel values.
  • At run time, the individual lines of a given show_help section are opal_argv_join()'ed together and emitted. The alloc'ed string is cached (just in case it is used again -- which it likely won't be) and freed during opal_finalize().

The resulting generated static initialization code looks like this:

static file_entry help_files[] = {
    {
	.filename = "help-opal-wrapper.txt",
	.entries = (ini_entry[]) {
	    {
		.section = "no-language-support",
		.content = (const char*[]) {
		    "Unfortunately, this installation of Open MPI was not compiled with",
		    "%s support.  As such, the %s compiler is non-functional.",
		    NULL
		},
	    }, // End of section no-language-support
	    {0}
	}, // End of file help-opal-wrapper.txt
    },
    {0}
};

Fixes #13167

Fix warnings from older C compilers that do not like literal strings
that are over 4095 characters line.  Admittedly do this by hueristic:
make each line in a show_help INI help file be its own string (rather
than joining all the lines in a given [section] together).  I.e.,
assume that each individual line is less than 4095 characters.

Also make a few other improvements:

* Remove an unused string in show_help.c
* Fixed a problem where leading spaces were trimmed from the help text
  files in the resulting C strings.
* Fixed a problem where blank lines were snipped from the help text
  files in the resulting C strings.
* Simplify the Python generation script by statically initialzing one
  large struct named help_files (vs. initializing a struct per help
  file, and then initializing a 2nd struct to map the filenames to all
  the individual per-file structs).
  * Also use C99-style name-specified initializers, making the
    resulting code mode human-readable.
  * Also add comments at the end of each INI section and filename to
    make the resulting code more human readable.
  * Use C99-style "{0}" to mark empty / end-of-array sentinel values.
* At run time, the individual lines of a given show_help section are
  opal_argv_join()'ed together and emitted.  The alloc'ed string is
  cached (just in case it is used again -- which it likely won't be)
  and freed during opal_finalize().

The resulting generated static initialization code looks like this:

```c
static file_entry help_files[] = {
    {
	.filename = "help-opal-wrapper.txt",
	.entries = (ini_entry[]) {
	    {
		.section = "no-language-support",
		.content = (const char*[]) {
		    "Unfortunately, this installation of Open MPI was not compiled with",
		    "%s support.  As such, the %s compiler is non-functional.",
		    NULL
		},
	    }, // End of section no-language-support
	    {0}
	}, // End of file help-opal-wrapper.txt
    },
    {0}
};
```

Signed-off-by: Jeff Squyres <[email protected]>
@bosilca bosilca merged commit 069a035 into open-mpi:main Apr 7, 2025
18 checks passed
@jsquyres jsquyres deleted the pr/show-help-static-string-improvements branch April 7, 2025 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Encoded show_help text causing compiler warnings
3 participants