From d7dfe51faed84ba2b06c32a302597c0226ea239c Mon Sep 17 00:00:00 2001 From: Steve Reinhardt Date: Thu, 5 Aug 2004 02:03:47 -0700 Subject: Integrate Python configuration script parsing into m5 itself. SConscript: Add pyconfig/{pyconfig,code}.cc Add list of object description (.od) files. Include pyconfig/SConscript. base/inifile.cc: Get rid of CPP_PIPE... it never really worked anyway. base/inifile.hh: Make load(ifstream&) method public so pyconfig code can call it. sim/main.cc: Handle Python config scripts (end in '.py' instead of '.ini'). sim/pyconfig/m5configbase.py: Add license. Fix minor __setattr__ problem (2.3 related?) --HG-- rename : util/config/m5configbase.py => sim/pyconfig/m5configbase.py extra : convert_revision : 5e004922f950bfdefced333285584b80ad7ffb83 --- base/inifile.cc | 42 +++++------------------------------------- base/inifile.hh | 12 ++++++------ 2 files changed, 11 insertions(+), 43 deletions(-) (limited to 'base') diff --git a/base/inifile.cc b/base/inifile.cc index 10836baea..94b17966a 100644 --- a/base/inifile.cc +++ b/base/inifile.cc @@ -27,8 +27,6 @@ */ #define USE_CPP -// #define CPP_PIPE - #ifdef USE_CPP #include @@ -43,9 +41,6 @@ #include #include -#if __GNUC__ >= 3 -#include -#endif #include #include @@ -74,8 +69,6 @@ IniFile::~IniFile() bool IniFile::loadCPP(const string &file, vector &cppArgs) { - int fd[2]; - // Open the file just to verify that we can. Otherwise if the // file doesn't exist or has bad permissions the user will get // confusing errors from cpp/g++. @@ -99,18 +92,13 @@ IniFile::loadCPP(const string &file, vector &cppArgs) delete [] cfile; -#ifdef CPP_PIPE - if (pipe(fd) == -1) - return false; -#else char tempfile[] = "/tmp/configXXXXXX"; - fd[0] = fd[1] = mkstemp(tempfile); -#endif + int tmp_fd = mkstemp(tempfile); int pid = fork(); if (pid == -1) - return 1; + return false; if (pid == 0) { char filename[FILENAME_MAX]; @@ -141,7 +129,7 @@ IniFile::loadCPP(const string &file, vector &cppArgs) args[nextArg++] = NULL; close(STDOUT_FILENO); - if (dup2(fd[1], STDOUT_FILENO) == -1) + if (dup2(tmp_fd, STDOUT_FILENO) == -1) exit(1); execvp("g++", args); @@ -158,33 +146,13 @@ IniFile::loadCPP(const string &file, vector &cppArgs) if (!WIFEXITED(retval) || WEXITSTATUS(retval) != 0) return false; -#ifdef CPP_PIPE - close(fd[1]); -#else - lseek(fd[0], 0, SEEK_SET); -#endif + close(tmp_fd); bool status = false; -#if __GNUC__ >= 3 - using namespace __gnu_cxx; - stdio_filebuf fbuf(fd[0], ios_base::in, true, - static_cast::int_type>(BUFSIZ)); - - if (fbuf.is_open()) { - istream f(&fbuf); - status = load(f); - } - -#else - ifstream f(fd[0]); - if (f.is_open()) - status = load(f); -#endif + status = load(tempfile); -#ifndef CPP_PIPE unlink(tempfile); -#endif return status; } diff --git a/base/inifile.hh b/base/inifile.hh index 01e4e6c17..58a657db4 100644 --- a/base/inifile.hh +++ b/base/inifile.hh @@ -151,12 +151,6 @@ class IniFile /// @retval Pointer to section object, or NULL if not found. Section *findSection(const std::string §ionName) const; - /// Load parameter settings from given istream. This is a helper - /// function for load(string) and loadCPP(), which open a file - /// and then pass it here. - /// @retval True if successful, false if errors were encountered. - bool load(std::istream &f); - public: /// Constructor. IniFile(); @@ -164,6 +158,12 @@ class IniFile /// Destructor. ~IniFile(); + /// Load parameter settings from given istream. This is a helper + /// function for load(string) and loadCPP(), which open a file + /// and then pass it here. + /// @retval True if successful, false if errors were encountered. + bool load(std::istream &f); + /// Load the specified file, passing it through the C preprocessor. /// Parameter settings found in the file will be merged with any /// already defined in this object. -- cgit v1.2.3