2003-05-29 Rachel Hestilow <rachel@nullenvoid.com>
* gconf/Value.cs: Update to use new string marshalling.
* generator/StringGen.cs, ConstStringGen.cs: Added.
* generator/IGeneratable.cs: Add new method ToNativeReturn.
* generator/CallbackGen.cs: Implement ToNativeReturn. Call
ToNativeReturn for the return statement. Fix a couple of
places where s_ret was being used incorrectly for m_ret.
* generator/ClassGen.cs, EnumGen.cs, ManualGen.cs,
SimpleGen.cs, StructBase.cs: Implement ToNativeReturn.
* generator/SignalHandler.cs: Call ToNativeReturn for the
return statement, instead of CallByName.
* generator/SymbolTable.cs: Use StringGen for gchar, char,
and gunichar, and ConstStringGen for their const variants.
Add a new method wrapper for ToNativeReturn.
(Trim): Add a special-case for const strings so that the
const is not stripped. Otherwise there is no way of
resolving the const case.
* glade/XML.custom: Update to use new string marshalling.
* glib/Marshaller.cs: Added.
* glib/GException.cs, Markup.cs, ObjectManager.cs,
Value.cs: Update to use new string marshalling.
* glib/Object.cs: Remove old g_type_name DllImport
as it is no longer used.
* glue/fileselection.c (gtksharp_file_selection_get_fileop_entry):
Mark this as const return.
* gtk/ColorSelection.custom, FileSelection.custom,
SelectionData.custom: Update to use new string marshalling.
svn path=/trunk/gtk-sharp/; revision=15286
2003-06-10 18:09:47 +00:00
|
|
|
// GLibSharp.Marshaller.cs : Marshalling utils
|
|
|
|
//
|
|
|
|
// Author: Rachel Hestilow <rachel@nullenvoid.com>
|
2004-05-19 18:57:28 +00:00
|
|
|
// Mike Kestner <mkestner@ximian.com>
|
2003-05-29 Rachel Hestilow <rachel@nullenvoid.com>
* gconf/Value.cs: Update to use new string marshalling.
* generator/StringGen.cs, ConstStringGen.cs: Added.
* generator/IGeneratable.cs: Add new method ToNativeReturn.
* generator/CallbackGen.cs: Implement ToNativeReturn. Call
ToNativeReturn for the return statement. Fix a couple of
places where s_ret was being used incorrectly for m_ret.
* generator/ClassGen.cs, EnumGen.cs, ManualGen.cs,
SimpleGen.cs, StructBase.cs: Implement ToNativeReturn.
* generator/SignalHandler.cs: Call ToNativeReturn for the
return statement, instead of CallByName.
* generator/SymbolTable.cs: Use StringGen for gchar, char,
and gunichar, and ConstStringGen for their const variants.
Add a new method wrapper for ToNativeReturn.
(Trim): Add a special-case for const strings so that the
const is not stripped. Otherwise there is no way of
resolving the const case.
* glade/XML.custom: Update to use new string marshalling.
* glib/Marshaller.cs: Added.
* glib/GException.cs, Markup.cs, ObjectManager.cs,
Value.cs: Update to use new string marshalling.
* glib/Object.cs: Remove old g_type_name DllImport
as it is no longer used.
* glue/fileselection.c (gtksharp_file_selection_get_fileop_entry):
Mark this as const return.
* gtk/ColorSelection.custom, FileSelection.custom,
SelectionData.custom: Update to use new string marshalling.
svn path=/trunk/gtk-sharp/; revision=15286
2003-06-10 18:09:47 +00:00
|
|
|
//
|
2004-05-19 18:57:28 +00:00
|
|
|
// Copyright (c) 2002, 2003 Rachel Hestilow
|
|
|
|
// Copyright (c) 2004 Novell, Inc.
|
2004-06-25 18:42:19 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2003-05-29 Rachel Hestilow <rachel@nullenvoid.com>
* gconf/Value.cs: Update to use new string marshalling.
* generator/StringGen.cs, ConstStringGen.cs: Added.
* generator/IGeneratable.cs: Add new method ToNativeReturn.
* generator/CallbackGen.cs: Implement ToNativeReturn. Call
ToNativeReturn for the return statement. Fix a couple of
places where s_ret was being used incorrectly for m_ret.
* generator/ClassGen.cs, EnumGen.cs, ManualGen.cs,
SimpleGen.cs, StructBase.cs: Implement ToNativeReturn.
* generator/SignalHandler.cs: Call ToNativeReturn for the
return statement, instead of CallByName.
* generator/SymbolTable.cs: Use StringGen for gchar, char,
and gunichar, and ConstStringGen for their const variants.
Add a new method wrapper for ToNativeReturn.
(Trim): Add a special-case for const strings so that the
const is not stripped. Otherwise there is no way of
resolving the const case.
* glade/XML.custom: Update to use new string marshalling.
* glib/Marshaller.cs: Added.
* glib/GException.cs, Markup.cs, ObjectManager.cs,
Value.cs: Update to use new string marshalling.
* glib/Object.cs: Remove old g_type_name DllImport
as it is no longer used.
* glue/fileselection.c (gtksharp_file_selection_get_fileop_entry):
Mark this as const return.
* gtk/ColorSelection.custom, FileSelection.custom,
SelectionData.custom: Update to use new string marshalling.
svn path=/trunk/gtk-sharp/; revision=15286
2003-06-10 18:09:47 +00:00
|
|
|
|
2004-05-19 18:57:28 +00:00
|
|
|
namespace GLib {
|
2003-05-29 Rachel Hestilow <rachel@nullenvoid.com>
* gconf/Value.cs: Update to use new string marshalling.
* generator/StringGen.cs, ConstStringGen.cs: Added.
* generator/IGeneratable.cs: Add new method ToNativeReturn.
* generator/CallbackGen.cs: Implement ToNativeReturn. Call
ToNativeReturn for the return statement. Fix a couple of
places where s_ret was being used incorrectly for m_ret.
* generator/ClassGen.cs, EnumGen.cs, ManualGen.cs,
SimpleGen.cs, StructBase.cs: Implement ToNativeReturn.
* generator/SignalHandler.cs: Call ToNativeReturn for the
return statement, instead of CallByName.
* generator/SymbolTable.cs: Use StringGen for gchar, char,
and gunichar, and ConstStringGen for their const variants.
Add a new method wrapper for ToNativeReturn.
(Trim): Add a special-case for const strings so that the
const is not stripped. Otherwise there is no way of
resolving the const case.
* glade/XML.custom: Update to use new string marshalling.
* glib/Marshaller.cs: Added.
* glib/GException.cs, Markup.cs, ObjectManager.cs,
Value.cs: Update to use new string marshalling.
* glib/Object.cs: Remove old g_type_name DllImport
as it is no longer used.
* glue/fileselection.c (gtksharp_file_selection_get_fileop_entry):
Mark this as const return.
* gtk/ColorSelection.custom, FileSelection.custom,
SelectionData.custom: Update to use new string marshalling.
svn path=/trunk/gtk-sharp/; revision=15286
2003-06-10 18:09:47 +00:00
|
|
|
using System;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
public class Marshaller {
|
2003-11-28 05:29:34 +00:00
|
|
|
|
|
|
|
private Marshaller () {}
|
|
|
|
|
2003-05-29 Rachel Hestilow <rachel@nullenvoid.com>
* gconf/Value.cs: Update to use new string marshalling.
* generator/StringGen.cs, ConstStringGen.cs: Added.
* generator/IGeneratable.cs: Add new method ToNativeReturn.
* generator/CallbackGen.cs: Implement ToNativeReturn. Call
ToNativeReturn for the return statement. Fix a couple of
places where s_ret was being used incorrectly for m_ret.
* generator/ClassGen.cs, EnumGen.cs, ManualGen.cs,
SimpleGen.cs, StructBase.cs: Implement ToNativeReturn.
* generator/SignalHandler.cs: Call ToNativeReturn for the
return statement, instead of CallByName.
* generator/SymbolTable.cs: Use StringGen for gchar, char,
and gunichar, and ConstStringGen for their const variants.
Add a new method wrapper for ToNativeReturn.
(Trim): Add a special-case for const strings so that the
const is not stripped. Otherwise there is no way of
resolving the const case.
* glade/XML.custom: Update to use new string marshalling.
* glib/Marshaller.cs: Added.
* glib/GException.cs, Markup.cs, ObjectManager.cs,
Value.cs: Update to use new string marshalling.
* glib/Object.cs: Remove old g_type_name DllImport
as it is no longer used.
* glue/fileselection.c (gtksharp_file_selection_get_fileop_entry):
Mark this as const return.
* gtk/ColorSelection.custom, FileSelection.custom,
SelectionData.custom: Update to use new string marshalling.
svn path=/trunk/gtk-sharp/; revision=15286
2003-06-10 18:09:47 +00:00
|
|
|
[DllImport("libglib-2.0-0.dll")]
|
|
|
|
static extern void g_free (IntPtr mem);
|
|
|
|
|
2005-03-08 21:28:08 +00:00
|
|
|
public static void Free (IntPtr ptr)
|
|
|
|
{
|
|
|
|
g_free (ptr);
|
|
|
|
}
|
|
|
|
|
2005-06-02 14:16:52 +00:00
|
|
|
[DllImport("libglib-2.0-0.dll")]
|
|
|
|
static extern IntPtr g_filename_to_utf8 (IntPtr mem, int len, IntPtr read, out IntPtr written, out IntPtr error);
|
|
|
|
|
|
|
|
public static string FilenamePtrToString (IntPtr ptr)
|
|
|
|
{
|
2005-06-09 14:52:24 +00:00
|
|
|
if (ptr == IntPtr.Zero) return null;
|
|
|
|
|
2005-06-02 14:16:52 +00:00
|
|
|
IntPtr dummy, error;
|
|
|
|
IntPtr utf8 = g_filename_to_utf8 (ptr, -1, IntPtr.Zero, out dummy, out error);
|
|
|
|
if (error != IntPtr.Zero)
|
|
|
|
throw new GLib.GException (error);
|
|
|
|
return Utf8PtrToString (utf8);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string FilenamePtrToStringGFree (IntPtr ptr)
|
|
|
|
{
|
|
|
|
string ret = FilenamePtrToString (ptr);
|
|
|
|
g_free (ptr);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-03-10 20:33:57 +00:00
|
|
|
[DllImport("glibsharpglue-2")]
|
|
|
|
static extern UIntPtr glibsharp_strlen (IntPtr mem);
|
2005-03-04 18:59:09 +00:00
|
|
|
|
|
|
|
public static string Utf8PtrToString (IntPtr ptr)
|
|
|
|
{
|
2005-03-09 17:01:35 +00:00
|
|
|
if (ptr == IntPtr.Zero)
|
|
|
|
return null;
|
|
|
|
|
2005-03-10 20:33:57 +00:00
|
|
|
int len = (int) (uint)glibsharp_strlen (ptr);
|
2005-03-04 18:59:09 +00:00
|
|
|
byte[] bytes = new byte [len];
|
|
|
|
Marshal.Copy (ptr, bytes, 0, len);
|
|
|
|
return System.Text.Encoding.UTF8.GetString (bytes);
|
|
|
|
}
|
|
|
|
|
2005-04-22 19:43:46 +00:00
|
|
|
public static string[] Utf8PtrToString (IntPtr[] ptrs) {
|
|
|
|
// The last pointer is a null terminator.
|
|
|
|
string[] ret = new string[ptrs.Length - 1];
|
|
|
|
for (int i = 0; i < ret.Length; i++)
|
|
|
|
ret[i] = Utf8PtrToString (ptrs[i]);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-03-04 18:59:09 +00:00
|
|
|
public static string PtrToStringGFree (IntPtr ptr)
|
|
|
|
{
|
|
|
|
string ret = Utf8PtrToString (ptr);
|
2003-05-29 Rachel Hestilow <rachel@nullenvoid.com>
* gconf/Value.cs: Update to use new string marshalling.
* generator/StringGen.cs, ConstStringGen.cs: Added.
* generator/IGeneratable.cs: Add new method ToNativeReturn.
* generator/CallbackGen.cs: Implement ToNativeReturn. Call
ToNativeReturn for the return statement. Fix a couple of
places where s_ret was being used incorrectly for m_ret.
* generator/ClassGen.cs, EnumGen.cs, ManualGen.cs,
SimpleGen.cs, StructBase.cs: Implement ToNativeReturn.
* generator/SignalHandler.cs: Call ToNativeReturn for the
return statement, instead of CallByName.
* generator/SymbolTable.cs: Use StringGen for gchar, char,
and gunichar, and ConstStringGen for their const variants.
Add a new method wrapper for ToNativeReturn.
(Trim): Add a special-case for const strings so that the
const is not stripped. Otherwise there is no way of
resolving the const case.
* glade/XML.custom: Update to use new string marshalling.
* glib/Marshaller.cs: Added.
* glib/GException.cs, Markup.cs, ObjectManager.cs,
Value.cs: Update to use new string marshalling.
* glib/Object.cs: Remove old g_type_name DllImport
as it is no longer used.
* glue/fileselection.c (gtksharp_file_selection_get_fileop_entry):
Mark this as const return.
* gtk/ColorSelection.custom, FileSelection.custom,
SelectionData.custom: Update to use new string marshalling.
svn path=/trunk/gtk-sharp/; revision=15286
2003-06-10 18:09:47 +00:00
|
|
|
g_free (ptr);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string[] PtrToStringGFree (IntPtr[] ptrs) {
|
|
|
|
// The last pointer is a null terminator.
|
|
|
|
string[] ret = new string[ptrs.Length - 1];
|
|
|
|
for (int i = 0; i < ret.Length; i++) {
|
2005-03-04 18:59:09 +00:00
|
|
|
ret[i] = Utf8PtrToString (ptrs[i]);
|
2003-05-29 Rachel Hestilow <rachel@nullenvoid.com>
* gconf/Value.cs: Update to use new string marshalling.
* generator/StringGen.cs, ConstStringGen.cs: Added.
* generator/IGeneratable.cs: Add new method ToNativeReturn.
* generator/CallbackGen.cs: Implement ToNativeReturn. Call
ToNativeReturn for the return statement. Fix a couple of
places where s_ret was being used incorrectly for m_ret.
* generator/ClassGen.cs, EnumGen.cs, ManualGen.cs,
SimpleGen.cs, StructBase.cs: Implement ToNativeReturn.
* generator/SignalHandler.cs: Call ToNativeReturn for the
return statement, instead of CallByName.
* generator/SymbolTable.cs: Use StringGen for gchar, char,
and gunichar, and ConstStringGen for their const variants.
Add a new method wrapper for ToNativeReturn.
(Trim): Add a special-case for const strings so that the
const is not stripped. Otherwise there is no way of
resolving the const case.
* glade/XML.custom: Update to use new string marshalling.
* glib/Marshaller.cs: Added.
* glib/GException.cs, Markup.cs, ObjectManager.cs,
Value.cs: Update to use new string marshalling.
* glib/Object.cs: Remove old g_type_name DllImport
as it is no longer used.
* glue/fileselection.c (gtksharp_file_selection_get_fileop_entry):
Mark this as const return.
* gtk/ColorSelection.custom, FileSelection.custom,
SelectionData.custom: Update to use new string marshalling.
svn path=/trunk/gtk-sharp/; revision=15286
2003-06-10 18:09:47 +00:00
|
|
|
g_free (ptrs[i]);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-06-02 14:16:52 +00:00
|
|
|
[DllImport("libglib-2.0-0.dll")]
|
|
|
|
static extern IntPtr g_filename_from_utf8 (IntPtr mem, int len, IntPtr read, out IntPtr written, out IntPtr error);
|
|
|
|
|
|
|
|
public static IntPtr StringToFilenamePtr (string str)
|
|
|
|
{
|
|
|
|
if (str == null)
|
|
|
|
return IntPtr.Zero;
|
|
|
|
|
|
|
|
IntPtr dummy, error;
|
|
|
|
IntPtr utf8 = StringToPtrGStrdup (str);
|
|
|
|
IntPtr result = g_filename_from_utf8 (utf8, -1, IntPtr.Zero, out dummy, out error);
|
|
|
|
g_free (utf8);
|
|
|
|
if (error != IntPtr.Zero)
|
|
|
|
throw new GException (error);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-05-29 Rachel Hestilow <rachel@nullenvoid.com>
* gconf/Value.cs: Update to use new string marshalling.
* generator/StringGen.cs, ConstStringGen.cs: Added.
* generator/IGeneratable.cs: Add new method ToNativeReturn.
* generator/CallbackGen.cs: Implement ToNativeReturn. Call
ToNativeReturn for the return statement. Fix a couple of
places where s_ret was being used incorrectly for m_ret.
* generator/ClassGen.cs, EnumGen.cs, ManualGen.cs,
SimpleGen.cs, StructBase.cs: Implement ToNativeReturn.
* generator/SignalHandler.cs: Call ToNativeReturn for the
return statement, instead of CallByName.
* generator/SymbolTable.cs: Use StringGen for gchar, char,
and gunichar, and ConstStringGen for their const variants.
Add a new method wrapper for ToNativeReturn.
(Trim): Add a special-case for const strings so that the
const is not stripped. Otherwise there is no way of
resolving the const case.
* glade/XML.custom: Update to use new string marshalling.
* glib/Marshaller.cs: Added.
* glib/GException.cs, Markup.cs, ObjectManager.cs,
Value.cs: Update to use new string marshalling.
* glib/Object.cs: Remove old g_type_name DllImport
as it is no longer used.
* glue/fileselection.c (gtksharp_file_selection_get_fileop_entry):
Mark this as const return.
* gtk/ColorSelection.custom, FileSelection.custom,
SelectionData.custom: Update to use new string marshalling.
svn path=/trunk/gtk-sharp/; revision=15286
2003-06-10 18:09:47 +00:00
|
|
|
public static IntPtr StringToPtrGStrdup (string str) {
|
2005-03-08 21:28:08 +00:00
|
|
|
if (str == null)
|
|
|
|
return IntPtr.Zero;
|
2005-03-04 18:59:09 +00:00
|
|
|
byte[] bytes = System.Text.Encoding.UTF8.GetBytes (str);
|
2005-03-08 21:28:08 +00:00
|
|
|
IntPtr result = g_malloc (new UIntPtr ((ulong)bytes.Length + 1));
|
|
|
|
Marshal.Copy (bytes, 0, result, bytes.Length);
|
|
|
|
Marshal.WriteByte (result, bytes.Length, 0);
|
|
|
|
return result;
|
2003-05-29 Rachel Hestilow <rachel@nullenvoid.com>
* gconf/Value.cs: Update to use new string marshalling.
* generator/StringGen.cs, ConstStringGen.cs: Added.
* generator/IGeneratable.cs: Add new method ToNativeReturn.
* generator/CallbackGen.cs: Implement ToNativeReturn. Call
ToNativeReturn for the return statement. Fix a couple of
places where s_ret was being used incorrectly for m_ret.
* generator/ClassGen.cs, EnumGen.cs, ManualGen.cs,
SimpleGen.cs, StructBase.cs: Implement ToNativeReturn.
* generator/SignalHandler.cs: Call ToNativeReturn for the
return statement, instead of CallByName.
* generator/SymbolTable.cs: Use StringGen for gchar, char,
and gunichar, and ConstStringGen for their const variants.
Add a new method wrapper for ToNativeReturn.
(Trim): Add a special-case for const strings so that the
const is not stripped. Otherwise there is no way of
resolving the const case.
* glade/XML.custom: Update to use new string marshalling.
* glib/Marshaller.cs: Added.
* glib/GException.cs, Markup.cs, ObjectManager.cs,
Value.cs: Update to use new string marshalling.
* glib/Object.cs: Remove old g_type_name DllImport
as it is no longer used.
* glue/fileselection.c (gtksharp_file_selection_get_fileop_entry):
Mark this as const return.
* gtk/ColorSelection.custom, FileSelection.custom,
SelectionData.custom: Update to use new string marshalling.
svn path=/trunk/gtk-sharp/; revision=15286
2003-06-10 18:09:47 +00:00
|
|
|
}
|
|
|
|
|
2005-01-20 15:45:13 +00:00
|
|
|
public static string StringFormat (string format, params object[] args) {
|
|
|
|
string ret = String.Format (format, args);
|
|
|
|
if (ret.IndexOf ('%') == -1)
|
|
|
|
return ret;
|
|
|
|
else
|
|
|
|
return ret.Replace ("%", "%%");
|
|
|
|
}
|
|
|
|
|
2004-01-19 03:24:25 +00:00
|
|
|
// Argv marshalling -- unpleasantly complex, but
|
|
|
|
// don't know of a better way to do it.
|
|
|
|
//
|
|
|
|
// Currently, the 64-bit cleanliness is
|
|
|
|
// hypothetical. It's also ugly, but I don't know of a
|
|
|
|
// construct to handle both 32 and 64 bitness
|
|
|
|
// transparently, since we need to alloc buffers of
|
|
|
|
// [native pointer size] * [count] bytes.
|
|
|
|
|
|
|
|
[DllImport("libglib-2.0-0.dll")]
|
2005-03-08 21:28:08 +00:00
|
|
|
static extern IntPtr g_malloc(UIntPtr size);
|
2004-01-19 03:24:25 +00:00
|
|
|
|
|
|
|
static bool check_sixtyfour () {
|
|
|
|
int szint = Marshal.SizeOf (typeof (int));
|
|
|
|
int szlong = Marshal.SizeOf (typeof (long));
|
|
|
|
int szptr = IntPtr.Size;
|
|
|
|
|
|
|
|
if (szptr == szint)
|
|
|
|
return false;
|
|
|
|
if (szptr == szlong)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
throw new Exception ("Pointers are neither int- nor long-sized???");
|
|
|
|
}
|
|
|
|
|
|
|
|
static IntPtr make_buf_32 (string[] args)
|
|
|
|
{
|
|
|
|
int[] ptrs = new int[args.Length];
|
|
|
|
|
|
|
|
for (int i = 0; i < args.Length; i++)
|
|
|
|
ptrs[i] = (int) Marshal.StringToHGlobalAuto (args[i]);
|
|
|
|
|
2005-03-08 21:28:08 +00:00
|
|
|
IntPtr buf = g_malloc (new UIntPtr ((ulong) Marshal.SizeOf(typeof(int)) *
|
|
|
|
(ulong) args.Length));
|
2004-01-19 03:24:25 +00:00
|
|
|
Marshal.Copy (ptrs, 0, buf, ptrs.Length);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static IntPtr make_buf_64 (string[] args)
|
|
|
|
{
|
|
|
|
long[] ptrs = new long[args.Length];
|
|
|
|
|
|
|
|
for (int i = 0; i < args.Length; i++)
|
|
|
|
ptrs[i] = (long) Marshal.StringToHGlobalAuto (args[i]);
|
|
|
|
|
2005-03-08 21:28:08 +00:00
|
|
|
IntPtr buf = g_malloc (new UIntPtr ((ulong) Marshal.SizeOf(typeof(long)) *
|
|
|
|
(ulong) args.Length));
|
2004-01-19 03:24:25 +00:00
|
|
|
Marshal.Copy (ptrs, 0, buf, ptrs.Length);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2004-12-21 19:47:55 +00:00
|
|
|
[Obsolete ("Use GLib.Argv instead to avoid leaks.")]
|
2004-01-19 03:24:25 +00:00
|
|
|
public static IntPtr ArgvToArrayPtr (string[] args)
|
|
|
|
{
|
|
|
|
if (args.Length == 0)
|
|
|
|
return IntPtr.Zero;
|
|
|
|
|
|
|
|
if (check_sixtyfour ())
|
|
|
|
return make_buf_64 (args);
|
|
|
|
|
|
|
|
return make_buf_32 (args);
|
|
|
|
}
|
|
|
|
|
|
|
|
// should we be freeing these pointers? they're marshalled
|
|
|
|
// from our own strings, so I think not ...
|
|
|
|
|
|
|
|
static string[] unmarshal_32 (IntPtr buf, int argc)
|
|
|
|
{
|
|
|
|
int[] ptrs = new int[argc];
|
|
|
|
string[] args = new string[argc];
|
|
|
|
|
|
|
|
Marshal.Copy (buf, ptrs, 0, argc);
|
|
|
|
|
|
|
|
for (int i = 0; i < ptrs.Length; i++)
|
|
|
|
args[i] = Marshal.PtrToStringAuto ((IntPtr) ptrs[i]);
|
|
|
|
|
|
|
|
return args;
|
|
|
|
}
|
|
|
|
|
|
|
|
static string[] unmarshal_64 (IntPtr buf, int argc)
|
|
|
|
{
|
|
|
|
long[] ptrs = new long[argc];
|
|
|
|
string[] args = new string[argc];
|
|
|
|
|
|
|
|
Marshal.Copy (buf, ptrs, 0, argc);
|
|
|
|
|
|
|
|
for (int i = 0; i < ptrs.Length; i++)
|
|
|
|
args[i] = Marshal.PtrToStringAuto ((IntPtr) ptrs[i]);
|
|
|
|
|
|
|
|
return args;
|
|
|
|
}
|
|
|
|
|
2004-12-21 19:47:55 +00:00
|
|
|
[Obsolete ("Use GLib.Argv instead to avoid leaks.")]
|
2004-01-19 03:24:25 +00:00
|
|
|
public static string[] ArrayPtrToArgv (IntPtr array, int argc)
|
|
|
|
{
|
|
|
|
if (argc == 0)
|
|
|
|
return new string[0];
|
|
|
|
|
|
|
|
if (check_sixtyfour ())
|
|
|
|
return unmarshal_64 (array, argc);
|
|
|
|
|
|
|
|
return unmarshal_32 (array, argc);
|
|
|
|
}
|
2004-05-19 18:57:28 +00:00
|
|
|
|
|
|
|
static DateTime local_epoch = new DateTime (1970, 1, 1, 0, 0, 0);
|
2005-02-01 22:35:48 +00:00
|
|
|
static int utc_offset = (int) (TimeZone.CurrentTimeZone.GetUtcOffset (DateTime.Now)).TotalSeconds;
|
2004-05-19 18:57:28 +00:00
|
|
|
|
|
|
|
public static IntPtr DateTimeTotime_t (DateTime time)
|
|
|
|
{
|
2006-01-14 14:07:27 +00:00
|
|
|
return new IntPtr (((int)time.Subtract (local_epoch).TotalSeconds) - utc_offset);
|
2004-05-19 18:57:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static DateTime time_tToDateTime (IntPtr time_t)
|
|
|
|
{
|
2004-08-31 16:36:32 +00:00
|
|
|
return local_epoch.AddSeconds ((int)time_t + utc_offset);
|
2004-05-19 18:57:28 +00:00
|
|
|
}
|
2004-08-17 20:43:49 +00:00
|
|
|
|
2004-12-07 19:03:55 +00:00
|
|
|
[DllImport("glibsharpglue-2")]
|
2004-08-17 20:43:49 +00:00
|
|
|
static extern IntPtr gtksharp_unichar_to_utf8_string (uint c);
|
|
|
|
|
|
|
|
public static char GUnicharToChar (uint ucs4_char)
|
|
|
|
{
|
2005-03-29 15:28:02 +00:00
|
|
|
if (ucs4_char == 0)
|
|
|
|
return (char) 0;
|
|
|
|
|
2004-08-17 20:43:49 +00:00
|
|
|
IntPtr raw_ret = gtksharp_unichar_to_utf8_string (ucs4_char);
|
|
|
|
string ret = GLib.Marshaller.PtrToStringGFree(raw_ret);
|
|
|
|
if (ret.Length > 1)
|
|
|
|
throw new ArgumentOutOfRangeException ("ucs4char is not representable by a char.");
|
|
|
|
|
|
|
|
return ret [0];
|
|
|
|
}
|
|
|
|
|
2004-12-07 19:03:55 +00:00
|
|
|
[DllImport("glibsharpglue-2")]
|
2004-12-20 22:05:21 +00:00
|
|
|
static extern uint glibsharp_utf16_to_unichar (ushort c);
|
2004-08-17 20:43:49 +00:00
|
|
|
|
|
|
|
public static uint CharToGUnichar (char c)
|
|
|
|
{
|
2004-12-20 22:05:21 +00:00
|
|
|
return glibsharp_utf16_to_unichar ((ushort) c);
|
2004-08-17 20:43:49 +00:00
|
|
|
}
|
|
|
|
|
2005-06-30 17:09:39 +00:00
|
|
|
public static IntPtr StructureToPtrAlloc (object o)
|
2005-03-04 18:59:09 +00:00
|
|
|
{
|
|
|
|
IntPtr result = Marshal.AllocHGlobal (Marshal.SizeOf (o));
|
|
|
|
Marshal.StructureToPtr (o, result, false);
|
|
|
|
return result;
|
|
|
|
}
|
2005-06-08 16:53:12 +00:00
|
|
|
|
|
|
|
public static Array ListToArray (ListBase list, System.Type type)
|
|
|
|
{
|
|
|
|
Array result = Array.CreateInstance (type, list.Count);
|
2005-06-08 17:29:48 +00:00
|
|
|
if (list.Count > 0)
|
|
|
|
list.CopyTo (result, 0);
|
2006-03-27 18:35:08 +00:00
|
|
|
|
|
|
|
if (type.IsSubclassOf (typeof (GLib.Opaque)))
|
|
|
|
list.elements_owned = false;
|
|
|
|
|
2005-06-08 16:53:12 +00:00
|
|
|
return result;
|
|
|
|
}
|
2003-05-29 Rachel Hestilow <rachel@nullenvoid.com>
* gconf/Value.cs: Update to use new string marshalling.
* generator/StringGen.cs, ConstStringGen.cs: Added.
* generator/IGeneratable.cs: Add new method ToNativeReturn.
* generator/CallbackGen.cs: Implement ToNativeReturn. Call
ToNativeReturn for the return statement. Fix a couple of
places where s_ret was being used incorrectly for m_ret.
* generator/ClassGen.cs, EnumGen.cs, ManualGen.cs,
SimpleGen.cs, StructBase.cs: Implement ToNativeReturn.
* generator/SignalHandler.cs: Call ToNativeReturn for the
return statement, instead of CallByName.
* generator/SymbolTable.cs: Use StringGen for gchar, char,
and gunichar, and ConstStringGen for their const variants.
Add a new method wrapper for ToNativeReturn.
(Trim): Add a special-case for const strings so that the
const is not stripped. Otherwise there is no way of
resolving the const case.
* glade/XML.custom: Update to use new string marshalling.
* glib/Marshaller.cs: Added.
* glib/GException.cs, Markup.cs, ObjectManager.cs,
Value.cs: Update to use new string marshalling.
* glib/Object.cs: Remove old g_type_name DllImport
as it is no longer used.
* glue/fileselection.c (gtksharp_file_selection_get_fileop_entry):
Mark this as const return.
* gtk/ColorSelection.custom, FileSelection.custom,
SelectionData.custom: Update to use new string marshalling.
svn path=/trunk/gtk-sharp/; revision=15286
2003-06-10 18:09:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|