Commit graph

32 commits

Author SHA1 Message Date
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
6833ead6ed Add -namespace option to use unique prefix for all wrappers
Using this option allows to prefix all exported symbols (functions,
enums and enum elements) with a prefix based on the given namespace.

Note that (global) variables can't be exported directly when using the
global namespace prefix, even if they are of C-compatible type.
2021-11-10 00:53:39 +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
45bb179407 Expand "$null" in typemaps in C backend too
This is used in some exception-related typemaps, both in SWIG itself
(although they're not used with C backend currently) and outside of it.
2021-10-07 22:03:47 +02:00
Vadim Zeitlin
b5a8ccffa3 Explicitly refuse to wrap vararg functions
They were not supported currently, but processing them resulted in just
a warning about missing ctype typemap and generated uncompilable code.

Give an error and don't generate any code at all now, which is more
clear and helpful.

Also exclude the part of kwargs_feature test using varargs from C test
suite.
2021-10-04 22:09:12 +02:00
Vadim Zeitlin
f1ab6b7ef2 Change the generated names for the global functions
Prefix them with namespace-based prefix (e.g. "ns1_ns2_" for a function
inside ns1::ns2) if feature:nspace is on. Otherwise, or if the function
is defined in the global namespace, use the module name as prefix
instead of "_wrap": this is slightly less ugly and results in more
unique names.
2019-08-05 14:51:10 +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
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
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
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
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
Leif Middelschulte
e4c486ae6f Add docs about known shortcomings of C++ wrapping.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13710 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-20 19:08:54 +00:00
Leif Middelschulte
b5d2f4765f Update docs to reflect typemap changes.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13708 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-20 18:55:34 +00:00
Leif Middelschulte
d6e0954620 Minor formatting tweaks.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13649 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-18 13:42:39 +00:00
Leif Middelschulte
200a678f61 Remove docs about 'wrap_call' typemap.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13648 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-18 13:42:28 +00:00
Leif Middelschulte
7330e2bbf7 Use actual generated code for 'would like' prologue.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13646 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-17 17:23:10 +00:00
Leif Middelschulte
abe23f2ca0 Unify beginning of command line code
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13645 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-17 17:22:59 +00:00
Leif Middelschulte
dc9f0e5076 Change style of command line snippets to "shell"
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13644 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-17 17:22:48 +00:00
Leif Middelschulte
0db6a8c201 Change style of C code to "targetlang"
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13643 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-17 17:22:38 +00:00
Leif Middelschulte
beb9851f04 Add docs about typemaps used by the C backend for proxy code generation.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13642 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-17 17:22:28 +00:00
Leif Middelschulte
370a7926d8 Use "targetlang" style for C code in docs.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13641 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-17 17:22:17 +00:00
Leif Middelschulte
a826cdda4e Add beginning of 'which typemap is for what' for C backend documentation.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13639 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-17 17:21:51 +00:00
Leif Middelschulte
1c38df4ceb Correct some descriptions of the typemaps. Remove duplicates
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13638 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-17 12:15:08 +00:00
Leif Middelschulte
d9c2e44b25 Fix compile instructions.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13194 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-06-26 16:37:34 +00:00
Leif Middelschulte
3ac7a8fc78 Document typemaps; Correct compile instructions
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13193 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-06-26 15:15:56 +00:00
William S Fulton
d0ae20ec39 set the references right
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10824 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-09-08 20:09:41 +00:00
William S Fulton
a3ad15a6d6 revert last checkin
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10822 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-09-08 20:02:18 +00:00
William S Fulton
a565b7250d updates after running makechap.py
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10821 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-09-08 19:53:42 +00:00
William S Fulton
fde19227a3 Fix typos after proof read
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10815 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-09-07 21:59:57 +00:00
Maciej Drwal
40fd778b23 1. char_strings runtime test
2. next chapters of HTML doc
3. minor bugfixes


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10796 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-08-24 12:39:30 +00:00
Maciej Drwal
5b00567154 Beginning of module documentation.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10795 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-08-19 07:43:48 +00:00