Commit graph

64 commits

Author SHA1 Message Date
Vadim Zeitlin
7bb7fe135a Let cpp_basic unit test pass without method pointers support
This was the only part of the test that didn't work, test at least the rest of
it.
2016-04-21 01:37:40 +02:00
Vadim Zeitlin
11fbdba9de Remove cpp_basic_template_class from the list of failing tests
It passes now.
2016-04-21 01:37:40 +02:00
Vadim Zeitlin
e28bd6bf3a Fix cpp_basic_class_var_pub_member_built_in test compilation
Use the correct header name in the test.
2016-04-21 01:37:40 +02:00
Vadim Zeitlin
4d774887cc Only syntax check generated header when not using run test
There is no need to syntax check the header if it's going to be really used,
so this is a small optimization.

It also separates building of the wrappers from testing them better.
2016-04-21 01:37:40 +02:00
Vadim Zeitlin
87d4a0da71 Reuse c_compile rule in C unit test suite makefile
No real changes, just reuse the commands defined in the C section of the top
level Examples/Makefile instead of (imperfectly, i.e. CFLAGS was forgotten
here) duplicating them in Examples/test-suite/c/Makefile.
2016-04-21 01:37:40 +02:00
Vadim Zeitlin
7a392fd21f Fix typemaps for "void*"
Pass void pointers directly to C, don't handle them objects which was done by
default previously because we didn't define any specific typemaps for them.

This allows to reenable another test.
2016-04-20 18:46:12 +02:00
Vadim Zeitlin
85c9b87f9b Fix ctype typemap for bool& too
Don't add an extra pointer, this is already done at the code level currently.

This makes the "bools" unit test pass.
2016-04-20 18:46:12 +02:00
Vadim Zeitlin
c8e4abd16e Use wrapper functions for global variables of non-C types
Don't try to export the variables whose type can't be represented in C
directly, this can't work.

Instead, just let use the default implementation to generate wrapper functions
for them.

Update "cpp_basic_global_var_class" unit test accordingly and remove it from
the list of the failing tests.
2016-04-20 18:45:42 +02:00
Vadim Zeitlin
668f2b4a85 Syntax check headers by C module when running the unit tests suite
Catch errors in the generated headers even when we don't have a run test.

Unfortunately this uncovered that almost no unit tests actually pass, so many,
many more of them had to be disabled.
2016-04-18 20:30:49 +02:00
Vadim Zeitlin
d98ef6ca07 Remove C-specific enum unit tests
These tests are just a small subset of the full language-independent tests and
it doesn't make much sense to keep them now that the full tests pass.
2016-04-16 00:48:17 +02:00
Vadim Zeitlin
44d68197d6 Hack for "true" and "false" used as enum element values
This is not a full solution by far, but should address the most common case.

This also allows "cpp_enum" unit test to pass.
2016-04-16 00:45:58 +02:00
Vadim Zeitlin
2a4bc0e7e5 Fix function names in the cpp_enum C test
This was just an error in the test.
2016-04-16 00:45:41 +02:00
Vadim Zeitlin
3d21bb2c96 Hack around parser bug with char enum element values
Enum element somehow lose the single quotes around them, compensate for it in
C module code (other modules use module-specific constvalue feature to work
around it, but it seems better to do it in SWIG itself rather than leaving the
user code to deal with it).

This finally makes the "enums" unit test pass.
2016-04-16 00:25:50 +02:00
Vadim Zeitlin
168e16ec67 Hack to support variables of anonymous enum types
Declare the variable as int as this is how variables of enum types are stored
(although this would have to be revised when support for C++11 base enum type
is added) and, although ugly, this at least allows the generated code to
compile.

This fixes some (but not all yet) errors in the "enums" and "cpp_enum" unit
tests.
2016-04-16 00:25:10 +02:00
Vadim Zeitlin
fb4d700279 Represent enums as themselves in generated code
Define enum type and enum values as the elements of this enum instead of using
preprocessor #defines for them.

This fixes a couple of enum-related unit tests.
2016-04-16 00:10:48 +02:00
Vadim Zeitlin
e1a4b02f69 No real changes, just convert files to Unix EOLs
Some tests and examples files as well as the C manual chapter used DOS EOLs,
get rid of them for consistency with all the other text files.
2016-04-16 00:10:22 +02:00
Vadim Zeitlin
c05f03d485 Fix esoteric regression in the previous commit
Implement the check for duplicate SWIG_derives_from<> specializations which
could happen if a template type with default parameters was exported both with
implicit default values used for these parameters and the same values
specified explicitly.

This makes the code more complicated and is very rarely needed (in addition to
the above, the template class must also have a base class to trigger the bug),
but it does happen and used to work, so restore this after breaking it in the
last commit and reenable the template_default2 unit test.
2016-04-16 00:06:35 +02:00
Vadim Zeitlin
818b399c9e Drastically simplify and optimize object creation and destruction
Don't populate the typenames array for each and every created object and don't
search it when deleting every object, this is O(N) in number of classes and is
completely impractical for any big library where N can easily be several
thousands. Use destructor function which will correctly destroy the object
instead.

Also don't store each created objects in the global registry, there doesn't
seem to be any point in it.

And, in fact, don't bother with the typenames at all, just use another
pseudo-virtual function for checking whether a class inherits from a class
with the given name.

There is unfortunately one problem with the new approach: it doesn't work when
the same C++ type is wrapped under different names as this results in multiple
specializations of SWIG_derives_from<> for this type. But this is a relatively
rare situation (but which does arise in template_default2 unit test, which had
to be disabled) and could be fixed in the future by completely resolving the
type, including the default template parameters values, and checking if
SWIG_derives_from had been already specialized for it. In the meanwhile, this
regression is not a big deal compared to the advantages of the new approach.
2016-04-15 23:25:32 +02:00
Vadim Zeitlin
3d6880aad1 Start removing proxy layer, just use the wrapped functions directly
The proxy layer, and all the extra complexity associated with it, seemed to be
only necessary in order to try to allow using the same name for the wrapped
global functions as were used for them in the original C or C++ code being
wrapped. However this could simply never work in all cases, notably it didn't
work at all when using ELF shared libraries under Unix as the functions with
the same name defined in the main program were interposed and replaced the
functions defined in the shared library, meaning that the proxy function foo()
called wrapper function _wrap_foo() which called back into proxy function
foo() itself again, resulting in guaranteed stack overflow. The only possible
way to fix this would be to use "protected" ELF visibility for the original
functions, but this is not always possible (e.g. if the sources of the
original library are not available) and not simple even when it is and,
besides, protected visibility has its own problems -- notably by making it
impossible to hook the library functions when you actually want to do it.
Besides, proxy-based approach simply couldn't work at all when using static
linking as it resulted in two copies of the function with the same name

Most importantly, however, the main task of this module is to wrap C++
classes, not C functions, and renaming them in the wrapper is not necessary at
all in this case as there is no conflict with the original names in this case.
So simply drop the idea of generating a separate proxy header and generate a
header declaring the functions declared in the wrapper instead and, also, do
not give them "_wrap_" prefix whenever possible, i.e. only do it for the
global functions.

This simplifies SWIG code itself and makes it simpler to use its output as
it's not necessary to link both with the wrapper (dynamically) and with the
proxy (statically) and it's not enough to link with the wrapper only and it
can be done in any way (i.e. either statically or dynamically).

As a side effect of this change, Swig_name_proxy() is not necessary any more
and was removed, eliminating the only difference with the master branch in any
source file other than c.cxx itself.
2016-04-14 02:44:45 +02:00
Vadim Zeitlin
e8ec13f56b Remove SWIG_MAKE_DELETE() macro from C runtime
This doesn't seem to be necessary nor even useful at all, just get rid of it
completely and expand it manually in the only place where it was used.
2016-04-13 18:10:36 +02:00
Vadim Zeitlin
82ce7e4725 Force the unit test suite to pass for C
Disable all currently failing tests.
2016-04-13 18:10:35 +02:00
Vadim Zeitlin
3b087fcb2b Fix running C test suite when using a separate build directory
Correct top_srcdir path and use ../$(srcdir) instead of just "../" which may
not be the same when building in another directory.
2016-04-13 18:10:35 +02:00
Leif Middelschulte
4da42db22e Remove the std_vector test I've added while trying for testing purposes
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13627 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-16 12:52:29 +00:00
Leif Middelschulte
ed402ceb37 Don't delete variables twice.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13587 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-10 15:43:11 +00:00
Leif Middelschulte
78ccc8f228 Fix wrong headers inclusion
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13586 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-10 14:50:18 +00:00
Leif Middelschulte
c81a3bd5ec Add typecast to silence compiler warnings caused by inheritance.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13585 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-10 14:50:04 +00:00
Leif Middelschulte
a84787c273 Rename reference to C++ native types from 'atomic' to 'built_in'
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13583 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-10 14:49:37 +00:00
Leif Middelschulte
56db1d6e4e Add C backend runtime implementation for basic C++ std::vector<int> test
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13581 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-09 20:03:42 +00:00
Leif Middelschulte
d272709899 Add C runtime test for corresponding C++ basic template test
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13573 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-09 13:06:22 +00:00
Leif Middelschulte
698d1851c3 Add C runtime test for basic C++ template functions
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13568 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-08 16:06:56 +00:00
Leif Middelschulte
b0318dae69 Add test for 'natural' C++ std::string handling in C (char*).
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13482 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-01 12:53:17 +00:00
Leif Middelschulte
44f4dd4dc0 Extend test to check dynamic binding of virtual methods
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13480 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-01 00:51:50 +00:00
Leif Middelschulte
130ae2cb26 Implement basic C++ exception test for C backend.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13479 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-31 21:15:33 +00:00
Leif Middelschulte
ffb2b6b73b Implement basic C++ virtual method test case for C
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13478 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-31 21:08:39 +00:00
Leif Middelschulte
ea240fdde3 Rename cpp_atomic_* tests to cpp_basic_*
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13423 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-27 14:05:14 +00:00
Leif Middelschulte
f7b5211739 Add C implementation of test cpp_atomic_class
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13422 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-26 20:23:53 +00:00
Leif Middelschulte
15e8b647a2 Add C implementation of test cpp_atomic_class_enum
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13420 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-26 20:23:27 +00:00
Leif Middelschulte
2080038170 Add C implementation of test cpp_atomic_class_method
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13418 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-26 20:23:02 +00:00
Leif Middelschulte
f24ce340ff Add C implementation of test cpp_atomic_class_var_pub_member_atom
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13416 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-26 20:22:37 +00:00
Leif Middelschulte
dbd8d3aabd Add C implementation of test cpp_atomic_class_var_pub_member_class
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13414 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-26 20:22:08 +00:00
Leif Middelschulte
cfc1a71b71 Add C implementation of test cpp_atomic_global_enum
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13412 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-26 20:21:35 +00:00
Leif Middelschulte
7d3677a5c8 Add C implementation of test cpp_atomic_global_var_atom
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13410 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-26 20:21:03 +00:00
Leif Middelschulte
48fe82841f Add C implementation of test cpp_atomic_global_var_class
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13408 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-26 20:20:29 +00:00
Leif Middelschulte
fca2262e28 Add C implementation of test cpp_atomic_namespaced_class
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13406 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-26 20:20:02 +00:00
Leif Middelschulte
3afdd50c78 Fix tests' LD_LYBRARY_PATH and alternatives
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13404 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-26 20:19:36 +00:00
Leif Middelschulte
95cd7ea300 Fix cpp_enum runtime test to include the right header
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13312 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-09 23:29:24 +00:00
Leif Middelschulte
f4ebc3068d Add runtime C++ test for enums.
What does not (entirely) work:
- 'extern "C"' enum declaration
- 'typedef enum {...} play_state'
- C++ class enums value definition in proxy

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13310 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-09 22:35:19 +00:00
Leif Middelschulte
8e66df1b5a Implement test case for C++ features listed below
- pointers
- references
- values
- static variables
- default parameters
- function pointers (reason the test fails)
- global (static) variables (code commented out so far)

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13259 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-05 00:23:17 +00:00
Leif Middelschulte
f18a62f57d Implement some test cases for the C backend
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13211 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-06-30 16:03:57 +00:00
Leif Middelschulte
5db9c97963 Compile _proxy.c even if _runme.c does not exist.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13195 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-06-26 16:37:50 +00:00