mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-30 12:10:37 +00:00
Fix marshalling of null terminated string arrays as return values
This commit is contained in:
parent
aba607129c
commit
6ab410403c
4 changed files with 53 additions and 4 deletions
|
@ -110,7 +110,9 @@ namespace GtkSharp.Generation {
|
|||
get {
|
||||
if (IGen == null)
|
||||
return String.Empty;
|
||||
return IGen.ToNativeReturnType + (is_array || is_null_term ? "[]" : String.Empty);
|
||||
else if (is_null_term)
|
||||
return "IntPtr";
|
||||
return IGen.ToNativeReturnType + (is_array ? "[]" : String.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,7 +130,7 @@ namespace GtkSharp.Generation {
|
|||
} else if (IGen is HandleBase)
|
||||
return ((HandleBase)IGen).FromNative (var, owned);
|
||||
else if (is_null_term)
|
||||
return String.Format ("GLib.Marshaller.NullTermPtrToStringArray ({0}, {1})", var, owned ? "true" : "false");
|
||||
return String.Format ("Gst.Marshaller.NullTermPtrToStringArray ({0}, {1})", var, owned ? "true" : "false");
|
||||
else
|
||||
return IGen.FromNativeReturn (var);
|
||||
}
|
||||
|
@ -142,7 +144,7 @@ namespace GtkSharp.Generation {
|
|||
string args = ", typeof (" + ElementType + "), " + (owned ? "true" : "false") + ", " + (elements_owned ? "true" : "false");
|
||||
var = "new " + IGen.QualifiedName + "(" + var + args + ")";
|
||||
} else if (is_null_term)
|
||||
return String.Format ("GLib.Marshaller.StringArrayToNullTermPointer ({0})", var);
|
||||
return String.Format ("Gst.Marshaller.StringArrayToNullTermPointer ({0})", var);
|
||||
|
||||
if (IGen is IManualMarshaler)
|
||||
return (IGen as IManualMarshaler).AllocNative (var);
|
||||
|
|
|
@ -239,7 +239,7 @@ namespace Gst {
|
|||
query = new SignalQuery ();
|
||||
|
||||
query.signal_id = signal_id;
|
||||
query.signal_name = Marshaller.Utf8PtrToString (q.signal_name);
|
||||
query.signal_name = GLib.Marshaller.Utf8PtrToString (q.signal_name);
|
||||
query.itype = new GType (q.itype);
|
||||
query.signal_flags = q.signal_flags;
|
||||
query.return_type = new GType (q.return_type);
|
||||
|
|
|
@ -48,6 +48,7 @@ sources = \
|
|||
EnumInfo.cs \
|
||||
Iterator.cs \
|
||||
MiniObject.cs \
|
||||
Marshaller.cs \
|
||||
GstSharp.PadQueryTypeFunctionNative.cs \
|
||||
PadQueryTypeFunction.cs \
|
||||
TypeFindDelegates.cs \
|
||||
|
|
46
gstreamer-sharp/Marshaller.cs
Normal file
46
gstreamer-sharp/Marshaller.cs
Normal file
|
@ -0,0 +1,46 @@
|
|||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using GLib;
|
||||
|
||||
namespace Gst {
|
||||
public static class Marshaller {
|
||||
|
||||
public static IntPtr StringArrayToNullTermPointer (string[] strs)
|
||||
{
|
||||
if (strs == null)
|
||||
return IntPtr.Zero;
|
||||
|
||||
IntPtr result = GLib.Marshaller.Malloc ((ulong) ((strs.Length + 1) * IntPtr.Size));
|
||||
|
||||
for (int i = 0; i < strs.Length; i++)
|
||||
Marshal.WriteIntPtr (result, i * IntPtr.Size, GLib.Marshaller.StringToPtrGStrdup (strs [i]));
|
||||
|
||||
Marshal.WriteIntPtr (result, strs.Length * IntPtr.Size, IntPtr.Zero);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[DllImport("libglib-2.0-0.dll")]
|
||||
static extern void g_strfreev (IntPtr mem);
|
||||
|
||||
public static string[] NullTermPtrToStringArray (IntPtr null_term_array, bool owned)
|
||||
{
|
||||
if (null_term_array == IntPtr.Zero)
|
||||
return new string [0];
|
||||
|
||||
int count = 0;
|
||||
System.Collections.ArrayList result = new System.Collections.ArrayList ();
|
||||
IntPtr s = Marshal.ReadIntPtr (null_term_array, count++ * IntPtr.Size);
|
||||
while (s != IntPtr.Zero) {
|
||||
result.Add (GLib.Marshaller.Utf8PtrToString (s));
|
||||
s = Marshal.ReadIntPtr (null_term_array, count++ * IntPtr.Size);
|
||||
}
|
||||
|
||||
if (owned)
|
||||
g_strfreev (null_term_array);
|
||||
|
||||
return (string[]) result.ToArray (typeof(string));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue