Commit graph

82 commits

Author SHA1 Message Date
William S Fulton
46f7501d94 Cleanup SWIG_VERSION definition
Add Swig_obligatory_macros which must be called by each
target language to define SWIG_VERSION correctly
in the generated code, as well as the language specific
macro SWIGXXX where XXX is the target language name.

Drop the #ifdef SWIGXXX that was previously generated -
I can't see the point of this and if users are defining
this macro somehow, then users will need to change this

Closes #1050
2022-10-13 19:47:43 +01:00
Olly Betts
4ac3c87a29 Sort out predefined SWIG-specific macros
Ensure that SWIG_VERSION is defined both at SWIG-time and in the
generated C/C++ wrapper code (it was only defined in the wrapper
for some target languages previously).

SWIGGO and SWIGJAVASCRIPT are now defined in the generated wrappers
to match behaviour for all other target languages.

Stop defining SWIGVERSION in the wrapper.  This only happened as a
side-effect of how SWIG_VERSION was defined but was never documented and
is redundant.

The new testcase also checks that SWIG is defined at SWIG-time but not
in the generated wrapper, and that exactly one of a list of
target-language specific macros is defined.

Fixes #1050
2022-10-05 12:40:15 +13:00
William S Fulton
ed333b6b97 std::string throws typemaps
Go, Guile, Racket, Scilab: Add throws typemaps for std::string so that
thrown string exception messages can be seen.

Test all language for std::string throws typemaps
2022-09-19 09:09:29 +01:00
William S Fulton
dad7c93ca0 Provide SWIGTYPE MOVE typemaps in swigmove.i
For implementing full move semantics when passing parameters by value.
Based on SWIGTYPE && and std::unique_ptr typemaps which implement move
semantics.

Added for all languages, but untested for: Go, Ocaml, R, Scilab (and
unlikely to be fully functional for same reasons as for std::unique_ptr
support).

Issue #999
2022-09-16 08:36:25 +01:00
William S Fulton
3f622ea65e SWIGTYPE && input typemaps now assume object has been moved - Go and OCaml
Not fully implemented and Untested.
Go's implementation needs fixing to fully support typemaps
before this can be done.
OCaml implementation does not have support for releasing ownership
which is required to add error checking preventing double deletes.
2022-08-31 19:40:13 +01:00
Ian Lance Taylor
87cbf8c341 [Go] #2245 Handle NULL pointers for string* conversions.
Rearrange generation of director methods and rename
receiver argument from p to swig_p.

Fixes #2245
2022-07-05 17:00:48 -07:00
William S Fulton
71cd6a38fe Performance optimisation for directors for classes passed by value
The directorin typemaps in the director methods now use std::move on the
input parameter when copying the object from the stack to the heap prior
to the callback into the target language, thereby taking advantage of
move semantics if available.
2022-07-04 11:19:29 +01:00
Olly Betts
2da3815f99 [Go] Make -intgosize optional
We no longer support Go < 1.2 so we can default intgo to ptrdiff_t
and uintgo to size_t.

Fixes #683
Fixes #2233
2022-03-16 18:30:05 +13:00
Ian Lance Taylor
0c0b93f8e0 [Go] add typemaps for std::string*
Fixes #2214
2022-03-15 20:30:53 -07:00
Ian Lance Taylor
70d530adfc swig -go: treat a nil argument as NULL
Let Go code pass "nil" when calling a C++ function that accepts a
pointer to a class.  The Go "nil" will be treated as a C++ "nullptr".

Fixes #2203
2022-03-08 15:15:05 -08:00
Ian Lance Taylor
a4c82052ce swig -go: free correct variable in char *& typemap 2022-03-06 21:58:13 -08:00
Ian Lance Taylor
27bdbc1f05 swig -go: treat non-const references as pointers
Also clean up the handling of int* and int& to convert between the C
type int and the Go type int, which are often different sizes.

Fixes #2210
2022-03-05 21:57:36 -08:00
Seth R Johnson
de78b80de9 Renames performed by %namewarn with rename= are printed in warning message
This is necessary for regex-like renames (where you can't use the #define trick
as is done in many of the %keywordwarn directives). It's now unnecessary to print
the "renaming to '`x`'" code explicitly by the kw.swg files.
2022-02-06 13:51:37 -05:00
ERROR
d73f933c4b
Support std::array in Golang (#2045)
Support std::array in Golang

Closes #2045
2022-01-04 12:12:56 +13:00
Ian Lance Taylor
6ca5d5d722 swig -go: don't use crosscall2 for panicking
Instead rely only on documented and exported interfaces.
2021-09-15 17:56:01 -07:00
Ian Lance Taylor
4461c443cf remove Go -no-cgo option
It only worked for Go versions before 1.5, which is more than five
years ago and long-unsupported.
2021-09-14 13:59:21 -07:00
William S Fulton
52063a732b Consistent parameter names for std::pair 2019-02-14 22:44:27 +00:00
William S Fulton
6d27ead9c0 Add STL container copy constructors where missing
Also provide consistent copy constructor declarations.
2019-02-14 18:53:05 +00:00
William S Fulton
440264e479 Add missing typedefs to std::list + typedef corrections
Numerous missing typedefs added.
std::list<T*>::const_reference and std::list<T*>::reference
specialization typedef fixes.
2019-02-14 07:31:21 +00:00
William S Fulton
e26f6bb4e2 Add missing typedefs to std::vector + typedef corrections
Tests for std::vector of pointers added which check
 std::vector<T*>::const_reference and std::vector<T*>::reference
usage which gave compilation errors in Python and Perl which had
specialized these vectors incorrectly.
2019-02-13 22:46:28 +00:00
William S Fulton
a47c2553f5 Add missing typedefs to std::pair 2019-02-13 22:46:28 +00:00
William S Fulton
9dd33e6367 Add missing typedefs to std::map 2019-02-13 22:46:27 +00:00
William S Fulton
6d0c495fd0 Add missing parameter names in STL container wrappers
Mostly in STL copy constructors.

Best to have parameter names as they make their way into the wrappers in
some target languages.
2019-02-13 22:45:47 +00:00
William S Fulton
68e86614ff Create a consistent stl.i library file
Same file now for all languages except R which is still missing std_map.i.
Recent Java changes adding in std_set.i removed.
2019-02-12 18:46:05 +00:00
William S Fulton
ca287ae13b Add support for non-default compare template argument in std::map wrappers 2018-10-09 19:44:00 +01:00
William S Fulton
bea708c796 Go - use director.swg like other languages
Changes the location of the director code wrt to the generated _wrap.h
file to fix throw macro skullduggery in the director_throws testcase
(see previous commit).
2018-05-06 09:46:37 +01:00
William S Fulton
e86c881a70 Fix directorout typemaps which were causing undefined behaviour when returning pointers by reference.
Closes #1167
2017-12-14 07:00:42 +00:00
William S Fulton
923091da13 Changes to use common DirectorException class
Add director.swg for Go as was completely absent.
This is just the start of a common exception handling approach to directors.
An exception thrown in a Java director method will be propogated back to
Java via a C++ DirectorException.
DirectorException throws typemap for Java is fully working, all other languages need work.
DirectorException throws typemap for Perl added just to fix compilation errors.
Add director_exception_catches test.
2017-11-29 20:31:55 +00:00
William S Fulton
72ba741d1c Fix wrapping of references/pointers and qualifiers to member pointers
Also fix Go wrapping of member const function pointers.
2017-03-16 21:04:38 +00:00
Daniel Vollmer
ce1cb85d86 Add <typeinfo> header for std::bad_cast 2016-09-17 13:24:32 +02:00
Daniel Vollmer
2dc87d7485 Add std::bad_cast to std_except.i
This exception occurs when dynamic_cast<T&> fails.

Fixes #783.
2016-09-17 10:26:54 +02:00
William S Fulton
98a31ff633 Fix directorin SWIGTYPE typemaps to make a copy as these are used for pass by value.
Closes #434
2016-05-14 21:32:24 +01:00
Ian Lance Taylor
9cd3e28c4e [Go] Fix "in" typemap for char *&. 2016-04-17 22:20:28 -07:00
Ian Lance Taylor
223c2a4835 [Go] Fixes for Go 1.6: avoid returning Go pointers from
directors that return string values; add a trailing 0 byte
when treating Go string as C char*.
2016-04-17 17:52:09 -07:00
Ian Lance Taylor
15b75a74c5 [Go] Ensure structs are properly packed between gc and GCC/clang.
From https://github.com/swig/swig/pull/262.
2016-01-27 15:51:13 -08:00
Rick Luddy
b1204ce92f Revert reference change; update CHANGES.current 2015-09-03 14:30:18 -04:00
Rick Luddy
a1e385694e Removed golang stringing for signed/unsigned char
With this change, generated code for golang treats char* as a string but
treats signed char* and unsigned char* as normal pointers. This seems to
fit better with the expected behavior, as the latter are more often used
as non-string data.
2015-08-25 09:17:19 -04:00
Ian Lance Taylor
48263f4802 [Go] Make sure that arguments for which use memcpy when calling C are
still live after the call.  This ensures that they will not be
collected if the GC runs during the call.
2015-05-04 15:11:31 -07:00
Ian Lance Taylor
661c4ba036 [Go] Add comments telling users that _swig_goallocate and
_swig_makegostring will no longer work in the Go 1.5 release.
Keep the existing code so that existing users with current versions of
Go will not break suddenly.
2015-04-17 09:44:40 -07:00
Ian Lance Taylor
9ad497c08e [Go] Add -cgo option, required for Go version 1.5 and later. 2015-03-02 14:03:33 -08:00
Ian Lance Taylor
1dd401899f [Go] Change SWIG directors to use a handle instead of a Go pointer.
In future releases of Go it will not be possible to pass Go pointers
into C/C++ code.  The handle is automatically translated back to the
Go value using a Go map.  Since directors must be explicitly deleted,
we can reliably use that call to remove the handle from the map.
2015-02-22 11:09:58 -08:00
William S Fulton
2947b711d9 Warning fixes in Go cdata library
GCC warnings -Wpointer-to-int-cast and -Wdeclaration-after-statement
2015-02-11 23:34:16 +00:00
Ian Lance Taylor
0a021a938e [Go] Remove all generated calls to _swig_makegostring, as it will no
longer as of Go 1.5.  In Go 1.5 or later user calls to
_swig_makegostring will fail at link time.

Instead, use goout and godirectorin typemaps to allocate strings in Go
code.

Change the Go typemaps support to ignore empty strings, so that we can
define empty strings for regular types so that %apply will override
the definitions for string types.

Fix the gccgo code to wrap SwigCgoCallback around all godirectorin
typemaps.

Add a few newlines after typemap code so that the typemaps don't have
to include them.
2015-02-05 10:15:37 -08:00
Ian Lance Taylor
2562c1eb41 [Go] Remove all calls to _swig_goallocate in the Go runtime, except
for the one from _swig_makegostring.  _swig_goallocate can not work
with the future Go 1.5 release.  When using Go 1.5 attempts to call
_swig_goallocate will fail at link time.
2015-02-04 16:08:44 -08:00
William S Fulton
fd8dcf44bf C++11 strongly typed enum fixes for directors
Tests added for previous commit. Further refinements to patch #308 and
fixes #307.
2015-01-15 19:48:07 +00:00
Ian Lance Taylor
0577ff2220 [Go] Adjust last patch to avoid write-after-write data race on global
variable.  Only set the variable if another global variable is true,
but that variable is always false.  The effect is that the variable is
never written, but as far as the compiler is concerned it might escape.
2014-10-14 10:05:43 -07:00
Ian Lance Taylor
4b64ce71a3 [Go] Adjust generated code to work with upcoming Go 1.4 release. 2014-09-25 12:10:11 -07:00
Ian Lance Taylor
acaaa0f31f [Go] Add goargout typemap. 2014-09-09 11:28:04 -07:00
Karl Wette
66555ad2a7 Fix go configuration and SWIG_GCC_VERSION
- in configure.ac: modify sed expression to only look at first line of
  gccgo --version, extract the last numeric token, and remove periods;
  this parses e.g. "gccgo (Debian 4.7.2-5) 4.7.2"
- in goruntime.swg: fix typo in __GNUC_PATCHLEVEL__ (SF Bug #1298)
2014-05-02 21:44:52 +02:00
Marvin Greenberg
843aa7cd65 Work around differences in clang libc++ std::vector<bool>::const_reference
clang++ using -stdlib=libc++ defines const_reference as a class,
to map boolean vectors onto a bit set.  Because swig does
not "see" the type as "const &" it generates incorrect code for this case,
generating a declaration like:

  const_reference result;

When const_reference is a typedef to 'bool' as is the case with stdlibc++
this works.  When this is actually a constant reference, this is clearly
invalid since it is not initialized.  For libc++, this is a class
which cannot be default constructed, resulting in an error.  The fix
is to explicitly define the various accessor extensions as having a
bool return type for this specialization.
2014-02-04 16:00:12 -05:00