Commit graph

5,274 commits

Author SHA1 Message Date
Olly Betts
471df4823b Don't call skip_decl() on "Syntax error in input(3)"
This is a useless left-over from long ago (2007) when we didn't exit
right away after reporting this error.
2022-04-04 08:59:36 +12:00
Olly Betts
ef3f25ab1c Remove -browse command line option
This option was undocumented.  If used it quietly did nothing
unless you'd installed the SWILL library before building SWIG, but
SWILL is no longer maintained and hasn't seen a release since
2008-04-10.

It's clear nobody has used this functionality for some time as the
code to support it in SWIG isn't actually valid ISO C++:

Modules/browser.cxx: In member function ‘void Browser::show_attributes(Node*)’:
Modules/browser.cxx:57:23: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
57 |         char *trunc = "";
   |                       ^~
Modules/browser.cxx:61:21: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
61 |             trunc = "...";
   |                     ^~~~~

Closes #2251
2022-04-03 08:56:07 +12:00
William S Fulton
2ded25d138 Fixes for ISO C89 2022-03-28 19:25:11 +01:00
William S Fulton
d1b93f2c0e Merge branch 'feature/python-builtin-separate-runtime-data'
* feature/python-builtin-separate-runtime-data:
  Rework swig_and_compile_multi_cpp makefile helper
  Different capsule names for builtin changes entry
  Use different capsule names with and without -builtin

Conflicts:
	CHANGES.current
2022-03-26 15:18:55 +00:00
William S Fulton
51a7f27d1c Minor fix to Swig_print_node 2022-03-25 23:44:07 +00:00
William S Fulton
1db04bf322 Improvements to the -debug command line options
The debug command line options that display parse tree nodes
(-debug-module, -debug-top, -debug-symtabs) now display previously hidden
linked list pointers which are useful for debugging parse trees.

Added new command line option -debug-quiet. This suppresses the display
of most linked list pointers and symbol table pointers in the parse tree nodes.

The keys in the parse tree node are now shown in alphabetical order.
2022-03-25 23:34:52 +00:00
William S Fulton
b737a64ec5 Remove minimum Python version check
The version checking was historically done to deal with
different versions and importing the low-level Python
module. Then it was used to try and help when using -py3.
A minimum version check implies that the wrappers work
with any version >= 2.7, which is not really correct.
The correct thing to do is to check that the exact
version used matches the one that the C layer was compiled
against, which can only be left for the user to do, perhaps
using %pythonbegin.

Issue #1779
2022-03-25 19:09:17 +00:00
William S Fulton
469f694ae6 Fix using declaration in derived class bugs
Problem when all the base class's overloaded methods were
overridden in the derived class - fixes "multiply defined" errors.

Linked lists of the overloaded methods were not set up correctly
when handling the using declaration.

Closes #2244
2022-03-24 20:52:58 +00:00
William S Fulton
a343b7e254 Remove -py3 command line option
Closes #1779
2022-03-23 18:13:07 +00:00
William S Fulton
df86fbc54e Remove option to use Python 3 only syntax for %pythonnondynamic feature
A metaclass is added using a decorator @_swig_add_metaclass which
is designed to provide a metaclass that works for both Python 2 and Python 3.
The option to use the Python 3 only syntax: metaclass=_SwigNonDynamicMeta
via the -py3 command line option has been removed as part of a
simplification to remove the -py3 option.

Issue #1779
2022-03-23 07:58:39 +00:00
William S Fulton
f068f2c2d6 Add Python < 3.3 support for pyabc.i
pyabc.i for abstract base classes now supports versions of Python
prior to 3.3 by using the collection module for these older versions.
Python-3.3 and later continue to use the collections.abc module.
The -py3 option no longer has any effect on the %pythonabc feature.
2022-03-23 07:58:01 +00:00
William S Fulton
9fd2356104 Merge branch 'flatstaticmember'
* flatstaticmember:
  Test -flatstaticmethod and %extend
  Python -flatstaticmethod corrections
  Enable flat static constructor methods
  Move low level static methods
  Use flat static method if it's a "friend"
  Python: Option to generate flat class methods
2022-03-21 19:28:52 +00:00
William S Fulton
21c2e47661 Python -flatstaticmethod corrections
Correct logic for suppressing static methods.
Previous logic was missing director disown methods.
Add changes file entry for -flatstaticmethod.

Closes #2137
2022-03-21 19:22:49 +00:00
Olly Betts
b2c58115d7 Fix previous commit
Revert changes inadvertently included, and fix `=` to `==`.
2022-03-20 19:44:23 +13:00
Olly Betts
029ddab8b5 [ci] Try to fix failing appveyor python builds 2022-03-20 18:42:50 +13:00
Ian Lance Taylor
90aa3f75ba [Go] Implement %extend base methods in child classes.
Fixes #337
2022-03-18 18:34:28 -07:00
Olly Betts
a0e3825de6 Fix replace handling corner case
With flags DOH_REPLACE_ID_BEGIN, DOH_REPLACE_ID_END and
DOH_REPLACE_NUMBER_END the code looked for a match for the token
string using strstr() and then checked the extra condition - if the
extra condition didn't apply it then advanced by the length of the token
before searching again.

However that can miss matches if the strstr() matches can overlap
one another, so only advance one position, which is conservative
but can't miss matches.

For example this would not match before:

Replace("123123", "1231", r, DOH_REPLACE_NUMBER_END);

This issue seems to be entirely latent in the current SWIG codebase
due to the nature of the token strings passed when using these flags.

See #2235
2022-03-19 08:55:39 +13:00
Olly Betts
d7e83c1cbc Fix checking of "optimal" typemap attribute
Previously SWIG checked that the typemap action contained ";\n" not
followed by an identifier character, and that it contained no other
`;`, but that incorrectly allows some cases it shouldn't.

Instead check that the action ends with `;\n` and contains no other
`;`, which is simpler and correctly rejects these cases.
2022-03-19 08:13:09 +13:00
Eugene Toder
f733efd3c0 Use different capsule names with and without -builtin
Types generated with and without -builtin are not compatible. Mixing
them in a common type list leads to crashes. Avoid this by using
different capsule names: "type_pointer_capsule" without -builtin and
"type_pointer_capsule_builtin" with.

See #1684
2022-03-18 13:44:54 -04:00
Jim Easterbrook
b8f10a55f9 Enable flat static constructor methods
These are needed to provide renamed overloaded constructors and the
like.
2022-03-18 11:10:14 +01:00
Jim Easterbrook
63ef91939b Use flat static method if it's a "friend"
This allows the friends test case to pass, with or without -builtin.
2022-03-18 11:10:14 +01:00
Julien Schueller
484e5316f2 Python: Option to generate flat class methods 2022-03-18 11:10:14 +01:00
Olly Betts
bb5cd94cad Fix GCC warning from recent -intgosize change
Modules/go.cxx:247:10: warning: variable ‘display_help’ set but not used [-Wunused-but-set-variable]
  247 |     bool display_help = false;
2022-03-17 18:55:31 +13:00
Olly Betts
2da3815f99 [Go] Make -intgosize optional
We no longer support Go < 1.2 so we can default intgo to ptrdiff_t
and uintgo to size_t.

Fixes #683
Fixes #2233
2022-03-16 18:30:05 +13:00
Ian Lance Taylor
b819363117 [Go] Don't convert arrays to pointers if there is a "gotype" typemap entry.
Fixes #749
2022-03-15 12:18:47 -07:00
YungLee
31f7b437f4
[scilab] Fix to work on Windows
* Change the builder filename to match the loader filename

* Mark extern functions with SWIGEXPORT

* Fix bug: builder.sce not generated if with  '-scilab -builder'  option

Fixes #1853
2022-03-15 15:06:17 +13:00
Olly Betts
9efcc785ae Re-enable symbol poisoning in a CI job
It seems too brittle to enable by default as we'd have to avoid
including any system headers after doh.h, which is hard to enforce,
but just having it enabled for one CI job should avoid uses of the
poisoned symbols from being accidentally introduced.

See #2223
2022-03-15 11:14:23 +13:00
William S Fulton
598736a6b2 %interface family of macros no longer add variable wrappers
The getter/setter methods used for wrapping methods are no longer
added to the interface class.

Closes #1524

Also add in testcase for enums.
2022-03-12 23:04:24 +00:00
William S Fulton
63bbf642f4 %interface family of macros enum fix for Java
enums were being generated into the interface class instead of the proxy
class.
2022-03-12 23:04:24 +00:00
William S Fulton
a87e722834 Use GetFlag instead of Getattr for feature:interface 2022-03-12 23:04:24 +00:00
William S Fulton
b6ece11fc1 Fixes for the family of %interface macros for overloaded methods
When C++ methods are not able to be overloaded in a derived class,
such as when they differ by just const, or the target language
parameters types are identical even when the C++ parameter types
are different, SWIG will ignore one of the overloaded methods with
a warning. A %ignore is required to explicitly ignore one of the
overloaded methods to avoid the warning message. Methods added
in the derived classes due to one of the %interface macros are now
similarly ignored/not added to the derived class.

The adding of additional methods into the parse tree is now more
robust and complete resulting in support for %feature and %rename
for the added methods.

Closes #1277
2022-03-12 23:04:24 +00:00
William S Fulton
77853770bd Disable use of gcc poison pragmas
Needs a rethink to avoid use of poisoned macros in system headers.
I see this on Ubuntu 16.04:

gcc -DHAVE_CONFIG_H   -I../Source/Include -I../Source/CParse
-I../Source/Include -I../Source/DOH -I../Source/CParse
-I../Source/Doxygen -I../Source/Preprocessor -I../Source/Swig
-I../Source/Modules   -g -O2 -Wall -W -pedantic -MT DOH/base.o -MD -MP
-MF $depbase.Tpo -c -o DOH/base.o DOH/base.c &&\
mv -f $depbase.Tpo $depbase.Po
In file included from /usr/include/string.h:630:0,
                 from DOH/dohint.h:21,
                 from DOH/base.c:15:
/usr/include/x86_64-linux-gnu/bits/string2.h:1282:19: error: attempt to
use poisoned "calloc"
        ? (char *) calloc ((size_t) 1, (size_t) 1)        \
                   ^
/usr/include/x86_64-linux-gnu/bits/string2.h:1284:32: error: attempt to
use poisoned "malloc"
      char *__retval = (char *) malloc (__len);       \
                                ^
/usr/include/x86_64-linux-gnu/bits/string2.h:1302:19: error: attempt to
use poisoned "calloc"
        ? (char *) calloc ((size_t) 1, (size_t) 1)        \
                   ^
/usr/include/x86_64-linux-gnu/bits/string2.h:1308:26: error: attempt to
use poisoned "malloc"
      __retval = (char *) malloc (__len);        \
                          ^
2022-03-12 23:04:24 +00:00
William S Fulton
50518d4e77 Using declarations, directors and overloaded methods
Language::unrollVirtualMethods was assuming that the using
declaration would only introduce one method. Fix this by adding
in all the overloaded methods from a base class.

Affects code generation in C# and Java, but I was not able
to construct a test that failed before this commit.
2022-03-10 22:18:23 +00:00
William S Fulton
8a8532d823 Refactor code out of Language::unrollVirtualMethods
Move code in main loop into new function to handle one method at a time.
In preparation for next commit for using declaration fix.
Remove unused default_director variable.
2022-03-10 22:18:23 +00:00
William S Fulton
fe27e3d2ba Language::unrollVirtualMethods variable initialisation refactor 2022-03-10 22:18:23 +00:00
William S Fulton
e53f51b89d Add missing symtab for functions added by using declarations
Fixes fully qualified names for functions added by using declarations:
- Error messages show fully qualified names in Lua
- Overload warning messages show fully qualified names
- Error messages calling dispatch functions for handling overloaded methods in OCaml, Python and Tcl
2022-03-10 22:18:23 +00:00
William S Fulton
c88a9436bc Fix segfault in C# layer handling using declarations
Segfault was actually avoided in previous commit ab23cb29.
This commit makes handling more robust in the event of
using %ignore just on the derived method, not tested as it is not
what one should do with directors, and possibly other cases.

Go still segfaults with the new testcase director_using_member_scopes.i.

Issue #1441.
2022-03-10 22:18:23 +00:00
William S Fulton
bd5ffe86e4 Using declarations in derived class parameters scoping fix
Fix using declaration in derived class incorrectly introducing a method
from a base class when the using declaration is declared before the method
declaration. Problem occurred when within a namespace and the parameter types
in the method signatures were not fully qualified.

Issue #1441
2022-03-10 22:18:23 +00:00
Ian Lance Taylor
70d530adfc swig -go: treat a nil argument as NULL
Let Go code pass "nil" when calling a C++ function that accepts a
pointer to a class.  The Go "nil" will be treated as a C++ "nullptr".

Fixes #2203
2022-03-08 15:15:05 -08:00
Olly Betts
f8a766295c Handle ) in command line interface filename
SWIG now handles an interface filename specified on the command line
which contains a closing parenthesis `)`, and more generally with
attributes to `%include` and `%import` which are quoted and contain
parentheses.

Fixes #1006
2022-03-08 18:15:18 +13:00
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