Author: mkestner
Date: 2005-03-04 13:59:09 -0500 (Fri, 04 Mar 2005)
New Revision: 41459

Removed:
   trunk/gtk-sharp/generator/StringGen.cs
Modified:
   trunk/gtk-sharp/ChangeLog
   trunk/gtk-sharp/generator/ImportSignature.cs
   trunk/gtk-sharp/generator/Makefile.am
   trunk/gtk-sharp/generator/MethodBody.cs
   trunk/gtk-sharp/generator/SymbolTable.cs
   trunk/gtk-sharp/glib/Marshaller.cs
   trunk/gtk-sharp/gtk/Gtk.metadata
Log:

2005-03-04  Mike Kestner  <[EMAIL PROTECTED]>

        * generator/ImportSignature.cs : out param handling fix.
        * generator/Makefile.am : kill StringGen.cs.
        * generator/MethodBody.cs : simplify out param handling.
        * generator/StringGen.cs : kill it, now using MarshalGen.
        * generator/SymbolTable.cs : make non-const strings use an appropriate
        MarshalGen.  Non-const strings are now correctly marshaled as Utf8.
        * glib/Marshaller.cs : add some utf8-fu for strdup/free marshaling.
        Add a method to alloc/copy structs to native memory, unused yet.
        * gtk/Gtk.metadata : partially fix a broken delegate.


Modified: trunk/gtk-sharp/ChangeLog
===================================================================
--- trunk/gtk-sharp/ChangeLog   2005-03-04 18:13:03 UTC (rev 41458)
+++ trunk/gtk-sharp/ChangeLog   2005-03-04 18:59:09 UTC (rev 41459)
@@ -1,5 +1,17 @@
 2005-03-04  Mike Kestner  <[EMAIL PROTECTED]>
 
+       * generator/ImportSignature.cs : out param handling fix.
+       * generator/Makefile.am : kill StringGen.cs.
+       * generator/MethodBody.cs : simplify out param handling.
+       * generator/StringGen.cs : kill it, now using MarshalGen.
+       * generator/SymbolTable.cs : make non-const strings use an appropriate
+       MarshalGen.  Non-const strings are now correctly marshaled as Utf8.
+       * glib/Marshaller.cs : add some utf8-fu for strdup/free marshaling.
+       Add a method to alloc/copy structs to native memory, unused yet.
+       * gtk/Gtk.metadata : partially fix a broken delegate.
+
+2005-03-04  Mike Kestner  <[EMAIL PROTECTED]>
+
        * generator/Method.cs : refactor out some retval logic.
        * generator/ReturnValue.cs : add FromNative and IsVoid members.
 

Modified: trunk/gtk-sharp/generator/ImportSignature.cs
===================================================================
--- trunk/gtk-sharp/generator/ImportSignature.cs        2005-03-04 18:13:03 UTC 
(rev 41458)
+++ trunk/gtk-sharp/generator/ImportSignature.cs        2005-03-04 18:59:09 UTC 
(rev 41459)
@@ -56,7 +56,7 @@
                                parms [i] = "";
                                if (p.CType == "GError**")
                                        parms [i] += "out ";
-                               else if (p.PassAs != "" && (!m_type.EndsWith 
("IntPtr") || p.Generatable is LPGen || p.Generatable is LPUGen || UsesHandle 
(p.Generatable)))
+                               else if (p.PassAs != "")
                                        parms [i] += p.PassAs + " ";
                                parms [i] += m_type + " " + p.Name;
                        }

Modified: trunk/gtk-sharp/generator/Makefile.am
===================================================================
--- trunk/gtk-sharp/generator/Makefile.am       2005-03-04 18:13:03 UTC (rev 
41458)
+++ trunk/gtk-sharp/generator/Makefile.am       2005-03-04 18:59:09 UTC (rev 
41459)
@@ -43,7 +43,6 @@
        SimpleBase.cs                   \
        SimpleGen.cs                    \
        Statistics.cs                   \
-       StringGen.cs                    \
        StructBase.cs                   \
        StructGen.cs                    \
        SymbolTable.cs                  \

Modified: trunk/gtk-sharp/generator/MethodBody.cs
===================================================================
--- trunk/gtk-sharp/generator/MethodBody.cs     2005-03-04 18:13:03 UTC (rev 
41458)
+++ trunk/gtk-sharp/generator/MethodBody.cs     2005-03-04 18:59:09 UTC (rev 
41459)
@@ -86,16 +86,10 @@
                                if (p.CType == "GError**") {
                                        result [i] += "out ";                   
        
                                } else if (p.PassAs != "") {
-                                       if (p.Generatable is LPGen || 
p.Generatable is LPUGen || !p.MarshalType.EndsWith ("IntPtr")) 
-                                               result [i] += p.PassAs + " ";
-                                       
-                                       if (igen is EnumGen)
-                                               call_parm = p.Name + "_as_int";
-                                       else if (igen is LPUGen || igen is 
LPGen)
-                                               call_parm = p.Name + "_as_ptr";
-                                       else if (UsesHandle (igen)) {
-                                               call_parm = p.PassAs + " " + 
p.Name + "_handle";
-                                       }
+                                       result [i] += p.PassAs + " ";
+
+                                       if (p.CSType != p.MarshalType && !(igen 
is StructBase || igen is ByRefGen))
+                                               call_parm = p.Name + 
"_as_native";
                                }
 
                                if (p.CType == "GError**") {
@@ -128,15 +122,9 @@
                                if (is_set)
                                        name = "value";
 
-                               if ((is_get || p.PassAs == "out") && UsesHandle 
(gen))
-                                       sw.WriteLine(indent + "\t\t\tIntPtr " + 
name + "_handle;");
+                               if ((is_get || p.PassAs == "out") && p.CSType 
!= p.MarshalType && !(gen is StructBase || gen is ByRefGen))
+                                       sw.WriteLine(indent + "\t\t\t" + 
gen.MarshalType + " " + name + "_as_native;");
 
-                               if (p.PassAs == "out" && gen is EnumGen)
-                                       sw.WriteLine(indent + "\t\t\tint " + 
name + "_as_int;");
-
-                               if (p.PassAs == "out" && (gen is LPGen || gen 
is LPUGen))
-                                       sw.WriteLine(indent + "\t\t\t" + 
gen.MarshalType + " " + name + "_as_ptr;");
-
                                if (p.IsArray && p.MarshalType != p.CSType) {
                                        sw.WriteLine(indent + "\t\t\t{0}[] 
native_{1} = new {0} [{1}.Length];", p.MarshalType.TrimEnd('[', ']'), name);
                                        sw.WriteLine(indent + "\t\t\tfor (int i 
= 0; i < {0}.Length; i++)", name);
@@ -170,14 +158,9 @@
 
                                IGeneratable gen = p.Generatable;
 
-                               if (p.PassAs == "out" && gen is EnumGen)
-                                       sw.WriteLine(indent + "\t\t\t" + p.Name 
+ " = (" + p.CSType + ") " + p.Name + "_as_int;");
-
-                               if (p.PassAs == "out" && (gen is LPGen || gen 
is LPUGen))
-                                       sw.WriteLine(indent + "\t\t\t" + p.Name 
+ " = (" + p.CSType + ") " + p.Name + "_as_ptr;");
-
-                               if (p.PassAs == "out" && UsesHandle (gen))
-                                       sw.WriteLine(indent + "\t\t\t" + p.Name 
+ " = " + gen.FromNativeReturn (p.Name + "_handle") + ";");
+                               string name = p.Name;
+                               if (p.PassAs == "out" && p.CSType != 
p.MarshalType && !(gen is StructBase || gen is ByRefGen))
+                                       sw.WriteLine(indent + "\t\t\t" + p.Name 
+ " = " + gen.FromNative (p.Name + "_as_native") + ";");
                        }
                }
 

Deleted: trunk/gtk-sharp/generator/StringGen.cs
===================================================================
--- trunk/gtk-sharp/generator/StringGen.cs      2005-03-04 18:13:03 UTC (rev 
41458)
+++ trunk/gtk-sharp/generator/StringGen.cs      2005-03-04 18:59:09 UTC (rev 
41459)
@@ -1,51 +0,0 @@
-// GtkSharp.Generation.StringGen.cs - The String type Generatable.
-//
-// Author: Rachel Hestilow <[EMAIL PROTECTED]>
-//         Mike Kestner  <[EMAIL PROTECTED]>
-//
-// Copyright (c) 2003 Rachel Hestilow
-// Copyright (c) 2004 Novell, Inc.
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of version 2 of the GNU General Public
-// License as published by the Free Software Foundation.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public
-// License along with this program; if not, write to the
-// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-// Boston, MA 02111-1307, USA.
-
-
-namespace GtkSharp.Generation {
-
-       using System;
-
-       public class StringGen : ConstStringGen {
-
-               public StringGen (string ctype) : base (ctype)
-               {
-               }
-       
-               public override string ToNativeReturnType {
-                       get {
-                               return "IntPtr";
-                       }
-               }
-
-               public override string FromNativeReturn(String var)
-               {
-                       return "GLib.Marshaller.PtrToStringGFree(" + var + ")";
-               }
-
-               public override string ToNativeReturn(String var)
-               {
-                       return "GLib.Marshaller.StringToPtrGStrdup(" + var + 
")";
-               }
-       }
-}
-

Modified: trunk/gtk-sharp/generator/SymbolTable.cs
===================================================================
--- trunk/gtk-sharp/generator/SymbolTable.cs    2005-03-04 18:13:03 UTC (rev 
41458)
+++ trunk/gtk-sharp/generator/SymbolTable.cs    2005-03-04 18:59:09 UTC (rev 
41459)
@@ -1,9 +1,9 @@
 // GtkSharp.Generation.SymbolTable.cs - The Symbol Table Class.
 //
-// Author: Mike Kestner <[EMAIL PROTECTED]>
+// Author: Mike Kestner <[EMAIL PROTECTED]>
 //
 // Copyright (c) 2001-2003 Mike Kestner
-// Copyright (c) 2004 Novell, Inc.
+// Copyright (c) 2004-2005 Novell, Inc.
 //
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of version 2 of the GNU General Public
@@ -90,8 +90,8 @@
                        AddType (new ConstStringGen ("const-gchar"));
                        AddType (new ConstStringGen ("const-xmlChar"));
                        AddType (new ConstStringGen ("const-char"));
-                       AddType (new StringGen ("gchar"));
-                       AddType (new StringGen ("char"));
+                       AddType (new MarshalGen ("gchar", "string", "IntPtr", 
"GLib.Marshaller.StringToPtrGStrdup({0})", 
"GLib.Marshaller.PtrToStringGFree({0})"));
+                       AddType (new MarshalGen ("char", "string", "IntPtr", 
"GLib.Marshaller.StringToPtrGStrdup({0})", 
"GLib.Marshaller.PtrToStringGFree({0})"));
 
                        // manually wrapped types requiring more complex 
marshaling
                        AddType (new ManualGen ("GObject", "GLib.Object", 
"GLib.Object.GetObject ({0})"));

Modified: trunk/gtk-sharp/glib/Marshaller.cs
===================================================================
--- trunk/gtk-sharp/glib/Marshaller.cs  2005-03-04 18:13:03 UTC (rev 41458)
+++ trunk/gtk-sharp/glib/Marshaller.cs  2005-03-04 18:59:09 UTC (rev 41459)
@@ -32,8 +32,20 @@
                [DllImport("libglib-2.0-0.dll")]
                static extern void g_free (IntPtr mem);
 
-               public static string PtrToStringGFree (IntPtr ptr) {
-                       string ret = Marshal.PtrToStringAnsi (ptr);
+               [DllImport("libglib-2.0-0.dll")]
+               static extern IntPtr g_utf8_strlen (IntPtr mem, int size);
+
+               public static string Utf8PtrToString (IntPtr ptr) 
+               {
+                       int len = (int) g_utf8_strlen (ptr, -1);
+                       byte[] bytes = new byte [len];
+                       Marshal.Copy (ptr, bytes, 0, len);
+                       return System.Text.Encoding.UTF8.GetString (bytes);
+               }
+
+               public static string PtrToStringGFree (IntPtr ptr) 
+               {
+                       string ret = Utf8PtrToString (ptr);
                        g_free (ptr);
                        return ret;
                }
@@ -45,17 +57,18 @@
                        // The last pointer is a null terminator.
                        string[] ret = new string[ptrs.Length - 1];
                        for (int i = 0; i < ret.Length; i++) {
-                               ret[i] = Marshal.PtrToStringAnsi (ptrs[i]);
+                               ret[i] = Utf8PtrToString (ptrs[i]);
                                g_free (ptrs[i]);
                        }
                        return ret;
                }
 
                [DllImport("libglib-2.0-0.dll")]
-               static extern IntPtr g_strdup (string str);
+               static extern IntPtr g_strdup (byte[] bytes);
 
                public static IntPtr StringToPtrGStrdup (string str) {
-                       return g_strdup (str);
+                       byte[] bytes = System.Text.Encoding.UTF8.GetBytes (str);
+                       return g_strdup (bytes);
                }
 
                public static string StringFormat (string format, params 
object[] args) {
@@ -204,6 +217,12 @@
                        return glibsharp_utf16_to_unichar ((ushort) c);
                }
 
+               public static IntPtr PtrToStructureAlloc (object o)
+               {
+                       IntPtr result = Marshal.AllocHGlobal (Marshal.SizeOf 
(o));
+                       Marshal.StructureToPtr (o, result, false);
+                       return result;
+               }
        }
 }
 

Modified: trunk/gtk-sharp/gtk/Gtk.metadata
===================================================================
--- trunk/gtk-sharp/gtk/Gtk.metadata    2005-03-04 18:13:03 UTC (rev 41458)
+++ trunk/gtk-sharp/gtk/Gtk.metadata    2005-03-04 18:59:09 UTC (rev 41459)
@@ -24,6 +24,7 @@
   <attr path="/api/namespace/[EMAIL PROTECTED]'GtkTextIter']/[EMAIL 
PROTECTED]'GetToggledTags']" name="hidden">1</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GtkTreePath']/[EMAIL 
PROTECTED]'GetIndices']" name="hidden">1</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GtkItemFactoryCallback2']" 
name="hidden">1</attr>
+  <attr path="/api/namespace/[EMAIL PROTECTED]'GtkModuleInitFunc']/*/[EMAIL 
PROTECTED]'argv']" name="array">1</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GtkAccel_']/[EMAIL 
PROTECTED]'GroupsFromObject']" name="hidden">1</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GtkAccelerator_']/[EMAIL 
PROTECTED]'GetDefaultModMask']/return-type" name="type">GdkModifierType</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GtkBindings_']/[EMAIL 
PROTECTED]'Activate']" name="name">BindingsActivate</attr>

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

Reply via email to