Fix loading of resources if jit inlines method (#328)

Added no inlining attribute for methods with Assembly.GetCallingAssembly() so caller assembly is correct if jit want to inline.
See https://github.com/picoe/Eto/pull/2049.
This commit is contained in:
zii-dmg 2022-01-27 23:49:41 +03:00 committed by GitHub
parent 0c5bd3f471
commit e48e6e0380
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 10 deletions

View file

@ -35,6 +35,7 @@
namespace Gdk { namespace Gdk {
using System; using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
public partial class Pixbuf { public partial class Pixbuf {
@ -95,6 +96,7 @@ namespace Gdk {
} }
} }
[MethodImpl(MethodImplOptions.NoInlining)]
public Pixbuf (System.Reflection.Assembly assembly, string resource) : base (IntPtr.Zero) public Pixbuf (System.Reflection.Assembly assembly, string resource) : base (IntPtr.Zero)
{ {
using (PixbufLoader pl = new PixbufLoader (assembly == null ? System.Reflection.Assembly.GetCallingAssembly () : assembly, resource)) { using (PixbufLoader pl = new PixbufLoader (assembly == null ? System.Reflection.Assembly.GetCallingAssembly () : assembly, resource)) {
@ -102,6 +104,7 @@ namespace Gdk {
} }
} }
[MethodImpl(MethodImplOptions.NoInlining)]
public Pixbuf (System.Reflection.Assembly assembly, string resource, int width, int height) : base (IntPtr.Zero) public Pixbuf (System.Reflection.Assembly assembly, string resource, int width, int height) : base (IntPtr.Zero)
{ {
using (PixbufLoader pl = new PixbufLoader (assembly == null ? System.Reflection.Assembly.GetCallingAssembly () : assembly, resource, width, height)) { using (PixbufLoader pl = new PixbufLoader (assembly == null ? System.Reflection.Assembly.GetCallingAssembly () : assembly, resource, width, height)) {
@ -123,6 +126,7 @@ namespace Gdk {
} }
} }
[MethodImpl(MethodImplOptions.NoInlining)]
static public Pixbuf LoadFromResource (string resource) static public Pixbuf LoadFromResource (string resource)
{ {
return new Pixbuf (System.Reflection.Assembly.GetCallingAssembly (), resource); return new Pixbuf (System.Reflection.Assembly.GetCallingAssembly (), resource);

View file

@ -21,6 +21,7 @@
namespace Gdk { namespace Gdk {
using System; using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
public partial class PixbufAnimation { public partial class PixbufAnimation {
@ -46,6 +47,7 @@ namespace Gdk {
} }
} }
[MethodImpl(MethodImplOptions.NoInlining)]
public PixbufAnimation (System.Reflection.Assembly assembly, string resource) : base (IntPtr.Zero) public PixbufAnimation (System.Reflection.Assembly assembly, string resource) : base (IntPtr.Zero)
{ {
if (assembly == null) if (assembly == null)
@ -56,6 +58,7 @@ namespace Gdk {
} }
} }
[MethodImpl(MethodImplOptions.NoInlining)]
static public PixbufAnimation LoadFromResource (string resource) static public PixbufAnimation LoadFromResource (string resource)
{ {
return new PixbufAnimation (System.Reflection.Assembly.GetCallingAssembly (), resource); return new PixbufAnimation (System.Reflection.Assembly.GetCallingAssembly (), resource);

View file

@ -24,6 +24,7 @@
namespace Gdk { namespace Gdk {
using System; using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
public partial class PixbufLoader { public partial class PixbufLoader {
@ -96,6 +97,7 @@ namespace Gdk {
InitFromStream(stream); InitFromStream(stream);
} }
[MethodImpl(MethodImplOptions.NoInlining)]
public PixbufLoader (System.Reflection.Assembly assembly, string resource) : this () public PixbufLoader (System.Reflection.Assembly assembly, string resource) : this ()
{ {
InitFromAssemblyResource(assembly == null ? System.Reflection.Assembly.GetCallingAssembly () : assembly, resource); InitFromAssemblyResource(assembly == null ? System.Reflection.Assembly.GetCallingAssembly () : assembly, resource);
@ -117,6 +119,7 @@ namespace Gdk {
} }
} }
[MethodImpl(MethodImplOptions.NoInlining)]
public PixbufLoader (System.Reflection.Assembly assembly, string resource, int width, int height) : this () public PixbufLoader (System.Reflection.Assembly assembly, string resource, int width, int height) : this ()
{ {
SetSize(width, height); SetSize(width, height);
@ -137,18 +140,16 @@ namespace Gdk {
} }
} }
public PixbufLoader (byte[] buffer, int width, int height) : this() public PixbufLoader (byte[] buffer, int width, int height) : this()
{ {
SetSize(width, height); SetSize(width, height);
InitFromBuffer(buffer); InitFromBuffer(buffer);
} }
[MethodImpl(MethodImplOptions.NoInlining)]
static public PixbufLoader LoadFromResource (string resource) static public PixbufLoader LoadFromResource (string resource)
{ {
return new PixbufLoader (System.Reflection.Assembly.GetCallingAssembly (), resource); return new PixbufLoader (System.Reflection.Assembly.GetCallingAssembly (), resource);
} }
} }
} }

View file

@ -28,6 +28,7 @@ namespace Gtk {
using System; using System;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
@ -175,15 +176,18 @@ namespace Gtk {
TranslationDomain = translation_domain; TranslationDomain = translation_domain;
} }
[MethodImpl(MethodImplOptions.NoInlining)]
public Builder (string resource_name) : this (Assembly.GetCallingAssembly (), resource_name, null) public Builder (string resource_name) : this (Assembly.GetCallingAssembly (), resource_name, null)
{ {
} }
[MethodImpl(MethodImplOptions.NoInlining)]
public Builder (string resource_name, string translation_domain) public Builder (string resource_name, string translation_domain)
: this (Assembly.GetCallingAssembly (), resource_name, translation_domain) : this (Assembly.GetCallingAssembly (), resource_name, translation_domain)
{ {
} }
[MethodImpl(MethodImplOptions.NoInlining)]
public Builder (Assembly assembly, string resource_name, string translation_domain) : this () public Builder (Assembly assembly, string resource_name, string translation_domain) : this ()
{ {
if (GetType() != typeof (Builder)) if (GetType() != typeof (Builder))

View file

@ -3,11 +3,14 @@ namespace Gtk
using System; using System;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
public partial class CssProvider public partial class CssProvider
{ {
[MethodImpl(MethodImplOptions.NoInlining)]
public bool LoadFromResource(string resource) => LoadFromResource(Assembly.GetCallingAssembly(), resource); public bool LoadFromResource(string resource) => LoadFromResource(Assembly.GetCallingAssembly(), resource);
[MethodImpl(MethodImplOptions.NoInlining)]
public bool LoadFromResource(Assembly assembly, string resource) public bool LoadFromResource(Assembly assembly, string resource)
{ {
if (assembly == null) if (assembly == null)

View file

@ -23,6 +23,7 @@ namespace Gtk {
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
public partial class Image { public partial class Image {
@ -83,6 +84,7 @@ namespace Gtk {
LoadFromStream (stream); LoadFromStream (stream);
} }
[MethodImpl(MethodImplOptions.NoInlining)]
public Image (System.Reflection.Assembly assembly, string resource) : this () public Image (System.Reflection.Assembly assembly, string resource) : this ()
{ {
if (assembly == null) if (assembly == null)
@ -95,6 +97,7 @@ namespace Gtk {
LoadFromStream (s); LoadFromStream (s);
} }
[MethodImpl(MethodImplOptions.NoInlining)]
static public Image LoadFromResource (string resource) static public Image LoadFromResource (string resource)
{ {
return new Image (System.Reflection.Assembly.GetCallingAssembly (), resource); return new Image (System.Reflection.Assembly.GetCallingAssembly (), resource);

View file

@ -21,10 +21,12 @@
namespace Gtk { namespace Gtk {
using System; using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
public partial class UIManager { public partial class UIManager {
[MethodImpl(MethodImplOptions.NoInlining)]
public uint AddUiFromResource (string resource) public uint AddUiFromResource (string resource)
{ {
if (resource == null) if (resource == null)