diff --git a/.gitignore b/.gitignore
index 7a2c3dc..b664cd7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1 @@
-SOURCES/glib-2.36.3.tar.xz
+SOURCES/glib-2.40.0.tar.xz
diff --git a/.glib2.metadata b/.glib2.metadata
index ea41664..0aefa1d 100644
--- a/.glib2.metadata
+++ b/.glib2.metadata
@@ -1 +1 @@
-aafba69934b9ba77cc8cb0e5d8105aa1d8463eba SOURCES/glib-2.36.3.tar.xz
+44e1442ed4d1bf3fa89138965deb35afc1335a65 SOURCES/glib-2.40.0.tar.xz
diff --git a/SOURCES/0001-Revert-g_file_set_contents-don-t-fsync-on-ext3-4.patch b/SOURCES/0001-Revert-g_file_set_contents-don-t-fsync-on-ext3-4.patch
deleted file mode 100644
index 8413503..0000000
--- a/SOURCES/0001-Revert-g_file_set_contents-don-t-fsync-on-ext3-4.patch
+++ /dev/null
@@ -1,41 +0,0 @@
-From 4829e02c09c9faa5a312bac04bbaaccb82fa7981 Mon Sep 17 00:00:00 2001
-From: Colin Walters <walters@verbum.org>
-Date: Thu, 20 Jun 2013 13:13:29 -0400
-Subject: [PATCH] Revert "g_file_set_contents(): don't fsync on ext3/4"
-
-We didn't actually do any real-world testing of this, and
-unsurprisingly it turns out to break in at least one widely-used
-configuration (Fedora 19 x86_64, ext4 on LVM).
-
-This reverts commit 9d0c17b50102267a5029b58b1f44efbad82d8f03.
-
-https://bugzilla.gnome.org/show_bug.cgi?id=701560
----
- glib/gfileutils.c |    9 +--------
- 1 files changed, 1 insertions(+), 8 deletions(-)
-
-diff --git a/glib/gfileutils.c b/glib/gfileutils.c
-index 05a46ee..7e5bedc 100644
---- a/glib/gfileutils.c
-+++ b/glib/gfileutils.c
-@@ -1088,16 +1088,9 @@ write_to_temp_file (const gchar  *contents,
-     /* On Linux, on btrfs, skip the fsync since rename-over-existing is
-      * guaranteed to be atomic and this is the only case in which we
-      * would fsync() anyway.
--     *
--     * ext3 and ext4 are also safe in this respect under the default
--     * mount options (and if someone picks non-default options to
--     * improve their performance at the cost of reliability, who are we
--     * to argue?)
--     *
--     * Note: EXT[234]_SUPER_MAGIC are equal.
-      */
- 
--    if (fstatfs (fd, &buf) == 0 && (buf.f_type == BTRFS_SUPER_MAGIC || buf.f_type == EXT3_SUPER_MAGIC))
-+    if (fstatfs (fd, &buf) == 0 && buf.f_type == BTRFS_SUPER_MAGIC)
-       goto no_fsync;
-   }
- #endif
--- 
-1.7.1
-
diff --git a/SOURCES/GCancellable_drop_lock_for_callback.patch b/SOURCES/GCancellable_drop_lock_for_callback.patch
deleted file mode 100644
index 21c5256..0000000
--- a/SOURCES/GCancellable_drop_lock_for_callback.patch
+++ /dev/null
@@ -1,43 +0,0 @@
-From 44606b2e5219d114cfaae2c8fbc48c7fffb2a9c0 Mon Sep 17 00:00:00 2001
-From: Ryan Lortie <desrt@desrt.ca>
-Date: Mon, 28 Oct 2013 11:44:16 -0700
-Subject: [PATCH] GCancellable: drop lock for callback during connect()
-
-Don't hold the lock when calling the user's callback during
-g_cancellable_connect() for the case that the cancellable has already
-fired.
-
-Taken from a patch by Alex Larsson.
-
-https://bugzilla.gnome.org/show_bug.cgi?id=705395
----
- gio/gcancellable.c | 5 ++++-
- 1 file changed, 4 insertions(+), 1 deletion(-)
-
-diff --git a/gio/gcancellable.c b/gio/gcancellable.c
-index fc56b87..2e52141 100644
---- a/gio/gcancellable.c
-+++ b/gio/gcancellable.c
-@@ -557,6 +557,8 @@ g_cancellable_connect (GCancellable   *cancellable,
-       void (*_callback) (GCancellable *cancellable,
-                          gpointer      user_data);
- 
-+      g_mutex_unlock (&cancellable_mutex);
-+
-       _callback = (void *)callback;
-       id = 0;
- 
-@@ -571,9 +573,10 @@ g_cancellable_connect (GCancellable   *cancellable,
-                                   callback, data,
-                                   (GClosureNotify) data_destroy_func,
-                                   0);
-+
-+      g_mutex_unlock (&cancellable_mutex);
-     }
- 
--  g_mutex_unlock (&cancellable_mutex);
- 
-   return id;
- }
--- 
-1.8.3.1
\ No newline at end of file
diff --git a/SOURCES/add-back-g-memmove.patch b/SOURCES/add-back-g-memmove.patch
new file mode 100644
index 0000000..499054b
--- /dev/null
+++ b/SOURCES/add-back-g-memmove.patch
@@ -0,0 +1,86 @@
+From f13fb775ddc9bd62c6f67ca3fab54197af8fa3e7 Mon Sep 17 00:00:00 2001
+From: Ray Strode <rstrode@redhat.com>
+Date: Wed, 3 Sep 2014 11:08:57 -0400
+Subject: [PATCH] configure: don't hide g_memmove and g_ATEXIT
+
+While they are deprected in 2.40, they weren't
+in 2.36, and we want apps that were compilable
+before 7.1 to stay compiling (even if they have
+wrongly have -DG_DISABLE_DEPRECATED in their build
+flags.
+---
+ configure.ac | 2 --
+ 1 file changed, 2 deletions(-)
+
+diff --git a/configure.ac b/configure.ac
+index a01e58d..8461d81 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -2898,64 +2898,62 @@ typedef gint64 goffset;
+ 
+ #define G_GOFFSET_MODIFIER      G_GINT64_MODIFIER
+ #define G_GOFFSET_FORMAT        G_GINT64_FORMAT
+ #define G_GOFFSET_CONSTANT(val) G_GINT64_CONSTANT(val)
+ 
+ _______EOF
+ 
+ 	if test -z "$glib_unknown_void_p"; then
+ 	  cat >>$outfile <<_______EOF
+ 
+ #define GPOINTER_TO_INT(p)	((gint)  ${glib_gpi_cast} (p))
+ #define GPOINTER_TO_UINT(p)	((guint) ${glib_gpui_cast} (p))
+ 
+ #define GINT_TO_POINTER(i)	((gpointer) ${glib_gpi_cast} (i))
+ #define GUINT_TO_POINTER(u)	((gpointer) ${glib_gpui_cast} (u))
+ 
+ typedef signed $glib_intptr_type_define gintptr;
+ typedef unsigned $glib_intptr_type_define guintptr;
+ 
+ #define G_GINTPTR_MODIFIER      $gintptr_modifier
+ #define G_GINTPTR_FORMAT        $gintptr_format
+ #define G_GUINTPTR_FORMAT       $guintptr_format
+ _______EOF
+ 	else
+ 	  echo '#error SIZEOF_VOID_P unknown - This should never happen' >>$outfile
+ 	fi
+ 
+ 
+ 
+ 	cat >>$outfile <<_______EOF
+-#ifndef G_DISABLE_DEPRECATED
+ #define g_ATEXIT(proc)	(atexit (proc))
+ #define g_memmove(dest,src,len) G_STMT_START { memmove ((dest), (src), (len)); } G_STMT_END
+-#endif
+ $glib_defines
+ $glib_os
+ $glib_static_compilation
+ 
+ $glib_vacopy
+ 
+ #ifdef	__cplusplus
+ #define	G_HAVE_INLINE	1
+ #else	/* !__cplusplus */
+ $glib_inline
+ #endif	/* !__cplusplus */
+ 
+ #ifdef	__cplusplus
+ #define G_CAN_INLINE	1
+ _______EOF
+ 
+ 	if test x$g_can_inline = xyes ; then
+ 		cat >>$outfile <<_______EOF
+ #else	/* !__cplusplus */
+ #define G_CAN_INLINE	1
+ _______EOF
+ 	fi
+ 
+ 	cat >>$outfile <<_______EOF
+ #endif
+ 
+ _______EOF
+ 
+ 	if test x$g_have_iso_c_varargs = xyes ; then
+ 		cat >>$outfile <<_______EOF
+-- 
+2.0.1
+
diff --git a/SOURCES/gmain_fix_double_unlock.patch b/SOURCES/gmain_fix_double_unlock.patch
deleted file mode 100644
index 4c2ff69..0000000
--- a/SOURCES/gmain_fix_double_unlock.patch
+++ /dev/null
@@ -1,38 +0,0 @@
-From 0513c855cba69b96e4c9d2200719249a8a0c586e Mon Sep 17 00:00:00 2001
-From: Dan Winship <danw@gnome.org>
-Date: Wed, 10 Apr 2013 11:39:12 -0400
-Subject: [PATCH] gmain: fix double-unlock in g_main_context_unref()
-
-When unreffing a context with sources still attached, it would end up
-unlocking an already-unlocked context, causing crashes on platforms
-that (unlike Linux) actually check for that.
-
-https://bugzilla.gnome.org/show_bug.cgi?id=697595
----
- glib/gmain.c | 6 +++++-
- 1 file changed, 5 insertions(+), 1 deletion(-)
-
-diff --git a/glib/gmain.c b/glib/gmain.c
-index 68a7f8e..d6037ba 100644
---- a/glib/gmain.c
-+++ b/glib/gmain.c
-@@ -520,12 +520,16 @@ g_main_context_unref (GMainContext *context)
-   main_context_list = g_slist_remove (main_context_list, context);
-   G_UNLOCK (main_context_list);
- 
-+  /* g_source_iter_next() assumes the context is locked. */
-+  LOCK_CONTEXT (context);
-   g_source_iter_init (&iter, context, TRUE);
-   while (g_source_iter_next (&iter, &source))
-     {
-       source->context = NULL;
--      g_source_destroy_internal (source, context, FALSE);
-+      g_source_destroy_internal (source, context, TRUE);
-     }
-+  UNLOCK_CONTEXT (context);
-+
-   for (sl_iter = context->source_lists; sl_iter; sl_iter = sl_iter->next)
-     {
-       list = sl_iter->data;
--- 
-1.8.1.4
\ No newline at end of file
diff --git a/SOURCES/revert-g-source-remove-critical.patch b/SOURCES/revert-g-source-remove-critical.patch
new file mode 100644
index 0000000..37b42e3
--- /dev/null
+++ b/SOURCES/revert-g-source-remove-critical.patch
@@ -0,0 +1,114 @@
+From c2ff9875185b49cae573c72dbbf419dbb2c4aaca Mon Sep 17 00:00:00 2001
+From: Ray Strode <rstrode@redhat.com>
+Date: Wed, 3 Sep 2014 10:36:14 -0400
+Subject: [PATCH] Revert "gmain: Warn when g_source_remove() fails"
+
+This reverts commit a919be3d39150328874ff647fb2c2be7af3df996.
+---
+ glib/gmain.c | 19 ++++++++-----------
+ 1 file changed, 8 insertions(+), 11 deletions(-)
+
+diff --git a/glib/gmain.c b/glib/gmain.c
+index 45ed402..085fb2b 100644
+--- a/glib/gmain.c
++++ b/glib/gmain.c
+@@ -2137,88 +2137,85 @@ g_main_context_find_source_by_user_data (GMainContext *context,
+   if (context == NULL)
+     context = g_main_context_default ();
+   
+   LOCK_CONTEXT (context);
+ 
+   g_source_iter_init (&iter, context, FALSE);
+   while (g_source_iter_next (&iter, &source))
+     {
+       if (!SOURCE_DESTROYED (source) &&
+ 	  source->callback_funcs)
+ 	{
+ 	  GSourceFunc callback;
+ 	  gpointer callback_data = NULL;
+ 
+ 	  source->callback_funcs->get (source->callback_data, source, &callback, &callback_data);
+ 
+ 	  if (callback_data == user_data)
+ 	    break;
+ 	}
+     }
+   g_source_iter_clear (&iter);
+ 
+   UNLOCK_CONTEXT (context);
+ 
+   return source;
+ }
+ 
+ /**
+  * g_source_remove:
+  * @tag: the ID of the source to remove.
+- *
+- * Removes the source with the given id from the default main context.
+- *
+- * The id of a #GSource is given by g_source_get_id(), or will be
+- * returned by the functions g_source_attach(), g_idle_add(),
+- * g_idle_add_full(), g_timeout_add(), g_timeout_add_full(),
+- * g_child_watch_add(), g_child_watch_add_full(), g_io_add_watch(), and
+- * g_io_add_watch_full().
++ * 
++ * Removes the source with the given id from the default main context. 
++ * The id of
++ * a #GSource is given by g_source_get_id(), or will be returned by the
++ * functions g_source_attach(), g_idle_add(), g_idle_add_full(),
++ * g_timeout_add(), g_timeout_add_full(), g_child_watch_add(),
++ * g_child_watch_add_full(), g_io_add_watch(), and g_io_add_watch_full().
+  *
+  * See also g_source_destroy(). You must use g_source_destroy() for sources
+  * added to a non-default main context.
+  *
+  * It is a programmer error to attempt to remove a non-existent source.
+  *
+  * Returns: For historical reasons, this function always returns %TRUE
+  **/
+ gboolean
+ g_source_remove (guint tag)
+ {
+   GSource *source;
+-
++  
+   g_return_val_if_fail (tag > 0, FALSE);
+ 
+   source = g_main_context_find_source_by_id (NULL, tag);
+   if (source)
+     g_source_destroy (source);
+-  else
+-    g_critical ("Source ID %u was not found when attempting to remove it", tag);
+ 
+   return source != NULL;
+ }
+ 
+ /**
+  * g_source_remove_by_user_data:
+  * @user_data: the user_data for the callback.
+  * 
+  * Removes a source from the default main loop context given the user
+  * data for the callback. If multiple sources exist with the same user
+  * data, only one will be destroyed.
+  * 
+  * Returns: %TRUE if a source was found and removed. 
+  **/
+ gboolean
+ g_source_remove_by_user_data (gpointer user_data)
+ {
+   GSource *source;
+   
+   source = g_main_context_find_source_by_user_data (NULL, user_data);
+   if (source)
+     {
+       g_source_destroy (source);
+       return TRUE;
+     }
+   else
+     return FALSE;
+ }
+ 
+ /**
+-- 
+2.0.1
+
diff --git a/SPECS/glib2.spec b/SPECS/glib2.spec
index f77c726..a8b8078 100644
--- a/SPECS/glib2.spec
+++ b/SPECS/glib2.spec
@@ -1,15 +1,12 @@
 Summary: A library of handy utility functions
 Name: glib2
-Version: 2.36.3
-Release: 5%{?dist}
+Version: 2.40.0
+Release: 4%{?dist}
 License: LGPLv2+
 Group: System Environment/Libraries
 URL: http://www.gtk.org
 #VCS: git:git://git.gnome.org/glib
-Source: http://download.gnome.org/sources/glib/2.36/glib-%{version}.tar.xz
-Patch0: 0001-Revert-g_file_set_contents-don-t-fsync-on-ext3-4.patch
-Patch1: GCancellable_drop_lock_for_callback.patch
-Patch2: gmain_fix_double_unlock.patch
+Source: http://download.gnome.org/sources/glib/2.40/glib-%{version}.tar.xz
 
 BuildRequires: pkgconfig
 BuildRequires: gettext
@@ -28,6 +25,9 @@ BuildRequires: libffi-devel
 BuildRequires: elfutils-libelf-devel
 BuildRequires: chrpath
 
+Patch0: revert-g-source-remove-critical.patch
+Patch1: add-back-g-memmove.patch
+
 # required for GIO content-type support
 Requires: shared-mime-info
 
@@ -67,9 +67,8 @@ The glib2-fam package contains the FAM (File Alteration Monitor) module for GIO.
 
 %prep
 %setup -q -n glib-%{version}
-%patch0 -p1
-%patch1 -p1
-%patch2 -p1
+%patch0 -p1 -b .revert-g-source-remove-critical
+%patch1 -p1 -b .add-back-g-memmove
 
 autoreconf -i -f
 
@@ -138,6 +137,7 @@ gio-querymodules-%{__isa_bits} %{_libdir}/gio/modules
 %dir %{_datadir}/bash-completion/completions
 %{_datadir}/bash-completion/completions/gdbus
 %{_datadir}/bash-completion/completions/gsettings
+%{_datadir}/bash-completion/completions/gapplication
 %dir %{_datadir}/glib-2.0
 %dir %{_datadir}/glib-2.0/schemas
 %dir %{_libdir}/gio
@@ -147,10 +147,12 @@ gio-querymodules-%{__isa_bits} %{_libdir}/gio/modules
 %{_bindir}/glib-compile-schemas
 %{_bindir}/gsettings
 %{_bindir}/gdbus
+%{_bindir}/gapplication
 %doc %{_mandir}/man1/gio-querymodules.1.gz
 %doc %{_mandir}/man1/glib-compile-schemas.1.gz
 %doc %{_mandir}/man1/gsettings.1.gz
 %doc %{_mandir}/man1/gdbus.1.gz
+%doc %{_mandir}/man1/gapplication.1.gz
 
 %files devel
 %{_libdir}/lib*.so
@@ -192,6 +194,18 @@ gio-querymodules-%{__isa_bits} %{_libdir}/gio/modules
 %{_libdir}/gio/modules/libgiofam.so
 
 %changelog
+* Wed Sep 03 2014 Ray Strode <rstrode@redhat.com> 2.40.0-4
+- Add back g_memmove define for backward compat
+  Related: #1104372
+
+* Wed Sep 03 2014 Ray Strode <rstrode@redhat.com> 2.40.0-3
+- Revert glib2 critical for better bug-for-bug 2.36.3 backward compatibility
+  Resolves: #1132624
+
+* Mon Mar 24 2014 Colin Walters <walters@redhat.com> - 2.40.0-1
+- Update to 2.40.0
+- Resolves: #1104372
+
 * Tue Feb 11 2014 Colin Walters <walters@redhat.com> - 2.36.3-5
 - Backport patch to fix gnome-shell lockups
   Resolves: #1030601