Merge branch 'swig-fortran/extern-c-int'

Fixes #2199
This commit is contained in:
Olly Betts 2022-02-11 08:28:27 +13:00
commit b624d17f3f
4 changed files with 37 additions and 4 deletions

View file

@ -16,7 +16,9 @@ thread_local static int tsval;
extern thread_local int etval;
thread_local extern int teval;
extern "C" thread_local int ectval;
extern "C" { thread_local int ectval2 = 56; }
extern "C++" thread_local int ecpptval;
extern "C++" { thread_local int ecpptval2 = 67; }
thread_local int ThreadLocals::stval = 11;
thread_local int ThreadLocals::tsval = 22;
@ -30,6 +32,10 @@ thread_local const int ThreadLocals::tscval99;
// externs
thread_local int etval = 33;
thread_local int teval = 44;
extern "C" {
thread_local int ectval = 55;
}
extern "C++" {
thread_local int ecpptval = 66;
}
%}

View file

@ -5,6 +5,7 @@ extern "C" {
void RealFunction(int value);
typedef void Function1(int value); // Fails
typedef int Integer1;
int Integer3;
}
typedef void Function2(int value); // Works
typedef int Integer2;
@ -27,5 +28,14 @@ Hook2_t hook2;
extern "C" typedef int Integer;
Integer int1;
extern "C" int int2;
extern "C" { extern int int3; }
extern "C" { int int4 = 789; }
%}
%{
extern "C" {
int int2 = 123;
int int3 = 456;
}
%}

View file

@ -1,3 +1,6 @@
import extern_c
extern_c.RealFunction(2)
assert extern_c.cvar.int2 == 123
assert extern_c.cvar.int3 == 456
assert extern_c.cvar.int4 == 789

View file

@ -3134,14 +3134,22 @@ c_declaration : c_decl {
Setattr($$,"name",$2);
appendChild($$,n);
while (n) {
SwigType *decl = Getattr(n,"decl");
if (SwigType_isfunction(decl) && !Equal(Getattr(n, "storage"), "typedef")) {
String *s = Getattr(n, "storage");
if (s) {
if (Strstr(s, "thread_local")) {
Insert(s,0,"externc ");
} else if (!Equal(s, "typedef")) {
Setattr(n,"storage","externc");
}
} else {
Setattr(n,"storage","externc");
}
n = nextSibling(n);
}
} else {
Swig_warning(WARN_PARSE_UNDEFINED_EXTERN,cparse_file, cparse_line,"Unrecognized extern type \"%s\".\n", $2);
if (!Equal($2,"C++")) {
Swig_warning(WARN_PARSE_UNDEFINED_EXTERN,cparse_file, cparse_line,"Unrecognized extern type \"%s\".\n", $2);
}
$$ = new_node("extern");
Setattr($$,"name",$2);
appendChild($$,firstChild($5));
@ -5087,7 +5095,13 @@ extern_string : EXTERN string {
storage_class : EXTERN { $$ = "extern"; }
| extern_string { $$ = $1; }
| extern_string THREAD_LOCAL { $$ = "thread_local"; }
| extern_string THREAD_LOCAL {
if (Equal($1, "extern")) {
$$ = "extern thread_local";
} else {
$$ = "externc thread_local";
}
}
| extern_string TYPEDEF { $$ = "typedef"; }
| STATIC { $$ = "static"; }
| TYPEDEF { $$ = "typedef"; }