mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2024-12-23 00:25:27 +00:00
Setup safer function loading so the bindings can be used on older versions of Gtk
This commit is contained in:
parent
af97186201
commit
8b5cb38bcb
|
@ -61,8 +61,16 @@ class FuncLoader
|
|||
ret = Linux.dlsym(library, function);
|
||||
|
||||
if (ret == IntPtr.Zero)
|
||||
throw new EntryPointNotFoundException(function);
|
||||
Console.WriteLine("[WARNING] Function not found: " + function);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static T LoadFunction<T>(IntPtr procaddress)
|
||||
{
|
||||
if (procaddress == IntPtr.Zero)
|
||||
return default(T);
|
||||
|
||||
return Marshal.GetDelegateForFunctionPointer<T>(procaddress);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ namespace GtkSharp.Generation {
|
|||
void GenerateImport (StreamWriter sw)
|
||||
{
|
||||
sw.WriteLine("\t\tdelegate IntPtr d_{0}({1});", CName, Parameters.ImportSignature);
|
||||
sw.WriteLine("\t\tstatic d_{0} {0} = Marshal.GetDelegateForFunctionPointer<d_{0}>(FuncLoader.GetProcAddress(GLibrary.Load(\"{1}\"), \"{0}\"));", CName, LibraryName);
|
||||
sw.WriteLine("\t\tstatic d_{0} {0} = FuncLoader.LoadFunction<d_{0}>(FuncLoader.GetProcAddress(GLibrary.Load(\"{1}\"), \"{0}\"));", CName, LibraryName);
|
||||
sw.WriteLine();
|
||||
}
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ namespace GtkSharp.Generation {
|
|||
sw.WriteLine ("\tinternal class " + Name + "GType {");
|
||||
var funcname = Elem.GetAttribute("gtype");
|
||||
sw.WriteLine ("\t\tdelegate IntPtr d_" + funcname + "();");
|
||||
sw.WriteLine ("\t\tstatic d_" + funcname + " " + funcname + " = Marshal.GetDelegateForFunctionPointer<d_" + funcname + ">(FuncLoader.GetProcAddress(GLibrary.Load(\"" + LibraryName + "\"), \"" + funcname + "\"));");
|
||||
sw.WriteLine ("\t\tstatic d_" + funcname + " " + funcname + " = FuncLoader.LoadFunction<d_" + funcname + ">(FuncLoader.GetProcAddress(GLibrary.Load(\"" + LibraryName + "\"), \"" + funcname + "\"));");
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("\t\tpublic static GLib.GType GType {");
|
||||
sw.WriteLine ("\t\t\tget {");
|
||||
|
|
|
@ -196,7 +196,7 @@ namespace GtkSharp.Generation {
|
|||
sw.WriteLine("\t\tdelegate " + retval.CSType + " d_" + CName + "(" + import_sig + ");");
|
||||
else
|
||||
sw.WriteLine("\t\tdelegate " + retval.MarshalType + " d_" + CName + "(" + import_sig + ");");
|
||||
sw.WriteLine("\t\tstatic d_" + CName + " " + CName + " = Marshal.GetDelegateForFunctionPointer<d_" + CName + ">(FuncLoader.GetProcAddress(GLibrary.Load(\"" + LibraryName + "\"), \"" + CName + "\"));");
|
||||
sw.WriteLine("\t\tstatic d_" + CName + " " + CName + " = FuncLoader.LoadFunction<d_" + CName + ">(FuncLoader.GetProcAddress(GLibrary.Load(\"" + LibraryName + "\"), \"" + CName + "\"));");
|
||||
sw.WriteLine();
|
||||
}
|
||||
|
||||
|
|
|
@ -186,7 +186,7 @@ namespace GtkSharp.Generation {
|
|||
#endif
|
||||
if (set_gvalue != null) {
|
||||
sw.WriteLine("\t\tdelegate IntPtr d_{0}(ref GLib.Value val, IntPtr obj);", set_gvalue.CName);
|
||||
sw.WriteLine("\t\tstatic d_{0} {0} = Marshal.GetDelegateForFunctionPointer<d_{0}>(FuncLoader.GetProcAddress(GLibrary.Load(\"{1}\"), \"{0}\"));", set_gvalue.CName, LibraryName);
|
||||
sw.WriteLine("\t\tstatic d_{0} {0} = FuncLoader.LoadFunction<d_{0}>(FuncLoader.GetProcAddress(GLibrary.Load(\"{1}\"), \"{0}\"));", set_gvalue.CName, LibraryName);
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("\t\tpublic void SetGValue (ref GLib.Value val)");
|
||||
sw.WriteLine ("\t\t{");
|
||||
|
|
Loading…
Reference in a new issue