Merge branch 'master' into directorargout_and_java_typemaps

This commit is contained in:
Andrey Starodubtsev 2016-11-02 18:12:38 +03:00
commit 3e449ea05f
68 changed files with 2861 additions and 2151 deletions

View file

@ -860,7 +860,8 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
global::System.IntPtr ret = $imcall;$excode
return ret;
}
%typemap(csdirectorin) void *VOID_INT_PTR "$iminput"
%typemap(csdirectorout) void *VOID_INT_PTR "$cscall"
/* Typemaps used for the generation of proxy and type wrapper class code */
%typemap(csbase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) ""

227
Lib/csharp/std_array.i Normal file
View file

@ -0,0 +1,227 @@
/* -----------------------------------------------------------------------------
* std_array.i
*
* SWIG typemaps for std::array<T, N>
* C# implementation
* The C# wrapper is made to look and feel like a C# System.Collections.Generic.IReadOnlyList<> collection.
* ----------------------------------------------------------------------------- */
%{
#include <algorithm>
#include <array>
#include <stdexcept>
%}
%include <std_common.i>
%define SWIG_STD_ARRAY_INTERNAL(T, N)
%typemap(csinterfaces) std::array< T, N > "global::System.IDisposable, global::System.Collections.IEnumerable\n , global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)>\n";
%typemap(cscode) std::array< T, N > %{
public $csclassname(global::System.Collections.ICollection c) : this() {
if (c == null)
throw new global::System.ArgumentNullException("c");
int end = global::System.Math.Min(this.Count, c.Count);
int i = 0;
foreach ($typemap(cstype, T) elem in c) {
if (i >= end)
break;
this[i++] = elem;
}
}
public int Count {
get {
return (int)size();
}
}
public $typemap(cstype, T) this[int index] {
get {
return getitem(index);
}
set {
setitem(index, value);
}
}
public bool IsEmpty {
get {
return empty();
}
}
public void CopyTo($typemap(cstype, T)[] array)
{
CopyTo(0, array, 0, this.Count);
}
public void CopyTo($typemap(cstype, T)[] array, int arrayIndex)
{
CopyTo(0, array, arrayIndex, this.Count);
}
public void CopyTo(int index, $typemap(cstype, T)[] array, int arrayIndex, int count)
{
if (array == null)
throw new global::System.ArgumentNullException("array");
if (index < 0)
throw new global::System.ArgumentOutOfRangeException("index", "Value is less than zero");
if (arrayIndex < 0)
throw new global::System.ArgumentOutOfRangeException("arrayIndex", "Value is less than zero");
if (count < 0)
throw new global::System.ArgumentOutOfRangeException("count", "Value is less than zero");
if (array.Rank > 1)
throw new global::System.ArgumentException("Multi dimensional array.", "array");
if (index+count > this.Count || arrayIndex+count > array.Length)
throw new global::System.ArgumentException("Number of elements to copy is too large.");
for (int i=0; i<count; i++)
array.SetValue(getitemcopy(index+i), arrayIndex+i);
}
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 int currentIndex;
private object currentObject;
private int currentSize;
public $csclassnameEnumerator($csclassname collection) {
collectionRef = collection;
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 ($typemap(cstype, T))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 = collectionRef[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 value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
array();
array(const array &other);
size_type size() const;
bool empty() const;
%rename(Fill) fill;
void fill(const value_type& val);
%rename(Swap) swap;
void swap(array& other);
%extend {
T getitemcopy(int index) throw (std::out_of_range) {
if (index>=0 && index<(int)$self->size())
return (*$self)[index];
else
throw std::out_of_range("index");
}
const_reference getitem(int index) throw (std::out_of_range) {
if (index>=0 && index<(int)$self->size())
return (*$self)[index];
else
throw std::out_of_range("index");
}
void setitem(int index, const_reference val) throw (std::out_of_range) {
if (index>=0 && index<(int)$self->size())
(*$self)[index] = val;
else
throw std::out_of_range("index");
}
void Reverse() {
std::reverse($self->begin(), $self->end());
}
void Reverse(int index, int count) throw (std::out_of_range, std::invalid_argument) {
if (index < 0)
throw std::out_of_range("index");
if (count < 0)
throw std::out_of_range("count");
if (index >= (int)$self->size()+1 || index+count > (int)$self->size())
throw std::invalid_argument("invalid range");
std::reverse($self->begin()+index, $self->begin()+index+count);
}
}
%enddef
%csmethodmodifiers std::array::empty "private"
%csmethodmodifiers std::array::getitemcopy "private"
%csmethodmodifiers std::array::getitem "private"
%csmethodmodifiers std::array::setitem "private"
%csmethodmodifiers std::array::size "private"
namespace std {
template<class T, size_t N> class array {
SWIG_STD_ARRAY_INTERNAL(T, N)
};
}

View file

@ -398,4 +398,5 @@ SWIG_STD_VECTOR_ENHANCED(unsigned long long)
SWIG_STD_VECTOR_ENHANCED(float)
SWIG_STD_VECTOR_ENHANCED(double)
SWIG_STD_VECTOR_ENHANCED(std::string) // also requires a %include <std_string.i>
SWIG_STD_VECTOR_ENHANCED(std::wstring) // also requires a %include <std_wstring.i>

View file

@ -60,16 +60,15 @@ class wstring;
%}
%typemap(directorin,descriptor="Ljava/lang/String;") wstring %{
{
jsize $1_len = $1.length();
jchar *conv_buf = new jchar[$1_len];
jchar *$1_conv_buf = new jchar[$1_len];
for (jsize i = 0; i < $1_len; ++i) {
conv_buf[i] = (jchar)$1[i];
$1_conv_buf[i] = (jchar)$1[i];
}
$input = jenv->NewString(conv_buf, $1_len);
delete [] conv_buf;
}
Swig::LocalRefGuard $1_refguard(jenv, $input); %}
$input = jenv->NewString($1_conv_buf, $1_len);
Swig::LocalRefGuard $1_refguard(jenv, $input);
delete [] $1_conv_buf;
%}
%typemap(out) wstring
%{jsize $1_len = $1.length();
@ -139,16 +138,15 @@ Swig::LocalRefGuard $1_refguard(jenv, $input); %}
jenv->ReleaseStringChars($input, $1_pstr); %}
%typemap(directorin,descriptor="Ljava/lang/String;") const wstring & %{
{
jsize $1_len = $1.length();
jchar *conv_buf = new jchar[$1_len];
jchar *$1_conv_buf = new jchar[$1_len];
for (jsize i = 0; i < $1_len; ++i) {
conv_buf[i] = (jchar)($1)[i];
$1_conv_buf[i] = (jchar)($1)[i];
}
$input = jenv->NewString(conv_buf, $1_len);
delete [] conv_buf;
}
Swig::LocalRefGuard $1_refguard(jenv, $input); %}
$input = jenv->NewString($1_conv_buf, $1_len);
Swig::LocalRefGuard $1_refguard(jenv, $input);
delete [] $1_conv_buf;
%}
%typemap(out) const wstring &
%{jsize $1_len = $1->length();

View file

@ -4,8 +4,7 @@
* Global variables - add the variable to PHP
* ----------------------------------------------------------------------------- */
%typemap(varinit) char *,
char []
%typemap(varinit) char *
{
zval *z_var;
MAKE_STD_ZVAL(z_var);
@ -20,6 +19,16 @@
zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void *)&z_var, sizeof(zval *), NULL);
}
%typemap(varinit) char []
{
zval *z_var;
MAKE_STD_ZVAL(z_var);
z_var->type = IS_STRING;
z_var->value.str.val = estrdup($1);
z_var->value.str.len = strlen($1);
zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void *)&z_var, sizeof(zval *), NULL);
}
%typemap(varinit) int,
unsigned int,
unsigned short,
@ -95,10 +104,7 @@
zval *z_var;
MAKE_STD_ZVAL(z_var);
z_var->type = IS_STRING;
if ($1) {
/* varinit char [ANY] */
ZVAL_STRINGL(z_var,(char*)$1, $1_dim0, 1);
}
ZVAL_STRINGL(z_var,(char*)$1, $1_dim0, 1);
zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void*)&z_var, sizeof(zval *), NULL);
}

View file

@ -164,9 +164,13 @@ SwigPyStaticVar_set(PyGetSetDescrObject *descr, PyObject *obj, PyObject *value)
}
SWIGINTERN int
SwigPyObjectType_setattro(PyTypeObject *type, PyObject *name, PyObject *value) {
SwigPyObjectType_setattro(PyObject *typeobject, PyObject *name, PyObject *value) {
PyObject *attribute;
PyTypeObject *type;
descrsetfunc local_set;
assert(PyType_Check(typeobject));
type = (PyTypeObject *)typeobject;
attribute = _PyType_Lookup(type, name);
if (attribute != NULL) {
/* Implement descriptor functionality, if any */
@ -276,6 +280,95 @@ SwigPyStaticVar_Type(void) {
return &staticvar_type;
}
SWIGINTERN PyTypeObject*
SwigPyObjectType(void) {
static char swigpyobjecttype_doc[] = "Metaclass for SWIG wrapped types";
static PyTypeObject swigpyobjecttype_type;
static int type_init = 0;
if (!type_init) {
const PyTypeObject tmp = {
#if PY_VERSION_HEX >= 0x03000000
PyVarObject_HEAD_INIT(&PyType_Type, 0)
#else
PyObject_HEAD_INIT(&PyType_Type)
0, /* ob_size */
#endif
"SwigPyObjectType", /* tp_name */
PyType_Type.tp_basicsize, /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
SwigPyObjectType_setattro, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_CLASS, /* tp_flags */
swigpyobjecttype_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
0, /* tp_free */
0, /* tp_is_gc */
0, /* tp_bases */
0, /* tp_mro */
0, /* tp_cache */
0, /* tp_subclasses */
0, /* tp_weaklist */
#if PY_VERSION_HEX >= 0x02030000
0, /* tp_del */
#endif
#if PY_VERSION_HEX >= 0x02060000
0, /* tp_version_tag */
#endif
#if PY_VERSION_HEX >= 0x03040000
0, /* tp_finalize */
#endif
#ifdef COUNT_ALLOCS
0, /* tp_allocs */
0, /* tp_frees */
0, /* tp_maxalloc */
#if PY_VERSION_HEX >= 0x02050000
0, /* tp_prev */
#endif
0 /* tp_next */
#endif
};
swigpyobjecttype_type = tmp;
type_init = 1;
swigpyobjecttype_type.tp_base = &PyType_Type;
#if PY_VERSION_HEX < 0x02020000
swigpyobjecttype_type.ob_type = &PyType_Type;
#else
if (PyType_Ready(&swigpyobjecttype_type) < 0)
return NULL;
#endif
}
return &swigpyobjecttype_type;
}
SWIGINTERN PyGetSetDescrObject *
SwigPyStaticVar_new_getset(PyTypeObject *type, PyGetSetDef *getset) {

View file

@ -374,13 +374,13 @@ SWIG_init(void) {
static PyGetSetDef thisown_getset_def = {
(char *)"thisown", SwigPyBuiltin_GetterClosure, SwigPyBuiltin_SetterClosure, NULL, &thisown_getset_closure
};
PyObject *metatype_args;
PyTypeObject *builtin_pytype;
int builtin_base_count;
swig_type_info *builtin_basetype;
PyObject *tuple;
PyGetSetDescrObject *static_getset;
PyTypeObject *metatype;
PyTypeObject *swigpyobject;
SwigPyClientData *cd;
PyObject *public_interface, *public_symbol;
PyObject *this_descr;
@ -395,14 +395,9 @@ SWIG_init(void) {
(void)static_getset;
(void)self;
/* metatype is used to implement static member variables. */
metatype_args = Py_BuildValue("(s(O){})", "SwigPyObjectType", &PyType_Type);
assert(metatype_args);
metatype = (PyTypeObject *) PyType_Type.tp_call((PyObject *) &PyType_Type, metatype_args, NULL);
/* Metaclass is used to implement static member variables */
metatype = SwigPyObjectType();
assert(metatype);
Py_DECREF(metatype_args);
metatype->tp_setattro = (setattrofunc) &SwigPyObjectType_setattro;
assert(PyType_Ready(metatype) >= 0);
#endif
/* Fix SwigMethods to carry the callback ptrs when needed */
@ -420,13 +415,15 @@ SWIG_init(void) {
SWIG_InitializeModule(0);
#ifdef SWIGPYTHON_BUILTIN
swigpyobject = SwigPyObject_TypeOnce();
SwigPyObject_stype = SWIG_MangledTypeQuery("_p_SwigPyObject");
assert(SwigPyObject_stype);
cd = (SwigPyClientData*) SwigPyObject_stype->clientdata;
if (!cd) {
SwigPyObject_stype->clientdata = &SwigPyObject_clientdata;
SwigPyObject_clientdata.pytype = SwigPyObject_TypeOnce();
} else if (SwigPyObject_TypeOnce()->tp_basicsize != cd->pytype->tp_basicsize) {
SwigPyObject_clientdata.pytype = swigpyobject;
} else if (swigpyobject->tp_basicsize != cd->pytype->tp_basicsize) {
PyErr_SetString(PyExc_RuntimeError, "Import error: attempted to load two incompatible swig-generated modules.");
# if PY_VERSION_HEX >= 0x03000000
return NULL;