summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/kernel
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2011-04-17 22:14:18 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2011-04-17 22:14:18 +0000
commita0f68830211cbea1112794922939f8c5e90d7c4e (patch)
tree79b0ac2bf128a18e80bb08c19f3d08efe6fc5ec6 /sca-cpp/trunk/kernel
parentff2490e3b4638b421c381946d8b1ebb30e51141b (diff)
Fix representation of null values and escape control characters in JSON and HTTP query strings.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1094210 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/kernel')
-rw-r--r--sca-cpp/trunk/kernel/gc.hpp29
-rw-r--r--sca-cpp/trunk/kernel/list.hpp2
-rw-r--r--sca-cpp/trunk/kernel/value.hpp28
3 files changed, 45 insertions, 14 deletions
diff --git a/sca-cpp/trunk/kernel/gc.hpp b/sca-cpp/trunk/kernel/gc.hpp
index 09dcd1e5ac..d843b50ca0 100644
--- a/sca-cpp/trunk/kernel/gc.hpp
+++ b/sca-cpp/trunk/kernel/gc.hpp
@@ -36,6 +36,23 @@
namespace tuscany
{
+#ifdef WANT_MAINTAINER_MODE
+
+/**
+ * Force a core dump on assertion violation.
+ */
+bool assertOrFail(const bool expr) {
+ if (!expr)
+ *(char*)NULL = '\0';
+ return true;
+}
+
+#else
+
+#define assertOrFail(expr)
+
+#endif
+
/**
* Pointer to a value.
*/
@@ -117,7 +134,7 @@ private:
apr_pool_t* mkpool() {
apr_pool_t* p = NULL;
apr_pool_create(&p, NULL);
- assert(p != NULL);
+ assertOrFail(p != NULL);
return p;
}
@@ -164,7 +181,7 @@ apr_pool_t* gc_current_pool() {
// Create a parent pool for the current thread
apr_pool_create(&apr_pool, NULL);
- assert(apr_pool != NULL);
+ assertOrFail(apr_pool != NULL);
gc_pool_stack = apr_pool;
return apr_pool;
}
@@ -196,7 +213,7 @@ public:
gc_scoped_pool() : gc_pool(NULL), prev(gc_current_pool()), owner(true) {
apr_pool_create(&apr_pool, NULL);
- assert(apr_pool != NULL);
+ assertOrFail(apr_pool != NULL);
gc_push_pool(apr_pool);
}
@@ -230,7 +247,7 @@ template<typename T> apr_status_t gc_pool_cleanup(void* v) {
template<typename T> T* gc_new(apr_pool_t* p) {
void* gc_new_ptr = apr_palloc(p, sizeof(T));
- assert(gc_new_ptr != NULL);
+ assertOrFail(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);
}
@@ -254,7 +271,7 @@ template<typename T> apr_status_t gc_pool_acleanup(void* v) {
template<typename T> T* gc_anew(apr_pool_t* p, size_t n) {
size_t* gc_anew_ptr = static_cast<size_t*>(apr_palloc(p, sizeof(size_t) + sizeof(T[n])));
- assert(gc_anew_ptr != NULL);
+ assertOrFail(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);
@@ -273,7 +290,7 @@ template<typename T> T* gc_anew(size_t n) {
*/
char* gc_cnew(apr_pool_t* p, size_t n) {
char* gc_cnew_ptr = static_cast<char*>(apr_palloc(p, n));
- assert(gc_cnew_ptr != NULL);
+ assertOrFail(gc_cnew_ptr != NULL);
return gc_cnew_ptr;
}
diff --git a/sca-cpp/trunk/kernel/list.hpp b/sca-cpp/trunk/kernel/list.hpp
index a8dbcc1b0c..df7bc27c03 100644
--- a/sca-cpp/trunk/kernel/list.hpp
+++ b/sca-cpp/trunk/kernel/list.hpp
@@ -301,7 +301,7 @@ template<typename T> const list<T> mklist(const T& a, const T& b, const T& c, co
*/
template<typename T> const T car(const list<T>& p) {
// Abort if trying to access the car of a nil list
- assert(!isNil(p.cdr));
+ assertOrFail(!isNil(p.cdr));
return p.car;
}
diff --git a/sca-cpp/trunk/kernel/value.hpp b/sca-cpp/trunk/kernel/value.hpp
index 07be7f5c82..3e0dd0002f 100644
--- a/sca-cpp/trunk/kernel/value.hpp
+++ b/sca-cpp/trunk/kernel/value.hpp
@@ -95,10 +95,10 @@ class value {
public:
enum ValueType {
- Undefined, Symbol, String, List, Number, Bool, Lambda, Ptr
+ Nil, Symbol, String, List, Number, Bool, Lambda, Ptr
};
- value() : type(value::Undefined) {
+ value() : type(value::Nil) {
debug_inc(countValues);
debug_inc(countEValues);
debug_watchValue();
@@ -239,8 +239,8 @@ public:
if(this == &v)
return true;
switch(type) {
- case value::Undefined:
- return v.type == value::Undefined;
+ case value::Nil:
+ return v.type == value::Nil;
case value::List:
return v.type == value::List && lst()() == v.lst()();
case value::Lambda:
@@ -448,6 +448,18 @@ const string watchValue(const value& v) {
#endif
/**
+ * Write an escaped string value to a stream.
+ */
+ostream& escvwrite(const char* s, ostream& out) {
+ if (*s == '\0')
+ return out;
+ if (*s == '\\' || *s == '"')
+ out << '\\';
+ out << *s;
+ return escvwrite(s + 1, out);
+}
+
+/**
* Write a value to a stream.
*/
ostream& operator<<(ostream& out, const value& v) {
@@ -459,7 +471,9 @@ ostream& operator<<(ostream& out, const value& v) {
case value::Symbol:
return out << v.str()();
case value::String:
- return out << '\"' << v.str()() << '\"';
+ out << '\"';
+ escvwrite(c_str(v.str()()), out);
+ return out << '\"';
case value::Number:
return out << v.num()();
case value::Bool:
@@ -474,7 +488,7 @@ ostream& operator<<(ostream& out, const value& v) {
return out << "gc_ptr::" << p;
}
default:
- return out << "undefined";
+ return out << "nil";
}
}
@@ -489,7 +503,7 @@ const value::ValueType type(const value& v) {
* Returns true if a value is nil.
*/
const bool isNil(const value& v) {
- return type(v) == value::Undefined;
+ return type(v) == value::Nil;
}
/**