Commit graph

116 commits

Author SHA1 Message Date
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
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
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
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
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
Vadim Zeitlin
fc1ebd7c18 Add trivial but working std::pair typemaps implementation
The existing typemaps didn't work at all and making them work would
require defining all the typemaps needed by the Unified Typemaps
Library, which seems to be geared towards dynamic languages.

Just implement completely straightforward (and not very convenient to
use) typemaps instead.

Enable the now passing unit tests and add a runme for one of them.
2019-08-07 02:16:33 +02:00
Vadim Zeitlin
c6efb0b8e6 Mark some C++11 tests as failing with C module too
Allow having the list of failing C++11 tests in the common makefile.
2019-08-06 20:57:44 +02:00
Vadim Zeitlin
f864fa0381 Fix types of some pointers in char_strings unit test
The tests still passed, but with warnings during compilation.
2019-08-06 20:56:48 +02:00
Vadim Zeitlin
82ae30722f Include missing header in char_strings test code
Avoid warnings about implicitly-declared strcmp().
2019-08-06 20:56:19 +02:00
Vadim Zeitlin
fd3e763656 Streamline and fix returning objects by value
Remove the code related to "_result_ref" which was confusing and plain
wrong, as it generated something that compiled but crashed during
run-time due to the use of a pointer to an already destroyed stack
object.

Instead, correct the "out" typemap to create a new copy of the object,
which mostly works fine on its own, except that it depends on using
SwigValueWrapper if necessary, so add the call to cplus_value_type()
does this. This also required removing the code resolving typedefs in
the "type" attribute because it confused the base class logic and still
needs an explicit cast to the actual return type due to the use of (and
probable bug in) get_wrapper_func_return_type().

These changes mean that "cppouttype" typemap is not used any longer, so
remove it too.

A couple more tests pass now.
2019-08-06 02:35:25 +02:00
Vadim Zeitlin
10b73ad2c1 Remove unnecessary override of classDeclaration()
It doesn't seem necessary to muck with sym:name explicitly when we
construct the fully qualified name using getNamespacedName() later
anyhow.

Moreover, the overridden version had a bug which resulted in a crash in
template_empty_inherit unit test and simply removing it entirely allows
the test to pass (without breaking anything else).
2019-08-05 02:02:25 +02:00
Vadim Zeitlin
dc2af47e1d Fix warning about undeclared strcmp() in a unit test
Just include the header declaring it in the test code.
2019-08-04 17:47:36 +02:00
Vadim Zeitlin
11d7f09f7a Fix bug with mangling enums in overloaded function names
Don't generate "enum foo" in the function names, which obviously can't
contain spaces.

This allows another unit test to pass.
2019-08-04 17:09:57 +02:00
Vadim Zeitlin
cb3d9df000 Fix bug with return value of getNamespacedName()
We need to make a copy instead of directly returning whatever sym::name
points to, as this value can be overwritten with something different
later, resulting in weird problems with the value of "proxyname"
attribute changing "on its own".

After this bug fix, a few more unit tests pass.
2019-08-04 15:45:54 +02:00
Vadim Zeitlin
b4d08c1787 Get rid of special ctor/dtor handling in C module
By delegating to the base class instead we not only save quite a few
lines of code, but gain support for ctors/dtors defined using %extend,
which didn't work before, allowing to reenable some of the previously
failing tests.
2019-08-04 02:22:16 +02:00
Vadim Zeitlin
875217b1e2 Disable more tests not passing since the last merge with master
They should be fixed later, but for now let at least the working unit
tests pass.
2019-08-03 17:27:45 +02:00
Vadim Zeitlin
690bf8e020 Replace SWIG_exit() with just exit() in test code
SWIG_exit() is not declared anywhere, so would need to be explicitly
declared to avoid warnings, while exit() can be declared just by
including <stdlib.h>, so prefer to use the latter, especially because
they're one and the same anyhow.
2019-07-24 20:47:59 +02:00
Vadim Zeitlin
d89a95a48c Use std/std_vector.i instead of a poor copy in c/std_vector.i
At the very least, this gives us a working vector<bool> and allows
"li_std_vector" unit test to pass. It is also just nice to reuse the existing
typemaps instead of having another copy of them.

As C doesn't have UTL, some parts of std_vector.i had to be excluded from it
however.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
29563ec98e Fix typemaps for bool
The existing typemaps didn't make much sense, simplify (there doesn't seem to
be any point in using $1_basetype when dealing with "bool") them and treat
"const bool&" as "bool", not as pointer, as this is much more convenient in C.

This also allows another unit test to pass.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
8eba14c6e0 Resolve typedefs in parameter types after applying ctype typemap
Typedefs were not resolved for non-object types in spite of
SwigType_typedef_resolve_all() call as it didn't affect "c_parm_type".

Actually it is not even clear if resolving typedefs is a good idea as using
them probably makes the generated code more clear, but at least in the case of
nested typedefs we do need to do it as "Class::Type" can't appear in C code.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
1912fd3a42 Suppress a warning in abstract_typedef unit test
Use an explicit cast to cast from derived to base, there is no better solution
currently.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
bca00c65dd Implement cdata typemaps for C
Just use the struct directly in the C wrappers.
2016-09-15 01:27:40 +02:00
Vadim Zeitlin
10d25c7327 Drop longjmp-based exception handling approach
Using longjmp was incompatible with using C++ objects in the code using the
wrappers, and using this C API from C++ to avoid ABI incompatibilities between
different C++ compilers is one of the main reasons for using this module.

Also, this required using a separate SwigObj instead of just using the real
object pointer which inevitably resulted in memory leaks whenever a non owned
object was returned from anywhere, e.g. from a member accessor or any method
returning pointer or reference.

Abandon the attempts to recreate C++ exceptions in C and just use a very
simple approach allowing to pass an error message out of band after any
function call in a global variable. An alternative could be to add a special
"out" error parameter to each and every function, but this risked being too
verbose, especially for the functions which don't really throw, and the calls
to SWIG_PendingException_get() won't need to be made explicitly when using a
C++ wrapper around the generated C API in the future.

This simplifies both the module and the generated code, in particular we don't
need any runtime code at all any more and there is no need for an extra level
of indirection for every object.

It also makes a couple more tests pass.
2016-09-15 01:27:40 +02:00
Vadim Zeitlin
bda731cd8f Change naming convention for wrapped ctors and dtor
Use Foo_{new,delete}() instead of {new,delete}_Foo() to ensure that all
methods of the class Foo start with the corresponding prefix.
2016-09-15 01:27:40 +02:00
Vadim Zeitlin
75d9cb4769 Remove C-specific cpp_basic_global_var_built_in unit test
There is no need for it, the common global_vars unit test is more extensive
and passes too now.
2016-09-15 01:27:39 +02:00
Vadim Zeitlin
862abb42e6 Allow suppressing progress messages when running C test suite
This makes the warnings more noticeable.
2016-09-15 01:27:39 +02:00
Vadim Zeitlin
8e30abf7ab Don't use "this" method parameter for disambiguating overloads
When building the unique suffix for each member of the overloaded functions
set, don't use the first "this" parameter of the object methods in it as it's
the same for all of them and so is completely useless for disambiguation
purposes and just results in unnecessarily long and ugly names.

Use "_const" suffix for the methods differing by their const-ness only, this
is necessary now that we don't use "_pFoo" or "_pcFoo" in their names.

This makes it superfluous to check for c:objstruct in
functionWrapperAppendOverloaded() (and checking for it there was not enough
neither, as the changes in the test suite show, sometimes the "this" parameter
type still found its way into the generated wrappers).
2016-09-15 01:27:39 +02:00
Vadim Zeitlin
e068aa8cc9 Simplify ctors/dtor handling by reusing base class code
Just use our custom object creation/destruction code, but let the base class
do everything else.

This uncovered complete lack of support for ctors/dtors defined using %extend,
but this is not new and will have to remain broken for now.
2016-09-15 01:27:39 +02:00
Vadim Zeitlin
160074a025 Suppress warnings about no typemaps being defined in C test suite
In many (although perhaps not all, so don't suppress this warning
unconditionally) cases, there is no need for special typemaps in C, the
parameters can be just used directly, so this warning is harmless but it was
given many times during the test suite execution, distracting from more
important messages.
2016-04-21 15:23:27 +02:00
Vadim Zeitlin
e2bb89ccb3 Replace unknown enums with int in the wrappers
An enum can be declared outside of the code wrapped by SWIG, just use int
instead of it then.
2016-04-21 01:37:42 +02:00
Vadim Zeitlin
4b5e5d0cc8 Allow to use the original name of the global functions
It is impossible to have two functions with the same name inside the same
program, but it is possible to provide a #define to allow the user code to use
the original function name for the wrapper function, so do it for convenience.

Remove the old changes adding explicit "_wrap_" prefix to the examples and the
tests and remove the few more now passing tests from the list of failing tests.
2016-04-21 01:37:42 +02:00
Vadim Zeitlin
36fdd4e78f Wrap unknown type as opaque pointers
Don't give errors for the unknown types, instead wrap them using the mangled
name of the type.

This is the expected (even if not particularly useful) SWIG behaviour and
allows many more tests to pass.
2016-04-21 01:37:42 +02:00
Vadim Zeitlin
2ec9d9da6e Don't try to export variables in namespace scope directly
The generated code, which used C++ scope operator "::" in a C header, didn't
compile and couldn't work anyhow.

Just use the accessor functions for not really global variables.
2016-04-21 01:37:41 +02:00
Vadim Zeitlin
e39265ba13 Handle primitive types when expanding "resolved_type" in typemaps
Although the default typemaps only use "resolved_type" for non-simple types,
the generic SWIGTYPE typemap can also be applied explicitly to other types as
"apply_strings" and "char_binary" unit tests do.

In this case just use the original type unchanged if we can, this is enough to
make these tests pass.
2016-04-21 01:37:41 +02:00
Vadim Zeitlin
59c131ea08 Fix broken anonymous_bitfield C checking code
For some reason the test expected another bit field be changed when setting
the given one, which was just plain wrong and prevented the test from passing.
2016-04-21 01:37:41 +02:00
Vadim Zeitlin
b062a63cd1 Fix abstract_typedef C test code
Don't refer to the typedef name (especially with a typo in it...), it is not
supposed to be exported.

Also fix the write() method call: use the right class for it and pass it the
correct arguments.
2016-04-21 01:37:41 +02:00
Vadim Zeitlin
b7bd0165e8 Remove more tests which pass now
All tests detected as passing by "make check-failing".
2016-04-21 01:37:41 +02:00
Vadim Zeitlin
3764ee1764 Make anonymous_bitfield test compile
It still doesn't pass, but at least include the correct header from it.
2016-04-21 01:37:40 +02:00