mirror of https://github.com/vitalif/openscad
bugfix: Don't return a temporary string from exception::what
parent
4b4f4386bb
commit
b6558889b4
|
@ -1,16 +1,14 @@
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
|
||||||
class RecursionException: public std::exception {
|
class RecursionException: public std::runtime_error {
|
||||||
public:
|
public:
|
||||||
RecursionException(const char *recursiontype, const std::string &name)
|
static RecursionException create(const char *recursiontype, const std::string &name) {
|
||||||
: rectype(recursiontype), name(name) {}
|
|
||||||
virtual ~RecursionException() throw() {}
|
|
||||||
virtual const char *what() const throw() {
|
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
out << "ERROR: Recursion detected calling " << this->rectype << " '" << this->name << "'";
|
out << "ERROR: Recursion detected calling " << recursiontype << " '" << name << "'";
|
||||||
return out.str().c_str();
|
return RecursionException(out.str());
|
||||||
}
|
}
|
||||||
|
virtual ~RecursionException() throw() {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char *rectype;
|
RecursionException(const std::string &what_arg) : std::runtime_error(what_arg) {}
|
||||||
const std::string name;
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -473,7 +473,7 @@ ExpressionFunctionCall::ExpressionFunctionCall(const std::string &funcname,
|
||||||
ValuePtr ExpressionFunctionCall::evaluate(const Context *context) const
|
ValuePtr ExpressionFunctionCall::evaluate(const Context *context) const
|
||||||
{
|
{
|
||||||
if (StackCheck::inst()->check()) {
|
if (StackCheck::inst()->check()) {
|
||||||
throw RecursionException("function", funcname);
|
throw RecursionException::create("function", funcname);
|
||||||
}
|
}
|
||||||
|
|
||||||
EvalContext c(context, this->call_arguments);
|
EvalContext c(context, this->call_arguments);
|
||||||
|
|
|
@ -156,7 +156,7 @@ ValuePtr FunctionTailRecursion::evaluate(const Context *ctx, const EvalContext *
|
||||||
tmp.setVariables(definition_arguments, &ec);
|
tmp.setVariables(definition_arguments, &ec);
|
||||||
c.apply_variables(tmp);
|
c.apply_variables(tmp);
|
||||||
|
|
||||||
if (counter++ == 1000000) throw RecursionException("function", this->name);
|
if (counter++ == 1000000) throw RecursionException::create("function", this->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
ValuePtr result = endexpr->evaluate(&c);
|
ValuePtr result = endexpr->evaluate(&c);
|
||||||
|
|
|
@ -156,7 +156,7 @@ AbstractNode *ModuleInstantiation::evaluate(const Context *ctx) const
|
||||||
try {
|
try {
|
||||||
AbstractNode *node = ctx->instantiate_module(*this, &c); // Passes c as evalctx
|
AbstractNode *node = ctx->instantiate_module(*this, &c); // Passes c as evalctx
|
||||||
return node;
|
return node;
|
||||||
} catch (RecursionException &e) {
|
} catch (const RecursionException &e) {
|
||||||
PRINT(e.what());
|
PRINT(e.what());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ Module::~Module()
|
||||||
AbstractNode *Module::instantiate(const Context *ctx, const ModuleInstantiation *inst, EvalContext *evalctx) const
|
AbstractNode *Module::instantiate(const Context *ctx, const ModuleInstantiation *inst, EvalContext *evalctx) const
|
||||||
{
|
{
|
||||||
if (StackCheck::inst()->check()) {
|
if (StackCheck::inst()->check()) {
|
||||||
throw RecursionException("module", inst->name());
|
throw RecursionException::create("module", inst->name());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue