Don't try to export variables in namespace scope directly

The generated code, which used C++ scope operator "::" in a C header, didn't
compile and couldn't work anyhow.

Just use the accessor functions for not really global variables.
This commit is contained in:
Vadim Zeitlin 2016-04-20 23:52:32 +02:00
commit 2ec9d9da6e
2 changed files with 11 additions and 6 deletions

View file

@ -57,7 +57,6 @@ FAILING_CPP_TESTS := \
class_ignore \
class_scope_weird \
constant_pointers \
cpp_namespace \
cpp_typedef \
c_backend_cpp_natural_std_string \
c_backend_cpp_exception \

View file

@ -458,11 +458,17 @@ public:
* ------------------------------------------------------------------------ */
virtual int globalvariableHandler(Node *n) {
// If we can export the variable directly, do it, this will be more convenient to use from C code than accessor functions.
if (String* const var_decl = make_c_var_decl(n)) {
Printv(f_wrappers_decl, "SWIGIMPORT ", var_decl, ";\n\n", NIL);
Delete(var_decl);
return SWIG_OK;
// We can't export variables defined inside namespaces to C directly, whatever their type.
String* const scope = Swig_scopename_prefix(Getattr(n, "name"));
if (!scope) {
// If we can export the variable directly, do it, this will be more convenient to use from C code than accessor functions.
if (String* const var_decl = make_c_var_decl(n)) {
Printv(f_wrappers_decl, "SWIGIMPORT ", var_decl, ";\n\n", NIL);
Delete(var_decl);
return SWIG_OK;
}
} else {
Delete(scope);
}
// Otherwise, e.g. if it's of a C++-only type, or a reference, generate accessor functions for it.