diff --git a/src/py_utils.cc b/src/py_utils.cc index 3e788442..c2177c20 100644 --- a/src/py_utils.cc +++ b/src/py_utils.cc @@ -74,11 +74,13 @@ typedef register_python_conversion bool_python_conversion; +#if defined(STRING_VERIFY_ON) + struct string_to_python { - static PyObject* convert(const string& str) + static PyObject* convert(const ledger::string& str) { - return incref(object(*boost::polymorphic_downcast(&str)).ptr()); + return incref(object(static_cast(str)).ptr()); } }; @@ -95,15 +97,17 @@ struct string_from_python const char* value = PyString_AsString(obj_ptr); if (value == 0) throw_error_already_set(); void* storage = - reinterpret_cast *>(data)->storage.bytes; - new (storage) string(value); + reinterpret_cast *>(data)->storage.bytes; + new (storage) ledger::string(value); data->convertible = storage; } }; -typedef register_python_conversion +typedef register_python_conversion string_python_conversion; +#endif // STRING_VERIFY_ON + struct istream_to_python { @@ -209,7 +213,9 @@ void export_utils() ; bool_python_conversion(); +#if defined(STRING_VERIFY_ON) string_python_conversion(); +#endif istream_python_conversion(); ostream_python_conversion(); } diff --git a/src/utils.cc b/src/utils.cc index c68737dc..2f2899fb 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -407,6 +407,8 @@ void report_memory(std::ostream& out, bool report_all) } +#if defined(STRING_VERIFY_ON) + string::string() : std::string() { TRACE_CTOR(string, ""); } @@ -443,6 +445,8 @@ string::~string() throw() { TRACE_DTOR(string); } +#endif // STRING_VERIFY_ON + } // namespace ledger #endif // VERIFY_ON diff --git a/src/utils.h b/src/utils.h index c3d3cf24..a8784a66 100644 --- a/src/utils.h +++ b/src/utils.h @@ -62,6 +62,10 @@ #define TIMERS_ON 1 #endif +#if defined(VERIFY_ON) +//#define STRING_VERIFY_ON 1 +#endif + /*@}*/ /** @@ -72,7 +76,7 @@ namespace ledger { using namespace boost; -#if defined(VERIFY_ON) +#if defined(STRING_VERIFY_ON) class string; #else typedef std::string string; @@ -158,6 +162,8 @@ void trace_dtor_func(void * ptr, const char * cls_name, std::size_t cls_size); void report_memory(std::ostream& out, bool report_all = false); +#if defined(STRING_VERIFY_ON) + /** * @brief Brief * @@ -236,6 +242,8 @@ inline bool operator!=(const char* __lhs, const string& __rhs) inline bool operator!=(const string& __lhs, const char* __rhs) { return __lhs.compare(__rhs) != 0; } +#endif // STRING_VERIFY_ON + } // namespace ledger #else // ! VERIFY_ON