]> www.ginac.de Git - ginac.git/blobdiff - ginac/excompiler.cpp
More evaluation rules: abs(x^n) => abs(x)^n (x > 0, n is real).
[ginac.git] / ginac / excompiler.cpp
index 30b33066e66f382eeb476f7b8ff18c8f02d8213b..e108895a0db65b17f1a8f4d7a6939b74ce5878c1 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 /*
- *  GiNaC Copyright (C) 1999-2006 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2011 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
 
 #include "excompiler.h"
 
-#include <stdexcept>
-#include <ios>
-#include <fstream>
-#include <sstream>
-#include <string>
-#include <vector>
-
+#ifdef HAVE_CONFIG_H
 #include "config.h"
-
-#ifdef HAVE_LIBDL
-#include <dlfcn.h>
-#endif // def HAVE_LIBDL
+#endif
 
 #include "ex.h"
 #include "lst.h"
 #include "relational.h"
 #include "symbol.h"
 
+#ifdef HAVE_LIBDL
+#include <dlfcn.h>
+#endif // def HAVE_LIBDL
+#include <fstream>
+#include <ios>
+#include <sstream>
+#include <stdexcept>
+#include <string>
+#include <vector>
+
 namespace GiNaC {
 
 #ifdef HAVE_LIBDL
@@ -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);
@@ -171,7 +172,7 @@ public:
                for (std::vector<filedesc>::iterator it = filelist.begin(); it != filelist.end();) {
                        if (it->name == filename) {
                                clean_up(it);
-                               filelist.erase(it);
+                               it = filelist.erase(it);
                        } else {
                                ++it;
                        }
@@ -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<syms.nops(); ++count) {
+       for (std::size_t count=0; count<syms.nops(); ++count) {
                std::ostringstream s;
                s << "a[" << count << "]";
                replacements.append(syms.op(count) == symbol(s.str()));
        }
 
        std::vector<ex> expr_with_cname;
-       for (int count=0; count<exprs.nops(); ++count) {
+       for (std::size_t count=0; count<exprs.nops(); ++count) {
                expr_with_cname.push_back(exprs.op(count).subs(replacements));
        }
 
@@ -261,7 +262,7 @@ void compile_ex(const lst& exprs, const lst& syms, FUNCP_CUBA& fp, const std::st
 
        ofs << "void compiled_ex(const int* an, const double a[], const int* fn, double f[])" << std::endl;
        ofs << "{" << std::endl;
-       for (int count=0; count<exprs.nops(); ++count) {
+       for (std::size_t count=0; count<exprs.nops(); ++count) {
                ofs << "f[" << count << "] = ";
                expr_with_cname[count].print(GiNaC::print_csrc_double(ofs));
                ofs << ";" << std::endl;
@@ -302,7 +303,7 @@ void unlink_ex(const std::string filename)
        global_excompiler.unlink(filename);
 }
 
-#elif // def HAVE_LIBDL
+#else // def HAVE_LIBDL
 
 /*
  * In case no working libdl has been found by configure, the following function