From b82ed61220ef11fd547c8297e59212e5fc84bf37 Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Wed, 29 Jul 2015 17:44:52 +0800 Subject: [PATCH] buffer: make buffer::exception classes undefined in dynamic objects On OSX, if the an exception class is declared and defined in header file, but it ends up being compiled as private symbols in different binaries. The exception handling code will take the two compiled exception classes as different types! In our case, the one in libcls_xxx.so and the one is ceph-osd are considered as different classes, thus the try-catch statement fails to work. The fix is force buffer::exception classes undefined in libcls_xxx.so. The ibcls_xxx.so are compiled with '-undefined dynamic_lookup' option. when it is loaded into ceph-osd, buffer::exception classes in ceph-osd will be used. Signed-off-by: Yan, Zheng --- src/common/buffer.cc | 12 ++++++++++++ src/include/buffer.h | 16 ++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 27dc62a19e5fc..1ab62241f9c06 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -120,6 +120,18 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; return 65536; } + const char * buffer::error::what() const throw () { + return "buffer::exception"; + } + const char * buffer::bad_alloc::what() const throw () { + return "buffer::bad_alloc"; + } + const char * buffer::end_of_buffer::what() const throw () { + return "buffer::end_of_buffer"; + } + const char * buffer::malformed_input::what() const throw () { + return buf; + } buffer::error_code::error_code(int error) : buffer::malformed_input(cpp_strerror(error).c_str()), code(error) {} diff --git a/src/include/buffer.h b/src/include/buffer.h index a54befa11c8a3..bb6ea9356c537 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -75,27 +75,19 @@ class CEPH_BUFFER_API buffer { public: struct error : public std::exception{ - const char *what() const throw () { - return "buffer::exception"; - } + const char *what() const throw (); }; struct bad_alloc : public error { - const char *what() const throw () { - return "buffer::bad_alloc"; - } + const char *what() const throw (); }; struct end_of_buffer : public error { - const char *what() const throw () { - return "buffer::end_of_buffer"; - } + const char *what() const throw (); }; struct malformed_input : public error { explicit malformed_input(const std::string& w) { snprintf(buf, sizeof(buf), "buffer::malformed_input: %s", w.c_str()); } - const char *what() const throw () { - return buf; - } + const char *what() const throw (); private: char buf[256]; }; -- 2.39.5