git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7306 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2005-06-18 08:04:30 +00:00
commit 45fb27f977
3 changed files with 55 additions and 28 deletions

View file

@ -138,6 +138,7 @@ CPP_TEST_CASES += \
extend_placement \
extend_template \
extend_template_ns \
extern_namespace \
extern_throws \
features \
friends \

View 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;
}
%}

View file

@ -799,38 +799,41 @@ int Language::cDeclaration(Node *n) {
/* Transform the node into a 'function' node and emit */
if (!CurrentClass) {
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) {
if (f_header) {
if ((Cmp(storage,"extern") == 0) || (ForceExtern && !storage)) {
/* we don't need the 'extern' part in the C/C++ declaration,
and it produces some problems when namespace and SUN
Studio is used.
--- foo.c ---
int foo(int bar) {
}
--- foo.c ---
Printf(f_header,"extern %s", SwigType_str(ty,name));
*/
String *str = SwigType_str(ty,name);
Printf(f_header,"%s", 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,")");
}
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);
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,";\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);
}
Printf(f_header,"%s", str);
Delete(str);
Printf(f_header,";\n");
}
}
}