mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2024-12-24 01:55:32 +00:00
2004-12-21 Mike Kestner <mkestner@novell.com>
* glib/Argv.cs : argv marshaling class. * glib/Makefile.am : add file. * glib/Marshaller.cs : mark the argv methods obsolete. * gtk/Application.cs : use GLib.Argv. [Fixes #68812] svn path=/trunk/gtk-sharp/; revision=38046
This commit is contained in:
parent
62258ca7c3
commit
e38ece1fdb
|
@ -1,3 +1,10 @@
|
||||||
|
2004-12-21 Mike Kestner <mkestner@novell.com>
|
||||||
|
|
||||||
|
* glib/Argv.cs : argv marshaling class.
|
||||||
|
* glib/Makefile.am : add file.
|
||||||
|
* glib/Marshaller.cs : mark the argv methods obsolete.
|
||||||
|
* gtk/Application.cs : use GLib.Argv. [Fixes #68812]
|
||||||
|
|
||||||
2004-12-21 Dan Winship <danw@novell.com>
|
2004-12-21 Dan Winship <danw@novell.com>
|
||||||
|
|
||||||
* generator/CallbackGen.cs:
|
* generator/CallbackGen.cs:
|
||||||
|
|
77
doc/en/GLib/Argv.xml
Normal file
77
doc/en/GLib/Argv.xml
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
<Type Name="Argv" FullName="GLib.Argv">
|
||||||
|
<TypeSignature Language="C#" Value="public class Argv" Maintainer="auto" />
|
||||||
|
<AssemblyInfo>
|
||||||
|
<AssemblyName>glib-sharp</AssemblyName>
|
||||||
|
<AssemblyPublicKey>[00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00 00 24 00 00 52 53 41 31 00 04 00 00 01 00 01 00 71 EB 6C 55 75 52 9C BF 72 44 F7 A6 EA 05 62 84 F9 EA E0 3B CF F2 CC 13 2C 9C 49 0A B3 09 EA B0 B5 6B CE 44 9D F5 03 D9 C0 A8 1E 52 05 85 CD BE 70 E2 FB 90 43 4B AC 04 FA 62 22 A8 00 98 B7 A1 A7 B3 AF 99 1A 41 23 24 BB 43 25 F6 B8 65 BB 64 EB F6 D1 C2 06 D5 73 2D DF BC 70 A7 38 9E E5 3E 0C 24 6E 32 79 74 1A D0 05 03 E4 98 42 E1 9B F3 7B 19 8B 40 21 26 CB 36 89 C2 EA 64 96 A4 7C B4]</AssemblyPublicKey>
|
||||||
|
<AssemblyVersion>2.0.0.0</AssemblyVersion>
|
||||||
|
<AssemblyCulture>neutral</AssemblyCulture>
|
||||||
|
<Attributes />
|
||||||
|
</AssemblyInfo>
|
||||||
|
<ThreadSafetyStatement>Gtk# is thread aware, but not thread safe; See the <link location="node:gtk-sharp/programming/threads">Gtk# Thread Programming</link> for details.</ThreadSafetyStatement>
|
||||||
|
<Docs>
|
||||||
|
<summary>Argv marshaling class.</summary>
|
||||||
|
<remarks />
|
||||||
|
</Docs>
|
||||||
|
<Base>
|
||||||
|
<BaseTypeName>System.Object</BaseTypeName>
|
||||||
|
</Base>
|
||||||
|
<Interfaces />
|
||||||
|
<Attributes />
|
||||||
|
<Members>
|
||||||
|
<Member MemberName="Finalize">
|
||||||
|
<MemberSignature Language="C#" Value="protected override void Finalize ();" />
|
||||||
|
<MemberType>Method</MemberType>
|
||||||
|
<ReturnValue>
|
||||||
|
<ReturnType>System.Void</ReturnType>
|
||||||
|
</ReturnValue>
|
||||||
|
<Parameters />
|
||||||
|
<Docs>
|
||||||
|
<summary>Releases native resources.</summary>
|
||||||
|
<remarks />
|
||||||
|
</Docs>
|
||||||
|
</Member>
|
||||||
|
<Member MemberName="GetArgs">
|
||||||
|
<MemberSignature Language="C#" Value="public string [] GetArgs (int argc);" />
|
||||||
|
<MemberType>Method</MemberType>
|
||||||
|
<ReturnValue>
|
||||||
|
<ReturnType>System.String[]</ReturnType>
|
||||||
|
</ReturnValue>
|
||||||
|
<Parameters>
|
||||||
|
<Parameter Name="argc" Type="System.Int32" />
|
||||||
|
</Parameters>
|
||||||
|
<Docs>
|
||||||
|
<summary>Gets a string array containing a specified number of arguments.</summary>
|
||||||
|
<param name="argc">a <see cref="T:System.Int32" /></param>
|
||||||
|
<returns>a <see cref="T:System.String[]" /></returns>
|
||||||
|
<remarks />
|
||||||
|
</Docs>
|
||||||
|
</Member>
|
||||||
|
<Member MemberName=".ctor">
|
||||||
|
<MemberSignature Language="C#" Value="public Argv (string [] args);" />
|
||||||
|
<MemberType>Constructor</MemberType>
|
||||||
|
<ReturnValue />
|
||||||
|
<Parameters>
|
||||||
|
<Parameter Name="args" Type="System.String[]" />
|
||||||
|
</Parameters>
|
||||||
|
<Docs>
|
||||||
|
<summary>Creates an Argv marshaler.</summary>
|
||||||
|
<param name="args">a <see cref="T:System.String" /></param>
|
||||||
|
<returns>a <see cref="T:GLib.Argv" /></returns>
|
||||||
|
<remarks />
|
||||||
|
</Docs>
|
||||||
|
</Member>
|
||||||
|
<Member MemberName="Handle">
|
||||||
|
<MemberSignature Language="C#" Value="public IntPtr Handle { get; };" />
|
||||||
|
<MemberType>Property</MemberType>
|
||||||
|
<ReturnValue>
|
||||||
|
<ReturnType>System.IntPtr</ReturnType>
|
||||||
|
</ReturnValue>
|
||||||
|
<Parameters />
|
||||||
|
<Docs>
|
||||||
|
<summary>Native pointer to the argument array.</summary>
|
||||||
|
<returns>a <see cref="T:System.IntPtr" /></returns>
|
||||||
|
<remarks />
|
||||||
|
</Docs>
|
||||||
|
</Member>
|
||||||
|
</Members>
|
||||||
|
</Type>
|
79
glib/Argv.cs
Normal file
79
glib/Argv.cs
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
// GLib.Argv.cs : Argv marshaling class
|
||||||
|
//
|
||||||
|
// Author: Mike Kestner <mkestner@novell.com>
|
||||||
|
//
|
||||||
|
// 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 Lesser 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
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser 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 GLib {
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
public class Argv {
|
||||||
|
|
||||||
|
IntPtr[] arg_ptrs;
|
||||||
|
IntPtr handle;
|
||||||
|
|
||||||
|
[DllImport("libglib-2.0-0.dll")]
|
||||||
|
static extern IntPtr g_strdup (string str);
|
||||||
|
|
||||||
|
[DllImport("libglib-2.0-0.dll")]
|
||||||
|
static extern IntPtr g_malloc(IntPtr size);
|
||||||
|
|
||||||
|
[DllImport("libglib-2.0-0.dll")]
|
||||||
|
static extern void g_free (IntPtr mem);
|
||||||
|
|
||||||
|
~Argv ()
|
||||||
|
{
|
||||||
|
foreach (IntPtr arg in arg_ptrs)
|
||||||
|
g_free (arg);
|
||||||
|
|
||||||
|
g_free (handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Argv (string[] args)
|
||||||
|
{
|
||||||
|
arg_ptrs = new IntPtr [args.Length];
|
||||||
|
|
||||||
|
for (int i = 0; i < args.Length; i++)
|
||||||
|
arg_ptrs [i] = g_strdup (args[i]);
|
||||||
|
|
||||||
|
handle = g_malloc (new IntPtr (IntPtr.Size * args.Length));
|
||||||
|
|
||||||
|
for (int i = 0; i < args.Length; i++)
|
||||||
|
Marshal.WriteIntPtr (handle, i * IntPtr.Size, arg_ptrs [i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntPtr Handle {
|
||||||
|
get {
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string[] GetArgs (int argc)
|
||||||
|
{
|
||||||
|
string[] result = new string [argc];
|
||||||
|
|
||||||
|
for (int i = 0; i < argc; i++)
|
||||||
|
result [i] = Marshal.PtrToStringAnsi (Marshal.ReadIntPtr (handle, i * IntPtr.Size));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ DISTCLEANFILES = $(ASSEMBLY).config AssemblyInfo.cs
|
||||||
references =
|
references =
|
||||||
|
|
||||||
sources = \
|
sources = \
|
||||||
|
Argv.cs \
|
||||||
Boxed.cs \
|
Boxed.cs \
|
||||||
ConnectBeforeAttribute.cs \
|
ConnectBeforeAttribute.cs \
|
||||||
DefaultSignalHandlerAttribute.cs \
|
DefaultSignalHandlerAttribute.cs \
|
||||||
|
|
|
@ -109,6 +109,7 @@ namespace GLib {
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Obsolete ("Use GLib.Argv instead to avoid leaks.")]
|
||||||
public static IntPtr ArgvToArrayPtr (string[] args)
|
public static IntPtr ArgvToArrayPtr (string[] args)
|
||||||
{
|
{
|
||||||
if (args.Length == 0)
|
if (args.Length == 0)
|
||||||
|
@ -149,6 +150,7 @@ namespace GLib {
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Obsolete ("Use GLib.Argv instead to avoid leaks.")]
|
||||||
public static string[] ArrayPtrToArgv (IntPtr array, int argc)
|
public static string[] ArrayPtrToArgv (IntPtr array, int argc)
|
||||||
{
|
{
|
||||||
if (argc == 0)
|
if (argc == 0)
|
||||||
|
|
|
@ -55,7 +55,8 @@ namespace Gtk {
|
||||||
progargs[0] = progname;
|
progargs[0] = progname;
|
||||||
args.CopyTo (progargs, 1);
|
args.CopyTo (progargs, 1);
|
||||||
|
|
||||||
IntPtr buf = GLib.Marshaller.ArgvToArrayPtr (progargs);
|
GLib.Argv argv = new GLib.Argv (progargs);
|
||||||
|
IntPtr buf = argv.Handle;
|
||||||
int argc = progargs.Length;
|
int argc = progargs.Length;
|
||||||
|
|
||||||
if (check)
|
if (check)
|
||||||
|
@ -63,13 +64,16 @@ namespace Gtk {
|
||||||
else
|
else
|
||||||
gtk_init (ref argc, ref buf);
|
gtk_init (ref argc, ref buf);
|
||||||
|
|
||||||
|
if (buf != argv.Handle)
|
||||||
|
throw new Exception ("init returned new argv handle");
|
||||||
|
|
||||||
// copy back the resulting argv, minus argv[0], which we're
|
// copy back the resulting argv, minus argv[0], which we're
|
||||||
// not interested in.
|
// not interested in.
|
||||||
|
|
||||||
if (argc == 0)
|
if (argc <= 1)
|
||||||
args = new string[0];
|
args = new string[0];
|
||||||
else {
|
else {
|
||||||
progargs = GLib.Marshaller.ArrayPtrToArgv (buf, argc);
|
progargs = argv.GetArgs (argc);
|
||||||
args = new string[argc - 1];
|
args = new string[argc - 1];
|
||||||
Array.Copy (progargs, 1, args, 0, argc - 1);
|
Array.Copy (progargs, 1, args, 0, argc - 1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue