]> git.notmuchmail.org Git - notmuch/commitdiff
lib: work around talloc_steal usage from C++ code
authorJani Nikula <jani@nikula.org>
Thu, 12 Apr 2012 20:57:39 +0000 (23:57 +0300)
committerDavid Bremner <bremner@debian.org>
Sun, 15 Apr 2012 12:42:15 +0000 (09:42 -0300)
Implicit typecast from 'void *' to 'T *' is okay in C, but not in
C++. In talloc_steal, an explicit cast is provided for type safety in
some GCC versions. Otherwise, a cast is required. Provide a template
function for this to maintain type safety, and redefine talloc_steal
to use it.

The template must be outside the extern "C" block (NOTMUCH_BEGIN_DECLS
and NOTMUCH_END_DECLS), but keep it within the GCC visibility #pragma.

No functional changes, apart from making the library build with
compilers other than recent GCC.

Signed-off-by: Jani Nikula <jani@nikula.org>
lib/notmuch-private.h

index ea836f721291c3d7d84bfb9edb3f70b3ea717155..3886e0ca0c86475e242ca6a7adf61b6b91c2d74e 100644 (file)
@@ -495,8 +495,26 @@ notmuch_filenames_t *
 _notmuch_filenames_create (const void *ctx,
                           notmuch_string_list_t *list);
 
 _notmuch_filenames_create (const void *ctx,
                           notmuch_string_list_t *list);
 
-#pragma GCC visibility pop
-
 NOTMUCH_END_DECLS
 
 NOTMUCH_END_DECLS
 
+#ifdef __cplusplus
+/* Implicit typecast from 'void *' to 'T *' is okay in C, but not in
+ * C++. In talloc_steal, an explicit cast is provided for type safety
+ * in some GCC versions. Otherwise, a cast is required. Provide a
+ * template function for this to maintain type safety, and redefine
+ * talloc_steal to use it.
+ */
+#if !(__GNUC__ >= 3)
+template <class T> T *
+_notmuch_talloc_steal (const void *new_ctx, const T *ptr)
+{
+    return static_cast<T *> (talloc_steal (new_ctx, ptr));
+}
+#undef talloc_steal
+#define talloc_steal _notmuch_talloc_steal
+#endif
+#endif
+
+#pragma GCC visibility pop
+
 #endif
 #endif