diff --git a/Lib/typemaps/swigmacros.swg b/Lib/typemaps/swigmacros.swg index 687b0680e..3a63a256c 100644 --- a/Lib/typemaps/swigmacros.swg +++ b/Lib/typemaps/swigmacros.swg @@ -31,7 +31,7 @@ %as_voidptrptr(a) reinterpret_cast(a) or their C unsafe versions. In C++ we use the safe version unless - SWIG_NO_CPLUSPLUS_CAST is defined + SWIG_NO_CPLUSPLUS_CAST is defined (usually via the -nocppcast swig flag). Memory allocation: @@ -123,7 +123,14 @@ nocppval * Casting operators * ----------------------------------------------------------------------------- */ -#if defined(__cplusplus) && !defined(SWIG_NO_CPLUSPLUS_CAST) +#if defined(SWIG_NO_CPLUSPLUS_CAST) +/* Disable 'modern' cplusplus casting operators */ +# if defined(SWIG_CPLUSPLUS_CAST) +# undef SWIG_CPLUSPLUS_CAST +# endif +#endif + +#if defined(__cplusplus) && defined(SWIG_CPLUSPLUS_CAST) # define %const_cast(a,Type...) const_cast< Type >(a) # define %static_cast(a,Type...) static_cast< Type >(a) # define %reinterpret_cast(a,Type...) reinterpret_cast< Type >(a) diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index a1a40d8ea..81434ce0b 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -19,8 +19,10 @@ static String *op_prefix = 0; static const char *usage = "\ Octave Options (available with -octave)\n\ + -cppcast - Enable C++ casting operators (default)\n\ -globals - Set used to access C global variables [default: 'cvar']\n\ Use '.' to load C global variables into module namespace\n\ + -nocppcast - Disable C++ casting operators\n\ -opprefix - Prefix for global operator functions [default: 'op_']\n\ \n"; @@ -90,7 +92,8 @@ public: } virtual void main(int argc, char *argv[]) { - + int cppcast = 1; + for (int i = 1; i < argc; i++) { if (argv[i]) { if (strcmp(argv[i], "-help") == 0) { @@ -113,13 +116,12 @@ public: } else { Swig_arg_error(); } - } else if (strcmp(argv[i], "-cppcast") == 0) { - Printf(stderr, "Deprecated command line option: %s. This option is now always on.\n", argv[i]); - Swig_mark_arg(i); - } else if (strcmp(argv[i], "-nocppcast") == 0) { - Printf(stderr, "Deprecated command line option: %s. This option is no longer supported.\n", argv[i]); - Swig_mark_arg(i); - SWIG_exit(EXIT_FAILURE); + } else if (strcmp(argv[i], "-cppcast") == 0) { + cppcast = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-nocppcast") == 0) { + cppcast = 0; + Swig_mark_arg(i); } } } @@ -128,6 +130,8 @@ public: global_name = NewString("cvar"); if (!op_prefix) op_prefix = NewString("op_"); + if(cppcast) + Preprocessor_define((DOH *) "SWIG_CPLUSPLUS_CAST", 0); SWIG_library_directory("octave"); Preprocessor_define("SWIGOCTAVE 1", 0); diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index 9fa301a21..4d2db6ec2 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -19,6 +19,8 @@ static const char *usage = "\ Perl5 Options (available with -perl5)\n\ -compat - Compatibility mode\n\ -const - Wrap constants as constants and not variables (implies -proxy)\n\ + -cppcast - Enable C++ casting operators\n\ + -nocppcast - Disable C++ casting operators, useful for generating bugs\n\ -nopm - Do not generate the .pm file\n\ -noproxy - Don't create proxy classes\n\ -proxy - Create proxy classes\n\ @@ -146,6 +148,7 @@ public: virtual void main(int argc, char *argv[]) { int i = 1; + int cppcast = 1; SWIG_library_directory("perl5"); @@ -186,22 +189,25 @@ public: } else if (strcmp(argv[i],"-v") == 0) { Swig_mark_arg(i); verbose++; + } else if (strcmp(argv[i], "-cppcast") == 0) { + cppcast = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-nocppcast") == 0) { + cppcast = 0; + Swig_mark_arg(i); } else if (strcmp(argv[i], "-compat") == 0) { compat = 1; Swig_mark_arg(i); } else if (strcmp(argv[i], "-help") == 0) { fputs(usage, stdout); - } else if (strcmp(argv[i], "-cppcast") == 0) { - Printf(stderr, "Deprecated command line option: %s. This option is now always on.\n", argv[i]); - Swig_mark_arg(i); - } else if (strcmp(argv[i], "-nocppcast") == 0) { - Printf(stderr, "Deprecated command line option: %s. This option is no longer supported.\n", argv[i]); - Swig_mark_arg(i); - SWIG_exit(EXIT_FAILURE); } } } + if (cppcast) { + Preprocessor_define((DOH *) "SWIG_CPLUSPLUS_CAST", 0); + } + Preprocessor_define("SWIGPERL 1", 0); // SWIGPERL5 is deprecated, and no longer documented. Preprocessor_define("SWIGPERL5 1", 0); diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 8f2964662..5a34d23ef 100755 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -110,6 +110,7 @@ static const char *usage1 = "\ Python Options (available with -python)\n\ -builtin - Create new python built-in types, rather than proxy classes, for better performance\n\ -castmode - Enable the casting mode, which allows implicit cast between types in python\n\ + -cppcast - Enable C++ casting operators (default) \n\ -dirvtable - Generate a pseudo virtual table for directors for faster dispatch \n\ -doxygen - Convert C++ doxygen comments to pydoc comments in proxy classes \n\ -debug-doxygen-parser - Display doxygen parser module debugging information\n\ @@ -122,6 +123,7 @@ Python Options (available with -python)\n\ static const char *usage2 = "\ -newvwm - New value wrapper mode, use only when everything else fails \n\ -nocastmode - Disable the casting mode (default)\n\ + -nocppcast - Disable C++ casting operators, useful for generating bugs\n\ -nodirvtable - Don't use the virtual table feature, resolve the python method each time (default)\n\ -noexcept - No automatic exception handling\n\ -noextranative - Don't use extra native C++ wraps for std containers when possible (default) \n\ @@ -308,6 +310,7 @@ public: * ------------------------------------------------------------ */ virtual void main(int argc, char *argv[]) { + int cppcast = 1; SWIG_library_directory("python"); @@ -347,6 +350,12 @@ public: use_kw = 1; SWIG_cparse_set_compact_default_args(1); Swig_mark_arg(i); + } else if (strcmp(argv[i], "-cppcast") == 0) { + cppcast = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-nocppcast") == 0) { + cppcast = 0; + Swig_mark_arg(i); } else if (strcmp(argv[i], "-outputtuple") == 0) { outputtuple = 1; Swig_mark_arg(i); @@ -434,8 +443,7 @@ public: } else if (strcmp(argv[i], "-relativeimport") == 0) { relativeimport = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i], "-cppcast") == 0 || - strcmp(argv[i], "-fastinit") == 0 || + } else if (strcmp(argv[i], "-fastinit") == 0 || strcmp(argv[i], "-fastquery") == 0 || strcmp(argv[i], "-fastunpack") == 0 || strcmp(argv[i], "-modern") == 0 || @@ -443,9 +451,8 @@ public: strcmp(argv[i], "-noproxydel") == 0 || strcmp(argv[i], "-safecstrings") == 0) { Printf(stderr, "Deprecated command line option: %s. This option is now always on.\n", argv[i]); - Swig_mark_arg(i); - } else if (strcmp(argv[i], "-aliasobj0") == 0 || - strcmp(argv[i], "-buildnone") == 0 || + } else if (strcmp(argv[i], "-buildnone") == 0 || + strcmp(argv[i], "-aliasobj0") == 0 || strcmp(argv[i], "-classic") == 0 || strcmp(argv[i], "-classptr") == 0 || strcmp(argv[i], "-new_repr") == 0 || @@ -453,7 +460,6 @@ public: strcmp(argv[i], "-newrepr") == 0 || strcmp(argv[i], "-noaliasobj0") == 0 || strcmp(argv[i], "-nobuildnone") == 0 || - strcmp(argv[i], "-nocppcast") == 0 || strcmp(argv[i], "-nofastinit") == 0 || strcmp(argv[i], "-nofastquery") == 0 || strcmp(argv[i], "-nomodern") == 0 || @@ -463,13 +469,16 @@ public: strcmp(argv[i], "-oldrepr") == 0 || strcmp(argv[i], "-proxydel") == 0) { Printf(stderr, "Deprecated command line option: %s. This option is no longer supported.\n", argv[i]); - Swig_mark_arg(i); SWIG_exit(EXIT_FAILURE); } } } + if (cppcast) { + Preprocessor_define((DOH *) "SWIG_CPLUSPLUS_CAST", 0); + } + if (doxygen) doxygenTranslator = new PyDocConverter(doxygen_translator_flags); diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index a82b8d15a..0fe730c83 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -208,6 +208,7 @@ static void writeListByLine(List *l, File *out, bool quote = 0) { static const char *usage = "\ R Options (available with -r)\n\ -copystruct - Emit R code to copy C structs (on by default)\n\ + -cppcast - Enable C++ casting operators (default) \n\ -debug - Output debug\n\ -dll - Name of the DLL (without the .dll or .so suffix).\n\ Default is the module name.\n\ @@ -2694,6 +2695,7 @@ String * R::runtimeCode() { Use Swig_mark_arg() to tell SWIG that it is understood and not to throw an error. **/ void R::main(int argc, char *argv[]) { + bool cppcast = true; init(); Preprocessor_define("SWIGR 1", 0); SWIG_library_directory("r"); @@ -2737,6 +2739,12 @@ void R::main(int argc, char *argv[]) { } else if(!strcmp(argv[i], "-debug")) { debugMode = true; Swig_mark_arg(i); + } else if (!strcmp(argv[i],"-cppcast")) { + cppcast = true; + Swig_mark_arg(i); + } else if (!strcmp(argv[i],"-nocppcast")) { + cppcast = false; + Swig_mark_arg(i); } else if (!strcmp(argv[i],"-copystruct")) { copyStruct = true; Swig_mark_arg(i); @@ -2755,13 +2763,10 @@ void R::main(int argc, char *argv[]) { } else if (!strcmp(argv[i], "-noaggressivegc")) { aggressiveGc = false; Swig_mark_arg(i); - } else if (strcmp(argv[i], "-cppcast") == 0) { - Printf(stderr, "Deprecated command line option: %s. This option is now always on.\n", argv[i]); - Swig_mark_arg(i); - } else if (strcmp(argv[i], "-nocppcast") == 0) { - Printf(stderr, "Deprecated command line option: %s. This option is no longer supported.\n", argv[i]); - Swig_mark_arg(i); - SWIG_exit(EXIT_FAILURE); + } + + if (cppcast) { + Preprocessor_define((DOH *) "SWIG_CPLUSPLUS_CAST", 0); } if (debugMode) { diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index 306570d96..b88ad3042 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -131,10 +131,12 @@ enum autodoc_t { static const char *usage = "\ Ruby Options (available with -ruby)\n\ -autorename - Enable renaming of classes and methods to follow Ruby coding standards\n\ + -cppcast - Enable C++ casting operators (default)\n\ -globalmodule - Wrap everything into the global module\n\ -initname - Set entry function to Init_ (used by `require')\n\ -minherit - Attempt to support multiple inheritance\n\ -noautorename - Disable renaming of classes and methods (default)\n\ + -nocppcast - Disable C++ casting operators, useful for generating bugs\n\ -prefix - Set a prefix to be prepended to all names\n\ "; @@ -842,6 +844,7 @@ public: virtual void main(int argc, char *argv[]) { + int cppcast = 1; int autorename = 0; /* Set location of SWIG library */ @@ -880,6 +883,12 @@ public: multipleInheritance = true; director_multiple_inheritance = 1; Swig_mark_arg(i); + } else if (strcmp(argv[i], "-cppcast") == 0) { + cppcast = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-nocppcast") == 0) { + cppcast = 0; + Swig_mark_arg(i); } else if (strcmp(argv[i], "-autorename") == 0) { autorename = 1; Swig_mark_arg(i); @@ -898,17 +907,15 @@ public: } } else if (strcmp(argv[i], "-help") == 0) { Printf(stdout, "%s\n", usage); - } else if (strcmp(argv[i], "-cppcast") == 0) { - Printf(stderr, "Deprecated command line option: %s. This option is now always on.\n", argv[i]); - Swig_mark_arg(i); - } else if (strcmp(argv[i], "-nocppcast") == 0) { - Printf(stderr, "Deprecated command line option: %s. This option is no longer supported.\n", argv[i]); - Swig_mark_arg(i); - SWIG_exit(EXIT_FAILURE); } } } + if (cppcast) { + /* Turn on cppcast mode */ + Preprocessor_define((DOH *) "SWIG_CPLUSPLUS_CAST", 0); + } + if (autorename) { /* Turn on the autorename mode */ Preprocessor_define((DOH *) "SWIG_RUBY_AUTORENAME", 0); diff --git a/Source/Modules/tcl8.cxx b/Source/Modules/tcl8.cxx index 57ef3e97b..1227af79c 100644 --- a/Source/Modules/tcl8.cxx +++ b/Source/Modules/tcl8.cxx @@ -76,6 +76,7 @@ public: * ------------------------------------------------------------ */ virtual void main(int argc, char *argv[]) { + int cppcast = 1; SWIG_library_directory("tcl"); @@ -105,19 +106,22 @@ public: } else if (strcmp(argv[i], "-nosafe") == 0) { nosafe = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i], "-help") == 0) { - fputs(usage, stdout); } else if (strcmp(argv[i], "-cppcast") == 0) { - Printf(stderr, "Deprecated command line option: %s. This option is now always on.\n", argv[i]); + cppcast = 1; Swig_mark_arg(i); } else if (strcmp(argv[i], "-nocppcast") == 0) { - Printf(stderr, "Deprecated command line option: %s. This option is no longer supported.\n", argv[i]); + cppcast = 0; Swig_mark_arg(i); - SWIG_exit(EXIT_FAILURE); + } else if (strcmp(argv[i], "-help") == 0) { + fputs(usage, stdout); } } } + if (cppcast) { + Preprocessor_define((DOH *) "SWIG_CPLUSPLUS_CAST", 0); + } + Preprocessor_define("SWIGTCL 1", 0); // SWIGTCL8 is deprecated, and no longer documented. Preprocessor_define("SWIGTCL8 1", 0);