Compare commits

...
Sign in to create a new pull request.

516 commits

Author SHA1 Message Date
494153fe86
Fix cxx 2023-02-18 00:43:25 -07:00
5a06ca1ed7
Merge branch 'master' of https://github.com/swig/swig into Cmerge 2023-02-18 00:05:36 -07:00
2a71d012c0
Resolve conflicts in same name vars 2023-02-17 21:07:37 -07:00
83ae863d4a
Add names to c function params 2023-02-17 18:55:32 -07:00
Vadim Zeitlin
b88df82c55 Fix another format mismatch error in char_strings runtime test 2022-09-17 17:39:04 +02:00
Vadim Zeitlin
799fd7a5be Exclude li_std_auto_ptr test from C test suite
There are (and there probably will never be) std::auto_ptr<> typemaps
for this language.
2022-09-17 17:33:31 +02:00
Vadim Zeitlin
23144219af Use "int" for variables printed out using "%d" in the code
Fix -Wformat warnings in the char_strings runtime test.
2022-09-17 17:30:54 +02:00
Vadim Zeitlin
2b2fe7785a Fix enabling C++11 for C CI builds
Set CPPSTD as CPP11 is not used any longer.
2022-09-17 17:22:30 +02:00
Vadim Zeitlin
0688ac7e07 Recognize C language in the test flags script 2022-09-17 15:37:51 +02:00
Vadim Zeitlin
049d3c309b Fix handling of const object parameters and return types
Simply ignore the const on them, to avoid ending up with an extra and
invalid "const" in the generated code.

This fixes director_pass_by_value and typemap_out_optimal unit tests
after the latest merge.
2022-09-17 15:30:31 +02:00
Vadim Zeitlin
2796f394f5 Exclude argcargvtest unit test from C test suite
There is no argcargv.i for C yet.
2022-09-17 15:09:51 +02:00
Vadim Zeitlin
523e58aa06 Check for multiple inheritance of the base classes too
If C++ wrappers for a class are not generated because it uses multiple
inheritance, we can't generate the C++ wrappers for any classes deriving
from it neither, so don't do it.

This fixes failure in multiple_inheritance_overload unit test.
2022-09-17 15:08:31 +02:00
Vadim Zeitlin
81866a0ce2 Re-enable use of method suffix for C module
This avoids conflicts with the actual function being wrapped.
2022-09-17 14:46:38 +02:00
Vadim Zeitlin
f83e2a7de7 Stop using SWIG_exit() in C backend
This function doesn't exist any more.
2022-09-17 14:39:23 +02:00
Vadim Zeitlin
864f32159a Merge branch 'restore-compat-wrappers-names' into C
Merge with the latest master including PR #2371.
2022-09-17 14:36:37 +02:00
Vadim Zeitlin
3caf285742 Make method wrappers suffix optional and disabled by default
Unfortunately the changes of 26bf86322 (Use SWIG-specific for
non-overloaded synthesized functions too, 2021-11-09) did break some
existing code bases using SWIG as they hardcoded the old wrapper
function names.

So turn this off by default and add a global variable allowing to enable
this, which can be done for a specific language only. This is ugly but,
unfortunately, there is no way to use the Language object from the C
function Swig_MethodToFunction(), so the only alternative would be to
add another parameter to it, but it already has 6 of them, so it
wouldn't really be that much better.

See #2366, #2368, #2370.
2022-09-17 14:27:51 +02:00
Vadim Zeitlin
4748e4f379 Remove more insignificant differences with examples in master
Follow the she style of the other existing examples.
2022-01-15 16:50:17 +01:00
Vadim Zeitlin
faa5d8bbf5 Change value of WARN_C_UNSUPPORTTED for consistency
Use consecutive value for the C-specific warnings instead of reserving
the first and last values of the range for consistency with the other
modules.
2022-01-15 16:40:46 +01:00
Vadim Zeitlin
c1fcf99ea7 Revert change to handling "#@" in SWIG preprocessor
The extra flexibility in expanding "#@" was considered inappropriate,
see the discussion in #2096, so revert the preprocessor part of the
changes of 5bf1497d7 (Allow customizing type mangling in SWIG
preprocessor, 2021-11-10).

This unfortunately means that the macros used in <attribute.i> don't
work for C backend any longer, so a previously passed unit test had to
be disabled.
2022-01-15 16:35:21 +01:00
Vadim Zeitlin
7eb67cecca Restore the use of matrix.desc in GHA workflow file
This is not used currently, but keep it there as this change is not
related to C backend addition.
2022-01-04 01:33:55 +01:00
Vadim Zeitlin
9a2e48b447 Clean up class example header
Apply changes of b115c984a (More cleaning up of the class examples,
2014-05-05) and other similar commits to the header in this branch too.
2022-01-04 01:32:25 +01:00
Vadim Zeitlin
cb974ef662 Use COMPILETOOL with C_LDSHARED and CXX_LDSHARED
This is consistent with the way this is done for the other backends and
allows to avoid overriding these variables for partialcheck target.

Co-Authored-By: Olly Betts <olly@survex.com>
2022-01-04 01:29:21 +01:00
Vadim Zeitlin
92c3b37337 Avoid defining custom assert() macro in one of the C tests
This was inconsistent with all the other tests and the macro suffered
from several problems. Just drop it and use the standard macro with the
same name instead.
2022-01-04 01:26:40 +01:00
Vadim Zeitlin
3b7f772dde Remove extra trailing blank line in examples makefile
This was removed in master but somehow survived in this branch.
2022-01-04 01:24:12 +01:00
Vadim Zeitlin
78e09d5372 Remove commented out code from c/std_except.i
This was added in 32e03aa13 (Many major improvements. Almost all
testsuite compiles now., 2009-04-15) and never really used.
2022-01-04 01:10:43 +01:00
Vadim Zeitlin
0fcdec302c Revert some insignificant changes done in historical C branch
This undoes parts of a2dc2756c (Several major fixes for: arrays, static
members, member func.ptrs., exceptions, ... Lots of tests runs ok now.,
2009-04-13) that shouldn't have been done in the first place.
2022-01-04 01:10:16 +01:00
Vadim Zeitlin
6a96b8d477 Disable warnings about unsupported features in C test suite
There are too many of them currently for them to be useful.
2021-12-09 00:50:26 +01:00
Vadim Zeitlin
e15d3e17ac Allow skipping creating C++ wrappers with cxxignore feature
This can be useful to avoid errors due to features not supported at C++
level in some tests.
2021-12-09 00:50:18 +01:00
Vadim Zeitlin
f06bba320a Make it possible to customize swig_check() definition
Move this function definition to cexcept.swg from the code and only
define it if SWIG_swig_check_DEFINED is not defined yet, which both
simplifies the code in C.cxx and makes exception handling code more
flexible, as it's now possible to predefine SWIG_swig_check_DEFINED
in the code injected into the "cxxheader" section to replace the default
implementation. Show an example of doing this in the documentation and
document handling exceptions with C API too.

The changes above required adding a new "cxxcode" section, corresponding
to the "implementation" part of C++ wrappers and defining a new
SWIG_CXX_WRAPPERS preprocessor symbol to allow only adding C++-specific
code when C++ wrappers are actually generated. Also improve the
documentation of the C-specific sections in the manual.
2021-12-09 00:31:14 +01:00
Vadim Zeitlin
86dbf6bcb5 Generate C++ wrappers for the global functions too
This ensures that global functions can also use C++ classes, enums etc
for their parameters and return types.

C++ wrappers for a couple of tests had to be disabled, but this is not
really a regression as wrapping global functions just made apparent
problems that were not visible before because the corresponding wrappers
were not created at all.
2021-12-08 03:29:09 +01:00
Vadim Zeitlin
1fd4c647b8 Add support for const references to pointers
They're used in some unit tests and we can support them by handling them
just as pointers in C++ wrappers (this was already the case for C
wrappers).
2021-12-08 03:28:44 +01:00
Vadim Zeitlin
3d0fe23e29 Move setting parameter/return type inside do_resolve_type()
No real changes, this just prepares for more changes later.
2021-12-08 03:09:28 +01:00
Vadim Zeitlin
bec35fa0c2 Define "equivalent" typecheck typemap attribute for shared_ptr<>
This is required to handle overloaded functions taking shared_ptr or raw
type correctly and is checked in cpp11_shared_ptr_overload unit test.
2021-12-08 03:09:28 +01:00
Vadim Zeitlin
74e8a6e729 Reenable C++ wrappers for some of the previously failing tests
Document the reason for failure for some of those that still fail
without -nocxx.
2021-12-08 03:09:28 +01:00
Vadim Zeitlin
edff57c2ad Don't generate C++ setters and getters inline
The type of the member may be incomplete, so generate the definitions of
these functions in a separate section, after declaring all the wrapper
classes, just as it was already done for the other functions.

This fixes compiling some of the previously failing tests in C++ mode.
2021-12-08 03:09:28 +01:00
Vadim Zeitlin
cc76e3a1d7 Fix crash for classes with ignored base class
This fixes class_ignore.cpptest.
2021-12-08 00:56:50 +01:00
Vadim Zeitlin
c5cd287ec6 Enable some C++ tests by just using a different namespace
Using "typename" or "dynamic_cast" as C++ namespace names unsurprisingly
resulted in compilation errors, so don't do this.
2021-12-08 00:56:13 +01:00
Vadim Zeitlin
184e620151 Fix $resolvedType expansion for references to pointers
Use the base type, not the full type, to deal with the special case of
references to pointers which are blacklisted by classLookup(), for some
reason, but can be represented at C wrappers level.
2021-12-07 23:55:10 +01:00
Vadim Zeitlin
26810a5f02 Fix support for "numinputs" in typemap argument in C++ wrappers
Ignore the parameters with numinputs==0 for C++ wrappers too, just as it
was already done for C ones.
2021-12-07 23:53:43 +01:00
Vadim Zeitlin
57ba3a7245 Factor out C++ function generation into cxx_function_wrapper
No real changes, just factor out the code for (non-special) functions
generation from emit_member_function() into a separate
cxx_function_wrapper class, so that it could be reused for the global
functions generation too.
2021-12-07 23:24:41 +01:00
Vadim Zeitlin
730384834d Fix dealing with class typedefs in do_resolve_type()
We must use the string for the resolved type, i.e. after replacing
typedefs with their expansions, as otherwise typedefs could leak into
the generated header.

In principle it might be possible to actually use the original typedefs
in the C++ part of the wrappers, but then we'd need to propagate the
typedef definitions there too and we don't do it currently.
2021-12-07 20:54:28 +01:00
Vadim Zeitlin
09f22c7453 Remove unnecessary stripped_type variable from do_resolve_type()
It's unnecessary to strip qualifiers ourselves when classLookup()
already does it internally anyhow.
2021-12-07 20:54:28 +01:00
Vadim Zeitlin
f3b0b42145 Add cxx_wrappers::is_exception_support_enabled()
No real changes, just add a helper function to make the code more clear.
2021-12-07 20:54:28 +01:00
Vadim Zeitlin
a2bd9eec05 Don't generate C++ wrappers for functions using unsupported types
This is far from ideal, but better than generating uncompilable code in
this case.
2021-12-07 20:54:28 +01:00
Vadim Zeitlin
a40b7b6d1c Change lookup_cxx_parm_type() to return bool too
This is more consistent with lookup_cxx_ret_type() and makes using it
simpler.

Also move error reporting into this function itself as it could fail for
other reasons than missing "ctype" typemap too.

No real changes.
2021-12-07 20:54:28 +01:00
Vadim Zeitlin
f4ecc3c06a Move type-resolving code to cxx_wrappers
This is also not specific to class wrappers, but can, and will be, used
for the global functions, so move it to a place where it can be reused.

No changes yet.
2021-12-07 20:54:28 +01:00
Vadim Zeitlin
9f80bc8113 Move void check and error reporting to lookup_cxx_ret_type()
This code doesn't belong to emit_member_function() as it's relevant for
all functions, not just the member ones.

No real changes.
2021-12-07 20:54:28 +01:00
Vadim Zeitlin
45feb91551 Move cxx_wrappers definition after cxx_{r,p}type_desc
No changes, just prepare for starting to use the "desc" classes in
cxx_wrappers.
2021-12-07 20:54:28 +01:00
Vadim Zeitlin
b072b2dc87 Represent empty shared pointers by null pointers at C level
This is much more convenient and allows checking if the shared pointer
is empty easily, unlike before, when it couldn't be done and adding
support for it would have required adding extra functions.

Also add a way to check whether an object is null in C++ wrappers of the
classes handled via shared pointers and static null() method for
creating null objects of such classes.
2021-12-07 20:54:28 +01:00
Vadim Zeitlin
8d9f3e88b2 Expand special variables in cxxcode typemap
This makes the typemap much more useful, as it can now reference the
name of the class it is being expanded for and the type of the C pointer
used by it (in principle, the latter could be recovered by using
decltype(), but this results in rather verbose code inside static
methods where a dummy pointer to the type must be constructed first, so
using another special variable seems like a simpler solution).
2021-12-07 20:54:28 +01:00
Vadim Zeitlin
f9b4ea2841 Define a local variable for sym:name attribute
No changes, this is just a tiny simplification.
2021-12-07 20:54:28 +01:00
Vadim Zeitlin
e2d32f33b2 Add support for "cxxcode" typemap
This allows injecting arbitrary code into the generated C++ classes and
can be useful for defining extra constructors or operators, for example.
2021-12-07 20:54:28 +01:00
Vadim Zeitlin
fd11a591a3 Add cxx{in,out}type typemaps and use them for std::string
This makes using returning strings much simpler to use from C++ code as
the returned pointers don't have to be deleted manually -- although, of
course, this does require an extra allocation and copy and so should be
avoided for the very long strings.

Add a new runtime test showing how simple and convenient it is to use
the functions working with string using the C++ wrappers now.
2021-12-07 20:54:28 +01:00
Vadim Zeitlin
8b871b10fe Replace type_desc with cxx_ptype_desc
This is similar to the last two commits for cxx_rtype_desc and uses a
more appropriate and more specific class for holding parameter type
description.

This is just a refactoring, no real changes yet.
2021-12-07 20:54:28 +01:00
Vadim Zeitlin
e3a1301698 Rename cxx_rtype_desc::set_return_xxx() to apply_out_typemap()
Instead of using ad hoc terminology, just call the string used here a
typemap because this is what it actually is.

Also keep just a single function and prepend "$result =" to it
automatically if necessary, as this is more convenient.

Still no real changes, but this will make it simpler to add support for
user-specified cxxout typemap.
2021-12-07 20:54:28 +01:00
Vadim Zeitlin
4ab28437a7 Separate cxx_rtype_desc from type_desc class
Maintaining just wrapper start/end fragments is too limiting, at least
for the return type, so allow making the "return action" a formatted
string in which the return value can be inserted at any place.

This will allow making return types more customizable in the upcoming
commits, but there are no changes yet, this is just a refactoring.
2021-12-06 16:50:17 +01:00
Vadim Zeitlin
7c46ff1b6e Add "cxxheader" section to allow injecting extra C++ declarations
This can also be used to include extra C++ headers.

Document this section as well as the already existing "cheader" one.
2021-12-06 16:50:17 +01:00
Vadim Zeitlin
a335fff2ec Avoid errors due to generating identical overloads
Add typecheck typemaps for primitive types and string and call
Swig_overload_check() to ensure that we don't generate two wrappers
functions taking the same "const char*" type if we have overloads taking
it and "std::string" (or a reference) in the original code.
2021-12-05 20:49:20 +01:00
Vadim Zeitlin
4a3ae6f8d3 Don't generate C++ wrappers for overridden virtual functions
This is harmless, but also useless, as the implementation is the same as
the existing one in the base class anyhow.
2021-12-05 20:24:38 +01:00
Vadim Zeitlin
aacc930023 Streamline and improve std::string typemaps
Avoid unnecessary heap allocations, just use temporary variables.

Actually update the string parameters passed by pointer/non-const
reference. This requires the pointers passed to actually be non-const,
so update the C-specific unit test runme to use a char buffer instead of
a literal string.

Also simplify the code copying the string contents to just use strdup()
(if there are ever any platforms where this POSIX functions is not
available, we could just define it ourselves once instead of using
strlen() + malloc() + memcpy() manually twice).
2021-12-05 03:31:35 +01:00
Vadim Zeitlin
628e2cf6d2 Make std::{set,map} has() and has_key() methods const
They don't modify the object, so should be callable on const objects.
2021-12-04 17:47:27 +01:00
Vadim Zeitlin
c4187f495f Fix definition of move assignment operator for wrapper classes
Classes not deriving from another class in the hierarchy must take care
of freeing their current pointer before reassigning it.

This should have been part of 3f3438093 (Define move ctor and assignment
operator for C++ wrappers, 2021-11-24).
2021-12-03 03:53:36 +01:00
Vadim Zeitlin
bfc6623bbd Make SWIG_CException dtor public to fix memory leak
The actual dtor was never called when the wrapper object was destroyed
before, due to dtor being private.
2021-12-03 03:38:33 +01:00
Vadim Zeitlin
19e0ecbb9d Don't leak the pointer returned by SWIG_CException::get_pending()
This pointer is always new (if non-null) and so must be deleted.
2021-12-03 03:38:04 +01:00
Vadim Zeitlin
d33e76e045 Fix bug with deleting even non-owned pointers in C++ wrappers
Only take ownership of the objects returned from functions that are
explicitly annotated with %newobject or from functions returning objects
by value -- as in this case nothing else can own the returned object
anyhow.

This required changing the code slightly to let do_resolve_type() access
the function node pointer, as the information we need is only available
in it and not in the dummy node passed to us when we're called from
inside Swig_typemap_lookup() due to $typemap() expansion.
2021-12-03 03:00:17 +01:00
Vadim Zeitlin
efdfad6565 Avoid redundant casts for function result in generated code
No real changes, just avoid somewhat ridiculously looking consecutive
casts to the same type in the generated code.
2021-12-02 00:31:33 +01:00
Vadim Zeitlin
e4bb84f3bd Represent scoped enums as scoped enums in C++ wrappers
This is better than turning them into unscoped enums with a prefix for
the elements.
2021-11-30 02:30:46 +01:00
Vadim Zeitlin
a031ec3474 Enable two previously failing tests that pass now
This is just the result of rerunning "make check-failing".
2021-11-30 02:29:31 +01:00
Vadim Zeitlin
579c343d5f Represent enums as enums, not int, if possible
Use enum types instead of int for the enum-valued parameters and
function return values, this is more type-safe and clear for the users
of the library.

Change cpp_enum unit test to use C++ to check that C++ enum wrappers
can at least be compiled, but still use C API in it.

Note that enum whose underlying type is bigger than int still don't
work, but this is no different from what it was before, so just document
this limitation but don't do anything else about it for now.

This commit is best viewed ignoring whitespace-only changes.
2021-11-30 02:22:25 +01:00
Vadim Zeitlin
815c7c0361 Don't call getEnumName() with NULL node
No real changes, just a tiny refactoring in preparation for the upcoming
changes.

This commit is best viewed ignoring whitespace-only changes.
2021-11-30 01:57:59 +01:00
Vadim Zeitlin
06c651431c Fix enum names for renamed typedefs
Also use sym:name even for typedefs for enums themselves, as they can
%renamed as well.

Note that this means that "tdname" itself should probably be never used
at all at this level, but it's still used for structs in C mode, which
is almost certainly wrong.
2021-11-30 01:43:22 +01:00
Vadim Zeitlin
1c06a43e35 Do use sym:name for the enum names themselves
Ever since fb4d70027 (Represent enums as themselves in generated code,
2016-04-14) the code used "name" attribute for the enums themselves
instead of "sym:name". The reason for this was documented in the comment
added in f4ee8e536 (Fix names of enums and their elements, 2021-11-04),
but this explanation was only half-correct: although we indeed shouldn't
use sym:name for typedefs, we should use it for the enums themselves, as
otherwise renaming them didn't work and enums were generated in the
wrappers with the wrong names.

Fix this by using sym:name for non typedef'd enums.
2021-11-30 00:17:27 +01:00
Vadim Zeitlin
6fb95e7e97 Fix wording of another error message
Don't use "reference return type" for the typemap used for returning
objects by value.
2021-11-29 15:45:38 +01:00
Vadim Zeitlin
4a3f4ba896 Improve error given for unsupported typemap in C++ wrappers
This error message should never happen, normally, but still make it more
informative if it does, as it could be just completely useless if there
was no sym:name attribute on the node (as is often the case for the
function parameters, for example).
2021-11-29 15:33:53 +01:00
Vadim Zeitlin
9a974040fa Fix naming scoped enums elements in C++ wrappers
For now still use prefix for them, as otherwise enum element names may
conflict with the other names defined in the same scope.

The upcoming commits will handle them as scoped enums in the wrappers
too.
2021-11-27 18:51:13 +01:00
Vadim Zeitlin
059f615a61 Generate C++ wrapper enums for nested enums too
This doesn't seem to be more difficult to do, just ensure that the
nested enums use the proper indentation and output them in the section
containing the class declaration, rather than the global ones.
2021-11-27 18:51:13 +01:00
Vadim Zeitlin
8643dcf426 Generate C++ enum wrappers
They are almost identical to C enums, but are more convenient to use
from C++ code, as the (possibly long) prefix doesn't need to be fully
specified if namespace using directive is used.

For now restrict the wrapper enums generation to global enums only.
2021-11-27 18:51:11 +01:00
Vadim Zeitlin
e8cb7cc952 Simplify code dealing with enum prefix
Use enum_prefix_, ending with "_" if it's not empty, as it can be used
unconditionally instead of having to check whether it's null every time
first.

No real changes, this is just a simplification.
2021-11-27 18:50:23 +01:00
Vadim Zeitlin
30bbb6ae1c Slightly simplify code in enumDeclaration()
Don't bother with maybe_owned_dohptr, we can just use tdname directly at
the cost of a single "if" at the end, so do it like this as it's more
clear and shorter.
2021-11-27 16:02:14 +01:00
Vadim Zeitlin
1087e250d6 Fix long-standing confusion between Files and Strings
Don't use "f_" prefix and "File *" type for the variables that are
strings and not files. Use "sect_" prefix, which means "section", and
"String *" for them.

This finally stops using misleading types (even if they all map to
"void*" anyhow) for the variables, which could result in using file-only
functions with non-files or string-only functions (e.g. Append()) with
two "f_" variables, only for it to work with one of them but not the
other (which was a real file, unlike the first one).

No real changes, this just clarifies the types.
2021-11-27 15:48:02 +01:00
Vadim Zeitlin
c02738270b Rename cxx_wrappers::f_fwd_decls to f_types
This section will contain other types declarations too soon, so rename
it in preparation for it.

No real changes so far.
2021-11-27 15:40:47 +01:00
Vadim Zeitlin
55dc976b9f Use "noexcept for internal ctor and special move operators
No real changes, but just make the trivial non-throwing members
explicitly noexcept.
2021-11-27 15:35:39 +01:00
Vadim Zeitlin
aa0df5faa0 Make swig_check() inline as it should have always been
Fix link errors when including the generated header from more than one
translation unit.
2021-11-27 01:03:12 +01:00
Vadim Zeitlin
c3b262c2f7 Merge branch 'master' into C
Merge with the latest master to resolve (trivial) conflict in the
GitHub workflow file.
2021-11-27 00:20:19 +01:00
Vadim Zeitlin
38b76bb7c6 Make global SWIG_CException::PendingException thread-local
This allows different threads to use the same library concurrently
without corrupting each other's exceptions.

Note that this requires C++11 support for wrapper compilation too. If
this really turns out to be a problem, we could always just #define
thread_local as compiler-specific equivalent such as "__thread" for gcc
or "__declspec(thread)" for MSVC, which are available since forever.
2021-11-27 00:19:05 +01:00
Vadim Zeitlin
c7fa9126ce Use a unique prefix for SWIG_CException_Raise()
This allows using different modules generated by SWIG in the same
process without conflicts.
2021-11-27 00:19:05 +01:00
Vadim Zeitlin
9dd1301ec4 Improve the fix for exceptions support with multiple modules
The approach of the parent commit almost worked, but broke down if the
main module itself redefined typemaps for SWIGTYPE, as this broke
generation of SWIG_CException wrappers when we finally did it at the
end.

This probably could be salvaged by explicitly defining the typemaps for
SWIG_CException itself and also "int" and "char*", used for its
functions, but this just seems too fragile so switch to a different
approach instead: examine the parse tree immediately when starting
generation to check if it contains any %imports, and decide whether we
need to generate exceptions support in this module based on this.

New version seems more robust and easier to understand, and is probably
not noticeably slower.

Still keep the one in the previous commit just in case we need/want to
return to it later -- but keep in min the typemap redefinition problem
described above if we do it.
2021-11-27 00:19:05 +01:00
Vadim Zeitlin
727a65c0e8 Fix using exception in modules importing other modules
Ensure that we have only a single SWIG_CException_Raise() function
across all modules instead of having per-module functions and, worse,
per-module PendingException variables, which resulted in compile-time
errors and couldn't work anyhow because function checking for the
current exception didn't necessarily use the same "global" variable
where it was stored. More formally, old version resulted in ODR
violations and undefined behaviour.

The way we avoid it now is rather ugly and consists in excluding
SWIG_CException from wrapping using the hack in the source code which
postpones wrapping this class until the very end and checks if we had
encountered any %import directives and simply doesn't wrap it if we did.

The same code is used to define the special SWIG_CException_DEFINED
preprocessor symbol which is then used in the generated code to prevent
the SWIG_CException class declaration from being compiled as part of the
wrapper too (because this still happens due to %inline being used for
its definition, and there doesn't seem to be any better way to avoid
this).

This is definitely not pretty, but at least adding "throw(char*)" to a
couple of functions in mod_[ab].i test suite files works now instead of
failing (even without linking and running) as before. This commit
doesn't modify the test suite to avoid possible problems with the other
languages, however.
2021-11-27 00:19:05 +01:00
Vadim Zeitlin
9a8ebbb998 Throw SWIG_CException from C++ wrappers automatically
Check for the pending exception after every call to a wrapper function
not marked "noexcept" and throw a C++ exception if necessary.

Add C++ version of the exception example to show how this works.

Also change SWIG_CException to use member functions for checking for and
resetting pending exceptions, this seems better than having separate
functions for it and will make it easier to customize exception handling
later by just replacing SWIG_CException class with something else.

Note that we still use a global (and not a member) function for raising
the exception, but this one is not exported at all, and needs to be a
function in order to be easily callable from other modules (see the
upcoming commit).
2021-11-27 00:19:05 +01:00
Vadim Zeitlin
52f8412a46 Simplify importDirective() code
Don't bother finding the "top" node when we can just save the contents
of its "outfile_h" attribute in top(), where we already use it (and we
already save the module name).

No real changes, just make the code simpler and marginally faster.

This commit is best viewed ignoring whitespace-only changes.
2021-11-27 00:19:05 +01:00
Vadim Zeitlin
17fbb0a528 Include required headers for %imported modules
We need the types from the imported modules, so #include the header
generated for it.

Unfortunately we have to half-guess the name used for that header, as
it's not available anywhere (and can't really be, as it could be changed
by a command line option used for another SWIG invocation that was used
to compile that module), but this seems to work well enough in practice.

In particular, this fixes failures in multi cpp tests, so that we don't
need FAILING_MULTI_CPP_TESTS any longer.
2021-11-27 00:19:05 +01:00
Vadim Zeitlin
f7f59f4648 Rename module_prefix to just module_name
It is used as a prefix, but it's really just the name of the module, so
the new name is less confusing.

There also doesn't seem to be any need to copy/delete it, just keep a
pointer, it's not going to change.

No real changes.
2021-11-27 00:19:05 +01:00
Vadim Zeitlin
43c7aefeb1 Don't leak namespace prefix variable
No real changes, just delete a local variable.
2021-11-27 00:19:05 +01:00
Vadim Zeitlin
f42b0eaa71 Use different executable names for C and C++ examples
Trying to create the same "runme" executable for both C and C++ examples
could result in errors when using parallel make, as one of the targets
could fail to write to the file being currently executed.

Using separate names works around this problem.
2021-11-27 00:19:05 +01:00
Vadim Zeitlin
d2546e23ff Don't use exception specification with C++ compiler in example
Support for the exception specifications using types was removed in
C++17 (and "throw ()" in C++20), so don't use them when using the C++
compiler any longer, as this broke the example with recent g++ versions
that use C++17 by default.

We still need them for SWIG, however, so use SWIG_THROW macro, defined
differently for SWIG and the compiler, to preserve the existing
behaviour.

Using %except might be a better idea, but would require more changes.
2021-11-24 20:16:42 +01:00
Vadim Zeitlin
43276f22a7 Enable testing some C++ wrappers code in the test suite
C++ wrappers still don't compile for about a hundred tests, but they do
compile for almost 500 more of them, so it's still valuable to be able
to check that there are no regressions for those that do work now.
2021-11-24 02:41:33 +01:00
Vadim Zeitlin
adb96f8b7a Always pass wrapper objects by const reference in C++ wrappers
Passing them by value doesn't seem to have any advantages, as the copy
will be made internally anyhow if the original function took them by
value and doing an extra one doesn't seem necessary, but does have a big
drawback of not compiling if the class doesn't define a copy ctor.
2021-11-24 02:41:33 +01:00
Vadim Zeitlin
3f3438093d Define move ctor and assignment operator for C++ wrappers
This can be done naturally and there doesn't seem to be any reason not
to do it.
2021-11-24 02:41:33 +01:00
Vadim Zeitlin
79e9d43c1b Disable broken default-generated copy ctor in C++ wrappers
We can't rely on the default-generated copy ctor because it simply
copies the (possibly) owned pointer, resulting in double destruction if
it's ever used, so disable it completely unless it is explicitly
declared in the original class, in which case we can wrap it using the C
function wrapper defined for it.

Note that we probably should also wrap default-generated copy ctor of
the original class, if it has any, but currently we don't do it even at
C wrappers level, and so can't do it for C++ wrappers neither.
2021-11-24 02:41:33 +01:00
Vadim Zeitlin
03c6099ac1 Define "classname" in cxx_class_wrapper dtor too
No changes, just a tiny refactoring before the upcoming commit.
2021-11-24 02:41:33 +01:00
Vadim Zeitlin
8d1fbbacb3 Use correct base class C proxy name even if it's not set yet
Replace C::getProxyName() with global get_c_proxy_name() and use it in
cxx_class_wrapper rather than relying on "proxyname" attribute being
already set because this might not be the case if the base class is
defined in another SWIG module just %import'ed from the current one: in
this case, the class is known, but no wrappers had been generated for it
yet, so "proxyname" for it is not set.

Note that, unlike getProxyName(), the new function doesn't bother with
always copying the string, as we may be sure it remains valid as it's
referenced by the node, as one of its attributes.
2021-11-24 02:41:33 +01:00
Vadim Zeitlin
b0c9991164 Separate forward declarations and implementations of C++ wrappers
This allows the generated code to compile when different classes depend
on each other, as the class must be forward-declared to be mentioned at
all (as either parameter or return type) and fully defined in order to
be used in either role, as we need to use its ctor or call swig_self()
on it.
2021-11-24 02:41:33 +01:00
Vadim Zeitlin
a13da1f8a9 Refactor code to use cxx_wrappers struct
No real changes, just prepare for adding more File objects to be used
for C++ wrappers generation: we can't generate all of them in a single
pass because there may be dependencies between classes.
2021-11-24 02:41:33 +01:00
Vadim Zeitlin
a980c036d6 Fix $typemap expansion for C++ wrappers
This required slightly changing the approach used for resolving types in
emit_member_function(), as we can't resolve the type and the casts
to/from it independently any more, but need to do both at once, as this
is required when it's done indirectly due to $typemap() expansion, and
we can't make "return" part of the returned wrapper as we could end with
multiple "returns".

So replace expr_wrapper with type_desc containing both the wrappers and
the type itself and add "return" in emit_member_function() itself for
non-void functions. Also use IIFE so that we can always just prepend
this "return" in the beginning.

Also connect things up so that C++-specific type resolution function is
used while C++ wrappers are being generated.
2021-11-24 02:41:33 +01:00
Vadim Zeitlin
e78f5dac45 Add temp_ptr_setter and use it with cxx_class_wrapper
The new helper class will be also useful in other places, so extract it
from cxx_class_wrapper.

No real changes, this is just a refactoring.
2021-11-24 02:41:33 +01:00
Vadim Zeitlin
7c6fb542d3 Convert li_boost_shared_ptr runtime test to C++ from C
It's simpler to write tests in C++ rather than C and checking the
generated C++ API also checks the C API it uses underneath, so there is
no need to have both.
2021-11-23 01:29:26 +01:00
Vadim Zeitlin
c434b867d7 Strip namespaces from parameter types
This fixes e.g. li_boost_shared_ptr unit test, which uses Space::Klass
that should be known as just Klass (inside the outer namespace) in the
generated C++ wrappers.
2021-11-23 01:29:26 +01:00
Vadim Zeitlin
036e3eb08c Correctly skip ignored base classes in C++ wrappers
Don't refuse to generate C++ wrapper class if there is just one real
base class and the other one(s) are ignored.
2021-11-23 01:29:26 +01:00
Vadim Zeitlin
0483e4017c Start adding C++ wrappers generation
Disable them for the test suite, as plenty things don't work yet, but
there is already more than enough code to not want to add even more
fixes to the same commit.
2021-11-23 01:29:26 +01:00
Vadim Zeitlin
606c1c6ea0 Make sure gcc gives error for passing scoped_dohptr to Printv()
After making this mistake too many times already, make sure it doesn't
happen again by requiring gcc to give an error for any attempt to pass
a non-trivial object to vararg functions such as Printv(), Printf(),
Swig_error() etc.
2021-11-21 16:42:11 +01:00
Vadim Zeitlin
7cbbfab198 Show using C++ wrapper API for the "class" example
This almost exactly mirrors the existing C examples, but modify both
examples slightly to make their output show which language is used.
2021-11-19 02:04:41 +01:00
Vadim Zeitlin
55d7db6b27 Get rid of an unnecessary intermediate string
Write the wrapper types and declarations directly to f_wrappers_h,
without passing by an intermediate f_wrappers_h_body which just
complicated things unnecessarily.

This means that "extern "C" { ... }" is now around the functions
declarations only, and not around the types and the declarations, but
this seems like a desirable side effect.

No real changes.
2021-11-19 00:08:44 +01:00
Vadim Zeitlin
8d1faa5b3b Rename various files used in C backend code
Also explain better what each of them is used for and use scoped_dohptr
instead of deleting them manually.

Stop writing everything to f_begin, which didn't make any sense, and use
a separate f_wrappers_cxx object for the contents of the cxx output file.

No real changes.
2021-11-19 00:08:44 +01:00
Vadim Zeitlin
2454efb989 Use Dump() instead of Wrapper_pretty_print()
This should be faster and we don't really need to prettify the wrappers
code which is already quite decent.
2021-11-19 00:08:44 +01:00
Vadim Zeitlin
afc02cbc01 Remove unused f_wrappers_cxx
This variable wasn't used since a long time and removing it doesn't
affect generated code.
2021-11-19 00:08:44 +01:00
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
0f734e1164 Don't generate empty enum declarations
They are invalid in C++ and there shouldn't actually be any in valid
input, but they do occur in SWIG test suite.

Don't generate anything for them in the output, especially because doing
this is not really more complicated than using "enum_is_empty" field
that we had previously and might even be a tad simpler, as it doesn't
split the "{" and "}" output between two different functions.
2021-11-19 00:08:43 +01:00
Vadim Zeitlin
e7fa72fc06 Don't generate invalid forward enum declarations
Such declarations are invalid without specifying the underlying type
(which is only possible since C++11) and are useless anyhow, so just
don't bother emitting them.
2021-11-19 00:08:43 +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
11bd97653f Inline functions used only once in functionWrapperCPPSpecific()
No real changes, just keep everything in a single function because it is
more clear than having both it and functionWrapperCPPSpecificWrapper()
doing the same thing.
2021-11-10 00:53:39 +01:00
Vadim Zeitlin
2f4a09fb21 Avoid calling getFunctionWrapperName() twice for each function
Pass the wrapper name to emit_wrapper_func_decl() to save on an extra
call to this function.

No real changes, this is just an optimization.
2021-11-10 00:53:39 +01:00
Vadim Zeitlin
fbf976768a Get rid of "c:globalfun" attribute
Use getCurrentClass() and other existing attributes to check if the
current node is inside a class or not (and hence is global), this is
more explicit and avoids confusion for static member functions that were
marked as being global in spite of being nested inside a class.
2021-11-10 00:53:39 +01:00
Vadim Zeitlin
8594a8def6 Use SWIG-specific suffix for non-overloaded %extend functions too
This avoids conflicts between functions synthesized by %extend when
adding static methods to an existing class, and the actual wrapper
functions generated by the backend.

This shouldn't result in any user-visible changes.
2021-11-10 00:53:39 +01:00
Vadim Zeitlin
70309fcb0a Refactor code in Language::staticmemberfunctionHandler()
No real changes, just move the test for "code" to the outer scope to
facilitate the upcoming changes.

This commit is best viewed ignoring whitespace-only changes.
2021-11-10 00:53:39 +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
54af856d09 Fix typemaps for arrays of objects and object pointers
These typemaps never worked, but this went unnoticed until now because
the nonsensical "ctype" expansion generated by them still compiled.

With types possibly having a namespace prefix, they didn't any longer,
so define them correctly for the objects using "$resolved_type" and
define the typemap for "void*[]" separately, as "$resolved_type" can't
be used for it.
2021-11-10 00:53:39 +01:00
Vadim Zeitlin
5bf1497d7b Allow customizing type mangling in SWIG preprocessor
Use the "type" naming format for the types mangled by "#@" and "##@"
preprocessor operators, in order to allow customizing them for a
particular backend.

This isn't used by any backend yet, so this doesn't change anything so
far.
2021-11-10 00:53:39 +01:00
Vadim Zeitlin
cda93bd903 Fix enum value translation
Don't rely on hack with checking the value length and looking it up,
just check its type instead.
2021-11-07 02:29:01 +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
81d1fec13c Remove code setting unused "c:retval" attribute
This became unused after the changes of fd3e76365 (Streamline and fix
returning objects by value, 2019-08-06) and allows to simplify code
further as we don't need to override static and non-static member
function handlers at all any more now.
2021-11-04 01:31:06 +01:00
Vadim Zeitlin
ec4cfd41de Return scoped_dohptr from get_wrapper_func_return_type()
Ensure that the returned pointer is deleted automatically instead of
doing it manually.
2021-11-04 01:31:06 +01:00
Vadim Zeitlin
07e7086b39 Generate wrapper function name in a single place
Rename getGlobalWrapperName() to getFunctionWrapperName() and make it
work for all functions, not just global ones.

This means that we can test whether the function is global or not in a
single place instead of doing it in two different ones.
2021-11-04 01:31:06 +01:00
Vadim Zeitlin
7e5e6a4cf0 Avoid unnecessary allocations of function name
Use maybe_owned_dohptr in function wrapper code to avoid making a copy
unnecessarily just to be able to Delete() this pointer later.

No real changes.
2021-11-04 01:31:06 +01:00
Vadim Zeitlin
4801a3154e Delete never used variables in function wrapper code
No real changes, just don't bother allocating and deleting strings that
are never used at all.
2021-11-04 01:31:06 +01:00
Vadim Zeitlin
ad3db88e44 Add maybe_owned_dohptr helper
This class allows to avoid allocating a new DOH object unnecessarily if
we can reuse an existing one.

It is not used yet, but will be soon.
2021-11-04 01:31:06 +01:00
Vadim Zeitlin
ca56f14aa5 Refactor scoped_dohptr() to reuse its reset()
No real changes, just avoid some code duplication and add an optional
argument to reset() to make it more compatible with std::unique_ptr<>
and also more flexible.
2021-11-04 01:31:06 +01:00
Vadim Zeitlin
8014af974d Revert accidental change to Python example
This was done way back in f84342a30 (Modified parameter handling using
typemaps. 'Reference' example. Visibility hint now applies only to the
global functions., 2008-06-28), surely accidentally.
2021-11-04 01:31:06 +01:00
Vadim Zeitlin
63a229a40f Don't disable experimental warning for C in GHA workflow any more
This is not necessary any longer after the previous commit and is better
than setting SWIG_FEATURES in the workflow file, as this resulted in
showing "-w524" in the name of C CI build since the changes of 04a6ad3bb
(Add SWIG_FEATURES into GHA name, 2021-10-21), which was a bit ugly.
2021-11-02 17:51:14 +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
080d3075e3 Rename getNamespacedName() to getProxyName()
This is a more logical name for this function, as it caches its return
value in "proxyname" attribute and doesn't really have much to do with
namespaces.

No real changes.
2021-10-30 21:11:02 +02:00
Vadim Zeitlin
0434b93cc9 Rename getProxyName() to getClassProxyName()
Show that this function only returns non-null result for classes, as
this was not at all obvious before.

No real changes.
2021-10-30 21:09:41 +02:00
Vadim Zeitlin
d7f06c3721 Reuse Swig_string_mangle() instead of using Replaceall()
Use the same function in getNamespacedName() which was already used in
getGlobalWrapperName() just below, this is more readable and more clear
than just replacing dots with underscores as we did before.

Also use scoped_dohptr instead of manual Delete() calls.

No real changes.
2021-10-30 18:51:19 +02:00
Vadim Zeitlin
1fb0de9e00 Don't call Swig_scopename_prefix() unnecessarily
No real changes, just make the code do what the comment said it did and
only use the namespace as prefix when "nspace" feature is on instead of
always trying to use it as prefix and then resetting it.

This required adding default ctor and assignment operator from raw
pointer to scoped_dohptr, but they can be useful elsewhere too, while
the actual code in getGlobalWrapperName() is simpler and more readable
now.

No real changes.
2021-10-30 18:47:12 +02: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
d65d7d7df3 Make SWIGIMPORT definition more consistent with SWIGEXPORT
Use the same checks as for the definition of SWIGEXPORT in
swiglabels.swg.

Also avoid defining __DLL_IMPORT symbol with a reserved name.
2021-10-20 01:57:18 +02:00
Vadim Zeitlin
e41234c5bc Inject just the relevant part of changes.swg in generated code
Don't include the entire file, including its header comment, into the
generated code, but just the part that we want to appear there.

This looks nicer and is also more explicit and hence clear.
2021-10-15 23:16:42 +02:00
Vadim Zeitlin
e45d8f94fc Link C modules with libpthread under Unix systems
Specify -pthread option which should be universally supported under
non-{MSW,Mac} platforms by now and which is required under Linux to link
the tests using boost::shared_ptr<>, which uses pthread_mutex_xxx().
2021-10-15 23:02:39 +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
d77e5d8b0e Enable C++11 testing for C backend
Not all C++11 tests pass, but some (and important ones) do, so do check
them.
2021-10-15 00:59:34 +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
5cbdae42d3 Revert "Use std/std_vector.i instead of a poor copy in c/std_vector.i"
This reverts commit d89a95a48c as,
finally, it's not worth trying to use UTL typemaps from C: this required
bad hacks for std::vector and would be even worse for std::map, so don't
bother with them and just correct the "poor" C typemaps to be slightly
less poor and use them instead.
2021-10-07 22:03:47 +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
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
e1815634ec Clean the generated headers for C too
This fixes a check-maintainer-clean problem.
2021-10-05 01:34:32 +02:00
Vadim Zeitlin
5bbaecfb81 Set LD_LIBRARY_PATH when running C examples too
This is needed to find the SWIG-generated shared library when using C
too, as it's already the case for many (but, surprisingly, not all)
other target languages.
2021-10-05 01:01:37 +02:00
Vadim Zeitlin
d2e3cce7d4 Avoid -Wformat warnings in C std_vector example
Use "%zd" for printing size_t values rather than "%d".
2021-10-05 00:57:45 +02:00
Vadim Zeitlin
03b6e2fbe6 Don't use SWIG_exit() in C examples
There doesn't seem to be any reason for using it rather than just
returning from main() as usual, and it provokes warnings about
implicitly declared function when compiling them.
2021-10-05 00:26:12 +02:00
Vadim Zeitlin
86205e86e3 Disable warnings about C backend being experimental in CI builds
These warnings are perhaps useful for the SWIG end users, but not really
in the CI build logs, where they just create noise and are distracting.
2021-10-05 00:23:20 +02:00
Vadim Zeitlin
52bd63b31d Test C backend in GitHub CI workflow 2021-10-04 22:17:06 +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
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
ac4f3c78be Merge branch 'master' into C
Merge with the latest master before making more changes.
2021-10-04 16:03:36 +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
8eda01fd75 Get rid of extra unnecessary blocks in common typemaps
Use "..." instead of "{...}" to avoid generating extra lines with
opening/closing curly braces, which are completely unnecessary.

Also remove an unnecessary "if" check in "in" typemap, which was
useless.

No real changes.
2019-08-06 00:24:07 +02:00
Vadim Zeitlin
70bc33a3be Add support for "$owner" expansion in "out" typemaps
This is going to be used for the upcoming shared_ptr<> support.
2019-08-05 20:43:09 +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
2d13e18d07 Allow reassigning scoped_dohptr
Not being able to do it is too restrictive in practice and just forces
to use raw DOH pointers, which is not really less dangerous than adding
the assignment operator and reset() method to this class.
2019-08-05 14:44:47 +02:00
Vadim Zeitlin
649a1c3c98 Provide trivial SWIG_exception definition even in C mode
This is not really useful, but gets rid of an annoying warning when
running li_constraints.ctest unit test.
2019-08-05 14:15:18 +02:00
Vadim Zeitlin
bd02ba19d8 Fix getNamespacedName() and reuse it for enum
There doesn't seem to be any unit tests covering this, but the old code
was wrong because it didn't replace periods used as namespace separators
with underscores, which resulted in periods appearing in the output when
nested namespace were used.

Fix this and also reuse the now fixed getNamespacedName() in
getEnumName() which contained its own buggy version of the same code.
2019-08-05 02:23:52 +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
ba564d4e4e Fix memory leak of getProxyName() return value
This is done not so much to fix the memory leak per se (as there are
gazillions of other ones remaining), but to show that the return value
of getProxyName() does need to be freed, as this was unclear previously,
with it being freed in one place where this function was used, but not
in the other one, here.

Also state this explicitly in the function comment.
2019-08-05 01:37:46 +02:00
Vadim Zeitlin
8f1b9dbbc5 Improve constants handling
Handle char constants defined using #define or %constant correctly.

Also handle static member const variables, which didn't work at all
before, and quote values of such variables of char type.
2019-08-04 17:47:54 +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
ef77cefd8d Rename operator() for C in functors unit test
This ensures that these operators are actually wrapped, instead of just
being ignored with warnings.
2019-08-04 17:45:59 +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
9615021a91 Micro optimize handling of prefix in get_mangled_type()
Don't bother with a bunch of Replaceall() calls if the prefix is empty
to begin with, which is commonly the case.

No real changes.
2019-08-04 17:09:57 +02:00
Vadim Zeitlin
579c441aa9 Get rid of rather useless "goto" statement in get_mangled_type()
It's not significantly simpler to use "goto" in this function, so just
replace it with "return".

Also remove the unnecessary checks for strings being deleted being
non-null, as they always are.

No real changes.
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
fb0579a0df Simplify SWIGTYPE "in" typemap
There is no need to check if the input is non-null, as the effect of
both branches of "if" is the same anyhow.

Also get rid of an extra and unnecessary block.

No real changes.
2019-08-04 15:23:35 +02:00
Vadim Zeitlin
61e13eb42b Get rid of useless IS_SET_TO_ONE macro
Just use the standard GetFlag() instead.
2019-08-04 14:59:48 +02:00
Vadim Zeitlin
d1f8d46528 Fix some very wrongly indented lines and "else" style
Consistently put "else" on the same line as closing "}" from the
matching "if", if any.

No real changes.
2019-08-04 14:57:08 +02:00
Vadim Zeitlin
92c922c841 Remove trailing whitespace
No real changes.
2019-08-04 14:57:08 +02:00
Vadim Zeitlin
0599b77377 Remove useless overridden extendDirective()
There is no need to override it just to call the base class version.

Also remove the outdated comment, as %extend is supported currently
(albeit with some bugs remaining).

No real changes.
2019-08-04 14:57:08 +02:00
Vadim Zeitlin
7bef0b704d Remove unnecessary "virtual" keywords
Don't mark functions not intended to be overridden (nor overriding those
in the base class) as "virtual", this is useless and confusing.

No real changes.
2019-08-04 14:57:08 +02:00
Vadim Zeitlin
83e9d50763 Remove unused C::int_string field
This was simply never used at all.
2019-08-04 14:43:02 +02:00
Vadim Zeitlin
290f49a2c1 Remove unused C::tl_namespace member
This was never set to anything, so just drop it.
2019-08-04 14:41:29 +02:00
Vadim Zeitlin
d9b3453763 Add missing SWIGIMPORT to function declarations
This went unnoticed under Linux, but would have resulted in link errors
for all functions under MSW.
2019-08-04 14:33:34 +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
bbac8ca521 Don't reimplement base class version of globalfunctionHandler()
This is useless and the C-specific version didn't handle template
methods added with %extend correctly, so removing this code also fixes
some (but not all yet) failures in extend_template_method.cpptest unit
test.
2019-08-03 14:40:09 +02:00
Vadim Zeitlin
b0d99a1cc3 Don't emit functions added by %extend into C structs
This is never going to work and just results in generating uncompilable
code.

In principle, we could either generate wrappers for these functions
while still handling the struct as a plain C struct, or switch to
generating class-like wrappers for it if it's %extended with any
functions, but for now just ignore them as this is the simplest thing to
do.

Incidentally, this makes the default_args_c test pass again now, after
the last merge with master pulled in such %extend directives into it.
2019-08-03 02:37:18 +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
fe5f367709 Show "C" in the list of languages at the end of configure
If C module wasn't disabled, show that the tests and examples will be
available for it too.
2019-07-24 20:35:42 +02:00
Vadim Zeitlin
55741f9e31 Merge branch 'master' into C 2019-07-24 20:26:50 +02:00
Vadim Zeitlin
93ca7451e6 Also remove SWIGTYPE*& typemaps for C
They seem unnecessary too and look suspicious, notably the use of "static" in
the "out" typemap is almost certainly wrong.

As all the tests still pass without them, don't bother fixing these typemaps
but just remove them completely.
2016-09-15 01:46:28 +02:00
Vadim Zeitlin
7a6edf8b82 Remove nonsensical typemaps for SWIGTYPE**
It's not clear why they were defined in the first place, but they broke
li_std_vector_ptr unit test, which now uses "T**", after the latest merge with
master, so just remove them to let the test pass again.
2016-09-15 01:41:20 +02:00
Vadim Zeitlin
f919896306 Merge branch 'master' into C 2016-09-15 01:30:49 +02:00
Vadim Zeitlin
9204e57cc1 Fix $typemap() expansion for "ctype" typemap
This didn't work correctly before because we need to override the base class
replaceSpecialVariables() method to expand $resolved_type, which appears
during the expansion, using the type supplied as $typemap() argument instead
of doing it later using it the type to which the typemap containing the macro
is attached.

This is a prerequisite for implementing smart pointers support.
2016-09-15 01:27:42 +02:00
Vadim Zeitlin
2f4eb2d412 Replace output_target parameter with global current_output
This will allow implementing replaceSpecialVariables(): as it is called from
inside the typemap lookup code, we can't pass any parameters to it directly,
but we can use a class language-global member variable to it indirectly.

No real changes yet.
2016-09-15 01:27:42 +02:00
Vadim Zeitlin
dcda566ce6 Remove unnecessary memory allocation from substituteResolvedType()
Don't allocate memory just to leak it, SwigType_typedef_resolve_all() already
returns a copy we can use.
2016-09-15 01:27:42 +02:00
Vadim Zeitlin
bf71891197 Just get rid of an unnecessary variable
Simplify the code by avoiding a superfluous extra variable.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
0353317a21 Remove substituteResolvedType() return value as it is unused
It doesn't matter if this function did anything or not as its output parameter
is always used anyhow by the caller.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
ad5de803b5 Avoid unnecessary allocation in get_wrapper_func_return_type()
Don't call NewString() just to overwrite it with another pointer (and leak the
one allocated by NewString()).
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
11426ac1cd Drop code dealing with tmap:ctype:out which is never used
This typemap attribute is not used with C (so far), there is no point in
checking for it in the code.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
6e0e728a14 Refactor node copying in C::classHandler()
Don't create a new node just to delete it if we don't need it, but rather only
create it if we do need it.

Also copy as much as can be copied in copy_node() helper, it was confusing to
copy part of the attributes in it and part in the caller. And one of them
("c:inherited_from") was even copied twice, it was first created in the
function and then unconditionally overwritten by the caller -- don't do this
any more.

No real changes.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
2ce15d3e6a Don't leak a Node in C::classHandler()
Delete the copied node if we end up not using it.
2016-09-15 01:27:41 +02:00
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
65d9cad1ca Don't force inheritance of ignored methods
If a symbol is ignored in the base class, it shouldn't appear in the derived
class neither.
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
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
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
8fa28e0ce9 Don't lose the correct sym:name when inheriting base class methods
For some reason, the copy of the function made in the derived class used the
"name" attribute instead of "sym:name", which means that any %renames attached
to it were lost and didn't affect the derived class version.

Fix this and also a problem uncovered by doing it in the operator_overload
unit test as the assignment operator shouldn't be inherited at all, the
compiler-generated operator is used instead if the derived class doesn't
define its own one.
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
0c936d9089 Simplify and inline functionWrapperAddCPPResult()
This function seemed to be doing a few unnecessary things, e.g. it resolved
the typedefs which doesn't seem to be necessary and the test for member
pointer seems to be useless too.

Just add a local "cppresult" directly in the caller instead of using a
separate function to do all this.
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
d3412499bb Use the original function name in C code wrappers
Using "sym:name" in the wrapping code is wrong, it is different from "name" if
the function has been renamed and we need to call the original C function, not
whichever name it is exported under.
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
b24665fa6a Add names of the functions being wrapped to symbol table
At the very least this results in clear error messages when running SWIG if
the symbol is encountered twice instead of errors given only when compiling
the generated code later.
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
7f4549a0f3 Ensure that we define bool before using it for variables
It would have been better to hook into the fragment machinery, but for now do
it directly to make sure the generated code compiles.
2016-09-15 01:27:39 +02:00
Vadim Zeitlin
5fd1f28477 Do not export static global variables at all
They shouldn't be exported and can't be when using shared libraries.
2016-09-15 01:27:39 +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
97fc60ef51 Get rid of c:objstruct attribute
The only remaining use of this attribute is to test for whether we're wrapping
a ctor and it is simpler and more clear to just check the node type directly
in this case.

This attribute was pretty confusing as it was used for parameters and entire
declarations, so removing it makes things more clear and simpler.
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
0480694a7a Remove the now unused functionWrapperCPPSpecificMarkFirstParam()
There is no need to set c:objstruct for the first parameter of the methods now
that we take care of it for disambiguating between overloads explicitly and
this function doesn't seem to be useful for anything else, simply drop it.
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
Vadim Zeitlin
2e3b427b7e Get rid of unnecessary and confusing c:stype attribute
We can just use "type" directly, there is no need for any C-specific stype.
2016-04-21 18:58:33 +02:00
Vadim Zeitlin
2c65b4db5b Remove obsolete RCS ID line
No real changes.
2016-04-21 18:58:33 +02:00
Vadim Zeitlin
02c52331cd Return scoped_dohptr from get_wrapper_func_proto()
This ensures that the pointer is not leaked.

Unfortunately it requires adding a dangerous, std::auto_ptr<>-like destructive
copy ctor to scoped_dohptr<>, but there is no better solution without C++11.
2016-04-21 18:58:33 +02:00
Vadim Zeitlin
e2738ad524 Refactor: add parentheses in get_wrapper_func_proto() itself
Return the prototype strings already surrounded by parentheses instead of
having to add them in the caller.

No real changes.
2016-04-21 18:58:33 +02:00
Vadim Zeitlin
c971919e2f Merge almost identical code generating wrapper function arguments
Reuse get_wrapper_func_proto() for the wrapper function definitions too, this
cuts down on the amount of duplicated code and also ensures that declarations
and definitions match.
2016-04-21 18:58:33 +02:00
Vadim Zeitlin
00ef2c4c7d Remove unused functionWrapperCPPSpecificProxyWrapperCallGet()
This is identical to the main part of functionWrapperCPPSpecificWrapper() now
and it is not used anywhere.
2016-04-21 18:58:33 +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
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
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
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
41d46460b8 Add helper scoped_dohptr class
This is useful for avoiding having to explicitly write Delete() calls for DOH
objects.
2016-04-21 01:37:42 +02:00
Vadim Zeitlin
113ce5ae7d Add a blank line to the generated code
This is purely cosmetic: add an extra blank line after the __cplusplus ifdef
end.
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
d9feedc37a Remove unnecessary SwigType_typedef_resolve_all() call
No real changes, just don't bother calling SwigType_typedef_resolve_all()
before calling classLookup() because the latter already does it anyhow.
2016-04-21 01:37:41 +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
4c654d9369 Give an error if unsupported type is encountered
This is better than silently generating completely wrong code with
$resolved_type in it and makes it easier to understand what exactly went wrong
and where.
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
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
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
19268d0865 Add check-failing target to check that failing tests still do fail
This is useful to remove the tests which pass after the latest fixes from the
list of the failing tests.
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
Vadim Zeitlin
af9dd72bb6 Fix function name in cpp_basic_template_function test
Use "_wrap_" prefix to make the test compile and pass.
2016-04-21 01:37:40 +02:00
Vadim Zeitlin
2edbbfd87f Fix cpp_basic_global_var_built_in unit test
Use the correct header name in it and remove it from the list of the failing
tests.
2016-04-21 01:37:40 +02:00
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
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
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
208980f4de Avoid gcc warnings for nested anonymous enums in the generated code
Output anonymous enums defined inside C structs in the global scope, this
doesn't change the semantics as the constants defined inside a struct still
have global scope in C, but avoids gcc warnings given when compiling the
generated code.
2016-04-20 18:46:12 +02:00
Vadim Zeitlin
6813c7eacf No changes, just write emit_c_struct_def() in a more natural way
Don't force the caller to pass firstChild() of the struct node to this
function, just pass it the struct node itself and iterate over all of its
children inside it.
2016-04-20 18:46:12 +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
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
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
c73acc44a7 Show the number of passed tests in "make check"
This is especially useful when some tests are disabled by using
FAILING_XXX_TESTS variables.
2016-04-20 01:53:23 +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
200ea0e37d Don't output "decl" attribute into the wrapper declarations
This doesn't make any sense as "decl" is a SWIG type string and not a C
declaration.
2016-04-18 20:30:49 +02:00
Vadim Zeitlin
1f6ce1ed64 Reuse existing wrapper declarations code for C functions too
We just copied the function prototype without any changes from the original C
function to the wrappers header when in C mode, but this wasn't correct, e.g.
the original function could use typedefs not available in the wrapper.

Fix this by applying the typemaps in C mode too, but without the C++-specific
parts.

This also makes C and C++ code paths slightly less different from each other,
the long-term goal is to make them identical.
2016-04-18 20:30:49 +02:00
Vadim Zeitlin
c4036fdc58 Fix handling of forward-declared enums
Don't output the enum body if it just forward-declared, empty enums are
invalid in C.
2016-04-18 01:09:29 +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
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
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
dbb9cc250c No real changes, just narrow scope for a variable
Initialize "baselist" just where it is needed.
2016-04-16 00:10:47 +02:00
Vadim Zeitlin
4995e96009 Fix double delete in C mode resulting in crashes later on
This was broken by f1ec1a26 which removed a call to Copy() but not the
matching call to Delete().
2016-04-16 00:10:22 +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
f9a2d81f29 Use a constant for the indentation in the generated C code
Instead of hard coding two spaces, use "cindent" constant to make it more
clear what is the intended indentation of the generated code and also to make
it possible to change it later easily if desired.
2016-04-16 00:10:20 +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
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
8ff7941503 Don't generate delete functions if dtor is not accessible
This fixes failures in virtual_dtor and using_protected unit tests.
2016-04-15 23:01:20 +02:00
Vadim Zeitlin
4962871cd9 No real changes, just remove an unused variable
"sobj" in C::classHandler() was not used at all.
2016-04-14 02:44:46 +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
2a37e53b62 Remove abstract_access from broken tests
It passes now with C backend.
2016-04-14 02:44:46 +02:00
Vadim Zeitlin
62230758e4 Output declarations of all types before the functions declarations
This fixes compilation of the generated code when a function uses a forward
declared type as was the case in e.g. std_vector example.
2016-04-14 02:44:46 +02:00
Vadim Zeitlin
795e3adb0d Use CFLAGS when compiling test code for C module tests
This is useful to pass e.g. CFLAGS=-g on make command line.
2016-04-14 02:44:46 +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
a1fedd5202 Minor cleanup: remove commented out code
No real changes, just remove commented out code and comments that didn't make
sense.
2016-04-13 18:10:36 +02:00
Vadim Zeitlin
5cfb66c1fb Remove unused functionWrapperCPPSpecificWrapperSetReturnType()
This function was never used anywhere since its addition back in
f1ec1a26a7.
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
Vadim Zeitlin
34431d72e6 Create output file with C++ extension for C++ C examples
This file contains C++ code when using "swig -c++", so create it with .cxx
extension.
2016-04-13 18:10:35 +02:00
Vadim Zeitlin
23d89c2cb4 Make "make check-c-version" work too
This is not very useful, but still add this target for consistency and to make
Travis CI script work with C too.
2016-04-13 18:10:35 +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
1af8e25d4d Add a possibility to disable failing test cases
Allow defining FAILING_{C,CPP,MULTI_CPP}_TESTS variables to exclude some tests
from the unit tests suite. This is useful to disable tests failing for some
language only.
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
Vadim Zeitlin
19ed0b531d Fix and simplify C examples makefiles
Make "make check-c-examples" perform the correct build commands, e.g. not link
the proxy code into the shared library as this can't work because it defines
the same functions that are already present in it.

Also fix the c_xxx targets to work when SWIG is built in a separate build
directory.

Finally, simplify them by removing the unnecessary variables.

Notice that std_vector example still doesn't build, but at least now it is due
to a real problem in the C module and not makefile bugs.
2016-04-10 22:45:51 +02:00
Vadim Zeitlin
7c402ad148 Merge branch 'master' into C 2016-04-08 17:29:16 +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
4ca26c150e Revert "Fix shadowing variable declaration", because it breaks c++ return value type casting in wrapper functions.
This reverts commit 818a9939ecf10ee6cde3e4e389eaf748ec3999d6.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13709 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-20 18:55:51 +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
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
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
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
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
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
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
Leif Middelschulte
7e673e7334 Add constant pointers to 'proxycouttype' typemap
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13616 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-15 19:56:53 +00:00
Leif Middelschulte
2d18d31bcc Add constant pointers to 'cppouttype' typemaps
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13615 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-15 19:56:33 +00:00
Leif Middelschulte
971e501546 add const pointers to 'couttype' typemap
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13614 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-15 19:56:19 +00:00
Leif Middelschulte
b70b752883 Add constant pointers to 'in' typemap
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13613 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-15 19:56:03 +00:00
Leif Middelschulte
41b3fcc1b6 Add constant pointers to 'ctype' typemap
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13612 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-15 19:55:49 +00:00
Leif Middelschulte
1440b43690 Add constant pointers to 'proxy' typemap
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13611 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-15 19:55:36 +00:00
Leif Middelschulte
a540f7199f Refactor 'cppouttype' to be split by type
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13610 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-15 19:55:22 +00:00
Leif Middelschulte
dddc13377a Move to appropriate segment
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13609 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-15 19:55:06 +00:00
Leif Middelschulte
88ffd102f3 Remove template specific typemaps. Leftover from the change to C# like template handling.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13605 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-13 16:22:30 +00:00
Leif Middelschulte
f50b903d64 Add wrapper typemap for "int *const &"
Fix proxy type of complex type (SWIGTYPE) references.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13604 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-13 16:22:02 +00:00
Leif Middelschulte
0dbfbb79ac use correct typemap for wrapper function.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13603 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-13 16:21:36 +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
8538e6c1db Fix wrong type.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13584 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-10 14:49:49 +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
c3236edf80 Add basic C++ test for std::vector instantiated with a native type.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13580 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-09 20:03:22 +00:00
Leif Middelschulte
9619d7c618 Remove wrong typemap.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13579 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-09 20:03:06 +00:00
Leif Middelschulte
333a842277 Type lookup of $1_ltype fails for templates, so use types directly. Add size_t as type.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13578 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-09 20:02:47 +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
2dac491434 Basic C++ test of very simple template class instantiation
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13572 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-09 13:06:03 +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
0a646835d2 Add basic C++ test for template functions.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13567 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-08 16:06:37 +00:00
Leif Middelschulte
a95e257fe8 unused variable--
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13566 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-08 16:06:23 +00:00
Leif Middelschulte
b6d00028bb Remove name_mangle approach. Broke template function names. Should work like classes, etc. based on "nspace" attribute of node, which is for some reason missing for this kind.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13565 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-08 16:06:09 +00:00
Leif Middelschulte
63b68eaafc Fix partialcheck of C backend.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13561 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-08 10:32:59 +00:00
Leif Middelschulte
725c7f395a remove debug printfs
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13553 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-07 20:30:00 +00:00
Leif Middelschulte
d6641336f8 Initial work for templates. Mostly adopted from C#.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13552 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-07 20:18:21 +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
0e75ebbc34 Update to reflect changes (additional typemaps) in the C backend.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13481 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-01 12:52: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
4dc9b5501c Add basic C++ test for virtual methods.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13477 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-31 21:05:16 +00:00
Leif Middelschulte
42681bd01d Fix unnecessary/wrong casts within proxy->wrapper call
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13431 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-30 10:47:37 +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
e9eaa05671 Add atomic test for C++ class
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13421 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-26 20:23:39 +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
cff735b570 Add atomic test for C++ class embedded enum
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13419 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-26 20:23:14 +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
f6bd496b76 Add atomic test for C++ class with a method
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13417 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-26 20:22:49 +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
cafa7e5995 Add atomic test for C++ class with a primitive/native type attribute
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13415 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-26 20:22:21 +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
d276aec0d0 Add atomic test for C++ class with another class as attribute
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13413 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-26 20:21:53 +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
244e3370dd Add atomic test for C++ global enums
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13411 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-26 20:21:20 +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
a2f104e3ca Add atomic test for C++ global atomic/native types variables
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13409 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-26 20:20:44 +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
a756a4f850 Add atomic test for C++ global class instance variables
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13407 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-26 20:20:14 +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
3324d68f2a Add atomic test for C++ namespaces
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13405 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-26 20:19:48 +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
4bc1223c1a Fix segfault of swig due to virtual methods
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13402 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-25 14:30:46 +00:00
Leif Middelschulte
e16672f90f Fix shadowing variable declaration
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13401 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-25 14:30:34 +00:00
Leif Middelschulte
1c4c1b13d8 Fix proxy return type namespacing
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13341 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-23 10:35:15 +00:00
Leif Middelschulte
433a1743ab Namespace functions as well; Remove :: from tl elements
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13332 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-18 23:35:22 +00:00
Leif Middelschulte
cfabfd92d2 Add initial namespace support for C backend.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13323 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-15 23:25:29 +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
70800398b1 Fix enum pointer typemaps
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13311 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-09 23:29:11 +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
884286678a Fix fptr cast of wrapper parameter within proxy function
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13258 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-05 00:22:59 +00:00
Leif Middelschulte
ae50f84237 Repair object references in proxy functions
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13257 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-05 00:22:44 +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
c4ae9c169c Fix linking of examples.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13208 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-06-28 23:29:56 +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
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
Leif Middelschulte
95ddf1174d Repair typemap for proxy function params.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13187 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-06-19 17:18:52 +00:00
Leif Middelschulte
122931dc59 Add 'struct' to typedef of SwibObj_Class declaration.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13186 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-06-19 17:18:39 +00:00
Leif Middelschulte
ae5413ff74 Remove macros "IS_EQUAL" and "IS_SET";Stay in line
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13170 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-06-16 18:58:10 +00:00
Leif Middelschulte
ed7e3143ce Use different types to generate typesafe API.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13169 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-06-16 18:57:55 +00:00
Leif Middelschulte
ef85d0d43f Remove SWIGPROTECT from generated code for now.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13168 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-06-16 18:57:41 +00:00
Leif Middelschulte
f1ec1a26a7 Use seperate typemaps for wrapper and proxy.Refactor bits.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13167 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-06-16 18:57:27 +00:00
Leif Middelschulte
a351c3441c Refactor the c module; initial split of wrapper/proxy
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13164 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-06-12 00:31:09 +00:00
Leif Middelschulte
1dddb18b4c Fix return type assignment
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13134 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-05-28 22:56:37 +00:00
Leif Middelschulte
e08563189f Fix missing braces in assignment-as-condition
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13104 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-05-22 17:15:22 +00:00
Leif Middelschulte
162ed6931a Fix attribute definition.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13103 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-05-22 17:14:59 +00:00
Leif Middelschulte
ce2e1f9765 add me to copyright file/test commit
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13055 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-05-09 16:45:07 +00:00
William S Fulton
8600d258d4 Add necessary test-suite changes made in trunk for running SWIG
From: William S Fulton <wsf@fultondesigns.co.uk>

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@13043 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-05-07 17:03:28 +00:00
William S Fulton
6b4880c81f Fix C examples for linking the output into a shared object
From: William S Fulton <wsf@fultondesigns.co.uk>

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@13042 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-05-07 17:03:09 +00:00
William S Fulton
dcc3756341 Make C example makefiles more standard. Note that valgrind can be used
via the RUNTOOL env variable, see the docs on running the test-suite.

From: William S Fulton <wsf@fultondesigns.co.uk>

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@13041 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-05-07 17:02:51 +00:00
William S Fulton
ee2979b362 Add some changes that are needed in all modules for the runtime banner
From: William S Fulton <wsf@fultondesigns.co.uk>

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@13040 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-05-07 17:02:21 +00:00
William S Fulton
ffe2a11294 Compile time fixes for C module since merge from trunk
From: William S Fulton <wsf@fultondesigns.co.uk>

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@13039 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-05-07 17:02:00 +00:00
William S Fulton
cebb2aaa93 Re-apply c.cxx changes from r11187
From: William S Fulton <wsf@fultondesigns.co.uk>

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@13038 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-05-07 17:01:40 +00:00
William S Fulton
994cf6f0c7 Remove GIFPlot C Examples
From: William S Fulton <wsf@fultondesigns.co.uk>

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@13037 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-05-07 17:01:20 +00:00
William S Fulton
e0067ea998 Merge trunk rev 13025 (swig-2.0.6) into gsoc2008-maciekd
Conflicts:
	Doc/Manual/chapters
	Examples/Makefile.in
	Examples/test-suite/dynamic_cast.i
	Lib/exception.i
	Makefile.in
	Source/Include/swigwarn.h
	Source/Modules/swigmain.cxx
	Source/Swig/swig.h
	Tools/config/config.guess
	Tools/config/config.sub
	configure.in

From: William S Fulton <wsf@fultondesigns.co.uk>

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@13036 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-05-07 16:59:38 +00:00
William S Fulton
1acc0167d1 Revert rev 10606 "Merged revisions 10498-10499,10503-10504,10506,10508,10511,10515-10516,10518-10519,10527,10530-10531,10536-10537,10539-10552,10558-10568,10574-10580,10582,10584,10588-10589,10594 via svnmerge from "
This reverts commit 379b9bcdf44dcd87c5eca7eb9a773aea793e7caf.

From: William S Fulton <wsf@fultondesigns.co.uk>

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@13034 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-05-06 01:17:11 +00:00
William S Fulton
d6b81eb831 Revert rev 11187 "Merged with recent changes from trunk."
This reverts commit c595e4d90ebfd63eb55430c735bb121cf690bd59.

Conflicts:

	Source/Modules/c.cxx

From: William S Fulton <wsf@fultondesigns.co.uk>

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@13033 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-05-06 01:13:16 +00:00
William S Fulton
34a628c7c7 Revert rev 11918 "merge revisions 11872:11876 from trunk to gsoc2008-maciekd branch - license changes"
This reverts commit ec942f04ca8b33520442f079e2ea2d8d3e4be73c.

From: William S Fulton <wsf@fultondesigns.co.uk>

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@13032 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-05-06 00:49:56 +00:00
William S Fulton
d1e871f0d2 merge revisions 11872:11876 from trunk to gsoc2008-maciekd branch - license changes
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@11918 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2010-03-06 13:26:09 +00:00
Maciej Drwal
3ab6cb695e One more runtime test case
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@11190 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2009-04-15 23:38:48 +00:00
Maciej Drwal
32e03aa13d Many major improvements. Almost all testsuite compiles now.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@11189 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2009-04-15 23:30:16 +00:00
Maciej Drwal
a2dc2756c8 Several major fixes for: arrays, static members, member func.ptrs., exceptions, ... Lots of tests runs ok now.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@11188 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2009-04-13 21:23:07 +00:00
Maciej Drwal
8c74fa0f46 Merged with recent changes from trunk.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@11187 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2009-04-11 16:46:47 +00:00
Maciej Drwal
da5ade3143 Refactored enums handling
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@11186 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2009-04-11 10:46:13 +00:00
Maciej Drwal
8c04b766d4 Fix for warning on return by value. Fix for std_string.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@11184 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2009-04-08 20:32:30 +00:00
Maciej Drwal
5002c69cd6 Fixed some issues with member variables handling
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@11155 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2009-03-18 15:04:20 +00:00
Maciej Drwal
4acb01b741 Fix for returning objects.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@11109 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2009-02-04 16:10:07 +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
William S Fulton
c7942801c0 minor display fix for swig -help
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10814 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-09-07 21:59:24 +00:00
Maciej Drwal
f2cd76308e include in char_strings_runme.c
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10797 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-08-24 12:59:17 +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
Maciej Drwal
54860c9595 1. Fixed the bug in enums. Now 'enums' test is compiling OK.
2. -noexcept flag disables generating exception-related code (like array of type names in SwigObj, object registry, etc.). This can be used when we are sure we won't handle exceptions on the C side, and this will generate much less code. 
3. Modified typemaps for object arrays. Multidimensional ones still needs some fixing.
4. Added 'enums' and 'cast_operator' runtime tests.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10771 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-08-17 13:42:19 +00:00
Maciej Drwal
8438e30b02 Fixed global function handler.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10760 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-08-14 09:50:13 +00:00
Maciej Drwal
ea556b565d Some function return cases fixed.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10748 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-08-09 20:14:41 +00:00
Maciej Drwal
83d60a1d36 Improved converting return values (avoiding using assignment and default constructors).
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10746 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-08-08 21:22:07 +00:00
Maciej Drwal
948c474a0d Modified examples' Makefiles to generate executables.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10729 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-08-02 16:38:27 +00:00
Maciej Drwal
dcec3c3fb0 Added std_string support. Renamed SWIG_exception to SWIG_exc to avoid name collision with macro in Lib/exception.i.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10720 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-07-30 22:09:02 +00:00
Maciej Drwal
d4f62fda47 Refactored member variable and function handlers.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10718 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-07-28 21:03:21 +00:00
Maciej Drwal
da73b796ea %extend feature
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10717 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-07-27 22:50:08 +00:00
Maciej Drwal
95045e73c6 Handling constants.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10716 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-07-27 15:20:56 +00:00
Maciej Drwal
7e23a5a55e Removing some memory leak problems when handling exceptions.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10713 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-07-26 14:18:37 +00:00
Maciej Drwal
96a52c763c Now constructors use SWIG_create_object() function, which fills type information for SwigObj struct. 'out' typemaps for objects and 'throws' typemaps also use this.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10696 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-07-21 18:22:43 +00:00
Maciej Drwal
6fd77fa609 Renaming and type mangling fixes. Reverted to normal typemaps searching.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10694 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-07-21 15:52:30 +00:00
Maciej Drwal
9c5ef7558c Support for enums and typedefs.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10691 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-07-21 10:55:05 +00:00
Maciej Drwal
e90a0692c7 Replaced SwigObjXXX with one type SwigObj. Added typemaps for bool.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10674 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-07-17 09:53:05 +00:00
Maciej Drwal
88facfd390 Exceptions support for C. exception_order test shows how to use type information to achieve correct catching order. Examples cleanup.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10671 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-07-17 00:52:11 +00:00
Maciej Drwal
03d275e42f Initial C++ exceptions support (still work in progress). Some typemap fixes.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10661 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-07-14 19:38:10 +00:00
Maciej Drwal
542c21b6fe Few C typemaps fixes (still using experimental approach).
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10658 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-07-11 16:12:14 +00:00
Maciej Drwal
b7340dd4d6 configure fix
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10657 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-07-11 09:34:10 +00:00
Maciej Drwal
a13c5976b5 Fixed naming convention issues (internal Swig variables, shadow -> proxy, test.c -> runme.c, etc.), modified Makefiles, bugfixes ("name" -> "sym:name"). Started C test-suite.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10655 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-07-09 20:02:20 +00:00
Maciej Drwal
f585c69d02 Some support for overloading, simplified wrapping of pure C functions, some improvements in argument passing typemaps.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10653 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-07-06 18:33:09 +00:00
Maciej Drwal
125f362852 Trying to work out the best solution for special cases of argument passing (arrays of objects, etc.). Some hacks in Swig_typemap_search() to distinguish between built-in types and objects, but this is experimental by now.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10652 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-07-05 21:29:07 +00:00
Maciej Drwal
97ffcf1da7 static member function, copy constructor, some minor fixes
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10646 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-07-03 23:26:10 +00:00
Maciej Drwal
b2d56dee8e Some fixes to linking problems.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10642 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-07-03 14:55:03 +00:00
Maciej Drwal
6355de87ef Simple runtime type checking (optional).
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10632 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-07-02 23:29:30 +00:00
Maciej Drwal
0b3d9dad0d Static member variable handler.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10623 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-07-01 23:32:34 +00:00
Maciej Drwal
9c07e2a9e5 Variable inheritance support: sets/gets for each class derived from a base class. Modified 'class' example.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10619 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-07-01 15:27:54 +00:00
Maciej Drwal
f74439e215 Better handling of return values. Some bugfixes.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10618 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-07-01 10:30:40 +00:00
Maciej Drwal
ea05035844 Namespaces support.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10611 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-06-29 15:09:31 +00:00
Maciej Drwal
e058e1f42f Merged revisions 10498-10499,10503-10504,10506,10508,10511,10515-10516,10518-10519,10527,10530-10531,10536-10537,10539-10552,10558-10568,10574-10580,10582,10584,10588-10589,10594 via svnmerge from
https://swig.svn.sourceforge.net/svnroot/swig/trunk

........
  r10498 | talby | 2008-05-26 22:09:56 +0200 (Pn, 26 maj 2008) | 2 lines
  
  run test cases in the Perl set by the --with-perl5 configure option.
........
  r10499 | talby | 2008-05-26 23:04:06 +0200 (Pn, 26 maj 2008) | 3 lines
  
  The perl5 minherit runtime test will work better if the classes are 
  actually built under SWIGPERL.
........
  r10503 | wsfulton | 2008-05-28 11:44:37 +0200 (Śr, 28 maj 2008) | 1 line
  
  Fix variable wrappers when using -proxy. Patch from Jan Jezabek
........
  r10504 | bhy | 2008-05-28 19:27:48 +0200 (Śr, 28 maj 2008) | 2 lines
  
  Fixed SF #1971977:  typo in pycontainer.swg (related to -extranative option)
........
  r10506 | wsfulton | 2008-05-29 02:45:28 +0200 (Cz, 29 maj 2008) | 1 line
  
  Fix variable wrappers when using -noproxy
........
  r10508 | bhy | 2008-05-30 15:53:33 +0200 (Pt, 30 maj 2008) | 1 line
  
  Fixed SF #1976978, apply the macros for primitive types to std::wstring
........
  r10511 | olly | 2008-05-30 18:11:27 +0200 (Pt, 30 maj 2008) | 4 lines
  
  Fix typo in handling of /*@SWIG[...]*/ comments in the scanner.  This just
  meant we were only actually looking for /*@SWI at the start of the comment, so
  was pretty harmless in practice.
........
  r10515 | wsfulton | 2008-06-02 22:10:40 +0200 (Pn, 02 cze 2008) | 1 line
  
  Fix samename testcase for c# and java
........
  r10516 | wsfulton | 2008-06-02 22:15:39 +0200 (Pn, 02 cze 2008) | 1 line
  
  Fix enums when using -noproxy
........
  r10518 | bhy | 2008-06-07 13:20:07 +0200 (So, 07 cze 2008) | 4 lines
  
  Added a test case for keyword renaming.
  Now it works for Python in SWIG's -c++ mode,
  but in C mode it doesn't work! (you can try with make keyword_rename.ctest)
........
  r10519 | bhy | 2008-06-07 15:40:51 +0200 (So, 07 cze 2008) | 1 line
  
  fixed keyword_rename.ctest tese case, caused by a mistake in Swig/naming.c
........
  r10527 | mgossage | 2008-06-17 04:57:15 +0200 (Wt, 17 cze 2008) | 1 line
  
  [lua] bugfix 1938142 (bool& and bool* support)
........
  r10530 | wsfulton | 2008-06-19 22:02:13 +0200 (Cz, 19 cze 2008) | 1 line
  
  Add R keyword support. Rename keywords for successful compilation of Java and C# code. More consistent keyword warnings across the different languages.
........
  r10531 | wsfulton | 2008-06-19 23:15:48 +0200 (Cz, 19 cze 2008) | 1 line
  
  add complete list of R reserved words
........
  r10536 | wsfulton | 2008-06-21 13:35:33 +0200 (So, 21 cze 2008) | 1 line
  
  better terminology for static types
........
  r10537 | wsfulton | 2008-06-21 13:42:48 +0200 (So, 21 cze 2008) | 1 line
  
  remove raise as keyword test- it conflicts with _raise in LIBCMT on windows
........
  r10539 | wsfulton | 2008-06-21 17:21:29 +0200 (So, 21 cze 2008) | 1 line
  
  Lua example warning removal fixes for vc++
........
  r10540 | wsfulton | 2008-06-21 17:23:02 +0200 (So, 21 cze 2008) | 1 line
  
  Remove some vc++ /W4 warnings
........
  r10541 | wsfulton | 2008-06-21 18:04:55 +0200 (So, 21 cze 2008) | 1 line
  
  minor vc++ /W4 warning fixes
........
  r10542 | wsfulton | 2008-06-21 21:07:51 +0200 (So, 21 cze 2008) | 1 line
  
  'byte' is already used in Ruby on windows, so use another keyword
........
  r10543 | wsfulton | 2008-06-21 22:45:32 +0200 (So, 21 cze 2008) | 1 line
  
  Fix crashing in the Ruby reject method in the STL wrappers
........
  r10544 | wsfulton | 2008-06-21 22:48:28 +0200 (So, 21 cze 2008) | 1 line
  
  Fix crashing in the Ruby reject method in the STL wrappers
........
  r10545 | wsfulton | 2008-06-21 22:49:10 +0200 (So, 21 cze 2008) | 1 line
  
  remove unnecessary variable int the char **STRING_ARRAY out typemap
........
  r10546 | wsfulton | 2008-06-21 23:07:49 +0200 (So, 21 cze 2008) | 1 line
  
  Fix Ruby C++ example dependencies in dsp files
........
  r10547 | wsfulton | 2008-06-22 00:25:36 +0200 (N, 22 cze 2008) | 1 line
  
  Fix unused parameter warnings in python when using gcc's -W -Wall options
........
  r10548 | wsfulton | 2008-06-22 00:26:35 +0200 (N, 22 cze 2008) | 1 line
  
  Fix virtual destructor
........
  r10549 | wsfulton | 2008-06-22 01:25:20 +0200 (N, 22 cze 2008) | 1 line
  
  various warning fixes
........
  r10550 | wsfulton | 2008-06-22 02:09:11 +0200 (N, 22 cze 2008) | 1 line
  
  Another fix for the JVM hanging on exit problem when using directors
........
  r10551 | wsfulton | 2008-06-22 02:09:51 +0200 (N, 22 cze 2008) | 1 line
  
  documentation sections update
........
  r10552 | wsfulton | 2008-06-22 02:18:10 +0200 (N, 22 cze 2008) | 1 line
  
  more docs on defining macros for the thread hanging problem
........
  r10558 | wsfulton | 2008-06-22 23:30:20 +0200 (N, 22 cze 2008) | 1 line
  
  fix unused parms in last commit for C code
........
  r10559 | wsfulton | 2008-06-23 00:12:43 +0200 (Pn, 23 cze 2008) | 1 line
  
  Suppress unused methods warning for VC++
........
  r10560 | wsfulton | 2008-06-23 22:26:07 +0200 (Pn, 23 cze 2008) | 1 line
  
  fix partialcheck-test-suite and parallel make for r, chicken, tcl and php
........
  r10561 | wsfulton | 2008-06-23 22:39:41 +0200 (Pn, 23 cze 2008) | 1 line
  
  correct message display when running the partialcheck-test-suite make target
........
  r10562 | wsfulton | 2008-06-23 23:14:53 +0200 (Pn, 23 cze 2008) | 1 line
  
  fix typo
........
  r10563 | olly | 2008-06-23 23:23:54 +0200 (Pn, 23 cze 2008) | 3 lines
  
  Fix bad use of Python API (untested, since I can't even compile this code on
  x86-64!)
........
  r10564 | olly | 2008-06-24 00:58:03 +0200 (Wt, 24 cze 2008) | 3 lines
  
  [PHP] Fix segfault when wrapping a non-class function marked with
  %newobject (testcase char_strings).
........
  r10565 | olly | 2008-06-24 02:27:34 +0200 (Wt, 24 cze 2008) | 3 lines
  
  [PHP] Fix assertion failure when handling %typemap(in,numinputs=0)
  (testcase ignore_parameter).
........
  r10566 | olly | 2008-06-24 02:33:08 +0200 (Wt, 24 cze 2008) | 2 lines
  
  [PHP] Fix typemap_namespace.i to not try to copy a non-existent typemap.
........
  r10567 | olly | 2008-06-24 02:41:07 +0200 (Wt, 24 cze 2008) | 3 lines
  
  Clean up dead and unused code in SwigToPhpType(), and rename to
  GetShadowReturnType().
........
  r10568 | olly | 2008-06-24 02:42:29 +0200 (Wt, 24 cze 2008) | 2 lines
  
  Fix cosmetic typo in string constant.
........
  r10574 | wsfulton | 2008-06-24 22:10:28 +0200 (Wt, 24 cze 2008) | 1 line
  
  zap last entry
........
  r10575 | wsfulton | 2008-06-24 22:11:46 +0200 (Wt, 24 cze 2008) | 1 line
  
  variable name changes to remove php keywords
........
  r10576 | wsfulton | 2008-06-24 22:12:08 +0200 (Wt, 24 cze 2008) | 1 line
  
  variable name hiding fix
........
  r10577 | wsfulton | 2008-06-24 22:12:43 +0200 (Wt, 24 cze 2008) | 1 line
  
  More info about numobjects added
........
  r10578 | wsfulton | 2008-06-24 22:13:41 +0200 (Wt, 24 cze 2008) | 1 line
  
  update for 1.3.36 release
........
  r10579 | wsfulton | 2008-06-24 23:48:46 +0200 (Wt, 24 cze 2008) | 1 line
  
  remove deprecated -c commandline option (runtime library generation)
........
  r10580 | wsfulton | 2008-06-24 23:53:12 +0200 (Wt, 24 cze 2008) | 1 line
  
  correct comment about deprecated option
........
  r10582 | wsfulton | 2008-06-25 01:00:27 +0200 (Śr, 25 cze 2008) | 1 line
  
  use rsync and ssh to upload releases to SourceForge as ftp no longer works
........
  r10584 | wsfulton | 2008-06-25 01:24:48 +0200 (Śr, 25 cze 2008) | 1 line
  
  correction for 1.3.36
........
  r10588 | wsfulton | 2008-06-25 02:16:04 +0200 (Śr, 25 cze 2008) | 1 line
  
  section update
........
  r10589 | wsfulton | 2008-06-25 02:16:40 +0200 (Śr, 25 cze 2008) | 1 line
  
  bump version to 1.3.37
........
  r10594 | wsfulton | 2008-06-26 20:33:06 +0200 (Cz, 26 cze 2008) | 1 line
  
  correct typo in first entry about %fragment
........


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10606 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-06-28 23:26:18 +00:00
Maciej Drwal
f03e17b405 Support for parameter passing by value, pointer and reference.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10604 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-06-28 20:48:40 +00:00
Maciej Drwal
f84342a301 Modified parameter handling using typemaps. 'Reference' example. Visibility hint now applies only to the global functions.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10603 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-06-28 16:22:07 +00:00
Maciej Drwal
cdd920a6ca Fix to linking problem for Linux in examples.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10600 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-06-28 00:06:33 +00:00
Maciej Drwal
2620bb218c Member variable and function wrappers. The simple 'class' test passed.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10538 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-06-21 14:51:02 +00:00
Maciej Drwal
e06b48e3f6 Basic constructor and destructor wrapper.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10532 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-06-20 16:34:35 +00:00
Maciej Drwal
a5b8db8296 Global variable and function handling from C to C.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10526 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-06-16 15:27:36 +00:00
Maciej Drwal
d828791f56 Some changes to generated proxy .c and .h file.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10522 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-06-07 20:30:42 +00:00
Maciej Drwal
a36f790271 Experimenting with global function wrapping, generating C proxy file, 'prepend' feature.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10512 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-05-30 16:17:24 +00:00
Maciej Drwal
338347feb0 Initial C module file and simple example added.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10501 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-05-28 06:25:25 +00:00
103 changed files with 7180 additions and 23 deletions

View file

@ -49,6 +49,8 @@ jobs:
os: ubuntu-22.04
- SWIGLANG: ""
compiler: clang
- SWIGLANG: c
CPPSTD: c++11
- SWIGLANG: csharp
# D support can't be enabled because dmd 2.066 fails to build anything
# under Ubuntu 18.04 due to its standard library (libphobos2.a) not

View file

@ -1,7 +1,7 @@
SWIG Copyright and Authors
--------------------------
Copyright (c) 1995-2011 The SWIG Developers
Copyright (c) 1995-2012 The SWIG Developers
Copyright (c) 2005-2006 Arizona Board of Regents (University of Arizona).
Copyright (c) 1998-2005 University of Chicago.
Copyright (c) 1995-1998 The University of Utah and the Regents of the University of California
@ -16,6 +16,7 @@ Active SWIG Developers:
Joseph Wang (joequant@gmail.com) (R)
Xavier Delacour (xavier.delacour@gmail.com) (Octave)
David Nadlinger (code@klickverbot.at) (D)
Leif Middelschulte (leif.middelschulte@gmail.com) (C)
Oliver Buchtala (oliver.buchtala@gmail.com) (Javascript)
Neha Narang (narangneha03@gmail.com) (Javascript)
Simon Marchetto (simon.marchetto@scilab-enterprises.com) (Scilab)

762
Doc/Manual/C.html Normal file
View file

@ -0,0 +1,762 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>SWIG and C as the target language</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body bgcolor="#FFFFFF">
<H1><a name="C"></a>36 SWIG and C as the target language</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
<li><a href="#C_overview">Overview</a>
<li><a href="#C_preliminaries">Preliminaries</a>
<ul>
<li><a href="#C_running_swig">Running SWIG</a>
<li><a href="#C_commandline">Command line options</a>
<li><a href="#C_dynamic">Compiling dynamic module</a>
<li><a href="#C_using_module">Using generated module</a>
</ul>
<li><a href="#C_basic_c_wrapping">Basic C wrapping</a>
<ul>
<li><a href="#C_functions">Functions</a>
<li><a href="#C_variables">Variables</a>
<li><a href="#C_enums">Enums</a>
</ul>
<li><a href="#C_basic_cpp_wrapping">Basic C++ wrapping</a>
<ul>
<li><a href="#C_classes">Classes</a>
</ul>
<li><a href="#C_exceptions">Exception handling</a>
<li><a href="#C_cxx_wrappers">C++ wrappers</a>
</ul>
</div>
<!-- INDEX -->
<p>
This chapter describes SWIG's support for creating ANSI C wrappers. This module has a special purpose and thus is different from most other modules.
</p>
<p>
<b>NOTE:</b> this module is still under development.
</p>
<H2><a name="C_overview"></a>36.1 Overview</H2>
<p>
SWIG is normally used to provide access to C or C++ libraries from target languages such as scripting languages or languages running on a virtual machine.
SWIG performs analysis of the input C/C++ library header files from which it generates further code. For most target languages this code consists of two layers; namely an intermediary C code layer and a set of language specific proxy classes and functions on top of the C code layer.
We could also think of C as just another target language supported by SWIG.
The aim then is to generate a pure ANSI C interface to the input C or C++ library and hence the C target language module.
</p>
<p>
With wrapper interfaces generated by SWIG, it is easy to use the functionality of C++ libraries inside application code written in C. This module may also be useful to generate custom APIs for a library, to suit particular needs, e.g. to supply function calls with error checking or to implement a "design by contract".
</p>
<p>
Flattening C++ language constructs into a set of C-style functions obviously comes with many limitations and inconveniences, but this module is actually also capable of generating C++ wrappers defined completely inline using the C functions, thus wrapping the original C++ library API in another, similar C++ API. Contrary to the natural initial reaction, this is far from being completely pointless, as wrapping C++ API in this way avoids all problems due to C++ ABI issues, e.g. it is now possible to use the original C++ API using a different C++ compiler, or a different version of the same compiler, or even the same compiler, but with different compilation options affecting the ABI. The C++ wrapper API is not identical to the original one, but strives to be as close to it as possible.
</p>
<H3>Known C++ Shortcomings in Generated C API:</H3>
<ul>
<li>Enums with a context like class or namespace are broken</li>
<li>Global variables are not supported</li>
<li>Qualifiers are stripped</li>
<li>Vararg functions are not supported.</li>
</ul>
<H2><a name="C_preliminaries"></a>36.2 Preliminaries</H2>
<H3><a name="C_running_swig"></a>36.2.1 Running SWIG</H3>
<p>
Consider the following simple example. Suppose we have an interface file like:
</p>
<div class="code">
<pre>
/* File: example.i */
%module test
%{
#include "stuff.h"
%}
int fact(int n);
</pre>
</div>
<p>
To build a C module (C as the target language), run SWIG using the <tt>-c</tt> option :</p>
<div class="shell"><pre>
$ swig -c example.i
</pre></div>
<p>
The above assumes C as the input language. If the input language is C++ add the <tt>-c++</tt> option:
</p>
<div class="shell"><pre>
$ swig -c++ -c example.i
</pre></div>
<p>
Note that <tt>-c</tt> is the option specifying the <b>target</b> language and <tt>-c++</tt> controls what the <b>input</b> language is.
<p>
<p>
This will generate an <tt>example_wrap.c</tt> file or, in the latter case, <tt>example_wrap.cxx</tt> file, along with <tt>example_wrap.h</tt> (the same extension is used in both C and C++ cases for the last one). The names of the files are derived from the name of the input file by default, but can be changed using the <tt>-o</tt> and <tt>-oh</tt> options common to all language modules.
</p>
<p>
The <tt>xxx_wrap.c</tt> file contains the wrapper functions, which perform the main functionality of SWIG: each of the wrappers translates the input arguments from C to C++, makes calls to the original functions and marshals C++ output back to C data. The <tt>xxx_wrap.h</tt> header file contains the declarations of these functions as well as global variables.
</p>
<H3><a name="C_commandline"></a>36.2.2 Command line options</H3>
<p>
The following table list the additional command line options available for the C module. They can also be seen by using:
</p>
<div class="shell"><pre>
$ swig -c -help
</pre></div>
<table summary="C specific options">
<tr>
<th>C specific options</th>
</tr>
<tr>
<td>-namespace &lt;nspace&gt;</td>
<td>Generate wrappers with the prefix based on the provided namespace, e.g. if the option value is <tt>outer::inner</tt>, the prefix <tt>outer_inner_</tt> will be used. Notice that this is different from using SWIG <tt>nspace</tt> feature, as it applies the the prefix to all the symbols, regardless of the namespace they were actually declared in. Notably, this allows to export instantiations of templates defined in the <tt>std</tt> namespace, such as <tt>std::vector</tt>, using a custom prefix rather than <tt>std_</tt>.</td>
</tr>
<tr>
<td>-nocxx</td>
<td>Don't generate C++ wrappers, even when <tt>-c++</tt> option is used. See <a href="#C_cxx_wrappers">C++ Wrappers</a> section for more details.</td>
</tr>
<tr>
<td>-noexcept</td>
<td>generate wrappers with no support of exception handling; see <a href="#C_exceptions">Exceptions</a> chapter for more details </td>
</tr>
</table>
<H3><a name="C_dynamic"></a>36.2.3 Compiling a dynamic module</H3>
<p>
The next step is to build a dynamically loadable module, which we can link to our application. This can be done easily, for example using the <tt>gcc</tt> compiler (Linux, MinGW, etc.):
</p>
<div class="shell"><pre>
$ swig -c example.i
$ gcc -c example_wrap.c
$ gcc -shared example_wrap.o -o libexample.so
</pre></div>
<p>
Or, for C++ input:
</p>
<div class="shell"><pre>
$ swig -c++ -c example.i
$ g++ -c example_wrap.cxx
$ g++ -shared example_wrap.o -o libexample.so
</pre></div>
<p>
Now the shared library module is ready to use. Note that the name of the generated module is important: is should be prefixed with <tt>lib</tt> on Unix, and have the specific extension, like <tt>.dll</tt> for Windows or <tt>.so</tt> for Unix systems.
</p>
<H3><a name="C_using_module"></a>36.2.4 Using the generated module</H3>
<p>
The simplest way to use the generated shared module is to link it to the application code during the compilation stage. The process is usually similar to this:
</p>
<div class="shell"><pre>
$ gcc runme.c -L. -lexample -o runme
</pre></div>
<p>
This will compile the application code (<tt>runme.c</tt>) and link it against the generated shared module. Following the <tt>-L</tt> option is the path to the directory containing the shared module. The output executable is ready to use. The last thing to do is to supply to the operating system the information of location of our module. This is system dependant, for instance Unix systems look for shared modules in certain directories, like <tt>/usr/lib</tt>, and additionally we can set the environment variable <tt>LD_LIBRARY_PATH</tt> (Unix) or <tt>PATH</tt> (Windows) for other directories.
</p>
<H2><a name="C_basic_c_wrapping"></a>36.3 Basic C wrapping</H2>
<p>
Wrapping C functions and variables is obviously performed in a straightforward way. There is no need to perform type conversions, and all language constructs can be preserved in their original form. However, SWIG allows you to enhance the code with some additional elements, for instance using <tt>check</tt> typemap or <tt>%extend</tt> directive.
</p>
<p>
It is also possible to output arbitrary additional code into the generated header by using <tt>%insert</tt> directive with <tt>cheader</tt> section, e.g.
<div class="code"><pre>
%insert("cheader") %{
#include "another.h"
%}
</pre></div>
</p>
<H3><a name="C_functions"></a>36.3.1 Functions</H3>
<p>
For each C function declared in the interface file a wrapper function with a prefix, required to make its name different from the original one, is created. The prefix for the global functions is <tt>module_</tt>, i.e. the name of the SWIG module followed by underscore, by default. If <tt>-namespace</tt> option is used, the prefix corresponding to the given fixed namespace is used instead. If <tt>nspace</tt> feature is used, the prefix corresponding to the namespace in which the function is defined is used -- note that, unlike with <tt>-namespace</tt> option, this prefix can be different for different functions. The wrapper function performs a call to the original function, and returns its result.
</p>
<p>
For example, for function declaration in the module <tt>mymath</tt>:
</p>
<div class="targetlang"><pre>
int gcd(int x, int y);
</pre></div>
<p>
The output is simply:
</p>
<div class="targetlang"><pre>
int mymath_gcd(int arg1, int arg2) {
int result;
result = gcd(arg1,arg2);
return result;
}
</pre></div>
<p>
Now one might think, what's the use of creating such functions in C? The answer is, you can apply special rules to the generated code. Take for example constraint checking. You can write a "check" typemap in your interface file:
</p>
<div class="code"><pre>
%typemap(check) int POSITIVE {
if ($1 <= 0)
fprintf(stderr, "Expected positive value in $name.\n");
}
int gcd(int POSITIVE, int POSITIVE);
</pre></div>
<p>
And now the generated result looks like:
</p>
<div class="targetlang"><pre>
int _wrap_gcd(int arg1, int arg2) {
{
if (arg1 <= 0)
fprintf(stderr, "Expected positive value in gcd.\n");
}
{
if (arg1 <= 0)
fprintf(stderr, "Expected positive value in gcd.\n");
}
int result;
result = gcd(arg1,arg2);
return result;
}
</pre></div>
<p>
This time calling <tt>gcd</tt> with negative value argument will trigger an error message. This can save you time writing all the constraint checking code by hand.
</p>
<H3><a name="C_variables"></a>36.3.2 Variables</H3>
<p>
Wrapping variables comes also without any special issues. All global variables are directly accessible from application code. There is a difference in the semantics of <tt>struct</tt> definition in C and C++. When handling C <tt>struct</tt>, SWIG simply rewrites its declaration. In C++ <tt>struct</tt> is handled as class declaration.
</p>
<p>
You can still apply some of the SWIG features when handling structs, e.g. <tt>%extend</tt> directive. Suppose, you have a C struct declaration:
</p>
<div class="targetlang"><pre>
typedef struct {
int x;
char *str;
} my_struct;
</pre></div>
<p>
You can redefine it to have an additional fields, like:
</p>
<div class="code"><pre>
%extend my_struct {
double d;
};
</pre></div>
<p>
In application code:
</p>
<div class="targetlang"><pre>
struct my_struct ms;
ms.x = 123;
ms.d = 123.123;
</pre></div>
<H2><a name="C_basic_cpp_wrapping"></a>36.4 Basic C++ wrapping</H2>
<p>
The main reason of having the C module in SWIG is to be able to access C++ from C. In this chapter we will take a look at the rules of wrapping elements of the C++ language.
</p>
<p>
By default, SWIG attempts to build a natural C interface to your C/C++ code.
<table BORDER summary="Generated C representation of C++">
<tr>
<th>C++ Type</th>
<th>SWIG C Translation</th>
</tr>
<tr>
<td>Class <tt>Example</tt></td>
<td>Empty structure <tt>Example</tt></td>
</tr>
<tr>
<td>Public, mutable member variable <tt><tt>Foo Example::foo</tt></td>
<td><tt>
Example_foo_get(Example *e);</br>
Example_foo_set(Example *e, Foo *f);
</tt></td>
</tr>
<tr>
<td>Public, immutable member variable <tt><tt>Foo Example::bar</tt></td>
<td><tt>
Example_foo_get(Example *e);</br>
</tt></td>
</tr>
</table>
This section briefly covers the essential aspects of this wrapping.
</p>
<H3><a name="C_enums"></a>36.3.3 Enums</H3>
<p>
C enums and unscoped C++ enums are simply copied to the generated code and both the enum itself and its elements keep the same name as in the original code unless <tt>-namespace</tt> option is used or <tt>nspace</tt> feature is enabled, in which case the prefix corresponding to the specified namespace is used.
</p>
<p>
For scoped C++11 enums, the enum name itself is used as an additional prefix.
</p>
<H3><a name="C_classes"></a>36.4.1 Classes</H3>
<p>
Consider the following example. We have a C++ class, and want to use it from C code.
</p>
<div class="targetlang"><pre>
class Circle {
public:
double radius;
Circle(double r) : radius(r) { };
double area(void);
};
</pre></div>
<p>
What we need to do is to create an object of the class, manipulate it, and finally, destroy it. SWIG generates C functions for this purpose each time a class declaration is encountered in the interface file.
</p>
<p>
The first two generated functions are used to create and destroy instances of class <tt>Circle</tt>. Such instances are represented on the C side as pointers to special structs, called <tt>SwigObj</tt>. They are all "renamed" (via typedef) to the original class names, so that you can use the object instances on the C side using pointers like:
</p>
<div class="targetlang"><pre>
Circle *circle;
</pre></div>
<p>
The generated functions make calls to class' constructors and destructors, respectively. They also do all the necessary things required by the SWIG object management system in C.
</p>
<div class="targetlang"><pre>
Circle * Circle_new(double r);
void Circle_delete(Circle * self);
</pre></div>
<p>
The class <tt>Circle</tt> has a public variable called <tt>radius</tt>. SWIG generates a pair of setters and getters for each such variable:
</p>
<div class="targetlang"><pre>
void Circle_radius_set(Circle * self, double radius);
double Circle_radius_get(Circle * self);
</pre></div>
<p>
For each public method, an appropriate function is generated:
</p>
<div class="targetlang"><pre>
double Circle_area(Circle * self);
</pre></div>
<p>
You can see that in order to use the generated object we need to provide a pointer to the object instance (struct <tt>Circle</tt> in this case) as the first function argument. In fact, this struct is basically wrapping pointer to the "real" C++ object.
</p>
<p>
Our application code could look like this:
</p>
<div class="targetlang"><pre>
Circle *c = Circle_new(1.5);
printf("radius: %f\narea: %f\n", Circle_radius_get(c), Circle_area(c));
Circle_delete(c);
</pre></div>
<p>
After running this we'll get:
</p>
<div class="shell"><pre>
radius: 1.500000
area: 7.068583
</pre></div>
<H2><a name="C_developer"></a>Backend Developer Documentation</H2>
<H2><a name="C_typemaps"></a>Typemaps</H2>
<table BORDER summary="C Backend Typemaps">
<tr>
<th>Typemap</th>
<th>Used for</th>
</tr>
<tr>
<td><tt>ctype</tt></td>
<td>Provides types used for the C API and</br>
Typecasts wrapper functions return values in proxy functions</br>
<code>
MyClass *MyClass_new(void) {</br>
&nbsp;return (MyClass *)MyClass_new();</br>
}
</code>
</td>
</tr>
<tr>
<td><tt>in</tt></td>
<td>Mapping of wrapper functions parameters to local C++ variables</br>
</br>
<code>
SwigObj* MyClass_do(SwigObj *carg1) {</br>
&nbsp;SomeCPPClass *arg1 = 0;</br>
&nbsp;if (carg1)</br>
&nbsp;&nbsp;arg1 = (SomeCPPClass*)carg1->obj</br>
&nbsp;else</br>
&nbsp;&nbsp;arg1 = 0;</br>
}
</code></td>
</tr>
<tr>
<td><tt>out</tt></td>
<td>Assigns wrapped function's return value to a dedicated return variable, packaging it into SwigObj if necessary</td>
</tr>
<tr>
<td><tt>cppouttype</tt></td>
<td>Type of the result variable used for the return value if the wrapped function is a C++ function
</td>
</tr>
<tr>
<td><tt>cxxintype</tt></td>
<td>Defines the type for the parameters of C++ wrapper functions corresponding to this type. By default is the same as <tt>ctype</tt>, but may sometimes be different to make the functions more convenient to use. For example, <tt>ctype</tt> for <tt>std::string</tt> is <tt>const char*</tt>, but <tt>cxxintype</tt> typemap for it is <tt>std::string const&amp;</tt>, i.e. even though the C++ string passed as a raw pointer via C API, the C++ wrapper still accepts a C++ string. If this typemap is defined, <tt>cxxin</tt> should normally be defined as well. If it is not defined, <tt>ctype</tt> is used.
</td>
</tr>
<tr>
<td><tt>cxxouttype</tt></td>
<td>Similar to <tt>cxxintype</tt>, but is used for the function return values and together with <tt>cxxout</tt> typemap. Also defaults to <tt>ctype</tt> if not defined.
</td>
</tr>
<tr>
<td><tt>cxxin</tt></td>
<td>Defines how to transform <tt>cxxintype</tt> value to <tt>ctype</tt>
</td>
</tr>
<tr>
<td><tt>cxxout</tt></td>
<td>Defines how to transform <tt>ctype</tt> value returned by a function to <tt>cxxouttype</tt>
</td>
</tr>
<tr>
<td><tt>cxxcode</tt></td>
<td>May contain arbitrary code that will be injected in the declaration of the C++ wrapper class corresponding to the given type. Ignored for non-class types. The special variable <tt>$cxxclassname</tt> is replaced with the name of the class inside this typemap expansion and <tt>$cclassptrname</tt> is replaced with the name of the pointer type used to represent the class in C wrapper functions.
</td>
</tr>
</table>
<H3>C Typemaps, a Code Generation Walkthrough</H3>
To get a better idea of which typemap is used for which generated code, have a look at the following 'walk through'.</br>
Let's assume we have the following C++ interface file, we'd like to generate code for:
<H4>The Interface</H4>
<div class="code"><pre>
%module example
%inline
%{
class SomeClass{};
template &lt;typename T&gt; class SomeTemplateClass{};
SomeClass someFunction(SomeTemplateClass&lt;int&gt; &someParameter, int simpleInt);
%}
%template (SomeIntTemplateClass) SomeTemplateClass&lt;int&gt;;
</pre></div>
What we would like to generate as a C interface of this function would be something like this:
<div class="targetlang"><pre>
// wrapper header file
typedef struct SwigObj_SomeClass SomeClass;
SomeClass * SomeClass_new();
void SomeClass_delete(SomeClass * carg1);
SomeClass* someFunction(SomeIntTemplateClass* carg1, int carg2);
typedef struct SwigObj_SomeIntTemplateClass SomeIntTemplateClass;
SomeIntTemplateClass * SomeIntTemplateClass_new();
void SomeIntTemplateClass_delete(SomeIntTemplateClass * carg1);
</pre></div>
<H4>The Wrapper</H4>
We'll examine the generation of the wrapper function first.
<div class="targetlang"><pre>
SWIGEXPORTC SwigObj * module_someFunction(SwigObj * carg1, int carg2) {
SomeClass * cppresult;
SomeTemplateClass< int > *arg1 = 0 ;
int arg2 ;
SwigObj * result;
{
if (carg1)
arg1 = (SomeTemplateClass< int > *) carg1->obj;
else
arg1 = (SomeTemplateClass< int > *) 0;
}
arg2 = (int) carg2;
{
const SomeClass &_result_ref = someFunction(*arg1,arg2);cppresult = (SomeClass*) &_result_ref;
}
{
result = SWIG_create_object(cppresult, SWIG_STR(SomeClass));
}
return result;
}
</pre></div>
It might be helpful to think of the way function calls are generated as a composition of building blocks.</br>
A typical wrapper will be composited with these [optional] blocks:
<ol>
<li>Prototype</li>
<li>C return value variable</li>
<li>Local variables equal to the called C++ function's parameters</li>
<li>[C++ return value variable]</li>
<li>Assignment (extraction) of wrapper parameters to local parameter copies</li>
<li>[Contract (e.g. constraints) checking]</li>
<li> C++ function call</li>
<li>[Exception handling]</li>
<li>[Assignment to C++ return value]</li>
<li>Assignment to C return value</li>
</ol>
Let's go through it step by step and start with the wrapper prototype
<div class="targetlang"><pre>
ctype ctype ctype
--------- --------- ---
SwigObj * module_someFunction(SwigObj * carg1, int carg2);
</pre></div>
As first unit of the wrapper code, a variable to hold the return value of the function is emitted to the wrapper's body
<div class="targetlang"><pre>
ctype
---------
SwigObj * result;
</pre></div>
Now for each of the C++ function's arguments, a local variable with the very same type is emitted to the wrapper's body.
<div class="targetlang"><pre>
SomeTemplateClass< int > *arg1 = 0 ;
int arg2 ;
</pre></div>
If it's a C++ function that is wrapped (in this case it is), another variable is emitted for the 'original' return value of the C++ function.</br>
At this point, we simply 'inject' behavior if it's a C++ function that is wrapped (in this case it obviously is).
<div class="targetlang"><pre>
cppouttype
-----------
SomeClass * cppresult;
</pre></div>
Next, the values of the input parameters are assigned to the local variables using the 'in' typemap.
<div class="targetlang"><pre>
{
if (carg1)
arg1 = (SomeTemplateClass< int > *) carg1->obj;
else
arg1 = (SomeTemplateClass< int > *) 0;
}
arg2 = (int) carg2;
</pre></div>
A reasonable question would be: "Why aren't the parameters assigned in the declaration of their local counterparts?"</br>
As seen above, for complex types pointers have to be verified before extracting and </br>
casting the actual data pointer from the provided SwigObj pointer.</br>
This could easily become messy if it was done in the same line with the local variable declaration.</br>
<p>
At this point we are ready to call the C++ function with our parameters.</br>
</p>
<div class="targetlang"><pre>
{
const SomeClass &_result_ref = someFunction(*arg1,arg2);cppresult = (SomeClass*) &_result_ref;
}
</pre></div>
Subsequently, the return value is assigned to the dedicated return value variable using the 'out' typemap
<div class="targetlang"><pre>
{
result = SWIG_create_object(cppresult, SWIG_STR(SomeClass));
}
</pre></div>
Finally, the return value variable is returned.
<div class="targetlang"><pre>
return result;
</pre></div>
Note that typemaps may use <tt>$null</tt> special variable which will be
replaced with either <tt>0</tt> or nothing, depending on whether the function
has a non-void return value or not.
<H4>The Proxy</H4>
Compared to the wrapper code generation, the header code is very simple.</br>
Basically it contains just the declarations corresponding to the definitions
above.
<div class="targetlang"><pre>
// wrapper header file
typedef struct SwigObj_SomeClass SomeClass;
SomeClass * SomeClass_new();
void SomeClass_delete(SomeClass * carg1);
SomeClass* someFunction(SomeIntTemplateClass* carg1, int carg2);
typedef struct SwigObj_SomeIntTemplateClass SomeIntTemplateClass;
SomeIntTemplateClass * SomeIntTemplateClass_new();
void SomeIntTemplateClass_delete(SomeIntTemplateClass * carg1);
</pre></div>
<H2><a name="C_exceptions"></a>36.5 Exception handling</H2>
<p>
Any call to a C++ function may throw an exception, which cannot be caught by C code. Instead, the special <tt>SWIG_CException_get_pending()</tt> function must be called to check for this. If it returns a non-null pointer, <tt>SWIG_CException_msg_get()</tt> can be called to retrieve the error message associated with the exception. Finally, <tt>SWIG_CException_reset_pending()</tt> must be called to free the exception object and reset the current pending exception. Note that exception handling is much simpler when using C++, rather than C, wrappers, see sections 36.6.2.
</p>
<H2><a name="C_cxx_wrappers"></a>36.6 C++ Wrappers</H2>
<p>
When <tt>-c++</tt> command line option is used (and <tt>-nocxx</tt> one is not), the header file generated by SWIG will also contain the declarations of C++ wrapper functions and classes mirroring the original API. All C++ wrappers are fully inline, i.e. don't need to be compiled separately, and are always defined inside the namespace (or nested namespaces) specified by <tt>-namespace</tt> command-line option or the namespace with the same name as the SWIG module name if this option is not specified.
</p>
<p>
C++ wrappers try to provide a similar API to the original C++ API being wrapped, notably any class <tt>Foo</tt> in the original API appears as a class with the same name in the wrappers namespace, and has the same, or similar, public methods. A class <tt>Bar</tt> deriving from <tt>Foo</tt> also derives from it in the wrappers and so on. There are some differences with the original API, however. Some of them are due to fundamental limitations of the approach used, e.g.:
<ul>
<li>Only template instantiations are present in the wrappers, not the templates themselves.</li>
</ul>
Other ones are due to things that could be supported but haven't been implemented yet:
<ul>
<li>Only single, not multiple, inheritance is currently supported.</li>
<li>Only enums using <tt>int</tt> (or smaller type) as underlying type are supported.</li>
</ul>
</p>
<H3>36.6.1 Additional customization possibilities</H3>
Generated C++ code can be customized by inserting custom code in the following sections:
<ul>
<li><tt>cxxheader</tt> for including additional headers and other declarations in the global scope.</li>
<li><tt>cxxcode</tt> for additional code to appear after the declarations of all wrapper classes, inside the module-specific namespace.</li>
</ul>
The following features are taken into account when generating C++ wrappers:
<ul>
<li><tt>cxxignore</tt> May be set to skip generation of C++ wrappers for the given function or class, while still generating C wrappers for them.</li>
</ul>
<H3>36.6.2 Exception handling</H3>
<p>
Exception handling in C++ is more natural, as the exceptions are re-thrown when using C++ wrappers and so can be caught, as objects of the special <tt>SWIG_CException</tt> type, using the usual <tt>try/catch</tt> statement. The objects of <tt>SWIG_CException</tt> class have <tt>code()</tt> and <tt>msg()</tt> methods, with the latter returning the error message associated with the exception.
</p>
<p>
If necessary, a custom exception type may be used instead of <tt>SWIG_CException</tt>. To do this, a custom implementation of <tt>swig_check()</tt> function, called to check for the pending exception and throw the corresponding C++ exception if necessary, must be provided and <tt>SWIG_swig_check_DEFINED</tt> preprocessor symbol must be defined to prevent the default implementation of this function from being compiled:
</p>
<div class="code"><pre>
%insert(cxxheader) %{
#ifndef SWIG_swig_check_DEFINED
#define SWIG_swig_check_DEFINED 1
#include <stdexcept>
class Exception : public std::runtime_error {
public:
explicit Exception(const char* msg) : std::runtime_error{msg} {}
};
inline void swig_check() {
if (auto* swig_ex = SWIG_CException_get_pending()) {
Exception const e{SWIG_CException_msg_get(swig_ex)};
SWIG_CException_reset_pending();
throw e;
}
}
template <typename T> T swig_check(T x) {
swig_check();
return x;
}
#endif // SWIG_swig_check_DEFINED
%}
</pre></div>
</body>
</html>

View file

@ -20,6 +20,7 @@ Warnings.html
Modules.html
CCache.html
Android.html
C.html
CSharp.html
D.html
Go.html

View file

@ -1472,6 +1472,377 @@ ruby_clean:
rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *$(RUBY_SO)
##################################################################
##### PHP ######
##################################################################
PHP = @PHP@
PHP_INCLUDE = @PHPINC@
PHP_SO = @PHP_SO@
PHP_SCRIPT = $(SRCDIR)$(RUNME).php
PHP_EXTENSION = example$(PHP_SO)
# -------------------------------------------------------------------
# Build a PHP dynamically loadable module (C)
# -------------------------------------------------------------------
php: $(SRCDIR_SRCS)
$(SWIG) -php $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
$(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES) $(PHP_INCLUDE)
$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(PHP_SO)
# --------------------------------------------------------------------
# Build a PHP dynamically loadable module (C++)
# --------------------------------------------------------------------
php_cpp: $(SRCDIR_SRCS)
$(SWIG) -php -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(PHP_INCLUDE)
$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(PHP_SO)
# -----------------------------------------------------------------
# Running a PHP example
# -----------------------------------------------------------------
php_run:
$(RUNTOOL) $(PHP) -n -d extension_dir=. -d extension=$(PHP_EXTENSION) -d display_errors=stderr -r 'set_error_handler(function($$n,$$s,$$f,$$l){if($$f!==Null){print$$f;if($$l!==Null)print":$$l";print": ";}print"$$s\n";exit(1);});if(strlen($$argv[1]))include($$argv[1]);' '$(PHP_SCRIPT)' $(RUNPIPE)
# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------
php_version:
$(PHP) -v | head -n 1
# -----------------------------------------------------------------
# Cleaning the PHP examples
# -----------------------------------------------------------------
php_clean:
rm -f *_wrap* *~ .~* example.php php_example.h
rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *$(PHP_SO)
##################################################################
##### CSHARP ######
##################################################################
# Extra CSharp specific dynamic linking options
CSHARP_DLNK = @CSHARPDYNAMICLINKING@
CSHARP_LIBPREFIX = @CSHARPLIBRARYPREFIX@
CSHARPCOMPILER = @CSHARPCOMPILER@
CSHARPCILINTERPRETER = @CSHARPCILINTERPRETER@
CSHARPCILINTERPRETER_FLAGS = @CSHARPCILINTERPRETER_FLAGS@
CSHARPCFLAGS = @CSHARPCFLAGS@
CSHARPFLAGS =
CSHARPOPTIONS =
CSHARPSO = @CSHARPSO@
CSHARP_RUNME = ./$(RUNME).exe
# ----------------------------------------------------------------
# Build a CSharp dynamically loadable module (C)
# ----------------------------------------------------------------
csharp: $(SRCDIR_SRCS)
$(SWIG) -csharp $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
$(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(CSHARPCFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES)
$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(CSHARP_DLNK) $(LIBS) -o $(CSHARP_LIBPREFIX)$(TARGET)$(CSHARPSO)
# ----------------------------------------------------------------
# Build a CSharp dynamically loadable module (C++)
# ----------------------------------------------------------------
csharp_cpp: $(SRCDIR_SRCS)
$(SWIG) -csharp -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(CSHARPCFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES)
$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(CSHARP_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(CSHARP_LIBPREFIX)$(TARGET)$(CSHARPSO)
# ----------------------------------------------------------------
# Compile CSharp files
# ----------------------------------------------------------------
ifneq (,$(SRCDIR))
SRCDIR_CSHARPSRCS = $(addprefix $(SRCDIR),$(CSHARPSRCS))
else
SRCDIR_CSHARPSRCS =
endif
csharp_compile: $(SRCDIR_SRCS)
$(COMPILETOOL) $(CSHARPCOMPILER) $(CSHARPFLAGS) $(CSHARPOPTIONS) $(CSHARPSRCS) $(SRCDIR_CSHARPSRCS)
# -----------------------------------------------------------------
# Run CSharp example
# -----------------------------------------------------------------
csharp_run:
env LD_LIBRARY_PATH=$$PWD $(RUNTOOL) $(CSHARPCILINTERPRETER) $(CSHARPCILINTERPRETER_FLAGS) $(CSHARP_RUNME) $(RUNPIPE)
# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------
# Version check below also works with MS csc.exe which does not understand --version
csharp_version:
$(CSHARPCOMPILER) --version | head -n 1
if test -n "$(CSHARPCILINTERPRETER)" ; then "$(CSHARPCILINTERPRETER)" --version ; fi
# -----------------------------------------------------------------
# Cleaning the CSharp examples
# -----------------------------------------------------------------
csharp_clean:
rm -f *_wrap* *~ .~* $(RUNME) $(RUNME).exe *.exe.mdb gc.log `find . -name \*.cs | grep -v $(RUNME).cs`
rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *@CSHARPSO@
##################################################################
##### LUA ######
##################################################################
# lua flags
LUA_INCLUDE= @LUAFLAGS@
LUA_LIB = @LUALINK@
# Extra specific dynamic linking options
LUA_DLNK = @LUADYNAMICLINKING@
LUA_SO = @LUA_SO@
LUA = @LUABIN@
LUA_SCRIPT = $(SRCDIR)$(RUNME).lua
# Extra code for lua static link
LUA_INTERP = ../lua.c
# ----------------------------------------------------------------
# Build a C dynamically loadable module
# ----------------------------------------------------------------
lua: $(SRCDIR_SRCS)
$(SWIG) -lua $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
$(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) $(LUA_INCLUDE)
$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(LUA_LIB) -o $(LIBPREFIX)$(TARGET)$(LUA_SO)
# -----------------------------------------------------------------
# Build a C++ dynamically loadable module
# -----------------------------------------------------------------
lua_cpp: $(SRCDIR_SRCS) $(GENCXXSRCS)
$(SWIG) -c++ -lua $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(GENCXXSRCS) $(INCLUDES) $(LUA_INCLUDE)
$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(LUA_LIB) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(LUA_SO)
lua_externalhdr:
$(SWIG) -lua -external-runtime $(TARGET)
lua_swig_cpp:
$(SWIG) -c++ -lua $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
# -----------------------------------------------------------------
# Build statically linked Lua interpreter
# -----------------------------------------------------------------
lua_static: $(SRCDIR_SRCS)
$(SWIG) -lua -module example $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(SRCDIR)$(LUA_INTERP) $(INCLUDES) \
$(LUA_INCLUDE) $(LIBS) $(LUA_LIB) -o $(TARGET)
lua_static_cpp: $(SRCDIR_SRCS) $(GENCXXSRCS)
$(SWIG) -c++ -lua -module example $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(GENCXXSRCS) $(SRCDIR)$(LUA_INTERP) $(INCLUDES) \
$(LUA_INCLUDE) $(LIBS) $(LUA_LIB) -o $(TARGET)
# -----------------------------------------------------------------
# Run Lua example
# -----------------------------------------------------------------
lua_run:
$(RUNTOOL) $(LUA) $(LUA_SCRIPT) $(RUNPIPE)
lua_embed_run:
$(RUNTOOL) ./$(TARGET) $(LUA_SCRIPT) $(RUNPIPE)
# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------
lua_version:
$(LUA) -v | head -n 1
# -----------------------------------------------------------------
# Cleaning the lua examples
# -----------------------------------------------------------------
lua_clean:
rm -f *_wrap* *~ .~* mylua@EXEEXT@
rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *$(LUA_SO)
##################################################################
##### CFFI ######
##################################################################
CFFI = @CFFIBIN@
CFFI_SCRIPT=$(RUNME).lisp
cffi: $(SRCDIR_SRCS)
$(SWIG) -cffi $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
# $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCDIR_SRCS)
# $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
cffi_cpp: $(SRCDIR_SRCS)
$(SWIG) -c++ -cffi $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES)
$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
# -----------------------------------------------------------------
# Run CFFI example
# -----------------------------------------------------------------
cffi_run:
$(RUNTOOL) $(CFFI) -batch -s $(CFFI_SCRIPT) $(RUNPIPE)
# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------
cffi_version:
$(CFFI) --version
# -----------------------------------------------------------------
# Cleaning the CFFI examples
# -----------------------------------------------------------------
cffi_clean:
rm -f *_wrap* *~ .~*
rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *@SO@
##################################################################
##### R ######
##################################################################
R = R
RCXXSRCS = $(INTERFACE:.i=_wrap.cpp) #Need to use _wrap.cpp for R build system as it does not understand _wrap.cxx
RRSRC = $(INTERFACE:.i=.R)
R_CFLAGS=-fPIC
R_OPT = --slave --quiet --no-save --no-restore
R_SCRIPT=$(SRCDIR)$(RUNME).R
# need to compile .cxx files outside of R build system to make sure that
# we get -fPIC
# CMD SHLIB stdout is piped to /dev/null to prevent echo of compiler command
# ----------------------------------------------------------------
# Build a R dynamically loadable module (C)
# ----------------------------------------------------------------
r: $(SRCDIR_SRCS)
$(SWIG) -r $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
ifneq ($(SRCDIR_SRCS),)
$(CC) -g -c $(CPPFLAGS) $(CFLAGS) $(R_CFLAGS) $(SRCDIR_SRCS) $(INCLUDES)
endif
+( PKG_CPPFLAGS="$(CPPFLAGS) $(INCLUDES)" PKG_CFLAGS="$(CFLAGS)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(ISRCS) $(OBJS) > /dev/null )
# ----------------------------------------------------------------
# Build a R dynamically loadable module (C++)
# ----------------------------------------------------------------
r_cpp: $(SRCDIR_CXXSRCS)
$(SWIG) -c++ -r $(SWIGOPT) -o $(RCXXSRCS) $(INTERFACEPATH)
ifneq ($(SRCDIR_CXXSRCS),)
$(CXX) -g -c $(CPPFLAGS) $(CXXFLAGS) $(R_CFLAGS) $(SRCDIR_CXXSRCS) $(INCLUDES)
endif
+( PKG_CPPFLAGS="$(CPPFLAGS) $(INCLUDES)" PKG_CXXFLAGS="$(CXXFLAGS)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(RCXXSRCS) $(OBJS) > /dev/null )
# -----------------------------------------------------------------
# Run R example
# -----------------------------------------------------------------
r_run:
$(RUNTOOL) $(R) $(R_OPT) -f $(R_SCRIPT) $(RUNPIPE)
# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------
r_version:
$(R) --version | head -n 1
# -----------------------------------------------------------------
# Cleaning the R examples
# -----------------------------------------------------------------
r_clean:
rm -f *_wrap* *~ .~*
rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *@SO@ NAMESPACE
rm -f $(RRSRC) $(RUNME).Rout .RData
##################################################################
##### C ######
##################################################################
# ----------------------------------------------------------------
# Build a C dynamically loadable module
# ----------------------------------------------------------------
CLIBPREFIX = lib
C_LDSHARED = @C_LDSHARED@
CXX_LDSHARED = @CXX_LDSHARED@
C_SO = @C_SO@
c: $(SRCDIR_SRCS)
$(SWIG) -c $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
$(CC) -c $(CCSHARED) -I$(SRCDIR) $(CFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES)
$(COMPILETOOL) $(C_LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(CLIBPREFIX)$(TARGET)$(C_SO)
c_cpp: $(SRCDIR_SRCS)
$(SWIG) -c++ -c $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
$(CXX) -c $(CCSHARED) -I$(SRCDIR) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_CXXSRCS) $(INCLUDES)
$(COMPILETOOL) $(CXX_LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(CLIBPREFIX)$(TARGET)$(C_SO)
c_compile_c: $(SRCDIR)$(RUNME).c
$(COMPILETOOL) $(CC) $(CFLAGS) -o $(RUNME)_$(RUNME_EXT) -I. -I.. $< -L. -l$(TARGET)
c_compile_cxx: $(SRCDIR)$(RUNME).cxx
$(COMPILETOOL) $(CXX) $(CXXFLAGS) -o $(RUNME)_$(RUNME_EXT) -I. -I.. $< -L. -l$(TARGET)
$(eval c_compile: c_compile_$(RUNME_EXT))
# This target is used for the unit tests: if we don't have any test code to
# run, we at least can check that the generated header can be included without
# giving any syntax errors, both when compiling it as C and C++ code.
c_syntax_check: c_syntax_check_c c_syntax_check_cxx
c_syntax_check_c:
$(CC) -fsyntax-only -x c -I$(SRCDIR)$(INTERFACEDIR) $(C_HEADER)
c_syntax_check_cxx:
$(CXX) -fsyntax-only -x c++ -I$(SRCDIR)$(INTERFACEDIR) $(C_HEADER)
# -----------------------------------------------------------------
# Run C example
# -----------------------------------------------------------------
c_run: c_compile
env LD_LIBRARY_PATH=$$PWD $(RUNTOOL) ./$(RUNME)_$(RUNME_EXT) $(RUNPIPE)
# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------
c_version:
$(CC) --version | head -n 1
# -----------------------------------------------------------------
# Cleaning the C examples
# -----------------------------------------------------------------
c_clean:
rm -f *_wrap.[ch] *_wrap.cxx
rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *@SO@
rm -f $(RUNME)_c $(RUNME)_cxx
##################################################################
##### SCILAB ######
##################################################################

5
Examples/c/check.list Normal file
View file

@ -0,0 +1,5 @@
# see top-level Makefile.in
simple
class
std_vector
exception

24
Examples/c/class/Makefile Normal file
View file

@ -0,0 +1,24 @@
TOP = ../..
SWIGEXE = $(TOP)/../swig
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
check_c: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' RUNME_EXT=c c_run
check_cxx: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' RUNME_EXT=cxx c_run
check: check_c check_cxx
build:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' c_cpp
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' c_clean

View file

@ -0,0 +1,28 @@
/* File : example.cxx */
#include "example.h"
#define M_PI 3.14159265358979323846
/* Move the shape to a new location */
void Shape::move(double dx, double dy) {
x += dx;
y += dy;
}
int Shape::nshapes = 0;
double Circle::area() {
return M_PI*radius*radius;
}
double Circle::perimeter() {
return 2*M_PI*radius;
}
double Square::area() {
return width*width;
}
double Square::perimeter() {
return 4*width;
}

View file

@ -0,0 +1,34 @@
/* File : example.h */
class Shape {
public:
Shape() {
nshapes++;
}
virtual ~Shape() {
nshapes--;
}
double x, y;
void move(double dx, double dy);
virtual double area() = 0;
virtual double perimeter() = 0;
static int nshapes;
};
class Circle : public Shape {
private:
double radius;
public:
Circle(double r) : radius(r) { }
virtual double area();
virtual double perimeter();
};
class Square : public Shape {
private:
double width;
public:
Square(double w) : width(w) { }
virtual double area();
virtual double perimeter();
};

View file

@ -0,0 +1,9 @@
/* File : example.i */
%module example
%{
#include "example.h"
%}
/* Let's just grab the original header file here */
%include "example.h"

44
Examples/c/class/runme.c Normal file
View file

@ -0,0 +1,44 @@
#include <stdio.h>
#include "example_wrap.h"
int main(int argc, char **argv) {
printf("Creating some objects from C:\n");
Circle* c = Circle_new(10);
printf(" Created circle\n");
Square* s = Square_new(10);
printf(" Created square\n");
printf("\nA total of %d shapes were created\n", Shape_nshapes_get());
Circle_x_set(c, 20);
Circle_y_set(c, 30);
Shape* shape = (Shape*) s;
Shape_x_set(shape, -10);
Shape_y_set(shape, 5);
printf("\nHere is their current positions:\n");
printf(" Circle = (%f %f)\n", Circle_x_get(c), Circle_y_get(c));
printf(" Square = (%f %f)\n", Square_x_get(s), Square_y_get(s));
printf("\nHere are some properties of the shapes:\n");
Shape* shapes[] = {(Shape*) c, (Shape*) s};
int i;
for (i = 0; i < 2; i++) {
printf(" %s\n", i ? "Square" : "Circle");
printf(" area = %f\n", Shape_area(shapes[i]));
printf(" perimeter = %f\n", Shape_perimeter(shapes[i]));
}
printf("\nGuess I'll clean up now\n");
Square_delete(s);
Circle_delete(c);
printf("%d shapes remain\n", Shape_nshapes_get());
printf("Goodbye from C\n");
return 0;
}

View file

@ -0,0 +1,41 @@
#include <iostream>
#include "example_wrap.h"
int main(int argc, char **argv) {
{ // Block containing the Circle and Square objects.
std::cout << "Creating some objects from C++:\n";
example::Circle c(10);
std::cout << " Created circle\n";
example::Square s(10);
std::cout << " Created square\n";
std::cout << "\nA total of " << example::Shape::nshapes() << " shapes were created\n";
c.x(20);
c.y(30);
example::Shape& shape = s;
shape.x(-10);
shape.y(5);
std::cout << "\nHere is their current positions:\n";
std::cout << " Circle = (" << c.x() << " " << c.y() << ")\n";
std::cout << " Square = (" << s.x() << " " << s.y() << ")\n";
std::cout << "\nHere are some properties of the shapes:\n";
example::Shape* shapes[] = {&c, &s};
for (int i = 0; i < 2; i++) {
std::cout << " " << (i ? "Square" : "Circle") << "\n";
std::cout << " area = " << shapes[i]->area() << "\n";
std::cout << " perimeter = " << shapes[i]->perimeter() << "\n";
}
std::cout << "\nGuess I'll clean up now\n";
}
std::cout << example::Shape::nshapes() << " shapes remain\n";
std::cout << "Goodbye from C++\n";
return 0;
}

View file

@ -0,0 +1,24 @@
TOP = ../..
SWIGEXE = $(TOP)/../swig
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
check_c: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' RUNME_EXT=c c_run
check_cxx: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' RUNME_EXT=cxx c_run
check: check_c check_cxx
build:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' c_cpp
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' c_clean

View file

View file

@ -0,0 +1,45 @@
/* File : example.h */
#include <string.h>
#ifndef SWIG
struct A {
};
#define SWIG_THROW(...)
#endif
class Exc {
public:
Exc(int c, const char *m) {
code = c;
strncpy(msg,m,255);
}
int code;
char msg[256];
};
class Test {
public:
int simple() SWIG_THROW(int&) {
throw(37);
return 1;
}
int message() SWIG_THROW(const char *) {
throw("I died.");
return 1;
}
int hosed() SWIG_THROW(Exc) {
throw(Exc(42,"Hosed"));
return 1;
}
int unknown() SWIG_THROW(A*) {
static A a;
throw &a;
return 1;
}
int multi(int x) SWIG_THROW(int, const char *, Exc) {
if (x == 1) throw(37);
if (x == 2) throw("Bleah!");
if (x == 3) throw(Exc(42,"No-go-diggy-die"));
return 1;
}
};

View file

@ -0,0 +1,17 @@
/* File : example.i */
%module example
%{
#include "example.h"
%}
%typemap(throws, noblock="1") Exc {
SWIG_exception(SWIG_RuntimeError, $1.msg);
}
/* This needs to be defined for SWIG, even though it can't be used in C++ any more. */
#define SWIG_THROW(...) throw(__VA_ARGS__)
/* Let's just grab the original header file here */
%include "example.h"

View file

@ -0,0 +1,47 @@
/*
* NOTE: this won't run with -noexcept flag
*/
#include <stdio.h>
#include <assert.h>
#include "example_wrap.h"
static void show_exception(const char* prefix) {
SWIG_CException* ex = SWIG_CException_get_pending();
assert(ex);
printf("%s exception: %s (%d)\n", prefix, SWIG_CException_msg_get(ex), SWIG_CException_code_get(ex));
SWIG_CException_reset_pending();
}
int main() {
Test *t = Test_new();
Test_unknown(t);
show_exception("Unknown");
Test_simple(t);
show_exception("Int");
Test_message(t);
show_exception("String");
Test_hosed(t);
show_exception("Custom");
int i;
for (i = 0; i < 4; ++i) {
Test_multi(t, i);
if (!SWIG_CException_get_pending()) {
printf("Success for i=%d\n", i);
} else {
printf("For i=%d", i);
show_exception("");
}
}
Test_delete(t);
return 0;
}

View file

@ -0,0 +1,69 @@
/*
* NOTE: this won't run with -noexcept flag
*/
#include <stdio.h>
#include <assert.h>
#include "example_wrap.h"
using Exception = example::SWIG_CException;
static int exit_code = 0;
static void show_exception(const char* prefix, Exception const& ex) {
printf("%s exception: %s (%d)\n", prefix, ex.msg(), ex.code());
}
static void missing_exception(const char* prefix) {
printf("*** ERROR: %s: expected exception not thrown.\n", prefix);
exit_code++;
}
int main() {
example::Test t;
try {
t.unknown();
missing_exception("Unknown");
} catch (Exception const& e) {
show_exception("Unknown", e);
}
try {
t.simple();
missing_exception("Int");
} catch (Exception const& e) {
show_exception("Int", e);
}
try {
t.message();
missing_exception("String");
} catch (Exception const& e) {
show_exception("String", e);
}
try {
t.hosed();
missing_exception("Custom");
} catch (Exception const& e) {
show_exception("Custom", e);
}
for (int i = 0; i < 4; ++i) {
try {
t.multi(i);
if (i == 0) {
printf("Success for i=%d\n", i);
} else {
missing_exception("Multi");
}
} catch (Exception const& e) {
printf("For i=%d", i);
show_exception("", e);
}
}
return exit_code;
}

View file

@ -0,0 +1,18 @@
TOP = ../..
SWIGEXE = $(TOP)/../swig
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
SRCS = example.c
TARGET = example
INTERFACE = example.i
check: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' RUNME_EXT=c c_run
build:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' c
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' c_clean

View file

@ -0,0 +1,18 @@
/* File : example.c */
/* A global variable */
double Foo = 3.0;
/* Compute the greatest common divisor of positive integers */
int gcd(int x, int y) {
int g;
g = y;
while (x > 0) {
g = x;
x = y % x;
y = g;
}
return g;
}

View file

@ -0,0 +1,7 @@
/* File : example.i */
%module example
%inline %{
extern int gcd(int x, int y);
extern double Foo;
%}

15
Examples/c/simple/runme.c Normal file
View file

@ -0,0 +1,15 @@
#include <stdio.h>
#include "example_wrap.h"
int main(int argc, char **argv) {
int a = 42;
int b = 105;
int g = example_gcd(a, b);
printf("The gcd of %d and %d is %d\n", a, b, g);
printf("Foo = %f\n", Foo);
Foo = 3.1415926;
printf("Foo = %f\n", Foo);
return 0;
}

View file

@ -0,0 +1,18 @@
TOP = ../..
SWIGEXE = $(TOP)/../swig
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
check: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' RUNME_EXT=c c_run
build:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' c_cpp
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' c_clean

View file

@ -0,0 +1,2 @@
/* File : example.c */

View file

@ -0,0 +1,18 @@
/* File : example.h */
#include <string>
#include <vector>
class A {
public:
A() : name(""), value(0) {}
A(std::string str, int i) : name(str), value(i) {}
std::string name;
int value;
};
class Klass {
public:
std::vector<int> vi;
std::vector<A> va;
};

View file

@ -0,0 +1,14 @@
/* File : example.i */
%module example
%include <std_string.i>
%include <std_vector.i>
%{
#include "example.h"
%}
/* Let's just grab the original header file here */
%include "example.h"
%template(Vint) std::vector<int>;
%template(VA) std::vector<A>;

View file

@ -0,0 +1,42 @@
#include <stdio.h>
#include "example_wrap.h"
int main() {
Klass *klass = Klass_new();
Vint *vint = Klass_vi_get(klass);
VA *va = Klass_va_get(klass);
printf("Vector of ints:\n");
printf("size=%zd\ncapacity=%zd\n\n", Vint_size(vint), Vint_capacity(vint));
int i;
for (i = 0; i < 10; i++)
Vint_push_back(vint, i*i);
printf("size=%zd\ncapacity=%zd\n\n", Vint_size(vint), Vint_capacity(vint));
for (i = 0; i < Vint_size(vint); i++)
printf("%d%c", Vint_get(vint, i), i+1 == Vint_size(vint) ? '\n' : ',');
Vint_clear(vint);
Vint_reserve(vint, 100);
printf("\nsize=%zd\ncapacity=%zd\n", Vint_size(vint), Vint_capacity(vint));
printf("\nVector of objects:\n");
for (i = 0; i < 10; i++) {
A *a = A_new_std_string_i("hello", i);
VA_push_back(va, a);
A_delete(a);
}
for (i = 0; i < VA_size(va); i++) {
A *a = VA_get(va, i);
printf("%s %d\n", A_name_get(a), A_value_get(a));
}
Klass_delete(klass);
return 0;
}

View file

@ -1,6 +1,6 @@
%module argcargvtest
#if !defined(SWIGCSHARP) && !defined(SWIGD) && !defined(SWIGGO) && !defined(SWIGGUILE) && !defined(SWIGJAVA) && !defined(SWIGJAVASCRIPT) && !defined(SWIGMZSCHEME) && !defined(SWIGOCAML) && !defined(SWIGR) && !defined(SWIGSCILAB)
#if !defined(SWIGC) && !defined(SWIGCSHARP) && !defined(SWIGD) && !defined(SWIGGO) && !defined(SWIGGUILE) && !defined(SWIGJAVA) && !defined(SWIGJAVASCRIPT) && !defined(SWIGMZSCHEME) && !defined(SWIGOCAML) && !defined(SWIGR) && !defined(SWIGSCILAB)
%include <argcargv.i>
%apply (int ARGC, char **ARGV) { (size_t argc, const char **argv) }

View file

@ -0,0 +1,239 @@
#######################################################################
# Makefile for C test-suite
#######################################################################
LANGUAGE = c
C = gcc
CXX = g++
RUNMESUFFIX = _runme
srcdir = @srcdir@
top_srcdir = ../@top_srcdir@
top_builddir = ../@top_builddir@
# This can be set to ":" to avoid progress messages.
ECHO_PROGRESS := echo
CPP_TEST_CASES := \
c_backend_cpp_natural_std_string \
c_backend_cpp_exception
CPP11_TEST_CASES := \
cpp11_shared_ptr_const \
cpp11_shared_ptr_nullptr_in_containers \
cpp11_shared_ptr_overload \
cpp11_shared_ptr_upcast \
# The following tests are currently broken and need to be fixed.
FAILING_C_TESTS := \
arrays \
funcptr \
function_typedef \
lextype \
li_carrays \
nested \
nested_extend_c \
nested_structs \
typedef_struct \
union_parameter \
unions \
FAILING_CPP_TESTS := \
apply_signed_char \
array_member \
array_typedef_memberin \
arrayref \
arrays_dimensionless \
arrays_global \
arrays_global_twodim \
constant_pointers \
enum_thorough \
extend \
extend_default \
extern_c \
extern_template_method \
funcptr_cpp \
global_scope_types \
grouping \
import_nomodule \
li_attribute \
li_attribute_template \
li_boost_shared_ptr_attribute \
li_std_auto_ptr \
li_std_deque \
li_std_wstring \
li_windows \
member_funcptr_galore \
member_pointer \
member_pointer_const \
mixed_types \
nested_class \
template_basic \
template_default \
template_enum \
template_explicit \
template_typedef_fnc \
typedef_array_member \
typedef_funcptr \
typedef_struct_cpp \
typemap_namespace \
typemap_various \
using_extend \
varargs \
varargs_overload \
virtual_poly \
cpp11_ref_qualifiers \
cpp11_ref_qualifiers_typemaps \
cpp11_result_of \
cpp11_rvalue_reference \
cpp11_rvalue_reference2 \
cpp11_rvalue_reference3 \
cpp11_type_aliasing \
# Ignore warnings about failing to apply typemaps because none are defined:
# usually there is no need for special typemaps in C.
char_binary.cpptest director_binary_string.cpptest li_typemaps.cpptest li_typemaps_apply.cpptest long_long_apply.cpptest: SWIGOPT += -w453
include $(srcdir)/../common.mk
# Overridden variables here
# Suppress warnings about experimental status and unsupported features -- there are just too many of those for now for these warnings to be useful.
SWIGOPT += -w524 -w779
%.ctest: SWIGOPT += -nocxx
# Tests for which C++ wrappers currently don't compile.
contract.cpptest: SWIG_NOCXX = -nocxx # Class derived from a base class with multiple base classes and hence ignored.
conversion.cpptest: SWIG_NOCXX = -nocxx # Conversion operator return type not handled specially.
conversion_namespace.cpptest: SWIG_NOCXX = -nocxx # Conversion operator name not handled correctly.
conversion_ns_template.cpptest: SWIG_NOCXX = -nocxx # Conversion operator return not handled specially.
cpp11_default_delete.cpptest: SWIG_NOCXX = -nocxx # Assignment operator and r-value references not handled.
cpp11_explicit_conversion_operators.cpptest: SWIG_NOCXX = -nocxx # Conversion operator return type.
cpp11_noexcept.cpptest: SWIG_NOCXX = -nocxx # Assignment operator.
default_constructor.cpptest: SWIG_NOCXX = -nocxx # Something weird with OSRSpatialReferenceShadow.
director_conversion_operators.cpptest: SWIG_NOCXX = -nocxx # Conversion operator return type.
director_frob.cpptest: SWIG_NOCXX = -nocxx # Conversion operator return type.
extend_template_method.cpptest: SWIG_NOCXX = -nocxx # Wrong form of template function name.
features.cpptest: SWIG_NOCXX = -nocxx # Conversion operator return type not handled specially.
global_namespace.cpptest: SWIG_NOCXX = -nocxx # Const const reference type.
li_carrays_cpp.cpptest: SWIG_NOCXX = -nocxx # Arrays not really supported currently.
li_cdata_cpp.cpptest: SWIG_NOCXX = -nocxx # No support for multiarg typemaps required here.
member_template.cpptest: SWIG_NOCXX = -nocxx # Wrong form of template function name.
multiple_inheritance_abstract.cpptest: SWIG_NOCXX = -nocxx # Multiple inheritance not supported.
multiple_inheritance_interfaces.cpptest: SWIG_NOCXX = -nocxx
multiple_inheritance_nspace.cpptest: SWIG_NOCXX = -nocxx
multiple_inheritance_shared_ptr.cpptest: SWIG_NOCXX = -nocxx
namespace_class.cpptest: SWIG_NOCXX = -nocxx # Many broken type names.
operator_pointer_ref.cpptest: SWIG_NOCXX = -nocxx
operbool.cpptest: SWIG_NOCXX = -nocxx
overload_null.cpptest: SWIG_NOCXX = -nocxx
overload_template.cpptest: SWIG_NOCXX = -nocxx
overload_template_fast.cpptest: SWIG_NOCXX = -nocxx
pure_virtual.cpptest: SWIG_NOCXX = -nocxx
rename1.cpptest: SWIG_NOCXX = -nocxx
rename2.cpptest: SWIG_NOCXX = -nocxx
rename3.cpptest: SWIG_NOCXX = -nocxx
rename4.cpptest: SWIG_NOCXX = -nocxx
rename_wildcard.cpptest: SWIG_NOCXX = -nocxx
return_const_value.cpptest: SWIG_NOCXX = -nocxx
smart_pointer_member.cpptest: SWIG_NOCXX = -nocxx
smart_pointer_template_const_overload.cpptest: SWIG_NOCXX = -nocxx
smart_pointer_templatemethods.cpptest: SWIG_NOCXX = -nocxx # Wrong form of template function name.
struct_initialization_cpp.cpptest: SWIG_NOCXX = -nocxx # Arrays in initialization not supported.
template_const_ref.cpptest: SWIG_NOCXX = -nocxx
template_default_arg_overloaded.cpptest: SWIG_NOCXX = -nocxx
template_inherit_abstract.cpptest: SWIG_NOCXX = -nocxx
template_methods.cpptest: SWIG_NOCXX = -nocxx
template_nested.cpptest: SWIG_NOCXX = -nocxx
template_nested_flat.cpptest: SWIG_NOCXX = -nocxx
template_qualifier.cpptest: SWIG_NOCXX = -nocxx
template_static.cpptest: SWIG_NOCXX = -nocxx
typemap_array_qualifiers.cpptest: SWIG_NOCXX = -nocxx # Arrays not supported.
valuewrapper_const.cpptest: SWIG_NOCXX = -nocxx # Misplaced const.
# Avoid conflict with the C++ keyword for some tests.
SWIG_NS = $*
dynamic_cast.cpptest: SWIG_NS = dyn_cast
typename.cpptest: SWIG_NS = type_name
%.multicpptest: SWIGOPT += -namespace $*
%.cpptest: SWIGOPT += -namespace $(SWIG_NS) $(SWIG_NOCXX)
SRCDIR = ../$(srcdir)/
# Make function to check if we have an executable test for the given test base name.
define has_runme
-f $(srcdir)/$1$(RUNMESUFFIX).c -o -f $(srcdir)/$1$(RUNMESUFFIX).cxx
endef
# Rules for the different types of tests
%.cpptest:
$(setup)
+(cd $* && $(swig_and_compile_cpp))
+if [ $(call has_runme,$*) ]; then \
$(do_run_testcase); \
else \
cd $* && $(call syntax_check_testcase,$*); \
fi
%.ctest:
$(setup)
+(cd $* && $(swig_and_compile_c))
+if [ $(call has_runme,$*) ]; then \
$(do_run_testcase); \
else \
cd $* && $(call syntax_check_testcase,$*,_c); \
fi
%.multicpptest:
$(setup)
+(cd $* && $(swig_and_compile_multi_cpp))
+if [ $(call has_runme,$*) ]; then \
$(do_run_testcase); \
else \
cd $* && for f in `cat $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list`; do \
$(call syntax_check_testcase,$${f}) || exit 1; \
done; \
fi
# Makes a directory for the testcase if it does not exist
setup = \
if [ $(call has_runme,$*) ]; then \
$(ECHO_PROGRESS) "$(ACTION)ing testcase $* (with run test) under $(LANGUAGE)" ; \
else \
$(ECHO_PROGRESS) "$(ACTION)ing testcase $* under $(LANGUAGE)" ; \
fi; \
if [ ! -d $* ]; then \
mkdir $*; \
fi;
# Checks the header syntax if there is no runnable testcase for it.
#
# The optional second argument can be "_c" to check syntax using C compiler only
# (by default both C and C++ compilers are used).
syntax_check_testcase = \
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \
SRCDIR='$(SRCDIR)' \
INTERFACEDIR='$(INTERFACEDIR)' \
C_HEADER=$1_wrap.h \
c_syntax_check$2
# Compiles C files then runs the testcase unconditionally.
do_run_testcase = \
cd $* && $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \
SRCDIR='$(SRCDIR)' \
RUNME=$*$(RUNMESUFFIX) \
RUNME_EXT=$(patsubst .%,%,$(suffix $(wildcard $(srcdir)/$*$(RUNMESUFFIX).c*))) \
TARGET='$*' \
c_run
# Clean: remove testcase directories
%.clean:
@if [ -d $* ]; then \
rm -rf $*; \
fi;
clean:
@rm -f *_wrap.* *~ *.exe *.dll *.so *.out *runme

View file

@ -0,0 +1,12 @@
#include "abstract_access/abstract_access_wrap.h"
#include <assert.h>
int main(int argc, const char *argv[]) {
abstract_access_D *d = abstract_access_D_new();
assert(abstract_access_D_do_x(d) == 1);
abstract_access_D_delete(d);
return 0;
}

View file

@ -0,0 +1,12 @@
#include "abstract_inherit_ok_wrap.h"
#include <assert.h>
int main(int argc, const char *argv[]) {
abstract_inherit_ok_Foo* const spam = (abstract_inherit_ok_Foo*)abstract_inherit_ok_Spam_new();
assert(abstract_inherit_ok_Foo_blah(spam) == 0);
abstract_inherit_ok_Foo_delete(spam);
return 0;
}

View file

@ -0,0 +1,15 @@
#include "abstract_typedef/abstract_typedef_wrap.h"
#include <stdbool.h>
#include <assert.h>
int main(int argc, const char *argv[]) {
abstract_typedef_Engine *e = abstract_typedef_Engine_new();
abstract_typedef_A *a = abstract_typedef_A_new();
assert(abstract_typedef_AbstractBaseClass_write((abstract_typedef_AbstractBaseClass*)a, e) == true);
abstract_typedef_A_delete(a);
abstract_typedef_Engine_delete(e);
return 0;
}

View file

@ -0,0 +1,18 @@
#include "abstract_virtual/abstract_virtual_wrap.h"
#include <assert.h>
int main(int argc, const char *argv[]) {
abstract_virtual_B *b = abstract_virtual_B_new();
abstract_virtual_D *d = abstract_virtual_D_new();
abstract_virtual_E *e = abstract_virtual_E_new();
assert(abstract_virtual_B_foo(b) == 0);
assert(abstract_virtual_D_foo(d) == 0);
assert(abstract_virtual_E_foo(e) == 0);
abstract_virtual_B_delete(b);
abstract_virtual_D_delete(d);
abstract_virtual_E_delete(e);
return 0;
}

View file

@ -0,0 +1,34 @@
#include "access_change_wrap.h"
#include <assert.h>
int main(int argc, const char *argv[]) {
access_change_BaseInt *ba = access_change_BaseInt_new();
access_change_DerivedInt *d = access_change_DerivedInt_new();
access_change_BottomInt *bo = access_change_BottomInt_new();
assert(access_change_BaseInt_PublicProtectedPublic1(ba) == 0);
assert(access_change_BaseInt_PublicProtectedPublic2(ba) == 0);
assert(access_change_BaseInt_PublicProtectedPublic3(ba) == 0);
assert(access_change_BaseInt_PublicProtectedPublic4(ba) == 0);
assert(access_change_DerivedInt_WasProtected1((access_change_DerivedInt*)ba) == 0);
assert(access_change_DerivedInt_WasProtected2((access_change_DerivedInt*)ba) == 0);
assert(access_change_DerivedInt_WasProtected3((access_change_DerivedInt*)ba) == 0);
assert(access_change_DerivedInt_WasProtected4((access_change_DerivedInt*)ba) == 0);
assert(access_change_BottomInt_PublicProtectedPublic1((access_change_BottomInt*)ba) == 0);
assert(access_change_BottomInt_PublicProtectedPublic2((access_change_BottomInt*)ba) == 0);
assert(access_change_BottomInt_PublicProtectedPublic3((access_change_BottomInt*)ba) == 0);
assert(access_change_BottomInt_PublicProtectedPublic4((access_change_BottomInt*)ba) == 0);
assert(access_change_BottomInt_WasProtected1((access_change_BottomInt*)ba) == 0);
assert(access_change_BottomInt_WasProtected2((access_change_BottomInt*)ba) == 0);
assert(access_change_BottomInt_WasProtected3((access_change_BottomInt*)ba) == 0);
assert(access_change_BottomInt_WasProtected4((access_change_BottomInt*)ba) == 0);
access_change_BaseInt_delete(ba);
access_change_DerivedInt_delete(d);
access_change_BottomInt_delete(bo);
return 0;
}

View file

@ -0,0 +1,14 @@
#include "add_link/add_link_wrap.h"
#include <assert.h>
int main(int argc, const char *argv[]) {
add_link_Foo *f = add_link_Foo_new();
add_link_Foo *f2 = add_link_Foo_blah(f);
assert(f2 != 0);
add_link_Foo_delete(f);
add_link_Foo_delete(f2);
return 0;
}

View file

@ -0,0 +1,29 @@
#include "anonymous_bitfield/anonymous_bitfield_wrap.h"
#include <assert.h>
int main(int argc, const char *argv[]) {
anonymous_bitfield_Foo *f = anonymous_bitfield_Foo_new();
assert(f != 0);
anonymous_bitfield_Foo_x_set(f, 1);
assert(anonymous_bitfield_Foo_x_get(f) == 1);
assert(anonymous_bitfield_Foo_y_get(f) == 0);
anonymous_bitfield_Foo_y_set(f, 0);
assert(anonymous_bitfield_Foo_x_get(f) == 1);
assert(anonymous_bitfield_Foo_y_get(f) == 0);
anonymous_bitfield_Foo_f_set(f, 1);
assert(anonymous_bitfield_Foo_f_get(f) == 1);
anonymous_bitfield_Foo_z_set(f, 1);
assert(anonymous_bitfield_Foo_z_get(f) == 1);
anonymous_bitfield_Foo_seq_set(f, 1);
assert(anonymous_bitfield_Foo_seq_get(f) == 1);
anonymous_bitfield_Foo_delete(f);
return 0;
}

View file

@ -0,0 +1,14 @@
#include <assert.h>
#include "c_backend_cpp_exception/c_backend_cpp_exception_wrap.h"
int main()
{
assert(c_backend_cpp_exception_checkVal_get() == 0);
c_backend_cpp_exception_throwSomeKnownException();
assert(c_backend_cpp_exception_checkVal_get() == 1);
c_backend_cpp_exception_throwSomeUnknownException();
assert(c_backend_cpp_exception_checkVal_get() == 2);
return 0;
}

View file

@ -0,0 +1,18 @@
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "c_backend_cpp_natural_std_string/c_backend_cpp_natural_std_string_wrap.h"
int main()
{
char buf[] = "World, ";
char *myComposedString = c_backend_cpp_natural_std_string_myStringAppend(buf, "Hello!");
assert(myComposedString);
assert(strcmp(myComposedString, "World, Hello!") == 0);
free(myComposedString);
return 0;
}

View file

@ -0,0 +1,14 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cast_operator/cast_operator_wrap.h"
int main() {
cast_operator_A *a = cast_operator_A_new();
if (strcmp(cast_operator_A_tochar(a), "hi"))
fprintf(stderr, "cast failed\n");
cast_operator_A_delete(a);
exit(0);
}

View file

@ -0,0 +1,200 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "char_strings/char_strings_wrap.h"
int main() {
char *CPLUSPLUS_MSG = "A message from the deep dark world of C++, where anything is possible.";
char *OTHERLAND_MSG = "Little message from the safe world.";
int count = 10000;
int i = 0;
// get functions
for (i=0; i<count; i++) {
char *str = char_strings_GetCharHeapString();
if (strcmp(str, CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test char get 1 failed, iteration %d\n", i);
exit(1);
}
char_strings_DeleteCharHeapString();
}
for (i=0; i<count; i++) {
const char *str = char_strings_GetConstCharProgramCodeString();
if (strcmp(str, CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test char get 2 failed, iteration %d\n", i);
exit(1);
}
char_strings_DeleteCharHeapString();
}
for (i=0; i<count; i++) {
char *str = char_strings_GetCharStaticString();
if (strcmp(str, CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test char get 3 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
char *str = char_strings_GetCharStaticStringFixed();
if (strcmp(str, CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test char get 4 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
const char *str = char_strings_GetConstCharStaticStringFixed();
if (strcmp(str, CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test char get 5 failed, iteration %d\n", i);
exit(1);
}
}
// set functions
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
if (!char_strings_SetCharHeapString(str, i)) {
fprintf(stderr, "Test char set 1 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
if (!char_strings_SetCharStaticString(str, i)) {
fprintf(stderr, "Test char set 2 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
if (!char_strings_SetCharArrayStaticString(str, i)) {
fprintf(stderr, "Test char set 3 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
if (!char_strings_SetConstCharHeapString(str, i)) {
fprintf(stderr, "Test char set 4 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
if (!char_strings_SetConstCharStaticString(str, i)) {
fprintf(stderr, "Test char set 5 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
if (!char_strings_SetConstCharArrayStaticString(str, i)) {
fprintf(stderr, "Test char set 6 failed, iteration %d\n", i);
exit(1);
}
}
// get set function
for (i=0; i<count; i++) {
char ping[256];
sprintf(ping, "%s%d", OTHERLAND_MSG, i);
char *pong = char_strings_CharPingPong(ping);
if (strcmp(ping, pong) != 0) {
fprintf(stderr, "Test PingPong 1 failed.\nExpected:%s\nReceived:%s\n", ping, pong);
exit(1);
}
}
// variables
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
char_strings_global_char_set(str);
if (strcmp(char_strings_global_char_get(), str) != 0) {
fprintf(stderr, "Test variables 1 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
sprintf(char_strings_global_char_array1_get(), "%s%d", OTHERLAND_MSG, i);
if (strcmp(char_strings_global_char_array1_get(), str) != 0) {
fprintf(stderr, "Test variables 2 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
sprintf(char_strings_global_char_array2_get(), "%s%d", OTHERLAND_MSG, i);
if (strcmp(char_strings_global_char_array2_get(), str) != 0) {
fprintf(stderr, "Test variables 3 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
if (strcmp(char_strings_global_const_char_get(), CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test variables 3 failed, iteration %d\n", i);
exit(1);
}
}
/*
for (i=0; i<count; i++) {
if (strcmp(global_const_char_array1, CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test variables 5 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
if (strcmp(global_const_char_array2, CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test variables 6 failed, iteration %d\n", i);
exit(1);
}
}
*/
// char *& tests
for (i=0; i<count; i++) {
const char **str = char_strings_GetConstCharPointerRef();
if (strcmp(*str, CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test char pointer ref get failed, iteration %d\n",i);
exit(1);
}
}
for (i=0; i<count; i++) {
char *str = (char*) malloc(sizeof(char) * 256);
sprintf(str, "%s%d", OTHERLAND_MSG, i);
if (!char_strings_SetConstCharPointerRef((const char **)&str, i)) {
fprintf(stderr, "Test char pointer ref set failed, iteration %d\n", i);
exit(1);
}
}
exit(0);
}

View file

@ -0,0 +1,16 @@
#include "cpp11_shared_ptr_const_wrap.h"
#include <assert.h>
int main(int argc, const char *argv[]) {
cpp11_shared_ptr_const_Foo* f;
cpp11_shared_ptr_const_Foo* f2;
f = cpp11_shared_ptr_const_Foo_new(17);
assert(cpp11_shared_ptr_const_Foo_get_m(f) == 17);
f2 = cpp11_shared_ptr_const_foo(f);
assert(cpp11_shared_ptr_const_Foo_get_m(f2) == 17);
cpp11_shared_ptr_const_Foo_delete(f2);
cpp11_shared_ptr_const_Foo_delete(f);
return 0;
}

View file

@ -0,0 +1,26 @@
#include "cpp11_shared_ptr_upcast_wrap.h"
#include <assert.h>
int main(int argc, const char *argv[]) {
{
cpp11_shared_ptr_upcast_Derived* d;
d = cpp11_shared_ptr_upcast_Derived_new_i(17);
assert( cpp11_shared_ptr_upcast_base_num1((cpp11_shared_ptr_upcast_Base *)d) == -1 );
assert( cpp11_shared_ptr_upcast_derived_num1(d) == 17 );
cpp11_shared_ptr_upcast_Derived_delete(d);
}
{
cpp11_shared_ptr_upcast_Derived2* d2;
d2 = cpp11_shared_ptr_upcast_Derived2_new_i(289);
assert( cpp11_shared_ptr_upcast_base2_num1((cpp11_shared_ptr_upcast_Base2 *)d2) == -1 );
assert( cpp11_shared_ptr_upcast_derived2_num1(d2) == 289 );
cpp11_shared_ptr_upcast_Derived2_delete(d2);
}
return 0;
}

View file

@ -0,0 +1,109 @@
#include "cpp_basic/cpp_basic_wrap.h"
#include <assert.h>
#include <stdio.h>
int main(int argc, const char *argv[]) {
cpp_basic_Foo *f = cpp_basic_Foo_new(5);
// test global static variables
// TODO: Implement or document as not available
/*
assert(init_ref != 0);
global_fptr_set(f);
assert(cpp_basic_Foo_num_get(global_fptr_get()) == 5);
assert(cpp_basic_Foo_num_get(global_fref_get()) == -4);
cpp_basic_Foo_num_set(f, 6);
global_fref_set(f);
assert(cpp_basic_Foo_num_get(global_fref_get()) == 6);
cpp_basic_Foo_num_set(f, 7);
global_fval_set(f);
assert(cpp_basic_Foo_num_get(global_fval_get()) == 7);
*/
cpp_basic_Foo_num_set(f, 5);
assert(cpp_basic_Foo_num_get(f) == 5);
assert(cpp_basic_Foo_func1(f, 2) == 20);
assert(cpp_basic_Foo_func2(f, 2) == -10);
// function pointer set/get tests are missing
// because of unclear implementation details
//foo_func_ptr_set(f, &cpp_basic_Foo_func1);
// test of global static variable is missing
// because of unclear implementation details
//assert(c_init_ref != 0);
cpp_basic_Bar *b = cpp_basic_Bar_new();
// check default value set by constructor
assert(cpp_basic_Bar_cint_get(b) == 3);
// check default value set by cpp_basic_Bar initializer
assert(cpp_basic_Foo_num_get(cpp_basic_Bar_fval_get(b)) == 15);
// change, recheck
cpp_basic_Foo_num_set(cpp_basic_Bar_fval_get(b), 2);
assert(cpp_basic_Foo_num_get(cpp_basic_Bar_fval_get(b)) == 2);
// check references
assert(cpp_basic_Bar_fref_get(b) != 0);
// check global static value and references
assert(cpp_basic_Foo_num_get(cpp_basic_Bar_fref_get(b)) == -4);
cpp_basic_Foo_num_set(cpp_basic_Bar_fref_get(b), 1);
assert(cpp_basic_Foo_num_get(cpp_basic_Bar_fref_get(b)) == 1);
// create new cpp_basic_Bar instance and check static member value
cpp_basic_Bar *b2 = cpp_basic_Bar_new();
assert(cpp_basic_Foo_num_get(cpp_basic_Bar_fref_get(b2)) == 1);
cpp_basic_Bar_delete(b2);
b2 = 0;
// Try to set a pointer
cpp_basic_Bar_fptr_set(b, f);
assert(cpp_basic_Bar_test(b, 2, f) == 9);
assert(cpp_basic_Bar_test(b, 2, 0) == 4);
cpp_basic_Foo *f2 = cpp_basic_Bar_testFoo(b, 2, f);
assert(cpp_basic_Foo_num_get(f2) == 11);
cpp_basic_Foo_delete(f2);
f2 = 0;
// test static variables
cpp_basic_Bar_global_fptr_set(f);
assert(cpp_basic_Foo_num_get(cpp_basic_Bar_global_fptr_get()) == 5);
cpp_basic_Foo_num_set(f, 6);
cpp_basic_Bar_global_fref_set(f);
assert(cpp_basic_Foo_num_get(cpp_basic_Bar_global_fref_get()) == 6);
cpp_basic_Foo_num_set(f, 7);
cpp_basic_Bar_global_fval_set(f);
assert(cpp_basic_Foo_num_get(cpp_basic_Bar_global_fval_get()) == 7);
// getting, setting and calling function pointers isn't supported yet
#if 0
SomeTypeForMemFnPtr func1 = get_func1_ptr();
cpp_basic_Foo_func_ptr_set(f, func1);
assert(test_func_ptr(f, 2) == 28);
SomeTypeForMemFnPtr func2 = get_func2_ptr();
cpp_basic_Foo_func_ptr_set(f, func2);
assert(test_func_ptr(f, 2) == -14);
#endif
cpp_basic_Bar_delete(b);
cpp_basic_Foo_delete(f);
cpp_basic_Fl_Window *w = cpp_basic_Fl_Window_new();
// Test whether macro worked for code extension
// and test optional function parameters
cpp_basic_Fl_Window_show(w);
cpp_basic_Fl_Window_show_pv(w, 0);
cpp_basic_Fl_Window_show_pv_pv(w, 0, 0);
cpp_basic_Fl_Window_delete(w);
w = 0;
return 0;
}

View file

@ -0,0 +1,71 @@
#include "cpp_enum/cpp_enum_wrap.h"
#include <assert.h>
#include <stdio.h>
int main(int argc, const char *argv[]) {
enum cpp_enum_SOME_ENUM e = cpp_enum_ENUM_ONE, *p;
// check the constructor's default value
cpp_enum_StructWithEnums *s = cpp_enum_StructWithEnums_new();
assert(cpp_enum_StructWithEnums_some_enum_get(s) == cpp_enum_ENUM_ONE);
// check setter
cpp_enum_StructWithEnums_some_enum_set(s, cpp_enum_ENUM_TWO);
assert(cpp_enum_StructWithEnums_some_enum_get(s) == cpp_enum_ENUM_TWO);
// check function call
cpp_enum_StructWithEnums_enum_test1(s, e, &e, &e);
// check function call
cpp_enum_StructWithEnums_enum_test2(s, e, &e, &e);
// check function call
assert(cpp_enum_StructWithEnums_enum_test3(s) == cpp_enum_ENUM_ONE);
// check function call
assert(cpp_enum_StructWithEnums_enum_test4(s) == cpp_enum_ENUM_TWO);
// check function call
p = cpp_enum_StructWithEnums_enum_test5(s);
assert(*p == cpp_enum_ENUM_TWO);
// check function call
p = cpp_enum_StructWithEnums_enum_test6(s);
assert(*p == cpp_enum_ENUM_TWO);
// check function call
p = cpp_enum_StructWithEnums_enum_test7(s);
assert(*p == cpp_enum_ENUM_TWO);
// check function call
p = cpp_enum_StructWithEnums_enum_test8(s);
assert(*p == cpp_enum_ENUM_TWO);
cpp_enum_StructWithEnums_delete(s);
cpp_enum_Foo *f = cpp_enum_Foo_new();
// check the constructor's default value
assert(cpp_enum_Foo_hola_get(f) == cpp_enum_Foo_Hello);
cpp_enum_Foo_hola_set(f, cpp_enum_Foo_Hi);
assert(cpp_enum_Foo_hola_get(f) == cpp_enum_Foo_Hi);
cpp_enum_Foo_delete(f);
//check C enum
cpp_enum_hi_set(cpp_enum_Hi);
cpp_enum_hi_set(cpp_enum_Hello);
// check typedef enum
cpp_enum_play_state t;
t = cpp_enum_PLAY;
assert(t == 1);
t = cpp_enum_STOP;
assert(t == 0);
return 0;
}

View file

@ -0,0 +1,12 @@
#include <assert.h>
#include "enum_rename/enum_rename_wrap.h"
int main() {
assert(enum_rename_M_Jan == 0);
assert(enum_rename_May == 1);
assert(enum_rename_M_Dec == 2);
assert(enum_rename_S_Can == 1);
assert(enum_rename_S_Must == 2);
}

View file

@ -0,0 +1,14 @@
#include <assert.h>
#include <stdlib.h>
#include "enums/enums_wrap.h"
int main() {
assert(GlobalInstance == globalinstance1);
assert(iFoo_Char == 'a');
enums_bar2(1);
enums_bar3(1);
enums_bar1(1);
exit(0);
}

View file

@ -0,0 +1,46 @@
#include <stdio.h>
#include <stdlib.h>
#include "exception_order/exception_order_wrap.h"
int main() {
exception_order_A* a = exception_order_A_new();
exception_order_A_foo(a);
if (!exception_order_SWIG_CException_get_pending()) {
fprintf(stderr, "foo: bad exception order\n");
} else {
exception_order_SWIG_CException_reset_pending();
}
exception_order_A_bar(a);
if (!exception_order_SWIG_CException_get_pending()) {
fprintf(stderr, "bar: bad exception order\n");
} else {
exception_order_SWIG_CException_reset_pending();
}
exception_order_A_foobar(a);
if (!exception_order_SWIG_CException_get_pending()) {
fprintf(stderr, "foobar: bad exception order\n");
} else {
exception_order_SWIG_CException_reset_pending();
}
exception_order_A_barfoo(a, 1);
if (!exception_order_SWIG_CException_get_pending()) {
fprintf(stderr, "barfoo(1): bad exception order\n");
} else {
exception_order_SWIG_CException_reset_pending();
}
exception_order_A_barfoo(a, 2);
if (!exception_order_SWIG_CException_get_pending()) {
fprintf(stderr, "barfoo(2): bad exception order\n");
} else {
exception_order_SWIG_CException_reset_pending();
}
exit(0);
}

View file

@ -0,0 +1,13 @@
#include <assert.h>
#include <string.h>
#include "global_vars/global_vars_wrap.h"
int main(int argc, const char *argv[])
{
global_vars_init();
assert(strcmp(global_vars_b_get(), "string b") == 0);
assert(global_vars_x_get() == 1234);
return 0;
}

View file

@ -0,0 +1,15 @@
#include "li_boost_shared_ptr_wrap.h"
#include <assert.h>
#include <string.h>
int main(int argc, const char *argv[]) {
{
li_boost_shared_ptr::Klass k("me oh my");
assert( k.getValue() == "me oh my" );
}
{
li_boost_shared_ptr::Klass k{li_boost_shared_ptr_factorycreate()};
assert( k.getValue() == "factorycreate" );
}
}

View file

@ -0,0 +1,26 @@
#include "li_std_map/li_std_map_wrap.h"
#include <assert.h>
int main() {
li_std_map_A* a1 = li_std_map_A_new_i(3);
li_std_map_A* a2 = li_std_map_A_new_i(7);
li_std_map_mapA* mA = li_std_map_mapA_new();
li_std_map_mapA_set(mA, 1, a1);
li_std_map_mapA_set(mA, 2, a2);
assert( li_std_map_mapA_size(mA) == 2 );
{
li_std_map_A* a = li_std_map_mapA_get(mA, 1);
assert( li_std_map_A_val_get(a) == 3 );
}
assert( !li_std_map_mapA_has_key(mA, 3) );
li_std_map_mapA_delete(mA);
li_std_map_A_delete(a2);
li_std_map_A_delete(a1);
return 0;
}

View file

@ -0,0 +1,42 @@
#include "li_std_pair/li_std_pair_wrap.h"
#include <assert.h>
int main() {
{
li_std_pair_IntPair* intPair = li_std_pair_makeIntPair(7, 6);
assert(li_std_pair_IntPair_first_get(intPair)==7 && li_std_pair_IntPair_second_get(intPair)==6);
assert(li_std_pair_product1(intPair) == 42);
assert(li_std_pair_product2(intPair) == 42);
assert(li_std_pair_product3(intPair) == 42);
li_std_pair_IntPair_delete(intPair);
}
{
li_std_pair_IntPair* intPairPtr = li_std_pair_makeIntPairPtr(7, 6);
assert(li_std_pair_IntPair_first_get(intPairPtr)==7 && li_std_pair_IntPair_second_get(intPairPtr)==6);
assert(li_std_pair_product1(intPairPtr) == 42);
assert(li_std_pair_product2(intPairPtr) == 42);
assert(li_std_pair_product3(intPairPtr) == 42);
}
{
li_std_pair_IntPair* intPairRef = li_std_pair_makeIntPairRef(7, 6);
assert(li_std_pair_IntPair_first_get(intPairRef)==7 && li_std_pair_IntPair_second_get(intPairRef)==6);
assert(li_std_pair_product1(intPairRef) == 42);
assert(li_std_pair_product2(intPairRef) == 42);
assert(li_std_pair_product3(intPairRef) == 42);
}
{
li_std_pair_IntPair* intPairConstRef = li_std_pair_makeIntPairConstRef(7, 6);
assert(li_std_pair_IntPair_first_get(intPairConstRef)==7 && li_std_pair_IntPair_second_get(intPairConstRef)==6);
assert(li_std_pair_product1(intPairConstRef) == 42);
assert(li_std_pair_product2(intPairConstRef) == 42);
assert(li_std_pair_product3(intPairConstRef) == 42);
}
}

View file

@ -0,0 +1,33 @@
#include "li_std_set/li_std_set_wrap.h"
#include <assert.h>
int main() {
{
li_std_set_IntSet* is = li_std_set_IntSet_new();
li_std_set_IntSet_add(is, 1);
li_std_set_IntSet_add(is, 4);
li_std_set_IntSet_add(is, 9);
assert( li_std_set_IntSet_size(is) == 3 );
assert( li_std_set_IntSet_has(is, 4) );
assert( !li_std_set_IntSet_has(is, 16) );
li_std_set_IntSet_delete(is);
}
{
li_std_set_StringSet* ss = li_std_set_StringSet_new();
li_std_set_StringSet_add(ss, "foo");
li_std_set_StringSet_add(ss, "bar");
assert( li_std_set_StringSet_size(ss) == 2 );
assert( li_std_set_StringSet_has(ss, "bar") );
assert( !li_std_set_StringSet_has(ss, "baz") );
li_std_set_StringSet_delete(ss);
}
return 0;
}

View file

@ -0,0 +1,26 @@
#include "li_std_string_wrap.h"
#include <assert.h>
using namespace li_std_string;
int main(int argc, const char *argv[]) {
Structure st;
assert( st.MemberString().empty() );
st.MemberString("bloordyblop");
assert( st.MemberString() == "bloordyblop" );
assert( st.MemberString2() == "member string 2" );
assert( st.ConstMemberString() == "const member string" );
st.StaticMemberString(std::string("static bloordyblop"));
assert( st.StaticMemberString() == "static bloordyblop" );
assert( Structure::StaticMemberString2() == "static member string 2" );
assert( Structure::ConstStaticMemberString() == "const static member string" );
Foo f;
assert( f.test("1+") == "1+1" );
}

View file

@ -0,0 +1,22 @@
#include "li_std_vector/li_std_vector_wrap.h"
#include <assert.h>
int main() {
size_t i;
li_std_vector_IntVector* iv = li_std_vector_IntVector_new();
assert( li_std_vector_IntVector_size(iv) == 0 );
li_std_vector_IntVector_push_back(iv, 1);
li_std_vector_IntVector_push_back(iv, 4);
li_std_vector_IntVector_push_back(iv, 9);
assert( li_std_vector_IntVector_size(iv) == 3 );
for ( i = 0; i < 3; i++ ) {
assert( li_std_vector_IntVector_get(iv, i) == (i + 1)*(i + 1) );
}
li_std_vector_IntVector_delete(iv);
return 0;
}

View file

@ -0,0 +1,25 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "operator_overload/operator_overload_wrap.h"
int main() {
operator_overload_Op_sanity_check();
operator_overload_Op *op1 = operator_overload_Op_new_i(1), *op2 = operator_overload_Op_new_i(2), *op3 = operator_overload_Op_copy(op1);
assert(operator_overload_Op_NotEqual(op1, op2));
operator_overload_Op_PlusPlusPrefix(op3);
assert(operator_overload_Op_EqualEqual(op2, op3));
assert(operator_overload_Op_GreaterThanEqual(op2, op1));
operator_overload_Op_PlusEqual(op3, op1);
assert(operator_overload_Op_LessThan(op1, op2) && operator_overload_Op_LessThan(op2, op3));
assert(3 == *operator_overload_Op_IndexInto(op3, operator_overload_Op_IndexIntoConst(op2, operator_overload_Op_Functor(op1))));
assert(5 == operator_overload_Op_Functor_i(op3, 2));
operator_overload_Op_delete(op1);
operator_overload_Op_delete(op2);
operator_overload_Op_delete(op3);
exit(0);
}

View file

@ -0,0 +1,25 @@
%module c_backend_cpp_exception
%exception {
try {
$action
} catch(SomeKnownException) {
checkVal = 1;
} catch(...) {
checkVal = 2;
}
}
%inline %{
class SomeKnownException{};
class SomeUnkownException{};
int checkVal = 0;
void throwSomeKnownException(void) {
throw SomeKnownException();
}
void throwSomeUnknownException(void) {
throw SomeUnkownException();
}
%}

View file

@ -0,0 +1,13 @@
%module c_backend_cpp_natural_std_string
%feature ("nspace", "1");
%include std_string.i
%inline %{
static std::string& myStringAppend(std::string &someString, const std::string &appendedString)
{
someString += appendedString;
return someString;
}
%}

View file

@ -11,8 +11,10 @@ struct SomeStruct {
auto addAlternateConst(int x, int y) const -> int;
auto addAlternateNoExcept(int x, int y) noexcept -> int;
auto addAlternateConstNoExcept(int x, int y) const noexcept -> int;
#ifndef SWIGC
auto addAlternateMemberPtrParm(int x, int (SomeStruct::*mp)(int, int)) -> int;
auto addAlternateMemberPtrConstParm(int x, int (SomeStruct::*mp)(int, int) const) const -> int;
#endif // !SWIGC
// Returning a reference didn't parse in SWIG < 4.1.0 (#231)
auto output() -> Hello&;
@ -26,6 +28,7 @@ auto SomeStruct::addAlternate(int x, int y) -> int { return x + y; }
auto SomeStruct::addAlternateConst(int x, int y) const -> int { return x + y; }
auto SomeStruct::addAlternateNoExcept(int x, int y) noexcept -> int { return x + y; }
auto SomeStruct::addAlternateConstNoExcept(int x, int y) const noexcept -> int { return x + y; }
#ifndef SWIGC
auto SomeStruct::addAlternateMemberPtrParm(int x, int (SomeStruct::*mp)(int, int)) -> int {
return 100*x + (this->*mp)(x, x);
}
@ -33,5 +36,6 @@ auto SomeStruct::addAlternateMemberPtrConstParm(int x, int (SomeStruct::*mp)(int
return 1000*x + (this->*mp)(x, x);
}
auto SomeStruct::output() -> Hello& { static Hello h; return h; }
#endif // !SWIGC
%}

View file

@ -31,7 +31,9 @@ class Foo {
return -a*num;
}
#ifndef SWIGC
int (Foo::*func_ptr)(int);
#endif // SWIGC
const char* __str__() const { return "Foo"; }
};
@ -100,6 +102,7 @@ Foo Bar::global_fval = Foo(3);
%}
/* member function tests */
#ifndef SWIGC
%inline %{
int (Foo::*get_func1_ptr())(int) {
return &Foo::func1;
@ -114,6 +117,7 @@ int test_func_ptr(Foo *f, int a) {
}
%}
#endif // SWIGC
#ifdef __cplusplus

View file

@ -34,7 +34,7 @@ public:
%}
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY)
#if defined(SWIGC) || defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY)
#define SHARED_PTR_WRAPPERS_IMPLEMENTED
#endif

View file

@ -1,7 +1,7 @@
/* File : example.i */
%module dynamic_cast
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) && !defined(SWIGD)
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) && !defined(SWIGD) && !defined(SWIGC)
%apply SWIGTYPE *DYNAMIC { Foo * };
#endif
@ -17,7 +17,7 @@ public:
};
%}
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGGO) || defined(SWIGD)
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGGO) || defined(SWIGD) || defined(SWIGC)
%typemap(out) Foo *blah {
Bar *downcast = dynamic_cast<Bar *>($1);
*(Bar **)&$result = downcast;
@ -69,7 +69,7 @@ char *do_test(Bar *b) {
}
%}
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) && !defined(SWIGD)
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) && !defined(SWIGD) && !defined(SWIGC)
// A general purpose function for dynamic casting of a Foo *
%{
static swig_type_info *

View file

@ -1,7 +1,7 @@
%module functors
// Rename operator() only if the language does not already do this by default
#if defined(SWIGCSHARP) || defined(SWIGGO) || defined(SWIGGUILE) || defined(SWIGJAVA) || defined(SWIGJAVASCRIPT) || defined(SWIGPHP) || defined(SWIGSCILAB) || defined(SWIGTCL)
#if defined(SWIGC) || defined(SWIGCSHARP) || defined(SWIGGO) || defined(SWIGGUILE) || defined(SWIGJAVA) || defined(SWIGJAVASCRIPT) || defined(SWIGPHP) || defined(SWIGSCILAB) || defined(SWIGTCL)
%rename(Funktor) operator();
#endif

View file

@ -1,5 +1,5 @@
#if !defined(SWIGGO)
// Prevent Go from generating a Go module import - this test is not set up as true multiple modules
#if !defined(SWIGC) && !defined(SWIGGO)
// Prevent C/Go from generating a C include/Go module import - this test is not set up as true multiple modules
%module import_fragments_a
#endif

View file

@ -128,6 +128,8 @@ struct ExtendingOptArgs1 {};
struct ExtendingOptArgs2 {};
%}
#ifndef SWIGC
// For strlen/strcpy
%{
#include <string.h>
@ -150,3 +152,5 @@ struct VarargConstructor {
}
};
%}
#endif // !SWIGC

View file

@ -44,7 +44,7 @@
# define SWIG_SHARED_PTR_NAMESPACE SwigBoost
#endif
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) || defined(SWIGR)
#if defined(SWIGC) || defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) || defined(SWIGR)
#define SHARED_PTR_WRAPPERS_IMPLEMENTED
#endif

View file

@ -1,6 +1,6 @@
%module li_boost_shared_ptr_attribute
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY)
#if defined(SWIGC) || defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY)
#define SHARED_PTR_WRAPPERS_IMPLEMENTED
#endif

View file

@ -1,6 +1,6 @@
%module li_boost_shared_ptr_bits
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY)
#if defined(SWIGC) || defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY)
#define SHARED_PTR_WRAPPERS_IMPLEMENTED
#endif

View file

@ -4,7 +4,7 @@
#include <boost/shared_ptr.hpp>
%}
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) || defined(SWIGR)
#if defined(SWIGC) || defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) || defined(SWIGR)
#define SHARED_PTR_WRAPPERS_IMPLEMENTED
#endif

View file

@ -30,7 +30,7 @@
%}
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY)
#if defined(SWIGC) || defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY)
#define SHARED_PTR_WRAPPERS_IMPLEMENTED
#endif

View file

@ -22,7 +22,7 @@
%template(set_int) std::multiset<int>;
%template(v_int) std::vector<int>;
%template(set_string) std::set<std::string>;
#elif defined(SWIGJAVA) || defined(SWIGCSHARP)
#elif defined(SWIGC) || defined(SWIGJAVA) || defined(SWIGCSHARP)
// This operator is only defined because it's needed to store objects of
// type Foo in std::set in C++, we don't need to wrap it.
%ignore operator<;

View file

@ -9,11 +9,20 @@ struct ExtendMe {
};
%}
// Use different names for the C backend to be consistent with the global prefix used.
%inline {
#ifdef SWIGC
%#define ADD_PREFIX(name) memberin_extend_ ## name
#else
%#define ADD_PREFIX(name) name
#endif
}
%{
#include <map>
#include <string.h>
std::map<ExtendMe*, char *> ExtendMeStringMap;
void ExtendMe_thing_set(ExtendMe *self, const char *val) {
void ADD_PREFIX(ExtendMe_thing_set)(ExtendMe *self, const char *val) {
char *old_val = ExtendMeStringMap[self];
delete [] old_val;
if (val) {
@ -23,7 +32,7 @@ void ExtendMe_thing_set(ExtendMe *self, const char *val) {
ExtendMeStringMap[self] = 0;
}
}
char * ExtendMe_thing_get(ExtendMe *self) {
char * ADD_PREFIX(ExtendMe_thing_get)(ExtendMe *self) {
return ExtendMeStringMap[self];
}
%}

View file

@ -8,16 +8,37 @@ namespace foo {
public:
};
}
%}
// C uses different naming convention, with all functions starting with the class prefix
// and using the global namespace prefix too, if specified (which is the case for the tests).
#ifdef SWIGC
%{
foo::bar *namespace_extend_foo_bar_new() {
return new foo::bar;
}
void namespace_extend_foo_bar_delete(foo::bar *self) {
delete self;
}
int namespace_extend_foo_bar_blah(foo::bar *self, int x) {
return x;
}
%}
#else
%{
foo::bar *new_foo_bar() {
return new foo::bar;
}
void delete_foo_bar(foo::bar *self) {
delete self;
}
int foo_bar_blah(foo::bar *self, int x) {
return x;
}
%}
#endif
namespace foo {
class bar {

View file

@ -16,7 +16,9 @@ public:
int blah(int x);
int spam(int x);
Integer bar(Integer x);
#ifndef SWIGC
void (Foo:: *func_ptr) (int);
#endif
};
inline Foo :: Foo () {}

View file

@ -15,6 +15,11 @@ see bottom for a set of possible tests
SWIGWARN_IGNORE_OPERATOR_LOR);
#endif
#if defined(SWIGC)
%warnfilter(SWIGWARN_IGNORE_OPERATOR_EQ,
SWIGWARN_IGNORE_OPERATOR_PLUSPLUS);
#endif
#if !defined(SWIGLUA) && !defined(SWIGR)
%rename(Equal) operator =;
%rename(PlusEqual) operator +=;

View file

@ -27,6 +27,19 @@ std::string ExceptionVars(double i, double j) {
%}
%rename(ExceptionVars) Space::exceptionvars;
#ifdef SWIGC
%exception Space::exceptionvars %{
$action
result = (char*)$symname(1.0,2.0).c_str(); // Should expand to ExceptionVars
result = (char*)$name(3.0,4.0).c_str(); // Should expand to Space::exceptionvars
// above will not compile if the variables are not expanded properly
result = (char*)"$action $name $symname $overname $wrapname";
%}
#else
%exception Space::exceptionvars %{
$action
result = $symname(1.0,2.0); // Should expand to ExceptionVars
@ -34,6 +47,9 @@ std::string ExceptionVars(double i, double j) {
// above will not compile if the variables are not expanded properly
result = "$action $name $symname $overname $wrapname $parentclassname $parentclasssymname";
%}
#endif
%inline %{
namespace Space {
std::string exceptionvars(double i, double j) {
@ -43,6 +59,20 @@ std::string exceptionvars(double i, double j) {
%}
#ifdef SWIGC
%exception Space::overloadedmethod %{
$action
result = (char*)Space::$symname(1.0).c_str();
result = (char*)$name().c_str();
result = (char*)$name(2.0).c_str();
// above will not compile if the variables are not expanded properly
result = (char*)"$action $name $symname $overname $wrapname";
// $decl
%}
#else
%exception Space::overloadedmethod %{
$action
result = Space::$symname(1.0);
@ -53,6 +83,8 @@ std::string exceptionvars(double i, double j) {
// $decl
%}
#endif
%inline %{
namespace Space {
std::string overloadedmethod(double j) {

View file

@ -9,7 +9,7 @@ struct NoDefaultCtor {
};
%}
#if defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGD)
#if defined(SWIGC) || defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGD)
%template(VectorNoDefaultCtor) std::vector<NoDefaultCtor>;
#endif

5
Lib/c/boost_shared_ptr.i Normal file
View file

@ -0,0 +1,5 @@
#ifndef SWIG_SHARED_PTR_NAMESPACE
#define SWIG_SHARED_PTR_NAMESPACE boost
#endif
%include <std_shared_ptr.i>

359
Lib/c/c.swg Normal file
View file

@ -0,0 +1,359 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* c.swg
* ----------------------------------------------------------------------------- */
%include <cheader.swg>
%insert("runtime") "clabels.swg"
%insert("runtime") %{
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <setjmp.h>
#define SWIG_contract_assert(expr, msg) if(!(expr)) { printf("%s\n", msg); SWIG_exit(0); } else
%}
%fragment("stdbool_inc", "cheader") {#include <stdbool.h>}
%define same_macro_all_primitive_types_but_void(macro_name, TM)
macro_name(TM, short);
macro_name(TM, unsigned short);
macro_name(TM, int);
macro_name(TM, unsigned int);
macro_name(TM, long);
macro_name(TM, unsigned long);
macro_name(TM, long long);
macro_name(TM, unsigned long long);
macro_name(TM, char);
macro_name(TM, signed char);
macro_name(TM, unsigned char);
macro_name(TM, float);
macro_name(TM, double);
macro_name(TM, size_t);
%enddef
// This is used to handle all primitive types as just themselves.
// This macro doesn't cover const references, use either cref_as_value or
// cref_as_ptr below in addition to it.
// Notice that const pointers are mapped to non-const ones as we need to
// declare variables of this type when it's used as a return type, and top
// level const doesn't matter anyhow in the function declarations.
%define same_type(TM, T)
%typemap(TM) T, const T "T"
%typemap(TM) T*, T&, T[ANY], T[] "T *"
%typemap(TM) const T*, const T[ANY], const T[] "const T *"
%typemap(TM) T**, T*&, T*[ANY], T[ANY][ANY] "T **"
%typemap(TM) const T**, const T*&, T *const &, const T*[ANY], const T[ANY][ANY] "const T **"
// constant pointers
%typemap(TM) T * const "T *"
%typemap(TM) T* * const "T* *"
%typemap(TM) const T* * const "const T* *"
%enddef
%define cref_as_value(TM, T)
%typemap(TM) const T& "T"
%enddef
%define cref_as_ptr(TM, T)
%typemap(TM) const T& "T *"
%enddef
%define same_type_all_primitive_types_but_void(TM)
%enddef
//Used by 'in' and 'out' typemaps
%define same_action(TM, T, ACTION, ACTION_CREF)
%typemap(TM) T, const T ACTION
%typemap(TM) const T& ACTION_CREF
%typemap(TM) T*, T&, T[ANY], T[] ACTION
%typemap(TM) const T*, const T[ANY], const T[] ACTION
%typemap(TM) T**, T*&, T*[ANY], T[ANY][ANY] ACTION
%typemap(TM) const T**, const T*&, const T*[ANY], const T[ANY][ANY] ACTION
// constant pointers
%typemap(TM) T * const ACTION
%typemap(TM) T* * const ACTION
%typemap(TM) const T* * const ACTION
%enddef
%define same_action_all_primitive_types(TM, ACTION, ACTION_CREF)
same_action(TM, short, ACTION, ACTION_CREF);
same_action(TM, unsigned short, ACTION, ACTION_CREF);
same_action(TM, int, ACTION, ACTION_CREF);
same_action(TM, unsigned int, ACTION, ACTION_CREF);
same_action(TM, long, ACTION, ACTION_CREF);
same_action(TM, unsigned long, ACTION, ACTION_CREF);
same_action(TM, long long, ACTION, ACTION_CREF);
same_action(TM, unsigned long long, ACTION, ACTION_CREF);
same_action(TM, char, ACTION, ACTION_CREF);
same_action(TM, signed char, ACTION, ACTION_CREF);
same_action(TM, unsigned char, ACTION, ACTION_CREF);
//unsigned only
same_action(TM, float, ACTION, ACTION_CREF);
same_action(TM, double, ACTION, ACTION_CREF);
same_action(TM, size_t, ACTION, ACTION_CREF);
%typemap(TM) void*, void const* ACTION
%enddef
// "ctype" is the type used with C wrapper functions.
// void
%typemap(ctype) void "void"
%typemap(ctype) void*, void& "void *"
%typemap(ctype) const void&, const void* "const void *"
%typemap(ctype) void**, void*& "void **"
%typemap(ctype) const void**, const void*& "const void **"
// constant pointers
%typemap(ctype) void* * const "void* * const"
%typemap(ctype) const void* * const "const void* * const"
same_macro_all_primitive_types_but_void(same_type,ctype);
same_macro_all_primitive_types_but_void(cref_as_value,ctype);
// trivial typemap for arrays of void pointers to avoid applying the object typemaps to them
%typemap(ctype) void*[ANY] "void **"
// objects
%typemap(ctype) SWIGTYPE "$&resolved_type*"
%typemap(ctype) SWIGTYPE * "$resolved_type*"
%typemap(ctype) SWIGTYPE * const & "$resolved_type*"
%typemap(ctype) SWIGTYPE & "$*resolved_type*"
%typemap(ctype) SWIGTYPE [ANY] "$resolved_type*"
%typemap(ctype) SWIGTYPE * [ANY] "$resolved_type**"
// enums
%typemap(ctype) enum SWIGTYPE "$resolved_type"
%typemap(ctype) enum SWIGTYPE * "$resolved_type*"
%typemap(ctype) enum SWIGTYPE & "$*resolved_type*"
%typemap(ctype) enum SWIGTYPE [ANY] "$resolved_type*"
%typemap(ctype, fragment="stdbool_inc") bool, const bool, const bool & "bool"
%typemap(ctype, fragment="stdbool_inc") bool *, const bool *, bool & "bool *"
// Typemaps for assigning wrapper parameters to local variables
same_action_all_primitive_types(in, "$1 = ($1_ltype) $input;", "$1 = &$input;")
%typemap(in) short [ANY], int [ANY], long [ANY], long long [ANY], char [ANY], float [ANY], double [ANY], unsigned char [ANY] "$1 = ($1_basetype *) $input;"
%typemap(in) short * [ANY], int * [ANY], long * [ANY], long long * [ANY], char * [ANY], float * [ANY], double * [ANY] "$1 = ($1_basetype *) $input;"
%typemap(in, fragment="stdbool_inc") bool, bool *, bool **, const bool, const bool * "$1 = ($1_ltype) $input;"
%typemap(in, fragment="stdbool_inc") bool & "$1 = ($1_basetype *) $input;"
%typemap(in, fragment="stdbool_inc") const bool &, const bool * "$1 = ($1_basetype *) $input;"
%typemap(in) enum SWIGTYPE "$1 = ($1_ltype) $input;"
%typemap(in) enum SWIGTYPE &,enum SWIGTYPE * "$1 = ($1_ltype) $input;"
%typemap(in) SWIGTYPE [] "$1 = ($1_ltype) $input;"
%typemap(in) SWIGTYPE ((&)[ANY]) "$1 = ($1_ltype) $input;"
%typemap(in) SWIGTYPE (CLASS::*) {
if ($input)
$1 = *($&1_ltype) &$input;
}
%typemap(in) SWIGTYPE "$1 = *($1_ltype *)$input;"
%typemap(in) SWIGTYPE * "$1 = ($1_ltype) $input;"
%typemap(in) SWIGTYPE *[ANY] {
if ($input) {
$1 = ($1_ltype) malloc($1_dim0 * sizeof($1_basetype));
size_t i = 0;
for ( ; i < $1_dim0; ++i)
if ($input[i])
$1[i] = ($*1_ltype) $input[i];
else
$1[i] = ($*1_ltype) 0;
}
else
$1 = ($1_ltype) 0;
}
%typemap(in) SWIGTYPE [ANY][ANY] {
if ($input) {
$1 = ($1_ltype) malloc($1_dim0 * $1_dim1 * sizeof($1_basetype));
size_t i = 0, j = 0;
for ( ; i < $1_dim0; ++i) {
for ( ; j < $1_dim1; ++j) {
if ($input[i][j])
$1[i][j] = * ($*1_ltype) $input[i][j];
else
$1[i][j] = * ($*1_ltype) 0;
}
}
}
else
$1 = ($1_ltype) 0;
}
%typemap(freearg) SWIGTYPE * [ANY], SWIGTYPE * [ANY][ANY] {
if ($input)
free($input);
}
%typemap(in) SWIGTYPE & %{
$1 = ($1_ltype) $input;
%}
// Typemaps for assigning result values to a special return variable
same_action_all_primitive_types(out, "$result = $1;", "$result = *$1;")
%typemap(out) void ""
%typemap(out, fragment="stdbool_inc") bool, bool *, const bool, const bool * "$result = ($1_ltype) $1;"
%typemap(out, fragment="stdbool_inc") bool &, const bool & "$result = $1;"
%typemap(out) enum SWIGTYPE "$result = (int) $1;"
%typemap(out) enum SWIGTYPE &, enum SWIGTYPE * "$result = $1;"
%typemap(out) SWIGTYPE (CLASS::*) {
*($&1_ltype) &$result = $1;
}
%typemap(out) SWIGTYPE "$result = (SwigObj*)new $1_ltype($1);"
%typemap(out) SWIGTYPE *, SWIGTYPE & "$result = (SwigObj*) $1;"
%typemap(out) SWIGTYPE * [ANY], SWIGTYPE [ANY][ANY] {
static SwigObj **_temp = 0;
if ($1) {
size_t i = 0;
if (_temp) {
for ( ; i < $1_dim0; ++i)
delete ($1_ltype *)_temp[i];
free(_temp);
}
_temp = (SwigObj**) malloc($1_dim0 * sizeof(SwigObj*));
for (i = 0 ; i < $1_dim0; ++i) {
if ($1[i]) {
_temp[i] = $1[i];
}
else
_temp[i] = (SwigObj*) 0;
}
$result = ($1_ltype) _temp;
}
else
$result = ($1_ltype) 0;
}
/* Typecheck typemaps - The purpose of these is merely to issue a warning for overloaded C++ functions
* that cannot be overloaded in the wrappers as more than one C++ type maps to a single C type */
%typecheck(SWIG_TYPECHECK_BOOL)
bool,
const bool &
""
%typecheck(SWIG_TYPECHECK_CHAR)
char,
const char &
""
%typecheck(SWIG_TYPECHECK_INT8)
signed char,
const signed char &
""
%typecheck(SWIG_TYPECHECK_UINT8)
unsigned char,
const unsigned char &
""
%typecheck(SWIG_TYPECHECK_INT16)
short,
const short &
""
%typecheck(SWIG_TYPECHECK_UINT16)
unsigned short,
const unsigned short &
""
%typecheck(SWIG_TYPECHECK_INT32)
int,
long,
const int &,
const long &
""
%typecheck(SWIG_TYPECHECK_UINT32)
unsigned int,
unsigned long,
const unsigned int &,
const unsigned long &
""
%typecheck(SWIG_TYPECHECK_INT64)
long long,
const long long &
""
%typecheck(SWIG_TYPECHECK_UINT64)
unsigned long long,
const unsigned long long &
""
%typecheck(SWIG_TYPECHECK_FLOAT)
float,
const float &
""
%typecheck(SWIG_TYPECHECK_DOUBLE)
double,
const double &
""
%typecheck(SWIG_TYPECHECK_STRING)
char *,
char *&,
char[ANY],
char[]
""
%typecheck(SWIG_TYPECHECK_POINTER)
SWIGTYPE,
SWIGTYPE *,
SWIGTYPE &,
SWIGTYPE &&,
SWIGTYPE *const&,
SWIGTYPE [],
SWIGTYPE (CLASS::*)
""
#ifdef SWIG_CPPMODE
%insert("runtime") %{
typedef struct SwigObj SwigObj;
%}
%insert("cheader") %{
typedef struct SwigObj SwigObj;
%}
#endif // SWIG_CPPMODE
#ifdef SWIG_C_EXCEPT
%include "cexcept.swg"
#else // !SWIG_C_EXCEPT
// Still define the macro used in some standard typemaps, but we can't
// implement it in C, so just allow the user predefining their own version.
%insert("runtime") %{
#ifndef SWIG_exception
#define SWIG_exception(code, msg)
#endif
%}
#endif // SWIG_C_EXCEPT/!SWIG_C_EXCEPT
%insert("runtime") %{
#ifdef __cplusplus
extern "C" {
#endif
SWIGEXPORTC int SWIG_exit(int code) { exit(code); }
#ifdef __cplusplus
}
#endif
%}

109
Lib/c/cexcept.swg Normal file
View file

@ -0,0 +1,109 @@
/* -----------------------------------------------------------------------------
* clabels.swg
*
* Exception handling code and typemaps for C module.
* ----------------------------------------------------------------------------- */
// This function is special: it's used by various typemaps (via SWIG_exception
// macro below) and needs to be defined, but we don't want to export it.
%ignore SWIG_CException_Raise;
%{
extern "C" void SWIG_CException_Raise(int code, const char* msg);
%}
// This class is special too because its name is used in c.cxx source. It is
// only defined if the code there didn't predefine SWIG_CException_DEFINED
// because the class is already defined in another module.
//
// It has to be seen by SWIG because we want to generate wrappers for its
// public functions to be able to use it from the application code.
%inline %{
#ifndef SWIG_CException_DEFINED
class SWIG_CException {
public:
SWIG_CException(const SWIG_CException& ex) throw() : code(ex.code), msg(strdup(ex.msg)) { }
~SWIG_CException() { free(const_cast<char*>(msg)); }
const int code;
const char* const msg;
static SWIG_CException* get_pending() throw() {
return PendingException;
}
static void reset_pending() throw() {
if (PendingException) {
delete PendingException;
PendingException = 0;
}
}
private:
friend void SWIG_CException_Raise(int code, const char* msg);
static thread_local SWIG_CException* PendingException;
SWIG_CException(int code, const char* msg) : code(code), msg(strdup(msg)) { }
SWIG_CException& operator=(const SWIG_CException& ex);
};
#endif // SWIG_CException_DEFINED
%}
// This part is implementation only and doesn't need to be seen by SWIG.
%{
#ifndef SWIG_CException_DEFINED
thread_local SWIG_CException *SWIG_CException::PendingException = 0;
SWIGEXPORTC void SWIG_CException_Raise(int code, const char* msg) {
delete SWIG_CException::PendingException;
SWIG_CException::PendingException = new SWIG_CException(code, msg);
}
#endif // SWIG_CException_DEFINED
%}
#ifdef SWIG_CXX_WRAPPERS
// This is somewhat of a hack, but our generated header may include another
// generated header, when using multiple modules, and defining swig_check() in
// all of them would result in errors, so we use SWIG_swig_check_DEFINED to
// prevent this from happening.
//
// This also has a nice side effect of allowing the user code to predefine this
// symbol and provide their own SWIG_swig_check_DEFINED implementation to
// customize exception handling.
%insert("cxxcode") %{
#ifndef SWIG_swig_check_DEFINED
#define SWIG_swig_check_DEFINED 1
inline void swig_check() {
if (SWIG_CException* swig_ex = SWIG_CException::get_pending()) {
SWIG_CException swig_ex_copy{*swig_ex};
delete swig_ex;
SWIG_CException::reset_pending();
throw swig_ex_copy;
}
}
template <typename T> T swig_check(T x) {
swig_check();
return x;
}
#endif // SWIG_swig_check_DEFINED
%}
#endif // SWIG_CXX_WRAPPERS
%insert("runtime") "swigerrors.swg"
#define SWIG_exception(code, msg)\
SWIG_CException_Raise(code, msg)
%typemap(throws, noblock="1") char *, const char * {
SWIG_exception(SWIG_RuntimeError, $1);
}
%typemap(throws, noblock="1") SWIGTYPE {
SWIG_exception(SWIG_UnknownError, "exception of type $1_type");
}

20
Lib/c/cheader.swg Normal file
View file

@ -0,0 +1,20 @@
/* -----------------------------------------------------------------------------
* cheader.swg
* ----------------------------------------------------------------------------- */
%insert("cheader") %{
#ifndef SWIGIMPORT
# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
# if defined(STATIC_LINKED)
# define SWIGDLLIMPORT
# else
# define SWIGDLLIMPORT __declspec(dllimport)
# endif
# else
# define SWIGDLLIMPORT
# endif
# define SWIGIMPORT extern SWIGDLLIMPORT
#endif
#include <stddef.h>
%}

19
Lib/c/clabels.swg Normal file
View file

@ -0,0 +1,19 @@
/* -----------------------------------------------------------------------------
* clabels.swg
*
* Definitions of C specific preprocessor symbols.
* ----------------------------------------------------------------------------- */
// this is used instead of default SWIGEXPORT symbol
#ifndef SWIGEXPORTC
# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) || defined(__APPLE__)
# define SWIGEXPORTC
# else
# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
# define SWIGEXPORTC __attribute__ ((visibility("default")))
# else
# define SWIGEXPORTC
# endif
# endif
#endif

4
Lib/c/std_common.i Normal file
View file

@ -0,0 +1,4 @@
%include <std_except.i>
%apply size_t { std::size_t };
%apply const size_t& { const std::size_t & };

20
Lib/c/std_except.i Normal file
View file

@ -0,0 +1,20 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* std_except.i
*
* Typemaps used by the STL wrappers that throw exceptions.
* These typemaps are used when methods are declared with an STL exception specification, such as
* size_t at() const throw (std::out_of_range);
* ----------------------------------------------------------------------------- */
%{
#include <stdexcept>
%}
namespace std
{
%ignore exception;
struct exception {};
}

61
Lib/c/std_map.i Normal file
View file

@ -0,0 +1,61 @@
/* -----------------------------------------------------------------------------
* std_map.i
*
* SWIG typemaps for std::map
* ----------------------------------------------------------------------------- */
%include <std_common.i>
// ------------------------------------------------------------------------
// std::map
// ------------------------------------------------------------------------
%{
#include <map>
#include <stdexcept>
%}
namespace std {
template<class K, class T, class C = std::less<K> > class map {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef K key_type;
typedef T mapped_type;
typedef std::pair< const K, T > value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
map();
map(const map& other);
size_t size() const;
bool empty() const;
void clear();
%extend {
const T& get(const K& key) throw (std::out_of_range) {
std::map< K, T, C >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
throw std::out_of_range("key not found");
}
void set(const K& key, const T& x) {
(*self)[key] = x;
}
void del(const K& key) throw (std::out_of_range) {
std::map< K, T, C >::iterator i = self->find(key);
if (i != self->end())
self->erase(i);
else
throw std::out_of_range("key not found");
}
bool has_key(const K& key) const {
std::map< K, T, C >::const_iterator i = self->find(key);
return i != self->end();
}
}
};
}

24
Lib/c/std_pair.i Normal file
View file

@ -0,0 +1,24 @@
%{
#include <utility>
%}
// Ideal, especially for the simple/primitive types, would be to represent
// pair<T,U> as a C struct with the 2 fields, but for now we use the simplest
// possible implementation, with the accessor functions required to work with
// the fields.
namespace std {
template <class T, class U> struct pair {
typedef T first_type;
typedef U second_type;
pair();
pair(T first, U second);
pair(const pair& other);
template <class T2, class U2> pair(const pair<T2, U2> &other);
T first;
U second;
};
}

48
Lib/c/std_set.i Normal file
View file

@ -0,0 +1,48 @@
/* -----------------------------------------------------------------------------
* std_set.i
*
* SWIG typesets for std::set
* ----------------------------------------------------------------------------- */
%include <std_common.i>
// ------------------------------------------------------------------------
// std::set
// ------------------------------------------------------------------------
%{
#include <set>
#include <stdexcept>
%}
namespace std {
template<class T> class set {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T key_type;
typedef T value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
set();
set(const set& other);
size_t size() const;
bool empty() const;
void clear();
%extend {
bool add(const T& item) {
return self->insert(item).second;
}
bool del(const T& item) {
return self->erase(item) != 0;
}
bool has(const T& item) const {
return self->count(item) != 0;
}
}
};
}

84
Lib/c/std_shared_ptr.i Normal file
View file

@ -0,0 +1,84 @@
// This could be predefined in e.g. our own boost_shared_ptr.i
#ifndef SWIG_SHARED_PTR_NAMESPACE
#define SWIG_SHARED_PTR_NAMESPACE std
#endif
%define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...)
%naturalvar TYPE;
%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
// Replace the default "delete arg1" with the code destroying the smart pointer itself instead.
%feature("unref") TYPE "(void)arg1; delete smartarg1;"
// All smart pointers look like normal objects to the code using the interface.
%typemap(ctype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >&,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >*
"$typemap(ctype, TYPE)";
// Typemap for smart pointer type itself: these are somewhat special because we represent empty shared pointers as null pointers at C level because there is
// no advantage in using a non-null pointer in this case, while testing for NULL is much simpler than testing whether a shared pointer is empty.
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > empty) %{
$1 = $input ? *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr<CONST TYPE>*)$input : empty; %}
%typemap(in) const SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >& (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > empty) %{
$1 = $input ? (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr<CONST TYPE>*)$input : &empty; %}
// Note that "&" here is required because "$1" ends up being SwigValueWrapper and not the shared pointer itself. This is wrong and should be fixed by disabling
// the use of SwigValueWrapper for shared pointers entirely, as it's never needed for them.
%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > %{ $result = (&$1 ? new $1_ltype($1) : 0); %}
// Use of "*" here is due to the fact that "$1" is a pointer, but we want to test the smart pointer itself.
%typemap(out) const SWIG_SHARED_PTR_QNAMESPACE::shared_ptr<CONST TYPE>& %{ $result = (*$1 ? $1 : 0); %}
// And for the plain type.
%typemap(in) CONST TYPE (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
smartarg = (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr<CONST TYPE > *)$input;
if (!smartarg || !smartarg->get()) {
SWIG_exception(SWIG_RuntimeError, "$1_type value is null");
return $null;
}
$1 = **smartarg;%}
%typemap(out) CONST TYPE %{
$result = (SwigObj*) new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr<CONST TYPE >(new $1_ltype($1));%}
// Plain type pointer.
%typemap(in) CONST TYPE * (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
smartarg = (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr<CONST TYPE > *)$input;
$1 = (TYPE *)(smartarg ? smartarg->get() : 0);%}
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE * %{
$result = $1 ? (SwigObj*) new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr<CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0;%}
// Plain type references.
%typemap(in) CONST TYPE & (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
smartarg = (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr<CONST TYPE > *)$input;
if (!smartarg || !smartarg->get()) {
SWIG_exception(SWIG_RuntimeError, "$1_type reference is null");
return $null;
}
$1 = (TYPE *)smartarg->get();%}
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE & %{
$result = (SwigObj*) new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr<CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner);%}
// Allow creating null shared pointers and testing them for validity.
%typemap(cxxcode) TYPE %{
static $cxxclassname null() { return $cxxclassname{($cclassptrname)nullptr, false}; }
explicit operator bool() const { return swig_self_ != nullptr; }
%}
// This is required to handle overloads on shared_ptr/normal type correctly.
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *")
TYPE CONST,
TYPE CONST &,
TYPE CONST *,
TYPE *CONST&,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *&
""
%enddef
%include <shared_ptr.i>

90
Lib/c/std_string.i Normal file
View file

@ -0,0 +1,90 @@
%{
#include <string>
%}
%fragment("SwigStrInOut", "header") {
class SwigStrInOut {
std::string str_;
char* ptr_;
size_t len_;
public:
void init(char* ptr) {
ptr_ = ptr;
if (ptr_) {
str_ = ptr_;
len_ = str_.length();
}
}
std::string* str() { return &str_; }
~SwigStrInOut() {
if (ptr_) {
memcpy(ptr_, str_.c_str(), len_);
ptr_[len_] = '\0';
}
}
};
}
%fragment("include_string", "cxxheader") %{
#include <string>
%}
namespace std {
// use "const string &" typemaps for wrapping member strings
%naturalvar string;
class string;
%typemap(ctype) string, const string & "const char *"
%typemap(ctype) string * "char *"
%typemap(ctype) string & "char *"
%typemap(in) string %{
if ($input)
$1 = $input;
%}
%typemap(in) const string & (std::string temp) %{
if ($input)
temp = $input;
$1 = &temp;
%}
%typemap(in, fragment="SwigStrInOut") string * (SwigStrInOut temp), string & (SwigStrInOut temp) %{
temp.init($input);
$1 = temp.str();
%}
// Note that we don't support strings with embedded NULs, as there is no way to
// return their length to C code anyhow.
%typemap(out) string %{
$result = strdup(cppresult.c_str());
%}
%typemap(out) const string &, string *, string & %{
$result = strdup(cppresult->c_str());
%}
// This is required to warn about clashes between the overloaded functions
// taking strings and raw pointers in the generated wrappers.
%typemap(typecheck) string, const string &, string *, string & = char *;
// Define typemaps for wrapping strings back into std::string in C++ wrappers
// and accepting strings directly.
%typemap(cxxintype, fragment="include_string") string, const string & "std::string const&"
%typemap(cxxin) string, const string & "$1.c_str()"
%typemap(cxxouttype, fragment="include_string") string, const string & "std::string"
%typemap(cxxout, noblock="1") string, const string & %{
$result = std::string($cresult);
free(const_cast<char*>($cresult));
%}
}

91
Lib/c/std_vector.i Normal file
View file

@ -0,0 +1,91 @@
/* -----------------------------------------------------------------------------
* std_vector.i
*
* SWIG typemaps for std::vector
* ----------------------------------------------------------------------------- */
%include <std_common.i>
%{
#include <vector>
#include <stdexcept>
%}
namespace std {
template<class T> class vector {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
vector();
vector(const vector& other);
size_type size() const;
size_type capacity() const;
void reserve(size_type n);
bool empty() const;
void clear();
void push_back(const value_type& x);
%extend {
const_reference get(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
return (*self)[i];
else
throw std::out_of_range("vector index out of range");
}
void set(int i, const value_type& val) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
(*self)[i] = val;
else
throw std::out_of_range("vector index out of range");
}
}
};
// bool specialization
template<> class vector<bool> {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef bool value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef bool const_reference;
vector();
vector(size_type n);
vector(const vector& other);
size_type size() const;
size_type capacity() const;
void reserve(size_type n);
bool empty() const;
void clear();
void push_back(bool x);
%extend {
bool get(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
return (*self)[i];
else
throw std::out_of_range("vector index out of range");
}
void set(int i, bool val) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
(*self)[i] = val;
else
throw std::out_of_range("vector index out of range");
}
}
};
}

12
Lib/c/stl.i Normal file
View file

@ -0,0 +1,12 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* stl.i
* ----------------------------------------------------------------------------- */
%include <std_common.i>
%include <std_string.i>
%include <std_vector.i>
%include <std_map.i>
%include <std_pair.i>

12
Lib/c/typemaps.i Normal file
View file

@ -0,0 +1,12 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* typemaps.i
*
* Pointer handling
* These mappings provide support for input/output arguments and common
* uses for C/C++ pointers.
* ----------------------------------------------------------------------------- */
%include <typemaps/typemaps.swg>

View file

@ -23,6 +23,28 @@ typedef struct SWIGCDATA {
}
%typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
#elif SWIGC
%insert("cheader") {
typedef struct SWIGCDATA {
char *data;
int len;
} SWIGCDATA;
}
%typemap(ctype) SWIGCDATA "SWIGCDATA"
%typemap(cppouttype) SWIGCDATA "SWIGCDATA"
%typemap(out) SWIGCDATA {
$result = $1;
}
%typemap(ctype) (const void *indata, int inlen) "const SWIGCDATA*"
%typemap(in) (const void *indata, int inlen) {
$1 = $input->data;
$2 = $input->len;
}
#elif SWIGPHP
%typemap(out) SWIGCDATA {

View file

@ -72,6 +72,7 @@ skip-perl5 = test -n "@SKIP_PERL5@"
skip-php = test -n "@SKIP_PHP@"
skip-python = test -n "@SKIP_PYTHON@"
skip-r = test -n "@SKIP_R@"
skip-c = test -n "@SKIP_C@"
skip-ruby = test -n "@SKIP_RUBY@"
skip-scilab = test -n "@SKIP_SCILAB@"
skip-tcl = test -n "@SKIP_TCL@"
@ -113,6 +114,7 @@ check-aliveness:
@$(skip-php) || ./$(TARGET) -php7 -help
@$(skip-python) || ./$(TARGET) -python -help
@$(skip-r) || ./$(TARGET) -r -help
@$(skip-c) || ./$(TARGET) -c -help
@$(skip-ruby) || ./$(TARGET) -ruby -help
@$(skip-scilab) || ./$(TARGET) -scilab -help
@$(skip-tcl) || ./$(TARGET) -tcl -help
@ -171,6 +173,7 @@ check-examples: \
check-php-examples \
check-python-examples \
check-r-examples \
check-c-examples \
check-ruby-examples \
check-scilab-examples \
check-tcl-examples \
@ -190,6 +193,7 @@ perl5_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/perl5/check.list)
php_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/php/check.list)
python_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/python/check.list)
r_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/r/check.list)
c_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/c/check.list)
ruby_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/ruby/check.list)
scilab_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/scilab/check.list)
tcl_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/tcl/check.list)
@ -231,6 +235,7 @@ check-test-suite: \
check-php-test-suite \
check-python-test-suite \
check-r-test-suite \
check-c-test-suite \
check-ruby-test-suite \
check-scilab-test-suite \
check-tcl-test-suite \
@ -278,6 +283,7 @@ all-test-suite: \
all-php-test-suite \
all-python-test-suite \
all-r-test-suite \
all-c-test-suite \
all-ruby-test-suite \
all-scilab-test-suite \
all-tcl-test-suite \
@ -301,8 +307,12 @@ broken-test-suite: \
broken-php-test-suite \
broken-python-test-suite \
broken-r-test-suite \
broken-c-test-suite \
broken-scilab-test-suite \
broken-go-test-suite \
broken-d-test-suite \
broken-javascript-test-suite
broken-ruby-test-suite \
broken-scilab-test-suite \
broken-tcl-test-suite \
broken-%-test-suite:
@ -435,7 +445,7 @@ install-main:
@$(INSTALL_PROGRAM) $(TARGET) $(DESTDIR)$(BIN_DIR)/`echo $(TARGET_NOEXE) | sed '$(transform)'`@EXEEXT@
lib-languages = typemaps tcl perl5 python guile java mzscheme ruby php ocaml octave \
csharp lua r go d javascript javascript/jsc \
csharp lua r c go d javascript javascript/jsc \
javascript/v8 scilab xml
lib-modules = std

View file

@ -264,6 +264,11 @@
/* please leave 750-759 free for R */
#define WARN_C_TYPEMAP_CTYPE_UNDEF 760
#define WARN_C_UNSUPPORTTED 761
/* please leave 760-779 free for C */
#define WARN_RUBY_WRONG_NAME 801
#define WARN_RUBY_MULTIPLE_INHERITANCE 802

View file

@ -45,6 +45,7 @@ eswig_SOURCES = CParse/cscanner.c \
Doxygen/pydoc.h \
Modules/allocate.cxx \
Modules/contract.cxx \
Modules/c.cxx \
Modules/csharp.cxx \
Modules/d.cxx \
Modules/directors.cxx \

3177
Source/Modules/c.cxx Normal file

File diff suppressed because it is too large Load diff

View file

@ -26,6 +26,7 @@
can be dynamically loaded in future versions. */
extern "C" {
Language *swig_c(void);
Language *swig_csharp(void);
Language *swig_d(void);
Language *swig_go(void);
@ -52,6 +53,7 @@ extern "C" {
static TargetLanguageModule modules[] = {
{"-allegrocl", NULL, "ALLEGROCL", Disabled},
{"-c", swig_c, "C", Experimental},
{"-chicken", NULL, "CHICKEN", Disabled},
{"-clisp", NULL, "CLISP", Disabled},
{"-cffi", NULL, "CFFI", Disabled},

View file

@ -15,7 +15,7 @@
#include "swig.h"
#include "cparse.h"
extern int UseWrapperSuffix;
extern int UseWrapperSuffix; // from main.cxx
static const char *cresult_variable_name = "result";
@ -58,7 +58,8 @@ const char *Swig_cresult_name(void) {
String *Swig_cparm_name(Parm *p, int i) {
String *name = NewStringf("arg%d", i + 1);
if (p) {
Setattr(p, "lname", name);
String *lname = Getattr(p, "lname");
if (!lname) Setattr(p, "lname", name);
}
return name;

View file

@ -181,6 +181,32 @@ String *Swig_name_mangle_type(const SwigType *s) {
return mangled;
}
/* -----------------------------------------------------------------------------
* Swig_name_type()
*
* Returns the name of a type.
* ----------------------------------------------------------------------------- */
String *Swig_name_type(const_String_or_char_ptr tname) {
String *r, *s;
String* f = naming_hash ? Getattr(naming_hash, "type") : NULL;
/* Don't bother doing anything else if there is no special naming format. */
if (f) {
s = Copy(f);
Replace(s, "%c", tname, DOH_REPLACE_ANY);
} else {
s = (String*)tname;
}
r = Swig_name_mangle_string(s);
if (s != tname)
Delete(s);
return r;
}
/* -----------------------------------------------------------------------------
* Swig_name_mangle_string()
*

View file

@ -276,6 +276,7 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern void Swig_name_register(const_String_or_char_ptr method, const_String_or_char_ptr format);
extern void Swig_name_unregister(const_String_or_char_ptr method);
extern String *Swig_name_type(const_String_or_char_ptr tname);
extern String *Swig_name_mangle_string(const String *s);
extern String *Swig_name_mangle_type(const SwigType *s);
extern String *Swig_name_wrapper(const_String_or_char_ptr fname);

Some files were not shown because too many files have changed in this diff Show more