*/
/*
- * GiNaC Copyright (C) 1999-2015 Johannes Gutenberg University Mainz, Germany
+ * GiNaC Copyright (C) 1999-2020 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 "symbol.h"
#ifdef HAVE_LIBDL
-#include <dlfcn.h>
+# include <dlfcn.h>
#endif // def HAVE_LIBDL
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#else
+# ifdef _MSC_VER
+# include <io.h> // for close(3)
+# endif // def _MSC_VER
+#endif // def HAVE_UNISTD_H
+#include <cstdlib>
#include <fstream>
#include <ios>
#include <sstream>
namespace GiNaC {
#ifdef HAVE_LIBDL
-
+
/**
* Small class that manages modules opened by libdl. It is used by compile_ex
* and link_ex in order to have a clean-up of opened modules and their
const char* filename_pattern = "./GiNaCXXXXXX";
char* new_filename = new char[strlen(filename_pattern)+1];
strcpy(new_filename, filename_pattern);
- if (!mktemp(new_filename)) {
+ int fd = mkstemp(new_filename);
+ if (fd == -1) {
delete[] new_filename;
- throw std::runtime_error("mktemp failed");
+ throw std::runtime_error("mkstemp failed");
}
filename = std::string(new_filename);
ofs.open(new_filename, std::ios::out);
+ close(fd);
delete[] new_filename;
} else {
// use parameter as filename
*/
void compile_src_file(const std::string filename, bool clean_up)
{
- std::string strcompile = "ginac-excompiler " + filename;
+ std::string strcompile = LIBEXECDIR "ginac-excompiler " + filename;
if (system(strcompile.c_str())) {
throw std::runtime_error("excompiler::compile_src_file: error compiling source file!");
}
{
void* module = nullptr;
module = dlopen(filename.c_str(), RTLD_NOW);
- if (module == nullptr) {
+ if (module == nullptr) {
throw std::runtime_error("excompiler::link_so_file: could not open compiled module!");
}
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;
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;