Commit graph

22 commits

Author SHA1 Message Date
William S Fulton
e75095e6c5 Add OCaml throws typemaps for std::string 2022-07-03 13:35:08 +01:00
William S Fulton
bf36bf7d8a Movable and move-only types supported in "out" typemaps.
Enhance SWIGTYPE "out" typemaps to use std::move when copying
objects, thereby making use of move semantics when wrapping a function returning
by value if the returned type supports move semantics.

Wrapping functions that return move only types 'by value' now work out the box
without having to provide custom typemaps.

The implementation removed all casts in the "out" typemaps to allow the compiler to
appropriately choose calling a move constructor, where possible, otherwise a copy
constructor. The implementation alsoand required modifying SwigValueWrapper to
change a cast operator from:

  SwigValueWrapper::operator T&() const;

to

  #if __cplusplus >=201103L
    SwigValueWrapper::operator T&&() const;
  #else
    SwigValueWrapper::operator T&() const;
  #endif

This is not backwards compatible for C++11 and later when using the valuewrapper feature
if a cast is explicitly being made in user supplied "out" typemaps. Suggested change
in custom "out" typemaps for C++11 and later code:

1. Try remove the cast altogether to let the compiler use an appropriate implicit cast.
2. Change the cast, for example, from static_cast<X &> to static_cast<X &&>, using the
   __cplusplus macro if all versions of C++ need to be supported.

Issue #999
Closes #1044

More about the commit:
Added some missing "varout" typemaps for Ocaml which was falling back to
use "out" typemaps as they were missing.

Ruby std::set fix for SwigValueWrapper C++11 changes.
2022-06-30 17:26:48 +01:00
Zackery Spytz
b7a400f991 [OCaml] Add a typecheck typemap for SWIGTYPE
This fixes many of the remaining warnings in the OCaml test suite.

Add multiple runtime tests.
2019-02-16 01:07:31 -07:00
Zackery Spytz
828ce477c8 [OCaml] Fix a bug in the ctors of director classes
If a class was given the director feature, it was not possible
to use ctors with multiple parameters.

Add director_default_runme.ml (it is based on
director_default_runme.java).
2019-02-05 13:35:43 -07:00
Zackery Spytz
4074f788b3 [OCaml] Fix %allowexception
OCaml's variableWrapper() wasn't calling emit_action_code() for
in/out typemaps, which meant that %allowexception was being ignored.

In addition, remove all comments in the typemaps in Lib/ocaml. In the
case of the allowexcept test, one of the typemap comments caused
compilation to fail because it became nested within another comment
in an %exception block.

Re-enable the allowexcept test.
Add allowexcept_runme.ml.
2019-01-22 07:51:45 -07:00
Zackery Spytz
83df4e8ed6 [OCaml] Fix and re-enable the string_simple, minherit, and unions tests
copy_string() is a macro in the OCaml C API, so rename the function
to copy_str(). Add a runtime test.

The minherit runtime test was fixed by b64d685.

Use the proper syntax for accessing member variables in
unions_runme.ml
2019-01-13 17:28:00 -07:00
William S Fulton
12a9671440 std::string typemap modifications so they can be used with %apply for other string classes
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13120 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-05-26 06:33:49 +00:00
William S Fulton
1fab53b204 [Ocaml] Apply patch #3151788 from Joel Reymont. Brings Ocaml support a up to date (ver 3.11 and 3.12), including std::string.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12460 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2011-02-14 07:22:06 +00:00
William S Fulton
4308dd03cf SWIG license change - The Examples and Lib move to a very permissive license in the LICENSE file, removing the BSD license restrictions as agreed by committers since it was inadvertently introduced. Remove some examples where the impact of the license change is not clear.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11874 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2010-02-27 23:26:02 +00:00
Olly Betts
c836c81acb When wrapping C++ code, generate code which uses
std::string::assign(PTR, LEN) rather than assigning
std::string(PTR, LEN).  Using assign generates more efficient code
(tested with GCC 4.1.2).


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9936 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2007-09-17 20:10:57 +00:00
William S Fulton
49be05f4fd Common template for head of each file detailing licence, distribution and authors information
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8973 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2006-03-07 00:14:10 +00:00
William S Fulton
7d07987098 std::wstring global and member variables are wrapped as strings by default
No need to use the %apply const std::wstring& { std::wstring* } trick anymore


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8626 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2006-01-29 22:32:07 +00:00
William S Fulton
568141faf7 std::string global and member variables are wrapped as strings by default
No need to use the %apply const std::string& { std::string* } trick anymore

Please test if possible, I can't run these languages.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8618 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2006-01-29 18:50:53 +00:00
William S Fulton
cfdad24993 Use the system angle brackets for %include
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7871 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2005-11-26 09:28:20 +00:00
Art Yerkes
e0dca0ec65 shapes example: slight correction to depth map.
makedebugtop: include swig.cmo
Lib: factored out more common code, slightly reorganized class type.
     added director define and exceptions.
     std_string: length from the original ocaml string (no longer depends on
      null termination)
     ocamldec.swg/ocaml.swg: added caml_string_len
Examples/Makefile.in: quiet about checking out files.
Ocaml.cxx:
     Fixed abstract director test case.
     Include/exclude director.swg based on directors being enabled.
Final edits for 1.3.20, barring bugs being discovered.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5477 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2003-12-04 06:15:07 +00:00
Art Yerkes
0f445779b9 All test cases work.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4868 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2003-06-06 04:29:38 +00:00
Art Yerkes
f7d59cab5d All but four test cases work. I'm going to leave these for afterward.
I've moved completely away from the "value" type to "caml_value_t".  Although
a bit painful, this will make things easier for me.  I seem to be seeing
quite a few things that use the word value as a function, type, etc, and
wanted to get something that doesn't collide.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4593 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2003-03-20 20:51:05 +00:00
Art Yerkes
4b2da49eb3 Added:
Type registration.  Correct support for casting.  Proper type safety.
Changed:
ocaml.swg: Correct casts, declaration order for C
ocamldec.swg: Removed problematic forward declarations without array index.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4573 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2003-03-19 16:24:47 +00:00
Art Yerkes
ade9d25284 Director: added disown. It now mutates the reference held by the object.
mlheading and mliheading: Added C_director_core, which holds the state needed
by the director to disown.
std_string and std_vector: Added specific support for the common case of
a zero-terminated char **.
typemaps.i: Withdraw default argout for SWIGTYPE &


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4481 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2003-03-08 20:14:31 +00:00
Art Yerkes
b8490f9c18 Added to typemaps: reference type in/out
Strings <=> std::string by value
std::wstring accessible from Ocaml.  The string example converts a multibyte
japanese EUC sequence to a single wchar_t sequence if you have the ja_JP.EUC-JP
locale, or similar.
Better handling of reference in types
Corrected problems with & * mismatch in type verifier.
Type verifier now really functional.  No more type errors in places they
wouldn't be allowed in C++, unless you work at it.
Added argout_ref example for argout_ref.
Init code now effective (called from let _ = f_<module>_init ())


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4412 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2003-02-27 07:09:12 +00:00
Art Yerkes
88b15ce253 corrections for std::string.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4325 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2003-02-16 13:32:40 +00:00
Dave Beazley
12a43edc2d The great merge
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4141 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2002-11-30 22:01:28 +00:00