2004-02-04 Mike Kestner <mkestner@ximian.com>
* generator/CustomMarshalerGen.cs : impl MarshalReturnType. * generator/Method.cs : add CustomMarshalerGen return type handling. * generator/Property.cs : rework property type selection. * generator/SymbolTable.cs : add time_t mapping * glib/time_t_CustomMarshaler.cs : impl native to managed methods. * glue/time_t.c : remove debugging code. svn path=/trunk/gtk-sharp/; revision=22772
This commit is contained in:
parent
1a679f2356
commit
4251d47fe9
7 changed files with 77 additions and 49 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
2004-02-04 Mike Kestner <mkestner@ximian.com>
|
||||||
|
|
||||||
|
* generator/CustomMarshalerGen.cs : impl MarshalReturnType.
|
||||||
|
* generator/Method.cs : add CustomMarshalerGen return type handling.
|
||||||
|
* generator/Property.cs : rework property type selection.
|
||||||
|
* generator/SymbolTable.cs : add time_t mapping
|
||||||
|
* glib/time_t_CustomMarshaler.cs : impl native to managed methods.
|
||||||
|
* glue/time_t.c : remove debugging code.
|
||||||
|
|
||||||
2004-02-03 Mike Kestner <mkestner@ximian.com>
|
2004-02-03 Mike Kestner <mkestner@ximian.com>
|
||||||
|
|
||||||
* glib/List.cs : add a ctor overload to create empty lists with
|
* glib/List.cs : add a ctor overload to create empty lists with
|
||||||
|
|
|
@ -46,7 +46,7 @@ namespace GtkSharp.Generation {
|
||||||
}
|
}
|
||||||
public virtual string MarshalReturnType {
|
public virtual string MarshalReturnType {
|
||||||
get {
|
get {
|
||||||
return String.Empty;
|
return "[return:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(" + marshaler + "))]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -270,7 +270,10 @@ namespace GtkSharp.Generation {
|
||||||
import_sig += !IsShared && parms != null ? ", " : "";
|
import_sig += !IsShared && parms != null ? ", " : "";
|
||||||
import_sig += isig.ToString();
|
import_sig += isig.ToString();
|
||||||
sw.WriteLine("\t\t[DllImport(\"" + libname + "\")]");
|
sw.WriteLine("\t\t[DllImport(\"" + libname + "\")]");
|
||||||
sw.WriteLine("\t\tstatic extern " + safety + m_ret + " " + cname + "(" + import_sig + ");");
|
if (m_ret.StartsWith ("[return:"))
|
||||||
|
sw.WriteLine("\t\t" + m_ret + " static extern " + safety + s_ret + " " + cname + "(" + import_sig + ");");
|
||||||
|
else
|
||||||
|
sw.WriteLine("\t\tstatic extern " + safety + m_ret + " " + cname + "(" + import_sig + ");");
|
||||||
sw.WriteLine();
|
sw.WriteLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,26 +352,25 @@ namespace GtkSharp.Generation {
|
||||||
body.Initialize(gen_info, is_get, is_set, indent);
|
body.Initialize(gen_info, is_get, is_set, indent);
|
||||||
|
|
||||||
SymbolTable table = SymbolTable.Table;
|
SymbolTable table = SymbolTable.Table;
|
||||||
|
IGeneratable ret_igen = table [rettype];
|
||||||
|
|
||||||
sw.Write(indent + "\t\t\t");
|
sw.Write(indent + "\t\t\t");
|
||||||
if (m_ret == "void") {
|
if (m_ret == "void") {
|
||||||
sw.WriteLine(cname + call + ";");
|
sw.WriteLine(cname + call + ";");
|
||||||
|
} else if (ret_igen is ObjectGen || ret_igen is OpaqueGen) {
|
||||||
|
sw.WriteLine(m_ret + " raw_ret = " + cname + call + ";");
|
||||||
|
sw.WriteLine(indent +"\t\t\t" + s_ret + " ret = " + table.FromNativeReturn(rettype, "raw_ret") + ";");
|
||||||
|
if (table.IsOpaque (rettype))
|
||||||
|
sw.WriteLine(indent + "\t\t\tif (ret == null) ret = new " + s_ret + "(raw_ret);");
|
||||||
|
} else if (ret_igen is CustomMarshalerGen) {
|
||||||
|
sw.WriteLine(s_ret + " ret = " + cname + call + ";");
|
||||||
} else {
|
} else {
|
||||||
if (table.IsObject (rettype) || table.IsOpaque (rettype))
|
sw.WriteLine(m_ret + " raw_ret = " + cname + call + ";");
|
||||||
{
|
sw.Write(indent + "\t\t\t");
|
||||||
sw.WriteLine(m_ret + " raw_ret = " + cname + call + ";");
|
string raw_parms = "raw_ret";
|
||||||
sw.WriteLine(indent +"\t\t\t" + s_ret + " ret = " + table.FromNativeReturn(rettype, "raw_ret") + ";");
|
if (element_type != null)
|
||||||
if (table.IsOpaque (rettype))
|
raw_parms += ", typeof (" + element_type + ")";
|
||||||
sw.WriteLine(indent + "\t\t\tif (ret == null) ret = new " + s_ret + "(raw_ret);");
|
sw.WriteLine(s_ret + " ret = " + table.FromNativeReturn(rettype, raw_parms) + ";");
|
||||||
}
|
|
||||||
else {
|
|
||||||
sw.WriteLine(m_ret + " raw_ret = " + cname + call + ";");
|
|
||||||
sw.Write(indent + "\t\t\t");
|
|
||||||
string raw_parms = "raw_ret";
|
|
||||||
if (element_type != null)
|
|
||||||
raw_parms += ", typeof (" + element_type + ")";
|
|
||||||
sw.WriteLine(s_ret + " ret = " + table.FromNativeReturn(rettype, raw_parms) + ";");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
body.Finish (sw, indent);
|
body.Finish (sw, indent);
|
||||||
|
|
|
@ -91,22 +91,37 @@ namespace GtkSharp.Generation {
|
||||||
|
|
||||||
bool has_getter = false;
|
bool has_getter = false;
|
||||||
bool has_setter = false;
|
bool has_setter = false;
|
||||||
|
string getter_type = String.Empty;
|
||||||
|
string setter_type = String.Empty;
|
||||||
|
|
||||||
Method getter = container_type.GetMethod("Get" + Name);
|
Method getter = container_type.GetMethod("Get" + Name);
|
||||||
|
if (getter != null && getter.Validate () && getter.IsGetter)
|
||||||
|
getter_type = getter.ReturnType;
|
||||||
|
|
||||||
Method setter = container_type.GetMethod("Set" + Name);
|
Method setter = container_type.GetMethod("Set" + Name);
|
||||||
|
if (setter != null && setter.Validate () && setter.IsSetter)
|
||||||
|
setter_type = setter.Signature.Types;
|
||||||
|
|
||||||
if (getter != null && getter.Validate() && getter.IsGetter && getter.ReturnType == cs_type) {
|
if (getter_type != String.Empty && getter_type == setter_type) {
|
||||||
has_getter = true;
|
has_getter = has_setter = true;
|
||||||
getter.GenerateImport(sw);
|
getter.GenerateImport (sw);
|
||||||
}
|
setter.GenerateImport (sw);
|
||||||
if (setter != null && setter.Validate() && setter.IsSetter) {
|
cs_type = getter_type;
|
||||||
has_setter = true;
|
} else {
|
||||||
setter.GenerateImport(sw);
|
if (getter_type == cs_type) {
|
||||||
}
|
has_getter = true;
|
||||||
|
getter.GenerateImport(sw);
|
||||||
|
}
|
||||||
|
if (setter_type != String.Empty) {
|
||||||
|
has_setter = true;
|
||||||
|
setter.GenerateImport(sw);
|
||||||
|
}
|
||||||
|
|
||||||
if (has_setter && setter.Signature.Types != cs_type)
|
if (has_setter && setter_type != cs_type)
|
||||||
cs_type = setter.Signature.Types;
|
cs_type = setter_type;
|
||||||
else if (has_getter && getter.ReturnType != cs_type)
|
else if (has_getter && getter_type != cs_type)
|
||||||
cs_type = getter.ReturnType;
|
cs_type = getter_type;
|
||||||
|
}
|
||||||
|
|
||||||
sw.WriteLine();
|
sw.WriteLine();
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ namespace GtkSharp.Generation {
|
||||||
AddType (new SimpleGen ("GParamSpec", "IntPtr"));
|
AddType (new SimpleGen ("GParamSpec", "IntPtr"));
|
||||||
AddType (new SimpleGen ("gconstpointer", "IntPtr"));
|
AddType (new SimpleGen ("gconstpointer", "IntPtr"));
|
||||||
|
|
||||||
// AddType (new CustomMarshalerGen ("time_t", "System.DateTime", "GLib.time_t_CustomMarshaler"));
|
AddType (new CustomMarshalerGen ("time_t", "System.DateTime", "GLib.time_t_CustomMarshaler"));
|
||||||
AddType (new ManualGen ("GSList", "GLib.SList"));
|
AddType (new ManualGen ("GSList", "GLib.SList"));
|
||||||
AddType (new ManualGen ("GList", "GLib.List"));
|
AddType (new ManualGen ("GList", "GLib.List"));
|
||||||
AddType (new ManualGen ("GValue", "GLib.Value"));
|
AddType (new ManualGen ("GValue", "GLib.Value"));
|
||||||
|
|
|
@ -29,23 +29,19 @@ namespace GLib {
|
||||||
return marshaler;
|
return marshaler;
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport ("gtksharpglue")]
|
|
||||||
static extern int gtksharp_time_t_sizeof ();
|
|
||||||
|
|
||||||
[DllImport ("gtksharpglue")]
|
|
||||||
static extern void gtksharp_time_t_print (int time_t);
|
|
||||||
|
|
||||||
public IntPtr MarshalManagedToNative (object obj)
|
public IntPtr MarshalManagedToNative (object obj)
|
||||||
{
|
{
|
||||||
DateTime dt = (DateTime) obj;
|
DateTime dt = (DateTime) obj;
|
||||||
int size = Marshal.SizeOf (typeof (int)) + gtksharp_time_t_sizeof ();
|
int size = Marshal.SizeOf (typeof (int)) + GetNativeDataSize ();
|
||||||
IntPtr ptr = Marshal.AllocCoTaskMem (size);
|
IntPtr ptr = Marshal.AllocCoTaskMem (size);
|
||||||
IntPtr time_t_ptr = new IntPtr (ptr.ToInt32 () + Marshal.SizeOf (typeof(int)));
|
IntPtr time_t_ptr = new IntPtr (ptr.ToInt32 () + Marshal.SizeOf (typeof(int)));
|
||||||
|
|
||||||
int secs = dt.Subtract (local_epoch).Seconds + utc_offset;
|
int secs = dt.Subtract (local_epoch).Seconds + utc_offset;
|
||||||
Console.WriteLine ("Marshaling DateTime: " + dt);
|
if (GetNativeDataSize () == 4)
|
||||||
Marshal.WriteInt32 (time_t_ptr, secs);
|
Marshal.WriteInt32 (time_t_ptr, secs);
|
||||||
gtksharp_time_t_print (secs);
|
else if (GetNativeDataSize () == 8)
|
||||||
|
Marshal.WriteInt64 (time_t_ptr, secs);
|
||||||
|
else
|
||||||
|
throw new Exception ("Unexpected native size for time_t.");
|
||||||
return time_t_ptr;
|
return time_t_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,14 +53,26 @@ namespace GLib {
|
||||||
|
|
||||||
public object MarshalNativeToManaged (IntPtr data)
|
public object MarshalNativeToManaged (IntPtr data)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException ();
|
int secs;
|
||||||
|
if (GetNativeDataSize () == 4)
|
||||||
|
secs = Marshal.ReadInt32 (data);
|
||||||
|
else if (GetNativeDataSize () == 8)
|
||||||
|
secs = (int) Marshal.ReadInt64 (data);
|
||||||
|
else
|
||||||
|
throw new Exception ("Unexpected native size for time_t.");
|
||||||
|
|
||||||
|
TimeSpan span = new TimeSpan (secs - utc_offset);
|
||||||
|
return local_epoch.Add (span);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CleanUpManagedData (object obj) {}
|
public void CleanUpManagedData (object obj) {}
|
||||||
|
|
||||||
|
[DllImport ("gtksharpglue")]
|
||||||
|
static extern int gtksharp_time_t_sizeof ();
|
||||||
|
|
||||||
public int GetNativeDataSize ()
|
public int GetNativeDataSize ()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException ();
|
return gtksharp_time_t_sizeof ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
|
|
||||||
/* Forward declarations */
|
/* Forward declarations */
|
||||||
gint gtksharp_time_t_sizeof (void);
|
gint gtksharp_time_t_sizeof (void);
|
||||||
void gtksharp_time_t_print (time_t t);
|
|
||||||
|
|
||||||
gint
|
gint
|
||||||
gtksharp_time_t_sizeof ()
|
gtksharp_time_t_sizeof ()
|
||||||
|
@ -19,8 +18,3 @@ gtksharp_time_t_sizeof ()
|
||||||
return sizeof (time_t);
|
return sizeof (time_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
gtksharp_time_t_print (time_t t)
|
|
||||||
{
|
|
||||||
printf ("%s\n", ctime (&t));
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue