Merge branch 'stack-size-hack' of github.com:openscad/openscad into stack-size-hack

Conflicts:
	src/expr.cc
master
Torsten Paul 2014-11-24 23:46:39 +01:00
commit 241723dd8f
7 changed files with 32 additions and 6 deletions

View File

@ -247,6 +247,7 @@ HEADERS += src/typedefs.h \
src/expression.h \
src/stackcheck.h \
src/function.h \
src/exceptions.h \
src/grid.h \
src/highlighter.h \
src/localscope.h \

View File

@ -73,7 +73,7 @@ Context::~Context()
unsigned long Context::stackUsage() const
{
if (parent == NULL) {
unsigned long ret = std::abs((unsigned long)stack_ptr - (unsigned long)stack_max);
unsigned long ret = std::labs((unsigned long)stack_ptr - (unsigned long)stack_max);
((Context *)this)->stack_ptr = 0;
((Context *)this)->stack_max = 0;
return ret;

View File

@ -5,6 +5,7 @@
#include "printutils.h"
#include "builtin.h"
#include "localscope.h"
#include "exceptions.h"
#include <boost/foreach.hpp>
@ -18,7 +19,16 @@ ValuePtr EvalContext::getArgValue(size_t i, const Context *ctx) const
{
assert(i < this->eval_arguments.size());
const Assignment &arg = this->eval_arguments[i];
return arg.second ? arg.second->evaluate(ctx ? ctx : this) : ValuePtr::undefined;
ValuePtr v;
if (arg.second) {
try {
v = arg.second->evaluate(ctx ? ctx : this);
}
catch (RecursionException &e) {
PRINT(e.what());
}
}
return v;
}
size_t EvalContext::numChildren() const

15
src/exceptions.h Normal file
View File

@ -0,0 +1,15 @@
#include <exception>
class RecursionException: public std::exception {
public:
RecursionException(const char *recursiontype, const char *funcname)
: rectype(recursiontype), funcname(funcname) {}
virtual const char *what() const throw() {
std::stringstream out;
out << "ERROR: Recursion detected calling " << this->rectype << " '" << this->funcname << "'";
return out.str().c_str();
}
private:
const char *rectype;
const char *funcname;
};

View File

@ -32,6 +32,7 @@
#include "stl-utils.h"
#include "printutils.h"
#include "stackcheck.h"
#include "exceptions.h"
#include <boost/bind.hpp>
#include <boost/foreach.hpp>
@ -487,8 +488,7 @@ ValuePtr ExpressionFunction::evaluate(const Context *context) const
{
if (StackCheck::inst()->check()) {
function_recursion_detected(this->call_funcname.c_str());
// TO DO: throw function_recursion_detected();
return ValuePtr::undefined;
throw RecursionException("function", call_funcname.c_str());
}
EvalContext *c = new EvalContext(context, this->call_arguments);

View File

@ -7,7 +7,6 @@
#include <string>
#include <vector>
class AbstractFunction
{
private:

View File

@ -33,6 +33,7 @@
#include "function.h"
#include "printutils.h"
#include "parsersettings.h"
#include "exceptions.h"
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
@ -189,7 +190,7 @@ AbstractNode *Module::instantiate(const Context *ctx, const ModuleInstantiation
{
ModRecursionGuard g(*inst);
if (g.recursion_detected()) {
PRINTB("ERROR: Recursion detected calling module '%s'", inst->name());
throw RecursionException("module", inst->name().c_str());
return NULL;
}