The default is now to not generate an additional method declaration when a method is declared with an extern. Use -addextern option to recreate original behaviour (new commandline option), with -noextern now redundant.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7318 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
4950f242ed
commit
11dc59b22e
3 changed files with 41 additions and 33 deletions
|
|
@ -43,6 +43,7 @@
|
||||||
#define WARN_DEPRECATED_IGNORE_TM 119
|
#define WARN_DEPRECATED_IGNORE_TM 119
|
||||||
#define WARN_DEPRECATED_OPTC 120
|
#define WARN_DEPRECATED_OPTC 120
|
||||||
#define WARN_DEPRECATED_NAME 121
|
#define WARN_DEPRECATED_NAME 121
|
||||||
|
#define WARN_DEPRECATED_NOEXTERN 122
|
||||||
|
|
||||||
/* -- Preprocessor -- */
|
/* -- Preprocessor -- */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ int SmartPointer = 0;
|
||||||
|
|
||||||
extern int GenerateDefault;
|
extern int GenerateDefault;
|
||||||
extern int ForceExtern;
|
extern int ForceExtern;
|
||||||
extern int NoExtern;
|
extern int AddExtern;
|
||||||
|
|
||||||
/* import modes */
|
/* import modes */
|
||||||
|
|
||||||
|
|
@ -799,40 +799,43 @@ int Language::cDeclaration(Node *n) {
|
||||||
/* Transform the node into a 'function' node and emit */
|
/* Transform the node into a 'function' node and emit */
|
||||||
if (!CurrentClass) {
|
if (!CurrentClass) {
|
||||||
f_header = Swig_filebyname("header");
|
f_header = Swig_filebyname("header");
|
||||||
/*
|
|
||||||
in C++ mode we can't emit a extern declaration derived from
|
|
||||||
the definition, for example, if we have
|
|
||||||
|
|
||||||
--- foo.c ---
|
if (AddExtern) {
|
||||||
int foo(int bar) {
|
if (f_header) {
|
||||||
}
|
if ((Cmp(storage,"extern") == 0) || (ForceExtern && !storage)) {
|
||||||
--- foo.c ---
|
/* we don't need the 'extern' part in the C/C++ declaration,
|
||||||
|
and it produces some problems when namespace and SUN
|
||||||
|
Studio is used.
|
||||||
|
|
||||||
we could be tempted to declare
|
Printf(f_header,"extern %s", SwigType_str(ty,name));
|
||||||
|
|
||||||
extern int foo(int bar);
|
In fact generating extern declarations is quite error prone and is
|
||||||
|
no longer the default. Getting it right seems impossible with namespaces
|
||||||
but the real declaration could be:
|
and default arguments and when a method is declared with the various Windows
|
||||||
|
calling conventions - SWIG doesn't understand Windows (non standard) calling
|
||||||
extern int foo(int bar = 1);
|
conventions in the first place, so can't regenerate them.
|
||||||
|
*/
|
||||||
hence, the user MUST provide the declaration, and swig
|
|
||||||
shouldn't attempt to deduce it.
|
|
||||||
*/
|
|
||||||
if (f_header) {
|
|
||||||
int extern_c = Cmp(storage,"externc") == 0;
|
|
||||||
int need_extern = CPlusPlus ? extern_c : 1;
|
|
||||||
if (!NoExtern && need_extern) {
|
|
||||||
if ((storage && Strstr(storage,"extern")) || (ForceExtern && !storage)) {
|
|
||||||
String *str = SwigType_str(ty,name);
|
String *str = SwigType_str(ty,name);
|
||||||
Printf(f_header,"extern ", str);
|
|
||||||
if (extern_c) {
|
|
||||||
/* here 'extern "C"' is needed */
|
|
||||||
Printf(f_header, "\"C\" ");
|
|
||||||
}
|
|
||||||
Printf(f_header,"%s", str);
|
Printf(f_header,"%s", str);
|
||||||
Delete(str);
|
Delete(str);
|
||||||
|
{
|
||||||
|
DOH *t = Getattr(n,"throws");
|
||||||
|
if (t) {
|
||||||
|
Printf(f_header," throw(");
|
||||||
|
while (t) {
|
||||||
|
Printf(f_header,"%s", Getattr(t,"type"));
|
||||||
|
t = nextSibling(t);
|
||||||
|
if (t) Printf(f_header,",");
|
||||||
|
}
|
||||||
|
Printf(f_header,")");
|
||||||
|
}
|
||||||
|
}
|
||||||
Printf(f_header,";\n");
|
Printf(f_header,";\n");
|
||||||
|
} else if (Cmp(storage,"externc") == 0) {
|
||||||
|
/* here 'extern "C"' is needed */
|
||||||
|
String *str = SwigType_str(ty,name);
|
||||||
|
Printf(f_header, "extern \"C\" %s;\n", str);
|
||||||
|
Delete(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -858,7 +861,7 @@ int Language::cDeclaration(Node *n) {
|
||||||
if (!CurrentClass) {
|
if (!CurrentClass) {
|
||||||
if ((Cmp(storage,"extern") == 0) || ForceExtern) {
|
if ((Cmp(storage,"extern") == 0) || ForceExtern) {
|
||||||
f_header = Swig_filebyname("header");
|
f_header = Swig_filebyname("header");
|
||||||
if (!NoExtern) {
|
if (AddExtern) {
|
||||||
if (f_header) {
|
if (f_header) {
|
||||||
String *str = SwigType_str(ty,name);
|
String *str = SwigType_str(ty,name);
|
||||||
Printf(f_header,"extern %s;\n", str);
|
Printf(f_header,"extern %s;\n", str);
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ char cvsroot_main_cxx[] = "$Header$";
|
||||||
int GenerateDefault = 1; // Generate default constructors
|
int GenerateDefault = 1; // Generate default constructors
|
||||||
char *Config = 0;
|
char *Config = 0;
|
||||||
int Verbose = 0;
|
int Verbose = 0;
|
||||||
int NoExtern = 0;
|
int AddExtern = 0;
|
||||||
int NoExcept = 0;
|
int NoExcept = 0;
|
||||||
char *SwigLib;
|
char *SwigLib;
|
||||||
int SwigRuntime = 0; // 0 = no option, 1 = -c or -runtime, 2 = -noruntime
|
int SwigRuntime = 0; // 0 = no option, 1 = -c or -runtime, 2 = -noruntime
|
||||||
|
|
@ -82,7 +82,7 @@ static const char *usage2 = (const char*)"\
|
||||||
-nodefault - Do not generate constructors/destructors\n\
|
-nodefault - Do not generate constructors/destructors\n\
|
||||||
-nodirprot - Do not wrap director protected members\n\
|
-nodirprot - Do not wrap director protected members\n\
|
||||||
-noexcept - Do not wrap exception specifiers\n\
|
-noexcept - Do not wrap exception specifiers\n\
|
||||||
-noextern - Do not generate extern declarations\n\
|
-addextern - Add extra extern declarations\n\
|
||||||
-nopreprocess - Skip the preprocessor step\n\
|
-nopreprocess - Skip the preprocessor step\n\
|
||||||
-notemplatereduce - Disable reduction of the typedefs in templates \n\
|
-notemplatereduce - Disable reduction of the typedefs in templates \n\
|
||||||
-o <outfile> - Set name of the output file to <outfile>\n\
|
-o <outfile> - Set name of the output file to <outfile>\n\
|
||||||
|
|
@ -421,7 +421,11 @@ void SWIG_getoptions(int argc, char *argv[])
|
||||||
NoExcept = 1;
|
NoExcept = 1;
|
||||||
Swig_mark_arg(i);
|
Swig_mark_arg(i);
|
||||||
} else if (strcmp(argv[i],"-noextern") == 0) {
|
} else if (strcmp(argv[i],"-noextern") == 0) {
|
||||||
NoExtern = 1;
|
Swig_warning(WARN_DEPRECATED_NOEXTERN, "SWIG",1, "-noextern command line option is deprecated; extern is no longer generated by default.\n");
|
||||||
|
AddExtern = 0;
|
||||||
|
Swig_mark_arg(i);
|
||||||
|
} else if (strcmp(argv[i],"-addextern") == 0) {
|
||||||
|
AddExtern = 1;
|
||||||
Swig_mark_arg(i);
|
Swig_mark_arg(i);
|
||||||
} else if (strcmp(argv[i],"-show_templates") == 0) {
|
} else if (strcmp(argv[i],"-show_templates") == 0) {
|
||||||
Swig_cparse_debug_templates(1);
|
Swig_cparse_debug_templates(1);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue