diff --git a/compiler/AST/AstDump.cpp b/compiler/AST/AstDump.cpp index e859977eac7c..5abd83d51a06 100644 --- a/compiler/AST/AstDump.cpp +++ b/compiler/AST/AstDump.cpp @@ -114,7 +114,7 @@ bool AstDump::open(const ModuleSymbol* module, const char* passName, int passNum snprintf(numBuf, 4, "%02d", passNum); mName = astr(module->name, "_", numBuf, passName, ".ast"); - mPath = astr(log_dir, mName); + mPath = astr(log_dir.c_str(), mName); mFP = fopen(mPath, "w"); mIndent = 0; mNeedSpace = false; diff --git a/compiler/AST/AstDumpToHtml.cpp b/compiler/AST/AstDumpToHtml.cpp index e1773bf55e46..101ae9a7568e 100644 --- a/compiler/AST/AstDumpToHtml.cpp +++ b/compiler/AST/AstDumpToHtml.cpp @@ -57,8 +57,9 @@ AstDumpToHtml::~AstDumpToHtml() { } void AstDumpToHtml::init() { - if (!(sIndexFP = fopen(astr(log_dir, "index.html"), "w"))) { - USR_FATAL("cannot open html index file \"%s\" for writing", astr(log_dir, "index.html")); + if (!(sIndexFP = fopen(astr(log_dir.c_str(), "index.html"), "w"))) { + USR_FATAL("cannot open html index file \"%s\" for writing", + astr(log_dir.c_str(), "index.html")); } fprintf(sIndexFP, "\n"); @@ -118,7 +119,7 @@ void AstDumpToHtml::view(const char* passName) { bool AstDumpToHtml::open(ModuleSymbol* module, const char* passName) { const char* name = html_file_name(sPassIndex, module->name); - const char* path = astr(log_dir, name); + const char* path = astr(log_dir.c_str(), name); mFP = fopen(path, "w"); diff --git a/compiler/codegen/codegen.cpp b/compiler/codegen/codegen.cpp index 7ac12522db60..c667e1e771fa 100644 --- a/compiler/codegen/codegen.cpp +++ b/compiler/codegen/codegen.cpp @@ -2266,7 +2266,7 @@ static const char* generateFileName(ChainHashMap& fil // with case-insensitivity taken into account // create the lowercase filename - char lowerFilename[FILENAME_MAX]; + std::string lowerFilename; snprintf(lowerFilename, sizeof(lowerFilename), "%s", currentModuleName); for (unsigned int i=0; i& fil // create a filename by bumping a version number until we get a // filename we haven't seen before - char filename[FILENAME_MAX]; + std::string filename; snprintf(filename, sizeof(filename), "%s", lowerFilename); int version = 1; while (filenames.get(filename)) { @@ -3143,7 +3143,7 @@ static void codegenPartTwo() { filename = generateFileName(fileNameHashMap, filename, currentModule->name); openCFile(&modulefile, filename, "c"); int modulePathLen = strlen(astr(modulefile.pathname)); - char path[FILENAME_MAX]; + std::string path; strncpy(path, astr(modulefile.pathname), modulePathLen-2); path[modulePathLen-2]='\0'; userFileName.push_back(astr(path)); diff --git a/compiler/codegen/library.cpp b/compiler/codegen/library.cpp index 71c87a96b493..c5c802a001e3 100644 --- a/compiler/codegen/library.cpp +++ b/compiler/codegen/library.cpp @@ -33,7 +33,7 @@ std::map exportedArrayElementType; -char libDir[FILENAME_MAX + 1] = ""; +std::string libDir; std::string pxdName = ""; // TypeSymbol -> (pxdName, pyxName) Will be "" if the cname should be used @@ -428,11 +428,11 @@ void ensureLibDirExists() { } void -openLibraryHelperFile(fileinfo* fi, const char* name, const char* ext) { +openLibraryHelperFile(fileinfo* fi, std::string name, const char* ext) { if (ext) - fi->filename = astr(name, ".", ext); + fi->filename = astr(name.c_str(), ".", ext); else - fi->filename = astr(name); + fi->filename = astr(name.c_str()); ensureLibDirExists(); fi->pathname = astr(libDir, "/", fi->filename); diff --git a/compiler/include/driver.h b/compiler/include/driver.h index cc2af3464386..6be018cdea75 100644 --- a/compiler/include/driver.h +++ b/compiler/include/driver.h @@ -103,10 +103,10 @@ bool useDefaultEnv(std::string key, bool isCrayPrgEnv); extern std::map envMap; -extern char CHPL_HOME[FILENAME_MAX+1]; -extern char CHPL_RUNTIME_LIB[FILENAME_MAX+1]; -extern char CHPL_RUNTIME_INCL[FILENAME_MAX+1]; -extern char CHPL_THIRD_PARTY[FILENAME_MAX+1]; +extern std::string CHPL_HOME; +extern std::string CHPL_RUNTIME_LIB; +extern std::string CHPL_RUNTIME_INCL; +extern std::string CHPL_THIRD_PARTY; extern const char* CHPL_HOST_PLATFORM; extern const char* CHPL_HOST_ARCH; @@ -174,7 +174,7 @@ extern bool fParseOnly; extern bool fDriverDoMonolithic; extern bool fDriverCompilationPhase; extern bool fDriverMakeBinaryPhase; -extern char driverTmpDir[FILENAME_MAX]; +extern std::string driverTmpDir; // end compiler driver control flags extern bool fExitLeaks; extern bool fPrintAllCandidates; diff --git a/compiler/include/files.h b/compiler/include/files.h index 61f848c01d07..d8bc4b452153 100644 --- a/compiler/include/files.h +++ b/compiler/include/files.h @@ -28,11 +28,11 @@ #include #include "vec.h" -extern char executableFilename[FILENAME_MAX+1]; -extern char libmodeHeadername[FILENAME_MAX+1]; -extern char fortranModulename[FILENAME_MAX+1]; -extern char pythonModulename[FILENAME_MAX+1]; -extern char saveCDir[FILENAME_MAX+1]; +extern std::string executableFilename; +extern std::string libmodeHeadername; +extern std::string fortranModulename; +extern std::string pythonModulename; +extern std::string saveCDir; extern std::string ccflags; extern std::string ldflags; extern bool ccwarnings; diff --git a/compiler/include/library.h b/compiler/include/library.h index 2cf5d3baaf39..bf680e441837 100644 --- a/compiler/include/library.h +++ b/compiler/include/library.h @@ -45,7 +45,7 @@ enum PythonFileType { // array return type extern std::map exportedArrayElementType; -extern char libDir[FILENAME_MAX + 1]; +extern std::string libDir; extern std::map > pythonNames; extern std::map fortranKindNames; extern std::map fortranTypeNames; @@ -62,7 +62,7 @@ void codegen_make_python_module(); void ensureLibDirExists(); void openLibraryHelperFile(fileinfo* fi, - const char* name, + std::string name, const char* ext = NULL); void closeLibraryHelperFile(fileinfo* fi, bool beautifyIt = true); const char* getLibraryExtension(); diff --git a/compiler/include/log.h b/compiler/include/log.h index 741075e49881..7fc252612592 100644 --- a/compiler/include/log.h +++ b/compiler/include/log.h @@ -49,7 +49,7 @@ void logWriteLog(const char* passName, int passNum, char logTag); bool deletedIdON(); -extern char log_dir [FILENAME_MAX + 1]; +extern std::string log_dir; extern std::set log_modules; extern bool fLogDir; // was --log-dir passed? @@ -58,13 +58,13 @@ extern bool fLog; extern bool fLogIds; extern LogFormat fLogFormat; -extern int fdump_html; -extern char fdump_html_chpl_home[FILENAME_MAX + 1]; -extern bool fdump_html_include_system_modules; -extern bool fdump_html_wrap_lines; -extern bool fdump_html_print_block_IDs; +extern int fdump_html; +extern std::string fdump_html_chpl_home; +extern bool fdump_html_include_system_modules; +extern bool fdump_html_wrap_lines; +extern bool fdump_html_print_block_IDs; -extern FILE* deletedIdHandle; -extern char deletedIdFilename[FILENAME_MAX + 1]; +extern FILE* deletedIdHandle; +extern std::string deletedIdFilename; #endif diff --git a/compiler/main/driver.cpp b/compiler/main/driver.cpp index f8f27ce58ce8..b1fad6a9eb28 100644 --- a/compiler/main/driver.cpp +++ b/compiler/main/driver.cpp @@ -75,13 +75,13 @@ std::map envMap; // envMap used as input to getChplEnv static std::map envMapChplEnvInput; -char CHPL_HOME[FILENAME_MAX+1] = ""; +std::string CHPL_HOME; // These are more specific than CHPL_HOME, to work in // settings where Chapel is installed. -char CHPL_RUNTIME_LIB[FILENAME_MAX+1] = ""; -char CHPL_RUNTIME_INCL[FILENAME_MAX+1] = ""; -char CHPL_THIRD_PARTY[FILENAME_MAX+1] = ""; +std::string CHPL_RUNTIME_LIB; +std::string CHPL_RUNTIME_INCL; +std::string CHPL_THIRD_PARTY; const char* CHPL_HOST_PLATFORM = NULL; const char* CHPL_HOST_ARCH = NULL; @@ -135,8 +135,8 @@ const char* CHPL_ROCM_AMDGCN_PATH = NULL; const char* CHPL_GPU = NULL; const char* CHPL_GPU_ARCH = NULL; -static char libraryFilename[FILENAME_MAX] = ""; -static char incFilename[FILENAME_MAX] = ""; +static std::string libraryFilename; +static std::string incFilename; static bool fBaseline = false; // Flags that were in commonFlags.h/cpp for awhile @@ -152,7 +152,7 @@ bool fDriverMakeBinaryPhase = false; bool fDriverDoMonolithic = false; bool driverDebugPhaseSpecified = false; // Tmp dir path managed by compiler driver -char driverTmpDir[FILENAME_MAX] = ""; +std::string driverTmpDir; bool fExitLeaks = false; bool fLibraryCompile = false; bool fLibraryFortran = false; @@ -390,7 +390,7 @@ bool fDynoGenStdLib = false; bool fDynoLibGenOrUse = false; // .dyno file or --dyno-gen-lib/std size_t fDynoBreakOnHash = 0; bool fDynoNoBreakError = false; -static char fDynoTimingPath[FILENAME_MAX] = ""; +static std::string fDynoTimingPath; bool fResolveConcreteFns = false; bool fIdBasedMunging = false; diff --git a/compiler/main/log.cpp b/compiler/main/log.cpp index bbd63031e50d..504b26cfce95 100644 --- a/compiler/main/log.cpp +++ b/compiler/main/log.cpp @@ -33,7 +33,7 @@ #include #include -char log_dir [FILENAME_MAX + 1] = "./log"; +std::string log_dir = "./log"; std::set log_modules; bool fLog = false; @@ -42,13 +42,13 @@ bool fLogIds = true; LogFormat fLogFormat = LogFormat::DEFAULT; int fdump_html = 0; -char fdump_html_chpl_home[FILENAME_MAX + 1] = ""; +std::string fdump_html_chpl_home = ""; bool fdump_html_include_system_modules = true; bool fdump_html_wrap_lines = true; bool fdump_html_print_block_IDs = false; FILE* deletedIdHandle = NULL; -char deletedIdFilename[FILENAME_MAX + 1] = ""; +std::string deletedIdFilename = ""; // Keeping names of available passes static bool availableInitialized = false; diff --git a/compiler/util/files.cpp b/compiler/util/files.cpp index a4695f1d8061..a2bed0897f18 100644 --- a/compiler/util/files.cpp +++ b/compiler/util/files.cpp @@ -61,11 +61,11 @@ #include -char executableFilename[FILENAME_MAX + 1] = ""; -char libmodeHeadername[FILENAME_MAX + 1] = ""; -char fortranModulename[FILENAME_MAX + 1] = ""; -char pythonModulename[FILENAME_MAX + 1] = ""; -char saveCDir[FILENAME_MAX + 1] = ""; +std::string executableFilename; +std::string libmodeHeadername; +std::string fortranModulename; +std::string pythonModulename; +std::string saveCDir; const char* additionalFilenamesListFilename = "additionalSourceFiles.tmp"; @@ -294,8 +294,8 @@ const char* getDirectory(const char* filename) { if (filenamebase == NULL) { return astr("."); } else { - char dir[FILENAME_MAX]; const int len = filenamebase - filename; + char dir[len + 1]; strncpy(dir, filename, len); dir[len] = '\0'; return astr(dir);