[D] Correctly annotate function pointers with C linkage.

Minor cleanups as well.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12899 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
David Nadlinger 2012-01-23 21:59:00 +00:00
commit 8fa4d20ec3
5 changed files with 50 additions and 8 deletions

View file

@ -3,15 +3,23 @@
*
* Support code for exceptions if the SWIG_D_NO_EXCEPTION_HELPER is not defined
* Support code for strings if the SWIG_D_NO_STRING_HELPER is not defined
* ----------------------------------------------------------------------------- */
*
* Support code for function pointers. ----------------------------------------------------------------------------- */
%insert(runtime) %{
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
/* Contract support. */
#define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_DSetPendingException(SWIG_DException, msg); return nullreturn; } else
%}
/*
* Exception support code.
*/
#if !defined(SWIG_D_NO_EXCEPTION_HELPER)
%insert(runtime) %{
// Support for throwing D exceptions from C/C++.
@ -250,6 +258,11 @@ alias void function(const char* message) SwigExceptionCallback;
// Callback registering function in wrapperloader.swg.
#endif // SWIG_D_NO_EXCEPTION_HELPER
/*
* String support code.
*/
#if !defined(SWIG_D_NO_STRING_HELPER)
%insert(runtime) %{
// Callback for returning strings to D without leaking memory.
@ -304,7 +317,28 @@ alias const(char)* function(const(char*) cString) SwigStringCallback;
// Callback registering function in wrapperloader.swg.
#endif // SWIG_D_NO_STRING_HELPER
%insert(runtime) %{
/* Contract support. */
#define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_DSetPendingException(SWIG_DException, msg); return nullreturn; } else
/*
* Function pointer support code.
*/
#if (SWIG_D_VERSION == 1)
%pragma(d) imdmodulecode = %{
template SwigExternC(T) {
static if (is(typeof(*(T.init)) R == return)) {
static if (is(typeof(*(T.init)) P == function)) {
alias extern(C) R function(P) SwigExternC;
}
}
}
%}
#else
%pragma(d) imdmodulecode = %{
template SwigExternC(T) if (is(typeof(*(T.init)) P == function)) {
static if (is(typeof(*(T.init)) R == return)) {
static if (is(typeof(*(T.init)) P == function)) {
alias extern(C) R function(P) SwigExternC;
}
}
}
%}
#endif