fix for #1205859
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7306 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
6aac5f45b2
commit
0bf296c7ad
3 changed files with 55 additions and 28 deletions
|
|
@ -138,6 +138,7 @@ CPP_TEST_CASES += \
|
||||||
extend_placement \
|
extend_placement \
|
||||||
extend_template \
|
extend_template \
|
||||||
extend_template_ns \
|
extend_template_ns \
|
||||||
|
extern_namespace \
|
||||||
extern_throws \
|
extern_throws \
|
||||||
features \
|
features \
|
||||||
friends \
|
friends \
|
||||||
|
|
|
||||||
23
SWIG/Examples/test-suite/extern_namespace.i
Normal file
23
SWIG/Examples/test-suite/extern_namespace.i
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
%module extern_namespace
|
||||||
|
%inline %{
|
||||||
|
|
||||||
|
namespace foo {
|
||||||
|
|
||||||
|
extern int bar(int blah = 1);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
extern "C" int foobar(int i) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%{
|
||||||
|
int foo::bar(int blah) {
|
||||||
|
return blah;
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
@ -799,38 +799,41 @@ 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
|
||||||
|
|
||||||
if (!NoExtern) {
|
--- foo.c ---
|
||||||
if (f_header) {
|
int foo(int bar) {
|
||||||
if ((Cmp(storage,"extern") == 0) || (ForceExtern && !storage)) {
|
}
|
||||||
/* we don't need the 'extern' part in the C/C++ declaration,
|
--- foo.c ---
|
||||||
and it produces some problems when namespace and SUN
|
|
||||||
Studio is used.
|
|
||||||
|
|
||||||
Printf(f_header,"extern %s", SwigType_str(ty,name));
|
we could be tempted to declare
|
||||||
|
|
||||||
|
extern int foo(int bar);
|
||||||
|
|
||||||
|
but the real declaration could be:
|
||||||
|
|
||||||
|
extern int foo(int bar = 1);
|
||||||
|
|
||||||
|
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) {
|
||||||
String *str = SwigType_str(ty,name);
|
String *str = SwigType_str(ty,name);
|
||||||
|
if ((storage && Strstr(storage,"extern")) || (ForceExtern && !storage)) {
|
||||||
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue