+ /**
+ * Closes a module and deletes the so-file if the associated clean-up flag is true.
+ */
+ void clean_up(const std::vector<filedesc>::const_iterator it)
+ {
+ dlclose(it->module);
+ if (it->clean_up) {
+ remove(it->name.c_str());
+ }
+ }
+ /**
+ * Creates a new C source file and adds a standard header. If filename is
+ * empty, a unique random name is produced and used.
+ */
+ void create_src_file(std::string& filename, std::ofstream& ofs)
+ {
+ if (filename.empty()) {
+ // fill filename with unique random word
+ const char* filename_pattern = "./GiNaCXXXXXX";
+ char* new_filename = new char[strlen(filename_pattern)+1];
+ strcpy(new_filename, filename_pattern);
+ if (!mktemp(new_filename)) {
+ delete[] new_filename;
+ throw std::runtime_error("mktemp failed");
+ }
+ filename = std::string(new_filename);
+ ofs.open(new_filename, std::ios::out);
+ delete[] new_filename;
+ } else {
+ // use parameter as filename
+ ofs.open(filename.c_str(), std::ios::out);
+ }
+
+ if (!ofs) {
+ throw std::runtime_error("could not create source code file for compilation");
+ }