Commit graph

5,234 commits

Author SHA1 Message Date
Olly Betts
d7625ee6b2 Fix fatal error implemented by assert
Calling assert() on a condition that's always false is not an
appropriate way to exit after emitting "Fatal error [...]" because
if NDEBUG is defined the assert() becomes a no-op and the error
stops actually being fatal.
2022-03-07 14:24:48 +13:00
Ian Lance Taylor
27bdbc1f05 swig -go: treat non-const references as pointers
Also clean up the handling of int* and int& to convert between the C
type int and the Go type int, which are often different sizes.

Fixes #2210
2022-03-05 21:57:36 -08:00
Olly Betts
747a51f095 Try to prevent direct use of exit(), malloc(), etc
Use `#pragma GCC poison` (supported since GCC 3, maybe earlier) when
compiling with GCC to help prevent direct uses being introduced for
functions which DOH provides a wrapper for.
2022-03-06 15:36:42 +13:00
Olly Betts
735732d721 Eliminate calls to abort()
Call Exit(EXIT_FAILURE) instead so that output files get removed.
2022-03-06 14:21:06 +13: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
8cd2cfa9d1 Improve the change to allow parsing 9%a
If there was a later syntax error, this could incorrectly get
reported as:

Error: Unknown directive '%a'.
2022-03-04 17:00:20 +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
Olly Betts
9eb75a0c07 Improve typemap method and attribute checking
Specifying a value on the typemap method now gives an error, e.g.:

%typemap(argout=123) char * ""

The old way of specifying a language name in the typemap attributes
is no longer supported (it has been deprecated for 16 years).

Closes #891
2022-03-03 18:46:15 +13:00
Julien Schueller
3ffbe29f52
Python: avoid unused SwigMethods_proxydocs var (#2222)
Avoids a warning since 3aa302c08f
2022-03-03 18:12:21 +13:00
Olly Betts
5755f399a2 Eliminate some temporary buffers 2022-03-03 12:27:04 +13:00
Olly Betts
b5dbcb4ece Rename free variable to jsfree
The collision with free() is a latent problem.
2022-03-03 12:23:41 +13:00
William S Fulton
3159de3e9f Add support for Python variable annotations as a feature.
Both function annotations and variable annotations are turned on using the
"python:annotations" feature. Example:

  %feature("python:annotations", "c");

  struct V {
    float val;
  };

The generated code contains a variable annotation containing the C float type:

  class V(object):
      val: "float" = property(_example.V_val_get, _example.V_val_set)
      ...

Python 3.5 and earlier do not support variable annotations, so variable
annotations can be turned off with a "python:annotations:novar" feature flag.
Example turning on function annotations but not variable annotations globally:

  %feature("python:annotations", "c");
  %feature("python:annotations:novar");

or via the command line:

  -features python:annotations=c,python:annotations:novar

Closes #1951
2022-03-02 19:33:03 +00:00
sethg
0ba26d8f73 Add property annotations 2022-03-02 07:44:04 +00:00
Olly Betts
3984321c44 Remove debug Printf accidentally left in previous commit 2022-03-02 16:08:22 +13:00
Olly Betts
aa24e6b22b Handle typemap argument without a value
This now gives an error, previously SWIG segfaulted.

Fixes #891
2022-03-02 15:56:43 +13:00
William S Fulton
064b8148ea Correct WARN_JAVA_TYPEMAP_INTERFACEMODIFIERS_UNDEF warning number 2022-03-01 23:10:25 +00:00
William S Fulton
2072ae19c9 Python function annotations removed from -py3 option.
Python function annotations containing C/C++ types are no longer
generated when using the -py3 option. Function annotations support
has been moved to a feature to provide finer grained control.
It can be turned on globally by adding:

  %feature("python:annotations", "c");

or by using the command line argument:

  -features python:annotations=c

The implementation is designed to be expandable to support different
annotations implementations. Future implementations could implement
something like the following for generating pure Python types:

  %feature("python:annotations", "python");

or typing module types to conform to PEP-484:

  %feature("python:annotations", "typing");

Closes #1561
Issue #735
2022-02-27 10:47:50 +00:00
Olly Betts
b127e11f1e Fix typos in docs and comments 2022-02-27 18:15:46 +13:00
William S Fulton
961424a986 Fix line/file info for methods added by using declarations 2022-02-26 20:07:58 +00:00
William S Fulton
79a1bbee8b Using declarations in inheritance hierarchy improvements.
- Improved documentation for using declarations.
- Issue new warning WARN_LANG_USING_NAME_DIFFERENT when there
  is a conflict in the target language name to be used when
  introducing a method via a using declaration. Previously
  the method was silently ignored. Issue #1840. Issue #655.
2022-02-26 12:46:06 +00:00
Olly Betts
7f37bfe2b5 Mark error messages more consistent
Always include English name of a mentioned character.
2022-02-25 10:07:17 +13:00
Olly Betts
d22b7dfaea scilab.cxx: Fix source code misindentation 2022-02-24 10:45:24 +13:00
Olly Betts
e95af9c474 Merge branch 'scilab-6' of https://github.com/davidcl/swig
Fixes #1751
2022-02-24 10:45:13 +13:00
Olly Betts
4986b8793d Emit preprocessor expr error for unary + on string
Previously other unary operators on a string all gave an error, but
unary + was handled as a no-op and so didn't.
2022-02-24 09:50:22 +13:00
Olly Betts
74d12d8c4c Don't report "Warning 202: Error: ..."
An invalid preprocessor expression is reported as a pair of
warnings with the second giving a more detailed message from the
expression evaluator.  Previously SWIG prefixed the second message
with "Error:" - that was confusing as it's actually only a warning
by default so we've now dropped this prefix.

Before:

x.i:1: Warning 202: Could not evaluate expression '1.2'
x.i:1: Warning 202: Error: 'Floating point constant in preprocessor expression'

Now:

x.i:1: Warning 202: Could not evaluate expression '1.2'
x.i:1: Warning 202: Floating point constant in preprocessor expression

See #1465
2022-02-24 08:40:27 +13:00
Olly Betts
81caed4f1d Clean up preprocessor expression evaluation code
Remove redundant code and add/improve comments.
2022-02-24 08:15:07 +13:00
Olly Betts
204a5f7bf3 Fix a preprocessor expression evaluation bug
A subexpression in parentheses lost its string/int type flag and
instead used whatever type was left in the stack entry from
previous use.  In practice we mostly got away with this because
most preprocessor expressions are integer, but it could have
resulted in a preprocessor expression incorrectly evaluating as
zero.  If -Wextra was in use you got a warning:

Warning 202: Error: 'Can't mix strings and integers in expression'

Fixes #1384
2022-02-23 18:53:59 +13:00
Clément DAVID
f93f8ad1d5 [Scilab] remove targetversion argument
This commit handles multi-version support at runtime, it
fixes:
 * 5.5.2 - with cutted long identifier name
 * 6.0.0 - with full string identifier
 * 6.1.0 - with 1 or 0 output argument

It also improves the codebase by:
 * Using `Char(X)` instead of `DohCheck(X)` and `Data(X)`
 * Using `Len(X)` instead of `strlen()`
 * Correctly detecting old Scilab versions
2022-02-21 10:01:59 +01:00
William S Fulton
d2e9b80be3 Merge branch 'using-declarations' into upstream-master
* using-declarations:
  Typo fixes
  Fix warning suppression for WARN_PARSE_USING_UNDEF
  Using declarations fix in symbol tables
  Revert recent using-declarations code changes

Conflicts:
	CHANGES.current
2022-02-20 17:04:56 +00:00
William S Fulton
1b0a9ccfc5 Typo fixes 2022-02-20 16:45:11 +00:00
William S Fulton
9b131a03d5 Fix warning suppression for WARN_PARSE_USING_UNDEF
New warnings for unknown using declarations since fix in previous commit
2022-02-20 16:45:10 +00:00
William S Fulton
cb963a1440 Using declarations fix in symbol tables
Implementation is very similar to typedef implementation.
Issue #655 and closes #1488.
Testcase using_member.i.
Better implementation to that reverted in previous commit 3f36157b.
Symbol tables shown with -debug-csymbols and -debug-symbols now correct
and are similar to when using a typedef.
2022-02-20 15:33:32 +00:00
William S Fulton
3f36157b39 Revert recent using-declarations code changes
Reverts code changes from 7b5a615e50
merge commit in preparation for better fix.
Issue #655 and issue #1488.
2022-02-20 11:12:16 +00:00
Olly Betts
1707d6b89b [PHP] Fix cleanup code handling issues
Fix to call cleanup code in exception situations and not to invoke
the freearg typemap twice in certain situations.

Fixes https://sourceforge.net/p/swig/bugs/1211/
2022-02-17 13:52:44 +13:00
Olly Betts
a7ff0da1f3 Improve parsing of % followed immediately by identifier
If it's not a recognised directive the scanner now emits MODULO and then
rescans what follows, and if the parser then gives a syntax error we
report it as an unknown directive. This means that `a%b` is now allowed
in an expression, and that things like `%std::vector<std::string>` now
give an error rather than being quietly ignored.

Fixes #300
Fixes #368
2022-02-15 15:09:44 +13:00
Olly Betts
fd6c0255a2 Remove superfluous semicolons 2022-02-15 14:00:12 +13:00
Olly Betts
abfd630c6d Remove comment on how to add new target lang
This information really doesn't belong in lua.cxx, and is covered better
in Doc/Manual/Extending.html already.
2022-02-15 10:35:17 +13:00
Olly Betts
b624d17f3f Merge branch 'swig-fortran/extern-c-int'
Fixes #2199
2022-02-11 08:28:27 +13:00
Seth R Johnson
af56a1f5c7 Preserve "externc" for non-brace thread_local 2022-02-11 08:25:03 +13:00
Seth R Johnson
14c0942505 Preserve thread_local for brace-enclosed extern "C" 2022-02-11 08:25:03 +13:00
Seth R Johnson
2ecc5bc214 Don't warn about legal extern "C++" {} block 2022-02-11 08:25:03 +13:00
Olly Betts
89a0a3c5f7
Merge pull request #2197 from swig-fortran/rename-warn
Print rename warnings except anonymous template methods
2022-02-10 16:15:10 +13:00
Dimitris Apostolou
40c3bf30b2 Fix typos 2022-02-10 16:12:24 +13:00
Seth R Johnson
a81a9452a8 Revert "Enable 'regextarget' option for '%namewarn'"
This reverts commit d7e0aaa57d. I can't
get regextarget to work correctly, and the fortran branch no longer
depends on it since pcre support is optional.
2022-02-09 18:11:12 -05: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
William S Fulton
013be550ed Merge branch 'fragment-typemap' into upstream-master
* fragment-typemap:
  Add documentation
  Enable multiple 'fragment' keywords to be attached to typemaps
2022-02-07 20:35:08 +00:00
Seth R Johnson
befc9bc1f0 Mark 'externc' storage for variables 2022-02-06 20:49:01 -05: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
Seth R Johnson
018254cca3 Reformat name warnings to reduce changes 2022-02-06 13:51:37 -05:00
Seth R Johnson
307c9814a0 Prevent "__dummy_0__" template methods from matching name warnings 2022-02-06 13:51:37 -05:00