Skip to content

Fix #11244 - Allow building with AppleClang 17#11246

Merged
mitchute merged 4 commits intodevelopfrom
11244_clang17
Oct 6, 2025
Merged

Fix #11244 - Allow building with AppleClang 17#11246
mitchute merged 4 commits intodevelopfrom
11244_clang17

Conversation

@jmarrec
Copy link
Contributor

@jmarrec jmarrec commented Oct 2, 2025

Pull request overview

Description of the purpose of this PR

  • Modernize the BCTVB C code
  • Ignore deprecated declarations (-Wno-deprecated-declarations) for penumbra's glfw

Review without the first commit, which is just clang format

https://github.com/NREL/EnergyPlus/pull/11246/files/8d0e1c0208bae1d0d40159c4a62136ceaf833b30..3405fb1bf5546c80646a996282eefa9391720421

Pull Request Author

  • Title of PR should be user-synopsis style (clearly understandable in a standalone changelog context)
  • Label the PR with at least one of: Defect, Refactoring, NewFeature, Performance, and/or DoNoPublish
  • Pull requests that impact EnergyPlus code must also include unit tests to cover enhancement or defect repair
  • Author should provide a "walkthrough" of relevant code changes using a GitHub code review comment process
  • If any diffs are expected, author must demonstrate they are justified using plots and descriptions
  • If changes fix a defect, the fix should be demonstrated in plots and descriptions
  • If any defect files are updated to a more recent version, upload new versions here or on DevSupport
  • If IDD requires transition, transition source, rules, ExpandObjects, and IDFs must be updated, and add IDDChange label
  • If structural output changes, add to output rules file and add OutputChange label
  • If adding/removing any LaTeX docs or figures, update that document's CMakeLists file dependencies

Reviewer

  • Perform a Code Review on GitHub
  • If branch is behind develop, merge develop and build locally to check for side effects of the merge
  • If defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If feature, test running new feature, try creative ways to break it
  • CI status: all green or justified
  • Check that performance is not impacted (CI Linux results include performance check)
  • Run Unit Test(s) locally
  • Check any new function arguments for performance impacts
  • Verify IDF naming conventions and styles, memos and notes and defaults
  • If new idf included, locally check the err file and other outputs

@jmarrec jmarrec self-assigned this Oct 2, 2025
@jmarrec jmarrec added Defect Includes code to repair a defect in EnergyPlus Developer Issue Related to cmake, packaging, installers, or developer tooling (CI, etc) labels Oct 2, 2025
Comment on lines +866 to +895
size_t n_BCVTB_HOME = strlen(BCVTB_HOME);
size_t n_fileName = strlen(fileName);
size_t n_xmlPath = strlen(xmlPath); // 9
size_t n_jarPath = strlen(jarPath); // 35
size_t n_dtdName = strlen(dtdName); // 13

// Verify that variables.dtd exists and is readable
{
// Add 1 for the null terminator
size_t n_needed = n_BCVTB_HOME + n_xmlPath + n_dtdName + 1;

char* dtdFileName = (char*)malloc(sizeof(char) * n_needed);
if (!dtdFileName) {
fprintf(stderr,
"Error: Memory allocation for 'dtdFileName' failed in check_variable_cfg_Validate when parsing file '%s'. \n"
" Program aborting.\n",
fileName);
// free(dtdFileName);
return -1;
}

snprintf(dtdFileName, n_needed, "%s%s%s", BCVTB_HOME, xmlPath, dtdName);
FILE* dtdF = fopen(dtdFileName, "r");
if (!dtdF) {
fprintf(stderr, "Error: Cannot open '%s'.\n", dtdFileName);
free(dtdFileName);
return -1;
} else {
fclose(dtdF);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calculate the size needed properly, use snprintf not sprintf.

A test bed that will showcase the before/after is provided for convenience here: https://compiler-explorer.com/z/xoW58hn3j

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also freeing as soon as I can, and scoping variables better.

Comment on lines -878 to -879
dtdFileName = (char*)malloc(sizeof(char) * (strlen(BCVTB_HOME) + 30));
if (NULL == command) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this check on line 879 was wrong, it was checking the wrong variable...

Doesn't matter that much because malloc will never fail on the systems we run this on, but still

Comment on lines +903 to +905
// Add 1 for the null terminator
size_t n_needed = 18 + 2 * n_BCVTB_HOME + n_jarPath + n_xmlPath + n_fileName + 1;
// int n_needed = snprintf(NULL, 0, cmd_fmt, BCVTB_HOME, jarPath, fileName, BCVTB_HOME, xmlPath) + 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have considered calling snprintf with a null ptr and bufsize of zero to let it calculate the needed size for me, but this I have everything I need I decided not to.

Comment on lines +33 to +35
if(NOT MSVC)
target_compile_options(glfw PRIVATE -Wno-deprecated-declarations)
endif()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For penumbra's glfw, just ignore deprecated declarations for now.

"Error: Memory allocation for 'dtdFileName' failed in check_variable_cfg_Validate when parsing file '%s'. \n"
" Program aborting.\n",
fileName);
// free(dtdFileName);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm omitting this because it's pointless.

(Note that I could have left it, because free on a null pointer has no effect)

@mitchute mitchute merged commit f6ff83e into develop Oct 6, 2025
13 checks passed
@mitchute mitchute deleted the 11244_clang17 branch October 6, 2025 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Defect Includes code to repair a defect in EnergyPlus Developer Issue Related to cmake, packaging, installers, or developer tooling (CI, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

can't build with Apple Clang 17+

3 participants