mirror of https://github.com/vitalif/openscad
Merge branch 'stack-size-hack' of github.com:openscad/openscad into stack-size-hack
Conflicts: src/expr.ccmaster
commit
241723dd8f
|
@ -247,6 +247,7 @@ HEADERS += src/typedefs.h \
|
||||||
src/expression.h \
|
src/expression.h \
|
||||||
src/stackcheck.h \
|
src/stackcheck.h \
|
||||||
src/function.h \
|
src/function.h \
|
||||||
|
src/exceptions.h \
|
||||||
src/grid.h \
|
src/grid.h \
|
||||||
src/highlighter.h \
|
src/highlighter.h \
|
||||||
src/localscope.h \
|
src/localscope.h \
|
||||||
|
|
|
@ -73,7 +73,7 @@ Context::~Context()
|
||||||
unsigned long Context::stackUsage() const
|
unsigned long Context::stackUsage() const
|
||||||
{
|
{
|
||||||
if (parent == NULL) {
|
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_ptr = 0;
|
||||||
((Context *)this)->stack_max = 0;
|
((Context *)this)->stack_max = 0;
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "printutils.h"
|
#include "printutils.h"
|
||||||
#include "builtin.h"
|
#include "builtin.h"
|
||||||
#include "localscope.h"
|
#include "localscope.h"
|
||||||
|
#include "exceptions.h"
|
||||||
|
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
|
|
||||||
|
@ -18,7 +19,16 @@ ValuePtr EvalContext::getArgValue(size_t i, const Context *ctx) const
|
||||||
{
|
{
|
||||||
assert(i < this->eval_arguments.size());
|
assert(i < this->eval_arguments.size());
|
||||||
const Assignment &arg = this->eval_arguments[i];
|
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
|
size_t EvalContext::numChildren() const
|
||||||
|
|
|
@ -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;
|
||||||
|
};
|
|
@ -32,6 +32,7 @@
|
||||||
#include "stl-utils.h"
|
#include "stl-utils.h"
|
||||||
#include "printutils.h"
|
#include "printutils.h"
|
||||||
#include "stackcheck.h"
|
#include "stackcheck.h"
|
||||||
|
#include "exceptions.h"
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
|
|
||||||
|
@ -487,8 +488,7 @@ ValuePtr ExpressionFunction::evaluate(const Context *context) const
|
||||||
{
|
{
|
||||||
if (StackCheck::inst()->check()) {
|
if (StackCheck::inst()->check()) {
|
||||||
function_recursion_detected(this->call_funcname.c_str());
|
function_recursion_detected(this->call_funcname.c_str());
|
||||||
// TO DO: throw function_recursion_detected();
|
throw RecursionException("function", call_funcname.c_str());
|
||||||
return ValuePtr::undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EvalContext *c = new EvalContext(context, this->call_arguments);
|
EvalContext *c = new EvalContext(context, this->call_arguments);
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
class AbstractFunction
|
class AbstractFunction
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include "function.h"
|
#include "function.h"
|
||||||
#include "printutils.h"
|
#include "printutils.h"
|
||||||
#include "parsersettings.h"
|
#include "parsersettings.h"
|
||||||
|
#include "exceptions.h"
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
|
@ -189,7 +190,7 @@ AbstractNode *Module::instantiate(const Context *ctx, const ModuleInstantiation
|
||||||
{
|
{
|
||||||
ModRecursionGuard g(*inst);
|
ModRecursionGuard g(*inst);
|
||||||
if (g.recursion_detected()) {
|
if (g.recursion_detected()) {
|
||||||
PRINTB("ERROR: Recursion detected calling module '%s'", inst->name());
|
throw RecursionException("module", inst->name().c_str());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue