talloc: problem with talloc_steal usage from C++

Jani Nikula jani at nikula.org
Thu Apr 12 15:32:24 MDT 2012


Hi all -

Recently, an issue came up with using talloc_steal() in C++ code. For
recent GCC, talloc.h has some macro magic to provide type safety for
talloc_steal(). Otherwise, it returns a 'void *', which is okay to
assign to a non-void pointer in C, but not in C++. An explicit cast
would be required, losing the type safety for recent GCC, which is not
very nice if you want to support both GCC and non-GCC compilers.

As a workaround in the notmuch project, I proposed [1]. Slightly hacky,
but maintains type safety and does not require any changes in
talloc_steal() callers. Now if this was done directly in talloc.h, it
would not be hacky at all... *hint* ;)

It's a corner case in many ways, and talloc is a C library, so you may
not be interested, but this is just to let you know such an issue
exists.

[1] http://mid.gmane.org/1334264259-17632-1-git-send-email-jani@nikula.org


BR,
Jani.


PS. I'm not subscribed; please keep me in the recipients.


More information about the samba-technical mailing list