Add talloc_get_type_abort as a macro
Usage:
struct smb_read *io = talloc_get_type_abort(r, struct smb_read);
will abort if r is NULL or not "struct smb_read".
When aborting, a helpful error would be shown, like:
Talloc type mismatch at xx.c:24, expected struct smb_read,
got struct smbcli_request
Based on vlendec's talloc_get_type_abort.
As abort is application specific, not library specific, the abort action
should be specificed by the application.
Implemented talloc_get_type_abort as a macro with the abort action
defined by default as TALLOC_ABORT(text), but can be overridden for
the application in any C file to specify an application specific abort action.
Because it is implemented as a macro and not a function there is no need
to change the talloc library api in any way at all, no need to link talloc.c
and the talloc library with an application specific abort method,
no need to define system wide talloc_abort handlers, and
so that the location of the offending type mismatch can be
more easily shown.
The abort behaviour defaults to
#define TALLOC_ABORT(why) (puts(why),abort())
But the TALLOC_ABORT(why) may be defined before
talloc_get_type_abort is used. For smb applications
where smb_panic is linked, I suggest that:
#define TALLOC_ABORT(why) smb_panic(why)
be defined in appropriate calling contexts in order to get
the error text shown in the usual way.
NOTE:
Because talloc_get_type_abort is a simple inline expression you
probably won't be able to define TALLOC_ABORT in terms
of macros that declare blocks, e.g. do { } while(0),
which would include samba's DEBUG macro.
The only bug is that the talloc_asprintf allocated error
message ought to be free'd by the ABORT function, but as that
function will typically quit the process it doesn't really matter.