tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsdelf...@apache.org
Subject svn commit: r1419987 [3/5] - in /tuscany/sca-cpp/trunk/modules: http/ java/ oauth/ opencl/ python/ server/ server/htdocs/test/ wsgi/
Date Tue, 11 Dec 2012 04:03:35 GMT
Modified: tuscany/sca-cpp/trunk/modules/oauth/mod-oauth2.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/oauth/mod-oauth2.cpp?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/oauth/mod-oauth2.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/oauth/mod-oauth2.cpp Tue Dec 11 04:03:29 2012
@@ -50,18 +50,18 @@ namespace oauth2 {
  */
 class ServerConf {
 public:
-    ServerConf(apr_pool_t* p, server_rec* s) : p(p), server(s) {
+    ServerConf(apr_pool_t* const p, server_rec* const s) : p(p), server(s) {
     }
 
     const gc_pool p;
-    server_rec* server;
-    string ca;
-    string cert;
-    string key;
-    list<list<value> > appkeys;
-    list<string> mcaddrs;
-    memcache::MemCached mc;
-    perthread_ptr<http::CURLSession> cs;
+    server_rec* const server;
+    gc_mutable_ref<string> ca;
+    gc_mutable_ref<string> cert;
+    gc_mutable_ref<string> key;
+    gc_mutable_ref<list<list<value> > > appkeys;
+    gc_mutable_ref<list<string> > mcaddrs;
+    gc_mutable_ref<memcache::MemCached> mc;
+    gc_mutable_ref<perthread_ptr<http::CURLSession> > cs;
 };
 
 /**
@@ -74,7 +74,7 @@ public:
     AuthnProviderConf(const string name, const authn_provider* provider) : name(name), provider(provider) {
     }
 
-    string name;
+    const string name;
     const authn_provider* provider;
 };
 
@@ -83,21 +83,21 @@ public:
  */
 class DirConf {
 public:
-    DirConf(apr_pool_t* p, char* d) : p(p), dir(d), enabled(false), login("") {
+    DirConf(apr_pool_t* const p, const char* const d) : p(p), dir(d), enabled(false), login(emptyString) {
     }
 
     const gc_pool p;
-    const char* dir;
+    const char* const dir;
     bool enabled;
-    string login;
-    list<list<value> > scopeattrs;
-    list<AuthnProviderConf> apcs;
+    gc_mutable_ref<string> login;
+    gc_mutable_ref<list<list<value> > > scopeattrs;
+    gc_mutable_ref<list<AuthnProviderConf> > apcs;
 };
 
 /**
  * Run the authnz hooks to authenticate a request.
  */
-const failable<int> checkAuthnzProviders(const string& user, request_rec* r, const list<AuthnProviderConf>& apcs) {
+const failable<int> checkAuthnzProviders(const string& user, request_rec* const r, const list<AuthnProviderConf>& apcs) {
     if (isNil(apcs))
         return mkfailure<int>("Authentication failure for: " + user, HTTP_UNAUTHORIZED);
     const AuthnProviderConf apc = car<AuthnProviderConf>(apcs);
@@ -112,7 +112,7 @@ const failable<int> checkAuthnzProviders
     return OK;
 }
 
-const failable<int> checkAuthnz(const string& user, request_rec* r, const list<AuthnProviderConf>& apcs) {
+const failable<int> checkAuthnz(const string& user, request_rec* const r, const list<AuthnProviderConf>& apcs) {
     if (substr(user, 0, 1) == "/")
         return mkfailure<int>(string("Encountered FakeBasicAuth spoof: ") + user, HTTP_UNAUTHORIZED);
 
@@ -133,7 +133,7 @@ const failable<value> userInfo(const val
 /**
  * Handle an authenticated request.
  */
-const failable<int> authenticated(const list<list<value> >& userinfo, const bool check, request_rec* r, const list<list<value> >& scopeattrs, const list<AuthnProviderConf>& apcs) {
+const failable<int> authenticated(const list<list<value> >& userinfo, const bool check, request_rec* const r, const list<list<value> >& scopeattrs, const list<AuthnProviderConf>& apcs) {
     debug(userinfo, "modoauth2::authenticated::userinfo");
 
     if (isNil(scopeattrs)) {
@@ -141,7 +141,7 @@ const failable<int> authenticated(const 
         // Store user id in an environment variable
         const list<value> id = assoc<value>("id", userinfo);
         if (isNil(id) || isNil(cdr(id)))
-            return mkfailure<int>("Couldn't retrieve user id");
+            return mkfailure<int>("Couldn't retrieve user id", HTTP_UNAUTHORIZED);
         apr_table_set(r->subprocess_env, "OAUTH2_ID", apr_pstrdup(r->pool, c_str(cadr(id))));
 
         // If the request user field has not been mapped to another attribute, map the
@@ -151,7 +151,7 @@ const failable<int> authenticated(const 
 
         // Run the authnz hooks to check the authenticated user
         if (check)
-            return checkAuthnz(r->user == NULL? "" : r->user, r, apcs);
+            return checkAuthnz(r->user == NULL? emptyString : r->user, r, apcs);
         return OK;
     }
 
@@ -172,7 +172,7 @@ const failable<int> authenticated(const 
 /**
  * Handle an authorize request.
  */
-const failable<int> authorize(const list<list<value> >& args, request_rec* r, const list<list<value> >& appkeys) {
+const failable<int> authorize(const list<list<value> >& args, request_rec* const r, const list<list<value> >& appkeys) {
     // Extract authorize, access_token, client ID and info URIs
     const list<value> ref = assoc<value>("openauth_referrer", args);
     if (isNil(ref) || isNil(cdr(ref)))
@@ -206,11 +206,11 @@ const failable<int> authorize(const list
     // Lookup client app configuration
     const list<value> app = assoc<value>(cadr(cid), appkeys);
     if (isNil(app) || isNil(cdr(app)))
-        return mkfailure<int>(string("client id not found: ") + cadr(cid));
+        return mkfailure<int>(string("client id not found: ") + (string)cadr(cid));
     list<value> appkey = cadr(app);
 
     // Redirect to the authorize URI
-    const list<value> adisplay = (isNil(display) || isNil(cdr(display)))? list<value>() : mklist<value>("display", cadr(display));
+    const list<value> adisplay = (isNil(display) || isNil(cdr(display)))? nilListValue : mklist<value>("display", cadr(display));
     const list<list<value> > aargs = mklist<list<value> >(mklist<value>("response_type", "code"), mklist<value>("client_id", car(appkey)), mklist<value>("scope", cadr(scope)), adisplay, mklist<value>("redirect_uri", httpd::escape(redir)), mklist<value>("state", httpd::escape(state)));
     const string uri = httpd::unescape(cadr(auth)) + string("?") + http::queryString(aargs);
     debug(uri, "modoauth2::authorize::uri");
@@ -229,7 +229,7 @@ const failable<list<value> > profileUser
 /**
  * Handle an access_token request.
  */
-const failable<int> accessToken(const list<list<value> >& args, request_rec* r, const list<list<value> >& appkeys, const perthread_ptr<http::CURLSession>& cs, const list<list<value> >& scopeattrs, const list<AuthnProviderConf>& apcs, const memcache::MemCached& mc) {
+const failable<int> accessToken(const list<list<value> >& args, request_rec* r, const list<list<value> >& appkeys, const http::CURLSession& cs, const list<list<value> >& scopeattrs, const list<AuthnProviderConf>& apcs, const memcache::MemCached& mc) {
 
     // Extract access_token URI, client ID and authorization code parameters
     const list<value> state = assoc<value>("state", args);
@@ -255,7 +255,7 @@ const failable<int> accessToken(const li
     // Lookup client app configuration
     const list<value> app = assoc<value>(cadr(cid), appkeys);
     if (isNil(app) || isNil(cdr(app)))
-        return mkfailure<int>(string("client id not found: ") + cadr(cid));
+        return mkfailure<int>(string("client id not found: ") + (string)cadr(cid));
     list<value> appkey = cadr(app);
 
     // Build the redirect URI
@@ -269,7 +269,7 @@ const failable<int> accessToken(const li
     const string turi = httpd::unescape(cadr(tok));
     debug(turi, "modoauth2::access_token::tokenuri");
     const value tval = mklist<value>(string("application/x-www-form-urlencoded;charset=UTF-8"), mklist<value>(tqs));
-    const failable<value> ftr = http::post(tval, turi, *(cs));
+    const failable<value> ftr = http::post(tval, turi, cs);
     if (!hasContent(ftr))
         return mkfailure<int>(ftr);
     const value tr = content(ftr);
@@ -288,7 +288,7 @@ const failable<int> accessToken(const li
     const list<list<value> > iargs = mklist<list<value> >(tv);
     const string iuri = httpd::unescape(cadr(info)) + string("?") + http::queryString(iargs);
     debug(iuri, "modoauth2::access_token::infouri");
-    const failable<value> profres = http::get(iuri, *(cs));
+    const failable<value> profres = http::get(iuri, cs);
     if (!hasContent(profres))
         return mkfailure<int>("Couldn't retrieve user info");
     debug(content(profres), "modoauth2::access_token::info");
@@ -304,7 +304,7 @@ const failable<int> accessToken(const li
         return authrc;
 
     // Store user info in memcached keyed by a session ID
-    const value sid = string("OAuth2_") + mkrand();
+    const value sid = string("OAuth2_") + (string)mkrand();
     const failable<bool> prc = memcache::put(mklist<value>("tuscanyOAuth2", sid), content(userinfo), mc);
     if (!hasContent(prc))
         return mkfailure<int>(prc);
@@ -319,7 +319,7 @@ const failable<int> accessToken(const li
  * Check user authentication.
  */
 static int checkAuthn(request_rec *r) {
-    gc_scoped_pool pool(r->pool);
+    const gc_scoped_pool sp(r->pool);
 
     // Decline if we're not enabled or AuthType is not set to Open
     const DirConf& dc = httpd::dirConf<DirConf>(r, &mod_tuscany_oauth2);
@@ -329,7 +329,7 @@ static int checkAuthn(request_rec *r) {
     if (atype == NULL || strcasecmp(atype, "Open"))
         return DECLINED;
     debug_httpdRequest(r, "modoauth2::checkAuthn::input");
-    debug(atype, "modopenauth::checkAuthn::auth_type");
+    debug(atype, "modoauth2::checkAuthn::auth_type");
 
     // Get the server configuration
     const ServerConf& sc = httpd::serverConf<ServerConf>(r, &mod_tuscany_oauth2);
@@ -344,9 +344,9 @@ static int checkAuthn(request_rec *r) {
         // Extract the user info from the auth session
         const failable<value> userinfo = userInfo(content(sid), sc.mc);
         if (!hasContent(userinfo))
-            return httpd::reportStatus(mkfailure<int>(userinfo));
+            return openauth::reportStatus(mkfailure<int>(reason(userinfo), HTTP_UNAUTHORIZED), dc.login, nilValue, r);
         r->ap_auth_type = const_cast<char*>(atype);
-        return httpd::reportStatus(authenticated(content(userinfo), false, r, dc.scopeattrs, dc.apcs));
+        return openauth::reportStatus(authenticated(content(userinfo), false, r, dc.scopeattrs, dc.apcs), dc.login, nilValue, r);
     }
 
     // Get the request args
@@ -355,19 +355,14 @@ static int checkAuthn(request_rec *r) {
     // Handle OAuth authorize request step
     if (string(r->uri) == "/oauth2/authorize/") {
         r->ap_auth_type = const_cast<char*>(atype);
-        return httpd::reportStatus(authorize(args, r, sc.appkeys));
+        return openauth::reportStatus(authorize(args, r, sc.appkeys), dc.login, 1, r);
     }
 
     // Handle OAuth access_token request step
     if (string(r->uri) == "/oauth2/access_token/") {
         r->ap_auth_type = const_cast<char*>(atype);
-        const failable<int> authrc = accessToken(args, r, sc.appkeys, sc.cs, dc.scopeattrs, dc.apcs, sc.mc);
-
-        // Redirect to the login page if user is not authorized
-        if (!hasContent(authrc) && rcode(authrc) == HTTP_UNAUTHORIZED)
-            return httpd::reportStatus(openauth::login(dc.login, string("/"), 1, r));
-
-        return httpd::reportStatus(authrc);
+        const failable<int> authrc = accessToken(args, r, sc.appkeys, *(*(perthread_ptr<http::CURLSession>*)sc.cs), dc.scopeattrs, dc.apcs, sc.mc);
+        return openauth::reportStatus(authrc, dc.login, 1, r);
     }
 
     // Redirect to the login page, unless we have a session id or an authorization
@@ -382,22 +377,22 @@ static int checkAuthn(request_rec *r) {
         return DECLINED;
 
     r->ap_auth_type = const_cast<char*>(atype);
-    return httpd::reportStatus(openauth::login(dc.login, value(), value(), r));
+    return httpd::reportStatus(openauth::login(dc.login, nilValue, nilValue, r));
 }
 
 /**
  * Process the module configuration.
  */
-int postConfigMerge(ServerConf& mainsc, server_rec* s) {
+int postConfigMerge(const ServerConf& mainsc, server_rec* const s) {
     if (s == NULL)
         return OK;
     ServerConf& sc = httpd::serverConf<ServerConf>(s, &mod_tuscany_oauth2);
     debug(httpd::serverName(s), "modoauth2::postConfigMerge::serverName");
 
     // Merge configuration from main server
-    if (isNil(sc.appkeys))
+    if (isNil((list<list<value> >)sc.appkeys))
         sc.appkeys = mainsc.appkeys;
-    if (isNil(sc.mcaddrs))
+    if (isNil((list<string>)sc.mcaddrs))
         sc.mcaddrs = mainsc.mcaddrs;
     sc.mc = mainsc.mc;
     sc.cs = mainsc.cs;
@@ -405,10 +400,10 @@ int postConfigMerge(ServerConf& mainsc, 
     return postConfigMerge(mainsc, s->next);
 }
 
-int postConfig(apr_pool_t* p, unused apr_pool_t* plog, unused apr_pool_t* ptemp, server_rec* s) {
-    gc_scoped_pool pool(p);
+int postConfig(apr_pool_t* const p, unused apr_pool_t* const plog, unused apr_pool_t* const ptemp, server_rec* const s) {
+    const gc_scoped_pool sp(p);
 
-    ServerConf& sc = httpd::serverConf<ServerConf>(s, &mod_tuscany_oauth2);
+    const ServerConf& sc = httpd::serverConf<ServerConf>(s, &mod_tuscany_oauth2);
     debug(httpd::serverName(s), "modoauth2::postConfig::serverName");
 
     // Merge server configurations
@@ -416,30 +411,12 @@ int postConfig(apr_pool_t* p, unused apr
 }
 
 /**
- * Lambda function that creates a new CURL session.
- */
-class newsession {
-public:
-    newsession(const string& ca, const string& cert, const string& key) : ca(ca), cert(cert), key(key) {
-    }
-
-    const gc_ptr<http::CURLSession> operator()() const {
-        return new (gc_new<http::CURLSession>()) http::CURLSession(ca, cert, key, "", 0);
-    }
-
-private:
-    const string ca;
-    const string cert;
-    const string key;
-};
-
-/**
  * Child process initialization.
  */
-void childInit(apr_pool_t* p, server_rec* s) {
-    gc_scoped_pool pool(p);
+void childInit(apr_pool_t* const p, server_rec* const s) {
+    const gc_scoped_pool sp(p);
 
-    ServerConf* psc = (ServerConf*)ap_get_module_config(s->module_config, &mod_tuscany_oauth2);
+    ServerConf* const psc = (ServerConf*)ap_get_module_config(s->module_config, &mod_tuscany_oauth2);
     if(psc == NULL) {
         cfailure << "[Tuscany] Due to one or more errors mod_tuscany_oauth2 loading failed. Causing apache to stop loading." << endl;
         exit(APEXIT_CHILDFATAL);
@@ -447,13 +424,21 @@ void childInit(apr_pool_t* p, server_rec
     ServerConf& sc = *psc;
 
     // Connect to Memcached
-    if (isNil(sc.mcaddrs))
+    if (isNil((list<string>)sc.mcaddrs))
         sc.mc = *(new (gc_new<memcache::MemCached>()) memcache::MemCached("localhost", 11211));
     else
         sc.mc = *(new (gc_new<memcache::MemCached>()) memcache::MemCached(sc.mcaddrs));
 
     // Setup a CURL session
-    sc.cs = perthread_ptr<http::CURLSession>(lambda<gc_ptr<http::CURLSession>()>(newsession(sc.ca, sc.cert, sc.key)));
+    const string ca = sc.ca;
+    const string cert = sc.cert;
+    const string key = sc.key;
+    const gc_pool cp = gc_current_pool();
+    const lambda<const gc_ptr<http::CURLSession>()> newsession = [ca, cert, key, cp]() -> const gc_ptr<http::CURLSession> {
+        const gc_scoped_pool sp(pool(cp));
+        return new (gc_new<http::CURLSession>()) http::CURLSession(ca, cert, key, emptyString, 0);
+    };
+    sc.cs = *(new (gc_new<perthread_ptr<http::CURLSession> >()) perthread_ptr<http::CURLSession>(newsession));
 
     // Merge the updated configuration into the virtual hosts
     postConfigMerge(sc, s->next);
@@ -462,56 +447,56 @@ void childInit(apr_pool_t* p, server_rec
 /**
  * Configuration commands.
  */
-const char* confAppKey(cmd_parms *cmd, unused void *c, const char *arg1, const char* arg2, const char* arg3) {
-    gc_scoped_pool pool(cmd->pool);
+char* confAppKey(cmd_parms *cmd, unused void *c, char *arg1, char* arg2, char* arg3) {
+    const gc_scoped_pool sp(cmd->pool);
     ServerConf& sc = httpd::serverConf<ServerConf>(cmd, &mod_tuscany_oauth2);
-    sc.appkeys = cons<list<value> >(mklist<value>(arg1, mklist<value>(arg2, arg3)), sc.appkeys);
+    sc.appkeys = cons<list<value> >(mklist<value>(arg1, mklist<value>(arg2, arg3)), (list<list<value> >)sc.appkeys);
     return NULL;
 }
-const char* confMemcached(cmd_parms *cmd, unused void *c, const char *arg) {
-    gc_scoped_pool pool(cmd->pool);
+char* confMemcached(cmd_parms *cmd, unused void *c, char *arg) {
+    const gc_scoped_pool sp(cmd->pool);
     ServerConf& sc = httpd::serverConf<ServerConf>(cmd, &mod_tuscany_oauth2);
-    sc.mcaddrs = cons<string>(arg, sc.mcaddrs);
+    sc.mcaddrs = cons<string>(arg, (list<string>)sc.mcaddrs);
     return NULL;
 }
-const char* confEnabled(cmd_parms *cmd, void *c, const int arg) {
-    gc_scoped_pool pool(cmd->pool);
+char* confEnabled(cmd_parms *cmd, void *c, int arg) {
+    const gc_scoped_pool sp(cmd->pool);
     DirConf& dc = httpd::dirConf<DirConf>(c);
     dc.enabled = (bool)arg;
     return NULL;
 }
-const char* confLogin(cmd_parms *cmd, void *c, const char* arg) {
-    gc_scoped_pool pool(cmd->pool);
+char* confLogin(cmd_parms *cmd, void *c, char* arg) {
+    const gc_scoped_pool sp(cmd->pool);
     DirConf& dc = httpd::dirConf<DirConf>(c);
     dc.login = arg;
     return NULL;
 }
-const char* confCAFile(cmd_parms *cmd, unused void *c, const char *arg) {
-    gc_scoped_pool pool(cmd->pool);
+char* confCAFile(cmd_parms *cmd, unused void *c, char *arg) {
+    const gc_scoped_pool sp(cmd->pool);
     ServerConf& sc = httpd::serverConf<ServerConf>(cmd, &mod_tuscany_oauth2);
     sc.ca = arg;
     return NULL;
 }
-const char* confCertFile(cmd_parms *cmd, unused void *c, const char *arg) {
-    gc_scoped_pool pool(cmd->pool);
+char* confCertFile(cmd_parms *cmd, unused void *c, char *arg) {
+    const gc_scoped_pool sp(cmd->pool);
     ServerConf& sc = httpd::serverConf<ServerConf>(cmd, &mod_tuscany_oauth2);
     sc.cert = arg;
     return NULL;
 }
-const char* confCertKeyFile(cmd_parms *cmd, unused void *c, const char *arg) {
-    gc_scoped_pool pool(cmd->pool);
+char* confCertKeyFile(cmd_parms *cmd, unused void *c, char *arg) {
+    const gc_scoped_pool sp(cmd->pool);
     ServerConf& sc = httpd::serverConf<ServerConf>(cmd, &mod_tuscany_oauth2);
     sc.key = arg;
     return NULL;
 }
-const char* confScopeAttr(cmd_parms *cmd, void* c, const char* arg1, const char* arg2) {
-    gc_scoped_pool pool(cmd->pool);
+char* confScopeAttr(cmd_parms *cmd, void* c, char* arg1, char* arg2) {
+    const gc_scoped_pool sp(cmd->pool);
     DirConf& dc = httpd::dirConf<DirConf>(c);
-    dc.scopeattrs = cons<list<value> >(mklist<value>(arg1, arg2), dc.scopeattrs);
+    dc.scopeattrs = cons<list<value> >(mklist<value>(arg1, arg2), (list<list<value> >)dc.scopeattrs);
     return NULL;
 }
-const char* confAuthnProvider(cmd_parms *cmd, void *c, const char* arg) {
-    gc_scoped_pool pool(cmd->pool);
+char* confAuthnProvider(cmd_parms *cmd, void *c, char* arg) {
+    const gc_scoped_pool sp(cmd->pool);
     DirConf& dc = httpd::dirConf<DirConf>(c);
 
     // Lookup and cache the Authn provider

Modified: tuscany/sca-cpp/trunk/modules/opencl/Makefile.am
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/opencl/Makefile.am?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/opencl/Makefile.am (original)
+++ tuscany/sca-cpp/trunk/modules/opencl/Makefile.am Tue Dec 11 04:03:29 2012
@@ -36,7 +36,7 @@ endif
 
 #mod_LTLIBRARIES = libmod_tuscany_opencl.la
 #libmod_tuscany_opencl_la_SOURCES = mod-opencl.cpp
-#libmod_tuscany_opencl_la_LDFLAGS = -lxml2 -lcurl -lmozjs -framework OpenCL
+#libmod_tuscany_opencl_la_LDFLAGS = -lxml2 -lcurl -ljansson -framework OpenCL
 #noinst_DATA = libmod_tuscany_opencl${libsuffix}
 #libmod_tuscany_opencl${libsuffix}:
 #	ln -s .libs/libmod_tuscany_opencl${libsuffix}
@@ -48,7 +48,7 @@ opencl_shell_SOURCES = opencl-shell.cpp
 opencl_shell_LDFLAGS = ${OPENCL_FLAGS}
 
 client_test_SOURCES = client-test.cpp
-client_test_LDFLAGS = -lxml2 -lcurl -lmozjs
+client_test_LDFLAGS = -lxml2 -lcurl -ljansson
 
 dist_noinst_SCRIPTS = server-test
 noinst_PROGRAMS = opencl-test client-test

Modified: tuscany/sca-cpp/trunk/modules/opencl/driver.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/opencl/driver.hpp?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/opencl/driver.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/opencl/driver.hpp Tue Dec 11 04:03:29 2012
@@ -37,7 +37,7 @@ namespace opencl {
 
 const value evalDriverLoop(const OpenCLProgram& clprog, istream& in, ostream& out, const OpenCLContext& cl) {
     scheme::promptForInput(scheme::evalInputPrompt, out);
-    value input = scheme::readValue(in);
+    const value input = content(scheme::readValue(in));
     if (isNil(input))
         return input;
     const failable<value> output = evalKernel(createKernel(input, clprog), input, 1, value::String, 512, cl);

Modified: tuscany/sca-cpp/trunk/modules/opencl/eval.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/opencl/eval.hpp?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/opencl/eval.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/opencl/eval.hpp Tue Dec 11 04:03:29 2012
@@ -61,7 +61,7 @@ cl_ulong evaltime = 0;
 /**
  * Reset the OpenCL profiling counters.
  */
-bool resetOpenCLCounters() {
+const bool resetOpenCLCounters() {
     memtime = kernelqtime = kerneltime = preptime = evaltime = 0;
     return true;
 }
@@ -69,7 +69,7 @@ bool resetOpenCLCounters() {
 /**
  * Print the OpenCL profiling counters.
  */
-bool printOpenCLCounters(const long n) {
+const bool printOpenCLCounters(const long n) {
     cout << " kernelq " << ((double)kernelqtime / 1000000.0) / (double)n << " ms kernel " << ((double)kerneltime / 1000000.0) / (double)n << " ms memory " << ((double)memtime / 1000000.0) / (double)n << " ms prep " << ((double)preptime / 1000000.0) / (double)n << " ms eval " << ((double)evaltime / 1000000.0) / (double)n << " ms";
     return true;
 }
@@ -77,7 +77,7 @@ bool printOpenCLCounters(const long n) {
 /**
  * Profile a memory event.
  */
-failable<cl_ulong> profileMemEvent(const cl_event evt) {
+const failable<cl_ulong> profileMemEvent(const cl_event evt) {
     cl_ulong start = 0;
     const cl_int serr = clGetEventProfilingInfo(evt, CL_PROFILING_COMMAND_START, sizeof(cl_ulong), &start, NULL);
     if (serr != CL_SUCCESS)
@@ -94,7 +94,7 @@ failable<cl_ulong> profileMemEvent(const
 /**
  * Profile a kernel event.
  */
-failable<cl_ulong> profileKernelEvent(const cl_event evt) {
+const failable<cl_ulong> profileKernelEvent(const cl_event evt) {
     cl_ulong queued = 0;
     const cl_int qerr = clGetEventProfilingInfo(evt, CL_PROFILING_COMMAND_QUEUED, sizeof(cl_ulong), &queued, NULL);
     if (qerr != CL_SUCCESS)
@@ -117,7 +117,7 @@ failable<cl_ulong> profileKernelEvent(co
 /**
  * Profile an array of memory events.
  */
-failable<cl_ulong> profileMemEvents(const cl_uint n, const cl_event* evt) {
+const failable<cl_ulong> profileMemEvents(const cl_uint n, const cl_event* const evt) {
     if (n == 0)
         return 0;
     const failable<cl_ulong> t = profileMemEvent(*evt);
@@ -221,6 +221,21 @@ public:
         }
     }
 
+    OpenCLContext(const OpenCLContext& c) : dev(c.dev), ndevs(c.ndevs), ctx(c.ctx) {
+        for (cl_uint i = 0; i < ndevs; i++) {
+            devid[i] = c.devid[i];
+            cq[i] = c.cq[i];
+            if (cq[i] != 0) {
+                const cl_int rcqerr = clRetainCommandQueue(cq[i]);
+                if (rcqerr != CL_SUCCESS)
+                    mkfailure<bool>(string("Couldn't retain OpenCL command queue: ") + clError(rcqerr));
+            }
+        }
+        const cl_int rcerr = clRetainContext(ctx);
+        if (rcerr != CL_SUCCESS)
+            mkfailure<bool>(string("Couldn't retain OpenCL context: ") + clError(rcerr));
+    }
+
     ~OpenCLContext() {
         for (cl_uint i = 0; i < ndevs; i++) {
             if (cq[i] != 0)
@@ -372,7 +387,7 @@ private:
 /**
  * Return a read-only memory buffer.
  */
-const failable<OpenCLBuffer> readOnlyBuffer(const size_t size, const void* p, const OpenCLContext& cl, const cl_command_queue cq) {
+const failable<OpenCLBuffer> readOnlyBuffer(const size_t size, const void* const p, const OpenCLContext& cl, const cl_command_queue cq) {
     if (cl.dev == OpenCLContext::CPU) {
         cl_int err;
         const cl_mem buf = clCreateBuffer(cl.ctx, CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR, size, const_cast<void*>(p), &err);
@@ -396,7 +411,7 @@ const failable<OpenCLBuffer> readOnlyBuf
 /**
  * Fill an array of write events for a given list of buffers.
  */
-const cl_uint writeBufferEvents(const list<OpenCLBuffer>& buf, cl_event* evt) {
+const cl_uint writeBufferEvents(const list<OpenCLBuffer>& buf, cl_event* const evt) {
     if (isNil(buf))
         return 0;
     const cl_event e = car(buf).evt;
@@ -427,7 +442,7 @@ const failable<OpenCLBuffer> writeOnlyBu
 /**
  * Convert a value to a kernel arg.
  */
-const failable<OpenCLBuffer> valueToKernelArg(const cl_uint i, const size_t size, const void* p, const failable<OpenCLBuffer>& buf, const OpenCLKernel& kernel) {
+const failable<OpenCLBuffer> valueToKernelArg(const cl_uint i, const size_t size, const void* const p, const failable<OpenCLBuffer>& buf, const OpenCLKernel& kernel) {
     if (!hasContent(buf))
         return buf;
     if (p != NULL) {
@@ -446,7 +461,7 @@ const failable<OpenCLBuffer> valueToKern
 const failable<OpenCLBuffer> valueToKernelArg(const value& v, const cl_uint i, const OpenCLKernel& kernel, const OpenCLContext& cl, const cl_command_queue cq) {
     switch (type(v)) {
     case value::Symbol: {
-        const string s = string("'") + v;
+        const string s = string("'") + (string)v;
         return valueToKernelArg(i, 0, NULL, readOnlyBuffer(length(s) + 1, c_str(s), cl, cq), kernel);
     }
     case value::String: {
@@ -489,28 +504,28 @@ const failable<list<OpenCLBuffer>> value
 /**
  * Convert a kernel result to a value.
  */
-const value kernelResultToValue(const void* p, const value::ValueType type) {
+const value kernelResultToValue(const void* const p, const value::ValueType type) {
     switch(type) {
     case value::Symbol: {
-        const char* s = static_cast<const char*>(p);
+        const char* const s = (const char*)p;
         const size_t l = strlen(s);
         if (l != 0 && *s == '\'')
             return value(s + 1);
         return value(s);
     }
     case value::String: {
-        const char* s = static_cast<const char*>(p);
+        const char* const s = (const char*)p;
         const size_t l = strlen(s);
         if (l != 0 && *s == '\'')
             return value(s + 1);
         return value(string(s, l));
     }
     case value::Number:
-        return (double)(*(static_cast<const cl_float*>(p)));
+        return (double)(*(const cl_float*)p);
     case value::Bool:
-        return (bool)(*(static_cast<const cl_int*>(p)));
+        return (bool)(*(const cl_int*)p);
     default:
-        return *(static_cast<const value*>(p));
+        return *(const value*)p;
     }
 }
 
@@ -582,9 +597,9 @@ const failable<OpenCLKernel> createKerne
 
         // The start, stop, and restart functions are optional
         //if (fn == "start" || fn == "stop")
-            //return value(lambda<value(const list<value>&)>());
+            //return value(lvvlambda());
 
-        return mkfailure<OpenCLKernel>(string("Couldn't find function: ") + car<value>(expr) + " : " + clError(ckerr));
+        return mkfailure<OpenCLKernel>(string("Couldn't find function: ") + (string)car<value>(expr) + " : " + clError(ckerr));
     }
     return OpenCLKernel(k);
 }

Modified: tuscany/sca-cpp/trunk/modules/opencl/opencl-shell.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/opencl/opencl-shell.cpp?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/opencl/opencl-shell.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/opencl/opencl-shell.cpp Tue Dec 11 04:03:29 2012
@@ -29,8 +29,8 @@
 #include "string.hpp"
 #include "driver.hpp"
 
-int main(const int argc, char** argv) {
-    tuscany::gc_scoped_pool pool;
+int main(const int argc, char** const argv) {
+    const tuscany::gc_scoped_pool pool;
     if (argc != 2) {
         tuscany::cerr << "Usage: opencl-shell <kernel.cl>" << tuscany::endl;
         return 1;

Modified: tuscany/sca-cpp/trunk/modules/opencl/opencl-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/opencl/opencl-test.cpp?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/opencl/opencl-test.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/opencl/opencl-test.cpp Tue Dec 11 04:03:29 2012
@@ -159,8 +159,8 @@ const string testCharsParallelGPU =
         "    r[i] = i < ixl? x[i] : i < ixl + iyl? y[i - ixl] : '\\0';\n"
         "}\n";
 
-bool testTaskParallel(const OpenCLContext::DeviceType dev) {
-    gc_scoped_pool pool;
+const bool testTaskParallel(const OpenCLContext::DeviceType dev) {
+    const gc_scoped_pool pool;
     OpenCLContext cl(dev);
     if (!devices(cl) != 0)
         return true;
@@ -192,12 +192,12 @@ bool testTaskParallel(const OpenCLContex
         const value exp = mklist<value>("int_or", true, false);
         const failable<value> r = evalKernel(createKernel(exp, content(clprog)), exp, cl);
         assert(hasContent(r));
-        assert(content(r) == value(true));
+        assert(content(r) == trueValue);
 
         const value exp2 = mklist<value>("int_or", false, false);
         const failable<value> r2 = evalKernel(createKernel(exp2, content(clprog)), exp2, cl);
         assert(hasContent(r2));
-        assert(content(r2) == value(false));
+        assert(content(r2) == falseValue);
     }
     {
         istringstream is(dev == OpenCLContext::CPU? testCharsCPU : testCharsGPU);
@@ -223,41 +223,33 @@ bool testTaskParallel(const OpenCLContex
     return true;
 }
 
-struct evalTaskParallelLoop {
-    evalTaskParallelLoop(const OpenCLContext& cl, const OpenCLProgram& clprog) : cl(cl), clprog(clprog), exp(mklist<value>("add", 60, string("Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello "), 60, string("World World World World World World World World World World "))) {
-    }
-    const bool operator()() const {
-        const failable<value> r = evalKernel(createKernel(exp, clprog), exp, 1, value::String, 128, cl);
-        assert(hasContent(r));
-        assert(content(r) == value(string("Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello World World World World World World World World World World ")));
-        return true;
-    }
-
-    const OpenCLContext& cl;
-    const OpenCLProgram& clprog;
-    const value exp;
-};
-
 const bool testTaskParallelPerf(const OpenCLContext::DeviceType dev, const bool copy) {
-    gc_scoped_pool pool;
+    const gc_scoped_pool pool;
     OpenCLContext cl(dev);
     if (!devices(cl) != 0)
         return true;
 
     istringstream is(dev == OpenCLContext::CPU? testCharsCPU : copy? testCharsCopyGPU : testCharsGPU);
-    failable<OpenCLProgram> clprog = readProgram("kernel.cl", is, cl);
-    assert(hasContent(clprog));
+    failable<OpenCLProgram> fclprog = readProgram("kernel.cl", is, cl);
+    assert(hasContent(fclprog));
 
     resetOpenCLCounters();
-    const lambda<bool()> el = evalTaskParallelLoop(cl, content(clprog));
+    OpenCLProgram clprog = content(fclprog);
+    const value exp = mklist<value>("add", 60, string("Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello "), 60, string("World World World World World World World World World World "));
+    const blambda el = [cl, clprog, exp]() -> const bool {
+        const failable<value> r = evalKernel(createKernel(exp, clprog), exp, 1, value::String, 128, cl);
+        assert(hasContent(r));
+        assert(content(r) == value(string("Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello World World World World World World World World World World ")));
+        return true;
+    };
     cout << "OpenCL task-parallel eval " << (dev == OpenCLContext::CPU? "CPU" : "GPU") << (copy? " copy" : "") << " test " << time(el, 5, 500) << " ms";
     printOpenCLCounters(500);
     cout << endl;
     return true;
 }
 
-bool testDataParallel(const OpenCLContext::DeviceType dev) {
-    gc_scoped_pool pool;
+const bool testDataParallel(const OpenCLContext::DeviceType dev) {
+    const gc_scoped_pool pool;
     OpenCLContext cl(dev);
     if (!devices(cl) != 0)
         return true;
@@ -276,33 +268,25 @@ bool testDataParallel(const OpenCLContex
     return true;
 }
 
-struct evalDataParallelLoop {
-    evalDataParallelLoop(const OpenCLContext& cl, const OpenCLProgram& clprog) : cl(cl), clprog(clprog), exp(mklist<value>("add", 60, string("Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello "), 60, string("World World World World World World World World World World "))) {
-    }
-    const bool operator()() const {
-        const failable<value> r = evalKernel(createKernel(exp, clprog), exp, 121, value::String, 128, cl);
-        assert(hasContent(r));
-        assert(content(r) == value(string("Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello World World World World World World World World World World ")));
-        return true;
-    }
-
-    const OpenCLContext& cl;
-    const OpenCLProgram& clprog;
-    const value exp;
-};
-
 const bool testDataParallelPerf(const OpenCLContext::DeviceType dev, const bool copy) {
-    gc_scoped_pool pool;
+    const gc_scoped_pool pool;
     OpenCLContext cl(dev);
     if (!devices(cl) != 0)
         return true;
 
     istringstream is(dev == OpenCLContext::CPU? testCharsParallelCPU : copy? testCharsParallelCopyGPU : testCharsParallelGPU);
-    failable<OpenCLProgram> clprog = readProgram("kernel.cl", is, cl);
-    assert(hasContent(clprog));
+    failable<OpenCLProgram> fclprog = readProgram("kernel.cl", is, cl);
+    assert(hasContent(fclprog));
 
     resetOpenCLCounters();
-    const lambda<bool()> el = evalDataParallelLoop(cl, content(clprog));
+    OpenCLProgram clprog = content(fclprog);
+    const value exp = mklist<value>("add", 60, string("Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello "), 60, string("World World World World World World World World World World "));
+    const blambda el = [cl, clprog, exp]() -> const bool {
+        const failable<value> r = evalKernel(createKernel(exp, clprog), exp, 121, value::String, 128, cl);
+        assert(hasContent(r));
+        assert(content(r) == value(string("Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello World World World World World World World World World World ")));
+        return true;
+    };
     cout << "OpenCL data-parallel eval " << (dev == OpenCLContext::CPU? "CPU" : "GPU") << (copy? " copy" : "") << " test " << time(el, 5, 500) << " ms";
     printOpenCLCounters(500);
     cout << endl;

Modified: tuscany/sca-cpp/trunk/modules/python/Makefile.am
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/python/Makefile.am?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/python/Makefile.am (original)
+++ tuscany/sca-cpp/trunk/modules/python/Makefile.am Tue Dec 11 04:03:29 2012
@@ -35,7 +35,7 @@ EXTRA_DIST = domain-test.composite clien
 
 mod_LTLIBRARIES = libmod_tuscany_python.la
 libmod_tuscany_python_la_SOURCES = mod-python.cpp
-libmod_tuscany_python_la_LDFLAGS = -lxml2 -lcurl -lmozjs -L${PYTHON_LIB} -R${PYTHON_LIB} -lpython${PYTHON_VERSION}
+libmod_tuscany_python_la_LDFLAGS = -lxml2 -lcurl -ljansson -L${PYTHON_LIB} -R${PYTHON_LIB} -lpython${PYTHON_VERSION}
 noinst_DATA = libmod_tuscany_python${libsuffix}
 libmod_tuscany_python${libsuffix}:
 	ln -s .libs/libmod_tuscany_python${libsuffix}
@@ -47,7 +47,7 @@ python_shell_SOURCES = python-shell.cpp
 python_shell_LDFLAGS = -L${PYTHON_LIB} -R${PYTHON_LIB} -lpython${PYTHON_VERSION}
 
 client_test_SOURCES = client-test.cpp
-client_test_LDFLAGS = -lxml2 -lcurl -lmozjs
+client_test_LDFLAGS = -lxml2 -lcurl -ljansson
 
 dist_noinst_SCRIPTS = server-test wiring-test
 noinst_PROGRAMS = python-test client-test

Modified: tuscany/sca-cpp/trunk/modules/python/driver.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/python/driver.hpp?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/python/driver.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/python/driver.hpp Tue Dec 11 04:03:29 2012
@@ -35,9 +35,9 @@
 namespace tuscany {
 namespace python {
 
-const value evalDriverLoop(PyObject* script, istream& in, ostream& out, PythonRuntime& py) {
+const value evalDriverLoop(PyObject* const script, istream& in, ostream& out, PythonRuntime& py) {
     scheme::promptForInput(scheme::evalInputPrompt, out);
-    value input = scheme::readValue(in);
+    const value input = content(scheme::readValue(in));
     if (isNil(input))
         return input;
     const failable<value> output = evalScript(input, script, py);
@@ -46,11 +46,11 @@ const value evalDriverLoop(PyObject* scr
     return evalDriverLoop(script, in, out, py);
 }
 
-const bool evalDriverRun(const char* path, istream& in, ostream& out) {
+const bool evalDriverRun(const char* const path, istream& in, ostream& out) {
     PythonRuntime py;
     scheme::setupDisplay(out);
     ifstream is(path);
-    failable<PyObject*> script = readScript(moduleName(path), path, is, py);
+    const failable<PyObject*> script = readScript(moduleName(path), path, is, py);
     if (!hasContent(script))
         return true;
     evalDriverLoop(content(script), in, out, py);

Modified: tuscany/sca-cpp/trunk/modules/python/eval.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/python/eval.hpp?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/python/eval.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/python/eval.hpp Tue Dec 11 04:03:29 2012
@@ -53,8 +53,8 @@ class PythonRuntime;
 /**
  * Maintain a garbage collected reference to a Python object.
  */
-const bool pyIncRef(PyObject* o);
-const bool pyDecRef(PyObject* o, PythonRuntime* py);
+const bool pyIncRef(PyObject* const o);
+const bool pyDecRef(PyObject* const o, PythonRuntime* const py);
 
 /**
  * Write to debug log from Python.
@@ -70,7 +70,7 @@ const value pyDebug(const list<value>& a
 
 class PythonRuntime {
 public:
-    PythonRuntime() {
+    PythonRuntime() : owner(true) {
         debug("python::pythonruntime");
 
         // Save current process id
@@ -115,7 +115,7 @@ public:
         PySys_SetArgv(0, const_cast<char**>(&arg0));
 
         // Install debug log function
-        PyObject* mkPyLambda(const lambda<value(const list<value>&)>& l, PythonRuntime* py);
+        PyObject* mkPyLambda(const lvvlambda& l, PythonRuntime* py);
         PyObject* pyd= mkPyLambda(pyDebug, this);
         PyObject* sys = PyImport_ImportModule("sys");
         PyObject_SetAttrString(sys, "debug", pyd);
@@ -127,10 +127,21 @@ public:
 #endif
     }
 
+#ifdef WANT_THREADS
+    PythonRuntime(const PythonRuntime& py) : owner(false), mutex(py.mutex), pidmutex(py.pidmutex), pid(py.pid) {
+    }
+#else
+    PythonRuntime(const PythonRuntime& py) : owner(false), pid(py.pid) {
+    }
+#endif
+
+    PythonRuntime& operator=(const PythonRuntime& py) = delete;
+
     ~PythonRuntime() {
     }
 
 private:
+    const bool owner;
 #ifdef WANT_THREADS
     pthread_mutex_t mutex;
     pthread_mutex_t pidmutex;
@@ -145,9 +156,9 @@ private:
 /**
  * Return the last python error.
  */
-const string lastErrorTrace(PyObject *trace) {
+const string lastErrorTrace(PyObject* const trace) {
     if (trace == NULL)
-        return "";
+        return emptyString;
     PyTracebackObject* tb = (PyTracebackObject*)trace;
     const int limit = 16;
     int depth = 0;
@@ -167,16 +178,16 @@ const string lastErrorTrace(PyObject *tr
     return str(os);
 }
 
-const string lastError(PythonRuntime* py) {
+const string lastError(PythonRuntime* const py) {
     if(PyErr_Occurred()) {
         PyObject* type = NULL;
         PyObject* val = NULL;
         PyObject* trace = NULL;
         PyErr_Fetch(&type, &val, &trace);
         if (type != NULL && val != NULL) {
-            PyObject* stype = PyObject_Repr(type);    
-            PyObject* sval = PyObject_Repr(val);    
-            string msg = string() + PyString_AsString(stype) + " : " + PyString_AsString(sval) + lastErrorTrace(trace);
+            PyObject* const stype = PyObject_Repr(type);    
+            PyObject* const sval = PyObject_Repr(val);    
+            const string msg = string() + PyString_AsString(stype) + " : " + PyString_AsString(sval) + lastErrorTrace(trace);
             pyDecRef(stype, py);
             pyDecRef(sval, py);
             PyErr_Restore(type, val, trace);
@@ -187,7 +198,7 @@ const string lastError(PythonRuntime* py
         PyErr_Clear();
         return "Unknown Python error";
     }
-    return "";
+    return emptyString;
 }
 
 /**
@@ -195,7 +206,7 @@ const string lastError(PythonRuntime* py
  */
 class PythonRuntimeLock {
 public:
-    PythonRuntimeLock(PythonRuntime* py) : py(py) {
+    PythonRuntimeLock(PythonRuntime* const py) : py(py) {
 #ifdef WANT_THREADS
         pthread_mutex_lock(&py->mutex);
 #endif
@@ -208,7 +219,7 @@ public:
     }
 
 private:
-    PythonRuntime* py;
+    PythonRuntime* const py;
 };
 
 /**
@@ -216,7 +227,7 @@ private:
  */
 class PythonThreadIn {
 public:
-    PythonThreadIn(PythonRuntime* py) : py(py) {
+    PythonThreadIn(PythonRuntime* const py) : py(py) {
 
         // Reinitialize Python thread support after a fork
         const unsigned long pid = processId();
@@ -261,7 +272,7 @@ public:
     }
 
 private:
-    PythonRuntime* py;
+    PythonRuntime* const py;
 #ifdef WANT_THREADS
     PyGILState_STATE gstate;
 #endif
@@ -272,7 +283,7 @@ private:
  */
 class PythonThreadOut {
 public:
-    PythonThreadOut(PythonRuntime* py) : py(py) {
+    PythonThreadOut(PythonRuntime* const py) : py(py) {
 #ifdef WANT_THREADS
         //debug("python::gil::save");
         tstate = PyEval_SaveThread();
@@ -289,7 +300,7 @@ public:
     }
 
 private:
-    PythonRuntime* py;
+    PythonRuntime* const py;
 #ifdef WANT_THREADS
     PyThreadState* tstate;
 #endif
@@ -300,7 +311,7 @@ private:
  */
 class PyGCRef {
 public:
-    PyGCRef(PyObject* o, PythonRuntime* py) : o(o), py(py) {
+    PyGCRef(PyObject* const o, PythonRuntime* const py) : o(o), py(py) {
     }
 
     ~PyGCRef() {
@@ -311,21 +322,21 @@ public:
     }
 
 private:
-    PyObject* o;
-    PythonRuntime* py;
+    PyObject* const o;
+    PythonRuntime* const py;
 };
 
 /**
  * Maintain a garbage collected reference to a Python object.
  */
-const bool pyIncRef(PyObject* o) {
+const bool pyIncRef(PyObject* const o) {
     if (o == NULL)
         return true;
     Py_INCREF(o);
     return true;
 }
 
-const bool pyDecRef(unused PyObject* o, unused PythonRuntime* py) {
+const bool pyDecRef(unused PyObject* const o, unused PythonRuntime* const py) {
     if (o == NULL)
         return true;
     //new (gc_new<PyGCRef>()) PyGCRef(o, py);
@@ -336,40 +347,40 @@ const bool pyDecRef(unused PyObject* o, 
 /**
  * Declare conversion functions.
  */
-PyObject* valueToPyObject(const value& v, PythonRuntime* py);
-const value pyObjectToValue(PyObject *o, PythonRuntime* py);
-PyObject* valuesToPyTuple(const list<value>& v, PythonRuntime* py);
-const list<value> pyTupleToValues(PyObject* o, PythonRuntime* py);
+PyObject* const valueToPyObject(const value& v, PythonRuntime* const py);
+const value pyObjectToValue(PyObject* const o, PythonRuntime* const py);
+PyObject* const valuesToPyTuple(const list<value>& v, PythonRuntime* const py);
+const list<value> pyTupleToValues(PyObject* const o, PythonRuntime* const py);
 
 /**
  * Callable python type used to represent a lambda expression.
  */
 typedef struct {
     PyObject_HEAD
-    lambda<value(const list<value>&)>* func;
+    lvvlambda* func;
     PythonRuntime* py;
 } pyLambda;
 
-PyObject *mkPyLambda(const lambda<value(const list<value>&)>& l, PythonRuntime* py);
+PyObject* const mkPyLambda(const lvvlambda& l, PythonRuntime* const py);
 
-void pyLambda_dealloc(PyObject* self) {
+void pyLambda_dealloc(PyObject* const self) {
     //debug(self, "python::pylambda_dealloc");
     PyObject_Del(self);
 }
 
-const string pyRepr(PyObject* o, PythonRuntime* py) {
-    PyObject* r = PyObject_Repr(o);
+const string pyRepr(PyObject* const o, PythonRuntime* const py) {
+    PyObject* const r = PyObject_Repr(o);
     const string s = PyString_AsString(r);
     pyDecRef(r, py);
     return s;
 }
 
-const value pyLambda_callout(const pyLambda* pyl, const list<value>& args, PythonRuntime* py) {
+const value pyLambda_callout(const pyLambda* const pyl, const list<value>& args, PythonRuntime* const py) {
     PythonThreadOut pyout(py);
     return (*(pyl->func))(args);
 }
 
-PyObject* pyLambda_call(PyObject* self, PyObject* args, unused PyObject* kwds) {
+PyObject* const pyLambda_call(PyObject* const self, PyObject* const args, unused PyObject* const kwds) {
     debug("python::call");
     const pyLambda* pyl = (const pyLambda*)self;
     const value result =  pyLambda_callout(pyl, pyTupleToValues(args, pyl->py), pyl->py);
@@ -378,22 +389,7 @@ PyObject* pyLambda_call(PyObject* self, 
     return pyr;
 }
 
-struct pyProxy {
-    const value name;
-    const lambda<value(const list<value>&)> func;
-
-    pyProxy(const value& name, const lambda<value(const list<value>&)>& func) : name(name), func(func) {
-    }
-
-    const value operator()(const list<value>& args) const {
-        debug(name, "python::proxy::name");
-        const value result = func(cons<value>(name, args));
-        debug(result, "python::proxy::result");
-        return result;
-    }
-};
-
-PyObject* pyLambda_getattr(PyObject *self, PyObject *attrname) {
+PyObject* const pyLambda_getattr(PyObject* const self, PyObject* const attrname) {
     const string name = PyString_AsString(attrname);
     if (substr(name, 0, 1) == "_")
         return PyObject_GenericGetAttr(self, attrname);
@@ -403,9 +399,18 @@ PyObject* pyLambda_getattr(PyObject *sel
         return self;
     }
 
-    const pyLambda* pyl = (pyLambda*)self;
+    const pyLambda* const pyl = (const pyLambda* const)self;
     debug(name, "python::getattr::name");
-    PyObject* pyr = mkPyLambda(pyProxy(name, *(pyl->func)), pyl->py);
+
+    const lvvlambda func = *(pyl->func);
+    const lvvlambda pyProxy = [name, func](const list<value>& args) -> const value {
+        debug(name, "python::proxy::name");
+        const value result = func(cons<value>(name, args));
+        debug(result, "python::proxy::result");
+        return result;
+    };
+
+    PyObject* const pyr = mkPyLambda(pyProxy, pyl->py);
     return pyr;
 }
 
@@ -464,10 +469,10 @@ PyObject* pyLambda_getattr(PyObject *sel
 /**
  * Create a new python object representing a lambda expression.
  */
-PyObject *mkPyLambda(const lambda<value(const list<value>&)>& l, PythonRuntime* py) {
-    pyLambda* pyl = PyObject_New(pyLambda, &pyLambda_type);
+PyObject* const mkPyLambda(const lvvlambda& l, PythonRuntime* const py) {
+    pyLambda* const pyl = PyObject_New(pyLambda, &pyLambda_type);
     if (pyl != NULL) {
-        pyl->func = new (gc_new<lambda<value(const list<value>&)> >()) lambda<value(const list<value>&)>(l);
+        pyl->func = new (gc_new<lvvlambda >()) lvvlambda(l);
         pyl->py = py;
     }
     //debug(pyl, "python::mkpylambda");
@@ -477,18 +482,18 @@ PyObject *mkPyLambda(const lambda<value(
 /**
  * Convert a list of values to a python list.
  */
-PyObject* valuesToPyListHelper(PyObject* l, const list<value>& v, PythonRuntime* py) {
+PyObject* const valuesToPyListHelper(PyObject* const l, const list<value>& v, PythonRuntime* const py) {
     if (isNil(v))
         return l;
-    PyObject* pyv = valueToPyObject(car(v), py);
+    PyObject* const pyv = valueToPyObject(car(v), py);
     PyList_Append(l, pyv);
     pyDecRef(pyv, py);
     return valuesToPyListHelper(l, cdr(v), py);
 }
 
-PyObject* valuesToPyTuple(const list<value>& v, PythonRuntime* py) {
-    PyObject* pyl = valuesToPyListHelper(PyList_New(0), v, py);
-    PyObject* pyt = PyList_AsTuple(pyl);
+PyObject* const valuesToPyTuple(const list<value>& v, PythonRuntime* const py) {
+    PyObject* const pyl = valuesToPyListHelper(PyList_New(0), v, py);
+    PyObject* const pyt = PyList_AsTuple(pyl);
     pyDecRef(pyl, py);
     return pyt;
 }
@@ -496,14 +501,14 @@ PyObject* valuesToPyTuple(const list<val
 /**
  * Convert a value to a python object.
  */
-PyObject* valueToPyObject(const value& v, PythonRuntime* py) {
+PyObject* const valueToPyObject(const value& v, PythonRuntime* const py) {
     switch (type(v)) {
     case value::List:
         return valuesToPyTuple(v, py);
     case value::Lambda:
         return mkPyLambda(v, py);
     case value::Symbol:
-        return PyString_FromString(c_str(string("'") + v));
+        return PyString_FromString(c_str(string("'") + (string)v));
     case value::String: {
         const string s = (string)v;
         return PyString_FromStringAndSize(c_str(s), length(s));
@@ -511,12 +516,12 @@ PyObject* valueToPyObject(const value& v
     case value::Number:
         return PyFloat_FromDouble((double)v);
     case value::Bool: {
-        PyObject* b = (bool)v? Py_True : Py_False;
+        PyObject* const b = (bool)v? Py_True : Py_False;
         pyIncRef(b);
         return b;
     }
     default: {
-        PyObject* n = Py_None;
+        PyObject* const n = Py_None;
         pyIncRef(n);
         return n;
     }
@@ -526,39 +531,29 @@ PyObject* valueToPyObject(const value& v
 /**
  * Convert a python tuple to a list of values.
  */
-const list<value> pyTupleToValuesHelper(PyObject* o, const size_t i, const size_t size, PythonRuntime* py) {
+const list<value> pyTupleToValuesHelper(PyObject* const o, const size_t i, const size_t size, PythonRuntime* const py) {
     if (i == size)
-        return list<value>();
+        return nilListValue;
     return cons(pyObjectToValue(PyTuple_GetItem(o, i), py), pyTupleToValuesHelper(o, i + 1, size, py));
 }
 
-const list<value> pyTupleToValues(PyObject* o, PythonRuntime* py) {
+const list<value> pyTupleToValues(PyObject* const o, PythonRuntime* const py) {
     return pyTupleToValuesHelper(o, 0, PyTuple_Size(o), py);
 }
 
 /**
  * Lambda function used to represent a python callable object.
  */
-struct pyCallable {
-    PyObject* func;
-    PythonRuntime* py;
-    bool owner;
-
-    pyCallable(PyObject* func, PythonRuntime* py) : func(func), py(py), owner(true) {
+class pyCallable {
+public:
+    pyCallable(PyObject* const func, PythonRuntime* const py) : func(func), py(py), owner(true) {
         pyIncRef(func);
     }
 
     pyCallable(const pyCallable& c) : func(c.func), py(c.py), owner(false) {
     }
 
-    const pyCallable& operator=(const pyCallable& c) {
-        if(this == &c)
-            return *this;
-        func = c.func;
-        py = c.py;
-        owner = false;
-        return *this;
-    }
+    pyCallable& operator=(const pyCallable& c) = delete;
 
     ~pyCallable() {
         if (!owner)
@@ -569,16 +564,16 @@ struct pyCallable {
     const value operator()(const list<value>& args) const {
         PythonThreadIn pyin(py);
         if (debug_islogging()) {
-            PyObject* rfunc = PyObject_Repr(func);
+            PyObject* const rfunc = PyObject_Repr(func);
             char* s = NULL;
             Py_ssize_t l = 0;
             PyString_AsStringAndSize(rfunc, &s, &l);
             debug(string(s, l), "python::operator()::func");
             pyDecRef(rfunc, py);
         }
-        PyObject* pyargs = valuesToPyTuple(args, py);
+        PyObject* const pyargs = valuesToPyTuple(args, py);
         if (debug_islogging()) {
-            PyObject* rargs = PyObject_Repr(pyargs);
+            PyObject* const rargs = PyObject_Repr(pyargs);
             char* s = NULL;
             Py_ssize_t l = 0;
             PyString_AsStringAndSize(rargs, &s, &l);
@@ -586,21 +581,26 @@ struct pyCallable {
             pyDecRef(rargs, py);
         }
 
-        PyObject* result = PyObject_CallObject(func, pyargs);
+        PyObject* const result = PyObject_CallObject(func, pyargs);
         pyDecRef(pyargs, py);
 
         const value v = pyObjectToValue(result, py);
         pyDecRef(result, py);
         return v;
     }
+
+private:
+    PyObject* const func;
+    PythonRuntime* const py;
+    const bool owner;
 };
 
 /**
  * Convert a python object to a value.
  */
-const value pyObjectToValue(PyObject *o, PythonRuntime* py) {
+const value pyObjectToValue(PyObject* const o, PythonRuntime* const py) {
     if (o == NULL)
-        return value();
+        return nilValue;
     if (PyString_Check(o)) {
         char* s = NULL;
         Py_ssize_t l = 0;
@@ -622,8 +622,8 @@ const value pyObjectToValue(PyObject *o,
     if (PyObject_TypeCheck(o, &pyLambda_type))
         return *(((pyLambda*)o)->func);
     if (PyCallable_Check(o))
-        return lambda<value(const list<value>&)>(pyCallable(o, py));
-    return value();
+        return lvvlambda(pyCallable(o, py));
+    return nilValue;
 }
 
 /**
@@ -636,37 +636,37 @@ const string moduleName(const string& pa
 /**
  * Evaluate an expression against a script provided as a python object.
  */
-const failable<value> evalScript(const value& expr, PyObject* script, PythonRuntime& py) {
+const failable<value> evalScript(const value& expr, PyObject* const script, PythonRuntime& py) {
     PythonThreadIn pyin(&py);
 
     // Get the requested function
-    PyObject* func = PyObject_GetAttrString(script, c_str(car<value>(expr)));
+    PyObject* const func = PyObject_GetAttrString(script, c_str(car<value>(expr)));
     if (func == NULL) {
 
         // The start, stop, and restart functions are optional
         const value fn = car<value>(expr);
         if (fn == "start" || fn == "stop") {
             PyErr_Clear();
-            return value(lambda<value(const list<value>&)>());
+            return value(lvvlambda());
         }
 
-        return mkfailure<value>(string("Couldn't find function: ") + car<value>(expr) + " : " + lastError(&py));
+        return mkfailure<value>(string("Couldn't find function: ") + (string)car<value>(expr) + " : " + lastError(&py));
     }
     if (!PyCallable_Check(func)) {
         pyDecRef(func, &py);
-        return mkfailure<value>(string("Couldn't find callable function: ") + car<value>(expr));
+        return mkfailure<value>(string("Couldn't find callable function: ") + (string)car<value>(expr));
     }
 
     // Convert args to python objects
-    PyObject* args = valuesToPyTuple(cdr<value>(expr), &py);
+    PyObject* const args = valuesToPyTuple(cdr<value>(expr), &py);
 
     // Call the function
-    PyObject* result = PyObject_CallObject(func, args);
+    PyObject* const result = PyObject_CallObject(func, args);
     if (result == NULL) {
         const string msg = lastError(&py);
         pyDecRef(func, &py);
         pyDecRef(args, &py);
-        return mkfailure<value>(string("Function call failed: ") + car<value>(expr) + " : " + msg);
+        return mkfailure<value>(string("Function call failed: ") + (string)car<value>(expr) + " : " + msg);
     }
     pyDecRef(func, &py);
     pyDecRef(args, &py);
@@ -684,8 +684,8 @@ const failable<PyObject*> readScript(con
     PythonThreadIn pyin(&py);
 
     // Lookup already loaded module
-    PyObject *mods = PyImport_GetModuleDict();
-    PyObject *emod = PyDict_GetItemString(mods, const_cast<char*>(c_str(name)));
+    PyObject* const mods = PyImport_GetModuleDict();
+    PyObject* const emod = PyDict_GetItemString(mods, const_cast<char*>(c_str(name)));
     if (emod != NULL)
         return emod;
 
@@ -695,10 +695,10 @@ const failable<PyObject*> readScript(con
     const list<string> ls = streamList(is);
     ostringstream os;
     write(ls, os);
-    PyObject* code = Py_CompileStringFlags(c_str(str(os)), c_str(path), Py_file_input, NULL);
+    PyObject* const code = Py_CompileStringFlags(c_str(str(os)), c_str(path), Py_file_input, NULL);
     if (code == NULL)
         return mkfailure<PyObject*>(string("Couldn't compile script: ") + path + " : " + lastError(&py));
-    PyObject* mod = PyImport_ExecCodeModuleEx(const_cast<char*>(c_str(name)), code, const_cast<char*>(c_str(path)));
+    PyObject* const mod = PyImport_ExecCodeModuleEx(const_cast<char*>(c_str(name)), code, const_cast<char*>(c_str(path)));
     if (mod == NULL) {
         const string msg = lastError(&py);
         pyDecRef(code, &py);
@@ -708,7 +708,7 @@ const failable<PyObject*> readScript(con
     pyDecRef(mod, &py);
 
     // Lookup the loaded module
-    PyObject *lmod = PyDict_GetItemString(mods, const_cast<char*>(c_str(name)));
+    PyObject* const lmod = PyDict_GetItemString(mods, const_cast<char*>(c_str(name)));
     if (lmod != NULL)
         return lmod;
 
@@ -718,7 +718,7 @@ const failable<PyObject*> readScript(con
 /**
  * Release a python script.
  */
-const failable<bool> releaseScript(unused PyObject* script, PythonRuntime& py) {
+const failable<bool> releaseScript(unused PyObject* const script, PythonRuntime& py) {
     PythonThreadIn pyin(&py);
     // No need to decref the script here, as it's referenced only once from sys.modules
     return true;

Modified: tuscany/sca-cpp/trunk/modules/python/mod-python.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/python/mod-python.cpp?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/python/mod-python.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/python/mod-python.cpp Tue Dec 11 04:03:29 2012
@@ -40,42 +40,35 @@ namespace modeval {
 /**
  * Apply a lifecycle start or restart event.
  */
-struct pythonLifecycle {
-    python::PythonRuntime& py;
-    pythonLifecycle(python::PythonRuntime& py) : py(py) {
-    }
-    const value operator()(const list<value>& params) const {
-        const value func = car(params);
-        if (func == "pythonRuntime")
-            return (gc_ptr<value>)(value*)&py;
-        return lambda<value(const list<value>&)>();
-    }
-};
-
 const value applyLifecycle(unused const list<value>& params) {
 
     // Create a Python runtime
     python::PythonRuntime& py = *(new (gc_new<python::PythonRuntime>()) python::PythonRuntime());
 
     // Return the function to invoke on subsequent events
-    return failable<value>(lambda<value(const list<value>&)>(pythonLifecycle(py)));
+    return failable<value>(lvvlambda([&py](const list<value>& params) -> const value {
+        const value func = car(params);
+        if (func == "pythonRuntime")
+            return (gc_ptr<value>)(value*)&py;
+        return lvvlambda();
+    }));
 }
 
 /**
  * Evaluate a Python component implementation and convert it to an applicable
  * lambda function.
  */
-const failable<lambda<value(const list<value>&)> > evalImplementation(const string& path, const value& impl, const list<value>& px, const lambda<value(const list<value>&)>& lifecycle) {
+const failable<lvvlambda > evalImplementation(const string& path, const value& impl, const list<value>& px, const lvvlambda& lifecycle) {
     const string itype(elementName(impl));
     if (contains(itype, ".python")) {
-        const value* p = (gc_ptr<value>)lifecycle(mklist<value>("pythonRuntime"));
+        const value* const p = (gc_ptr<value>)lifecycle(mklist<value>("pythonRuntime"));
         return modpython::evalImplementation(path, impl, px, *(python::PythonRuntime*)p);
     }
     if (contains(itype, ".cpp"))
         return modcpp::evalImplementation(path, impl, px);
     if (contains(itype, ".widget"))
-        return mkfailure<lambda<value(const list<value>&)> >(string("Unsupported implementation type: ") + itype, -1, false);
-    return mkfailure<lambda<value(const list<value>&)> >(string("Unsupported implementation type: ") + itype);
+        return mkfailure<lvvlambda >(string("Unsupported implementation type: ") + itype, -1, false);
+    return mkfailure<lvvlambda >(string("Unsupported implementation type: ") + itype);
 }
 
 }

Modified: tuscany/sca-cpp/trunk/modules/python/mod-python.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/python/mod-python.hpp?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/python/mod-python.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/python/mod-python.hpp Tue Dec 11 04:03:29 2012
@@ -40,38 +40,30 @@ namespace server {
 namespace modpython {
 
 /**
- * Apply a Python component implementation function.
- */
-struct applyImplementation {
-    PyObject* impl;
-    const list<value> px;
-    python::PythonRuntime& py;
-    applyImplementation(PyObject* impl, const list<value>& px, python::PythonRuntime& py) : impl(impl), px(px), py(py) {
-    }
-    const value operator()(const list<value>& params) const {
-        const value expr = append<value>(params, px);
-        debug(expr, "modeval::python::applyImplementation::input");
-        const failable<value> res = python::evalScript(expr, impl, py);
-        const value val = !hasContent(res)? mklist<value>(value(), reason(res), rcode(res)) : mklist<value>(content(res));
-        debug(val, "modeval::python::applyImplementation::result");
-        return val;
-    }
-};
-
-/**
  * Evaluate a Python component implementation and convert it to an applicable
  * lambda function.
  */
-const failable<lambda<value(const list<value>&)> > evalImplementation(const string& path, const value& impl, const list<value>& px, python::PythonRuntime& py) {
+const failable<lvvlambda > evalImplementation(const string& path, const value& impl, const list<value>& px, python::PythonRuntime& py) {
     const string spath(attributeValue("script", impl));
     const string fpath(path + spath);
     ifstream is(fpath);
     if (fail(is))
-        return mkfailure<lambda<value(const list<value>&)> >(string("Could not read implementation: ") + fpath);
-    const failable<PyObject*> script = python::readScript(python::moduleName(spath), fpath, is, py);
-    if (!hasContent(script))
-        return mkfailure<lambda<value(const list<value>&)> >(script);
-    return lambda<value(const list<value>&)>(applyImplementation(content(script), px, py));
+        return mkfailure<lvvlambda >(string("Could not read implementation: ") + fpath);
+    const failable<PyObject*> fscript = python::readScript(python::moduleName(spath), fpath, is, py);
+    if (!hasContent(fscript))
+        return mkfailure<lvvlambda >(fscript);
+    PyObject* const script = content(fscript);
+
+    const lvvlambda applyImplementation = [script, px, &py](const list<value>& params) -> const value {
+        // Apply a Python component implementation function
+        const value expr = append<value>(params, px);
+        debug(expr, "modeval::python::applyImplementation::input");
+        const failable<value> res = python::evalScript(expr, script, py);
+        const value val = !hasContent(res)? mklist<value>(nilValue, reason(res), rcode(res)) : mklist<value>(content(res));
+        debug(val, "modeval::python::applyImplementation::result");
+        return val;
+    };
+    return applyImplementation;
 }
 
 }

Modified: tuscany/sca-cpp/trunk/modules/python/python-shell.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/python/python-shell.cpp?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/python/python-shell.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/python/python-shell.cpp Tue Dec 11 04:03:29 2012
@@ -29,8 +29,8 @@
 #include "string.hpp"
 #include "driver.hpp"
 
-int main(const int argc, char** argv) {
-    tuscany::gc_scoped_pool pool;
+int main(const int argc, const char** const argv) {
+    const tuscany::gc_scoped_pool pool;
     if (argc != 2) {
         tuscany::cerr << "Usage: python-shell <script.py>" << tuscany::endl;
         return 1;

Modified: tuscany/sca-cpp/trunk/modules/python/python-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/python/python-test.cpp?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/python/python-test.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/python/python-test.cpp Tue Dec 11 04:03:29 2012
@@ -37,12 +37,12 @@ const string testPythonAdd =
         "def add(x, y):\n"
         "    return x + y\n";
 
-bool testEvalExpr() {
-    gc_scoped_pool pool;
+const bool testEvalExpr() {
+    const gc_scoped_pool pool;
     PythonRuntime py;
 
     istringstream is(testPythonAdd);
-    failable<PyObject*> script = readScript("script1", "script1.py", is, py);
+    const failable<PyObject*> script = readScript("script1", "script1.py", is, py);
     assert(hasContent(script));
 
     const value exp = mklist<value>("add", 2, 3);
@@ -58,12 +58,12 @@ const string testPythonMap =
         "def addmap(x, y):\n"
         "    return tuple(map(lambda i: i + y, x))\n";
 
-bool testEvalList() {
-    gc_scoped_pool pool;
+const bool testEvalList() {
+    const gc_scoped_pool pool;
     PythonRuntime py;
 
     istringstream is(testPythonMap);
-    failable<PyObject*> script = readScript("script2", "script2.py", is, py);
+    const failable<PyObject*> script = readScript("script2", "script2.py", is, py);
     assert(hasContent(script));
 
     const value exp = mklist<value>("addmap", mklist<value>(1, 2, 3), 1);
@@ -94,8 +94,8 @@ const string testCallLambda(
   "def testCallLambda(l, x, y):\n"
   "    return l(x, y)\n");
 
-bool testEvalLambda() {
-    gc_scoped_pool pool;
+const bool testEvalLambda() {
+    const gc_scoped_pool pool;
     PythonRuntime py;
 
     const value trl = mklist<value>("testReturnLambda");
@@ -104,7 +104,7 @@ bool testEvalLambda() {
 
     assert(hasContent(trlv));
     assert(isLambda(content(trlv)));
-    const lambda<value(const list<value>&)> trll(content(trlv));
+    const lvvlambda trll(content(trlv));
     assert(trll(mklist<value>(2, 3)) == value(6));
 
     istringstream tclis(testCallLambda);
@@ -114,20 +114,20 @@ bool testEvalLambda() {
     assert(content(tclv) == value(6));
 
     istringstream tcelis(testCallLambda);
-    const value tcel = mklist<value>("testCallLambda", lambda<value(const list<value>&)>(mult), 3, 4);
+    const value tcel = mklist<value>("testCallLambda", lvvlambda(mult), 3, 4);
     const failable<value> tcelv = evalScript(tcel, tcelis, py);
     assert(hasContent(tcelv));
     assert(content(tcelv) == value(12));
     return true;
 }
 
-struct testEvalReadAdd {
-    PythonRuntime& py;
-    testEvalReadAdd(PythonRuntime& py) : py(py) {
-    }
-    const bool operator()() const {
+const bool testEvalPerf() {
+    const gc_scoped_pool pool;
+    PythonRuntime py;
+
+    const blambda erl = [&py]() -> const bool {
         istringstream is(testPythonAdd);
-        failable<PyObject*> script = readScript("script3", "script3.py", is, py);
+        const failable<PyObject*> script = readScript("script3", "script3.py", is, py);
         assert(hasContent(script));
 
         const value exp = mklist<value>("add", 2, 3);
@@ -137,51 +137,36 @@ struct testEvalReadAdd {
 
         releaseScript(content(script), py);
         return true;
-    }
-};
+    };
+    cout << "Python read + eval test " << time(erl, 5, 10000) << " ms" << endl;
 
-struct testEvalAdd {
-    PyObject* script;
-    PythonRuntime& py;
-    testEvalAdd(PyObject* script, PythonRuntime& py) : script(script), py(py) {
-    }
-    const bool operator()() const {
+    istringstream is(testPythonAdd);
+    const failable<PyObject*> fscript = readScript("script4", "script4.py", is, py);
+    assert(hasContent(fscript));
+
+    PyObject* const script = content(fscript);
+    const blambda el = [script, &py]() -> const bool {
         const value exp = mklist<value>("add", 2, 3);
         const failable<value> r = evalScript(exp, script, py);
         assert(hasContent(r));
         assert(content(r) == value(5));
         return true;
-    }
-};
-
-bool testEvalPerf() {
-    gc_scoped_pool pool;
-    PythonRuntime py;
-
-    const lambda<bool()> erl = lambda<bool()>(testEvalReadAdd(py));
-    cout << "Python read + eval test " << time(erl, 5, 10000) << " ms" << endl;
-
-    istringstream is(testPythonAdd);
-    failable<PyObject*> script = readScript("script4", "script4.py", is, py);
-    assert(hasContent(script));
-
-    const lambda<bool()> el = lambda<bool()>(testEvalAdd(content(script), py));
+    };
     cout << "Python eval test " << time(el, 5, 10000) << " ms" << endl;
 
-    releaseScript(content(script), py);
+    releaseScript(script, py);
     return true;
 }
 
 #ifdef WANT_THREADS
 
-struct testReadEvalAddLoop {
-    PythonRuntime& py;
-    testReadEvalAddLoop(PythonRuntime& py) : py(py) {
-    }
-    const bool operator()() const {
+const list<future<bool> > submitReadEvals(worker& w, const int max, const int i, PythonRuntime& py) {
+    if (i == max)
+        return list<future<bool> >();
+    const blambda func = [&py]() -> const bool {
         for (int i = 0; i < 100; i++) {
             istringstream is(testPythonAdd);
-            failable<PyObject*> script = readScript("script6", "script6.py", is, py);
+            const failable<PyObject*> script = readScript("script6", "script6.py", is, py);
             assert(hasContent(script));
 
             const value exp = mklist<value>("add", 2, 3);
@@ -192,15 +177,14 @@ struct testReadEvalAddLoop {
             releaseScript(content(script), py);
         }
         return true;
-    }
-};
+    };
+    return cons(submit(w, func), submitReadEvals(w, max, i + 1, py));
+}
 
-struct testEvalAddLoop {
-    PyObject* script;
-    PythonRuntime& py;
-    testEvalAddLoop(PyObject* script, PythonRuntime& py) : script(script), py(py) {
-    }
-    const bool operator()() const {
+const list<future<bool> > submitEvals(worker& w, const int max, const int i, PyObject* const script, PythonRuntime& py) {
+    if (i == max)
+        return list<future<bool> >();
+    const blambda func = [script, &py]() -> const bool {
         for (int i = 0; i < 100; i++) {
             const value exp = mklist<value>("add", 2, 3);
             const failable<value> r = evalScript(exp, script, py);
@@ -208,75 +192,44 @@ struct testEvalAddLoop {
             assert(content(r) == value(5));
         }
         return true;
-    }
-};
-
-const list<future<bool> > submitReadEvals(worker& w, const int max, const int i, PythonRuntime& py) {
-    if (i == max)
-        return list<future<bool> >();
-    const lambda<bool()> func = lambda<bool()>(testReadEvalAddLoop(py));
-    return cons(submit(w, func), submitReadEvals(w, max, i + 1, py));
-}
-
-const list<future<bool> > submitEvals(worker& w, const int max, const int i, PyObject* script, PythonRuntime& py) {
-    if (i == max)
-        return list<future<bool> >();
-    const lambda<bool()> func = lambda<bool()>(testEvalAddLoop(script, py));
+    };
     return cons(submit(w, func), submitEvals(w, max, i + 1, script, py));
 }
 
-bool checkEvalResults(const list<future<bool> > r) {
+const bool checkEvalResults(const list<future<bool> > r) {
     if (isNil(r))
         return true;
     assert(car(r) == true);
     return checkEvalResults(cdr(r));
 }
 
-struct testReadEvalThreads {
-    worker& w;
-    const int max;
-    PythonRuntime& py;
-    testReadEvalThreads(worker& w, const int max, PythonRuntime& py) : w(w), max(max), py(py) {
-    }
-    const bool operator()() const {
-        const list<future<bool> > r(submitReadEvals(w, max, 0, py));
-        checkEvalResults(r);
-        return true;
-    }
-};
-
-struct testEvalThreads {
-    worker& w;
-    const int max;
-    PyObject* script;
-    PythonRuntime& py;
-    testEvalThreads(worker& w, const int max, PyObject* script, PythonRuntime& py) : w(w), max(max), script(script), py(py) {
-    }
-    const bool operator()() const {
-        const list<future<bool> > r(submitEvals(w, max, 0, script, py));
-        checkEvalResults(r);
-        return true;
-    }
-};
-
-bool testThreads() {
-    gc_scoped_pool pool;
+const bool testThreads() {
+    const gc_scoped_pool pool;
     PythonRuntime py;
 
     const int max = 100;
     worker w(max);
 
-    const lambda<bool()> elr = lambda<bool()>(testReadEvalThreads(w, max, py));
+    const blambda elr = [&w, max, &py]() -> const bool {
+        const list<future<bool> > r(submitReadEvals(w, max, 0, py));
+        checkEvalResults(r);
+        return true;
+    };
     cout << "Python eval + read thread test " << time(elr, 1, 1) / 10000.0 << " ms" << endl;
 
     istringstream is(testPythonAdd);
-    failable<PyObject*> script = readScript("script7", "script7.py", is, py);
-    assert(hasContent(script));
+    const failable<PyObject*> fscript = readScript("script7", "script7.py", is, py);
+    assert(hasContent(fscript));
 
-    const lambda<bool()> el = lambda<bool()>(testEvalThreads(w, max, content(script), py));
+    PyObject* const script = content(fscript);
+    const blambda el = [&w, max, script, &py]() -> const bool {
+        const list<future<bool> > r(submitEvals(w, max, 0, script, py));
+        checkEvalResults(r);
+        return true;
+    };
     cout << "Python eval thread test " << time(el, 1, 1) / 10000.0 << " ms" << endl;
 
-    releaseScript(content(script), py);
+    releaseScript(script, py);
     return true;
 }
 
@@ -286,7 +239,7 @@ bool testThreads() {
 }
 
 int main() {
-    tuscany::gc_scoped_pool p;
+    const tuscany::gc_scoped_pool p;
     tuscany::cout << "Testing..." << tuscany::endl;
 
     tuscany::python::testEvalExpr();

Modified: tuscany/sca-cpp/trunk/modules/server/Makefile.am
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/Makefile.am?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/Makefile.am (original)
+++ tuscany/sca-cpp/trunk/modules/server/Makefile.am Tue Dec 11 04:03:29 2012
@@ -29,7 +29,7 @@ mod_LTLIBRARIES = libmod_tuscany_eval.la
 noinst_DATA = libmod_tuscany_eval${libsuffix}
 
 libmod_tuscany_eval_la_SOURCES = mod-eval.cpp
-libmod_tuscany_eval_la_LDFLAGS = -lxml2 -lcurl -lmozjs
+libmod_tuscany_eval_la_LDFLAGS = -lxml2 -lcurl -ljansson
 libmod_tuscany_eval${libsuffix}:
 	ln -s .libs/libmod_tuscany_eval${libsuffix}
 
@@ -42,7 +42,7 @@ libimpl-test${libsuffix}:
 	ln -s .libs/libimpl-test${libsuffix}
 
 client_test_SOURCES = client-test.cpp
-client_test_LDFLAGS = -lxml2 -lcurl -lmozjs
+client_test_LDFLAGS = -lxml2 -lcurl -ljansson
 
 dist_noinst_SCRIPTS = httpd-test server-test wiring-test
 noinst_PROGRAMS = client-test



Mime
View raw message