--- parser3/src/classes/op.C 2001/10/10 12:52:13 1.52 +++ parser3/src/classes/op.C 2001/11/01 16:30:14 1.57 @@ -4,7 +4,7 @@ Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - $Id: op.C,v 1.52 2001/10/10 12:52:13 parser Exp $ + $Id: op.C,v 1.57 2001/11/01 16:30:14 paf Exp $ */ #include "classes.h" @@ -57,7 +57,7 @@ static void _untaint(Request& r, const S String::Untaint_lang lang=static_cast( untaint_lang_name2enum->get_int(lang_name)); if(!lang) - PTHROW(0, 0, + throw Exception(0, 0, &lang_name, "invalid untaint language"); @@ -80,7 +80,7 @@ static void _taint(Request& r, const Str lang=static_cast( untaint_lang_name2enum->get_int(lang_name)); if(!lang) - PTHROW(0, 0, + throw Exception(0, 0, &lang_name, "invalid taint language"); } @@ -146,7 +146,7 @@ static void _while(Request& r, const Str int endless_loop_count=0; while(true) { if(++endless_loop_count>=MAX_LOOPS) // endless loop? - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "endless loop detected"); @@ -176,16 +176,16 @@ static void _for(Request& r, const Strin Value& body_code=params->as_junction(3, "body must be code"); Value *delim_maybe_code=params->size()>4?¶ms->get(4):0; + if(to-from>=MAX_LOOPS) // too long loop? + throw Exception(0, 0, + &method_name, + "endless loop detected"); + bool need_delim=false; VInt *vint=new(pool) VInt(pool, 0); - int endless_loop_count=0; for(int i=from; i<=to; i++) { - if(++endless_loop_count>=MAX_LOOPS) // endless loop? - PTHROW(0, 0, - &method_name, - "endless loop detected"); vint->set_int(i); - r.self/*root*/->put_element(var_name, vint); + r.root->put_element(var_name, vint); Value& processed_body=r.process(body_code); if(delim_maybe_code) { // delimiter set? @@ -220,12 +220,13 @@ static void _error(Request& r, const Str Pool& pool=r.pool(); const String& serror=params->as_string(0, "message must be string"); - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "%s", serror.cstr()); } +/// @todo rewrite ugly code with try/try to autoobject TempConnection static void _connect(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); @@ -239,40 +240,35 @@ static void _connect(Request& r, const S SQL_Connection& connection=SQL_driver_manager->get_connection( url.as_string(), method_name, protocol2driver_and_client); - Exception rethrow_me; // remember/set current connection SQL_Connection *saved_connection=r.connection; r.connection=&connection; // execute body - bool body_failed=false; - PTRY - r.write_assign_lang(r.process(body_code)); - PCATCH(e) { // connect/process problem - rethrow_me=e; body_failed=true; - } - PEND_CATCH - - bool finalizer_failed=false; - PTRY - // FINALLY - if(body_failed) - connection.rollback(); - else + try { + try { + r.write_assign_lang(r.process(body_code)); + connection.commit(); - PCATCH(e) { // commit/rollback problem - rethrow_me=e; finalizer_failed=true; + } catch(...) { // process/commit problem + connection.rollback(); + + /*re*/throw; + } + + } catch(...) { + // close connection [cache it] + connection.close(); + // recall current connection from remembered + r.connection=saved_connection; + + /*re*/throw; } - PEND_CATCH + // and anyway // close connection [cache it] connection.close(); // recall current connection from remembered r.connection=saved_connection; - - if(body_failed || finalizer_failed) // were there an exception for us to rethrow? - PTHROW(rethrow_me.type(), rethrow_me.code(), - rethrow_me.problem_source(), - rethrow_me.comment()); } #ifndef DOXYGEN @@ -300,7 +296,7 @@ static void _case(Request& r, const Stri Switch_data *data=static_cast(r.classes_conf.get(*switch_data_name)); if(!data) - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "without switch"); @@ -357,7 +353,7 @@ MOP::MOP(Pool& apool) : Methoded(apool), // ^use[file] add_native_method("use", Method::CT_ANY, _use, 1, 1); - // ^for[i;from-number;to-number-inclusive]{code}[delim] + // ^for[i](from-number;to-number-inclusive){code}[delim] add_native_method("for", Method::CT_ANY, _for, 3+1, 3+1+1); // ^eval(expr)