diff options
author | Zackery Spytz <zspytz@gmail.com> | 2019-05-08 14:05:02 -0600 |
---|---|---|
committer | Zackery Spytz <zspytz@gmail.com> | 2019-05-08 14:05:02 -0600 |
commit | 2f48bec6665628e5d05159fdfca49c1853572b84 (patch) | |
tree | e0effbe3ec0206307e09df4981f36fe31432ea48 /Lib | |
parent | 1eb9cd3211ef646aa4683dd976eb2d06d6826bcc (diff) | |
parent | f06330e720b0867817679fbf67aa8705ce13bbcf (diff) | |
download | swig-2f48bec6665628e5d05159fdfca49c1853572b84.tar.gz |
Merge remote-tracking branch 'upstream/master' into OCaml-INPUT-OUTPUT-INOUT-primitives
Diffstat (limited to 'Lib')
46 files changed, 1152 insertions, 273 deletions
diff --git a/Lib/chicken/chickenrun.swg b/Lib/chicken/chickenrun.swg index d4255c365..bb14b4bc9 100644 --- a/Lib/chicken/chickenrun.swg +++ b/Lib/chicken/chickenrun.swg @@ -7,7 +7,7 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> -#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) +#if (defined(_MSC_VER) && (_MSC_VER < 1900)) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf # define snprintf _snprintf # endif diff --git a/Lib/csharp/boost_intrusive_ptr.i b/Lib/csharp/boost_intrusive_ptr.i index 6b0392d3d..fa3f53a20 100644 --- a/Lib/csharp/boost_intrusive_ptr.i +++ b/Lib/csharp/boost_intrusive_ptr.i @@ -314,7 +314,7 @@ } %} -%typemap(csdestruct, methodname="Dispose", methodmodifiers="public") TYPE { +%typemap(csdisposing, methodname="Dispose", methodmodifiers="protected", parameters="bool disposing") TYPE { lock(this) { if (swigCPtr.Handle != global::System.IntPtr.Zero) { if (swigCMemOwnBase) { @@ -323,11 +323,10 @@ } swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } - global::System.GC.SuppressFinalize(this); } } -%typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") TYPE { +%typemap(csdisposing_derived, methodname="Dispose", methodmodifiers="protected", parameters="bool disposing") TYPE { lock(this) { if (swigCPtr.Handle != global::System.IntPtr.Zero) { if (swigCMemOwnDerived) { @@ -336,8 +335,7 @@ } swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } - global::System.GC.SuppressFinalize(this); - base.Dispose(); + base.Dispose(disposing); } } @@ -473,7 +471,7 @@ } %} -%typemap(csdestruct, methodname="Dispose", methodmodifiers="public") TYPE { +%typemap(csdisposing, methodname="Dispose", methodmodifiers="protected", parameters="bool disposing") TYPE { lock(this) { if (swigCPtr.Handle != global::System.IntPtr.Zero) { if (swigCMemOwnBase) { @@ -482,11 +480,10 @@ } swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } - global::System.GC.SuppressFinalize(this); } } -%typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") TYPE { +%typemap(csdisposing_derived, methodname="Dispose", methodmodifiers="protected", parameters="bool disposing") TYPE { lock(this) { if (swigCPtr.Handle != global::System.IntPtr.Zero) { if (swigCMemOwnDerived) { @@ -495,8 +492,7 @@ } swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } - global::System.GC.SuppressFinalize(this); - base.Dispose(); + base.Dispose(disposing); } } diff --git a/Lib/csharp/boost_shared_ptr.i b/Lib/csharp/boost_shared_ptr.i index 73212dddc..508c0ec14 100644 --- a/Lib/csharp/boost_shared_ptr.i +++ b/Lib/csharp/boost_shared_ptr.i @@ -282,7 +282,7 @@ } %} -%typemap(csdestruct, methodname="Dispose", methodmodifiers="public") TYPE { +%typemap(csdisposing, methodname="Dispose", methodmodifiers="protected", parameters="bool disposing") TYPE { lock(this) { if (swigCPtr.Handle != global::System.IntPtr.Zero) { if (swigCMemOwnBase) { @@ -291,11 +291,10 @@ } swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } - global::System.GC.SuppressFinalize(this); } } -%typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") TYPE { +%typemap(csdisposing_derived, methodname="Dispose", methodmodifiers="protected", parameters="bool disposing") TYPE { lock(this) { if (swigCPtr.Handle != global::System.IntPtr.Zero) { if (swigCMemOwnDerived) { @@ -304,8 +303,7 @@ } swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } - global::System.GC.SuppressFinalize(this); - base.Dispose(); + base.Dispose(disposing); } } diff --git a/Lib/csharp/csharp.swg b/Lib/csharp/csharp.swg index e1554dcb8..832206386 100644 --- a/Lib/csharp/csharp.swg +++ b/Lib/csharp/csharp.swg @@ -959,17 +959,24 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { SWIG_CSBODY_PROXY(internal, internal, SWIGTYPE) SWIG_CSBODY_TYPEWRAPPER(internal, protected, internal, SWIGTYPE) -%typemap(csfinalize) SWIGTYPE %{ +%typemap(csdispose) SWIGTYPE %{ ~$csclassname() { - Dispose(); + Dispose(false); + } + + public void Dispose() { + Dispose(true); + global::System.GC.SuppressFinalize(this); } %} +%typemap(csdispose_derived) SWIGTYPE "" + %typemap(csconstruct, excode=SWIGEXCODE,directorconnect="\n SwigDirectorConnect();") SWIGTYPE %{: this($imcall, true) {$excode$directorconnect } %} -%typemap(csdestruct, methodname="Dispose", methodmodifiers="public") SWIGTYPE { +%typemap(csdisposing, methodname="Dispose", methodmodifiers="protected", parameters="bool disposing") SWIGTYPE { lock(this) { if (swigCPtr.Handle != global::System.IntPtr.Zero) { if (swigCMemOwn) { @@ -978,11 +985,10 @@ SWIG_CSBODY_TYPEWRAPPER(internal, protected, internal, SWIGTYPE) } swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } - global::System.GC.SuppressFinalize(this); } } -%typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") SWIGTYPE { +%typemap(csdisposing_derived, methodname="Dispose", methodmodifiers="protected", parameters="bool disposing") SWIGTYPE { lock(this) { if (swigCPtr.Handle != global::System.IntPtr.Zero) { if (swigCMemOwn) { @@ -991,8 +997,7 @@ SWIG_CSBODY_TYPEWRAPPER(internal, protected, internal, SWIGTYPE) } swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } - global::System.GC.SuppressFinalize(this); - base.Dispose(); + base.Dispose(disposing); } } diff --git a/Lib/csharp/csharphead.swg b/Lib/csharp/csharphead.swg index 0b55635b3..7db4c0e3c 100644 --- a/Lib/csharp/csharphead.swg +++ b/Lib/csharp/csharphead.swg @@ -244,6 +244,7 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionArgumentCallbacks_$module( [global::System.ThreadStatic] private static global::System.Exception pendingException = null; private static int numExceptionsPending = 0; + private static global::System.Object exceptionsLock = null; public static bool Pending { get { @@ -259,7 +260,7 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionArgumentCallbacks_$module( if (pendingException != null) throw new global::System.ApplicationException("FATAL: An earlier pending exception from unmanaged code was missed and thus not thrown (" + pendingException.ToString() + ")", e); pendingException = e; - lock(typeof($imclassname)) { + lock(exceptionsLock) { numExceptionsPending++; } } @@ -270,13 +271,17 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionArgumentCallbacks_$module( if (pendingException != null) { e = pendingException; pendingException = null; - lock(typeof($imclassname)) { + lock(exceptionsLock) { numExceptionsPending--; } } } return e; } + + static SWIGPendingException() { + exceptionsLock = new global::System.Object(); + } } %} #endif // SWIG_CSHARP_NO_EXCEPTION_HELPER diff --git a/Lib/csharp/std_array.i b/Lib/csharp/std_array.i index e7d392b85..a4f0f9640 100644 --- a/Lib/csharp/std_array.i +++ b/Lib/csharp/std_array.i @@ -192,9 +192,9 @@ else throw std::out_of_range("index"); } - void setitem(int index, const_reference value) throw (std::out_of_range) { + void setitem(int index, const_reference val) throw (std::out_of_range) { if (index>=0 && index<(int)$self->size()) - (*$self)[index] = value; + (*$self)[index] = val; else throw std::out_of_range("index"); } diff --git a/Lib/csharp/std_list.i b/Lib/csharp/std_list.i new file mode 100644 index 000000000..674aba0ab --- /dev/null +++ b/Lib/csharp/std_list.i @@ -0,0 +1,519 @@ +/* ----------------------------------------------------------------------------- + * std_list.i + * + * SWIG typemaps for std::list<T> + * C# implementation + * The C# wrapper is made to look and feel like a C# System.Collections.Generic.LinkedList<> collection. + * + * Note that IEnumerable<> is implemented in the proxy class which is useful for using LINQ with + * C++ std::list wrappers. The ICollection<> interface is also implemented to provide enhanced functionality + * whenever we are confident that the required C++ operator== is available. This is the case for when + * T is a primitive type or a pointer. If T does define an operator==, then use the SWIG_STD_LIST_ENHANCED + * macro to obtain this enhanced functionality, for example: + * + * SWIG_STD_LIST_ENHANCED(SomeNamespace::Klass) + * %template(ListKlass) std::list<SomeNamespace::Klass>; + * ----------------------------------------------------------------------------- */ + +%include <std_common.i> + +// MACRO for use within the std::list class body +%define SWIG_STD_LIST_MINIMUM_INTERNAL(CSINTERFACE, CTYPE...) +%typemap(csinterfaces) std::list< CTYPE > "global::System.IDisposable, global::System.Collections.IEnumerable, global::System.Collections.Generic.CSINTERFACE<$typemap(cstype, CTYPE)>\n"; + +%apply void *VOID_INT_PTR { std::list< CTYPE >::iterator * }; + +%proxycode %{ + public $csclassname(global::System.Collections.IEnumerable c) : this() { + if (c == null) + throw new global::System.ArgumentNullException("c"); + foreach ($typemap(cstype, CTYPE) element in c) { + this.AddLast(element); + } + } + + public bool IsReadOnly { + get { + return false; + } + } + + public int Count { + get { + return (int)size(); + } + } + + public $csclassnameNode First { + get { + if (Count == 0) + return null; + return new $csclassnameNode(getFirstIter(), this); + } + } + + public $csclassnameNode Last { + get { + if (Count == 0) + return null; + return new $csclassnameNode(getLastIter(), this); + } + } + + public $csclassnameNode AddFirst($typemap(cstype, CTYPE) value) { + push_front(value); + return new $csclassnameNode(getFirstIter(), this); + } + + public void AddFirst($csclassnameNode newNode) { + ValidateNewNode(newNode); + if (!newNode.inlist) { + push_front(newNode.csharpvalue); + newNode.iter = getFirstIter(); + newNode.inlist = true; + } else { + throw new global::System.InvalidOperationException("The " + newNode.GetType().Name + " node already belongs to a " + this.GetType().Name); + } + } + + public $csclassnameNode AddLast($typemap(cstype, CTYPE) value) { + push_back(value); + return new $csclassnameNode(getLastIter(), this); + } + + public void AddLast($csclassnameNode newNode) { + ValidateNewNode(newNode); + if (!newNode.inlist) { + push_back(newNode.csharpvalue); + newNode.iter = getLastIter(); + newNode.inlist = true; + } else { + throw new global::System.InvalidOperationException("The " + newNode.GetType().Name + " node already belongs to a " + this.GetType().Name); + } + } + + public $csclassnameNode AddBefore($csclassnameNode node, $typemap(cstype, CTYPE) value) { + return new $csclassnameNode(insertNode(node.iter, value), this); + } + + public void AddBefore($csclassnameNode node, $csclassnameNode newNode) { + ValidateNode(node); + ValidateNewNode(newNode); + if (!newNode.inlist) { + newNode.iter = insertNode(node.iter, newNode.csharpvalue); + newNode.inlist = true; + } else { + throw new global::System.InvalidOperationException("The " + newNode.GetType().Name + " node already belongs to a " + this.GetType().Name); + } + } + + public $csclassnameNode AddAfter($csclassnameNode node, $typemap(cstype, CTYPE) value) { + node = node.Next; + return new $csclassnameNode(insertNode(node.iter, value), this); + } + + public void AddAfter($csclassnameNode node, $csclassnameNode newNode) { + ValidateNode(node); + ValidateNewNode(newNode); + if (!newNode.inlist) { + if (node == this.Last) + AddLast(newNode); + else + { + node = node.Next; + newNode.iter = insertNode(node.iter, newNode.csharpvalue); + newNode.inlist = true; + } + } else { + throw new global::System.InvalidOperationException("The " + newNode.GetType().Name + " node already belongs to a " + this.GetType().Name); + } + } + + public void Add($typemap(cstype, CTYPE) value) { + AddLast(value); + } + + public void Remove($csclassnameNode node) { + ValidateNode(node); + eraseIter(node.iter); + } + + public void CopyTo($typemap(cstype, CTYPE)[] array, int index) { + if (array == null) + throw new global::System.ArgumentNullException("array"); + if (index < 0 || index > array.Length) + throw new global::System.ArgumentOutOfRangeException("index", "Value is less than zero"); + if (array.Rank > 1) + throw new global::System.ArgumentException("Multi dimensional array.", "array"); + $csclassnameNode node = this.First; + if (node != null) { + do { + array[index++] = node.Value; + node = node.Next; + } while (node != null); + } + } + + internal void ValidateNode($csclassnameNode node) { + if (node == null) { + throw new System.ArgumentNullException("node"); + } + if (!node.inlist || node.list != this) { + throw new System.InvalidOperationException("node"); + } + } + + internal void ValidateNewNode($csclassnameNode node) { + if (node == null) { + throw new System.ArgumentNullException("node"); + } + } + + global::System.Collections.Generic.IEnumerator<$typemap(cstype, CTYPE)> global::System.Collections.Generic.IEnumerable<$typemap(cstype, CTYPE)>.GetEnumerator() { + return new $csclassnameEnumerator(this); + } + + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { + return new $csclassnameEnumerator(this); + } + + public $csclassnameEnumerator GetEnumerator() { + return new $csclassnameEnumerator(this); + } + + public sealed class $csclassnameEnumerator : global::System.Collections.IEnumerator, + global::System.Collections.Generic.IEnumerator<$typemap(cstype, CTYPE)> + { + private $csclassname collectionRef; + private $csclassnameNode currentNode; + private int currentIndex; + private object currentObject; + private int currentSize; + + public $csclassnameEnumerator($csclassname collection) { + collectionRef = collection; + currentNode = collection.First; + currentIndex = 0; + currentObject = null; + currentSize = collectionRef.Count; + } + + // Type-safe iterator Current + public $typemap(cstype, CTYPE) Current { + get { + if (currentIndex == -1) + throw new global::System.InvalidOperationException("Enumeration not started."); + if (currentIndex > currentSize) + throw new global::System.InvalidOperationException("Enumeration finished."); + if (currentObject == null) + throw new global::System.InvalidOperationException("Collection modified."); + return ($typemap(cstype, CTYPE))currentObject; + } + } + + // Type-unsafe IEnumerator.Current + object global::System.Collections.IEnumerator.Current { + get { + return Current; + } + } + + public bool MoveNext() { + if (currentNode == null) { + currentIndex = collectionRef.Count + 1; + return false; + } + ++currentIndex; + currentObject = currentNode.Value; + currentNode = currentNode.Next; + return true; + } + + public void Reset() { + currentIndex = -1; + currentObject = null; + if (collectionRef.Count != currentSize) { + throw new global::System.InvalidOperationException("Collection modified."); + } + } + + public void Dispose() { + currentIndex = -1; + currentObject = null; + } + } + + public sealed class $csclassnameNode { + internal $csclassname list; + internal System.IntPtr iter; + internal $typemap(cstype, CTYPE) csharpvalue; + internal bool inlist; + + public $csclassnameNode($typemap(cstype, CTYPE) value) { + csharpvalue = value; + inlist = false; + } + + internal $csclassnameNode(System.IntPtr iter, $csclassname list) { + this.list = list; + this.iter = iter; + inlist = true; + } + + public $csclassname List { + get { + return this.list; + } + } + + public $csclassnameNode Next { + get { + if (list.getNextIter(iter) == System.IntPtr.Zero) + return null; + return new $csclassnameNode(list.getNextIter(iter), list); + } + } + + public $csclassnameNode Previous { + get { + if (list.getPrevIter(iter) == System.IntPtr.Zero) + return null; + return new $csclassnameNode(list.getPrevIter(iter), list); + } + } + + public $typemap(cstype, CTYPE) Value { + get { + return list.getItem(this.iter); + } + set { + list.setItem(this.iter, value); + } + } + + public static bool operator==($csclassnameNode node1, $csclassnameNode node2) { + if (object.ReferenceEquals(node1, null) && object.ReferenceEquals(node2, null)) + return true; + if (object.ReferenceEquals(node1, null) || object.ReferenceEquals(node2, null)) + return false; + return node1.Equals(node2); + } + + public static bool operator!=($csclassnameNode node1, $csclassnameNode node2) { + if (node1 == null && node2 == null) + return false; + if (node1 == null || node2 == null) + return true; + return !node1.Equals(node2); + } + + public bool Equals($csclassnameNode node) { + if (node == null) + return false; + if (!node.inlist || !this.inlist) + return object.ReferenceEquals(this, node); + return list.equals(this.iter, node.iter); + } + + public override bool Equals(object node) { + return Equals(($csclassnameNode)node); + } + + public override int GetHashCode() { + int hash = 13; + if (inlist) { + hash = (hash * 7) + this.list.GetHashCode(); + hash = (hash * 7) + this.Value.GetHashCode(); + hash = (hash * 7) + this.list.getNextIter(this.iter).GetHashCode(); + hash = (hash * 7) + this.list.getPrevIter(this.iter).GetHashCode(); + } else { + hash = (hash * 7) + this.csharpvalue.GetHashCode(); + } + return hash; + } + + public void Dispose() { + list.deleteIter(this.iter); + } + } +%} + +public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef CTYPE value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + + class iterator; + + void push_front(CTYPE const& x); + void push_back(CTYPE const& x); + %rename(RemoveFirst) pop_front; + void pop_front(); + %rename(RemoveLast) pop_back; + void pop_back(); + size_type size() const; + %rename(Clear) clear; + void clear(); + %extend { + const_reference getItem(iterator *iter) { + return **iter; + } + + void setItem(iterator *iter, CTYPE const& val) { + *(*iter) = val; + } + + iterator *getFirstIter() { + if ($self->size() == 0) + return NULL; + return new std::list< CTYPE >::iterator($self->begin()); + } + + iterator *getLastIter() { + if ($self->size() == 0) + return NULL; + return new std::list< CTYPE >::iterator(--$self->end()); + } + + iterator *getNextIter(iterator *iter) { + std::list< CTYPE >::iterator it = *iter; + if (std::distance(it, --$self->end()) != 0) { + std::list< CTYPE >::iterator* itnext = new std::list< CTYPE >::iterator(++it); + return itnext; + } + return NULL; + } + + iterator *getPrevIter(iterator *iter) { + std::list< CTYPE >::iterator it = *iter; + if (std::distance($self->begin(), it) != 0) { + std::list< CTYPE >::iterator* itprev = new std::list< CTYPE >::iterator(--it); + return itprev; + } + return NULL; + } + + iterator *insertNode(iterator *iter, CTYPE const& value) { + std::list< CTYPE >::iterator it = $self->insert(*iter, value); + return new std::list< CTYPE >::iterator(it); + } + + void eraseIter(iterator *iter) { + std::list< CTYPE >::iterator it = *iter; + $self->erase(it); + } + + void deleteIter(iterator *iter) { + delete iter; + } + + bool equals(iterator *iter1, iterator *iter2) { + if (iter1 == NULL && iter2 == NULL) + return true; + std::list< CTYPE >::iterator it1 = *iter1; + std::list< CTYPE >::iterator it2 = *iter2; + return it1 == it2; + } + } +%enddef + +// Extra methods added to the collection class if operator== is defined for the class being wrapped +// The class will then implement ICollection<>, which adds extra functionality +%define SWIG_STD_LIST_EXTRA_OP_EQUALS_EQUALS(CTYPE...) + %extend { + bool Contains(CTYPE const& value) { + return std::find($self->begin(), $self->end(), value) != $self->end(); + } + + bool Remove(CTYPE const& value) { + std::list< CTYPE >::iterator it = std::find($self->begin(), $self->end(), value); + if (it != $self->end()) { + $self->erase(it); + return true; + } + return false; + } + + iterator *find(CTYPE const& value) { + if (std::find($self->begin(), $self->end(), value) != $self->end()) { + return new std::list< CTYPE >::iterator(std::find($self->begin(), $self->end(), value)); + } + return NULL; + } + } +%proxycode %{ + public $csclassnameNode Find($typemap(cstype, CTYPE) value) { + System.IntPtr tmp = find(value); + if (tmp != System.IntPtr.Zero) { + return new $csclassnameNode(tmp, this); + } + return null; + } +%} +%enddef + +// Macros for std::list class specializations/enhancements +%define SWIG_STD_LIST_ENHANCED(CTYPE...) +namespace std { + template<> class list< CTYPE > { + SWIG_STD_LIST_MINIMUM_INTERNAL(ICollection, %arg(CTYPE)); + SWIG_STD_LIST_EXTRA_OP_EQUALS_EQUALS(CTYPE) + }; +} +%enddef + + +%{ +#include <list> +#include <algorithm> +#include <stdexcept> +%} + +%csmethodmodifiers std::list::size "private" +%csmethodmodifiers std::list::getItem "private" +%csmethodmodifiers std::list::setItem "private" +%csmethodmodifiers std::list::push_front "private" +%csmethodmodifiers std::list::push_back "private" +%csmethodmodifiers std::list::getFirstIter "private" +%csmethodmodifiers std::list::getNextIter "private" +%csmethodmodifiers std::list::getPrevIter "private" +%csmethodmodifiers std::list::getLastIter "private" +%csmethodmodifiers std::list::find "private" +%csmethodmodifiers std::list::deleteIter "private" + +namespace std { + // primary (unspecialized) class template for std::list + // does not require operator== to be defined + template<class T> + class list { + SWIG_STD_LIST_MINIMUM_INTERNAL(IEnumerable, T) + }; + // specialization for pointers + template<class T> + class list<T *> { + SWIG_STD_LIST_MINIMUM_INTERNAL(ICollection, T *) + SWIG_STD_LIST_EXTRA_OP_EQUALS_EQUALS(T *) + }; +} + +// template specializations for std::list +// these provide extra collections methods as operator== is defined +SWIG_STD_LIST_ENHANCED(char) +SWIG_STD_LIST_ENHANCED(signed char) +SWIG_STD_LIST_ENHANCED(unsigned char) +SWIG_STD_LIST_ENHANCED(short) +SWIG_STD_LIST_ENHANCED(unsigned short) +SWIG_STD_LIST_ENHANCED(int) +SWIG_STD_LIST_ENHANCED(unsigned int) +SWIG_STD_LIST_ENHANCED(long) +SWIG_STD_LIST_ENHANCED(unsigned long) +SWIG_STD_LIST_ENHANCED(long long) +SWIG_STD_LIST_ENHANCED(unsigned long long) +SWIG_STD_LIST_ENHANCED(float) +SWIG_STD_LIST_ENHANCED(double) +SWIG_STD_LIST_ENHANCED(std::string) // also requires a %include <std_string.i> +SWIG_STD_LIST_ENHANCED(std::wstring) // also requires a %include <std_wstring.i> diff --git a/Lib/csharp/std_set.i b/Lib/csharp/std_set.i new file mode 100644 index 000000000..3b2492e0e --- /dev/null +++ b/Lib/csharp/std_set.i @@ -0,0 +1,311 @@ +/* ----------------------------------------------------------------------------- + * std_set.i + * + * SWIG typemaps for std::set<T>. + * + * Note that ISet<> used here requires .NET 4 or later. + * + * The C# wrapper implements ISet<> interface and shares performance + * characteristics of C# System.Collections.Generic.SortedSet<> class, but + * doesn't provide quite all of its methods. + * ----------------------------------------------------------------------------- */ + +%{ +#include <set> +#include <algorithm> +#include <stdexcept> +%} + +%csmethodmodifiers std::set::size "private" +%csmethodmodifiers std::set::getitem "private" +%csmethodmodifiers std::set::create_iterator_begin "private" +%csmethodmodifiers std::set::get_next "private" +%csmethodmodifiers std::set::destroy_iterator "private" + +namespace std { + +// TODO: Add support for comparator and allocator template parameters. +template <class T> +class set { + +%typemap(csinterfaces) std::set<T> "global::System.IDisposable, global::System.Collections.Generic.ISet<$typemap(cstype, T)>\n"; +%proxycode %{ + void global::System.Collections.Generic.ICollection<$typemap(cstype, T)>.Add(string item) { + ((global::System.Collections.Generic.ISet<$typemap(cstype, T)>)this).Add(item); + } + + public bool TryGetValue($typemap(cstype, T) equalValue, out $typemap(cstype, T) actualValue) { + try { + actualValue = getitem(equalValue); + return true; + } catch { + actualValue = default($typemap(cstype, T)); + return false; + } + } + + public int Count { + get { + return (int)size(); + } + } + + public bool IsReadOnly { + get { + return false; + } + } + + public void CopyTo($typemap(cstype, T)[] array) { + CopyTo(array, 0); + } + + public void CopyTo($typemap(cstype, T)[] array, int arrayIndex) { + if (array == null) + throw new global::System.ArgumentNullException("array"); + if (arrayIndex < 0) + throw new global::System.ArgumentOutOfRangeException("arrayIndex", "Value is less than zero"); + if (array.Rank > 1) + throw new global::System.ArgumentException("Multi dimensional array.", "array"); + if (arrayIndex+this.Count > array.Length) + throw new global::System.ArgumentException("Number of elements to copy is too large."); + + foreach ($typemap(cstype, T) item in this) { + array.SetValue(item, arrayIndex++); + } + } + + public void ExceptWith(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) { + foreach ($typemap(cstype, T) item in other) { + Remove(item); + } + } + + public void IntersectWith(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) { + $csclassname old = new $csclassname(this); + + Clear(); + foreach ($typemap(cstype, T) item in other) { + if (old.Contains(item)) + Add(item); + } + } + + private static int count_enum(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) { + int count = 0; + foreach ($typemap(cstype, T) item in other) { + count++; + } + + return count; + } + + public bool IsProperSubsetOf(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) { + return IsSubsetOf(other) && Count < count_enum(other); + } + + public bool IsProperSupersetOf(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) { + return IsSupersetOf(other) && Count > count_enum(other); + } + + public bool IsSubsetOf(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) { + int countContained = 0; + + foreach ($typemap(cstype, T) item in other) { + if (Contains(item)) + countContained++; + } + + return countContained == Count; + } + + public bool IsSupersetOf(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) { + foreach ($typemap(cstype, T) item in other) { + if (!Contains(item)) + return false; + } + + return true; + } + + public bool Overlaps(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) { + foreach ($typemap(cstype, T) item in other) { + if (Contains(item)) + return true; + } + + return false; + } + + public bool SetEquals(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) { + return IsSupersetOf(other) && Count == count_enum(other); + } + + public void SymmetricExceptWith(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) { + foreach ($typemap(cstype, T) item in other) { + if (!Remove(item)) + Add(item); + } + } + + public void UnionWith(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) { + foreach ($typemap(cstype, T) item in other) { + Add(item); + } + } + + private global::System.Collections.Generic.ICollection<$typemap(cstype, T)> Items { + get { + global::System.Collections.Generic.ICollection<$typemap(cstype, T)> items = new global::System.Collections.Generic.List<$typemap(cstype, T)>(); + int size = this.Count; + if (size > 0) { + global::System.IntPtr iter = create_iterator_begin(); + for (int i = 0; i < size; i++) { + items.Add(get_next(iter)); + } + destroy_iterator(iter); + } + return items; + } + } + + global::System.Collections.Generic.IEnumerator<$typemap(cstype, T)> global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)>.GetEnumerator() { + return new $csclassnameEnumerator(this); + } + + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { + return new $csclassnameEnumerator(this); + } + + public $csclassnameEnumerator GetEnumerator() { + return new $csclassnameEnumerator(this); + } + + // Type-safe enumerator + /// Note that the IEnumerator documentation requires an InvalidOperationException to be thrown + /// whenever the collection is modified. This has been done for changes in the size of the + /// collection but not when one of the elements of the collection is modified as it is a bit + /// tricky to detect unmanaged code that modifies the collection under our feet. + public sealed class $csclassnameEnumerator : global::System.Collections.IEnumerator, + global::System.Collections.Generic.IEnumerator<$typemap(cstype, T)> + { + private $csclassname collectionRef; + private global::System.Collections.Generic.IList<$typemap(cstype, T)> ItemsCollection; + private int currentIndex; + private $typemap(cstype, T) currentObject; + private int currentSize; + + public $csclassnameEnumerator($csclassname collection) { + collectionRef = collection; + ItemsCollection = new global::System.Collections.Generic.List<$typemap(cstype, T)>(collection.Items); + currentIndex = -1; + currentObject = null; + currentSize = collectionRef.Count; + } + + // Type-safe iterator Current + public $typemap(cstype, T) Current { + get { + if (currentIndex == -1) + throw new global::System.InvalidOperationException("Enumeration not started."); + if (currentIndex > currentSize - 1) + throw new global::System.InvalidOperationException("Enumeration finished."); + if (currentObject == null) + throw new global::System.InvalidOperationException("Collection modified."); + return currentObject; + } + } + + // Type-unsafe IEnumerator.Current + object global::System.Collections.IEnumerator.Current { + get { + return Current; + } + } + + public bool MoveNext() { + int size = collectionRef.Count; + bool moveOkay = (currentIndex+1 < size) && (size == currentSize); + if (moveOkay) { + currentIndex++; + currentObject = ItemsCollection[currentIndex]; + } else { + currentObject = null; + } + return moveOkay; + } + + public void Reset() { + currentIndex = -1; + currentObject = null; + if (collectionRef.Count != currentSize) { + throw new global::System.InvalidOperationException("Collection modified."); + } + } + + public void Dispose() { + currentIndex = -1; + currentObject = null; + } + } + +%} + + 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_type size() const; + bool empty() const; + %rename(Clear) clear; + void clear(); + %extend { + bool Add(const value_type& item) { + return $self->insert(item).second; + } + + bool Contains(const value_type& item) { + return $self->count(item) != 0; + } + + bool Remove(const value_type& item) { + return $self->erase(item) != 0; + } + + const value_type& getitem(const value_type& item) throw (std::out_of_range) { + std::set<T>::iterator iter = $self->find(item); + if (iter == $self->end()) + throw std::out_of_range("item not found"); + + return *iter; + } + + // create_iterator_begin(), get_next() and destroy_iterator work together to provide a collection of items to C# + %apply void *VOID_INT_PTR { std::set<T>::iterator *create_iterator_begin } + %apply void *VOID_INT_PTR { std::set<T>::iterator *swigiterator } + + std::set<T>::iterator *create_iterator_begin() { + return new std::set<T>::iterator($self->begin()); + } + + const key_type& get_next(std::set<T>::iterator *swigiterator) { + std::set<T>::iterator iter = *swigiterator; + (*swigiterator)++; + return *iter; + } + + void destroy_iterator(std::set<T>::iterator *swigiterator) { + delete swigiterator; + } + } +}; + +} diff --git a/Lib/csharp/std_vector.i b/Lib/csharp/std_vector.i index b1e8da963..e2811290c 100644 --- a/Lib/csharp/std_vector.i +++ b/Lib/csharp/std_vector.i @@ -13,18 +13,13 @@ * * SWIG_STD_VECTOR_ENHANCED(SomeNamespace::Klass) * %template(VectKlass) std::vector<SomeNamespace::Klass>; - * - * Warning: heavy macro usage in this file. Use swig -E to get a sane view on the real file contents! * ----------------------------------------------------------------------------- */ -// Warning: Use the typemaps here in the expectation that the macros they are in will change name. - - %include <std_common.i> // MACRO for use within the std::vector class body %define SWIG_STD_VECTOR_MINIMUM_INTERNAL(CSINTERFACE, CONST_REFERENCE, CTYPE...) -%typemap(csinterfaces) std::vector< CTYPE > "global::System.IDisposable, global::System.Collections.IEnumerable\n , global::System.Collections.Generic.CSINTERFACE<$typemap(cstype, CTYPE)>\n"; +%typemap(csinterfaces) std::vector< CTYPE > "global::System.IDisposable, global::System.Collections.IEnumerable, global::System.Collections.Generic.CSINTERFACE<$typemap(cstype, CTYPE)>\n"; %proxycode %{ public $csclassname(global::System.Collections.IEnumerable c) : this() { if (c == null) @@ -244,9 +239,9 @@ else throw std::out_of_range("index"); } - void setitem(int index, CTYPE const& value) throw (std::out_of_range) { + void setitem(int index, CTYPE const& val) throw (std::out_of_range) { if (index>=0 && index<(int)$self->size()) - (*$self)[index] = value; + (*$self)[index] = val; else throw std::out_of_range("index"); } @@ -356,7 +351,7 @@ %define SWIG_STD_VECTOR_ENHANCED(CTYPE...) namespace std { template<> class vector< CTYPE > { - SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, %arg(CTYPE const&), %arg(CTYPE)) + SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, const value_type&, %arg(CTYPE)) SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CTYPE) }; } @@ -389,11 +384,11 @@ namespace std { // primary (unspecialized) class template for std::vector // does not require operator== to be defined template<class T> class vector { - SWIG_STD_VECTOR_MINIMUM_INTERNAL(IEnumerable, T const&, T) + SWIG_STD_VECTOR_MINIMUM_INTERNAL(IEnumerable, const value_type&, T) }; // specialization for pointers template<class T> class vector<T *> { - SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, T *const&, T *) + SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, const value_type&, T *) SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(T *) }; // bool is specialized in the C++ standard - const_reference in particular diff --git a/Lib/d/dclassgen.swg b/Lib/d/dclassgen.swg index 68910b412..84fa03a0b 100644 --- a/Lib/d/dclassgen.swg +++ b/Lib/d/dclassgen.swg @@ -33,7 +33,7 @@ // We do not use »override« attribute for generated dispose() methods to stay // somewhat compatible to Phobos and older Tango versions where Object.dispose() // does not exist. -%typemap(ddispose, methodname="dispose", methodmodifiers="public") SWIGTYPE { +%typemap(ddispose, methodname="dispose", methodmodifiers="public", parameters="") SWIGTYPE { synchronized(this) { if (swigCPtr !is null) { if (swigCMemOwn) { @@ -45,7 +45,7 @@ } } -%typemap(ddispose_derived, methodname="dispose", methodmodifiers="public") SWIGTYPE { +%typemap(ddispose_derived, methodname="dispose", methodmodifiers="public", parameters="") SWIGTYPE { synchronized(this) { if (swigCPtr !is null) { if (swigCMemOwn) { diff --git a/Lib/d/std_vector.i b/Lib/d/std_vector.i index 9dcb184c6..fb8f7d2e0 100644 --- a/Lib/d/std_vector.i +++ b/Lib/d/std_vector.i @@ -135,7 +135,7 @@ public void capacity(size_t value) { return $self->capacity() - $self->size(); } - CONST_REFERENCE remove() throw (std::out_of_range) { + const_reference remove() throw (std::out_of_range) { if ($self->empty()) { throw std::out_of_range("Tried to remove last element from empty vector."); } @@ -145,7 +145,7 @@ public void capacity(size_t value) { return value; } - CONST_REFERENCE remove(size_type index) throw (std::out_of_range) { + const_reference remove(size_type index) throw (std::out_of_range) { if (index >= $self->size()) { throw std::out_of_range("Tried to remove element with invalid index."); } @@ -160,7 +160,7 @@ public void capacity(size_t value) { // Wrappers for setting/getting items with the possibly thrown exception // specified (important for SWIG wrapper generation). %extend { - CONST_REFERENCE getElement(size_type index) throw (std::out_of_range) { + const_reference getElement(size_type index) throw (std::out_of_range) { if ((index < 0) || ($self->size() <= index)) { throw std::out_of_range("Tried to get value of element with invalid index."); } @@ -172,11 +172,11 @@ public void capacity(size_t value) { // generation issue when using const pointers as vector elements (like // std::vector< const int* >). %extend { - void setElement(size_type index, CTYPE const& value) throw (std::out_of_range) { + void setElement(size_type index, CTYPE const& val) throw (std::out_of_range) { if ((index < 0) || ($self->size() <= index)) { throw std::out_of_range("Tried to set value of element with invalid index."); } - (*$self)[index] = value; + (*$self)[index] = val; } } @@ -478,7 +478,7 @@ int opApply(int delegate(ref size_t index, ref $typemap(dtype, CTYPE) value) dg) return pv; } - CONST_REFERENCE remove() throw (std::out_of_range) { + const_reference remove() throw (std::out_of_range) { if ($self->empty()) { throw std::out_of_range("Tried to remove last element from empty vector."); } @@ -488,7 +488,7 @@ int opApply(int delegate(ref size_t index, ref $typemap(dtype, CTYPE) value) dg) return value; } - CONST_REFERENCE remove(size_type index) throw (std::out_of_range) { + const_reference remove(size_type index) throw (std::out_of_range) { if (index >= $self->size()) { throw std::out_of_range("Tried to remove element with invalid index."); } @@ -520,7 +520,7 @@ int opApply(int delegate(ref size_t index, ref $typemap(dtype, CTYPE) value) dg) // Wrappers for setting/getting items with the possibly thrown exception // specified (important for SWIG wrapper generation). %extend { - CONST_REFERENCE getElement(size_type index) throw (std::out_of_range) { + const_reference getElement(size_type index) throw (std::out_of_range) { if ((index < 0) || ($self->size() <= index)) { throw std::out_of_range("Tried to get value of element with invalid index."); } @@ -531,11 +531,11 @@ int opApply(int delegate(ref size_t index, ref $typemap(dtype, CTYPE) value) dg) // generation issue when using const pointers as vector elements (like // std::vector< const int* >). %extend { - void setElement(size_type index, CTYPE const& value) throw (std::out_of_range) { + void setElement(size_type index, CTYPE const& val) throw (std::out_of_range) { if ((index < 0) || ($self->size() <= index)) { throw std::out_of_range("Tried to set value of element with invalid index."); } - (*$self)[index] = value; + (*$self)[index] = val; } } @@ -558,7 +558,7 @@ int opApply(int delegate(ref size_t index, ref $typemap(dtype, CTYPE) value) dg) %define SWIG_STD_VECTOR_ENHANCED(CTYPE...) namespace std { template<> class vector<CTYPE > { - SWIG_STD_VECTOR_MINIMUM_INTERNAL(%arg(CTYPE const&), %arg(CTYPE)) + SWIG_STD_VECTOR_MINIMUM_INTERNAL(const value_type&, %arg(CTYPE)) SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CTYPE) }; } @@ -573,11 +573,11 @@ namespace std { // primary (unspecialized) class template for std::vector // does not require operator== to be defined template<class T> class vector { - SWIG_STD_VECTOR_MINIMUM_INTERNAL(T const&, T) + SWIG_STD_VECTOR_MINIMUM_INTERNAL(const value_type&, T) }; // specializations for pointers template<class T> class vector<T *> { - SWIG_STD_VECTOR_MINIMUM_INTERNAL(T *const&, T *) + SWIG_STD_VECTOR_MINIMUM_INTERNAL(const value_type&, T *) SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(T *) }; // bool is a bit different in the C++ standard - const_reference in particular diff --git a/Lib/java/java.swg b/Lib/java/java.swg index 19e597bd9..e9309331a 100644 --- a/Lib/java/java.swg +++ b/Lib/java/java.swg @@ -160,7 +160,7 @@ SWIGINTERN jint SWIG_JavaIntFromSize_t(size_t size) { %typemap(jtype) jfloat "float" %typemap(jtype) jdouble "double" %typemap(jtype) jstring "String" -%typemap(jtype) jobject "Object" +%typemap(jtype) jobject "java.lang.Object" %typemap(jtype) jbooleanArray "boolean[]" %typemap(jtype) jcharArray "char[]" %typemap(jtype) jbyteArray "byte[]" @@ -169,7 +169,7 @@ SWIGINTERN jint SWIG_JavaIntFromSize_t(size_t size) { %typemap(jtype) jlongArray "long[]" %typemap(jtype) jfloatArray "float[]" %typemap(jtype) jdoubleArray "double[]" -%typemap(jtype) jobjectArray "Object[]" +%typemap(jtype) jobjectArray "java.lang.Object[]" %typemap(jstype) jboolean "boolean" %typemap(jstype) jchar "char" @@ -180,7 +180,7 @@ SWIGINTERN jint SWIG_JavaIntFromSize_t(size_t size) { %typemap(jstype) jfloat "float" %typemap(jstype) jdouble "double" %typemap(jstype) jstring "String" -%typemap(jstype) jobject "Object" +%typemap(jstype) jobject "java.lang.Object" %typemap(jstype) jbooleanArray "boolean[]" %typemap(jstype) jcharArray "char[]" %typemap(jstype) jbyteArray "byte[]" @@ -189,7 +189,7 @@ SWIGINTERN jint SWIG_JavaIntFromSize_t(size_t size) { %typemap(jstype) jlongArray "long[]" %typemap(jstype) jfloatArray "float[]" %typemap(jstype) jdoubleArray "double[]" -%typemap(jstype) jobjectArray "Object[]" +%typemap(jstype) jobjectArray "java.lang.Object[]" /* Non primitive types */ %typemap(jni) SWIGTYPE "jlong" @@ -1273,6 +1273,7 @@ SWIG_JAVABODY_PROXY(protected, protected, SWIGTYPE) SWIG_JAVABODY_TYPEWRAPPER(protected, protected, protected, SWIGTYPE) %typemap(javafinalize) SWIGTYPE %{ + @SuppressWarnings("deprecation") protected void finalize() { delete(); } @@ -1312,7 +1313,7 @@ SWIG_PROXY_CONSTRUCTOR(true, false, TYPENAME) // Set the default for SWIGTYPE: Java owns the C/C++ object. SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE) -%typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized") SWIGTYPE { +%typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized", parameters="") SWIGTYPE { if (swigCPtr != 0) { if (swigCMemOwn) { swigCMemOwn = false; @@ -1322,7 +1323,7 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE) } } -%typemap(javadestruct_derived, methodname="delete", methodmodifiers="public synchronized") SWIGTYPE { +%typemap(javadestruct_derived, methodname="delete", methodmodifiers="public synchronized", parameters="") SWIGTYPE { if (swigCPtr != 0) { if (swigCMemOwn) { swigCMemOwn = false; @@ -1382,12 +1383,12 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE) %apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) } /* String & length */ -%typemap(jni) (char *STRING, size_t LENGTH) "jbyteArray" -%typemap(jtype) (char *STRING, size_t LENGTH) "byte[]" -%typemap(jstype) (char *STRING, size_t LENGTH) "byte[]" -%typemap(javain) (char *STRING, size_t LENGTH) "$javainput" -%typemap(freearg) (char *STRING, size_t LENGTH) "" -%typemap(in) (char *STRING, size_t LENGTH) { +%typemap(jni) (const char *STRING, size_t LENGTH) "jbyteArray" +%typemap(jtype) (const char *STRING, size_t LENGTH) "byte[]" +%typemap(jstype) (const char *STRING, size_t LENGTH) "byte[]" +%typemap(javain) (const char *STRING, size_t LENGTH) "$javainput" +%typemap(freearg) (const char *STRING, size_t LENGTH) "" +%typemap(in) (const char *STRING, size_t LENGTH) { if ($input) { $1 = ($1_ltype) JCALL2(GetByteArrayElements, jenv, $input, 0); $2 = ($2_type) JCALL1(GetArrayLength, jenv, $input); @@ -1396,10 +1397,10 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE) $2 = 0; } } -%typemap(argout) (char *STRING, size_t LENGTH) { - if ($input) JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, 0); +%typemap(argout) (const char *STRING, size_t LENGTH) { + if ($input) JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, JNI_ABORT); } -%typemap(directorin, descriptor="[B", noblock=1) (char *STRING, size_t LENGTH) { +%typemap(directorin, descriptor="[B", noblock=1) (const char *STRING, size_t LENGTH) { $input = 0; if ($1) { $input = JCALL1(NewByteArray, jenv, (jsize)$2); @@ -1408,9 +1409,14 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE) } Swig::LocalRefGuard $1_refguard(jenv, $input); } +%typemap(javadirectorin, descriptor="[B") (const char *STRING, size_t LENGTH) "$jniinput" +%apply (const char *STRING, size_t LENGTH) { (char *STRING, size_t LENGTH) } +/* Enable write-back for non-const version */ +%typemap(argout) (char *STRING, size_t LENGTH) { + if ($input) JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, 0); +} %typemap(directorargout, noblock=1) (char *STRING, size_t LENGTH) { if ($input && $1) JCALL4(GetByteArrayRegion, jenv, $input, 0, (jsize)$2, (jbyte *)$1); } -%typemap(javadirectorin, descriptor="[B") (char *STRING, size_t LENGTH) "$jniinput" %apply (char *STRING, size_t LENGTH) { (char *STRING, int LENGTH) } /* java keywords */ diff --git a/Lib/java/std_array.i b/Lib/java/std_array.i index f67b18d9b..d3436cc66 100644 --- a/Lib/java/std_array.i +++ b/Lib/java/std_array.i @@ -31,10 +31,10 @@ namespace std { else throw std::out_of_range("array index out of range"); } - void set(int i, const value_type& value) throw (std::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] = value; + (*self)[i] = val; else throw std::out_of_range("array index out of range"); } diff --git a/Lib/java/std_list.i b/Lib/java/std_list.i index 3ad6511ce..1077bd0a0 100644 --- a/Lib/java/std_list.i +++ b/Lib/java/std_list.i @@ -43,7 +43,7 @@ namespace std { this(); java.util.ListIterator<$typemap(jboxtype, T)> it = listIterator(0); // Special case the "copy constructor" here to avoid lots of cross-language calls - for (Object o : c) { + for (java.lang.Object o : c) { it.add(($typemap(jboxtype, T))o); } } @@ -198,11 +198,6 @@ namespace std { %extend { %fragment("SWIG_ListSize"); - list(jint count) throw (std::out_of_range) { - if (count < 0) - throw std::out_of_range("list count must be positive"); - return new std::list<T>(static_cast<std::list<T>::size_type>(count)); - } list(jint count, const T &value) throw (std::out_of_range) { if (count < 0) diff --git a/Lib/java/std_map.i b/Lib/java/std_map.i index 4b891e74a..6d5ca1aac 100644 --- a/Lib/java/std_map.i +++ b/Lib/java/std_map.i @@ -57,7 +57,7 @@ template<class K, class T, class C = std::less< K> > class map { return sizeImpl(); } - public boolean containsKey(Object key) { + public boolean containsKey(java.lang.Object key) { if (!(key instanceof $typemap(jboxtype, K))) { return false; } @@ -65,7 +65,7 @@ template<class K, class T, class C = std::less< K> > class map { return containsImpl(($typemap(jboxtype, K))key); } - public $typemap(jboxtype, T) get(Object key) { + public $typemap(jboxtype, T) get(java.lang.Object key) { if (!(key instanceof $typemap(jboxtype, K))) { return null; } @@ -90,7 +90,7 @@ template<class K, class T, class C = std::less< K> > class map { } } - public $typemap(jboxtype, T) remove(Object key) { + public $typemap(jboxtype, T) remove(java.lang.Object key) { if (!(key instanceof $typemap(jboxtype, K))) { return null; } diff --git a/Lib/java/std_set.i b/Lib/java/std_set.i index 06c5a63e7..04658f765 100644 --- a/Lib/java/std_set.i +++ b/Lib/java/std_set.i @@ -59,7 +59,7 @@ class set { public boolean addAll(java.util.Collection<? extends $typemap(jboxtype, T)> collection) { boolean didAddElement = false; - for (Object object : collection) { + for (java.lang.Object object : collection) { didAddElement |= add(($typemap(jboxtype, T))object); } @@ -96,7 +96,7 @@ class set { } public boolean containsAll(java.util.Collection<?> collection) { - for (Object object : collection) { + for (java.lang.Object object : collection) { if (!contains(object)) { return false; } @@ -105,7 +105,7 @@ class set { return true; } - public boolean contains(Object object) { + public boolean contains(java.lang.Object object) { if (!(object instanceof $typemap(jboxtype, T))) { return false; } @@ -115,14 +115,14 @@ class set { public boolean removeAll(java.util.Collection<?> collection) { boolean didRemoveElement = false; - for (Object object : collection) { + for (java.lang.Object object : collection) { didRemoveElement |= remove(object); } return didRemoveElement; } - public boolean remove(Object object) { + public boolean remove(java.lang.Object object) { if (!(object instanceof $typemap(jboxtype, T))) { return false; } @@ -152,8 +152,8 @@ class set { typedef size_t size_type; typedef ptrdiff_t difference_type; - typedef T value_type; typedef T key_type; + typedef T value_type; typedef value_type* pointer; typedef const value_type* const_pointer; typedef value_type& reference; diff --git a/Lib/java/std_unordered_map.i b/Lib/java/std_unordered_map.i index 8f62d7290..283a9b464 100644 --- a/Lib/java/std_unordered_map.i +++ b/Lib/java/std_unordered_map.i @@ -57,7 +57,7 @@ template<class K, class T> class unordered_map { return sizeImpl(); } - public boolean containsKey(Object key) { + public boolean containsKey(java.lang.Object key) { if (!(key instanceof $typemap(jboxtype, K))) { return false; } @@ -65,7 +65,7 @@ template<class K, class T> class unordered_map { return containsImpl(($typemap(jboxtype, K))key); } - public $typemap(jboxtype, T) get(Object key) { + public $typemap(jboxtype, T) get(java.lang.Object key) { if (!(key instanceof $typemap(jboxtype, K))) { return null; } @@ -90,7 +90,7 @@ template<class K, class T> class unordered_map { } } - public $typemap(jboxtype, T) remove(Object key) { + public $typemap(jboxtype, T) remove(java.lang.Object key) { if (!(key instanceof $typemap(jboxtype, K))) { return null; } diff --git a/Lib/java/std_unordered_set.i b/Lib/java/std_unordered_set.i index cdc116e49..59726e94d 100644 --- a/Lib/java/std_unordered_set.i +++ b/Lib/java/std_unordered_set.i @@ -43,12 +43,12 @@ namespace std { -template <class T> +template <class Key> class unordered_set { -%typemap(javabase) std::unordered_set<T> "java.util.AbstractSet<$typemap(jboxtype, T)>" +%typemap(javabase) std::unordered_set<Key> "java.util.AbstractSet<$typemap(jboxtype, Key)>" %proxycode %{ - public $javaclassname(java.util.Collection<? extends $typemap(jboxtype, T)> collection) { + public $javaclassname(java.util.Collection<? extends $typemap(jboxtype, Key)> collection) { this(); addAll(collection); } @@ -57,34 +57,34 @@ class unordered_set { return sizeImpl(); } - public boolean addAll(java.util.Collection<? extends $typemap(jboxtype, T)> collection) { + public boolean addAll(java.util.Collection<? extends $typemap(jboxtype, Key)> collection) { boolean didAddElement = false; - for (Object object : collection) { - didAddElement |= add(($typemap(jboxtype, T))object); + for (java.lang.Object object : collection) { + didAddElement |= add(($typemap(jboxtype, Key))object); } return didAddElement; } - public java.util.Iterator<$typemap(jboxtype, T)> iterator() { - return new java.util.Iterator<$typemap(jboxtype, T)>() { + public java.util.Iterator<$typemap(jboxtype, Key)> iterator() { + return new java.util.Iterator<$typemap(jboxtype, Key)>() { private Iterator curr; private Iterator end; - private java.util.Iterator<$typemap(jboxtype, T)> init() { + private java.util.Iterator<$typemap(jboxtype, Key)> init() { curr = $javaclassname.this.begin(); end = $javaclassname.this.end(); return this; } - public $typemap(jboxtype, T) next() { + public $typemap(jboxtype, Key) next() { if (!hasNext()) { throw new java.util.NoSuchElementException(); } // Save the current position, increment it, // then return the value at the position before the increment. - final $typemap(jboxtype, T) currValue = curr.derefUnchecked(); + final $typemap(jboxtype, Key) currValue = curr.derefUnchecked(); curr.incrementUnchecked(); return currValue; } @@ -96,7 +96,7 @@ class unordered_set { } public boolean containsAll(java.util.Collection<?> collection) { - for (Object object : collection) { + for (java.lang.Object object : collection) { if (!contains(object)) { return false; } @@ -105,29 +105,29 @@ class unordered_set { return true; } - public boolean contains(Object object) { - if (!(object instanceof $typemap(jboxtype, T))) { + public boolean contains(java.lang.Object object) { + if (!(object instanceof $typemap(jboxtype, Key))) { return false; } - return containsImpl(($typemap(jboxtype, T))object); + return containsImpl(($typemap(jboxtype, Key))object); } public boolean removeAll(java.util.Collection<?> collection) { boolean didRemoveElement = false; - for (Object object : collection) { + for (java.lang.Object object : collection) { didRemoveElement |= remove(object); } return didRemoveElement; } - public boolean remove(Object object) { - if (!(object instanceof $typemap(jboxtype, T))) { + public boolean remove(java.lang.Object object) { + if (!(object instanceof $typemap(jboxtype, Key))) { return false; } - return removeImpl(($typemap(jboxtype, T))object); + return removeImpl(($typemap(jboxtype, Key))object); } %} @@ -140,7 +140,7 @@ class unordered_set { ++(*$self); } - T derefUnchecked() const { + Key derefUnchecked() const { return **$self; } @@ -152,8 +152,8 @@ class unordered_set { typedef size_t size_type; typedef ptrdiff_t difference_type; - typedef T value_type; - typedef T key_type; + typedef Key value_type; + typedef Key key_type; typedef value_type* pointer; typedef const value_type* const_pointer; typedef value_type& reference; @@ -172,17 +172,17 @@ class unordered_set { %fragment("SWIG_UnorderedSetSize"); // Returns whether item was inserted. - bool add(const T& key) { + bool add(const Key& key) { return self->insert(key).second; } // Returns whether set contains key. - bool containsImpl(const T& key) { + bool containsImpl(const Key& key) { return (self->count(key) > 0); } // Returns whether the item was erased. - bool removeImpl(const T& key) { + bool removeImpl(const Key& key) { return (self->erase(key) > 0); } diff --git a/Lib/java/std_vector.i b/Lib/java/std_vector.i index f621e8992..955e20cac 100644 --- a/Lib/java/std_vector.i +++ b/Lib/java/std_vector.i @@ -94,11 +94,6 @@ SWIGINTERN jint SWIG_VectorSize(size_t size) { void clear(); %extend { %fragment("SWIG_VectorSize"); - vector(jint count) throw (std::out_of_range) { - if (count < 0) - throw std::out_of_range("vector count must be positive"); - return new std::vector< CTYPE >(static_cast<std::vector< CTYPE >::size_type>(count)); - } vector(jint count, const CTYPE &value) throw (std::out_of_range) { if (count < 0) @@ -110,14 +105,14 @@ SWIGINTERN jint SWIG_VectorSize(size_t size) { return SWIG_VectorSize(self->size()); } - void doAdd(const value_type& value) { - self->push_back(value); + void doAdd(const value_type& x) { + self->push_back(x); } - void doAdd(jint index, const value_type& value) throw (std::out_of_range) { + void doAdd(jint index, const value_type& x) throw (std::out_of_range) { jint size = static_cast<jint>(self->size()); if (0 <= index && index <= size) { - self->insert(self->begin() + index, value); + self->insert(self->begin() + index, x); } else { throw std::out_of_range("vector index out of range"); } @@ -142,11 +137,11 @@ SWIGINTERN jint SWIG_VectorSize(size_t size) { throw std::out_of_range("vector index out of range"); } - value_type doSet(jint index, const value_type& value) throw (std::out_of_range) { + value_type doSet(jint index, const value_type& val) throw (std::out_of_range) { jint size = static_cast<jint>(self->size()); if (index >= 0 && index < size) { CTYPE const old_value = (*self)[index]; - (*self)[index] = value; + (*self)[index] = val; return old_value; } else @@ -174,7 +169,7 @@ SWIGINTERN jint SWIG_VectorSize(size_t size) { namespace std { template<class T> class vector { - SWIG_STD_VECTOR_MINIMUM_INTERNAL(T, const T&) + SWIG_STD_VECTOR_MINIMUM_INTERNAL(T, const value_type&) }; // bool specialization diff --git a/Lib/javascript/v8/javascripthelpers.swg b/Lib/javascript/v8/javascripthelpers.swg index 7b8a5ec23..80fbd7aa1 100644 --- a/Lib/javascript/v8/javascripthelpers.swg +++ b/Lib/javascript/v8/javascripthelpers.swg @@ -93,7 +93,7 @@ SWIGRUNTIME void JS_veto_set_variable(v8::Local<v8::Name> property, v8::Local<v8 #else v8::Local<v8::String> sproperty; if (property->ToString(SWIGV8_CURRENT_CONTEXT()).ToLocal(&sproperty)) { - sproperty->WriteUtf8(buffer, 256); + SWIGV8_WRITE_UTF8(sproperty, buffer, 256); res = sprintf(msg, "Tried to write read-only variable: %s.", buffer); } else { diff --git a/Lib/javascript/v8/javascriptprimtypes.swg b/Lib/javascript/v8/javascriptprimtypes.swg index c0055c48e..f76be983b 100644 --- a/Lib/javascript/v8/javascriptprimtypes.swg +++ b/Lib/javascript/v8/javascriptprimtypes.swg @@ -22,7 +22,7 @@ int SWIG_AsVal_dec(bool)(v8::Handle<v8::Value> obj, bool *val) return SWIG_ERROR; } - if (val) *val = obj->BooleanValue(); + if (val) *val = SWIGV8_BOOLEAN_VALUE(obj); return SWIG_OK; } } @@ -44,7 +44,7 @@ int SWIG_AsVal_dec(int)(v8::Handle<v8::Value> valRef, int* val) if (!valRef->IsNumber()) { return SWIG_TypeError; } - if(val) *val = valRef->IntegerValue(); + if(val) *val = SWIGV8_INTEGER_VALUE(valRef); return SWIG_OK; } @@ -68,7 +68,7 @@ int SWIG_AsVal_dec(long)(v8::Handle<v8::Value> obj, long* val) if (!obj->IsNumber()) { return SWIG_TypeError; } - if(val) *val = (long) obj->IntegerValue(); + if(val) *val = (long) SWIGV8_INTEGER_VALUE(obj); return SWIG_OK; } @@ -95,7 +95,7 @@ int SWIG_AsVal_dec(unsigned long)(v8::Handle<v8::Value> obj, unsigned long *val) return SWIG_TypeError; } - long longVal = (long) obj->NumberValue(); + long longVal = (long) SWIGV8_NUMBER_VALUE(obj); if(longVal < 0) { return SWIG_OverflowError; @@ -133,7 +133,7 @@ int SWIG_AsVal_dec(long long)(v8::Handle<v8::Value> obj, long long* val) if (!obj->IsNumber()) { return SWIG_TypeError; } - if(val) *val = (long long) obj->IntegerValue(); + if(val) *val = (long long) SWIGV8_INTEGER_VALUE(obj); return SWIG_OK; } @@ -168,7 +168,7 @@ int SWIG_AsVal_dec(unsigned long long)(v8::Handle<v8::Value> obj, unsigned long return SWIG_TypeError; } - long long longVal = (long long) obj->NumberValue(); + long long longVal = (long long) SWIGV8_NUMBER_VALUE(obj); if(longVal < 0) { return SWIG_OverflowError; @@ -198,7 +198,7 @@ int SWIG_AsVal_dec(double)(v8::Handle<v8::Value> obj, double *val) if(!obj->IsNumber()) { return SWIG_TypeError; } - if(val) *val = obj->NumberValue(); + if(val) *val = SWIGV8_NUMBER_VALUE(obj); return SWIG_OK; } diff --git a/Lib/javascript/v8/javascriptrun.swg b/Lib/javascript/v8/javascriptrun.swg index 84bd4cc67..2452f4040 100644 --- a/Lib/javascript/v8/javascriptrun.swg +++ b/Lib/javascript/v8/javascriptrun.swg @@ -91,6 +91,32 @@ typedef v8::PropertyCallbackInfo<v8::Value> SwigV8PropertyCallbackInfo; #define SWIGV8_SET_CLASS_TEMPL(class_templ, class) class_templ.Reset(v8::Isolate::GetCurrent(), class); #endif +#ifdef NODE_VERSION +#if NODE_VERSION_AT_LEAST(10, 12, 0) +#define SWIG_NODE_AT_LEAST_1012 +#endif +#endif + +//Necessary to check Node.js version because V8 API changes are backported in Node.js +#if (defined(NODE_VERSION) && !defined(SWIG_NODE_AT_LEAST_1012)) || \ + (!defined(NODE_VERSION) && (V8_MAJOR_VERSION-0) < 7) +#define SWIGV8_TO_OBJECT(handle) (handle)->ToObject() +#define SWIGV8_TO_STRING(handle) (handle)->ToString() +#define SWIGV8_NUMBER_VALUE(handle) (handle)->NumberValue() +#define SWIGV8_INTEGER_VALUE(handle) (handle)->IntegerValue() +#define SWIGV8_BOOLEAN_VALUE(handle) (handle)->BooleanValue() +#define SWIGV8_WRITE_UTF8(handle, buffer, len) (handle)->WriteUtf8(buffer, len) +#define SWIGV8_UTF8_LENGTH(handle) (handle)->Utf8Length() +#else +#define SWIGV8_TO_OBJECT(handle) (handle)->ToObject(SWIGV8_CURRENT_CONTEXT()).ToLocalChecked() +#define SWIGV8_TO_STRING(handle) (handle)->ToString(SWIGV8_CURRENT_CONTEXT()).ToLocalChecked() +#define SWIGV8_NUMBER_VALUE(handle) (handle)->NumberValue(SWIGV8_CURRENT_CONTEXT()).ToChecked() +#define SWIGV8_INTEGER_VALUE(handle) (handle)->IntegerValue(SWIGV8_CURRENT_CONTEXT()).ToChecked() +#define SWIGV8_BOOLEAN_VALUE(handle) (handle)->BooleanValue(SWIGV8_CURRENT_CONTEXT()).ToChecked() +#define SWIGV8_WRITE_UTF8(handle, buffer, len) (handle)->WriteUtf8(v8::Isolate::GetCurrent(), buffer, len) +#define SWIGV8_UTF8_LENGTH(handle) (handle)->Utf8Length(v8::Isolate::GetCurrent()) +#endif + /* --------------------------------------------------------------------------- * Error handling * @@ -258,7 +284,7 @@ SWIGRUNTIME int SWIG_V8_GetInstancePtr(v8::Handle<v8::Value> valRef, void **ptr) if(!valRef->IsObject()) { return SWIG_TypeError; } - v8::Handle<v8::Object> objRef = valRef->ToObject(); + v8::Handle<v8::Object> objRef = SWIGV8_TO_OBJECT(valRef); if(objRef->InternalFieldCount() < 1) return SWIG_ERROR; @@ -352,7 +378,7 @@ SWIGRUNTIME int SWIG_V8_ConvertPtr(v8::Handle<v8::Value> valRef, void **ptr, swi if(!valRef->IsObject()) { return SWIG_TypeError; } - v8::Handle<v8::Object> objRef = valRef->ToObject(); + v8::Handle<v8::Object> objRef = SWIGV8_TO_OBJECT(valRef); return SWIG_V8_ConvertInstancePtr(objRef, ptr, info, flags); } @@ -479,7 +505,7 @@ SWIGRUNTIMEINLINE int SwigV8Packed_Check(v8::Handle<v8::Value> valRef) { SWIGV8_HANDLESCOPE(); - v8::Handle<v8::Object> objRef = valRef->ToObject(); + v8::Handle<v8::Object> objRef = SWIGV8_TO_OBJECT(valRef); if(objRef->InternalFieldCount() < 1) return false; #if (V8_MAJOR_VERSION-0) < 5 v8::Handle<v8::Value> flag = objRef->GetHiddenValue(SWIGV8_STRING_NEW("__swig__packed_data__")); @@ -489,7 +515,7 @@ int SwigV8Packed_Check(v8::Handle<v8::Value> valRef) { if (!objRef->GetPrivate(SWIGV8_CURRENT_CONTEXT(), privateKey).ToLocal(&flag)) return false; #endif - return (flag->IsBoolean() && flag->BooleanValue()); + return (flag->IsBoolean() && SWIGV8_BOOLEAN_VALUE(flag)); } SWIGRUNTIME @@ -499,7 +525,7 @@ swig_type_info *SwigV8Packed_UnpackData(v8::Handle<v8::Value> valRef, void *ptr, SwigV8PackedData *sobj; - v8::Handle<v8::Object> objRef = valRef->ToObject(); + v8::Handle<v8::Object> objRef = SWIGV8_TO_OBJECT(valRef); #if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031511) v8::Handle<v8::Value> cdataRef = objRef->GetInternalField(0); diff --git a/Lib/javascript/v8/javascriptruntime.swg b/Lib/javascript/v8/javascriptruntime.swg index 0e4059326..c78e04efb 100644 --- a/Lib/javascript/v8/javascriptruntime.swg +++ b/Lib/javascript/v8/javascriptruntime.swg @@ -44,6 +44,8 @@ #ifdef BUILDING_NODE_EXTENSION %insert("runtime") %{ #include <node.h> +//Older version of node.h does not include this +#include <node_version.h> %} #endif diff --git a/Lib/javascript/v8/javascriptstrings.swg b/Lib/javascript/v8/javascriptstrings.swg index 65ba20e5a..e767a6d66 100644 --- a/Lib/javascript/v8/javascriptstrings.swg +++ b/Lib/javascript/v8/javascriptstrings.swg @@ -7,11 +7,11 @@ SWIGINTERN int SWIG_AsCharPtrAndSize(v8::Handle<v8::Value> valRef, char** cptr, size_t* psize, int *alloc) { if(valRef->IsString()) { - v8::Handle<v8::String> js_str = valRef->ToString(); + v8::Handle<v8::String> js_str = SWIGV8_TO_STRING(valRef); - size_t len = js_str->Utf8Length() + 1; + size_t len = SWIGV8_UTF8_LENGTH(js_str) + 1; char* cstr = new char[len]; - js_str->WriteUtf8(cstr, len); + SWIGV8_WRITE_UTF8(js_str, cstr, len); if(alloc) *alloc = SWIG_NEWOBJ; if(psize) *psize = len; @@ -20,7 +20,7 @@ SWIG_AsCharPtrAndSize(v8::Handle<v8::Value> valRef, char** cptr, size_t* psize, return SWIG_OK; } else { if(valRef->IsObject()) { - v8::Handle<v8::Object> obj = valRef->ToObject(); + v8::Handle<v8::Object> obj = SWIGV8_TO_OBJECT(valRef); // try if the object is a wrapped char[] swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); if (pchar_descriptor) { diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index 301233103..ff614e681 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -51,7 +51,7 @@ SWIGRUNTIME octave_value SWIG_Error(int code, const char *msg) { octave_value type(SWIG_ErrorType(code)); std::string r = msg; r += " (" + type.string_value() + ")"; - error(r.c_str()); + error("%s", r.c_str()); return octave_value(r); } @@ -840,7 +840,7 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); const std::string opname = std::string("__") + octave_base_value::get_umap_name(umap) + std::string("__"); octave_value ret; if (!dispatch_unary_op(opname, ret)) { - error((opname + std::string(" method not found")).c_str()); + error("%s", (opname + std::string(" method not found")).c_str()); return octave_value(); } return ret; diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg index 5c2a981ee..ef2f725af 100644 --- a/Lib/python/pycontainer.swg +++ b/Lib/python/pycontainer.swg @@ -43,7 +43,7 @@ %fragment("reference_container_owner", "header", fragment="container_owner_attribute_init") { namespace swig { - PyObject* container_owner_attribute() { + static PyObject* container_owner_attribute() { static PyObject* attr = SWIG_Python_str_FromChar("__swig_container"); return attr; } diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index f5be6d599..dfbf40b34 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -8,6 +8,22 @@ %fragment("<stddef.h>"); // For offsetof #endif +%insert(runtime) %{ +#ifdef __cplusplus +extern "C" { +#endif + +/* Method creation and docstring support functions */ + +SWIGINTERN PyMethodDef *SWIG_PythonGetProxyDoc(const char *name); +SWIGINTERN PyObject *SWIG_PyInstanceMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func); +SWIGINTERN PyObject *SWIG_PyStaticMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func); + +#ifdef __cplusplus +} +#endif +%} + %init %{ #ifdef __cplusplus diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 693cd6d46..ad1b81963 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -213,12 +213,6 @@ SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssi extern "C" { #endif -/* Method creation and docstring support functions */ - -SWIGINTERN PyMethodDef *SWIG_PythonGetProxyDoc(const char *name); -SWIGINTERN PyObject *SWIG_PyInstanceMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func); -SWIGINTERN PyObject *SWIG_PyStaticMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func); - /* The python void return value */ SWIGRUNTIMEINLINE PyObject * diff --git a/Lib/python/std_unordered_map.i b/Lib/python/std_unordered_map.i index 79882b292..042d5b671 100644 --- a/Lib/python/std_unordered_map.i +++ b/Lib/python/std_unordered_map.i @@ -56,26 +56,26 @@ %fragment("StdUnorderedMapTraits","header",fragment="StdMapCommonTraits",fragment="StdUnorderedMapForwardIteratorTraits") { namespace swig { - template <class SwigPySeq, class K, class T > + template <class SwigPySeq, class K, class T, class Hash, class Compare, class Alloc> inline void - assign(const SwigPySeq& swigpyseq, std::unordered_map<K,T > *unordered_map) { - typedef typename std::unordered_map<K,T>::value_type value_type; + assign(const SwigPySeq& swigpyseq, std::unordered_map<K,T,Hash,Compare,Alloc> *unordered_map) { + typedef typename std::unordered_map<K,T,Hash,Compare,Alloc>::value_type value_type; typename SwigPySeq::const_iterator it = swigpyseq.begin(); for (;it != swigpyseq.end(); ++it) { unordered_map->insert(value_type(it->first, it->second)); } } - template <class K, class T> - struct traits_reserve<std::unordered_map<K,T> > { - static void reserve(std::unordered_map<K,T> &seq, typename std::unordered_map<K,T>::size_type n) { + template <class K, class T, class Hash, class Compare, class Alloc> + struct traits_reserve<std::unordered_map<K,T,Hash,Compare,Alloc> > { + static void reserve(std::unordered_map<K,T,Hash,Compare,Alloc> &seq, typename std::unordered_map<K,T,Hash,Compare,Alloc>::size_type n) { seq.reserve(n); } }; - template <class K, class T> - struct traits_asptr<std::unordered_map<K,T> > { - typedef std::unordered_map<K,T> unordered_map_type; + template <class K, class T, class Hash, class Compare, class Alloc> + struct traits_asptr<std::unordered_map<K,T,Hash,Compare,Alloc> > { + typedef std::unordered_map<K,T,Hash,Compare,Alloc> unordered_map_type; static int asptr(PyObject *obj, unordered_map_type **val) { int res = SWIG_ERROR; SWIG_PYTHON_THREAD_BEGIN_BLOCK; @@ -85,7 +85,7 @@ /* In Python 3.x the ".items()" method returns a dict_items object */ items = PySequence_Fast(items, ".items() didn't return a sequence!"); %#endif - res = traits_asptr_stdseq<std::unordered_map<K,T>, std::pair<K, T> >::asptr(items, val); + res = traits_asptr_stdseq<std::unordered_map<K,T,Hash,Compare,Alloc>, std::pair<K, T> >::asptr(items, val); } else { unordered_map_type *p; swig_type_info *descriptor = swig::type_info<unordered_map_type>(); @@ -97,9 +97,9 @@ } }; - template <class K, class T > - struct traits_from<std::unordered_map<K,T> > { - typedef std::unordered_map<K,T> unordered_map_type; + template <class K, class T, class Hash, class Compare, class Alloc> + struct traits_from<std::unordered_map<K,T,Hash,Compare,Alloc> > { + typedef std::unordered_map<K,T,Hash,Compare,Alloc> unordered_map_type; typedef typename unordered_map_type::const_iterator const_iterator; typedef typename unordered_map_type::size_type size_type; diff --git a/Lib/python/std_unordered_multimap.i b/Lib/python/std_unordered_multimap.i index aa29a7cff..281140445 100644 --- a/Lib/python/std_unordered_multimap.i +++ b/Lib/python/std_unordered_multimap.i @@ -6,27 +6,27 @@ %fragment("StdUnorderedMultimapTraits","header",fragment="StdMapCommonTraits",fragment="StdUnorderedMapForwardIteratorTraits") { namespace swig { - template <class SwigPySeq, class K, class T > + template <class SwigPySeq, class K, class T, class Hash, class Compare, class Alloc> inline void - assign(const SwigPySeq& swigpyseq, std::unordered_multimap<K,T > *unordered_multimap) { - typedef typename std::unordered_multimap<K,T>::value_type value_type; + assign(const SwigPySeq& swigpyseq, std::unordered_multimap<K,T,Hash,Compare,Alloc> *unordered_multimap) { + typedef typename std::unordered_multimap<K,T,Hash,Compare,Alloc>::value_type value_type; typename SwigPySeq::const_iterator it = swigpyseq.begin(); for (;it != swigpyseq.end(); ++it) { unordered_multimap->insert(value_type(it->first, it->second)); } } - template <class K, class T> - struct traits_reserve<std::unordered_multimap<K,T> > { - static void reserve(std::unordered_multimap<K,T> &seq, typename std::unordered_multimap<K,T>::size_type n) { + template <class K, class T, class Hash, class Compare, class Alloc> + struct traits_reserve<std::unordered_multimap<K,T,Hash,Compare,Alloc> > { + static void reserve(std::unordered_multimap<K,T,Hash,Compare,Alloc> &seq, typename std::unordered_multimap<K,T,Hash,Compare,Alloc>::size_type n) { seq.reserve(n); } }; - template <class K, class T> - struct traits_asptr<std::unordered_multimap<K,T> > { - typedef std::unordered_multimap<K,T> unordered_multimap_type; - static int asptr(PyObject *obj, std::unordered_multimap<K,T> **val) { + template <class K, class T, class Hash, class Compare, class Alloc> + struct traits_asptr<std::unordered_multimap<K,T,Hash,Compare,Alloc> > { + typedef std::unordered_multimap<K,T,Hash,Compare,Alloc> unordered_multimap_type; + static int asptr(PyObject *obj, std::unordered_multimap<K,T,Hash,Compare,Alloc> **val) { int res = SWIG_ERROR; if (PyDict_Check(obj)) { SwigVar_PyObject items = PyObject_CallMethod(obj,(char *)"items",NULL); @@ -34,7 +34,7 @@ /* In Python 3.x the ".items()" method returns a dict_items object */ items = PySequence_Fast(items, ".items() didn't return a sequence!"); %#endif - res = traits_asptr_stdseq<std::unordered_multimap<K,T>, std::pair<K, T> >::asptr(items, val); + res = traits_asptr_stdseq<std::unordered_multimap<K,T,Hash,Compare,Alloc>, std::pair<K, T> >::asptr(items, val); } else { unordered_multimap_type *p; swig_type_info *descriptor = swig::type_info<unordered_multimap_type>(); @@ -45,9 +45,9 @@ } }; - template <class K, class T > - struct traits_from<std::unordered_multimap<K,T> > { - typedef std::unordered_multimap<K,T> unordered_multimap_type; + template <class K, class T, class Hash, class Compare, class Alloc> + struct traits_from<std::unordered_multimap<K,T,Hash,Compare,Alloc> > { + typedef std::unordered_multimap<K,T,Hash,Compare,Alloc> unordered_multimap_type; typedef typename unordered_multimap_type::const_iterator const_iterator; typedef typename unordered_multimap_type::size_type size_type; diff --git a/Lib/python/std_unordered_multiset.i b/Lib/python/std_unordered_multiset.i index d90a97bdc..b0f3f096b 100644 --- a/Lib/python/std_unordered_multiset.i +++ b/Lib/python/std_unordered_multiset.i @@ -7,9 +7,9 @@ %fragment("StdUnorderedMultisetTraits","header",fragment="StdSequenceTraits") %{ namespace swig { - template <class SwigPySeq, class T> + template <class SwigPySeq, class Key, class Hash, class Compare, class Alloc> inline void - assign(const SwigPySeq& swigpyseq, std::unordered_multiset<T>* seq) { + assign(const SwigPySeq& swigpyseq, std::unordered_multiset<Key,Hash,Compare,Alloc>* seq) { // seq->insert(swigpyseq.begin(), swigpyseq.end()); // not used as not always implemented typedef typename SwigPySeq::value_type value_type; typename SwigPySeq::const_iterator it = swigpyseq.begin(); @@ -18,24 +18,24 @@ } } - template <class T> - struct traits_reserve<std::unordered_multiset<T> > { - static void reserve(std::unordered_multiset<T> &seq, typename std::unordered_multiset<T>::size_type n) { + template <class Key, class Hash, class Compare, class Alloc> + struct traits_reserve<std::unordered_multiset<Key,Hash,Compare,Alloc> > { + static void reserve(std::unordered_multiset<Key,Hash,Compare,Alloc> &seq, typename std::unordered_multiset<Key,Hash,Compare,Alloc>::size_type n) { seq.reserve(n); } }; - template <class T> - struct traits_asptr<std::unordered_multiset<T> > { - static int asptr(PyObject *obj, std::unordered_multiset<T> **m) { - return traits_asptr_stdseq<std::unordered_multiset<T> >::asptr(obj, m); + template <class Key, class Hash, class Compare, class Alloc> + struct traits_asptr<std::unordered_multiset<Key,Hash,Compare,Alloc> > { + static int asptr(PyObject *obj, std::unordered_multiset<Key,Hash,Compare,Alloc> **m) { + return traits_asptr_stdseq<std::unordered_multiset<Key,Hash,Compare,Alloc> >::asptr(obj, m); } }; - template <class T> - struct traits_from<std::unordered_multiset<T> > { - static PyObject *from(const std::unordered_multiset<T>& vec) { - return traits_from_stdseq<std::unordered_multiset<T> >::from(vec); + template <class Key, class Hash, class Compare, class Alloc> + struct traits_from<std::unordered_multiset<Key,Hash,Compare,Alloc> > { + static PyObject *from(const std::unordered_multiset<Key,Hash,Compare,Alloc>& vec) { + return traits_from_stdseq<std::unordered_multiset<Key,Hash,Compare,Alloc> >::from(vec); } }; } diff --git a/Lib/python/std_unordered_set.i b/Lib/python/std_unordered_set.i index 8736cb1b5..79fca6c2f 100644 --- a/Lib/python/std_unordered_set.i +++ b/Lib/python/std_unordered_set.i @@ -5,9 +5,9 @@ %fragment("StdUnorderedSetTraits","header",fragment="StdSequenceTraits") %{ namespace swig { - template <class SwigPySeq, class T> + template <class SwigPySeq, class Key, class Hash, class Compare, class Alloc> inline void - assign(const SwigPySeq& swigpyseq, std::unordered_set<T>* seq) { + assign(const SwigPySeq& swigpyseq, std::unordered_set<Key,Hash,Compare,Alloc>* seq) { // seq->insert(swigpyseq.begin(), swigpyseq.end()); // not used as not always implemented typedef typename SwigPySeq::value_type value_type; typename SwigPySeq::const_iterator it = swigpyseq.begin(); @@ -16,24 +16,24 @@ } } - template <class T> - struct traits_reserve<std::unordered_set<T> > { - static void reserve(std::unordered_set<T> &seq, typename std::unordered_set<T>::size_type n) { + template <class Key, class Hash, class Compare, class Alloc> + struct traits_reserve<std::unordered_set<Key,Hash,Compare,Alloc> > { + static void reserve(std::unordered_set<Key,Hash,Compare,Alloc> &seq, typename std::unordered_set<Key,Hash,Compare,Alloc>::size_type n) { seq.reserve(n); } }; - template <class T> - struct traits_asptr<std::unordered_set<T> > { - static int asptr(PyObject *obj, std::unordered_set<T> **s) { - return traits_asptr_stdseq<std::unordered_set<T> >::asptr(obj, s); + template <class Key, class Hash, class Compare, class Alloc> + struct traits_asptr<std::unordered_set<Key,Hash,Compare,Alloc> > { + static int asptr(PyObject *obj, std::unordered_set<Key,Hash,Compare,Alloc> **s) { + return traits_asptr_stdseq<std::unordered_set<Key,Hash,Compare,Alloc> >::asptr(obj, s); } }; - template <class T> - struct traits_from<std::unordered_set<T> > { - static PyObject *from(const std::unordered_set<T>& vec) { - return traits_from_stdseq<std::unordered_set<T> >::from(vec); + template <class Key, class Hash, class Compare, class Alloc> + struct traits_from<std::unordered_set<Key,Hash,Compare,Alloc> > { + static PyObject *from(const std::unordered_set<Key,Hash,Compare,Alloc>& vec) { + return traits_from_stdseq<std::unordered_set<Key,Hash,Compare,Alloc> >::from(vec); } }; } diff --git a/Lib/r/r.swg b/Lib/r/r.swg index a9035331b..8cf8cdf53 100644 --- a/Lib/r/r.swg +++ b/Lib/r/r.swg @@ -192,6 +192,11 @@ unsigned char *OUTPUT free($1); } +%typemap(in) const enum SWIGTYPE & ($*1_ltype temp) +%{ temp = ($*1_ltype)INTEGER($input)[0]; + $1 = &temp; %} + +%typemap(out) const enum SWIGTYPE & %{ $result = Rf_ScalarInteger((int)*$1); %} %typemap(memberin) char[] %{ if ($input) strcpy($1, $input); diff --git a/Lib/r/rtype.swg b/Lib/r/rtype.swg index c55c70377..bdc48c24e 100644 --- a/Lib/r/rtype.swg +++ b/Lib/r/rtype.swg @@ -16,6 +16,7 @@ %typemap("rtype") enum SWIGTYPE * "character"; %typemap("rtype") enum SWIGTYPE *const "character"; %typemap("rtype") enum SWIGTYPE & "character"; +%typemap("rtype") const enum SWIGTYPE & "character"; %typemap("rtype") enum SWIGTYPE && "character"; %typemap("rtype") SWIGTYPE * "$R_class"; %typemap("rtype") SWIGTYPE *const "$R_class"; @@ -86,9 +87,7 @@ %typemap(scoercein) enum SWIGTYPE %{ $input = enumToInteger($input, "$R_class"); %} %typemap(scoercein) enum SWIGTYPE & - %{ $input = enumToInteger($input, "$R_class"); %} -%typemap(scoercein) enum SWIGTYPE && - %{ $input = enumToInteger($input, "$R_class"); %} + %{ $input = enumToInteger($input, "$*R_class"); %} %typemap(scoercein) enum SWIGTYPE * %{ $input = enumToInteger($input, "$R_class"); %} %typemap(scoercein) enum SWIGTYPE *const @@ -138,7 +137,7 @@ string &, std::string & %{ $result = enumFromInteger($result, "$R_class"); %} %typemap(scoerceout) enum SWIGTYPE & - %{ $result = enumFromInteger($result, "$R_class"); %} + %{ $result = enumFromInteger($result, "$*R_class"); %} %typemap(scoerceout) enum SWIGTYPE && %{ $result = enumFromInteger($result, "$R_class"); %} diff --git a/Lib/r/srun.swg b/Lib/r/srun.swg index d07218a77..2e8eda112 100644 --- a/Lib/r/srun.swg +++ b/Lib/r/srun.swg @@ -73,7 +73,7 @@ function(name, .values, where = topenv(parent.frame()), suffix = "Value") { # Mirror the class definitions via the E analogous to .__C__ defName = paste(".__E__", name, sep = "") - assign(defName, .values, envir = where) + delayedAssign(defName, .values, assign.env = where) if(nchar(suffix)) name = paste(name, suffix, sep = "") diff --git a/Lib/ruby/rubyhead.swg b/Lib/ruby/rubyhead.swg index 9960087c6..90f07cf68 100644 --- a/Lib/ruby/rubyhead.swg +++ b/Lib/ruby/rubyhead.swg @@ -91,6 +91,9 @@ #ifndef RSTRUCT_PTR # define RSTRUCT_PTR(x) RSTRUCT(x)->ptr #endif +#ifndef RTYPEDDATA_P +# define RTYPEDDATA_P(x) (TYPE(x) != T_DATA) +#endif diff --git a/Lib/ruby/rubyrun.swg b/Lib/ruby/rubyrun.swg index b4dd9ddf0..4b2ffe4b4 100644 --- a/Lib/ruby/rubyrun.swg +++ b/Lib/ruby/rubyrun.swg @@ -247,7 +247,7 @@ typedef struct { SWIGRUNTIME swig_ruby_owntype SWIG_Ruby_AcquirePtr(VALUE obj, swig_ruby_owntype own) { swig_ruby_owntype oldown = {0, 0}; - if (TYPE(obj) == T_DATA) { + if (TYPE(obj) == T_DATA && !RTYPEDDATA_P(obj)) { oldown.datafree = RDATA(obj)->dfree; RDATA(obj)->dfree = own.datafree; } @@ -268,7 +268,7 @@ SWIG_Ruby_ConvertPtrAndOwn(VALUE obj, void **ptr, swig_type_info *ty, int flags, *ptr = 0; return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK; } else { - if (TYPE(obj) != T_DATA) { + if (TYPE(obj) != T_DATA || (TYPE(obj) == T_DATA && RTYPEDDATA_P(obj))) { return SWIG_ERROR; } Data_Get_Struct(obj, void, vptr); diff --git a/Lib/ruby/std_unordered_map.i b/Lib/ruby/std_unordered_map.i index c3f60bbba..48c875214 100644 --- a/Lib/ruby/std_unordered_map.i +++ b/Lib/ruby/std_unordered_map.i @@ -6,25 +6,25 @@ %fragment("StdUnorderedMapTraits","header",fragment="StdMapCommonTraits") { namespace swig { - template <class RubySeq, class K, class T > + template <class RubySeq, class K, class T, class Hash, class Compare, class Alloc> inline void - assign(const RubySeq& rubyseq, std::unordered_map<K,T > *map) { - typedef typename std::unordered_map<K,T>::value_type value_type; + assign(const RubySeq& rubyseq, std::unordered_map<K,T,Hash,Compare,Alloc> *map) { + typedef typename std::unordered_map<K,T,Hash,Compare,Alloc>::value_type value_type; typename RubySeq::const_iterator it = rubyseq.begin(); for (;it != rubyseq.end(); ++it) { map->insert(value_type(it->first, it->second)); } } - template <class K, class T> - struct traits_asptr<std::unordered_map<K,T> > { - typedef std::unordered_map<K,T> map_type; + template <class K, class T, class Hash, class Compare, class Alloc> + struct traits_asptr<std::unordered_map<K,T,Hash,Compare,Alloc> > { + typedef std::unordered_map<K,T,Hash,Compare,Alloc> map_type; static int asptr(VALUE obj, map_type **val) { int res = SWIG_ERROR; if (TYPE(obj) == T_HASH) { static ID id_to_a = rb_intern("to_a"); VALUE items = rb_funcall(obj, id_to_a, 0); - res = traits_asptr_stdseq<std::unordered_map<K,T>, std::pair<K, T> >::asptr(items, val); + res = traits_asptr_stdseq<std::unordered_map<K,T,Hash,Compare,Alloc>, std::pair<K, T> >::asptr(items, val); } else { map_type *p; swig_type_info *descriptor = swig::type_info<map_type>(); @@ -35,9 +35,9 @@ } }; - template <class K, class T > - struct traits_from<std::unordered_map<K,T> > { - typedef std::unordered_map<K,T> map_type; + template <class K, class T, class Hash, class Compare, class Alloc> + struct traits_from<std::unordered_map<K,T,Hash,Compare,Alloc> > { + typedef std::unordered_map<K,T,Hash,Compare,Alloc> map_type; typedef typename map_type::const_iterator const_iterator; typedef typename map_type::size_type size_type; diff --git a/Lib/ruby/std_unordered_multimap.i b/Lib/ruby/std_unordered_multimap.i index b663c1298..ebc53b597 100644 --- a/Lib/ruby/std_unordered_multimap.i +++ b/Lib/ruby/std_unordered_multimap.i @@ -6,25 +6,25 @@ %fragment("StdUnorderedMultimapTraits","header",fragment="StdMapCommonTraits") { namespace swig { - template <class RubySeq, class K, class T > + template <class RubySeq, class K, class T, class Hash, class Compare, class Alloc> inline void - assign(const RubySeq& rubyseq, std::unordered_multimap<K,T > *multimap) { - typedef typename std::unordered_multimap<K,T>::value_type value_type; + assign(const RubySeq& rubyseq, std::unordered_multimap<K,T,Hash,Compare,Alloc> *multimap) { + typedef typename std::unordered_multimap<K,T,Hash,Compare,Alloc>::value_type value_type; typename RubySeq::const_iterator it = rubyseq.begin(); for (;it != rubyseq.end(); ++it) { multimap->insert(value_type(it->first, it->second)); } } - template <class K, class T> - struct traits_asptr<std::unordered_multimap<K,T> > { - typedef std::unordered_multimap<K,T> multimap_type; - static int asptr(VALUE obj, std::unordered_multimap<K,T> **val) { + template <class K, class T, class Hash, class Compare, class Alloc> + struct traits_asptr<std::unordered_multimap<K,T,Hash,Compare,Alloc> > { + typedef std::unordered_multimap<K,T,Hash,Compare,Alloc> multimap_type; + static int asptr(VALUE obj, std::unordered_multimap<K,T,Hash,Compare,Alloc> **val) { int res = SWIG_ERROR; if ( TYPE(obj) == T_HASH ) { static ID id_to_a = rb_intern("to_a"); VALUE items = rb_funcall(obj, id_to_a, 0); - return traits_asptr_stdseq<std::unordered_multimap<K,T>, std::pair<K, T> >::asptr(items, val); + return traits_asptr_stdseq<std::unordered_multimap<K,T,Hash,Compare,Alloc>, std::pair<K, T> >::asptr(items, val); } else { multimap_type *p; res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<multimap_type>(),0); @@ -34,9 +34,9 @@ } }; - template <class K, class T > - struct traits_from<std::unordered_multimap<K,T> > { - typedef std::unordered_multimap<K,T> multimap_type; + template <class K, class T, class Hash, class Compare, class Alloc> + struct traits_from<std::unordered_multimap<K,T,Hash,Compare,Alloc> > { + typedef std::unordered_multimap<K,T,Hash,Compare,Alloc> multimap_type; typedef typename multimap_type::const_iterator const_iterator; typedef typename multimap_type::size_type size_type; diff --git a/Lib/ruby/std_unordered_multiset.i b/Lib/ruby/std_unordered_multiset.i index 181aa212d..dae13eef3 100644 --- a/Lib/ruby/std_unordered_multiset.i +++ b/Lib/ruby/std_unordered_multiset.i @@ -7,9 +7,9 @@ %fragment("StdUnorderedMultisetTraits","header",fragment="StdUnorderedSetTraits") %{ namespace swig { - template <class RubySeq, class T> + template <class RubySeq, class Key, class Hash, class Compare, class Alloc> inline void - assign(const RubySeq& rubyseq, std::unordered_multiset<T>* seq) { + assign(const RubySeq& rubyseq, std::unordered_multiset<Key,Hash,Compare,Alloc>* seq) { // seq->insert(rubyseq.begin(), rubyseq.end()); // not used as not always implemented typedef typename RubySeq::value_type value_type; typename RubySeq::const_iterator it = rubyseq.begin(); @@ -18,17 +18,17 @@ } } - template <class T> - struct traits_asptr<std::unordered_multiset<T> > { - static int asptr(VALUE obj, std::unordered_multiset<T> **m) { - return traits_asptr_stdseq<std::unordered_multiset<T> >::asptr(obj, m); + template <class Key, class Hash, class Compare, class Alloc> + struct traits_asptr<std::unordered_multiset<Key,Hash,Compare,Alloc> > { + static int asptr(VALUE obj, std::unordered_multiset<Key,Hash,Compare,Alloc> **m) { + return traits_asptr_stdseq<std::unordered_multiset<Key,Hash,Compare,Alloc> >::asptr(obj, m); } }; - template <class T> - struct traits_from<std::unordered_multiset<T> > { - static VALUE from(const std::unordered_multiset<T>& vec) { - return traits_from_stdseq<std::unordered_multiset<T> >::from(vec); + template <class Key, class Hash, class Compare, class Alloc> + struct traits_from<std::unordered_multiset<Key,Hash,Compare,Alloc> > { + static VALUE from(const std::unordered_multiset<Key,Hash,Compare,Alloc>& vec) { + return traits_from_stdseq<std::unordered_multiset<Key,Hash,Compare,Alloc> >::from(vec); } }; } diff --git a/Lib/ruby/std_unordered_set.i b/Lib/ruby/std_unordered_set.i index 3d4494351..e8e1b0872 100644 --- a/Lib/ruby/std_unordered_set.i +++ b/Lib/ruby/std_unordered_set.i @@ -7,9 +7,9 @@ %fragment("StdUnorderedSetTraits","header",fragment="<stddef.h>",fragment="StdSetTraits") %{ namespace swig { - template <class RubySeq, class T> + template <class RubySeq, class Key, class Hash, class Compare, class Alloc> inline void - assign(const RubySeq& rubyseq, std::unordered_set<T>* seq) { + assign(const RubySeq& rubyseq, std::unordered_set<Key,Hash,Compare,Alloc>* seq) { // seq->insert(rubyseq.begin(), rubyseq.end()); // not used as not always implemented typedef typename RubySeq::value_type value_type; typename RubySeq::const_iterator it = rubyseq.begin(); @@ -18,17 +18,17 @@ } } - template <class T> - struct traits_asptr<std::unordered_set<T> > { - static int asptr(VALUE obj, std::unordered_set<T> **s) { - return traits_asptr_stdseq<std::unordered_set<T> >::asptr(obj, s); + template <class Key, class Hash, class Compare, class Alloc> + struct traits_asptr<std::unordered_set<Key,Hash,Compare,Alloc> > { + static int asptr(VALUE obj, std::unordered_set<Key,Hash,Compare,Alloc> **s) { + return traits_asptr_stdseq<std::unordered_set<Key,Hash,Compare,Alloc> >::asptr(obj, s); } }; - template <class T> - struct traits_from<std::unordered_set<T> > { - static VALUE from(const std::unordered_set<T>& vec) { - return traits_from_stdseq<std::unordered_set<T> >::from(vec); + template <class Key, class Hash, class Compare, class Alloc> + struct traits_from<std::unordered_set<Key,Hash,Compare,Alloc> > { + static VALUE from(const std::unordered_set<Key,Hash,Compare,Alloc>& vec) { + return traits_from_stdseq<std::unordered_set<Key,Hash,Compare,Alloc> >::from(vec); } }; } diff --git a/Lib/std/std_unordered_map.i b/Lib/std/std_unordered_map.i index 723c0232d..1fd1eb980 100644 --- a/Lib/std/std_unordered_map.i +++ b/Lib/std/std_unordered_map.i @@ -75,6 +75,8 @@ namespace std { typedef const value_type* const_pointer; typedef value_type& reference; typedef const value_type& const_reference; + typedef _Hash hasher; + typedef _Compare key_equal; typedef _Alloc allocator_type; %traits_swigtype(_Key); diff --git a/Lib/std/std_unordered_multimap.i b/Lib/std/std_unordered_multimap.i index f2855343d..4be6aa492 100644 --- a/Lib/std/std_unordered_multimap.i +++ b/Lib/std/std_unordered_multimap.i @@ -53,6 +53,8 @@ namespace std { typedef const value_type* const_pointer; typedef value_type& reference; typedef const value_type& const_reference; + typedef _Hash hasher; + typedef _Compare key_equal; typedef _Alloc allocator_type; %traits_swigtype(_Key); diff --git a/Lib/std/std_unordered_multiset.i b/Lib/std/std_unordered_multiset.i index 1817fc24a..2910fb6ff 100644 --- a/Lib/std/std_unordered_multiset.i +++ b/Lib/std/std_unordered_multiset.i @@ -17,19 +17,19 @@ // const declarations are used to guess the intent of the function being // exported; therefore, the following rationale is applied: // -// -- f(std::unordered_multiset<T>), f(const std::unordered_multiset<T>&): +// -- f(std::unordered_multiset<Key>), f(const std::unordered_multiset<Key>&): // the parameter being read-only, either a sequence or a -// previously wrapped std::unordered_multiset<T> can be passed. -// -- f(std::unordered_multiset<T>&), f(std::unordered_multiset<T>*): +// previously wrapped std::unordered_multiset<Key> can be passed. +// -- f(std::unordered_multiset<Key>&), f(std::unordered_multiset<Key>*): // the parameter may be modified; therefore, only a wrapped std::unordered_multiset // can be passed. -// -- std::unordered_multiset<T> f(), const std::unordered_multiset<T>& f(): -// the set is returned by copy; therefore, a sequence of T:s +// -- std::unordered_multiset<Key> f(), const std::unordered_multiset<Key>& f(): +// the set is returned by copy; therefore, a sequence of Key:s // is returned which is most easily used in other functions -// -- std::unordered_multiset<T>& f(), std::unordered_multiset<T>* f(): +// -- std::unordered_multiset<Key>& f(), std::unordered_multiset<Key>* f(): // the set is returned by reference; therefore, a wrapped std::unordered_multiset // is returned -// -- const std::unordered_multiset<T>* f(), f(const std::unordered_multiset<T>*): +// -- const std::unordered_multiset<Key>* f(), f(const std::unordered_multiset<Key>*): // for consistency, they expect and return a plain set pointer. // ------------------------------------------------------------------------ @@ -40,9 +40,10 @@ namespace std { //unordered_multiset - template <class _Key, class _Hash = std::hash< _Key >, + template <class _Key, + class _Hash = std::hash< _Key >, class _Compare = std::equal_to< _Key >, - class _Alloc = allocator< _Key > > + class _Alloc = allocator< _Key > > class unordered_multiset { public: typedef size_t size_type; @@ -53,6 +54,8 @@ namespace std { typedef const value_type* const_pointer; typedef value_type& reference; typedef const value_type& const_reference; + typedef _Hash hasher; + typedef _Compare key_equal; typedef _Alloc allocator_type; %traits_swigtype(_Key); diff --git a/Lib/std/std_unordered_set.i b/Lib/std/std_unordered_set.i index 133246da8..91e807423 100644 --- a/Lib/std/std_unordered_set.i +++ b/Lib/std/std_unordered_set.i @@ -50,19 +50,19 @@ // const declarations are used to guess the intent of the function being // exported; therefore, the following rationale is applied: // -// -- f(std::unordered_set<T>), f(const std::unordered_set<T>&): +// -- f(std::unordered_set<Key>), f(const std::unordered_set<Key>&): // the parameter being read-only, either a sequence or a -// previously wrapped std::unordered_set<T> can be passed. -// -- f(std::unordered_set<T>&), f(std::unordered_set<T>*): +// previously wrapped std::unordered_set<Key> can be passed. +// -- f(std::unordered_set<Key>&), f(std::unordered_set<Key>*): // the parameter may be modified; therefore, only a wrapped std::unordered_set // can be passed. -// -- std::unordered_set<T> f(), const std::unordered_set<T>& f(): -// the unordered_set is returned by copy; therefore, a sequence of T:s +// -- std::unordered_set<Key> f(), const std::unordered_set<Key>& f(): +// the unordered_set is returned by copy; therefore, a sequence of Key:s // is returned which is most easily used in other functions -// -- std::unordered_set<T>& f(), std::unordered_set<T>* f(): +// -- std::unordered_set<Key>& f(), std::unordered_set<Key>* f(): // the unordered_set is returned by reference; therefore, a wrapped std::unordered_set // is returned -// -- const std::unordered_set<T>* f(), f(const std::unordered_set<T>*): +// -- const std::unordered_set<Key>* f(), f(const std::unordered_set<Key>*): // for consistency, they expect and return a plain unordered_set pointer. // ------------------------------------------------------------------------ @@ -74,20 +74,22 @@ namespace std { - template <class _Key, class _Hash = std::hash< _Key >, + template <class _Key, + class _Hash = std::hash< _Key >, class _Compare = std::equal_to< _Key >, - class _Alloc = allocator< _Key > > + class _Alloc = allocator< _Key > > class unordered_set { public: typedef size_t size_type; typedef ptrdiff_t difference_type; - typedef _Hash hasher; typedef _Key value_type; typedef _Key key_type; typedef value_type* pointer; typedef const value_type* const_pointer; typedef value_type& reference; typedef const value_type& const_reference; + typedef _Hash hasher; + typedef _Compare key_equal; typedef _Alloc allocator_type; %traits_swigtype(_Key); diff --git a/Lib/swigfragments.swg b/Lib/swigfragments.swg index 63bb6c8f4..2cbef7cce 100644 --- a/Lib/swigfragments.swg +++ b/Lib/swigfragments.swg @@ -35,7 +35,7 @@ %fragment("<stdio.h>", "header") %{ #include <stdio.h> -#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) +#if (defined(_MSC_VER) && (_MSC_VER < 1900)) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf # define snprintf _snprintf # endif |