Commit graph

4,466 commits

Author SHA1 Message Date
Vadim Zeitlin
f919896306 Merge branch 'master' into C 2016-09-15 01:30:49 +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
a6f53d18ea Fix memory leak in std::vector example
Delete the object we allocate.
2016-09-15 01:27:40 +02:00
Vadim Zeitlin
55f7d51979 Fix memory leak in the exception example
Delete the object we allocate.
2016-09-15 01:27:40 +02:00
Vadim Zeitlin
dfac9ce325 Show how to handle a custom exception class in the example
Define "throws" typemap for it.
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
4ba57e577a Fix obvious memory leaks in the std_vector example
Delete the class when we're done with it.
2016-09-15 01:27:40 +02:00
Vadim Zeitlin
4a0ed9cb42 Declare printf() before using it in std_vector example
Just add missing #include <stdio.h>.
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
1dfbd492b9 Add more warning-suppressing casts to special_variables test
Avoid harmless but annoying warning about assigning a literal string to
a non-const char pointer.
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
Olly Betts
a4015acaca [PHP] Fix out typemap for member function pointers
The existing typemap was just broken - it correctly created the resource
and then did nothing with it, and instead tried to register the member
pointer as a normal pointer, which is never going to work as it's larger
than a normal pointer.

Add cpp_basic_runme.php as a regression test for this.
2016-09-02 09:51:18 +12:00
Olly Betts
888e9c6fec Use preg_match() in PHP test harness code
ereg() and eregi() were deprecated in PHP 5.3.0 and removed in PHP 7.0.0,
and preg_match() has been available since PHP4.
2016-09-02 09:09:24 +12:00
William S Fulton
5b7c08c214 Make Python builtin types hashable by default
Default hash is the underlying C/C++ pointer.
This matches up with testing for equivalence (Py_EQ in SwigPyObject_richcompare)
which compares the pointers.
2016-08-23 19:06:36 +01:00
William S Fulton
4f777b181c Correct notes on customising Python builtin comparison operators
Also add example for python:compare feature
2016-08-22 07:22:40 +01:00
William S Fulton
4c0c802aa0 Add Python builtin tp_dealloc override test 2016-08-19 18:35:51 +01:00
William S Fulton
f778ee19df Python builtin hashfunc closure fix
If the wrong return type in the hash function was used, an error:
  SystemError: error return without exception set
was raised

Add some tests for testing builtin slots
2016-08-18 07:10:54 +01:00
William S Fulton
4ab3af90cb Merge branch 'stl-vector-ptrs'
* stl-vector-ptrs:
  Test case warning fixes for nodejs
  Fix testcase causing nodejs test failure
  UTL STL container descriptor checks
  Fix std::vector of pointers which failed if a pointer to a pointer of the container element type existed (Python)
  Remove unused traits.swg
2016-08-01 06:55:01 +01:00
William S Fulton
56ab717ff3 Test case warning fixes for nodejs
nodejs 4.2.1 on Ubuntu Xenial Xerus
2016-07-30 21:23:57 +01:00
William S Fulton
0177937f7e Fix testcase causing nodejs test failure 2016-07-30 15:00:55 +01:00
Simon Marchetto
95a5def328 scilab: fix issue #755 2016-07-29 11:52:26 +02:00
William S Fulton
6e9184b6f8 Fix std::vector of pointers which failed if a pointer to a pointer of the container element type existed (Python)
Closes SF Bug 2359417 created after commit 93f0390322 (svn rev 10958)
2016-07-28 22:51:22 +01:00
William S Fulton
9c3f608ef7 Remove unused traits.swg
This file has code that looks like it was migrated to Lib/std/std_common.i
2016-07-27 18:46:23 +01:00
William S Fulton
b24e970a28 Merge branch 'wkalinin-nested-ignore-fix'
* wkalinin-nested-ignore-fix:
  renamed test module, in accordance with other tests
  function body fixed
  added foo() definition to satisfy some test linking fails
  func() renamed to foo() for 'go'
  fixed test-suite/nested_ignore.i
  test for #662
  fix for nested ignored types

Closes #662
2016-06-26 00:33:19 +01:00
Lior Goldberg
c363a93d69 Added support for type alias 2016-06-22 23:13:28 +03:00
William S Fulton
86fd5c9858 Fix autodoc testcase for python -fastproxy
Also fixes -O.
This is a minimal change avoiding the differences in the function names
when -fastproxy is used until autodoc code is improved with doxygen
changes.

Closes #721.
2016-06-22 00:15:05 +01:00
William S Fulton
3459099fb8 %shared_ptr and %template testcase modified to work for python -O
Testcase has now been modified to mask the problem by providing the default parameter 'int' in:
%shared_ptr(Space::BaseDefault<short, int>)
If this is not done then d fails to convert to BaseDefault<short>&

This needs fixing in SWIG, but the problem is masked for now, so that the python
testcase works when run with the -O option.
2016-06-21 19:49:27 +01:00
William S Fulton
38cda92938 smartptr inheritance fix when using templates and typedefs
Fixes SF bug 3333549 - %shared_ptr fixes when the type is a template using
template parameters that are typedef'd to another type.

Also fixes python -O optimization where the smart pointer conversion to the
base class needs to work because of the virtual methods that have been
optimized away.
2016-06-21 07:00:56 +01:00
William S Fulton
cc7319f52f Replace assert from Python testcases with code that always runs.
assert code is sometimes not executed, eg when running python -O.
2016-06-19 20:11:51 +01:00
Vladimir Kalinin
4aa86c6647 renamed test module, in accordance with other tests 2016-06-08 14:19:29 +03:00
William S Fulton
98e2132c0b Merge branch 'mromberg-relative'
* mromberg-relative:
  Python: Do not import all of sys when using -relativeimport
  Add missing print statements to the Python import_packages tests
  Update -relative import documentation to reflect runtime check.
  > to >=
  Make the check for python3 -relative does python runtime check.
2016-06-06 22:23:27 +01:00
William S Fulton
dd40a25349 Add missing print statements to the Python import_packages tests 2016-06-06 22:12:56 +01:00
William S Fulton
2d5c32048c Only test python:abc feature when passing -py3 to swig 2016-06-06 19:10:25 +01:00
William S Fulton
df30ae0f0b Examples makefile changes to make it easier to test python3 without -py3
Use:
  make check-python-test-suite PY3=1 SWIGOPTPY3=
  make check-python-examples PY3=1 SWIGOPTPY3=
2016-06-05 22:39:34 +01:00
William S Fulton
53ff928688 Examples readme file tweak 2016-06-05 11:23:58 +01:00
Mike Romberg
2ea01f349d remove builtin tests as they are already covered. 2016-06-04 14:12:33 -06:00
Mike Romberg
0cc3c78abf Apply patch to cleanup whitespace from wsfulton 2016-06-04 14:07:50 -06:00
Mike Romberg
906564d97c and... remove all the .py files that were copied over from the source tree. 2016-06-03 20:20:33 -06:00
Mike Romberg
055ddc6dfc remove -py3 related tests. Move py3 specific code to it's own module 2016-06-03 18:11:07 -06:00
Mike Romberg
f102d587bc copy everything with a .py extension into the build tree (creating dirs if needed) 2016-06-03 17:30:01 -06:00
Mike Romberg
f1aea15cf7 debug 2016-06-03 13:26:12 -06:00
Mike Romberg
f3c373a584 avoid the shell checks involving __init__.py 2016-06-03 03:17:19 -06:00
Mike Romberg
621325a7dd Something optimizes out empty files and breaks the tests. Put something in. 2016-06-03 01:30:43 -06:00