possible bug in wchar.i (swig 4.0.2) ?

Carlos Frederico Biscaya <[email protected]>
Newsgroups gmane.comp.programming.swig
Message-ID <CANWOLaYjShYGsUqTtdYT1CAgN-nSTZ=OmaFw9Zqs5QtA2Lpnhg@mail.gmail.com>
Hi guys,

I have been trying to create a c# wrapper for a c++ structure that looks
like this:

struct Person {
    const wchar* name;
}

If I include wchar.i in my project file, I get an interface that looks ok.
BUT: When trying to compile, the getter for name will not be compilable
because of code that looks like this:

public string name {
   get {
       string ret = SomethingPINVOKE.Person_name_get(swigCPtr);  // the
return value here is a System.IntPtr
   }
}

assigning a System.IntPtr to a string is not possible and will therefore
not build.

I would suggest adapting the typemap for the getter generation so it looks
like this:

%typemap(csvarout, excode=SWIGEXCODE2) wchar_t * %{
    get {
      string ret =
global::System.Runtime.InteropServices.Marshal.PtrToStringUni($imcall);$excode
      return ret;
    } %}

The typemap for csout already contains the conversion, and maybe I am not
correct in my understanding of the problem here, but as it is right now,
without this change the generated code is unbuildable.

Best regards,
Fred

_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.