From f3a997ca6fcff772c0c3e20502c4d741a2e7aad3 Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Tue, 26 Mar 2002 01:29:43 +0000 Subject: [PATCH] 2002-03-25 Mike Kestner * generator/StructBase.cs : Throttle _gtk methods. * generator/SymbolTable.cs : tweak dll names. * glib/Object.cs : restructure DllImports and prop code. * glib/SList.cs : restructure DllImports. * glib/Value.cs : restructure DllImports. * gtk/Application.cs : overload Init() to get past the string[] marshaling crash on linux. * sample/HelloWorld.cs : Use App::Init() since no args are needed. svn path=/trunk/gtk-sharp/; revision=3341 --- ChangeLog | 11 +++ generator/StructBase.cs | 5 ++ generator/SymbolTable.cs | 8 +- glib/Object.cs | 155 +++++++++++++-------------------------- glib/SList.cs | 4 +- glib/Value.cs | 18 ++--- gtk/Application.cs | 14 +++- sample/HelloWorld.cs | 2 +- 8 files changed, 96 insertions(+), 121 deletions(-) diff --git a/ChangeLog b/ChangeLog index f5417991f..39c0006af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2002-03-25 Mike Kestner + + * generator/StructBase.cs : Throttle _gtk methods. + * generator/SymbolTable.cs : tweak dll names. + * glib/Object.cs : restructure DllImports and prop code. + * glib/SList.cs : restructure DllImports. + * glib/Value.cs : restructure DllImports. + * gtk/Application.cs : overload Init() to get past the string[] + marshaling crash on linux. + * sample/HelloWorld.cs : Use App::Init() since no args are needed. + 2002-03-24 Mike Kestner * generator/*Gen.cs : Use Path.DirectorySeparatorChar. diff --git a/generator/StructBase.cs b/generator/StructBase.cs index 65c35ab42..e6913d7f6 100644 --- a/generator/StructBase.cs +++ b/generator/StructBase.cs @@ -173,6 +173,11 @@ namespace GtkSharp.Generation { String cname = method.GetAttribute("cname"); String name = method.GetAttribute("name"); + if (cname[0] == '_') { + Statistics.ThrottledCount++; + return true; + } + sw.WriteLine("\t\t[DllImport(\"" + table.GetDllName(ns) + "\", CallingConvention=CallingConvention.Cdecl)]"); sw.Write("\t\tstatic extern " + m_ret + " " + cname + isig); diff --git a/generator/SymbolTable.cs b/generator/SymbolTable.cs index 3fa268b2a..a268de347 100644 --- a/generator/SymbolTable.cs +++ b/generator/SymbolTable.cs @@ -66,10 +66,10 @@ namespace GtkSharp.Generation { simple_types.Add ("GParamSpec", "IntPtr"); dlls = new Hashtable(); - dlls.Add("Pango", "pango.dll"); - dlls.Add("Atk", "atk.dll"); - dlls.Add("Gdk", "gdk-x11-1.3.dll"); - dlls.Add("Gtk", "gtk-x11-1.3.dll"); + dlls.Add("Pango", "pango"); + dlls.Add("Atk", "atk"); + dlls.Add("Gdk", "gdk-x11-1.3"); + dlls.Add("Gtk", "gtk-x11-1.3"); } public void AddType (IGeneratable gen) diff --git a/glib/Object.cs b/glib/Object.cs index 8013c8c27..ed8ec8952 100644 --- a/glib/Object.cs +++ b/glib/Object.cs @@ -197,18 +197,13 @@ namespace GLib { /// Accesses a string Property. /// - [DllImport("gobject-1.3.dll", CharSet=CharSet.Ansi, - CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_get (IntPtr obj, IntPtr name, - out IntPtr val, IntPtr term); + [DllImport("gobject-1.3", CallingConvention=CallingConvention.Cdecl)] + static extern void g_object_get (IntPtr obj, string name, + out string val, IntPtr term); public void GetProperty (String name, out String val) { - IntPtr propval; - g_object_get (Raw, - Marshal.StringToHGlobalAnsi (name), - out propval, new IntPtr (0)); - val = Marshal.PtrToStringAnsi (propval); + g_object_get (Raw, name, out val, new IntPtr (0)); } /// @@ -219,16 +214,13 @@ namespace GLib { /// Accesses a boolean Property. /// - [DllImport("gobject-1.3.dll", CharSet=CharSet.Ansi, - CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_get (IntPtr obj, IntPtr name, + [DllImport("gobject-1.3", CallingConvention=CallingConvention.Cdecl)] + static extern void g_object_get (IntPtr obj, string name, out bool val, IntPtr term); public void GetProperty (String name, out bool val) { - g_object_get (Raw, - Marshal.StringToHGlobalAnsi (name), - out val, new IntPtr (0)); + g_object_get (Raw, name, out val, new IntPtr (0)); } /// @@ -239,16 +231,13 @@ namespace GLib { /// Accesses a double Property. /// - [DllImport("gobject-1.3.dll", CharSet=CharSet.Ansi, - CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_get (IntPtr obj, IntPtr name, + [DllImport("gobject-1.3", CallingConvention=CallingConvention.Cdecl)] + static extern void g_object_get (IntPtr obj, string name, out double val, IntPtr term); public void GetProperty (String name, out double val) { - g_object_get (Raw, - Marshal.StringToHGlobalAnsi (name), - out val, new IntPtr (0)); + g_object_get (Raw, name, out val, new IntPtr (0)); } /// @@ -259,16 +248,13 @@ namespace GLib { /// Accesses a float Property. /// - [DllImport("gobject-1.3.dll", CharSet=CharSet.Ansi, - CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_get (IntPtr obj, IntPtr name, + [DllImport("gobject-1.3", CallingConvention=CallingConvention.Cdecl)] + static extern void g_object_get (IntPtr obj, string name, out float val, IntPtr term); public void GetProperty (String name, out float val) { - g_object_get (Raw, - Marshal.StringToHGlobalAnsi (name), - out val, new IntPtr (0)); + g_object_get (Raw, name, out val, new IntPtr (0)); } /// @@ -279,16 +265,13 @@ namespace GLib { /// Accesses an integer Property. /// - [DllImport("gobject-1.3.dll", CharSet=CharSet.Ansi, - CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_get (IntPtr obj, IntPtr name, + [DllImport("gobject-1.3", CallingConvention=CallingConvention.Cdecl)] + static extern void g_object_get (IntPtr obj, string name, out int val, IntPtr term); public void GetProperty (String name, out int val) { - g_object_get (Raw, - Marshal.StringToHGlobalAnsi (name), - out val, new IntPtr (0)); + g_object_get (Raw, name, out val, new IntPtr (0)); } /// @@ -299,16 +282,13 @@ namespace GLib { /// Accesses an unsigned integer Property. /// - [DllImport("gobject-1.3.dll", CharSet=CharSet.Ansi, - CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_get (IntPtr obj, IntPtr name, + [DllImport("gobject-1.3", CallingConvention=CallingConvention.Cdecl)] + static extern void g_object_get (IntPtr obj, string name, out uint val, IntPtr term); public void GetProperty (String name, out uint val) { - g_object_get (Raw, - Marshal.StringToHGlobalAnsi (name), - out val, new IntPtr (0)); + g_object_get (Raw, name, out val, new IntPtr (0)); } /// @@ -319,12 +299,14 @@ namespace GLib { /// Accesses an Object Property. /// + [DllImport("gobject-1.3", CallingConvention=CallingConvention.Cdecl)] + static extern void g_object_get (IntPtr obj, string name, + out IntPtr val, IntPtr term); + public void GetProperty (String name, out GLib.Object val) { IntPtr obj; - g_object_get (Raw, - Marshal.StringToHGlobalAnsi (name), - out obj, new IntPtr (0)); + g_object_get (Raw, name, out obj, new IntPtr (0)); val = GLib.Object.GetObject (obj); } @@ -339,15 +321,10 @@ namespace GLib { public void GetProperty (String name, out GtkSharp.Boxed val) { IntPtr raw; - g_object_get (Raw, - Marshal.StringToHGlobalAnsi (name), - out raw, new IntPtr (0)); + g_object_get (Raw, name, out raw, new IntPtr (0)); val = GtkSharp.Boxed.GetBoxed (raw); } - /// - /// GetProperty Method - /// /// /// GetProperty Method /// @@ -358,14 +335,9 @@ namespace GLib { public void GetProperty (String name, out IntPtr val) { - g_object_get (Raw, - Marshal.StringToHGlobalAnsi (name), - out val, new IntPtr (0)); + g_object_get (Raw, name, out val, new IntPtr (0)); } - /// - /// SetProperty Method - /// /// /// SetProperty Method /// @@ -374,17 +346,13 @@ namespace GLib { /// Changes the value of a string Property. /// - [DllImport("gobject-1.3.dll", CharSet=CharSet.Ansi, - CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_set (IntPtr obj, IntPtr name, - IntPtr val, IntPtr term); + [DllImport("gobject-1.3", CallingConvention=CallingConvention.Cdecl)] + static extern void g_object_set (IntPtr obj, string name, + string val, IntPtr term); public void SetProperty (String name, String val) { - g_object_set (Raw, - Marshal.StringToHGlobalAnsi (name), - Marshal.StringToHGlobalAnsi (val), - new IntPtr (0)); + g_object_set (Raw, name, val, new IntPtr (0)); } /// @@ -395,16 +363,13 @@ namespace GLib { /// Changes the value of an integer Property. /// - [DllImport("gobject-1.3.dll", CharSet=CharSet.Ansi, - CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_set (IntPtr obj, IntPtr name, + [DllImport("gobject-1.3", CallingConvention=CallingConvention.Cdecl)] + static extern void g_object_set (IntPtr obj, string name, int val, IntPtr term); public void SetProperty (String name, int val) { - g_object_set (Raw, - Marshal.StringToHGlobalAnsi (name), - val, new IntPtr (0)); + g_object_set (Raw, name, val, new IntPtr (0)); } /// @@ -415,16 +380,13 @@ namespace GLib { /// Changes the value of an unsigned integer Property. /// - [DllImport("gobject-1.3.dll", CharSet=CharSet.Ansi, - CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_set (IntPtr obj, IntPtr name, + [DllImport("gobject-1.3", CallingConvention=CallingConvention.Cdecl)] + static extern void g_object_set (IntPtr obj, string name, uint val, IntPtr term); public void SetProperty (String name, uint val) { - g_object_set (Raw, - Marshal.StringToHGlobalAnsi (name), - val, new IntPtr (0)); + g_object_set (Raw, name, val, new IntPtr (0)); } /// @@ -435,16 +397,13 @@ namespace GLib { /// Changes the value of a boolean Property. /// - [DllImport("gobject-1.3.dll", CharSet=CharSet.Ansi, - CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_set (IntPtr obj, IntPtr name, + [DllImport("gobject-1.3", CallingConvention=CallingConvention.Cdecl)] + static extern void g_object_set (IntPtr obj, string name, bool val, IntPtr term); public void SetProperty (String name, bool val) { - g_object_set (Raw, - Marshal.StringToHGlobalAnsi (name), - val, new IntPtr (0)); + g_object_set (Raw, name, val, new IntPtr (0)); } /// @@ -455,16 +414,13 @@ namespace GLib { /// Changes the value of a double Property. /// - [DllImport("gobject-1.3.dll", CharSet=CharSet.Ansi, - CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_set (IntPtr obj, IntPtr name, + [DllImport("gobject-1.3", CallingConvention=CallingConvention.Cdecl)] + static extern void g_object_set (IntPtr obj, string name, double val, IntPtr term); public void SetProperty (String name, double val) { - g_object_set (Raw, - Marshal.StringToHGlobalAnsi (name), - val, new IntPtr (0)); + g_object_set (Raw, name, val, new IntPtr (0)); } /// @@ -475,16 +431,13 @@ namespace GLib { /// Changes the value of a float Property. /// - [DllImport("gobject-1.3.dll", CharSet=CharSet.Ansi, - CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_set (IntPtr obj, IntPtr name, + [DllImport("gobject-1.3", CallingConvention=CallingConvention.Cdecl)] + static extern void g_object_set (IntPtr obj, string name, float val, IntPtr term); public void SetProperty (String name, float val) { - g_object_set (Raw, - Marshal.StringToHGlobalAnsi (name), - val, new IntPtr (0)); + g_object_set (Raw, name, val, new IntPtr (0)); } /// @@ -495,11 +448,13 @@ namespace GLib { /// Changes the value of an IntPtr Property. /// + [DllImport("gobject-1.3", CallingConvention=CallingConvention.Cdecl)] + static extern void g_object_set (IntPtr obj, string name, + IntPtr val, IntPtr term); + public void SetProperty (String name, IntPtr val) { - g_object_set (Raw, - Marshal.StringToHGlobalAnsi (name), - val, new IntPtr (0)); + g_object_set (Raw, name, val, new IntPtr (0)); } /// @@ -512,9 +467,7 @@ namespace GLib { public void SetProperty (String name, GLib.Object val) { - g_object_set (Raw, - Marshal.StringToHGlobalAnsi (name), - val.Handle, new IntPtr (0)); + g_object_set (Raw, name, val.Handle, new IntPtr (0)); } /// @@ -527,14 +480,12 @@ namespace GLib { public void SetProperty (String name, GtkSharp.Boxed val) { - g_object_set (Raw, - Marshal.StringToHGlobalAnsi (name), - val.Handle, new IntPtr (0)); + g_object_set (Raw, name, val.Handle, new IntPtr (0)); } /* - [DllImport("gtk-1.3.dll")] + [DllImport("gtk-1.3")] static extern void g_object_set_data_full ( IntPtr obj, String key, diff --git a/glib/SList.cs b/glib/SList.cs index ee974881c..a71375581 100644 --- a/glib/SList.cs +++ b/glib/SList.cs @@ -65,7 +65,7 @@ namespace GLib { /// The number of elements in the SList. /// - [DllImport("glib-1.3.dll", CallingConvention=CallingConvention.Cdecl)] + [DllImport("glib-1.3", CallingConvention=CallingConvention.Cdecl)] static extern int g_slist_length(IntPtr raw); public int Count { @@ -168,7 +168,7 @@ namespace GLib { /// Indexer to access members of the SList. /// - [DllImport("glib-1.3.dll", CallingConvention=CallingConvention.Cdecl)] + [DllImport("glib-1.3", CallingConvention=CallingConvention.Cdecl)] static extern IntPtr g_slist_nth_data(IntPtr raw, int index); public object this[int index] { diff --git a/glib/Value.cs b/glib/Value.cs index c77459e8c..b06552235 100755 --- a/glib/Value.cs +++ b/glib/Value.cs @@ -26,7 +26,7 @@ namespace GLib { // Destructor is required since we are allocating unmananged // heap resources. - [DllImport("glib-1.3.dll")] + [DllImport("glib-1.3")] static extern void g_free (IntPtr mem); ~Value () @@ -44,7 +44,7 @@ namespace GLib { /// value to it. /// - [DllImport("glib-1.3.dll", + [DllImport("glib-1.3", CallingConvention=CallingConvention.Cdecl)] static extern IntPtr g_malloc0 (long n_bytes); @@ -74,7 +74,7 @@ namespace GLib { /// Constructs a Value from a specified boolean. /// - [DllImport("gobject-1.3.dll", + [DllImport("gobject-1.3", CallingConvention=CallingConvention.Cdecl)] static extern void g_value_set_boolean (IntPtr val, bool data); @@ -92,7 +92,7 @@ namespace GLib { /// Constructs a Value from a specified integer. /// - [DllImport("gobject-1.3.dll", + [DllImport("gobject-1.3", CallingConvention=CallingConvention.Cdecl)] static extern void g_value_set_int (IntPtr val, int data); @@ -110,7 +110,7 @@ namespace GLib { /// Constructs a Value from a specified string. /// - [DllImport("gobject-1.3.dll", + [DllImport("gobject-1.3", CallingConvention=CallingConvention.Cdecl)] static extern void g_value_set_string (IntPtr val, IntPtr data); @@ -129,7 +129,7 @@ namespace GLib { /// Prepares a raw value to hold a specified type. /// - [DllImport("gobject-1.3.dll", + [DllImport("gobject-1.3", CallingConvention=CallingConvention.Cdecl)] static extern void g_value_init (IntPtr val, TypeFundamentals type); @@ -149,7 +149,7 @@ namespace GLib { /// boolean value. /// - [DllImport("gobject-1.3.dll", + [DllImport("gobject-1.3", CallingConvention=CallingConvention.Cdecl)] static extern bool g_value_get_boolean (IntPtr val); @@ -170,7 +170,7 @@ namespace GLib { /// integer value. /// - [DllImport("gobject-1.3.dll", + [DllImport("gobject-1.3", CallingConvention=CallingConvention.Cdecl)] static extern int g_value_get_int (IntPtr val); @@ -191,7 +191,7 @@ namespace GLib { /// string value. /// - [DllImport("gobject-1.3.dll", + [DllImport("gobject-1.3", CallingConvention=CallingConvention.Cdecl)] static extern IntPtr g_value_get_string (IntPtr val); diff --git a/gtk/Application.cs b/gtk/Application.cs index fd2542c0b..e4009f88c 100755 --- a/gtk/Application.cs +++ b/gtk/Application.cs @@ -23,7 +23,15 @@ namespace Gtk { public class Application { - [DllImport("gtk-1.3.dll")] + [DllImport("gtk-x11-1.3")] + static extern void gtk_init (int argc, IntPtr argv); + + public static void Init () + { + gtk_init (0, new IntPtr(0)); + } + + [DllImport("gtk-x11-1.3")] static extern void gtk_init (ref int argc, ref String[] argv); /// @@ -48,7 +56,7 @@ namespace Gtk { /// Begins the event loop iteration. /// - [DllImport("gtk-1.3.dll")] + [DllImport("gtk-x11-1.3")] static extern void gtk_main (); public static void Run () @@ -65,7 +73,7 @@ namespace Gtk { /// Terminates the event loop iteration. /// - [DllImport("gtk-1.3.dll")] + [DllImport("gtk-x11-1.3")] static extern void gtk_main_quit (); public static void Quit () diff --git a/sample/HelloWorld.cs b/sample/HelloWorld.cs index ef6e5858a..d7ff906ca 100755 --- a/sample/HelloWorld.cs +++ b/sample/HelloWorld.cs @@ -16,7 +16,7 @@ namespace GtkSamples { public static int Main (string[] args) { - Application.Init (ref args); + Application.Init (); Gtk.Window win = new Gtk.Window (Gtk.WindowType.Toplevel); win.Title = "Gtk# Hello World"; win.DeleteEvent += new EventHandler (Window_Delete);