Commit graph

142 commits

Author SHA1 Message Date
William S Fulton
46f7501d94 Cleanup SWIG_VERSION definition
Add Swig_obligatory_macros which must be called by each
target language to define SWIG_VERSION correctly
in the generated code, as well as the language specific
macro SWIGXXX where XXX is the target language name.

Drop the #ifdef SWIGXXX that was previously generated -
I can't see the point of this and if users are defining
this macro somehow, then users will need to change this

Closes #1050
2022-10-13 19:47:43 +01:00
Olly Betts
80d05a1a6c Eliminate 2 redundant copies of swig banner
We had a banner for C, a banner for target languages (parameterised
to allow the comment sequence to be specified) and a special banner
for XML files in scilab.cxx.

The XML variant was only needed because the standard banner contains
`--` for a hyphen, so we now use ` - ` for that instead.

The C banner now calls Swig_banner_target_lang() with a suitable
comment sequence to print the actual banner text.
2022-10-06 14:33:15 +13:00
Olly Betts
631b41ae7b Use https for swig.org links 2022-10-06 13:16:39 +13:00
Olly Betts
6b4d5fe3f0 Remove remaining code to support macos9
This OS has been unsupported for over 20 years.  We stopped providing
macswig builds more than 20 years ago too:

https://sourceforge.net/projects/swig/files/macswig/

The required SIOUX library doesn't seem to be available anywhere
now either.

Closes #2323
2022-07-19 11:22:37 +12:00
Olly Betts
6c4010e442 Resolve -Wstrict-prototypes warnings with clang-15
warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
2022-06-30 12:52:00 +12:00
Olly Betts
55377bdc08 Add DOH Exit() and SetExitHandler()
Exit() is a wrapper for exit() by default, but SetExitHandler() allows
specifying a function to call instead.

This means that failures within DOH (e.g. Malloc() failing due to lack
of memory) will now perform cleanup such as removing output files.

This commit also cleans up exit statuses so SWIG should now reliably
exit with status 0 if the run was successful and status 1 if there was
an error (or a warning and -Werror was in effect).

Previously in some situations SWIG would try to exit with the status set
to the number of errors encountered, but that's problematic - for
example if there were 256 errors this would result in exit status 0 on
most platforms.  Also some error statuses have special meanings e.g.
those defined by <sysexits.h>.

Also SWIG/Javascript tried to exit with status -1 in a few places (which
typically results in exit status 255).
2022-03-06 12:33:54 +13:00
Olly Betts
e38847f7e1 Fail cleanly on allocation failures
Previously code in the SWIG tool didn't handle allocation failures
well.  Most places didn't check for NULL return from
malloc()/realloc()/calloc() at all, typically resulting in undefined
behaviour, and some places used assert() to check for a NULL return
(which is a misuse of assert() and such checks disappear if built with
NDEBUG defined leaving us back with undefined behaviour).

All C allocations are now done via wrapper functions (Malloc(),
Realloc() and Calloc()) which emit and error and exit with non-zero
status on failure, so a non-NULL return can be relied upon.

Fixes #1901.
2022-03-04 11:47:49 +13:00
William S Fulton
a5315e1159 gcc warning fix
warning: control reaches end of non-void function [-Wreturn-type]
2022-02-07 21:50:13 +00:00
Olly Betts
467c530e65 Remove support for the "command" encoder
The "command" encoder was mostly intended for use in `%rename` - most
uses can be achieved using the "regex" encoder, so we recommend using
that instead.

The "command" encoder suffers from a number of issues - as the
documentation for it admitted, "[it] is extremely slow compared to all
the other [encoders] as it involves spawning a separate process and
using it for many declarations is not recommended" and that it "should
generally be avoided because of performance considerations".

But it's also not portable.  The design assumes that `/bin/sh` supports
`<<<` but that's a bash-specific feature so it doesn't work on platforms
where `/bin/sh` is not bash - it fails on Debian, Ubuntu and probably
some other Linux distros, plus most non-Linux platforms.  Microsoft
Windows doesn't even have a /bin/sh as standard.

Finally, no escaping of the passed string is done, so it has potential
security issues (though at least with %rename the input is limited to
valid C/C++ symbol names).

Fixes #1806
2022-02-07 09:47:01 +13:00
William S Fulton
f8e4a5cc25 Few more PCRE to PCRE2 changes 2022-01-21 18:35:20 +00:00
Julien Schueller
15515f390c PCRE2
Closes #2120
2022-01-21 07:46:08 +01:00
Noah Stegmaier
3cc4d76e23 escape filepaths 2020-06-04 12:10:24 +02:00
William S Fulton
2cf075558c Replace all exit() with SWIG_exit()
For consistent cleanup on error
2019-07-31 00:08:49 +01:00
William S Fulton
33921666a1 Merge branch 'vadz-doxygen'
This is the Doxygen work begun in Google Summer of Code projects 2008
and 2012 and subsequently improved by numerous contributors.

* vadz-doxygen: (314 commits)
  Add changes entry for Doxygen support
  Add some missing doctype tyemaps
  Doxygen warnings cleanup
  Move doxygen warning numbers
  Add Python doxygen example
  Doxygen example
  Add Doxygen to include paths
  Doxygen source rename
  More merge fixes from doxygen branches
  Correct python example headers
  Correct source code headers
  Another merge fix from doxygen branches
  Java enums output format fixes
  Add omitted doxygen_parsing_enums testcase
  PEP8 conformance for comment verifier module
  Clean up merge problem
  Doxygen html tweaks
  Update html chapter numbering for added Doxygen chapter
  Fixes to makechap.py to detect ill-formed headers
  html fixes for Doxygen
  Add missing CPlusPlus17.html file
  Format files to unix format
  Doxygen testcase tweak to match that in the html docs
  Doxygen html documentation updates and corrections
  Remove doxygen Examples subdirectory
  Beautify doxygen source code
  Code formatting fixes in doxygen code
  Remove unused doxygen code
  new_node refactor
  Various merge fixes in doxygen branches
  Unused variable warning fix
  Fix wrongly resetting indent after formulae in Doxygen comments
  Add support for doxygen:alias feature
  Get rid of meaningless return type of DoxygenParser methods
  Return enum, not untyped int, when classifying Doxygen commands
  Get rid of unnecessary "typedef enum" in C++ code
  Use slash, not backslash, in "C/C++" in the documentation
  Replace literal "<" with "&lt;" in HTML documentation
  Fix broken link to java.sun.com in Doxygen documentation
  Fix using com.sun.tools.javadoc package under macOS
  Fix error reporting for special characters in Doxygen parsing code
  Switch Python Doxygen unit tests to use inspect.getdoc()
  Use correct separator in Java class path under Windows.
  Remove executable permission from appveyor.yml.
  Use JAVA_HOME value in configure to detect Java.
  Display JAVA_HOME value in "make java_version".
  Fix harmless MSVC warning in DoxygenTranslator code.
  Reset "_last" for all but first enum elements.
  Don't duplicate Javadoc from global enum Doxygen comments twice.
  Move Doxygen comments concatenation from the parser to the lexer.
  Fix shift/reduce conflicts in Doxygen pre/post comment parsing.
  Rewrote part of the grammar dealing with Doxygen comments for enums.
  No changes, just remove spurious white space only differences.
  Move Doxygen comment mangling from the parser to the lexer.
  Merge "-builtin" autodoc bugs workarounds from master into test.
  Quote JAVA_HOME variable value in Java test suite makefile.
  Remove unused C_COMMENT_STRING terminal from the grammar.
  Fix missing returns in the Doxygen test suite code.
  Fix trimming whitespace from Doxygen comments.
  Remove code not doing anything from PyDocConverter.
  Remove unused <sstream> header.
  Remove unreferenced struct declaration.
  Remove unused Swig_warn() function.
  Remove any whitespace before ignored Doxygen commands.
  Remove trailing space from one of Doxygen tests.
  Fix autodoc strings generated in Python builtin case and the test.
  Fix Doxygen unit test in Python "-builtin" case.
  Use class docstrings in "-builtin" Python case.
  Don't indent Doxygen doc strings in generated Python code.
  Add a possibility to flexibly ignore custom Doxygen tags.
  Stop completely ignoring many Doxygen comments.
  Fix structural Doxygen comment recognition in the parser.
  No changes, just make checking for Doxygen structural tags more sane.
  Use "//", not "#", for comments in SWIG input.
  Allow upper case letters and digits in Doxygen words.
  Pass the node the Doxygen comment is attached to to DoxygenParser.
  Get rid of findCommand() which duplicaed commandBelongs().
  Recognize unknown Doxygen tags correctly.
  No real changes, just pass original command to commandBelongs().
  Describe Doxygen-specific %features in a single place.
  Give warnings for unknown Doxygen commands in Doxygen parser.
  Document the return type when translating Doxygen @return to Python.
  Fix translated Doxygen comments for overloaded functions in Python.
  Also merge Doxygen comments for overloaded constructors in Python.
  Allow using enum elements as default values for Python functions.
  Don't always use "*args" for all Python wrapper functions.
  No real changes, just make PYTHON::check_kwargs() const.
  Refactor: move makeParameterName() to common Language base class.
  Remove long line wrapping from Python parameter list generation code.
  Simplify and make more efficient building Python docstrings.
  Translate Doxygen code blocks to Sphinx code blocks.
  Add a simple test of multiple parameters to Doxygen test suite.
  Make Python parameters types hyperlinks in the doc strings.
  Make Language::classLookup() and enumLookup() static.
  Fix arguments of @param, @return etc translations to Python.
  Remove unused method from PyDocConverter.
  No real changes, just remove an unnecessary variable.
  Preserve relative indentation when parsing Doxygen comments.
  Use Sphinx-friendly formatting for overloaded functions documentation.
  Add poor man trailing white space detection to Doxygen Python tests.
  ...
2018-06-07 08:13:10 +01:00
luz.paz
60dfa31a67 Misc. typos
found via `codespell` and `grep`
2018-05-17 10:04:23 -04:00
Vadim Zeitlin
db65ae5aea Merge branch 'master' into doxygen
Fix the usual conflicts in autodoc unit test due to fixing the
divergences in autodoc generation between builtin and default cases in
this branch.
2017-09-19 14:02:53 +02:00
William S Fulton
959e627208 %template scope enforcement and class definition fixes
The scoping rules around %template have been specified and enforced.
The %template directive for a class template is the equivalent to an
explicit instantiation of a C++ class template. The scope for a valid
%template instantiation is now the same as the scope required for a
valid explicit instantiation of a C++ template. A definition of the
template for the explicit instantiation must be in scope where the
instantiation is declared and must not be enclosed within a different
namespace.

For example, a few %template and explicit instantiations of std::vector
are shown below:

  // valid
  namespace std {
    %template(vin) vector<int>;
    template class vector<int>;
  }

  // valid
  using namespace std;
  %template(vin) vector<int>;
  template class vector<int>;

  // valid
  using std::vector;
  %template(vin) vector<int>;
  template class vector<int>;

  // ill-formed
  namespace unrelated {
    using std::vector;
    %template(vin) vector<int>;
    template class vector<int>;
  }

  // ill-formed
  namespace unrelated {
    using namespace std;
    %template(vin) vector<int>;
    template class vector<int>;
  }

  // ill-formed
  namespace unrelated {
    namespace std {
      %template(vin) vector<int>;
      template class vector<int>;
    }
  }

  // ill-formed
  namespace unrelated {
    %template(vin) std::vector<int>;
    template class std::vector<int>;
  }

When the scope is incorrect, an error now occurs such as:

cpp_template_scope.i:34: Error: 'vector' resolves to 'std::vector' and
was incorrectly instantiated in scope 'unrelated' instead of within scope 'std'.

Previously SWIG accepted the ill-formed examples above but this led to
numerous subtle template scope problems especially in the presence of
using declarations and using directives as well as with %feature and %typemap.

Actually, a valid instantiation is one which conforms to the C++03
standard as C++11 made a change to disallow using declarations and
using directives to find a template.

  // valid C++03, ill-formed C++11
  using std::vector;
  template class vector<int>;

Similar fixes for defining classes using forward class references have
also been put in place. For example:

namespace Space1 {
  struct A;
}
namespace Space2 {
  struct Space1::A {
    void x();
  }
}

will now error out with:

cpp_class_definition.i:5: Error: 'Space1::A' resolves to 'Space1::A' and
was incorrectly instantiated in scope 'Space2' instead of within scope 'Space1'.
2017-08-16 00:24:25 +01:00
William S Fulton
d387e749f5 Warning fix for visual c++ 2017-02-04 19:18:54 +00:00
William S Fulton
25ac8f97f6 Fix popen pclose warnings compiling under wine
Fix i686-w64-mingw32-g++ compiler on linux warning:

In file included from Swig/swig.h:21:0,
                 from Swig/misc.c:14:
Swig/misc.c:1125:14: warning: ‘_popen’ redeclared without dllimport attribute: previous dllimport ignored [-Wattributes]
 extern FILE *popen(const char *command, const char *type);
              ^
Swig/misc.c:1126:12: warning: ‘_pclose’ redeclared without dllimport attribute: previous dllimport ignored [-Wattributes]
 extern int pclose(FILE *stream);
2017-02-04 19:18:54 +00:00
Vadim Zeitlin
e668c47b70 Merge branch 'master' into doxygen
The way Python docstrings are indented has changed on master, so use the
standard inspect module in Python autodoc unit test to ignore the differences
in their indentation level between -builtin and non-builtin cases to make the
test still pass with the branch version, which avoids the use of different
(but almost identical) values in the test itself.
2016-12-12 01:24:17 +01:00
William S Fulton
ac495d5c66 Merge branch 'char-escaping'
* char-escaping:
  Add missing string_constant.i testcase
  changes file update for char wrappers
  C# char wrappers fixes for enum values, static const member char values and %csconst
  D testing added for %dmanifestconst and char constants
  Fix wrapping D constants using %dmanifestconst
  Php fix for enum value of '\0'
  Fix static const char member variables wrappers with %javaconst(1).
  Expand char testing in enums and %constant
  Java char changes file update
  Java enum and static member variable escaping fix for chars
  Add tests for enum values and static const member variables chars containing escape sequences
  Minor documentation tweak

Conflicts:
	CHANGES.current
2016-03-12 23:27:51 +00:00
William S Fulton
5fb6537f69 C# char wrappers fixes for enum values, static const member char values and %csconst
Use hex escaping for char values used as C# constants
2016-03-12 18:52:49 +00:00
William S Fulton
4a3e1fd44c Add rstrip encoder for use in %rename.
This is like the strip encoder but strips the symbol's suffix instead
of the prefix.
2016-03-02 07:11:09 +00:00
William S Fulton
f112a0b610 Correct regex example comment 2016-02-29 07:55:01 +00:00
Vadim Zeitlin
302955a152 Another merge with master.
Updated Doxygen error numbers yet again, as Python errors got added in the
meanwhile, pushing the Doxygen ones further off.

And re-merged PEP8/whitespace-related conflicts in autodoc_runme.py once again
(if anybody is looking for a motivating example about why significant
whitespace is bad, here is a great use case).
2015-07-20 00:44:26 +02:00
William S Fulton
fb2b1af2e7 Warning fixes for 64bit visual c++ on Windows 2015-07-03 20:59:24 +01:00
William S Fulton
edcdaaec16 Warning fixes for 64bit visual c++ on Windows 2015-07-03 20:59:24 +01:00
Vadim Zeitlin
1ebd2334b8 Merge branch 'master' into doxygen
Merge with ~3.0.1 sources from master.
2014-04-30 18:37:57 +02:00
William S Fulton
eab762baa2 gcc-3.4 warning fix 2014-03-15 22:45:28 +00:00
Vladimir Kalinin
b4fef06c42 fixed %template within %extend, test added
fixed language symbol table nested classes name separator, test added
fixed %feature "flatnested" working with %extend
fixed Swig_offset_string for empty string
added simple template to save/restore values in current scope (readability reasons)
2013-12-19 02:11:22 +04:00
William S Fulton
7103a06849 Swig_offset_string moved to misc.c 2013-12-05 20:59:09 +00:00
Vadim Zeitlin
72afb74f47 Add support for case conversion characters in regex substitutions.
Allow using Perl-like \l, \L, \u, \U and \E escape sequences in the
substitution string used with %rename("%(regex:/pattern/subst/)s").
This is useful for e.g. title casing all string after removing some prefix.

Closes #82
2013-10-15 07:17:56 +01:00
William S Fulton
bcb7aee022 Merge branch 'master' into gsoc2009-matevz
Conflicts:
	Examples/Makefile.in
	Examples/guile/Makefile.in
	Lib/php/php.swg
	Makefile.in
	Source/CParse/parser.y
	configure.ac
2013-10-10 07:26:09 +01:00
Sylvestre Ledru
7a88729c87 Remove trailing spaces in the generated code.
No functional changes
2013-09-13 10:02:39 +02:00
Olly Betts
918c64af84 Fix comment typos 2013-06-04 12:44:28 +12:00
William S Fulton
e44656cfe5 Add support for extern "C" thread_local 2013-02-08 18:45:29 +00:00
William S Fulton
7fcfdeee08 Fixes detecting if a variable is extern when using 'extern thread_local' 2013-02-08 07:38:10 +00:00
William S Fulton
b725625e6f Add support for thread_local when specified with other legitimate storage class specifiers - extern and static 2013-02-08 06:36:39 +00:00
William S Fulton
7841a0d097 Remove cvs/svn Id strings 2013-01-12 01:21:16 +00:00
William S Fulton
b107f57e59 NULL pointer clarification in Swig_new_subdirectory
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13897 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-11-16 19:39:50 +00:00
William S Fulton
e475ce1d6b Fix race condition 'time of check time of use' - TOCTOU - when creating subdirectories.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13891 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-11-16 19:32:40 +00:00
William S Fulton
d4b7275f51 Fix Swig_scopename_last. It was truncating the first two letters of a symbol if the symbol did not contain any qualifiers. Does not seem to change much currently except some generated error messages in overloaded templated methods in classes. However the fix is needed for some commits shortly forthcoming.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13881 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-11-13 22:18:52 +00:00
William S Fulton
af1c6ac3c3 Merge trunk (up to just after swig 2.0.5 release - rev 13009) to gsoc2008-cherylfoil
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-cherylfoil@13017 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-04-27 18:55:37 +00:00
William S Fulton
29fd1e3ce4 Fix crash when requesting more matches than available in regex
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12904 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-01-27 20:55:32 +00:00
Olly Betts
5b8ca942ad This is a minor portability fix - isdigit() (and friends) are only portably defined for unsigned char values (though glibc extends them to work for signed char too) so this fixes this code to handle top bit set characters on non-glibc platforms where char is signed by default.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12846 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2011-11-28 04:08:25 +00:00
William S Fulton
17c5f881ee warning fix
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12827 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2011-10-19 20:41:24 +00:00
William S Fulton
02750e80a3 Fix #3127394 - use of network paths on Windows/MSys.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12322 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2010-12-06 20:43:56 +00:00
William S Fulton
766ed8db37 Add -pcreversion option to display PCRE version information
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12239 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2010-10-01 23:52:46 +00:00
William S Fulton
d1e6643161 Expand the family of debug print functions for displaying DOH types. Provide gdb support for calling these. Document improved debugging experience.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12221 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2010-09-15 20:17:11 +00:00
Vadim Zeitlin
024ed6ce2a Fix bug in applying regex replacement to non-matching strings.
We didn't handle pcre_exec() return code properly and so the replacement could
be still done even if there was no match if the replacement part contained
anything else than back-references (in this, the only tested so far, case the
replacement was still done but the result turned out to be empty and the
calling code assumed the regex didn't match).

Do check for PCRE_ERROR_NOMATCH now and also give an error message if another
error unexpectedly occurred.

Add a test case for the bug that was fixed.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12187 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2010-08-14 14:12:23 +00:00