diff options
49 files changed, 990 insertions, 146 deletions
@@ -1,4 +1,61 @@ 2006-05-09 Murray Cumming <murrayc@murrayc.com> + + * glib/glibmm/ustring.cc: + * glib/src/date.ccg: + * glib/src/convert.ccg: + * glib/src/convert.hg: Added #ifdefed versions for the case that + exceptions are disabled. + +2006-05-10 Murray Cumming <murrayc@murrayc.com> + + * configure.in: + * scripts/reduced.m4: Moved --enable-deprecated-api macro into scripts/reduced.m4. + Added the --enable-api-exceptions macro that was missing from my last commit. + +2006-04-05 Murray Cumming <murrayc@murrayc.com> + + * configure.in: + * scripts/reduced.m4: Added --enable-api-exceptions option. When this + is used, methods that would normally throw an exception will now take + an extra std::auto_ptr<Glib::Error> argument that should be checked with + auto_ptr::get(). + * glib/glibmmconfig.h.in: Undef the GLIBMM_EXCEPTIONS_ENABLED, + so it will be defined. + * tools/m4/gerror.m4: throw_func() returns an auto_ptr of a + Glib::Error when exceptions are disabled. + * tools/m4/method.m4: + * tools/pm/Output.pm: on_wrap_method(): Added alternative API with + #ifdefs + * tools/m4/signal.m4: + * tools/m4/signalproxy_custom.m4: + * tools/m4/vfunc.m4: Put #ifdefs around the exception re-throwing + try/catch blocks. + * glib/glibmm/dispatcher.cc: + * glib/glibmm/dispatcher.h: + * glib/glibmm/error.cc: + * glib/glibmm/error.h: + * glib/glibmm/exceptionhandler.cc: + * glib/glibmm/exceptionhandler.h: + * glib/glibmm/main.cc: + * glib/glibmm/signalproxy.cc: + * glib/glibmm/streamiochannel.cc: + * glib/glibmm/stringutils.cc: + * glib/glibmm/threadpool.cc: + * glib/src/iochannel.ccg: + * glib/src/iochannel.hg: + * glib/src/markup.ccg: + * glib/src/spawn.ccg: + * glib/src/thread.ccg: Put #ifdefs around try/catch blocks, and + use alternative API when appropriate. + * examples/iochannel_stream/fdstream.cc: + * examples/markup/parser.cc: + * examples/options/main.cc: Adapted examples to + the alternative API, with #ifdefs + * tools/m4/convert_base.m4: Avoid any conversion if the result is + void, to allow _WRAP_METHOD() to ignore bool results, so we can + generate some methods that are currently hand-coded. + +2006-05-09 Murray Cumming <murrayc@murrayc.com> * glib/glibmm/value.cc: * glib/glibmm/value.h: Added init(const GValue*), so that we can copy GValue instances @@ -1,3 +1,11 @@ +2.10.2: + +* Added --enable-api-properties, --enable-api-vfuncs, and --enable-api-exceptions. + When using these, the API, and any API generated by gmmproc, will be + changed. This allows users of embedded platforms to reduce the code size of *mm + libraries and *mm-using applications, at the small cost of losing some rarely-used + API. Alternatives exist for that API, as show in the examples. + 2.10.1 * Windows Build: diff --git a/configure.in b/configure.in index 11f51147..74cb64e2 100644 --- a/configure.in +++ b/configure.in @@ -18,8 +18,8 @@ AC_PREREQ(2.50) # Version and initialization ######################################################################### GLIBMM_MAJOR_VERSION=2 -GLIBMM_MINOR_VERSION=10 -GLIBMM_MICRO_VERSION=1 +GLIBMM_MINOR_VERSION=11 +GLIBMM_MICRO_VERSION=0 GLIBMM_VERSION=$GLIBMM_MAJOR_VERSION.$GLIBMM_MINOR_VERSION.$GLIBMM_MICRO_VERSION GLIBMM_RELEASE=$GLIBMM_MAJOR_VERSION.$GLIBMM_MINOR_VERSION AC_DEFINE_UNQUOTED(GLIBMM_MAJOR_VERSION, $GLIBMM_MAJOR_VERSION) @@ -38,7 +38,7 @@ AC_SUBST(GLIBMM_RELEASE) # ? :+1 : ? == just some internal changes, nothing breaks but might work # better # CURRENT : REVISION : AGE -LIBGLIBMM_SO_VERSION=1:22:0 +LIBGLIBMM_SO_VERSION=1:23:0 AC_SUBST(LIBGLIBMM_SO_VERSION) AC_CONFIG_AUX_DIR(scripts) @@ -224,18 +224,12 @@ if test "x$enable_use_deprecations" = "xyes"; then AC_SUBST(DISABLE_DEPRECATED_CFLAGS) fi - -# Add an --enable-deprecated-api option: -AC_ARG_ENABLE(deprecated-api, [AC_HELP_STRING([--enable-deprecated-api], - [include (build) deprecated API in the libraries [default=yes]])],, - [enable_deprecated_api=yes]) -if test "x$enable_deprecated_api" = "xyes"; then -AC_MSG_WARN([Deprecated API will be built, for backwards-compatibility.]) -else - DISABLE_DEPRECATED_API_CFLAGS="-DGLIBMM_DISABLE_DEPRECATED" -AC_SUBST(DISABLE_DEPRECATED_API_CFLAGS) -AC_MSG_WARN([Deprecated API will not be built, breaking backwards-compatibility. Do not use this build for distribution packages.]) -fi +#Offer the ability to omit some API from the library, +#to reduce the code size: +GLIBMM_ARG_ENABLE_API_DEPRECATED() +GLIBMM_ARG_ENABLE_API_EXCEPTIONS() +GLIBMM_ARG_ENABLE_API_PROPERTIES() +GLIBMM_ARG_ENABLE_API_VFUNCS() # Dummy conditional just to make automake-1.4 happy. diff --git a/examples/iochannel_stream/fdstream.cc b/examples/iochannel_stream/fdstream.cc index 96a49fc6..bc46a3db 100644 --- a/examples/iochannel_stream/fdstream.cc +++ b/examples/iochannel_stream/fdstream.cc @@ -48,7 +48,14 @@ void fdstreambuf::create_iochannel(int fd, bool manage) if(fd >= 0) { iochannel_ = Glib::IOChannel::create_from_fd(fd); + + #ifdef GLIBMM_EXCEPTIONS_ENABLED iochannel_->set_encoding(""); + #else + std::auto_ptr<Glib::Error> ex; + iochannel_->set_encoding("", ex); + #endif //GLIBMM_EXCEPTIONS_ENABLED + iochannel_->set_buffered(true); iochannel_->set_close_on_unref(manage); } @@ -76,6 +83,7 @@ int fdstreambuf::sync() if (!iochannel_) return -1; + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { iochannel_->flush(); @@ -86,6 +94,16 @@ int fdstreambuf::sync() error_condition.code = io_error.code(); return -1; } + #else + std::auto_ptr<Glib::Error> io_error; + iochannel_->flush(io_error); + if(io_error.get()) + { + error_condition.error = true; + error_condition.code = (Glib::IOChannelError::Code)io_error->code(); + return -1; + } + #endif //GLIBMM_EXCEPTIONS_ENABLED return 0; } @@ -95,6 +113,7 @@ void fdstreambuf::close_iochannel() iochannel_->set_close_on_unref(false); reset(); + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { iochannel_->close(true); @@ -104,6 +123,16 @@ void fdstreambuf::close_iochannel() error_condition.error = true; error_condition.code = io_error.code(); } + #else + std::auto_ptr<Glib::Error> io_error; + iochannel_->close(true, io_error); + if(io_error.get()) + { + error_condition.error = true; + error_condition.code = (Glib::IOChannelError::Code)io_error->code(); + } + #endif //GLIBMM_EXCEPTIONS_ENABLED + } // the standard requires this to return either the character @@ -112,6 +141,7 @@ fdstreambuf::traits_type::int_type fdstreambuf::overflow(int_type c) { if(!traits_type::eq_int_type(c, traits_type::eof())) { + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { gsize result = 0; @@ -124,6 +154,18 @@ fdstreambuf::traits_type::int_type fdstreambuf::overflow(int_type c) error_condition.code = io_error.code(); return traits_type::eof(); } + #else + std::auto_ptr<Glib::Error> io_error; + gsize result = 0; + char write_char = c; + iochannel_->write(&write_char, 1, result, io_error); + if(io_error.get()) + { + error_condition.error = true; + error_condition.code = (Glib::IOChannelError::Code)io_error->code(); + return traits_type::eof();; + } + #endif //GLIBMM_EXCEPTIONS_ENABLED } return traits_type::not_eof(c); } @@ -138,6 +180,7 @@ std::streamsize fdstreambuf::xsputn(const char* source, std::streamsize num) // will only do a short write in the event of stream failure, so there is no // need to check result and have a second bite (byte) at it as would be // necessary with Unix write() + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { iochannel_->write(source, num, result); @@ -148,6 +191,16 @@ std::streamsize fdstreambuf::xsputn(const char* source, std::streamsize num) error_condition.code = io_error.code(); result = 0; } + #else + std::auto_ptr<Glib::Error> io_error; + iochannel_->write(source, num, result, io_error); + if(io_error.get()) + { + error_condition.error = true; + error_condition.code = (Glib::IOChannelError::Code)io_error->code(); + result = 0; + } + #endif //GLIBMM_EXCEPTIONS_ENABLED return result; } @@ -165,6 +218,7 @@ fdstreambuf::traits_type::int_type fdstreambuf::underflow() // now insert a character into the bump position gsize result = 0; + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { iochannel_->read(putback_buffer + 1, 1, result); @@ -175,6 +229,16 @@ fdstreambuf::traits_type::int_type fdstreambuf::underflow() error_condition.code = io_error.code(); return traits_type::eof(); } + #else + std::auto_ptr<Glib::Error> io_error; + iochannel_->read(putback_buffer + 1, 1, result, io_error); + if(io_error.get()) + { + error_condition.error = true; + error_condition.code = (Glib::IOChannelError::Code)io_error->code(); + return traits_type::eof(); + } + #endif //GLIBMM_EXCEPTIONS_ENABLED // some other error - is this possible? In case it is, cater for it if (result == 0) @@ -218,22 +282,42 @@ std::streamsize fdstreambuf::xsgetn(char* dest, std::streamsize num) // read up to everything else we need with Glib::IOChannel::read() gsize result = 0; + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #else + std::auto_ptr<Glib::Error> io_error; + #endif //GLIBMM_EXCEPTIONS_ENABLED do { + #ifdef GLIBMM_EXCEPTIONS_ENABLED iochannel_->read(dest + chars_read, num - chars_read, result); + #else + iochannel_->read(dest + chars_read, + num - chars_read, + result, io_error); + #endif //GLIBMM_EXCEPTIONS_ENABLED + if (result > 0) chars_read += result; } while (result > 0 && result < static_cast<gsize>(num - chars_read)); + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(Glib::IOChannelError& io_error) + #else + if(io_error.get()) + #endif //GLIBMM_EXCEPTIONS_ENABLED { error_condition.error = true; + + #ifdef GLIBMM_EXCEPTIONS_ENABLED error_condition.code = io_error.code(); + #else + error_condition.code = (Glib::IOChannelError::Code)io_error->code(); + #endif //GLIBMM_EXCEPTIONS_ENABLED return chars_read; } diff --git a/examples/markup/parser.cc b/examples/markup/parser.cc index cd4cc859..c9286f6c 100644 --- a/examples/markup/parser.cc +++ b/examples/markup/parser.cc @@ -23,10 +23,20 @@ namespace { +#ifndef GLIBMM_EXCEPTIONS_ENABLED +//This is an alternative, to use when we have disabled exceptions: +std::auto_ptr<Glib::Error> processing_error; +#endif //GLIBMM_EXCEPTIONS_ENABLED + void file_get_contents(const std::string& filename, Glib::ustring& contents) { + #ifdef GLIBMM_EXCEPTIONS_ENABLED const Glib::RefPtr<Glib::IOChannel> channel = Glib::IOChannel::create_from_file(filename, "r"); channel->read_to_end(contents); + #else + const Glib::RefPtr<Glib::IOChannel> channel = Glib::IOChannel::create_from_file(filename, "r", processing_error); + channel->read_to_end(contents, processing_error); + #endif //GLIBMM_EXCEPTIONS_ENABLED } Glib::ustring trim_whitespace(const Glib::ustring& text) @@ -136,19 +146,30 @@ int main(int argc, char** argv) DumpParser parser; Glib::Markup::ParseContext context (parser); + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED Glib::ustring contents; file_get_contents(argv[1], contents); context.parse(contents); context.end_parse(); + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(const Glib::Error& error) { std::cerr << argv[1] << ": " << error.what() << std::endl; return 1; } + #else + if(processing_error.get()) + { + std::cerr << argv[1] << ": " << processing_error->what() << std::endl; + return 1; + } + #endif //GLIBMM_EXCEPTIONS_ENABLED + return 0; } diff --git a/examples/options/main.cc b/examples/options/main.cc index ac055b94..2fa85376 100644 --- a/examples/options/main.cc +++ b/examples/options/main.cc @@ -104,6 +104,7 @@ int main(int argc, char** argv) ExampleOptionGroup group; context.set_main_group(group); + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { context.parse(argc, argv); @@ -112,6 +113,14 @@ int main(int argc, char** argv) { std::cout << "Exception: " << ex.what() << std::endl; } + #else + std::auto_ptr<Glib::Error> ex; + context.parse(argc, argv, ex); + if(ex.get()) + { + std::cout << "Exception: " << ex->what() << std::endl; + } + #endif //GLIBMM_EXCEPTIONS_ENABLED std::cout << "parsed values: " << std::endl << " foo = " << group.m_arg_foo << std::endl << diff --git a/glib/glibmm/class.cc b/glib/glibmm/class.cc index ff4a671d..596057a5 100644 --- a/glib/glibmm/class.cc +++ b/glib/glibmm/class.cc @@ -108,8 +108,10 @@ void Class::custom_class_init_function(void* g_class, void* class_data) GObjectClass *const gobject_class = static_cast<GObjectClass*>(g_class); +#ifdef GLIBMM_PROPERTIES_ENABLED gobject_class->get_property = &Glib::custom_get_property_callback; gobject_class->set_property = &Glib::custom_set_property_callback; +#endif //GLIBMM_PROPERTIES_ENABLED } } // namespace Glib diff --git a/glib/glibmm/class.h b/glib/glibmm/class.h index c7b5a96f..2610d758 100644 --- a/glib/glibmm/class.h +++ b/glib/glibmm/class.h @@ -23,6 +23,7 @@ */ #include <glib-object.h> +#include <glibmmconfig.h> //Include this here so that the /private/*.h classes have access to GLIBMM_VFUNCS_ENABLED #ifndef DOXYGEN_SHOULD_SKIP_THIS diff --git a/glib/glibmm/dispatcher.cc b/glib/glibmm/dispatcher.cc index 3bda9fb1..28609129 100644 --- a/glib/glibmm/dispatcher.cc +++ b/glib/glibmm/dispatcher.cc @@ -188,8 +188,10 @@ DispatchNotifier::DispatchNotifier(const Glib::RefPtr<MainContext>& context) { create_pipe(); + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED #ifdef G_OS_WIN32 conn_io_handler_ = context_->signal_io().connect( sigc::mem_fun(*this, &DispatchNotifier::pipe_io_handler), @@ -199,6 +201,7 @@ DispatchNotifier::DispatchNotifier(const Glib::RefPtr<MainContext>& context) sigc::mem_fun(*this, &DispatchNotifier::pipe_io_handler), fd_receiver_, Glib::IO_IN); #endif /* !G_OS_WIN32 */ + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(...) { @@ -209,6 +212,7 @@ DispatchNotifier::DispatchNotifier(const Glib::RefPtr<MainContext>& context) throw; } + #endif //GLIBMM_EXCEPTIONS_ENABLED } DispatchNotifier::~DispatchNotifier() @@ -231,20 +235,29 @@ void DispatchNotifier::create_pipe() if(!fd_receiver_) { +#ifdef GLIBMM_EXCEPTIONS_ENABLED GError* const error = g_error_new(G_FILE_ERROR, G_FILE_ERROR_FAILED, "Failed to create event for inter-thread communication: %s", g_win32_error_message(GetLastError())); throw Glib::FileError(error); +#else + return; //TODO: Provide an alternative to the exception. +#endif //GLIBMM_EXCEPTIONS_ENABLED } + #else /* !G_OS_WIN32 */ int filedes[2] = { -1, -1 }; if(pipe(filedes) < 0) { +#ifdef GLIBMM_EXCEPTIONS_ENABLED GError* const error = g_error_new(G_FILE_ERROR, g_file_error_from_errno(errno), "Failed to create pipe for inter-thread communication: %s", g_strerror(errno)); throw Glib::FileError(error); +#else + return; //TODO: Provide an alternative to the exception. +#endif //GLIBMM_EXCEPTIONS_ENABLED } fd_set_close_on_exec(filedes[0]); @@ -353,14 +366,18 @@ bool DispatchNotifier::pipe_io_handler(Glib::IOCondition) // Actually, we wouldn't need the try/catch block because the Glib::Source // C callback already does it for us. However, we do it anyway because the // default return value is 'false', which is not what we want. + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED data.dispatcher->signal_(); + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(...) { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED } #else /* !G_OS_WIN32 */ DispatchNotifyData data; @@ -390,14 +407,18 @@ bool DispatchNotifier::pipe_io_handler(Glib::IOCondition) // Actually, we wouldn't need the try/catch block because the Glib::Source // C callback already does it for us. However, we do it anyway because the // default return value is 'false', which is not what we want. + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED data.dispatcher->signal_(); // emit + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(...) { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED #endif /* !G_OS_WIN32 */ return true; diff --git a/glib/glibmm/dispatcher.h b/glib/glibmm/dispatcher.h index cecf606e..3cfa754d 100644 --- a/glib/glibmm/dispatcher.h +++ b/glib/glibmm/dispatcher.h @@ -67,6 +67,7 @@ public: * @throw Glib::FileError */ Dispatcher(); + /** Create new Dispatcher instance using an arbitrary main context. * @throw Glib::FileError */ diff --git a/glib/glibmm/error.cc b/glib/glibmm/error.cc index 2e8f0723..fea6d660 100644 --- a/glib/glibmm/error.cc +++ b/glib/glibmm/error.cc @@ -30,7 +30,6 @@ GLIBMM_USING_STD(map) - namespace { @@ -131,7 +130,6 @@ void Error::propagate(GError** dest) gobject_ = 0; } - // static void Error::register_init() { @@ -160,8 +158,12 @@ void Error::register_domain(GQuark domain, Error::ThrowFunc throw_func) (*throw_func_table)[domain] = throw_func; } +#ifdef GLIBMM_EXCEPTIONS_ENABLED // static, noreturn void Error::throw_exception(GError* gobject) +#else +std::auto_ptr<Glib::Error> Error::throw_exception(GError* gobject) +#endif //GLIBMM_EXCEPTIONS_ENABLED { g_assert(gobject != 0); @@ -171,7 +173,11 @@ void Error::throw_exception(GError* gobject) if(const ThrowFunc throw_func = (*throw_func_table)[gobject->domain]) { + #ifdef GLIBMM_EXCEPTIONS_ENABLED (*throw_func)(gobject); + #else + return (*throw_func)(gobject); + #endif //GLIBMM_EXCEPTIONS_ENABLED g_assert_not_reached(); } @@ -179,9 +185,14 @@ void Error::throw_exception(GError* gobject) "unknown error domain '%s': throwing generic Glib::Error exception\n", (gobject->domain) ? g_quark_to_string(gobject->domain) : "(null)"); +#ifdef GLIBMM_EXCEPTIONS_ENABLED // Doesn't copy, because error-returning functions return a newly allocated GError for us. throw Glib::Error(gobject); +#else + return std::auto_ptr<Glib::Error>(new Glib::Error(gobject)); +#endif //GLIBMM_EXCEPTIONS_ENABLED } + } // namespace Glib diff --git a/glib/glibmm/error.h b/glib/glibmm/error.h index d4c39e6d..835b026b 100644 --- a/glib/glibmm/error.h +++ b/glib/glibmm/error.h @@ -26,6 +26,12 @@ extern "C" { typedef struct _GError GError; } #include <glib/gquark.h> #include <glibmm/exception.h> +#include <glibmmconfig.h> //For GLIBMM_EXCEPTIONS_ENABLED + +#ifndef GLIBMM_EXCEPTIONS_ENABLED +//When not usinge exceptions, we pass auto_ptrs of the exceptions objects around instead. +#include <memory> //For std::auto_ptr +#endif namespace Glib @@ -56,13 +62,22 @@ public: void propagate(GError** dest); +#ifdef GLIBMM_EXCEPTIONS_ENABLED typedef void (* ThrowFunc) (GError*); +#else + //When not using exceptions, we just pass the Exception object around without throwing it: + typedef std::auto_ptr<Glib::Error> (* ThrowFunc) (GError*); +#endif //GLIBMM_EXCEPTIONS_ENABLED static void register_init(); static void register_cleanup(); static void register_domain(GQuark domain, ThrowFunc throw_func); +#ifdef GLIBMM_EXCEPTIONS_ENABLED static void throw_exception(GError* gobject) G_GNUC_NORETURN; +#else + static std::auto_ptr<Glib::Error> throw_exception(GError* gobject) G_GNUC_NORETURN; +#endif //GLIBMM_EXCEPTIONS_ENABLED #endif /* DOXYGEN_SHOULD_SKIP_THIS */ diff --git a/glib/glibmm/exceptionhandler.cc b/glib/glibmm/exceptionhandler.cc index cfe68924..c879972a 100644 --- a/glib/glibmm/exceptionhandler.cc +++ b/glib/glibmm/exceptionhandler.cc @@ -32,6 +32,7 @@ GLIBMM_USING_STD(exception) GLIBMM_USING_STD(list) +#ifdef GLIBMM_EXCEPTIONS_ENABLED namespace { @@ -157,3 +158,6 @@ void exception_handlers_invoke() throw() } // namespace Glib +#endif //GLIBMM_EXCEPTIONS_ENABLED + + diff --git a/glib/glibmm/exceptionhandler.h b/glib/glibmm/exceptionhandler.h index de1d68f4..03079399 100644 --- a/glib/glibmm/exceptionhandler.h +++ b/glib/glibmm/exceptionhandler.h @@ -24,7 +24,9 @@ */ #include <sigc++/sigc++.h> +#include <glibmmconfig.h> +#ifdef GLIBMM_EXCEPTIONS_ENABLED namespace Glib { @@ -40,6 +42,7 @@ void exception_handlers_invoke() throw(); } // namespace Glib +#endif //GLIBMM_EXCEPTIONS_ENABLED #endif /* _GLIBMM_EXCEPTIONHANDLER_H */ diff --git a/glib/glibmm/main.cc b/glib/glibmm/main.cc index f040f053..cada0401 100644 --- a/glib/glibmm/main.cc +++ b/glib/glibmm/main.cc @@ -189,15 +189,19 @@ static gboolean glibmm_source_callback(void* data) { SourceConnectionNode *const conn_data = static_cast<SourceConnectionNode*>(data); + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED // Recreate the specific slot from the generic slot node. return (*static_cast<sigc::slot<bool>*>(conn_data->get_slot()))(); + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(...) { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED return 0; } @@ -206,16 +210,20 @@ static gboolean glibmm_iosource_callback(GIOChannel*, GIOCondition condition, vo SourceCallbackData *const callback_data = static_cast<SourceCallbackData*>(data); g_return_val_if_fail(callback_data->node != 0, 0); + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED // Recreate the specific slot from the generic slot node. return (*static_cast<sigc::slot<bool, Glib::IOCondition>*>(callback_data->node->get_slot())) ((Glib::IOCondition) condition); + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(...) { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED return 0; } @@ -227,15 +235,18 @@ static gboolean glibmm_child_watch_callback(GPid pid, gint child_status, void* d { SourceConnectionNode *const conn_data = static_cast<SourceConnectionNode*>(data); + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED //Recreate the specific slot from the generic slot node. (*static_cast<sigc::slot<void, GPid, int>*>(conn_data->get_slot()))(pid, child_status); + #ifdef GLIBMM_EXCEPTIONS_ENABLED } - catch(...) { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED return 0; } @@ -806,30 +817,40 @@ Source* Source::get_wrapper(GSource* source) // static gboolean Source::prepare_vfunc(GSource* source, int* timeout) { + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED Source *const self = get_wrapper(source); return self->prepare(*timeout); + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(...) { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED + return 0; } // static gboolean Source::check_vfunc(GSource* source) { + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED Source *const self = get_wrapper(source); return self->check(); + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(...) { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED + return 0; } @@ -841,15 +862,19 @@ gboolean Source::dispatch_vfunc(GSource*, GSourceFunc callback, void* user_data) g_return_val_if_fail(callback == &glibmm_dummy_source_callback, 0); g_return_val_if_fail(callback_data != 0 && callback_data->node != 0, 0); + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED Source *const self = callback_data->wrapper; return self->dispatch(callback_data->node->get_slot()); + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(...) { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED return 0; } diff --git a/glib/glibmm/objectbase.h b/glib/glibmm/objectbase.h index 2b152fbb..75c2788b 100644 --- a/glib/glibmm/objectbase.h +++ b/glib/glibmm/objectbase.h @@ -23,6 +23,8 @@ #include <glibmm/signalproxy.h> #include <glibmm/propertyproxy.h> +#include <glibmm/ustring.h> +#include <glibmm/value.h> #include <sigc++/trackable.h> #include <typeinfo> #include <glibmmconfig.h> diff --git a/glib/glibmm/property.cc b/glib/glibmm/property.cc index 73d22ffd..f8f52b2f 100644 --- a/glib/glibmm/property.cc +++ b/glib/glibmm/property.cc @@ -19,6 +19,9 @@ */ #include <glibmm/property.h> + +#ifdef GLIBMM_PROPERTIES_ENABLED + #include <glibmm/object.h> #include <cstddef> @@ -196,3 +199,5 @@ void PropertyBase::notify() } // namespace Glib +#endif //GLIBMM_PROPERTIES_ENABLED + diff --git a/glib/glibmm/property.h b/glib/glibmm/property.h index f25ef84d..2b524f9b 100644 --- a/glib/glibmm/property.h +++ b/glib/glibmm/property.h @@ -21,8 +21,10 @@ */ #include <glibmm/propertyproxy.h> -#include <glibmm/value.h> +#ifdef GLIBMM_PROPERTIES_ENABLED + +#include <glibmm/value.h> namespace Glib { @@ -166,6 +168,7 @@ Glib::PropertyProxy<T> Property<T>::get_proxy() } // namespace Glib +#endif //GLIBMM_PROPERTIES_ENABLED #endif /* _GLIBMM_PROPERTY_H */ diff --git a/glib/glibmm/propertyproxy.h b/glib/glibmm/propertyproxy.h index e21c4b25..392f5c24 100644 --- a/glib/glibmm/propertyproxy.h +++ b/glib/glibmm/propertyproxy.h @@ -24,6 +24,7 @@ #include <glibmm/propertyproxy_base.h> +#ifdef GLIBMM_PROPERTIES_ENABLED namespace Glib { @@ -174,6 +175,7 @@ T PropertyProxy_ReadOnly<T>::get_value() const } // namespace Glib +#endif //GLIBMM_PROPERTIES_ENABLED #endif /* _GLIBMM_PROPERTYPROXY_H */ diff --git a/glib/glibmm/propertyproxy_base.cc b/glib/glibmm/propertyproxy_base.cc index d10c8cd3..d542c193 100644 --- a/glib/glibmm/propertyproxy_base.cc +++ b/glib/glibmm/propertyproxy_base.cc @@ -21,6 +21,9 @@ */ #include <glibmm/propertyproxy_base.h> + +#ifdef GLIBMM_PROPERTIES_ENABLED + #include <glibmm/signalproxy_connectionnode.h> #include <glibmm/object.h> #include <glibmm/private/object_p.h> @@ -149,3 +152,4 @@ void PropertyProxy_Base::reset_property_() } // namespace Glib +#endif //GLIBMM_PROPERTIES_ENABLED diff --git a/glib/glibmm/propertyproxy_base.h b/glib/glibmm/propertyproxy_base.h index 036291df..5f7f8743 100644 --- a/glib/glibmm/propertyproxy_base.h +++ b/glib/glibmm/propertyproxy_base.h @@ -22,10 +22,13 @@ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include <glibmmconfig.h> + +#ifdef GLIBMM_PROPERTIES_ENABLED + #include <glibmm/value.h> #include <glibmm/signalproxy.h> - namespace Glib { @@ -80,5 +83,7 @@ private: } // namespace Glib +#endif //GLIBMM_PROPERTIES_ENABLED + #endif /* _GLIBMM_PROPERTYPROXY_BASE_H */ diff --git a/glib/glibmm/signalproxy.cc b/glib/glibmm/signalproxy.cc index 67f7a929..6b6ed645 100644 --- a/glib/glibmm/signalproxy.cc +++ b/glib/glibmm/signalproxy.cc @@ -89,15 +89,19 @@ void SignalProxyNormal::slot0_void_callback(GObject* self, void* data) // Do not try to call a signal on a disassociated wrapper. if(Glib::ObjectBase::_get_current_wrapper(self)) { + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED if(sigc::slot_base *const slot = data_to_slot(data)) (*static_cast<sigc::slot<void>*>(slot))(); + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(...) { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED } } diff --git a/glib/glibmm/streamiochannel.cc b/glib/glibmm/streamiochannel.cc index 985931de..e535cecd 100644 --- a/glib/glibmm/streamiochannel.cc +++ b/glib/glibmm/streamiochannel.cc @@ -69,7 +69,13 @@ IOStatus StreamIOChannel::read_vfunc(char* buf, gsize count, gsize& bytes_read) return IO_STATUS_EOF; if(stream_in_->fail()) + { + #ifdef GLIBMM_EXCEPTIONS_ENABLED throw Glib::Error(G_IO_CHANNEL_ERROR, G_IO_CHANNEL_ERROR_FAILED, "Reading from stream failed"); + #else + return IO_STATUS_ERROR; + #endif //GLIBMM_EXCEPTIONS_ENABLED + } return IO_STATUS_NORMAL; } @@ -84,7 +90,13 @@ IOStatus StreamIOChannel::write_vfunc(const char* buf, gsize count, gsize& bytes stream_out_->write(buf, count); if(stream_out_->fail()) + { + #ifdef GLIBMM_EXCEPTIONS_ENABLED throw Glib::Error(G_IO_CHANNEL_ERROR, G_IO_CHANNEL_ERROR_FAILED, "Writing to stream failed"); + #else + return IO_STATUS_ERROR; + #endif //GLIBMM_EXCEPTIONS_ENABLED + } bytes_written = count; // all or nothing ;) @@ -118,7 +130,13 @@ IOStatus StreamIOChannel::seek_vfunc(gint64 offset, SeekType type) } if(failed) + { + #ifdef GLIBMM_EXCEPTIONS_ENABLED throw Glib::Error(G_IO_CHANNEL_ERROR, G_IO_CHANNEL_ERROR_FAILED, "Seeking into stream failed"); + #else + return IO_STATUS_ERROR; + #endif //GLIBMM_EXCEPTIONS_ENABLED + } return Glib::IO_STATUS_NORMAL; } @@ -147,12 +165,22 @@ IOStatus StreamIOChannel::close_vfunc() } else { + #ifdef GLIBMM_EXCEPTIONS_ENABLED throw Glib::Error(G_IO_CHANNEL_ERROR, G_IO_CHANNEL_ERROR_FAILED, "Attempt to close non-file stream"); + #else + return IO_STATUS_ERROR; + #endif //GLIBMM_EXCEPTIONS_ENABLED } if(failed) + { + #ifdef GLIBMM_EXCEPTIONS_ENABLED throw Glib::Error(G_IO_CHANNEL_ERROR, G_IO_CHANNEL_ERROR_FAILED, "Failed to close stream"); + #else + return IO_STATUS_ERROR; + #endif //GLIBMM_EXCEPTIONS_ENABLED + } return IO_STATUS_NORMAL; } diff --git a/glib/glibmm/stringutils.cc b/glib/glibmm/stringutils.cc index 7113c014..7a464138 100644 --- a/glib/glibmm/stringutils.cc +++ b/glib/glibmm/stringutils.cc @@ -51,7 +51,13 @@ double Glib::Ascii::strtod(const std::string& str, std::string::size_type start_index) { if(start_index > str.size()) + { + #ifdef GLIBMM_EXCEPTIONS_ENABLED throw std::out_of_range("out of range (strtod): start_index > str.size()"); + #else + return 0; + #endif //GLIBMM_EXCEPTIONS_ENABLED + } const char *const bufptr = str.c_str(); char* endptr = 0; @@ -63,6 +69,8 @@ double Glib::Ascii::strtod(const std::string& str, { g_return_val_if_fail(err_no == ERANGE, result); + #ifdef GLIBMM_EXCEPTIONS_ENABLED + //Interpret the result in the event of an error: if(result > 0.0) throw std::overflow_error("overflow (strtod): positive number too large"); @@ -70,6 +78,9 @@ double Glib::Ascii::strtod(const std::string& str, throw std::overflow_error("overflow (strtod): negative number too large"); throw std::underflow_error("underflow (strtod): number too small"); + #else + return result; + #endif // GLIBMM_EXCEPTIONS_ENABLED } if(endptr) diff --git a/glib/glibmm/threadpool.cc b/glib/glibmm/threadpool.cc index db9b089c..556eeb72 100644 --- a/glib/glibmm/threadpool.cc +++ b/glib/glibmm/threadpool.cc @@ -100,14 +100,17 @@ namespace static void call_thread_entry_slot(void* data, void* user_data) { + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED Glib::ThreadPool::SlotList *const slot_list = static_cast<Glib::ThreadPool::SlotList*>(user_data); sigc::slot<void> slot (slot_list->pop(static_cast<sigc::slot<void>*>(data))); slot(); + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(Glib::Thread::Exit&) { @@ -118,6 +121,7 @@ static void call_thread_entry_slot(void* data, void* user_data) { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED } } // anonymous namespace diff --git a/glib/glibmm/ustring.cc b/glib/glibmm/ustring.cc index 788658ae..36d709da 100644 --- a/glib/glibmm/ustring.cc +++ b/glib/glibmm/ustring.cc @@ -1193,13 +1193,25 @@ std::istream& operator>>(std::istream& is, Glib::ustring& utf8_string) { std::string locale_string; is >> locale_string; + + #ifdef GLIBMM_EXCEPTIONS_ENABLED utf8_string = Glib::locale_to_utf8(locale_string); + #else + std::auto_ptr<Glib::Error> error; //TODO: Check this? + utf8_string = Glib::locale_to_utf8(locale_string, error); + #endif //GLIBMM_EXCEPTIONS_ENABLED return is; } std::ostream& operator<<(std::ostream& os, const Glib::ustring& utf8_string) { + #ifdef GLIBMM_EXCEPTIONS_ENABLED os << Glib::locale_from_utf8(utf8_string); + #else + std::auto_ptr<Glib::Error> error; //TODO: Check this? + os << Glib::locale_from_utf8(utf8_string, error); + #endif //GLIBMM_EXCEPTIONS_ENABLED + return os; } diff --git a/glib/glibmm/value.cc b/glib/glibmm/value.cc index 12ba6fc9..adb3e902 100644 --- a/glib/glibmm/value.cc +++ b/glib/glibmm/value.cc @@ -39,14 +39,6 @@ void ValueBase::init(GType type) g_value_init(&gobject_, type); } -void ValueBase::init(const GValue* value) -{ - g_value_init(&gobject_, G_VALUE_TYPE(value)); - - if(value) - g_value_copy(value, &gobject_); -} - ValueBase::ValueBase(const ValueBase& other) { GLIBMM_INITIALIZE_STRUCT(gobject_, GValue); diff --git a/glib/glibmm/value.h b/glib/glibmm/value.h index a891418c..94203a32 100644 --- a/glib/glibmm/value.h +++ b/glib/glibmm/value.h @@ -69,21 +69,9 @@ public: * * init() is not implemented as constructor, to avoid the necessity * to implement a forward constructor in each derived class. - * - * @param type The type that the Value should hold. */ void init(GType type); - /** Setup the GValue storing the type and value of the specified @a value. - * Note that init() should never be called twice. - * - * init() is not implemented as constructor, to avoid the necessity - * to implement a forward constructor in each derived class. - * - * @param value The existing GValue. - */ - void init(const GValue* value); - /** Reset contents to the default value of its type. */ void reset(); diff --git a/glib/glibmmconfig.h.in b/glib/glibmmconfig.h.in index d3081cae..292b0f23 100644 --- a/glib/glibmmconfig.h.in +++ b/glib/glibmmconfig.h.in @@ -28,9 +28,6 @@ #endif /* _WIN32 */ #ifdef GLIBMM_CONFIGURE -/* compiler feature tests that are used during compile time and run-time - by gtk-- only. tests used by gdk-- and gtk-- should go into - gdk--config.h.in */ #undef GLIBMM_CXX_HAVE_MUTABLE #undef GLIBMM_CXX_HAVE_NAMESPACES //#undef GLIBMM_CXX_GAUB @@ -46,6 +43,9 @@ #undef GLIBMM_CAN_ASSIGN_NON_EXTERN_C_FUNCTIONS_TO_EXTERN_C_CALLBACKS #undef GLIBMM_CAN_USE_NAMESPACES_INSIDE_EXTERNC #undef GLIBMM_HAVE_ALLOWS_STATIC_INLINE_NPOS +#undef GLIBMM_PROPERTIES_ENABLED +#undef GLIBMM_VFUNCS_ENABLED +#undef GLIBMM_EXCEPTIONS_ENABLED #endif #ifdef GLIBMM_MSC @@ -58,6 +58,9 @@ #define GLIBMM_CAN_USE_DYNAMIC_CAST_IN_UNUSED_TEMPLATE_WITHOUT_DEFINITION 1 #define GLIBMM_CAN_ASSIGN_NON_EXTERN_C_FUNCTIONS_TO_EXTERN_C_CALLBACKS 1 #define GLIBMM_CAN_USE_NAMESPACES_INSIDE_EXTERNC 1 + #define GLIBMM_PROPERTIES_ENABLED 1 + #define GLIBMM_VFUNCS_ENABLED 1 + #define GLIBMM_EXCEPTIONS_ENABLED 1 #pragma warning (disable: 4786 4355 4800 4181) #endif diff --git a/glib/src/convert.ccg b/glib/src/convert.ccg index b888e8d5..9a4dae14 100644 --- a/glib/src/convert.ccg +++ b/glib/src/convert.ccg @@ -35,17 +35,19 @@ IConv::IConv(const std::string& to_codeset, const std::string& from_codeset) { if(gobject_ == reinterpret_cast<GIConv>(-1)) { - GError* error = 0; + GError* gerror = 0; // Abuse g_convert() to create a GError object. This may seem a weird // thing to do, but it gives us consistently translated error messages // at no further cost. - g_convert("", 0, to_codeset.c_str(), from_codeset.c_str(), 0, 0, &error); + g_convert("", 0, to_codeset.c_str(), from_codeset.c_str(), 0, 0, &gerror); // If this should ever fail we're fucked. - g_assert(error != 0); + g_assert(gerror != 0); - Error::throw_exception(error); + #ifdef GLIBMM_EXCEPTIONS_ENABLED + if(gerror) ::Glib::Error::throw_exception(gerror); + #endif //GLIBMM_EXCEPTIONS_ENABLED } } @@ -77,16 +79,23 @@ void IConv::reset() g_iconv(gobject_, 0, &inbytes_left, &outbuf, &outbytes_left); } +#ifdef GLIBMM_EXCEPTIONS_ENABLED std::string IConv::convert(const std::string& str) +#else +std::string IConv::convert(const std::string& str, std::auto_ptr<Glib::Error>& error) +#endif //GLIBMM_EXCEPTIONS_ENABLED { gsize bytes_written = 0; - GError* error = 0; + GError* gerror = 0; char *const buf = g_convert_with_iconv( - str.data(), str.size(), gobject_, 0, &bytes_written, &error); + str.data(), str.size(), gobject_, 0, &bytes_written, &gerror); - if(error) - Error::throw_exception(error); + #ifdef GLIBMM_EXCEPTIONS_ENABLED + if(gerror) ::Glib::Error::throw_exception(gerror); + #else + error = ::Glib::Error::throw_exception(gerror); + #endif //GLIBMM_EXCEPTIONS_ENABLED return std::string(ScopedPtr<char>(buf).get(), bytes_written); } @@ -108,125 +117,196 @@ bool get_charset(std::string& charset) return is_utf8; } + +#ifdef GLIBMM_EXCEPTIONS_ENABLED std::string convert(const std::string& str, const std::string& to_codeset, const std::string& from_codeset) +#else +std::string convert(const std::string& str, + const std::string& to_codeset, + const std::string& from_codeset, std::auto_ptr<Glib::Error>& error) +#endif //GLIBMM_EXCEPTIONS_ENABLED { gsize bytes_written = 0; - GError* error = 0; + GError* gerror = 0; char *const buf = g_convert( str.data(), str.size(), to_codeset.c_str(), from_codeset.c_str(), - 0, &bytes_written, &error); + 0, &bytes_written, &gerror); - if(error) - Error::throw_exception(error); + #ifdef GLIBMM_EXCEPTIONS_ENABLED + if(gerror) ::Glib::Error::throw_exception(gerror); + #else + error = ::Glib::Error::throw_exception(gerror); + #endif //GLIBMM_EXCEPTIONS_ENABLED return std::string(ScopedPtr<char>(buf).get(), bytes_written); } + +#ifdef GLIBMM_EXCEPTIONS_ENABLED std::string convert_with_fallback(const std::string& str, const std::string& to_codeset, const std::string& from_codeset) +#else +std::string convert_with_fallback(const std::string& str, + const std::string& to_codeset, + const std::string& from_codeset, std::auto_ptr<Glib::Error>& error) +#endif //GLIBMM_EXCEPTIONS_ENABLED { gsize bytes_written = 0; - GError* error = 0; + GError* gerror = 0; char *const buf = g_convert_with_fallback( str.data(), str.size(), to_codeset.c_str(), from_codeset.c_str(), 0, - 0, &bytes_written, &error); + 0, &bytes_written, &gerror); - if(error) - Error::throw_exception(error); + #ifdef GLIBMM_EXCEPTIONS_ENABLED + if(gerror) ::Glib::Error::throw_exception(gerror); + #else + error = ::Glib::Error::throw_exception(gerror); + #endif //GLIBMM_EXCEPTIONS_ENABLED return std::string(ScopedPtr<char>(buf).get(), bytes_written); } + +#ifdef GLIBMM_EXCEPTIONS_ENABLED std::string convert_with_fallback(const std::string& str, const std::string& to_codeset, const std::string& from_codeset, const Glib::ustring& fallback) +#else +std::string convert_with_fallback(const std::string& str, + const std::string& to_codeset, + const std::string& from_codeset, + const Glib::ustring& fallback, std::auto_ptr<Glib::Error>& error) +#endif //GLIBMM_EXCEPTIONS_ENABLED { gsize bytes_written = 0; - GError* error = 0; + GError* gerror = 0; char *const buf = g_convert_with_fallback( str.data(), str.size(), to_codeset.c_str(), from_codeset.c_str(), - const_cast<char*>(fallback.c_str()), 0, &bytes_written, &error); + const_cast<char*>(fallback.c_str()), 0, &bytes_written, &gerror); - if(error) - Error::throw_exception(error); + #ifdef GLIBMM_EXCEPTIONS_ENABLED + if(gerror) ::Glib::Error::throw_exception(gerror); + #else + error = ::Glib::Error::throw_exception(gerror); + #endif //GLIBMM_EXCEPTIONS_ENABLED return std::string(ScopedPtr<char>(buf).get(), bytes_written); } + +#ifdef GLIBMM_EXCEPTIONS_ENABLED Glib::ustring locale_to_utf8(const std::string& opsys_string) +#else +Glib::ustring locale_to_utf8(const std::string& opsys_string, std::auto_ptr<Glib::Error>& error) +#endif //GLIBMM_EXCEPTIONS_ENABLED { gsize bytes_written = 0; - GError* error = 0; + GError* gerror = 0; char *const buf = g_locale_to_utf8( - opsys_string.data(), opsys_string.size(), 0, &bytes_written, &error); + opsys_string.data(), opsys_string.size(), 0, &bytes_written, &gerror); - if(error) - Error::throw_exception(error); + #ifdef GLIBMM_EXCEPTIONS_ENABLED + if(gerror) ::Glib::Error::throw_exception(gerror); + #else + error = ::Glib::Error::throw_exception(gerror); + #endif //GLIBMM_EXCEPTIONS_ENABLED const ScopedPtr<char> scoped_buf (buf); return Glib::ustring(scoped_buf.get(), scoped_buf.get() + bytes_written); } + +#ifdef GLIBMM_EXCEPTIONS_ENABLED std::string locale_from_utf8(const Glib::ustring& utf8_string) +#else +std::string locale_from_utf8(const Glib::ustring& utf8_string, std::auto_ptr<Glib::Error>& error) +#endif //GLIBMM_EXCEPTIONS_ENABLED { gsize bytes_written = 0; - GError* error = 0; + GError* gerror = 0; char *const buf = g_locale_from_utf8( - utf8_string.data(), utf8_string.bytes(), 0, &bytes_written, &error); + utf8_string.data(), utf8_string.bytes(), 0, &bytes_written, &gerror); - if(error) - Error::throw_exception(error); + #ifdef GLIBMM_EXCEPTIONS_ENABLED + if(gerror) ::Glib::Error::throw_exception(gerror); + #else + error = ::Glib::Error::throw_exception(gerror); + #endif //GLIBMM_EXCEPTIONS_ENABLED return std::string(ScopedPtr<char>(buf).get(), bytes_written); } + +#ifdef GLIBMM_EXCEPTIONS_ENABLED Glib::ustring filename_to_utf8(const std::string& opsys_string) +#else +Glib::ustring filename_to_utf8(const std::string& opsys_string, std::auto_ptr<Glib::Error>& error) +#endif //GLIBMM_EXCEPTIONS_ENABLED { gsize bytes_written = 0; - GError* error = 0; + GError* gerror = 0; char *const buf = g_filename_to_utf8( - opsys_string.data(), opsys_string.size(), 0, &bytes_written, &error); + opsys_string.data(), opsys_string.size(), 0, &bytes_written, &gerror); - if(error) - Error::throw_exception(error); + #ifdef GLIBMM_EXCEPTIONS_ENABLED + if(gerror) ::Glib::Error::throw_exception(gerror); + #else + error = ::Glib::Error::throw_exception(gerror); + #endif //GLIBMM_EXCEPTIONS_ENABLED const ScopedPtr<char> scoped_buf (buf); return Glib::ustring(scoped_buf.get(), scoped_buf.get() + bytes_written); } + +#ifdef GLIBMM_EXCEPTIONS_ENABLED std::string filename_from_utf8(const Glib::ustring& utf8_string) +#else +std::string filename_from_utf8(const Glib::ustring& utf8_string, std::auto_ptr<Glib::Error>& error) +#endif //GLIBMM_EXCEPTIONS_ENABLED { gsize bytes_written = 0; - GError* error = 0; + GError* gerror = 0; char *const buf = g_filename_from_utf8( - utf8_string.data(), utf8_string.bytes(), 0, &bytes_written, &error); + utf8_string.data(), utf8_string.bytes(), 0, &bytes_written, &gerror); - if(error) - Error::throw_exception(error); + #ifdef GLIBMM_EXCEPTIONS_ENABLED + if(gerror) ::Glib::Error::throw_exception(gerror); + #else + error = ::Glib::Error::throw_exception(gerror); + #endif //GLIBMM_EXCEPTIONS_ENABLED return std::string(ScopedPtr<char>(buf).get(), bytes_written); } + +#ifdef GLIBMM_EXCEPTIONS_ENABLED std::string filename_from_uri(const Glib::ustring& uri, Glib::ustring& hostname) +#else +std::string filename_from_uri(const Glib::ustring& uri, Glib::ustring& hostname, std::auto_ptr<Glib::Error>& error) +#endif //GLIBMM_EXCEPTIONS_ENABLED { char* hostname_buf = 0; - GError* error = 0; + GError* gerror = 0; - char *const buf = g_filename_from_uri(uri.c_str(), &hostname_buf, &error); + char *const buf = g_filename_from_uri(uri.c_str(), &hostname_buf, &gerror); - if(error) - Error::throw_exception(error); + #ifdef GLIBMM_EXCEPTIONS_ENABLED + if(gerror) ::Glib::Error::throw_exception(gerror); + #else + error = ::Glib::Error::throw_exception(gerror); + #endif //GLIBMM_EXCEPTIONS_ENABLED // Let's take ownership at this point. const ScopedPtr<char> scoped_buf (buf); @@ -239,35 +319,59 @@ std::string filename_from_uri(const Glib::ustring& uri, Glib::ustring& hostname) return std::string(scoped_buf.get()); } + +#ifdef GLIBMM_EXCEPTIONS_ENABLED std::string filename_from_uri(const Glib::ustring& uri) +#else +std::string filename_from_uri(const Glib::ustring& uri, std::auto_ptr<Glib::Error>& error) +#endif //GLIBMM_EXCEPTIONS_ENABLED { - GError* error = 0; - char *const buf = g_filename_from_uri(uri.c_str(), 0, &error); + GError* gerror = 0; + char *const buf = g_filename_from_uri(uri.c_str(), 0, &gerror); - if(error) - Error::throw_exception(error); + #ifdef GLIBMM_EXCEPTIONS_ENABLED + if(gerror) ::Glib::Error::throw_exception(gerror); + #else + error = ::Glib::Error::throw_exception(gerror); + #endif //GLIBMM_EXCEPTIONS_ENABLED return std::string(ScopedPtr<char>(buf).get()); } + +#ifdef GLIBMM_EXCEPTIONS_ENABLED Glib::ustring filename_to_uri(const std::string& filename, const Glib::ustring& hostname) +#else +Glib::ustring filename_to_uri(const std::string& filename, const Glib::ustring& hostname, std::auto_ptr<Glib::Error>& error) +#endif //GLIBMM_EXCEPTIONS_ENABLED { - GError* error = 0; - char *const buf = g_filename_to_uri(filename.c_str(), hostname.c_str(), &error); + GError* gerror = 0; + char *const buf = g_filename_to_uri(filename.c_str(), hostname.c_str(), &gerror); - if(error) - Error::throw_exception(error); + #ifdef GLIBMM_EXCEPTIONS_ENABLED + if(gerror) ::Glib::Error::throw_exception(gerror); + #else + error = ::Glib::Error::throw_exception(gerror); + #endif //GLIBMM_EXCEPTIONS_ENABLED return Glib::ustring(ScopedPtr<char>(buf).get()); } + +#ifdef GLIBMM_EXCEPTIONS_ENABLED Glib::ustring filename_to_uri(const std::string& filename) +#else +Glib::ustring filename_to_uri(const std::string& filename, std::auto_ptr<Glib::Error>& error) +#endif //GLIBMM_EXCEPTIONS_ENABLED { - GError* error = 0; - char *const buf = g_filename_to_uri(filename.c_str(), 0, &error); - - if(error) - Error::throw_exception(error); + GError* gerror = 0; + char *const buf = g_filename_to_uri(filename.c_str(), 0, &gerror); + + #ifdef GLIBMM_EXCEPTIONS_ENABLED + if(gerror) ::Glib::Error::throw_exception(gerror); + #else + error = ::Glib::Error::throw_exception(gerror); + #endif //GLIBMM_EXCEPTIONS_ENABLED return Glib::ustring(ScopedPtr<char>(buf).get()); } diff --git a/glib/src/convert.hg b/glib/src/convert.hg index 8c206d26..cfa326bf 100644 --- a/glib/src/convert.hg +++ b/glib/src/convert.hg @@ -92,7 +92,11 @@ public: * @return The converted string. * @throw Glib::ConvertError */ + #ifdef GLIBMM_EXCEPTIONS_ENABLED std::string convert(const std::string& str); + #else + std::string convert(const std::string& str, std::auto_ptr<Glib::Error>& error); + #endif //GLIBMM_EXCEPTIONS_ENABLED GIConv gobj() { return gobject_; } @@ -123,9 +127,15 @@ bool get_charset(std::string& charset); * @return The converted string. * @throw Glib::ConvertError */ +#ifdef GLIBMM_EXCEPTIONS_ENABLED std::string convert(const std::string& str, const std::string& to_codeset, const std::string& from_codeset); +#else +std::string convert(const std::string& str, + const std::string& to_codeset, + const std::string& from_codeset, std::auto_ptr<Glib::Error>& error); +#endif //GLIBMM_EXCEPTIONS_ENABLED /** Converts a string from one character set to another, possibly including * fallback sequences for characters not representable in the output. @@ -137,9 +147,15 @@ std::string convert(const std::string& str, * @return The converted string. * @throw Glib::ConvertError */ +#ifdef GLIBMM_EXCEPTIONS_ENABLED std::string convert_with_fallback(const std::string& str, const std::string& to_codeset, const std::string& from_codeset); +#else +std::string convert_with_fallback(const std::string& str, + const std::string& to_codeset, + const std::string& from_codeset, std::auto_ptr<Glib::Error>& error); +#endif //GLIBMM_EXCEPTIONS_ENABLED /** Converts a string from one character set to another, possibly including * fallback sequences for characters not representable in the output. @@ -157,10 +173,17 @@ std::string convert_with_fallback(const std::string& str, * @return The converted string. * @throw Glib::ConvertError */ +#ifdef GLIBMM_EXCEPTIONS_ENABLED std::string convert_with_fallback(const std::string& str, const std::string& to_codeset, const std::string& from_codeset, const Glib::ustring& fallback); +#else +std::string convert_with_fallback(const std::string& str, + const std::string& to_codeset, + const std::string& from_codeset, + const Glib::ustring& fallback, std::auto_ptr<Glib::Error>& error); +#endif //GLIBMM_EXCEPTIONS_ENABLED /** Convert from the current locale's encoding to UTF-8. * Convenience wrapper around Glib::convert(). @@ -169,7 +192,11 @@ std::string convert_with_fallback(const std::string& str, * @return The input string converted to UTF-8 encoding. * @throw Glib::ConvertError */ +#ifdef GLIBMM_EXCEPTIONS_ENABLED Glib::ustring locale_to_utf8(const std::string& opsys_string); +#else +Glib::ustring locale_to_utf8(const std::string& opsys_string, std::auto_ptr<Glib::Error>& error); +#endif //GLIBMM_EXCEPTIONS_ENABLED /** Convert from UTF-8 to the current locale's encoding. * Convenience wrapper around Glib::convert(). @@ -178,7 +205,11 @@ Glib::ustring locale_to_utf8(const std::string& opsys_string); * system's current locale. * @throw Glib::ConvertError */ +#ifdef GLIBMM_EXCEPTIONS_ENABLED std::string locale_from_utf8(const Glib::ustring& utf8_string); +#else +std::string locale_from_utf8(const Glib::ustring& utf8_string, std::auto_ptr<Glib::Error>& error); +#endif //GLIBMM_EXCEPTIONS_ENABLED /** Converts a string which is in the encoding used for filenames into * a UTF-8 string. @@ -186,14 +217,22 @@ std::string locale_from_utf8(const Glib::ustring& utf8_string); * @return The converted string. * @throw Glib::ConvertError */ +#ifdef GLIBMM_EXCEPTIONS_ENABLED Glib::ustring filename_to_utf8(const std::string& opsys_string); +#else +Glib::ustring filename_to_utf8(const std::string& opsys_string, std::auto_ptr<Glib::Error>& error); +#endif //GLIBMM_EXCEPTIONS_ENABLED /** Converts a string from UTF-8 to the encoding used for filenames. * @param utf8_string A UTF-8 encoded string. * @return The converted string. * @throw Glib::ConvertError */ +#ifdef GLIBMM_EXCEPTIONS_ENABLED std::string filename_from_utf8(const Glib::ustring& utf8_string); +#else +std::string filename_from_utf8(const Glib::ustring& utf8_string, std::auto_ptr<Glib::Error>& error); +#endif //GLIBMM_EXCEPTIONS_ENABLED /** Converts an escaped UTF-8 encoded URI to a local filename * in the encoding used for filenames. @@ -203,7 +242,11 @@ std::string filename_from_utf8(const Glib::ustring& utf8_string); * @return The resulting filename. * @throw Glib::ConvertError */ +#ifdef GLIBMM_EXCEPTIONS_ENABLED std::string filename_from_uri(const Glib::ustring& uri, Glib::ustring& hostname); +#else +std::string filename_from_uri(const Glib::ustring& uri, Glib::ustring& hostname, std::auto_ptr<Glib::Error>& error); +#endif //GLIBMM_EXCEPTIONS_ENABLED /** Converts an escaped UTF-8 encoded URI to a local filename in the encoding * used for filenames. @@ -211,7 +254,11 @@ std::string filename_from_uri(const Glib::ustring& uri, Glib::ustring& hostname) * @return The resulting filename. * @throw Glib::ConvertError */ +#ifdef GLIBMM_EXCEPTIONS_ENABLED std::string filename_from_uri(const Glib::ustring& uri); +#else +std::string filename_from_uri(const Glib::ustring& uri, std::auto_ptr<Glib::Error>& error); +#endif //GLIBMM_EXCEPTIONS_ENABLED /** Converts an absolute filename to an escaped UTF-8 encoded URI. * @param filename An absolute filename specified in the encoding used @@ -220,7 +267,11 @@ std::string filename_from_uri(const Glib::ustring& uri); * @return The resulting URI. * @throw Glib::ConvertError */ +#ifdef GLIBMM_EXCEPTIONS_ENABLED Glib::ustring filename_to_uri(const std::string& filename, const Glib::ustring& hostname); +#else +Glib::ustring filename_to_uri(const std::string& filename, const Glib::ustring& hostname, std::auto_ptr<Glib::Error>& error); +#endif //GLIBMM_EXCEPTIONS_ENABLED /** Converts an absolute filename to an escaped UTF-8 encoded URI. * @param filename An absolute filename specified in the encoding used @@ -228,7 +279,11 @@ Glib::ustring filename_to_uri(const std::string& filename, const Glib::ustring& * @return The resulting URI. * @throw Glib::ConvertError */ +#ifdef GLIBMM_EXCEPTIONS_ENABLED Glib::ustring filename_to_uri(const std::string& filename); +#else +Glib::ustring filename_to_uri(const std::string& filename, std::auto_ptr<Glib::Error>& error); +#endif //GLIBMM_EXCEPTIONS_ENABLED /** Returns the display basename for the particular filename, guaranteed * to be valid UTF-8. The display name might not be identical to the filename, diff --git a/glib/src/date.ccg b/glib/src/date.ccg index e70a0e26..b59810ab 100644 --- a/glib/src/date.ccg +++ b/glib/src/date.ccg @@ -280,7 +280,13 @@ Glib::ustring Date::format_string(const Glib::ustring& format) const struct tm tm_data; g_date_to_struct_tm(&gobject_, &tm_data); + #ifdef GLIBMM_EXCEPTIONS_ENABLED const std::string locale_format = locale_from_utf8(format); + #else + std::auto_ptr<Glib::Error> error; //TODO: Check it? + const std::string locale_format = locale_from_utf8(format, error); + #endif //GLIBMM_EXCEPTIONS_ENABLED + gsize bufsize = std::max<gsize>(2 * locale_format.size(), 128); do @@ -295,7 +301,12 @@ Glib::ustring Date::format_string(const Glib::ustring& format) const if(len != 0 || buf.get()[0] == '\0') { g_assert(len < bufsize); + #ifdef GLIBMM_EXCEPTIONS_ENABLED return locale_to_utf8(std::string(buf.get(), len)); + #else + std::auto_ptr<Glib::Error> error; //TODO: Check it? + return locale_to_utf8(std::string(buf.get(), len), error); + #endif //GLIBMM_EXCEPTIONS_ENABLED } } while((bufsize *= 2) <= 65536); diff --git a/glib/src/iochannel.ccg b/glib/src/iochannel.ccg index 6e637079..03783a4a 100644 --- a/glib/src/iochannel.ccg +++ b/glib/src/iochannel.ccg @@ -171,13 +171,23 @@ IOChannel::~IOChannel() } } +#ifdef GLIBMM_EXCEPTIONS_ENABLED Glib::RefPtr<IOChannel> IOChannel::create_from_file(const std::string& filename, const std::string& mode) +#else +Glib::RefPtr<IOChannel> IOChannel::create_from_file(const std::string& filename, const std::string& mode, std::auto_ptr<Glib::Error>& error) +#endif //GLIBMM_EXCEPTIONS_ENABLED { - GError* error = 0; - GIOChannel *const channel = g_io_channel_new_file(filename.c_str(), mode.c_str(), &error); + GError* gerror = 0; + GIOChannel *const channel = g_io_channel_new_file(filename.c_str(), mode.c_str(), &gerror); - if(error) - Glib::Error::throw_exception(error); + if(gerror) + { + #ifdef GLIBMM_EXCEPTIONS_ENABLED + Glib::Error::throw_exception(gerror); + #else + error = Glib::Error::throw_exception(gerror); + #endif //GLIBMM_EXCEPTIONS_ENABLED + } return Glib::wrap(channel, false); } @@ -201,22 +211,40 @@ Glib::RefPtr<IOChannel> IOChannel::create_from_win32_socket(int socket) #endif /* G_OS_WIN32 */ +#ifdef GLIBMM_EXCEPTIONS_ENABLED IOStatus IOChannel::write(const Glib::ustring& str) +#else +IOStatus IOChannel::write(const Glib::ustring& str, std::auto_ptr<Glib::Error>& error) +#endif //GLIBMM_EXCEPTIONS_ENABLED { gsize bytes_written = 0; +#ifdef GLIBMM_EXCEPTIONS_ENABLED return write(str.data(), str.bytes(), bytes_written); +#else + return write(str.data(), str.bytes(), bytes_written, error); +#endif //GLIBMM_EXCEPTIONS_ENABLED } +#ifdef GLIBMM_EXCEPTIONS_ENABLED IOStatus IOChannel::read_line(Glib::ustring& line) +#else +IOStatus IOChannel::read_line(Glib::ustring& line, std::auto_ptr<Glib::Error>& error) +#endif //GLIBMM_EXCEPTIONS_ENABLED { Glib::ScopedPtr<char> buf; - GError* error = 0; + GError* gerror = 0; gsize bytes = 0; - const GIOStatus status = g_io_channel_read_line(gobj(), buf.addr(), &bytes, 0, &error); + const GIOStatus status = g_io_channel_read_line(gobj(), buf.addr(), &bytes, 0, &gerror); - if(error) - Glib::Error::throw_exception(error); + if(gerror) + { + #ifdef GLIBMM_EXCEPTIONS_ENABLED + Glib::Error::throw_exception(gerror); + #else + error = Glib::Error::throw_exception(gerror); + #endif //GLIBMM_EXCEPTIONS_ENABLED + } if(buf.get()) line.assign(buf.get(), buf.get() + bytes); @@ -226,16 +254,26 @@ IOStatus IOChannel::read_line(Glib::ustring& line) return (IOStatus) status; } +#ifdef GLIBMM_EXCEPTIONS_ENABLED IOStatus IOChannel::read_to_end(Glib::ustring& str) +#else +IOStatus IOChannel::read_to_end(Glib::ustring& str, std::auto_ptr<Glib::Error>& error) +#endif //GLIBMM_EXCEPTIONS_ENABLED { Glib::ScopedPtr<char> buf; - GError* error = 0; + GError* gerror = 0; gsize bytes = 0; - const GIOStatus status = g_io_channel_read_to_end(gobj(), buf.addr(), &bytes, &error); + const GIOStatus status = g_io_channel_read_to_end(gobj(), buf.addr(), &bytes, &gerror); - if(error) - Glib::Error::throw_exception(error); + if(gerror) + { + #ifdef GLIBMM_EXCEPTIONS_ENABLED + Glib::Error::throw_exception(gerror); + #else + error = Glib::Error::throw_exception(gerror); + #endif //GLIBMM_EXCEPTIONS_ENABLED + } if(buf.get()) str.assign(buf.get(), buf.get() + bytes); @@ -245,16 +283,26 @@ IOStatus IOChannel::read_to_end(Glib::ustring& str) return (IOStatus) status; } +#ifdef GLIBMM_EXCEPTIONS_ENABLED IOStatus IOChannel::read(Glib::ustring& str, gsize count) +#else +IOStatus IOChannel::read(Glib::ustring& str, gsize count, std::auto_ptr<Glib::Error>& error) +#endif //GLIBMM_EXCEPTIONS_ENABLED { Glib::ScopedPtr<char> buf (g_new(char, count)); - GError* error = 0; + GError* gerror = 0; gsize bytes = 0; - const GIOStatus status = g_io_channel_read_chars(gobj(), buf.get(), count, &bytes, &error); + const GIOStatus status = g_io_channel_read_chars(gobj(), buf.get(), count, &bytes, &gerror); - if(error) - Glib::Error::throw_exception(error); + if(gerror) + { + #ifdef GLIBMM_EXCEPTIONS_ENABLED + Glib::Error::throw_exception(gerror); + #else + error = Glib::Error::throw_exception(gerror); + #endif //GLIBMM_EXCEPTIONS_ENABLED + } if(buf.get()) str.assign(buf.get(), buf.get() + bytes); @@ -264,15 +312,25 @@ IOStatus IOChannel::read(Glib::ustring& str, gsize count) return (IOStatus) status; } +#ifdef GLIBMM_EXCEPTIONS_ENABLED IOStatus IOChannel::set_encoding(const std::string& encoding) +#else +IOStatus IOChannel::set_encoding(const std::string& encoding, std::auto_ptr<Glib::Error>& error) +#endif //GLIBMM_EXCEPTIONS_ENABLED { - GError* error = 0; + GError* gerror = 0; const GIOStatus status = g_io_channel_set_encoding( - gobj(), (encoding.empty()) ? 0 : encoding.c_str(), &error); + gobj(), (encoding.empty()) ? 0 : encoding.c_str(), &gerror); - if(error) - Glib::Error::throw_exception(error); + if(gerror) + { + #ifdef GLIBMM_EXCEPTIONS_ENABLED + Glib::Error::throw_exception(gerror); + #else + error = Glib::Error::throw_exception(gerror); + #endif //GLIBMM_EXCEPTIONS_ENABLED + } return (IOStatus) status; } @@ -391,9 +449,12 @@ GIOStatus GlibmmIOChannel::io_read(GIOChannel* channel, char* buf, gsize count, { IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper; + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED return (GIOStatus) wrapper->read_vfunc(buf, count, *bytes_read); + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(Glib::Error& error) { @@ -403,6 +464,7 @@ GIOStatus GlibmmIOChannel::io_read(GIOChannel* channel, char* buf, gsize count, { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED return G_IO_STATUS_ERROR; } @@ -413,9 +475,12 @@ GIOStatus GlibmmIOChannel::io_write(GIOChannel* channel, const char* buf, gsize { IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper; + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED return (GIOStatus) wrapper->write_vfunc(buf, count, *bytes_written); + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(Glib::Error& error) { @@ -425,6 +490,7 @@ GIOStatus GlibmmIOChannel::io_write(GIOChannel* channel, const char* buf, gsize { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED return G_IO_STATUS_ERROR; } @@ -434,9 +500,12 @@ GIOStatus GlibmmIOChannel::io_seek(GIOChannel* channel, gint64 offset, GSeekType { IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper; + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED return (GIOStatus) wrapper->seek_vfunc(offset, (SeekType) type); + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(Glib::Error& error) { @@ -446,6 +515,7 @@ GIOStatus GlibmmIOChannel::io_seek(GIOChannel* channel, gint64 offset, GSeekType { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED return G_IO_STATUS_ERROR; } @@ -455,9 +525,12 @@ GIOStatus GlibmmIOChannel::io_close(GIOChannel* channel, GError** err) { IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper; + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED return (GIOStatus) wrapper->close_vfunc(); + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(Glib::Error& error) { @@ -467,6 +540,8 @@ GIOStatus GlibmmIOChannel::io_close(GIOChannel* channel, GError** err) { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED + return G_IO_STATUS_ERROR; } @@ -476,15 +551,19 @@ GSource* GlibmmIOChannel::io_create_watch(GIOChannel* channel, GIOCondition cond { IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper; + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED const Glib::RefPtr<Source> source = wrapper->create_watch_vfunc((IOCondition) condition); return (source) ? source->gobj_copy() : 0; + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(...) { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED return 0; } @@ -506,9 +585,12 @@ GIOStatus GlibmmIOChannel::io_set_flags(GIOChannel* channel, GIOFlags flags, GEr { IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper; + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED return (GIOStatus) wrapper->set_flags_vfunc((IOFlags) flags); + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(Glib::Error& error) { @@ -518,6 +600,7 @@ GIOStatus GlibmmIOChannel::io_set_flags(GIOChannel* channel, GIOFlags flags, GEr { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED return G_IO_STATUS_ERROR; } @@ -527,14 +610,18 @@ GIOFlags GlibmmIOChannel::io_get_flags(GIOChannel* channel) { IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper; + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED return (GIOFlags) wrapper->get_flags_vfunc(); + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(...) { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED return GIOFlags(0); } diff --git a/glib/src/iochannel.hg b/glib/src/iochannel.hg index f109235d..7edd0cab 100644 --- a/glib/src/iochannel.hg +++ b/glib/src/iochannel.hg @@ -109,7 +109,11 @@ public: * @return An IOChannel for the opened file. * @throw Glib::FileError */ +#ifdef GLIBMM_EXCEPTIONS_ENABLED static Glib::RefPtr<IOChannel> create_from_file(const std::string& filename, const std::string& mode); +#else + static Glib::RefPtr<IOChannel> create_from_file(const std::string& filename, const std::string& mode, std::auto_ptr<Glib::Error>& error); +#endif //GLIBMM_EXCEPTIONS_ENABLED _IGNORE(g_io_channel_new_file) /** Creates an I/O channel from a file descriptor. @@ -188,7 +192,11 @@ public: * @throw Glib::IOChannelError * @throw Glib::ConvertError */ +#ifdef GLIBMM_EXCEPTIONS_ENABLED IOStatus read(Glib::ustring& str, gsize count); +#else + IOStatus read(Glib::ustring& str, gsize count, std::auto_ptr<Glib::Error>& error); +#endif //GLIBMM_EXCEPTIONS_ENABLED /** Read a whole line. * Reads until the line separator is found, which is included @@ -198,7 +206,11 @@ public: * @throw Glib::IOChannelError * @throw Glib::ConvertError */ +#ifdef GLIBMM_EXCEPTIONS_ENABLED IOStatus read_line(Glib::ustring& line); +#else + IOStatus read_line(Glib::ustring& line, std::auto_ptr<Glib::Error>& error); +#endif //GLIBMM_EXCEPTIONS_ENABLED _IGNORE(g_io_channel_read_line, g_io_channel_read_line_string) /** Reads all the remaining data from the file. @@ -208,7 +220,11 @@ public: * @throw Glib::IOChannelError * @throw Glib::ConvertError */ +#ifdef GLIBMM_EXCEPTIONS_ENABLED IOStatus read_to_end(Glib::ustring& str); +#else + IOStatus read_to_end(Glib::ustring& str, std::auto_ptr<Glib::Error>& error); +#endif //GLIBMM_EXCEPTIONS_ENABLED _IGNORE(g_io_channel_read_to_end) /** Write a string to the I/O channel. @@ -220,7 +236,11 @@ public: * @throw Glib::IOChannelError * @throw Glib::ConvertError */ +#ifdef GLIBMM_EXCEPTIONS_ENABLED IOStatus write(const Glib::ustring& str); +#else + IOStatus write(const Glib::ustring& str, std::auto_ptr<Glib::Error>& error); +#endif //GLIBMM_EXCEPTIONS_ENABLED /** Write a memory area of @a count bytes to the I/O channel. * @param buf The start of the memory area. @@ -379,7 +399,11 @@ public: * @return Glib::IO_STATUS_NORMAL if the encoding was successfully set. * @throw Glib::IOChannelError */ +#ifdef GLIBMM_EXCEPTIONS_ENABLED IOStatus set_encoding(const std::string& encoding = std::string()); +#else + IOStatus set_encoding(const std::string& encoding, std::auto_ptr<Glib::Error>& error); +#endif //GLIBMM_EXCEPTIONS_ENABLED _IGNORE(g_io_channel_set_encoding) /** Get the encoding of the I/O channel. diff --git a/glib/src/markup.ccg b/glib/src/markup.ccg index 2b61a358..16dfcf3f 100644 --- a/glib/src/markup.ccg +++ b/glib/src/markup.ccg @@ -101,8 +101,10 @@ void ParserCallbacks::start_element(GMarkupParseContext* context, ParseContext& cpp_context = *static_cast<ParseContext*>(user_data); g_return_if_fail(context == cpp_context.gobj()); + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED Parser::AttributeMap attributes; if(attribute_names && attribute_values) @@ -117,6 +119,7 @@ void ParserCallbacks::start_element(GMarkupParseContext* context, } cpp_context.get_parser()->on_start_element(cpp_context, element_name, attributes); + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(MarkupError& err) { @@ -126,6 +129,7 @@ void ParserCallbacks::start_element(GMarkupParseContext* context, { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED } void ParserCallbacks::end_element(GMarkupParseContext* context, @@ -136,9 +140,12 @@ void ParserCallbacks::end_element(GMarkupParseContext* context, ParseContext& cpp_context = *static_cast<ParseContext*>(user_data); g_return_if_fail(context == cpp_context.gobj()); + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED cpp_context.get_parser()->on_end_element(cpp_context, element_name); + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(MarkupError& err) { @@ -148,6 +155,7 @@ void ParserCallbacks::end_element(GMarkupParseContext* context, { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED } void ParserCallbacks::text(GMarkupParseContext* context, @@ -159,9 +167,12 @@ void ParserCallbacks::text(GMarkupParseContext* context, ParseContext& cpp_context = *static_cast<ParseContext*>(user_data); g_return_if_fail(context == cpp_context.gobj()); + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED cpp_context.get_parser()->on_text(cpp_context, Glib::ustring(text, text + text_len)); + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(MarkupError& err) { @@ -171,6 +182,7 @@ void ParserCallbacks::text(GMarkupParseContext* context, { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED } void ParserCallbacks::passthrough(GMarkupParseContext* context, @@ -182,10 +194,13 @@ void ParserCallbacks::passthrough(GMarkupParseContext* context, ParseContext& cpp_context = *static_cast<ParseContext*>(user_data); g_return_if_fail(context == cpp_context.gobj()); + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED cpp_context.get_parser()->on_passthrough( cpp_context, Glib::ustring(passthrough_text, passthrough_text + text_len)); + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(MarkupError& err) { @@ -195,6 +210,7 @@ void ParserCallbacks::passthrough(GMarkupParseContext* context, { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED } void ParserCallbacks::error(GMarkupParseContext* context, @@ -206,14 +222,18 @@ void ParserCallbacks::error(GMarkupParseContext* context, g_return_if_fail(context == cpp_context.gobj()); g_return_if_fail(error->domain == G_MARKUP_ERROR); + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED cpp_context.get_parser()->on_error(cpp_context, MarkupError(g_error_copy(error))); + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(...) { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED } diff --git a/glib/src/spawn.ccg b/glib/src/spawn.ccg index 5007ad9c..c45c48e6 100644 --- a/glib/src/spawn.ccg +++ b/glib/src/spawn.ccg @@ -35,14 +35,18 @@ extern "C" */ static void child_setup_callback(void* user_data) { + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED (*reinterpret_cast<sigc::slot<void>*>(user_data))(); + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(...) { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED } static void copy_output_buf(std::string* dest, const char* buf) diff --git a/glib/src/thread.ccg b/glib/src/thread.ccg index a041e35e..962311fb 100644 --- a/glib/src/thread.ccg +++ b/glib/src/thread.ccg @@ -32,10 +32,13 @@ static void* call_thread_entry_slot(void* data) { sigc::slot_base *const slot = reinterpret_cast<sigc::slot_base*>(data); + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED // Recreate the specific slot, and drop the reference obtained by create(). (*static_cast<sigc::slot<void>*>(slot))(); + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(Glib::Thread::Exit&) { @@ -46,6 +49,7 @@ static void* call_thread_entry_slot(void* data) { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED delete slot; return 0; diff --git a/scripts/Makefile.am b/scripts/Makefile.am index f6f9ad1a..0edd72f1 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -3,6 +3,6 @@ m4dir = $(datadir)/aclocal m4_DATA = glibmm_check_perl.m4 EXTRA_DIST = README config.sub missing config.guess install-sh \ - ltmain.sh cxx.m4 cxx_std.m4 docgen.m4 macros.m4 \ + ltmain.sh cxx.m4 cxx_std.m4 docgen.m4 macros.m4 reduced.m4 \ $(m4_DATA) diff --git a/scripts/reduced.m4 b/scripts/reduced.m4 new file mode 100644 index 00000000..dbceee0f --- /dev/null +++ b/scripts/reduced.m4 @@ -0,0 +1,86 @@ +## GLIBMM_ARG_ENABLE_API_PROPERTIES() +## +## Provide the --enable-api-properties configure argument, enabled +## by default. +## +AC_DEFUN([GLIBMM_ARG_ENABLE_API_PROPERTIES], +[ + AC_ARG_ENABLE([api-properties], + [ --enable-api-properties Build properties API. + [[default=yes]]], + [glibmm_enable_api_properties="$enableval"], + [glibmm_enable_api_properties='yes']) + + if test "x$glibmm_enable_api_properties" = "xyes"; then + { + AC_DEFINE([GLIBMM_PROPERTIES_ENABLED],[1], [Defined when the --enable-api-properties configure argument was given]) + } + fi +]) + +## GLIBMM_ARG_ENABLE_API_VFUNCS() +## +## Provide the --enable-api-vfuncs configure argument, enabled +## by default. +## +AC_DEFUN([GLIBMM_ARG_ENABLE_API_VFUNCS], +[ + AC_ARG_ENABLE([api-vfuncs], + [ --enable-api-vfuncs Build vfuncs API. + [[default=yes]]], + [glibmm_enable_api_vfuncs="$enableval"], + [glibmm_enable_api_vfuncs='yes']) + + if test "x$glibmm_enable_api_vfuncs" = "xyes"; then + { + AC_DEFINE([GLIBMM_VFUNCS_ENABLED],[1], [Defined when the --enable-api-vfuncs configure argument was given]) + } + fi +]) + +## GLIBMM_ARG_ENABLE_API_EXCEPTIONS() +## +## Provide the --enable-api-exceptions configure argument, enabled +## by default. +## +AC_DEFUN([GLIBMM_ARG_ENABLE_API_EXCEPTIONS], +[ + AC_ARG_ENABLE([api-exceptions], + [ --enable-api-exceptions Build exceptions API. + [[default=yes]]], + [glibmm_enable_api_exceptions="$enableval"], + [glibmm_enable_api_exceptions='yes']) + + if test "x$glibmm_enable_api_exceptions" = "xyes"; then + { + AC_DEFINE([GLIBMM_EXCEPTIONS_ENABLED],[1], [Defined when the --enable-api-exceptions configure argument was given]) + } + fi +]) + +## GLIBMM_ARG_ENABLE_API_DEPRECATED() +## +## Provide the --enable-deprecated-api configure argument, enabled +## by default. +## +AC_DEFUN([GLIBMM_ARG_ENABLE_API_DEPRECATED], +[ + AC_ARG_ENABLE(deprecated-api, + [ --enable-deprecated-api Include (build) deprecated API in the libraries. + [[default=yes]]], + [glibmm_enable_api_deprecated="$enableval"], + [glibmm_enable_api_deprecated='yes']) + + if test "x$glibmm_enable_api_deprecated" = "xyes"; then + { + AC_MSG_WARN([Deprecated API will be built, for backwards-compatibility.]) + } + else + { + AC_MSG_WARN([Deprecated API will not be built, breaking backwards-compatibility. Do not use this build for distribution packages.]) + DISABLE_DEPRECATED_API_CFLAGS="-DGLIBMM_DISABLE_DEPRECATED" + AC_SUBST(DISABLE_DEPRECATED_API_CFLAGS) + } + fi +]) + diff --git a/tools/m4/class_interface.m4 b/tools/m4/class_interface.m4 index d63fd40d..0e93bd98 100644 --- a/tools/m4/class_interface.m4 +++ b/tools/m4/class_interface.m4 @@ -58,7 +58,9 @@ protected: _IMPORT(SECTION_PH_DEFAULT_SIGNAL_HANDLERS) //Callbacks (virtual functions): +#ifdef GLIBMM_VFUNCS_ENABLED _IMPORT(SECTION_PH_VFUNCS) +#endif //GLIBMM_VFUNCS_ENABLED }; ') @@ -90,11 +92,16 @@ void __CPPNAME__`'_Class::iface_init_function(void* g_iface, void*) //This is a temporary fix until I find out why I can not seem to derive a GtkFileChooser interface. murrayc g_assert(klass != 0); +#ifdef GLIBMM_VFUNCS_ENABLED _IMPORT(SECTION_PCC_CLASS_INIT_VFUNCS) +#endif //GLIBMM_VFUNCS_ENABLED + _IMPORT(SECTION_PCC_CLASS_INIT_DEFAULT_SIGNAL_HANDLERS) } +#ifdef GLIBMM_VFUNCS_ENABLED _IMPORT(SECTION_PCC_VFUNCS) +#endif //GLIBMM_VFUNCS_ENABLED _IMPORT(SECTION_PCC_DEFAULT_SIGNAL_HANDLERS) ') diff --git a/tools/m4/class_shared.m4 b/tools/m4/class_shared.m4 index 1cb066a3..ad74ade4 100644 --- a/tools/m4/class_shared.m4 +++ b/tools/m4/class_shared.m4 @@ -11,11 +11,15 @@ define(`_H_VFUNCS_AND_SIGNALS',`dnl public: //C++ methods used to invoke GTK+ virtual functions: +#ifdef GLIBMM_VFUNCS_ENABLED _IMPORT(SECTION_H_VFUNCS_CPPWRAPPER) +#endif //GLIBMM_VFUNCS_ENABLED protected: //GTK+ Virtual Functions (override these to change behaviour): +#ifdef GLIBMM_VFUNCS_ENABLED _IMPORT(SECTION_H_VFUNCS) +#endif //GLIBMM_VFUNCS_ENABLED //Default Signal Handlers:: _IMPORT(SECTION_H_DEFAULT_SIGNAL_HANDLERS) @@ -70,7 +74,9 @@ protected: _IMPORT(SECTION_PH_DEFAULT_SIGNAL_HANDLERS) //Callbacks (virtual functions): +#ifdef GLIBMM_VFUNCS_ENABLED _IMPORT(SECTION_PH_VFUNCS) +#endif //GLIBMM_VFUNCS_ENABLED }; ') @@ -107,12 +113,16 @@ void __CPPNAME__`'_Class::class_init_function(void* g_class, void* class_data) BaseClassType *const klass = static_cast<BaseClassType*>(g_class); CppClassParent::class_init_function(klass, class_data); +#ifdef GLIBMM_VFUNCS_ENABLED _IMPORT(SECTION_PCC_CLASS_INIT_VFUNCS) +#endif //GLIBMM_VFUNCS_ENABLED _IMPORT(SECTION_PCC_CLASS_INIT_DEFAULT_SIGNAL_HANDLERS) } ')dnl +#ifdef GLIBMM_VFUNCS_ENABLED _IMPORT(SECTION_PCC_VFUNCS) +#endif //GLIBMM_VFUNCS_ENABLED _IMPORT(SECTION_PCC_DEFAULT_SIGNAL_HANDLERS) ') @@ -145,8 +155,10 @@ _IMPORT(SECTION_CC_PROPERTYPROXIES) _IMPORT(SECTION_CC_DEFAULT_SIGNAL_HANDLERS) +#ifdef GLIBMM_VFUNCS_ENABLED _IMPORT(SECTION_CC_VFUNCS) _IMPORT(SECTION_CC_VFUNCS_CPPWRAPPER) +#endif //GLIBMM_VFUNCS_ENABLED ') dnl _PARENT_GCLASS_FROM_OBJECT(object_instance_name) diff --git a/tools/m4/convert_base.m4 b/tools/m4/convert_base.m4 index 29fbb26e..51d1f41b 100644 --- a/tools/m4/convert_base.m4 +++ b/tools/m4/convert_base.m4 @@ -14,15 +14,17 @@ popdef(`__E1')popdef(`__E2')`'') define(`CF__EQ',`$3') # -# _CONVERT(ctype, cpptype, name, wrap_line) +# _CONVERT(fromtype, totype, name, wrap_line) # Print the conversion from ctype to cpptype define(`_CONVERT',`dnl +m4_ifelse(`$2',void,,`dnl pushdef(`__COV',`CF`'__HASH2(`$1',`$2')')dnl m4_ifdef(__COV,`m4_indir(__COV,`$1',`$2',`$3')',` m4_errprint(`No conversion from $1 to $2 defined (line: $4, parameter name: $3) ') m4_m4exit(1) ')`'dnl +')`'dnl ') diff --git a/tools/m4/gerror.m4 b/tools/m4/gerror.m4 index bb3eb7d4..9bc27249 100644 --- a/tools/m4/gerror.m4 +++ b/tools/m4/gerror.m4 @@ -27,7 +27,14 @@ $4 #ifndef DOXYGEN_SHOULD_SKIP_THIS private: + +#ifdef GLIBMM_EXCEPTIONS_ENABLED static void throw_func(GError* gobject); +#else + //When not using exceptions, we just pass the Exception object around without throwing it: + static std::auto_ptr<Glib::Error> throw_func(GError* gobject); +#endif //GLIBMM_EXCEPTIONS_ENABLED + friend void wrap_init(); // uses throw_func() #endif }; @@ -69,10 +76,18 @@ __NAMESPACE__::__CPPNAME__::Code __NAMESPACE__::__CPPNAME__::code() const return static_cast<Code>(Glib::Error::code()); } +#ifdef GLIBMM_EXCEPTIONS_ENABLED void __NAMESPACE__::__CPPNAME__::throw_func(GError* gobject) { throw __NAMESPACE__::__CPPNAME__`'(gobject); } +#else +//When not using exceptions, we just pass the Exception object around without throwing it: +std::auto_ptr<Glib::Error> __NAMESPACE__::__CPPNAME__::throw_func(GError* gobject) +{ + return std::auto_ptr<Glib::Error>(new __NAMESPACE__::__CPPNAME__`'(gobject)); +} +#endif //GLIBMM_EXCEPTIONS_ENABLED m4_ifelse($5,`NO_GTYPE',,`dnl else // static diff --git a/tools/m4/method.m4 b/tools/m4/method.m4 index f4bee93e..4193e04b 100644 --- a/tools/m4/method.m4 +++ b/tools/m4/method.m4 @@ -9,26 +9,41 @@ dnl dnl dnl method -dnl $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 +dnl $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 dnl _METHOD(cppname,cname,cpprettype,crettype,arglist,cargs,const,refreturn,errthrow,deprecated,constversion,arglist_without_types) define(`_METHOD',`dnl _PUSH(SECTION_CC) ifelse(`$10',,,`_DEPRECATE_IFDEF_START') +ifelse(`$9',,,`#ifdef GLIBMM_EXCEPTIONS_ENABLED') $3 __CPPNAME__::$1`'($5)ifelse(`$7',1,` const') +ifelse(`$9',,,`#else +$3 __CPPNAME__::$1`'(`'$5`'ifelse(($5),(),`',`, ')std::auto_ptr<Glib::Error>& error)ifelse(`$7',1,` const') +#endif //GLIBMM_EXCEPTIONS_ENABLED +') { ifelse(`$11',,dnl -` ifelse(`$8'`$9',,dnl -` ifelse(`$3',void,,`return ')_CONVERT($4,$3,`$2`'(ifelse(`$7',1,const_cast<__CNAME__*>(gobj()),gobj())`'ifelse(`$6',,,`, ')$6)'); -', dnl -`ifelse(`$9',,,` GError *error = 0;') - ifelse(`$3',void,,``$3' retvalue = ')_CONVERT($4,$3,`$2`'(ifelse(`$7',1,const_cast<__CNAME__*>(gobj()),gobj())`'ifelse(`$6',,,`, ')$6)'); -ifelse(`$9',,,` if(error) ::Glib::Error::throw_exception(error);') +` ifelse(`$8'`$9',,dnl If it is not errthrow or refreturn +`ifelse(`$3',void,dnl If it returns voids: +`$2(ifelse(`$7',1,const_cast<__CNAME__*>(gobj()),gobj())`'ifelse(`$6',,,`, ')$6);' dnl It it returns non-void: +,`return _CONVERT($4,$3,`$2`'(ifelse(`$7',1,const_cast<__CNAME__*>(gobj()),gobj())`'ifelse(`$6',,,`, ')$6)');')' dnl End if it returns voids. +,dnl If is errthrow or refreturn +`ifelse(`$9',,,` GError* gerror = 0;') + ifelse(`$3',void,,``$3' retvalue = _CONVERT($4,$3,`$2`'(ifelse(`$7',1,const_cast<__CNAME__*>(gobj()),gobj())`'ifelse(`$6',,,`, ')$6)');')dnl +ifelse(`$9',,,` +#ifdef GLIBMM_EXCEPTIONS_ENABLED + if(gerror) + ::Glib::Error::throw_exception(gerror); +#else + if(gerror) + error = ::Glib::Error::throw_exception(gerror); +#endif //GLIBMM_EXCEPTIONS_ENABLED +') ifelse(`$8',,,`dnl if(retvalue) retvalue->reference(); //The function does not do a ref for us. ')dnl ifelse(`$3',void,,` return retvalue;') -')dnl +')dnl End errthrow/refreturn ',` return const_cast<__CPPNAME__*>(this)->$1($12);') } ifelse(`$10',,,`_DEPRECATE_IFDEF_END @@ -42,14 +57,27 @@ dnl _STATIC_METHOD(cppname,cname,cpprettype,crettype,arglist,cargs,refreturn,er define(`_STATIC_METHOD',`dnl _PUSH(SECTION_CC) ifelse(`$9',,,`_DEPRECATE_IFDEF_START') dnl +ifelse(`$8',,,`#ifdef GLIBMM_EXCEPTIONS_ENABLED') $3 __CPPNAME__::$1($5) +ifelse(`$8',,,`#else +$3 __CPPNAME__::$1(`'$5`'ifelse(($5),(),`',`, ')std::auto_ptr<Glib::Error>& error) +#endif //GLIBMM_EXCEPTIONS_ENABLED +') { ifelse(`$7'`$8',,dnl ` ifelse(`$3',void,,`return ')_CONVERT($4,$3,`$2`'($6)'); ', dnl -`ifelse(`$8',,,` GError *error = 0;') +`ifelse(`$8',,,` GError* gerror = 0;') ifelse(`$3',void,,``$3' retvalue = ')_CONVERT($4,$3,`$2`'($6)'); -ifelse(`$8',,,` if(error) ::Glib::Error::throw_exception(error);') +ifelse(`$8',,,` +#ifdef GLIBMM_EXCEPTIONS_ENABLED + if(gerror) + ::Glib::Error::throw_exception(gerror); +#else + if(gerror) + error = ::Glib::Error::throw_exception(gerror); +#endif //GLIBMM_EXCEPTIONS_ENABLED +') ifelse(`$7',,,`dnl if(retvalue) retvalue->reference(); //The function does not do a ref for us. diff --git a/tools/m4/property.m4 b/tools/m4/property.m4 index 28c4c1e7..4a9877bd 100644 --- a/tools/m4/property.m4 +++ b/tools/m4/property.m4 @@ -17,6 +17,7 @@ dnl Put spaces around the template parameter if necessary. pushdef(`__PROXY_TYPE__',`dnl Glib::PropertyProxy$4<'ifelse(regexp(_QUOTE($3),`>$'),`-1',_QUOTE($3),` '_QUOTE($3)` ')`>'dnl )dnl +#ifdef GLIBMM_PROPERTIES_ENABLED /** $5 * * You rarely need to use properties because there are get_ and set_ methods for almost all of them. @@ -24,11 +25,14 @@ Glib::PropertyProxy$4<'ifelse(regexp(_QUOTE($3),`>$'),`-1',_QUOTE($3),` '_QUOTE( * the value of the property changes. */ __PROXY_TYPE__ property_$2`'() ifelse($4,_ReadOnly, const,); +#endif //#GLIBMM_PROPERTIES_ENABLED _PUSH(SECTION_CC_PROPERTYPROXIES) +#ifdef GLIBMM_PROPERTIES_ENABLED __PROXY_TYPE__ __CPPNAME__::property_$2`'() ifelse($4,_ReadOnly, const,) { return __PROXY_TYPE__`'(this, "$1"); } +#endif //GLIBMM_PROPERTIES_ENABLED _POP() popdef(`__PROXY_TYPE__')dnl diff --git a/tools/m4/signal.m4 b/tools/m4/signal.m4 index 4e55e168..989e898e 100644 --- a/tools/m4/signal.m4 +++ b/tools/m4/signal.m4 @@ -40,19 +40,23 @@ static $2 __CPPNAME__`'_signal_$4_callback`'(__CNAME__`'* self, _COMMA_SUFFIX($3 // Do not try to call a signal on a disassociated wrapper. if(Glib::ObjectBase::_get_current_wrapper((GObject*) self)) { + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED if(sigc::slot_base *const slot = Glib::SignalProxyNormal::data_to_slot`'(data)) ifelse(`$2',void,`dnl (*static_cast<SlotType*>(slot))($7); ',`dnl else return _CONVERT($5,$2,`(*static_cast<SlotType*>(slot))($7)'); ')dnl endif + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(...) { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED } ifelse($2,void,,`dnl else @@ -70,15 +74,19 @@ static $2 __CPPNAME__`'_signal_$4_notify_callback`'(__CNAME__`'* self, _COMMA_SU // Do not try to call a signal on a disassociated wrapper. if(Glib::ObjectBase::_get_current_wrapper((GObject*) self)) { + #ifdef GLIBMM_EXCEPTIONS_ENABLED try { + #endif //GLIBMM_EXCEPTIONS_ENABLED if(sigc::slot_base *const slot = Glib::SignalProxyNormal::data_to_slot`'(data)) (*static_cast<SlotType*>(slot))($7); + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(...) { Glib::exception_handlers_invoke(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED } typedef $2 RType; @@ -140,19 +148,23 @@ _IMPORT(SECTION_CHECK) // being overridden: if(obj && obj->is_derived_()) { + #ifdef GLIBMM_EXCEPTIONS_ENABLED try // Trap C++ exceptions which would normally be lost because this is a C callback. { + #endif //GLIBMM_EXCEPTIONS_ENABLED // Call the virtual member method, which derived classes might override. ifelse($4,void,`dnl obj->on_$1`'($7); ',`dnl return _CONVERT($3,$4,`obj->on_$1`'($7)'); ')dnl + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(...) { Glib::exception_handlers_invoke`'(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED } else { diff --git a/tools/m4/vfunc.m4 b/tools/m4/vfunc.m4 index 5b26b7d9..a6dad27f 100644 --- a/tools/m4/vfunc.m4 +++ b/tools/m4/vfunc.m4 @@ -33,8 +33,10 @@ _IMPORT(SECTION_CHECK) // being overridden: if(obj && obj->is_derived_()) { + #ifdef GLIBMM_EXCEPTIONS_ENABLED try // Trap C++ exceptions which would normally be lost because this is a C callback. { + #endif //GLIBMM_EXCEPTIONS_ENABLED // Call the virtual member method, which derived classes might override. ifelse($4,void,`dnl obj->$1`'($7); @@ -45,11 +47,13 @@ ifelse($9,refreturn_ctype,`dnl Assume Glib::unwrap_copy() is correct if refretur return _CONVERT($3,$4,`obj->$1`'($7)'); ')dnl ')dnl + #ifdef GLIBMM_EXCEPTIONS_ENABLED } catch(...) { Glib::exception_handlers_invoke`'(); } + #endif //GLIBMM_EXCEPTIONS_ENABLED } else { @@ -74,20 +78,6 @@ ifelse($4,void,,`dnl _POP()') - -# $1 $2 $3 $4 -# _VFUNC_H(vfunc_name, rettype, `<cppargs>', is_const) -# -define(`_VFUNC_H',`dnl -_PUSH(SECTION_H_VFUNCS) -ifelse($4,`1',`dnl -virtual $2 $1`'($3) const; -',`dnl -virtual $2 $1`'($3); -') - -_POP()') - # $1 $2 $3 $4 $5 $6 $7 $8 # _VFUNC_CC(vfunc_name, gtkname, cpp_rettype, c_rettype, `<cppargs>', `<carg_names>', is_const, refreturn) # @@ -121,3 +111,18 @@ ifelse($8,refreturn,`dnl Assume Glib::wrap() is correct if refreturn is requeste _POP()') +# $1 $2 $3 $4 +# _VFUNC_H(vfunc_name, rettype, `<cppargs>', is_const) +# Only used for custom vfuncs. +# +define(`_VFUNC_H',`dnl +_PUSH(SECTION_H_VFUNCS) +ifelse($4,`1',`dnl +virtual $2 $1`'($3) const; +',`dnl +virtual $2 $1`'($3); +') + +_POP()') + + diff --git a/tools/pm/FunctionBase.pm b/tools/pm/FunctionBase.pm index a78cef43..00c1c051 100644 --- a/tools/pm/FunctionBase.pm +++ b/tools/pm/FunctionBase.pm @@ -63,13 +63,20 @@ sub args_types_and_names($) my $param_types = $$self{param_types}; my @out; + #debugging: + #if($#$param_types) + #{ + # return "NOARGS"; + #} + for ($i = 0; $i < $#$param_types + 1; $i++) { my $str = sprintf("%s %s", $$param_types[$i], $$param_names[$i]); push(@out, $str); } - return join(", ", @out); + my $result = join(", ", @out); + return $result; } # $string args_names_only_without_object($) diff --git a/tools/pm/Output.pm b/tools/pm/Output.pm index f7db4695..b3ffe714 100644 --- a/tools/pm/Output.pm +++ b/tools/pm/Output.pm @@ -86,7 +86,7 @@ sub output_wrap_vfunc_h($$$$$) { my ($self, $filename, $line_num, $objCppfunc, $objCDefsFunc) = @_; -#TODO: We can probably remove _VFUNC_H from the .m4 file +#Old code. We removed _VFUNC_H from the .m4 file # my $str = sprintf("_VFUNC_H(%s,%s,\`%s\',%s)dnl\n", # $$objCppfunc{name}, # $$objCppfunc{rettype}, @@ -101,7 +101,9 @@ sub output_wrap_vfunc_h($$$$$) $cppVfuncDecl .= " const"; } - $self->append(" $cppVfuncDecl;"); + $self->append("#ifdef GLIBMM_VFUNCS_ENABLED\n"); + $self->append(" $cppVfuncDecl;\n"); + $self->append("#endif //GLIBMM_VFUNCS_ENABLED\n"); #The default callback, which will call *_vfunc, which will then call the base default callback. #Declares the callback in the private *Class class and sets it in the class_init function. @@ -262,9 +264,45 @@ sub output_wrap_meth($$$$$$) # Doxygen documentation before the method declaration: $self->output_wrap_meth_docs_only($filename, $line_num, $documentation); + if($$objCDefsFunc{throw_any_errors}) + { + $self->append("#ifdef GLIBMM_EXCEPTIONS_ENABLED\n"); + } $self->append(" ${cppMethodDecl};"); + if($$objCDefsFunc{throw_any_errors}) + { + $self->append("\n#else\n"); + + # #Add an error argument, by searching for ) at the end and replacing it: + # my $declWithErrorArg = ${cppMethodDecl}; + # $declWithErrorArg =~ s/\)$/, std::auto_ptr<Glib::Error>& error\)/g; + + #Recreate the declaration, to remove the default values, which we can't have as well as an error parameter at the end: + my $declWithErrorArg = $$objCppfunc{rettype} . " " . $$objCppfunc{name} . "(" . $objCppfunc->args_types_and_names() . ", std::auto_ptr<Glib::Error>& error)"; + + if($$objCppfunc{static}) + { + $declWithErrorArg = "static " . $declWithErrorArg; + } + + if($objCppfunc->get_is_const() eq 1) + { + if($$objCppfunc{static} ne 1) #It can't be const and static at the same time. + { + $declWithErrorArg = $declWithErrorArg . " const"; + } + } + + #remove any superfluous ,: + $declWithErrorArg =~ s/\(, /\(/g; + + $self->append(" ${declWithErrorArg};"); + + $self->append("\n#endif //GLIBMM_EXCEPTIONS_ENABLED\n"); + } + if($deprecated ne "") { $self->append("\n_DEPRECATE_IFDEF_END\n"); @@ -652,7 +690,7 @@ sub convert_args_cpp_to_c($$$$;$) ${$c_param_types}[-1] eq "GError**" ) { $num_cpp_args++; - $cpp_param_names = [@{$cpp_param_names},"error"]; + $cpp_param_names = [@{$cpp_param_names},"gerror"]; $cpp_param_types = [@{$cpp_param_types},"GError*&"]; } |