Fix Octave C support by adding extern "C" around header section. Fix Octave examples (simple, contract, variables, pointer, funcptr) such that example.c files are built with C compiler, and wrappers with C++ compiler.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10299 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Xavier Delacour 2008-03-05 15:29:01 +00:00
commit 13c0b040fc
11 changed files with 83 additions and 51 deletions

View file

@ -296,6 +296,7 @@ classtypes(NewHash()),
enumtypes(NewHash()),
overloading(0),
multiinput(0),
cplus_runtime(0),
directors(0) {
argc_template_string = NewString("argc");
argv_template_string = NewString("argv[%d]");
@ -3065,6 +3066,22 @@ void Language::allow_multiple_input(int val) {
multiinput = val;
}
/* -----------------------------------------------------------------------------
* Language::enable_cplus_runtime_mode()
* ----------------------------------------------------------------------------- */
void Language::enable_cplus_runtime_mode() {
cplus_runtime = 1;
}
/* -----------------------------------------------------------------------------
* Language::cplus_runtime_mode()
* ----------------------------------------------------------------------------- */
int Language::cplus_runtime_mode() {
return cplus_runtime;
}
/* -----------------------------------------------------------------------------
* Language::allow_directors()
* ----------------------------------------------------------------------------- */

View file

@ -998,7 +998,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
if (depend) {
String *outfile;
if (!outfile_name) {
if (CPlusPlus) {
if (CPlusPlus || lang->cplus_runtime_mode()) {
outfile = NewStringf("%s_wrap.%s", Swig_file_basename(input_file), cpp_extension);
} else {
outfile = NewStringf("%s_wrap.c", Swig_file_basename(input_file));
@ -1116,7 +1116,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
/* Set some filename information on the object */
Setattr(top, "infile", input_file);
if (!outfile_name) {
if (CPlusPlus) {
if (CPlusPlus || lang->cplus_runtime_mode()) {
Setattr(top, "outfile", NewStringf("%s_wrap.%s", Swig_file_basename(input_file), cpp_extension));
} else {
Setattr(top, "outfile", NewStringf("%s_wrap.c", Swig_file_basename(input_file)));

View file

@ -40,10 +40,13 @@ public:
OCTAVE():f_runtime(0), f_header(0), f_wrappers(0),
f_init(0), f_initbeforefunc(0), f_directors(0), f_directors_h(0),
s_global_tab(0), s_members_tab(0), class_name(0) {
allow_overloading();
director_multiple_inheritance = 1;
director_language = 1;
} virtual void main(int argc, char *argv[]) {
enable_cplus_runtime_mode();
allow_overloading();
director_multiple_inheritance = 1;
director_language = 1;
}
virtual void main(int argc, char *argv[]) {
for (int i = 1; i < argc; i++) {
if (argv[i]) {
if (strcmp(argv[i], "-help") == 0) {
@ -118,8 +121,14 @@ public:
Printf(s_global_tab, "\nstatic const struct swig_octave_member swig_globals[] = {\n");
Printf(f_init, "void SWIG_init_user(octave_swig_type* module_ns)\n{\n");
if (!CPlusPlus)
Printf(f_header,"extern \"C\" {\n");
Language::top(n);
if (!CPlusPlus)
Printf(f_header,"}\n");
if (directorsEnabled())
Swig_insert_file("director.swg", f_runtime);
@ -545,7 +554,7 @@ public:
return SWIG_ERROR;
// This is a bug, due to the fact that swig_type -> octave_class mapping
// is not 1-to-1.
// is n-to-1.
static Hash *emitted = NewHash();
String *mangled_classname = Swig_name_mangle(Getattr(n, "name"));
if (Getattr(emitted, mangled_classname)) {

View file

@ -53,7 +53,8 @@ class Dispatcher {
public:
Dispatcher ():cplus_mode(PUBLIC) {
} virtual ~ Dispatcher () {
}
virtual ~ Dispatcher () {
}
virtual int emit_one(Node *n);
@ -216,6 +217,12 @@ public:
virtual String *runtimeCode(); /* returns the language specific runtime code */
virtual String *defaultExternalRuntimeFilename(); /* the default filename for the external runtime */
/* Runtime is C++ based, so extern "C" header section */
void enable_cplus_runtime_mode();
/* Returns the cpp_runtime mode */
int cplus_runtime_mode();
/* Allow director related code generation */
void allow_directors(int val = 1);
@ -295,6 +302,7 @@ private:
Hash *enumtypes;
int overloading;
int multiinput;
int cplus_runtime;
int directors;
};