mirror of https://github.com/swig/swig
'out' or 'ref' usage in a cstype typemap in directors
'out' / 'ref' was not always stripped out in parts of the director code generation. Issue #1628
This commit is contained in:
parent
cb5d7398b5
commit
6fb345feb2
|
@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
|||
Version 4.0.2 (in progress)
|
||||
===========================
|
||||
|
||||
2019-11-26: wsfulton
|
||||
[C#] #1628 'out' or 'ref' used in a cstype typemap was not always stripped out in parts
|
||||
of director code generation.
|
||||
|
||||
2019-11-01: wsfulton
|
||||
[Python] #1595 Fix bug in support for keyword arguments (kwargs feature or -keyword)
|
||||
when using -builtin. The fix is in the argument error checking when wrapping zero
|
||||
|
|
|
@ -16,6 +16,7 @@ CPP_TEST_CASES = \
|
|||
complextest \
|
||||
csharp_attributes \
|
||||
csharp_swig2_compatibility \
|
||||
csharp_director_typemaps \
|
||||
csharp_exceptions \
|
||||
csharp_features \
|
||||
csharp_lib_arrays \
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using csharp_director_typemapsNamespace;
|
||||
|
||||
public class csharp_director_typemaps_runme {
|
||||
|
||||
class CSharpDirectorTypemaps_InStreamDerived : InStream
|
||||
{
|
||||
private int constant;
|
||||
public CSharpDirectorTypemaps_InStreamDerived(int constant) { this.constant = constant; }
|
||||
public override int Read(global::System.IntPtr buf, int len, out int readLen) {
|
||||
readLen = (buf == global::System.IntPtr.Zero) ? -len - constant : len + constant;
|
||||
return readLen;
|
||||
}
|
||||
public override int Write(global::System.IntPtr buf, int len, out int writeLen) {
|
||||
writeLen = (buf == global::System.IntPtr.Zero) ? -len - constant : len + constant;
|
||||
return writeLen;
|
||||
}
|
||||
}
|
||||
public static void Main() {
|
||||
int outLen = -1;
|
||||
int k = 100;
|
||||
int j = 23;
|
||||
InStream instream = new CSharpDirectorTypemaps_InStreamDerived(k);
|
||||
|
||||
{
|
||||
int ret = csharp_director_typemaps.callRead(instream, InStream.getCPtr(instream).Handle, j, out outLen);
|
||||
Assert(outLen, j + k);
|
||||
Assert(ret, j + k);
|
||||
}
|
||||
{
|
||||
int ret = csharp_director_typemaps.callRead(instream, global::System.IntPtr.Zero, j, out outLen);
|
||||
Assert(outLen, -j - k);
|
||||
Assert(ret, -j - k);
|
||||
}
|
||||
|
||||
{
|
||||
int ret = csharp_director_typemaps.callWrite(instream, InStream.getCPtr(instream).Handle, j, out outLen);
|
||||
Assert(outLen, j + k);
|
||||
Assert(ret, j + k);
|
||||
}
|
||||
{
|
||||
int ret = csharp_director_typemaps.callWrite(instream, global::System.IntPtr.Zero, j, out outLen);
|
||||
Assert(outLen, -j - k);
|
||||
Assert(ret, -j - k);
|
||||
}
|
||||
}
|
||||
private static void Assert(int i1, int i2) {
|
||||
if (i1 != i2)
|
||||
throw new Exception("assertion failure. " + i1 + " != " + i2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
%module (directors="1") csharp_director_typemaps
|
||||
|
||||
// This tests that the csout typemap is handled correctly in the director code.
|
||||
// The 'out' needs stripping in some parts of the generated director code.
|
||||
|
||||
%feature("director") InStream;
|
||||
|
||||
%apply void *VOID_INT_PTR { void * }
|
||||
|
||||
%typemap(ctype) int* readLen, int* writeLen "/*ctype*/ int*"
|
||||
%typemap(imtype) int* readLen, int* writeLen "/*imtype*/ out int"
|
||||
%typemap(cstype) int* readLen "/*cstype*/ out int"
|
||||
//%typemap(cstype) int* writeLen "/*out cstype out*/ out int"
|
||||
%apply int *readLen { int* writeLen } // Replaced above - 'out' in a comment is not working yet
|
||||
%typemap(csin) int* readLen, int* writeLen "/*csin*/ out $csinput"
|
||||
%typemap(in) int* readLen, int* writeLen %{/*in*/ $1 = ($1_ltype)$input; %}
|
||||
%typemap(out) int* readLen, int* writeLen %{/*out*/ $result = (void *)$1; %}
|
||||
%typemap(csdirectorin) int* readLen, int* writeLen "/*csdirectorin*/ out $iminput"
|
||||
%typemap(csdirectorout) int* readLen, int* writeLen "/*csdirectorout*/ $cscall"
|
||||
%typemap(directorin) int* readLen, int* writeLen "/*directorin*/ $input = $1;"
|
||||
%typemap(directorout) int* readLen, int* writeLen %{/*directorout*/ $result = ($1_ltype)$input; %}
|
||||
|
||||
%inline %{
|
||||
class InStream
|
||||
{
|
||||
public:
|
||||
virtual int Read(void* buf, int len, int* readLen) = 0;
|
||||
virtual int Write(void* buf, int len, int* writeLen) = 0;
|
||||
virtual ~InStream() {}
|
||||
};
|
||||
int callRead(InStream* stream, void* buf, int len, int* readLen) {
|
||||
return stream->Read(buf, len, readLen);
|
||||
}
|
||||
int callWrite(InStream* stream, void* buf, int len, int* writeLen) {
|
||||
return stream->Write(buf, len, writeLen);
|
||||
}
|
||||
%}
|
|
@ -4064,11 +4064,10 @@ public:
|
|||
/* Get the C# parameter type */
|
||||
if ((tm = Getattr(p, "tmap:cstype"))) {
|
||||
substituteClassname(pt, tm);
|
||||
if (Strncmp(tm, "ref ", 4) == 0) {
|
||||
Replace(tm, "ref ", "", DOH_REPLACE_FIRST);
|
||||
int flags = DOH_REPLACE_FIRST | DOH_REPLACE_ID_BEGIN;
|
||||
if (Replace(tm, "ref ", "", flags) || Replace(tm, "ref\t", "", flags)) {
|
||||
Printf(proxy_method_types, "typeof(%s).MakeByRefType()", tm);
|
||||
} else if (Strncmp(tm, "out ", 4) == 0) {
|
||||
Replace(tm, "out ", "", DOH_REPLACE_FIRST);
|
||||
} else if (Replace(tm, "out ", "", flags) || Replace(tm, "out\t", "", flags)) {
|
||||
Printf(proxy_method_types, "typeof(%s).MakeByRefType()", tm);
|
||||
} else {
|
||||
Printf(proxy_method_types, "typeof(%s)", tm);
|
||||
|
|
Loading…
Reference in New Issue