* [PATCH] lib: work around talloc_steal usage from C++ code
@ 2012-04-12 20:57 Jani Nikula
2012-04-12 21:04 ` Austin Clements
2012-04-15 12:45 ` David Bremner
0 siblings, 2 replies; 3+ messages in thread
From: Jani Nikula @ 2012-04-12 20:57 UTC (permalink / raw)
To: notmuch
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>
---
For background, see discussion starting at
id:"1333966665-10469-5-git-send-email-Vladimir.Marek@oracle.com"
Vladimir, please test this. Thanks.
---
lib/notmuch-private.h | 22 ++++++++++++++++++++--
1 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
index ea836f7..3886e0c 100644
--- a/lib/notmuch-private.h
+++ b/lib/notmuch-private.h
@@ -495,8 +495,26 @@ notmuch_filenames_t *
_notmuch_filenames_create (const void *ctx,
notmuch_string_list_t *list);
-#pragma GCC visibility pop
-
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
--
1.7.5.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] lib: work around talloc_steal usage from C++ code
2012-04-12 20:57 [PATCH] lib: work around talloc_steal usage from C++ code Jani Nikula
@ 2012-04-12 21:04 ` Austin Clements
2012-04-15 12:45 ` David Bremner
1 sibling, 0 replies; 3+ messages in thread
From: Austin Clements @ 2012-04-12 21:04 UTC (permalink / raw)
To: Jani Nikula; +Cc: notmuch
Quoth Jani Nikula on Apr 12 at 11:57 pm:
> 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>
LGTM.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] lib: work around talloc_steal usage from C++ code
2012-04-12 20:57 [PATCH] lib: work around talloc_steal usage from C++ code Jani Nikula
2012-04-12 21:04 ` Austin Clements
@ 2012-04-15 12:45 ` David Bremner
1 sibling, 0 replies; 3+ messages in thread
From: David Bremner @ 2012-04-15 12:45 UTC (permalink / raw)
To: Jani Nikula, notmuch
Jani Nikula <jani@nikula.org> writes:
> 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.
pushed,
d
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-04-15 12:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-12 20:57 [PATCH] lib: work around talloc_steal usage from C++ code Jani Nikula
2012-04-12 21:04 ` Austin Clements
2012-04-15 12:45 ` David Bremner
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).