mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2024-09-09 00:13:20 +02:00
2008-02-29 Mike Kestner <mkestner@novell.com>
* generator/ReturnValue.cs: null-term array handling. * glib/Marshaller.cs: marshaling methods for null-term arrays. svn path=/trunk/gtk-sharp/; revision=97032
This commit is contained in:
parent
ada526a153
commit
be28ed3597
@ -1,3 +1,8 @@
|
|||||||
|
2008-02-29 Mike Kestner <mkestner@novell.com>
|
||||||
|
|
||||||
|
* generator/ReturnValue.cs: null-term array handling.
|
||||||
|
* glib/Marshaller.cs: marshaling methods for null-term arrays.
|
||||||
|
|
||||||
2008-02-29 Mike Kestner <mkestner@novell.com>
|
2008-02-29 Mike Kestner <mkestner@novell.com>
|
||||||
|
|
||||||
* sample/Action.cs: qualify Action usage.
|
* sample/Action.cs: qualify Action usage.
|
||||||
|
@ -373,5 +373,54 @@
|
|||||||
<remarks />
|
<remarks />
|
||||||
</Docs>
|
</Docs>
|
||||||
</Member>
|
</Member>
|
||||||
|
<Member MemberName="Malloc">
|
||||||
|
<MemberSignature Language="C#" Value="public static IntPtr Malloc (ulong size);" />
|
||||||
|
<MemberType>Method</MemberType>
|
||||||
|
<ReturnValue>
|
||||||
|
<ReturnType>System.IntPtr</ReturnType>
|
||||||
|
</ReturnValue>
|
||||||
|
<Parameters>
|
||||||
|
<Parameter Name="size" Type="System.UInt64" />
|
||||||
|
</Parameters>
|
||||||
|
<Docs>
|
||||||
|
<param name="size">Size in bytes to be allocated.</param>
|
||||||
|
<summary>Allocates a block of heap memory using the glib allocator.</summary>
|
||||||
|
<returns>A pointer to the block.</returns>
|
||||||
|
<remarks />
|
||||||
|
</Docs>
|
||||||
|
</Member>
|
||||||
|
<Member MemberName="NullTermPtrToStringArray">
|
||||||
|
<MemberSignature Language="C#" Value="public static string[] NullTermPtrToStringArray (IntPtr null_term_array, bool owned);" />
|
||||||
|
<MemberType>Method</MemberType>
|
||||||
|
<ReturnValue>
|
||||||
|
<ReturnType>System.String[]</ReturnType>
|
||||||
|
</ReturnValue>
|
||||||
|
<Parameters>
|
||||||
|
<Parameter Name="null_term_array" Type="System.IntPtr" />
|
||||||
|
<Parameter Name="owned" Type="System.Boolean" />
|
||||||
|
</Parameters>
|
||||||
|
<Docs>
|
||||||
|
<param name="null_term_array">Pointer to a null-terminated string array.</param>
|
||||||
|
<param name="owned">Indicates if the memory is owned and should be released.</param>
|
||||||
|
<summary>Marshals a native null-terminated string array to a managed string array.</summary>
|
||||||
|
<returns>an array of managed strings.</returns>
|
||||||
|
<remarks />
|
||||||
|
</Docs>
|
||||||
|
</Member>
|
||||||
|
<Member MemberName="StrFreeV">
|
||||||
|
<MemberSignature Language="C#" Value="public static void StrFreeV (IntPtr null_term_array);" />
|
||||||
|
<MemberType>Method</MemberType>
|
||||||
|
<ReturnValue>
|
||||||
|
<ReturnType>System.Void</ReturnType>
|
||||||
|
</ReturnValue>
|
||||||
|
<Parameters>
|
||||||
|
<Parameter Name="null_term_array" Type="System.IntPtr" />
|
||||||
|
</Parameters>
|
||||||
|
<Docs>
|
||||||
|
<param name="null_term_array">Pointer to a native null-terminated string array.</param>
|
||||||
|
<summary>Frees a string array, including its member strings.</summary>
|
||||||
|
<remarks />
|
||||||
|
</Docs>
|
||||||
|
</Member>
|
||||||
</Members>
|
</Members>
|
||||||
</Type>
|
</Type>
|
||||||
|
@ -28,15 +28,29 @@ namespace GtkSharp.Generation {
|
|||||||
|
|
||||||
|
|
||||||
private XmlElement elem;
|
private XmlElement elem;
|
||||||
|
bool is_null_term;
|
||||||
|
bool is_array;
|
||||||
|
bool elements_owned;
|
||||||
|
bool owned;
|
||||||
|
string ctype = String.Empty;
|
||||||
|
string element_ctype = String.Empty;
|
||||||
|
|
||||||
public ReturnValue (XmlElement elem)
|
public ReturnValue (XmlElement elem)
|
||||||
{
|
{
|
||||||
this.elem = elem;
|
this.elem = elem;
|
||||||
|
if (elem != null) {
|
||||||
|
is_null_term = elem.HasAttribute ("null_term_array");
|
||||||
|
is_array = elem.HasAttribute ("array");
|
||||||
|
elements_owned = elem.GetAttribute ("elements_owned") == "true";
|
||||||
|
owned = elem.GetAttribute ("owned") == "true";
|
||||||
|
ctype = elem.GetAttribute("type");
|
||||||
|
element_ctype = elem.GetAttribute ("element_type");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string CType {
|
public string CType {
|
||||||
get {
|
get {
|
||||||
return elem == null ? String.Empty : elem.GetAttribute("type");
|
return ctype;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +62,7 @@ namespace GtkSharp.Generation {
|
|||||||
if (ElementType != String.Empty)
|
if (ElementType != String.Empty)
|
||||||
return ElementType + "[]";
|
return ElementType + "[]";
|
||||||
|
|
||||||
return IGen.QualifiedName + (IsArray ? "[]" : String.Empty);
|
return IGen.QualifiedName + (is_array || is_null_term ? "[]" : String.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,28 +74,10 @@ namespace GtkSharp.Generation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string ElementCType {
|
|
||||||
get {
|
|
||||||
if (elem != null && elem.HasAttribute ("element_type"))
|
|
||||||
return elem.GetAttribute ("element_type");
|
|
||||||
|
|
||||||
return String.Empty;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ElementsOwned {
|
|
||||||
get {
|
|
||||||
if (elem != null && elem.GetAttribute ("elements_owned") == "true")
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
string ElementType {
|
string ElementType {
|
||||||
get {
|
get {
|
||||||
if (ElementCType.Length > 0)
|
if (element_ctype.Length > 0)
|
||||||
return SymbolTable.Table.GetCSType (ElementCType);
|
return SymbolTable.Table.GetCSType (element_ctype);
|
||||||
|
|
||||||
return String.Empty;
|
return String.Empty;
|
||||||
}
|
}
|
||||||
@ -96,12 +92,6 @@ namespace GtkSharp.Generation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsArray {
|
|
||||||
get {
|
|
||||||
return elem == null ? false : elem.HasAttribute ("array");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsVoid {
|
public bool IsVoid {
|
||||||
get {
|
get {
|
||||||
return CSType == "void";
|
return CSType == "void";
|
||||||
@ -112,13 +102,9 @@ namespace GtkSharp.Generation {
|
|||||||
get {
|
get {
|
||||||
if (IGen == null)
|
if (IGen == null)
|
||||||
return String.Empty;
|
return String.Empty;
|
||||||
return IGen.MarshalReturnType + (IsArray ? "[]" : String.Empty);
|
else if (is_null_term)
|
||||||
}
|
return "IntPtr";
|
||||||
}
|
return IGen.MarshalReturnType + (is_array ? "[]" : String.Empty);
|
||||||
|
|
||||||
bool Owned {
|
|
||||||
get {
|
|
||||||
return elem.GetAttribute ("owned") == "true";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +112,9 @@ namespace GtkSharp.Generation {
|
|||||||
get {
|
get {
|
||||||
if (IGen == null)
|
if (IGen == null)
|
||||||
return String.Empty;
|
return String.Empty;
|
||||||
return IGen.ToNativeReturnType + (IsArray ? "[]" : String.Empty);
|
else if (is_null_term)
|
||||||
|
return "IntPtr"; //FIXME
|
||||||
|
return IGen.ToNativeReturnType + (is_array ? "[]" : String.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,10 +125,12 @@ namespace GtkSharp.Generation {
|
|||||||
|
|
||||||
if (ElementType != String.Empty) {
|
if (ElementType != String.Empty) {
|
||||||
string type_str = "typeof (" + ElementType + ")";
|
string type_str = "typeof (" + ElementType + ")";
|
||||||
string args = type_str + ", " + (Owned ? "true" : "false") + ", " + (ElementsOwned ? "true" : "false");
|
string args = type_str + ", " + (owned ? "true" : "false") + ", " + (elements_owned ? "true" : "false");
|
||||||
return String.Format ("({0}[]) GLib.Marshaller.ListToArray ({1}, {2})", ElementType, IGen.FromNativeReturn (var + ", " + args), type_str);
|
return String.Format ("({0}[]) GLib.Marshaller.ListToArray ({1}, {2})", ElementType, IGen.FromNativeReturn (var + ", " + args), type_str);
|
||||||
} else if (IGen is HandleBase)
|
} else if (IGen is HandleBase)
|
||||||
return ((HandleBase)IGen).FromNative (var, Owned);
|
return ((HandleBase)IGen).FromNative (var, owned);
|
||||||
|
else if (is_null_term)
|
||||||
|
return String.Format ("GLib.Marshaller.NullTermPtrToStringArray ({0}, {1})", var, owned ? "true" : "false");
|
||||||
else
|
else
|
||||||
return IGen.FromNativeReturn (var);
|
return IGen.FromNativeReturn (var);
|
||||||
}
|
}
|
||||||
@ -151,9 +141,10 @@ namespace GtkSharp.Generation {
|
|||||||
return String.Empty;
|
return String.Empty;
|
||||||
|
|
||||||
if (ElementType.Length > 0) {
|
if (ElementType.Length > 0) {
|
||||||
string args = ", typeof (" + ElementType + "), " + (Owned ? "true" : "false") + ", " + (ElementsOwned ? "true" : "false");
|
string args = ", typeof (" + ElementType + "), " + (owned ? "true" : "false") + ", " + (elements_owned ? "true" : "false");
|
||||||
var = "new " + IGen.QualifiedName + "(" + var + args + ")";
|
var = "new " + IGen.QualifiedName + "(" + var + args + ")";
|
||||||
}
|
} else if (is_null_term)
|
||||||
|
return String.Format ("GLib.Marshaller.StringArrayToNullTermPtr ({0})", var);
|
||||||
|
|
||||||
if (IGen is IManualMarshaler)
|
if (IGen is IManualMarshaler)
|
||||||
return (IGen as IManualMarshaler).AllocNative (var);
|
return (IGen as IManualMarshaler).AllocNative (var);
|
||||||
|
@ -150,6 +150,33 @@ namespace GLib {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[DllImport("libglib-2.0-0.dll")]
|
||||||
|
static extern void g_strfreev (IntPtr mem);
|
||||||
|
|
||||||
|
public static void StrFreeV (IntPtr null_term_array)
|
||||||
|
{
|
||||||
|
g_strfreev (null_term_array);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (Utf8PtrToString (s));
|
||||||
|
s = Marshal.ReadIntPtr (null_term_array, count++ * IntPtr.Size);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (owned)
|
||||||
|
g_strfreev (null_term_array);
|
||||||
|
|
||||||
|
return (string[]) result.ToArray (typeof(string));
|
||||||
|
}
|
||||||
|
|
||||||
public static string[] PtrToStringArrayGFree (IntPtr string_array)
|
public static string[] PtrToStringArrayGFree (IntPtr string_array)
|
||||||
{
|
{
|
||||||
if (string_array == IntPtr.Zero)
|
if (string_array == IntPtr.Zero)
|
||||||
@ -180,6 +207,11 @@ namespace GLib {
|
|||||||
[DllImport("libglib-2.0-0.dll")]
|
[DllImport("libglib-2.0-0.dll")]
|
||||||
static extern IntPtr g_malloc(UIntPtr size);
|
static extern IntPtr g_malloc(UIntPtr size);
|
||||||
|
|
||||||
|
public static IntPtr Malloc (ulong size)
|
||||||
|
{
|
||||||
|
return g_malloc (new UIntPtr (size));
|
||||||
|
}
|
||||||
|
|
||||||
static bool check_sixtyfour () {
|
static bool check_sixtyfour () {
|
||||||
int szint = Marshal.SizeOf (typeof (int));
|
int szint = Marshal.SizeOf (typeof (int));
|
||||||
int szlong = Marshal.SizeOf (typeof (long));
|
int szlong = Marshal.SizeOf (typeof (long));
|
||||||
|
Loading…
Reference in New Issue
Block a user