Commit graph

5,642 commits

Author SHA1 Message Date
Vadim Zeitlin
74e8a6e729 Reenable C++ wrappers for some of the previously failing tests
Document the reason for failure for some of those that still fail
without -nocxx.
2021-12-08 03:09:28 +01:00
Vadim Zeitlin
cc76e3a1d7 Fix crash for classes with ignored base class
This fixes class_ignore.cpptest.
2021-12-08 00:56:50 +01:00
Vadim Zeitlin
c5cd287ec6 Enable some C++ tests by just using a different namespace
Using "typename" or "dynamic_cast" as C++ namespace names unsurprisingly
resulted in compilation errors, so don't do this.
2021-12-08 00:56:13 +01:00
Vadim Zeitlin
fd11a591a3 Add cxx{in,out}type typemaps and use them for std::string
This makes using returning strings much simpler to use from C++ code as
the returned pointers don't have to be deleted manually -- although, of
course, this does require an extra allocation and copy and so should be
avoided for the very long strings.

Add a new runtime test showing how simple and convenient it is to use
the functions working with string using the C++ wrappers now.
2021-12-07 20:54:28 +01:00
Vadim Zeitlin
aacc930023 Streamline and improve std::string typemaps
Avoid unnecessary heap allocations, just use temporary variables.

Actually update the string parameters passed by pointer/non-const
reference. This requires the pointers passed to actually be non-const,
so update the C-specific unit test runme to use a char buffer instead of
a literal string.

Also simplify the code copying the string contents to just use strdup()
(if there are ever any platforms where this POSIX functions is not
available, we could just define it ourselves once instead of using
strlen() + malloc() + memcpy() manually twice).
2021-12-05 03:31:35 +01:00
Vadim Zeitlin
a031ec3474 Enable two previously failing tests that pass now
This is just the result of rerunning "make check-failing".
2021-11-30 02:29:31 +01:00
Vadim Zeitlin
579c343d5f Represent enums as enums, not int, if possible
Use enum types instead of int for the enum-valued parameters and
function return values, this is more type-safe and clear for the users
of the library.

Change cpp_enum unit test to use C++ to check that C++ enum wrappers
can at least be compiled, but still use C API in it.

Note that enum whose underlying type is bigger than int still don't
work, but this is no different from what it was before, so just document
this limitation but don't do anything else about it for now.

This commit is best viewed ignoring whitespace-only changes.
2021-11-30 02:22:25 +01:00
Vadim Zeitlin
c3b262c2f7 Merge branch 'master' into C
Merge with the latest master to resolve (trivial) conflict in the
GitHub workflow file.
2021-11-27 00:20:19 +01:00
Vadim Zeitlin
9a8ebbb998 Throw SWIG_CException from C++ wrappers automatically
Check for the pending exception after every call to a wrapper function
not marked "noexcept" and throw a C++ exception if necessary.

Add C++ version of the exception example to show how this works.

Also change SWIG_CException to use member functions for checking for and
resetting pending exceptions, this seems better than having separate
functions for it and will make it easier to customize exception handling
later by just replacing SWIG_CException class with something else.

Note that we still use a global (and not a member) function for raising
the exception, but this one is not exported at all, and needs to be a
function in order to be easily callable from other modules (see the
upcoming commit).
2021-11-27 00:19:05 +01:00
Vadim Zeitlin
17fbb0a528 Include required headers for %imported modules
We need the types from the imported modules, so #include the header
generated for it.

Unfortunately we have to half-guess the name used for that header, as
it's not available anywhere (and can't really be, as it could be changed
by a command line option used for another SWIG invocation that was used
to compile that module), but this seems to work well enough in practice.

In particular, this fixes failures in multi cpp tests, so that we don't
need FAILING_MULTI_CPP_TESTS any longer.
2021-11-27 00:19:05 +01:00
Vadim Zeitlin
f42b0eaa71 Use different executable names for C and C++ examples
Trying to create the same "runme" executable for both C and C++ examples
could result in errors when using parallel make, as one of the targets
could fail to write to the file being currently executed.

Using separate names works around this problem.
2021-11-27 00:19:05 +01:00
Vadim Zeitlin
d2546e23ff Don't use exception specification with C++ compiler in example
Support for the exception specifications using types was removed in
C++17 (and "throw ()" in C++20), so don't use them when using the C++
compiler any longer, as this broke the example with recent g++ versions
that use C++17 by default.

We still need them for SWIG, however, so use SWIG_THROW macro, defined
differently for SWIG and the compiler, to preserve the existing
behaviour.

Using %except might be a better idea, but would require more changes.
2021-11-24 20:16:42 +01:00
Vadim Zeitlin
43276f22a7 Enable testing some C++ wrappers code in the test suite
C++ wrappers still don't compile for about a hundred tests, but they do
compile for almost 500 more of them, so it's still valuable to be able
to check that there are no regressions for those that do work now.
2021-11-24 02:41:33 +01:00
Vadim Zeitlin
7c6fb542d3 Convert li_boost_shared_ptr runtime test to C++ from C
It's simpler to write tests in C++ rather than C and checking the
generated C++ API also checks the C API it uses underneath, so there is
no need to have both.
2021-11-23 01:29:26 +01:00
Vadim Zeitlin
0483e4017c Start adding C++ wrappers generation
Disable them for the test suite, as plenty things don't work yet, but
there is already more than enough code to not want to add even more
fixes to the same commit.
2021-11-23 01:29:26 +01:00
Vadim Zeitlin
7cbbfab198 Show using C++ wrapper API for the "class" example
This almost exactly mirrors the existing C examples, but modify both
examples slightly to make their output show which language is used.
2021-11-19 02:04:41 +01:00
Vadim Zeitlin
2ab549611b Syntax check generated headers using both C and C++ compilers
For C++ tests, check header compilation using C++ compiler too, as this
detects constructs valid in C but invalid in C++ and will also be useful
for checking C++-specific parts of the headers that will be generated in
the future.
2021-11-19 00:08:44 +01:00
Vadim Zeitlin
3765a08743 Allow having C++ test cases for C backend
Support compiling and running either _runme.c or _runme.cxx files for
the given test (but not both).

Add a simple C++ test file to check that it actually works.
2021-11-19 00:08:43 +01:00
Dimitris Apostolou
f586d920f7
Fix typos 2021-11-17 07:07:02 +02:00
William S Fulton
63733a3b5c Short struct name in cpp11_final_override for Scilab 2021-11-15 22:56:29 +00:00
William S Fulton
99954d6d4e Shorten testcase variable names for Scilab 6 to work 2021-11-15 22:45:56 +00:00
William S Fulton
b53b2f1a27 Shorter names in cpp11_rvalue_reference3 testcase for Scilab 2021-11-15 22:13:27 +00:00
William S Fulton
e6b6fa93aa Fix guile examples for C11 and later conformance 2021-11-15 19:25:41 +00:00
William S Fulton
54e2ad073f Fix cpp11_type_aliasing test
Ordering fix for Guile wrappers to compile
2021-11-15 08:00:46 +00:00
William S Fulton
10af8fd921 Workaround Lua failing cpp11_raw_string_literals test 2021-11-12 19:45:25 +00:00
William S Fulton
842ed6ca9d Testcase warning fix using gcc-11
warning: ‘this’ pointer is null [-Wnonnull]
2021-11-12 19:00:20 +00:00
William S Fulton
6cafc93135 -Wfree-nonheap-object warning fix using gcc-11 2021-11-12 19:00:20 +00:00
William S Fulton
d15a3cb1d4 Fix testcase -Wstringop-truncation warning in gcc11 2021-11-12 19:00:20 +00:00
William S Fulton
1bd3e771a0 Fix C tests for Javascript and c++17 2021-11-11 19:56:37 +00:00
Vadim Zeitlin
5219338160 Fix previously unused access_change unit test runme file
This file had a wrong name and so wasn't used at all.

Do use it now, after renaming it to the required name and fixing its
compilation.
2021-11-10 02:17:07 +01:00
Vadim Zeitlin
e8f9bdba80 Remove wrapper aliases generation and use -namespace in the tests
The -namespace option provides a better way of using the wrapped API, so
drop the optional wrapper generation, which is useless when this option
is used and just generates many lines of unwanted junk in the header.

Update the test suite and the examples to compensate to not rely on
being able to define SWIG_DEFINE_WRAPPER_ALIASES and add -namespace
option to all C++ tests, as it's done for C# test suite, and update them
to use the correct prefix and also use the accessors for the global
variables rather than using them directly, as this is impossible when
namespace prefix is used (it would have been possible to define a
preprocessor symbol corresponding to the real variable name, but it's
arguably not worth it).

fixup! Remove wrapper aliases generation and use -namespace in the tests
2021-11-10 02:11:59 +01:00
Vadim Zeitlin
3ebf1c1769 Remove redundant cpp_basic_xxx tests
These tests duplicate the other, more complex, existing unit tests, so
it's just not useful to have them at all any more (they could have been
useful at the very beginning of C backend development, when none of the
other tests worked).
2021-11-10 00:53:39 +01:00
Vadim Zeitlin
f4ee8e5369 Fix names of enums and their elements
Use the containing class name as prefix, and add the name of the enum
itself to the prefix for the scoped enums, instead of doing something
strange and semi-random that we did before, with prefixes including the
namespace (which should never be the case without "nspace" feature), but
not the scoped enum.

This also fixes renaming of enum elements, as a side effect, which
didn't work before, add run test for enum_rename unit test to prove it.
2021-11-07 02:14:16 +01:00
Vadim Zeitlin
8014af974d Revert accidental change to Python example
This was done way back in f84342a30 (Modified parameter handling using
typemaps. 'Reference' example. Visibility hint now applies only to the
global functions., 2008-06-28), surely accidentally.
2021-11-04 01:31:06 +01:00
Vadim Zeitlin
9ac6ab3b8a Disable SWIGWARN_LANG_EXPERIMENTAL while running test suite for C
We really don't need all the warnings while testing, they are only
useful for SWIG users, not when developing it.
2021-11-02 17:51:14 +01:00
William S Fulton
76d8e2cfaf
Merge pull request #2064 from jschueller/py310
[Python] Fix overload_simple_cast test with 3.10
2021-10-20 19:45:55 +01:00
Vadim Zeitlin
2f6f6df211 Generate wrapper aliases only if requested and not by default
Defining the aliases by default results in conflicts when including
headers from multiple modules as e.g. SWIG_PendingException_get() is
defined in all of them, and could also easily result in other unwanted
clashes, so make this opt-in and update the examples and tests relying
on using the wrappers without the module prefix to define
SWIG_DEFINE_WRAPPER_ALIASES explicitly.
2021-10-20 01:57:20 +02:00
Vadim Zeitlin
e78c8f39ed Add minimal shared_ptr support
Enable the tests and support of shared_ptr in them for C (which required
disabling a previously passing, because not doing anything, attributes
test which is currently broken for unrelated reasons).
2021-10-15 01:26:22 +02:00
Vadim Zeitlin
8d7c1c4227 Eliminate a separate FAILING_CPP_TESTS variable in C Makefile
Also undo the changes to common.mk originally done in this branch and
rendered unnecessary by de5e0c865 (C++11 testing moved to a configure
option, 2013-10-08) on master.
2021-10-15 00:57:25 +02:00
Vadim Zeitlin
10dbb92182 Remove another not failing unit test
This test doesn't really work, as directors support is not implemented
at all in C backend, but remove it from here to prevent reports from
"make check-failing" about "failing test passing".
2021-10-14 19:54:50 +02:00
Vadim Zeitlin
d0e979278e Re-enable passing li_std_pair_using test
This must have been fixed by fc1ebd7c1 (Add trivial but working
std::pair typemaps implementation, 2019-08-07).
2021-10-14 19:48:59 +02:00
Vadim Zeitlin
3dd96d5b95 Allow using vector with classes without default ctor in C too
This is similar to be491506a (Java std::vector improvements for types
that do not have a default constructor., 2019-03-01) for Java, except we
don't have to bother with any compatibility constraints for this, not
yet used by anyone. module.
2021-10-07 22:03:47 +02:00
Vadim Zeitlin
0706ed4d35 Add simple std::set<> typemaps too
This is similar to the previous commit for std::map<>.
2021-10-07 22:03:47 +02:00
Vadim Zeitlin
9efb508eda Fix std::map<> typemap
Use simple fixed typemap instead of trying to use the much more complex
one from the UTL which doesn't work for C.

Add a simple test case for std::map<>.
2021-10-07 22:03:47 +02:00
Vadim Zeitlin
b88491fe89 Add at least a very minimal run test for std::vector
The test is trivial, but still better than nothing.
2021-10-07 22:03:47 +02:00
Vadim Zeitlin
e1815634ec Clean the generated headers for C too
This fixes a check-maintainer-clean problem.
2021-10-05 01:34:32 +02:00
Vadim Zeitlin
5bbaecfb81 Set LD_LIBRARY_PATH when running C examples too
This is needed to find the SWIG-generated shared library when using C
too, as it's already the case for many (but, surprisingly, not all)
other target languages.
2021-10-05 01:01:37 +02:00
Vadim Zeitlin
d2e3cce7d4 Avoid -Wformat warnings in C std_vector example
Use "%zd" for printing size_t values rather than "%d".
2021-10-05 00:57:45 +02:00
Vadim Zeitlin
03b6e2fbe6 Don't use SWIG_exit() in C examples
There doesn't seem to be any reason for using it rather than just
returning from main() as usual, and it provokes warnings about
implicitly declared function when compiling them.
2021-10-05 00:26:12 +02:00
Vadim Zeitlin
3da85eb4c5 Disable only part of cpp11_alternate_function_syntax test
Instead of skipping it entirely, just disable the part using member
function pointers, which are not supported in C backend.
2021-10-04 22:11:29 +02:00