Author: mkestner
Date: 2007-11-09 16:06:30 -0500 (Fri, 09 Nov 2007)
New Revision: 89345

Modified:
   trunk/gtk-sharp/ChangeLog
   trunk/gtk-sharp/generator/Parameters.cs
Log:

2007-11-09  Mike Kestner  <[EMAIL PROTECTED]>

        * generator/Parameters.cs: support for null_term_array attribute.


Modified: trunk/gtk-sharp/ChangeLog
===================================================================
--- trunk/gtk-sharp/ChangeLog   2007-11-09 20:16:52 UTC (rev 89344)
+++ trunk/gtk-sharp/ChangeLog   2007-11-09 21:06:30 UTC (rev 89345)
@@ -1,3 +1,7 @@
+2007-11-09  Mike Kestner  <[EMAIL PROTECTED]>
+
+       * generator/Parameters.cs: support for null_term_array attribute.
+
 2007-11-08  Mike Kestner  <[EMAIL PROTECTED]>
 
        * glib/Marshaller.cs: new null-terminated string[] marshaler from

Modified: trunk/gtk-sharp/generator/Parameters.cs
===================================================================
--- trunk/gtk-sharp/generator/Parameters.cs     2007-11-09 20:16:52 UTC (rev 
89344)
+++ trunk/gtk-sharp/generator/Parameters.cs     2007-11-09 21:06:30 UTC (rev 
89345)
@@ -81,7 +81,7 @@
 
                public bool IsArray {
                        get {
-                               return elem.HasAttribute("array");
+                               return elem.HasAttribute("array") || 
elem.HasAttribute("null_term_array");
                        }
                }
 
@@ -311,8 +311,13 @@
 
        public class ArrayParameter : Parameter {
 
-               public ArrayParameter (XmlElement elem) : base (elem) {}
+               bool null_terminated;
 
+               public ArrayParameter (XmlElement elem) : base (elem) 
+               {
+                       null_terminated = elem.HasAttribute ("null_term_array");
+               }
+
                public override string MarshalType {
                        get {
                                if (Generatable is StructBase)
@@ -322,6 +327,12 @@
                        }
                }
 
+               bool NullTerminated {
+                       get {
+                               return null_terminated;
+                       }
+               }
+
                public override string[] Prepare {
                        get {
                                if (CSType == MarshalType)
@@ -329,13 +340,16 @@
 
                                ArrayList result = new ArrayList ();
                                result.Add (String.Format ("int cnt_{0} = {0} 
== null ? 0 : {0}.Length;", CallName));
-                               result.Add (String.Format ("{0}[] native_{1} = 
new {0} [cnt_{1}];", MarshalType.TrimEnd('[', ']'), CallName));
+                               result.Add (String.Format ("{0}[] native_{1} = 
new {0} [cnt_{1}" + (NullTerminated ? " + 1" : "") + "];", 
MarshalType.TrimEnd('[', ']'), CallName));
                                result.Add (String.Format ("for (int i = 0; i < 
cnt_{0}; i++)", CallName));
                                IGeneratable gen = Generatable;
                                if (gen is IManualMarshaler)
                                        result.Add (String.Format 
("\tnative_{0} [i] = {1};", CallName, (gen as IManualMarshaler).AllocNative 
(CallName + "[i]")));
                                else
                                        result.Add (String.Format 
("\tnative_{0} [i] = {1};", CallName, gen.CallByName (CallName + "[i]")));
+
+                               if (NullTerminated)
+                                       result.Add (String.Format ("native_{0} 
[cnt_{0} + 1] = IntPtr.Zero;", CallName));
                                return (string[]) result.ToArray (typeof 
(string));
                        }
                }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to