Idl Generator - Error in signature for nsIBinaryInputStream.ReadByteArray

Issue #7 resolved
Anonymous created an issue

I discovered this when upgrading my app from the original GeckoFX to GeckoFX-7.0. The auto-generated signature from GeckoFX-7.0 for this method (in nsIBinaryInputStream) is:

byte ReadByteArray(uint aLength)

Ideally, this method would be:

byte[] ReadByteArray(uint aLength)

I don't have much experience dealing with marshalling so I fixed this locally by changing that function to return an IntPtr.

This same issue also affects the matching function, nsIBinaryOutputStream.WriteByteArray

Comments (4)

  1. geckofx repo owner

    idl signature is:

    void readByteArray(in PRUint32 aLength, [array, size_is(aLength), retval] out PRUint8 aBytes);

    so I suspect that my IDL compiler is looking at the type PRUint8 and typing that as a byte. So it seems I need to take notice of the "array" attribute.

    This will take a fix to IDLImp. Thanks for the bug report.

  2. geckofx repo owner

    So I have IDLImp generating the following signature:

    [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] void ReadByteArray(uint aLength, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=0)] ref byte[] aBytes);

    Could you test, to see if it works ok for you?

    Alternatively I could generate:

    [return: MarshalAs(UnmanagedType.LPArray, SizeParamIndex=0)] [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] byte[] ReadByteArray(uint aLength);

    perhaps you could test that as well, to see if it works for you. Thanks

  3. tomlor

    Thanks a bunch for the quick response. Your first function signature works. The 2nd function (which returns byte[]) doesn't work - I get a MarshalDirectiveException ("Cannot marshal 'return value': Invalid managed/unmanaged type combination.")

    (I am seeing an occasional access violation exception in ReadByteArray but I was seeing that using my IntPtr signature so I presume that problem lies elsewhere).

    I also modified the function declaration of nsIBinaryOutputStream.WriteByteArray and that appears to be working:

    [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] void WriteByteArray([MarshalAs(UnmanagedType.LPArray)] byte[] aBytes, uint aLength);


  4. Log in to comment