Commit graph

99 commits

Author SHA1 Message Date
Vadim Zeitlin
fe8c6fad44 Ignore std::vector<T>::get_allocator()
This is not really useful in C wrappers and results in ugly descriptor for the
allocator type appearing in the output, better to avoid it.
2016-09-15 01:27:41 +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
f533e3c488 Pass const references to primitive types by value
Change the typemaps to use values, not pointers, for arguments of "T const&"
type, this is much more natural in C.
2016-09-15 01:27:41 +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
8cae88dd39 Get rid of separate cmodtype typemap
Use the same ctype for wrapper declarations and definitions and just expand
$resolved_type differently in the two cases.

This simplifies the typemaps and ensures that the declarations and definitions
use the same types, at least for all non-object parameters.
2016-04-21 18:58:32 +02:00
Vadim Zeitlin
5de29df38e Simplify typemaps by merging both const and "unconst" versions
We can always just use the "unconst" one because it works when the type is
used for a return value and is the same as the other one when it's used for a
parameter anyhow because top-level const is ignored in function signatures, so
don't bother defining two sets of macros when one will do.
2016-04-21 17:55:47 +02:00
Vadim Zeitlin
806f79de14 No real changes, just rename "proxy_header" to "cheader"
Continue getting rid of "proxy" terminology, there is no proxy when using C
module, so it's confusing to use this term.
2016-04-21 15:18:22 +02:00
Vadim Zeitlin
e934c51425 Include stddef.h instead of stdio.h in the generated header
The sole reason for including this header seems to be to get size_t
declaration, so include the smallest header sufficient for this.

It would be even better to use a fragment for all size_t typemaps to only
include it if necessary, but it doesn't seem to be worth doing this right now.
2016-04-21 01:37:41 +02:00
Vadim Zeitlin
e8c6bfbc8f Remove completely broken handling of member function pointers
Member function pointers can't possibly be represented as function pointers,
they have a strictly bigger size and attempting to do it resulted in code
which, with a lot of bad casts, compiled, but crashed during run-time.

The proper solution is to represent C++ method pointers with an appropriate
opaque type, but for now this remains broken -- just make it explicitly broken
instead of pretending that it works when it actually has no chance to.

Let "namespace_spaces" unit test pass, as it's not really related to the
function pointers, by adding an explicit SWIGC test to it.
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
18cb946405 Fix cmodtype typemap for "const bool &"
We need bool to be "const", not the pointer.

This fixes a few of the errors in the "bools" unit test.
2016-04-20 18:46:12 +02:00
Vadim Zeitlin
8104c24f71 Fix typemaps for templates with more than one parameter
Ensure that any commas inside SWIG_STR() used in "out" typemaps for class
types are not interpreted as macro argument separators by using an extra pair
of parenthesis around the type.
2016-04-20 01:53:26 +02:00
Vadim Zeitlin
0be93325a9 Fix "out" typemap for enum pointers/references
Taking the address of C++ result doesn't make sense here, the C++ result is
already a pointer and so should be just returned as is.
2016-04-16 00:44:41 +02:00
Vadim Zeitlin
27abb84113 Fix runtime code when not using exceptions
Add the missing "%insert" line which had been somehow lost.
2016-04-16 00:09:09 +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
42c3d420b2 Remove SWIG_temporary from the generated code
This doesn't seem to be used anywhere.
2016-04-14 02:44:46 +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
6bbe375a37 Remove unused SWIGPROTECT
It doesn't make any sense to use protected visibility for the symbols in the
proxy code, the only use for it would be if it could be applied to the
original functions being wrapped, to prevent them from being shadowed by the
proxy versions, but this cannot be done, in general.

Apparently this was already understood as the code using SWIGPROTECT was
commented out, but ef85d0d43f didn't give any
reason for doing this, nor for leaving this code.

Assume there was none and just remove it completely now to avoid confusion.
2016-04-13 18:10:35 +02:00
Leif Middelschulte
49735451ee Update comments in typemaps file.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13682 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-20 13:23:29 +00:00
Leif Middelschulte
d906d3c73e Reuse 'cmodtype' typemap and remove 'couttype' typemap completely.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13681 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-20 13:23:18 +00:00
Leif Middelschulte
5aa23f9bdb Reuse 'ctype' typemap and remove 'proxycouttype' typemap.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13680 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-20 13:23:03 +00:00
Leif Middelschulte
a894545c9a Rename 'proxy' to 'ctype' as it's the typemap used for the C API.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13679 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-20 13:22:48 +00:00
Leif Middelschulte
fcecbf17a2 Rename 'ctype' typemap to 'cmodtype' since it's only used for internal (wrapper) stuff.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13678 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-20 13:22:33 +00:00
Leif Middelschulte
7a0a1022f8 Remove leftovers of removed 'wrap_call' typemap.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13677 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-20 13:22:18 +00:00
Leif Middelschulte
b75cba540a Remove leftovers of replaced typemap macro
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13676 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-20 13:22:07 +00:00
Leif Middelschulte
b7699ce14a Use macros even more.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13675 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-20 00:05:43 +00:00
Leif Middelschulte
a932e9eb8a Rename internal macro.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13674 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-20 00:05:24 +00:00
Leif Middelschulte
7fc64478b0 Base macros on types rather than on qualifiers.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13673 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-20 00:04:57 +00:00
Leif Middelschulte
e01955d0ff Move '[const] T ** const' and size_t of 'out' typemap into macros
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13672 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-19 21:08:23 +00:00
Leif Middelschulte
f9c0e104e6 Move '[const] T const **' and 'size_t' of 'in' typemap into macros
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13671 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-19 21:08:12 +00:00
Leif Middelschulte
89725492f2 Revert lines, which weren't meant to get in.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13670 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-19 20:00:28 +00:00
Leif Middelschulte
87644d282b Remove line that is already covered by macro.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13669 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-19 20:00:14 +00:00
Leif Middelschulte
4c1b189d72 Remove void 'cppouttype' typemap. Doesn't make sense.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13666 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-19 13:50:44 +00:00
Leif Middelschulte
a94ef7b1be Remove void arrays.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13665 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-19 13:50:32 +00:00
Leif Middelschulte
adb9b16167 Fix typo
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13664 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-19 13:50:20 +00:00
Leif Middelschulte
dc9b3c01ff Removed leftovers from macrofication.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13659 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-18 23:58:44 +00:00
Leif Middelschulte
6b0403c33c Fix missing macro argument usage due to copy&pasta
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13658 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-18 23:58:33 +00:00
Leif Middelschulte
032c12b70e move signed char to the group of types for which no unsigned exist
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13657 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-18 23:58:22 +00:00
Leif Middelschulte
04efe5fe66 Remove old (and commented out) region about template typemaps.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13656 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-18 23:31:35 +00:00
Leif Middelschulte
e3f351bf4b Macrofy more typemaps. Does not work yet, because SWIG's preprocessor seems to have problems with empty args of macros.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13655 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-18 23:30:19 +00:00
Leif Middelschulte
3ca35323f6 Macrofy 'ctype' typemap
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13654 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-18 23:30:09 +00:00
Leif Middelschulte
2e0a4c7f85 Macrofy 'proxy' typemap.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13653 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-18 23:29:53 +00:00
Leif Middelschulte
b25f28938b Reuse 'ctype' typemap to cast wrapper calls. Reduces number of typemaps for the cost of unnecessary casts (e.g. 'int' to 'int').
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13640 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-17 17:22:06 +00:00
Leif Middelschulte
3b6e37bdf8 Workaround issue with swig casting to wrong (not const) type in wrapper's C++ function call, by setting variables to non const.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13626 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-16 12:48:00 +00:00
Leif Middelschulte
554a3f9e01 Remove copy and pasta (unsigned float and unsigned double typemaps).
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13625 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-16 12:47:49 +00:00
Leif Middelschulte
f013b9d044 Add explicit types for 'ctype' typemap because swig does not resolve e.g. std::vector<int>::value_type to 'int' with the $1_ltype approach.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13624 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-16 12:47:39 +00:00
Leif Middelschulte
9cd39cca50 Fix typemaps of char* and equivalents to be explicit about the resolved type.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13623 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-16 12:47:27 +00:00
Leif Middelschulte
0d472a6cb7 Add constant pointers to 'out' typemap.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13617 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-15 19:57:11 +00:00