[glibmm] Fix the build with --disable-deprecated-api.



commit 423e6fbb104bb08ab876f1642b043de996467f0b
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Tue Feb 28 15:58:01 2012 +0100

    Fix the build with --disable-deprecated-api.
    
    * glib/glibmm/main.cc: Call get_time() instead of the deprecated
    get_current_time(), when GLIBMM_DISABLE_DEPRECATED is defined.
    * glib/src/thread.[hg|ccg]: Use _IS_DEPRECATED instead of
    _DEPRECATE_IFDEF_{START|END}. _DEPRECATE_IFDEF_{START|END} does not include
    code generated by gmmproc within #ifndef/#endif.
    * glib/src/threads.ccg: Change catch(Glib::Thread::Exit&) to
    catch(Glib::Threads::Thread::Exit&).
    * glib/src/threads.hg: Add _GMMPROC_EXTRA_NAMESPACE(Threads).
    * glib/src/valuearray.hg:
    * gio/src/application.hg: #undef G_DISABLE_DEPRECATED in the .cc file.
    * tools/m4/class_shared.m4: Define _IS_DEPRECATED. Bug #640029.

 ChangeLog                |   16 ++++++++++++++++
 gio/src/application.hg   |    5 +++++
 glib/glibmm/main.cc      |   22 ++++++++++++++++++++++
 glib/src/thread.ccg      |    3 ---
 glib/src/thread.hg       |   10 +++++++---
 glib/src/threads.ccg     |    4 ++--
 glib/src/threads.hg      |   19 ++++++++++---------
 glib/src/valuearray.hg   |    5 +++++
 tools/m4/class_shared.m4 |    9 +++++++++
 9 files changed, 76 insertions(+), 17 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 4eb9ffe..d417621 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
 2012-02-28  Kjell Ahlstedt  <kjell ahlstedt bredband net>
  
+	Fix the build with --disable-deprecated-api.
+
+	* glib/glibmm/main.cc: Call get_time() instead of the deprecated
+	get_current_time(), when GLIBMM_DISABLE_DEPRECATED is defined.
+	* glib/src/thread.[hg|ccg]: Use _IS_DEPRECATED instead of
+	_DEPRECATE_IFDEF_{START|END}. _DEPRECATE_IFDEF_{START|END} does not include
+	code generated by gmmproc within #ifndef/#endif.
+	* glib/src/threads.ccg: Change catch(Glib::Thread::Exit&) to
+	catch(Glib::Threads::Thread::Exit&).
+	* glib/src/threads.hg: Add _GMMPROC_EXTRA_NAMESPACE(Threads).
+	* glib/src/valuearray.hg:
+	* gio/src/application.hg: #undef G_DISABLE_DEPRECATED in the .cc file.
+	* tools/m4/class_shared.m4: Define _IS_DEPRECATED. Bug #640029.
+
+2012-02-28  Kjell Ahlstedt  <kjell ahlstedt bredband net>
+ 
 	generate_wrap_init.pl: Improve reg. of exception classes in sub-namespaces.
 
 	* tools/generate_wrap_init.pl.in: When there are exception classes in sub-
diff --git a/gio/src/application.hg b/gio/src/application.hg
index 888b3a8..b2287bc 100644
--- a/gio/src/application.hg
+++ b/gio/src/application.hg
@@ -17,6 +17,11 @@
  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#m4 _PUSH(SECTION_CC_PRE_INCLUDES)
+#undef G_DISABLE_DEPRECATED
+#define GLIB_DISABLE_DEPRECATION_WARNINGS 1
+#m4 _POP()
+
 #include <giomm/actiongroup.h>
 #include <giomm/actionmap.h>
 #include <giomm/applicationcommandline.h>
diff --git a/glib/glibmm/main.cc b/glib/glibmm/main.cc
index eb279c5..91da784 100644
--- a/glib/glibmm/main.cc
+++ b/glib/glibmm/main.cc
@@ -35,6 +35,16 @@
 
 namespace
 {
+#ifdef GLIBMM_DISABLE_DEPRECATED
+void time64_to_time_val(gint64 time64, Glib::TimeVal& time_val)
+{
+  // This function is not guaranteed to convert correctly if time64 is negative.
+  const long seconds = static_cast<long>(time64 / G_GINT64_CONSTANT(1000000));
+  const long microseconds = static_cast<long>(time64 -
+                            static_cast<gint64>(seconds) * G_GINT64_CONSTANT(1000000));
+  time_val = Glib::TimeVal(seconds, microseconds);
+}
+#endif //GLIBMM_DISABLE_DEPRECATED
 
 class SourceConnectionNode
 {
@@ -955,7 +965,11 @@ TimeoutSource::~TimeoutSource()
 bool TimeoutSource::prepare(int& timeout)
 {
   Glib::TimeVal current_time;
+#ifndef GLIBMM_DISABLE_DEPRECATED
   get_current_time(current_time);
+#else
+  time64_to_time_val(get_time(), current_time);
+#endif //GLIBMM_DISABLE_DEPRECATED
 
   Glib::TimeVal remaining = expiration_;
   remaining.subtract(current_time);
@@ -992,7 +1006,11 @@ bool TimeoutSource::prepare(int& timeout)
 bool TimeoutSource::check()
 {
   Glib::TimeVal current_time;
+#ifndef GLIBMM_DISABLE_DEPRECATED
   get_current_time(current_time);
+#else
+  time64_to_time_val(get_time(), current_time);
+#endif //GLIBMM_DISABLE_DEPRECATED
 
   return (expiration_ <= current_time);
 }
@@ -1003,7 +1021,11 @@ bool TimeoutSource::dispatch(sigc::slot_base* slot)
 
   if(again)
   {
+#ifndef GLIBMM_DISABLE_DEPRECATED
     get_current_time(expiration_);
+#else
+    time64_to_time_val(get_time(), expiration_);
+#endif //GLIBMM_DISABLE_DEPRECATED
     expiration_.add_milliseconds(std::min<unsigned long>(G_MAXLONG, interval_));
   }
 
diff --git a/glib/src/thread.ccg b/glib/src/thread.ccg
index 58853c4..09e53b9 100644
--- a/glib/src/thread.ccg
+++ b/glib/src/thread.ccg
@@ -21,8 +21,6 @@
 #include <glibmm/exceptionhandler.h>
 #include <glib.h>
 
-_DEPRECATE_IFDEF_START
-
 namespace
 {
 
@@ -390,4 +388,3 @@ GPrivate* GPrivate_new_helper(GDestroyNotify notify) {
 
 } // namespace Glib
 
-_DEPRECATE_IFDEF_END
diff --git a/glib/src/thread.hg b/glib/src/thread.hg
index bc91586..8c92e41 100644
--- a/glib/src/thread.hg
+++ b/glib/src/thread.hg
@@ -16,10 +16,15 @@
  */
 
 _DEFS(glibmm,glib)
+_CONFIGINCLUDE(glibmmconfig.h)
 
-#include <glibmmconfig.h>
+_IS_DEPRECATED // This whole file is deprecated.
 
-_DEPRECATE_IFDEF_START
+#m4 _PUSH(SECTION_CC_PRE_INCLUDES)
+// Must be included in the .cc file before the generated #ifndef GLIBMM_DISABLE_DEPRECATED,
+// or else "configure --disable-deprecated-api" + "make" will fail.
+#include <glibmmconfig.h>
+#m4 _POP()
 
 // We use GThreadFunctions in the (deprecated) API, so we must temporarily undef G_DISABLE_DEPRECATED.
 // Temporarily undef G_DISABLE_DEPRECATED, redefining it later if appropriate.
@@ -1084,4 +1089,3 @@ _IGNORE(g_iconv)
 
 } // namespace Glib
 
-_DEPRECATE_IFDEF_END
diff --git a/glib/src/threads.ccg b/glib/src/threads.ccg
index 2431b0c..78369d5 100644
--- a/glib/src/threads.ccg
+++ b/glib/src/threads.ccg
@@ -37,9 +37,9 @@ static void* call_thread_entry_slot(void* data)
     // Recreate the specific slot, and drop the reference obtained by create().
     (*static_cast<sigc::slot<void>*>(slot))();
   }
-  catch(Glib::Thread::Exit&)
+  catch(Glib::Threads::Thread::Exit&)
   {
-    // Just exit from the thread.  The Thread::Exit exception
+    // Just exit from the thread.  The Threads::Thread::Exit exception
     // is our sane C++ replacement of g_thread_exit().
   }
   catch(...)
diff --git a/glib/src/threads.hg b/glib/src/threads.hg
index 8069fb8..c19547e 100644
--- a/glib/src/threads.hg
+++ b/glib/src/threads.hg
@@ -16,8 +16,7 @@
  */
 
 _DEFS(glibmm,glib)
-
-#include <glibmmconfig.h>
+_CONFIGINCLUDE(glibmmconfig.h)
 
 #include <glib.h>
 
@@ -31,6 +30,8 @@ namespace Glib
 
 namespace Threads
 {
+//The GMMPROC_EXTRA_NAMESPACE() macro is a hint to generate_wrap_init.pl to put it in the Threads sub-namespace
+_GMMPROC_EXTRA_NAMESPACE(Threads)
 
 /** @defgroup Threads Threads
  * Thread abstraction; including threads, different mutexes,
@@ -60,7 +61,7 @@ _WRAP_GERROR(ThreadError, GThreadError, G_THREAD_ERROR, NO_GTYPE)
  * @note g_thread_exit() is not wrapped, because that function exits a thread
  * without any cleanup.  That's especially dangerous in C++ code, since the
  * destructors of automatic objects won't be invoked.  Instead, you can throw
- * a Thread::Exit exception, which will be caught by the internal thread
+ * a Threads::Thread::Exit exception, which will be caught by the internal thread
  * entry function.
  *
  * @note You might have noticed that the thread entry slot doesn't have the
@@ -79,7 +80,7 @@ public:
    *
    * The new thread executes the function or method @a slot points to.  You can
    * pass additional arguments using sigc::bind().  If the thread was created
-   * successfully, it is returned, otherwise a ThreadError exception is thrown.
+   * successfully, it is returned, otherwise a Threads::ThreadError exception is thrown.
    *
    * Because sigc::trackable is not thread safe, if the slot represents a
    * non-static class method (that is, it is created by sigc::mem_fun()), the
@@ -88,7 +89,7 @@ public:
    * @param slot A slot to execute in the new thread.
    * @param joinable This parameter is now ignored because Threads are now always joinable.
    * @return The new Thread* on success.
-   * @throw Glib::ThreadError
+   * @throw Glib::Threads::ThreadError
    */
   static Thread* create(const sigc::slot<void>& slot, bool joinable = true);
 
@@ -101,7 +102,7 @@ public:
    * Waits until the thread finishes, i.e. the slot, as given to create(),
    * returns or g_thread_exit() is called by the thread.  (Calling
    * g_thread_exit() in a C++ program should be avoided.)  All resources of
-   * the thread including the Glib::Thread object are released.  The thread
+   * the thread including the Glib::Threads::Thread object are released.  The thread
    * must have been created with <tt>joinable&nbsp;=&nbsp;true</tt>.
    */
   void join();
@@ -130,10 +131,10 @@ private:
 
 /** %Exception class used to exit from a thread.
  * @code
- * throw Glib::Thread::Exit();
+ * throw Glib::Threads::Thread::Exit();
  * @endcode
- * Write this if you want to exit from a thread created by Thread::create().
- * Of course you must make sure not to catch Thread::Exit by accident, i.e.
+ * Write this if you want to exit from a thread created by Threads::Thread::create().
+ * Of course you must make sure not to catch Threads::Thread::Exit by accident, i.e.
  * when using <tt>catch(...)</tt> somewhere in your code.
  */
 class Thread::Exit
diff --git a/glib/src/valuearray.hg b/glib/src/valuearray.hg
index 64bb99d..a4a4941 100644
--- a/glib/src/valuearray.hg
+++ b/glib/src/valuearray.hg
@@ -23,6 +23,11 @@ _DEFS(glibmm,glib)
 #include <glibmm/value.h>
 #include <sigc++/functors/slot.h>
 
+#m4 _PUSH(SECTION_CC_PRE_INCLUDES)
+#undef G_DISABLE_DEPRECATED
+#define GLIB_DISABLE_DEPRECATION_WARNINGS 1
+#m4 _POP()
+
 namespace Glib
 {
 
diff --git a/tools/m4/class_shared.m4 b/tools/m4/class_shared.m4
index b1af688..f807de6 100644
--- a/tools/m4/class_shared.m4
+++ b/tools/m4/class_shared.m4
@@ -266,4 +266,13 @@ define(`_GTKMMPROC_WIN32_NO_WRAP', dnl
 //and the class will not be registered in wrap_init.h or wrap_init.cc
 ')dnl
 
+dnl _IS_DEPRECATED
+dnl ifdef-out the whole .h and .cc files.
+dnl generate_wrap_init.pl will look for this in the original .hg file.
+define(`_IS_DEPRECATED',`dnl
+_PUSH()
+dnl Define this macro to be tested for later. See base.m4.
+define(`__BOOL_DEPRECATED__',`$1')
+_POP()
+')
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]