X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fexcompiler.cpp;h=1ef61d1f786ec309195e1c456f441f1cc54428e5;hp=30b33066e66f382eeb476f7b8ff18c8f02d8213b;hb=25b4d894b5b2f7f56fb49e62a7767ab969d5249f;hpb=43287525116c2265404f224bbf0311d9fec4b516 diff --git a/ginac/excompiler.cpp b/ginac/excompiler.cpp index 30b33066..1ef61d1f 100644 --- a/ginac/excompiler.cpp +++ b/ginac/excompiler.cpp @@ -6,7 +6,7 @@ */ /* - * GiNaC Copyright (C) 1999-2006 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2016 Johannes Gutenberg University Mainz, Germany * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,18 +25,9 @@ #include "excompiler.h" -#include -#include -#include -#include -#include -#include - +#ifdef HAVE_CONFIG_H #include "config.h" - -#ifdef HAVE_LIBDL -#include -#endif // def HAVE_LIBDL +#endif #include "ex.h" #include "lst.h" @@ -44,6 +35,16 @@ #include "relational.h" #include "symbol.h" +#ifdef HAVE_LIBDL +#include +#endif // def HAVE_LIBDL +#include +#include +#include +#include +#include +#include + namespace GiNaC { #ifdef HAVE_LIBDL @@ -71,11 +72,11 @@ class excompiler std::vector filelist; /**< List of all opened modules */ public: /** - * Complete clean-up of opend modules is done on destruction. + * Complete clean-up of opened modules is done on destruction. */ ~excompiler() { - for (std::vector::const_iterator it = filelist.begin(); it != filelist.end(); ++it) { + for (auto it = filelist.begin(); it != filelist.end(); ++it) { clean_up(it); } } @@ -108,16 +109,16 @@ public: { if (filename.empty()) { // fill filename with unique random word - const char* filename_pattern = "GiNaCXXXXXX"; + 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; + delete[] new_filename; throw std::runtime_error("mktemp failed"); } filename = std::string(new_filename); ofs.open(new_filename, std::ios::out); - delete new_filename; + delete[] new_filename; } else { // use parameter as filename ofs.open(filename.c_str(), std::ios::out); @@ -152,9 +153,9 @@ public: */ void* link_so_file(const std::string filename, bool clean_up) { - void* module = NULL; + void* module = nullptr; module = dlopen(filename.c_str(), RTLD_NOW); - if (module == NULL) { + if (module == nullptr) { throw std::runtime_error("excompiler::link_so_file: could not open compiled module!"); } @@ -168,10 +169,10 @@ public: */ void unlink(const std::string filename) { - for (std::vector::iterator it = filelist.begin(); it != filelist.end();) { + for (auto it = filelist.begin(); it != filelist.end();) { if (it->name == filename) { clean_up(it); - filelist.erase(it); + it = filelist.erase(it); } else { ++it; } @@ -180,7 +181,7 @@ public: }; /** - * This static object manages the modules opened by the complile_ex and link_ex + * This static object manages the modules opened by the compile_ex and link_ex * functions. On program termination its dtor is called and all open modules * are closed. The associated source and so-files are eventually deleted then * as well. @@ -194,7 +195,7 @@ static excompiler global_excompiler; void compile_ex(const ex& expr, const symbol& sym, FUNCP_1P& fp, const std::string filename) { symbol x("x"); - ex expr_with_x = expr.subs(lst(sym==x)); + ex expr_with_x = expr.subs(lst{sym==x}); std::ofstream ofs; std::string unique_filename = filename; @@ -219,7 +220,7 @@ void compile_ex(const ex& expr, const symbol& sym, FUNCP_1P& fp, const std::stri void compile_ex(const ex& expr, const symbol& sym1, const symbol& sym2, FUNCP_2P& fp, const std::string filename) { symbol x("x"), y("y"); - ex expr_with_xy = expr.subs(lst(sym1==x, sym2==y)); + ex expr_with_xy = expr.subs(lst{sym1==x, sym2==y}); std::ofstream ofs; std::string unique_filename = filename; @@ -244,14 +245,14 @@ void compile_ex(const ex& expr, const symbol& sym1, const symbol& sym2, FUNCP_2P void compile_ex(const lst& exprs, const lst& syms, FUNCP_CUBA& fp, const std::string filename) { lst replacements; - for (int count=0; count expr_with_cname; - for (int count=0; count