You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2010/01/17 10:03:02 UTC

svn commit: r900074 - in /tuscany/sca-cpp/trunk: kernel/gc.hpp modules/json/json.hpp modules/server/client-test.hpp

Author: jsdelfino
Date: Sun Jan 17 09:03:01 2010
New Revision: 900074

URL: http://svn.apache.org/viewvc?rev=900074&view=rev
Log:
Added asserts to memory alloc functions. Fixed JSON request construction to support char func names. Reduced size of test messages to speed up test cases.

Modified:
    tuscany/sca-cpp/trunk/kernel/gc.hpp
    tuscany/sca-cpp/trunk/modules/json/json.hpp
    tuscany/sca-cpp/trunk/modules/server/client-test.hpp

Modified: tuscany/sca-cpp/trunk/kernel/gc.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/gc.hpp?rev=900074&r1=900073&r2=900074&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/gc.hpp (original)
+++ tuscany/sca-cpp/trunk/kernel/gc.hpp Sun Jan 17 09:03:01 2010
@@ -87,19 +87,19 @@
  */
 class gc_pool {
 public:
-    gc_pool() : p(NULL) {
+    gc_pool() : apr_pool(NULL) {
     }
 
-    gc_pool(apr_pool_t* p) : p(p) {
+    gc_pool(apr_pool_t* p) : apr_pool(p) {
     }
 
-    gc_pool(const gc_pool& pool) : p(pool.p) {
+    gc_pool(const gc_pool& pool) : apr_pool(pool.apr_pool) {
     }
 
     gc_pool& operator=(const gc_pool& pool) {
         if (this == &pool)
             return *this;
-        p = pool.p;
+        apr_pool = pool.apr_pool;
         return *this;
     }
 
@@ -108,14 +108,14 @@
     friend class gc_global_pool_t;
     friend class gc_scoped_pool;
 
-    apr_pool_t* p;
+    apr_pool_t* apr_pool;
 };
 
 /**
  * Return APR pool used by a gc_pool.
  */
 apr_pool_t* pool(const gc_pool& pool) {
-    return pool.p;
+    return pool.apr_pool;
 }
 
 /**
@@ -148,14 +148,15 @@
  * Return the current memory pool.
  */
 apr_pool_t* gc_current_pool() {
-    apr_pool_t* p = gc_pool_stack;
-    if (p != NULL)
-        return p;
+    apr_pool_t* apr_pool = gc_pool_stack;
+    if (apr_pool != NULL)
+        return apr_pool;
 
     // Create a parent pool for the current thread
-    apr_pool_create(&p, NULL);
-    gc_pool_stack = p;
-    return p;
+    apr_pool_create(&apr_pool, NULL);
+    assert(apr_pool != NULL);
+    gc_pool_stack = apr_pool;
+    return apr_pool;
 }
 
 /**
@@ -184,22 +185,23 @@
 public:
 
     gc_scoped_pool() : gc_pool(NULL), prev(gc_current_pool()), owner(true) {
-        apr_pool_create(&p, NULL);
-        gc_push_pool(p);
+        apr_pool_create(&apr_pool, NULL);
+        assert(apr_pool != NULL);
+        gc_push_pool(apr_pool);
     }
 
     gc_scoped_pool(apr_pool_t* pool) : gc_pool(pool), prev(gc_current_pool()), owner(false) {
-        gc_push_pool(p);
+        gc_push_pool(apr_pool);
     }
 
     ~gc_scoped_pool() {
         if (owner)
-            apr_pool_destroy(p);
+            apr_pool_destroy(apr_pool);
         gc_pop_pool(prev);
     }
 
 private:
-    gc_scoped_pool(const unused gc_scoped_pool& pool) : gc_pool(pool.p), prev(NULL), owner(false) {
+    gc_scoped_pool(const unused gc_scoped_pool& pool) : gc_pool(pool.apr_pool), prev(NULL), owner(false) {
     }
 
     apr_pool_t* prev;
@@ -217,9 +219,10 @@
 }
 
 template<typename T> T* gc_new(apr_pool_t* p) {
-    void* m = apr_palloc(p, sizeof(T));
-    apr_pool_cleanup_register(p, m, gc_pool_cleanup<T>, apr_pool_cleanup_null) ;
-    return static_cast<T*>(m);
+    void* gc_new_ptr = apr_palloc(p, sizeof(T));
+    assert(gc_new_ptr != NULL);
+    apr_pool_cleanup_register(p, gc_new_ptr, gc_pool_cleanup<T>, apr_pool_cleanup_null) ;
+    return static_cast<T*>(gc_new_ptr);
 }
 
 template<typename T> T* gc_new(const gc_pool& p) {
@@ -240,10 +243,11 @@
 }
 
 template<typename T> T* gc_anew(apr_pool_t* p, int n) {
-    int* m = static_cast<int*>(apr_palloc(p, sizeof(int) + sizeof(T[n])));
-    *m = n;
-    apr_pool_cleanup_register(p, m, gc_pool_acleanup<T>, apr_pool_cleanup_null) ;
-    return (T*)(m + 1);
+    int* gc_anew_ptr = static_cast<int*>(apr_palloc(p, sizeof(int) + sizeof(T[n])));
+    assert(gc_anew_ptr != NULL);
+    *gc_anew_ptr = n;
+    apr_pool_cleanup_register(p, gc_anew_ptr, gc_pool_acleanup<T>, apr_pool_cleanup_null) ;
+    return (T*)(gc_anew_ptr + 1);
 }
 
 template<typename T> T* gc_anew(const gc_pool& p, int n) {
@@ -258,7 +262,9 @@
  * Allocate an array of chars.
  */
 char* gc_cnew(apr_pool_t* p, int n) {
-    return static_cast<char*>(apr_palloc(p, n));
+    char* gc_cnew_ptr = static_cast<char*>(apr_palloc(p, n));
+    assert(gc_cnew_ptr != NULL);
+    return gc_cnew_ptr;
 }
 
 char* gc_cnew(int n) {

Modified: tuscany/sca-cpp/trunk/modules/json/json.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/json/json.hpp?rev=900074&r1=900073&r2=900074&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/json/json.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/json/json.hpp Sun Jan 17 09:03:01 2010
@@ -370,7 +370,7 @@
  * Convert a function + params to a JSON request.
  */
 const failable<list<string> > jsonRequest(const value& id, const value& func, const value& params, json::JSONContext& cx) {
-    const list<value> r = mklist<value>(mklist<value>("id", id), mklist<value>("method", func), mklist<value>("params", params));
+    const list<value> r = mklist<value>(mklist<value>("id", id), mklist<value>("method", string(func)), mklist<value>("params", params));
     return writeJSON(valuesToElements(r), cx);
 }
 

Modified: tuscany/sca-cpp/trunk/modules/server/client-test.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/client-test.hpp?rev=900074&r1=900073&r2=900074&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/client-test.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/server/client-test.hpp Sun Jan 17 09:03:01 2010
@@ -101,8 +101,8 @@
     }
 };
 
-const value blob(string(3000, 'A'));
-const list<value> blobs = mklist(blob, blob, blob, blob, blob);
+const value blob(string(2048, 'A'));
+const list<value> blobs = mklist(blob, blob);
 
 struct blobEvalLoop {
     const string uri;
@@ -181,9 +181,6 @@
             + (list<value>() + "name" + string("Apple"))
             + (list<value>() + "blob1" + blob)
             + (list<value>() + "blob2" + blob)
-            + (list<value>() + "blob3" + blob)
-            + (list<value>() + "blob4" + blob)
-            + (list<value>() + "blob5" + blob)
             + (list<value>() + "price" + string("$2.99"));
         const list<value> val = mklist<value>(string("item"), string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i);
         const lambda<bool()> pl = postBlobLoop(testURI, val, ch);