-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Converted Memory
into a readonly struct
#224
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it! (Maybe this could later also be done for other Extern
types.)
One minor thing to note is that the Memory
struct size (Unsafe.SizeOf<Memory>()
) is currently 56
(on 64-bit) due to the fields Minimum
, Maximum
and Is64Bit
, which can also be retrieved from the ExternMemory
. Removing the fields would reduce the struct size to 24
, in which case the properties would need to retrieve the values from the ExternMemory
on every call. But I'm not sure how expensive that is, so it's probably OK to keep it in the struct.
Also note that because Memory
implements an interface (IExternal
), this will cause boxing to occur where this is used, for example with Linker.Define(string module, string name, object item)
, so an additional allocation will now occur there.
If desired, I think this could be avoided by having an internal Linker.Define(string, string, Store store, Extern extern)
, and then overloads for the struct types like Linker.Define(string, string, Memory)
that calls it.
Thanks!
If it's just an internal interface I would change it to |
That sounds reasonable to me! |
MacOS CI failure is a bit cryptic, I'm hoping it's just another transient error. |
Hi, Can you reset the branch to commit 7e2d02a and force-push it (as I think that was the intended commit)? |
20e20ca
to
7e2d02a
Compare
Thanks for the hint @kpreisser, I didn't notice that the history was in such a messy state! Doing as you suggested has fixed it. |
Unfortunately I don't have access to a Mac to investigate the test issues. There's no detail in the log on what the problem might be either :/ |
I'm also not sure why it's crashing, but maybe it is caused by/related to the
Thanks! |
After skipping some tests and commenting them back in one by one I've narrowed it down to this test: [Fact]
public void AccessDefaultThrows()
{
var memory = default(Memory);
Assert.Throws<NullReferenceException>(() => memory.GetLength());
} I added this test to reproduce the problem: [Fact]
public void TestMacOsCI()
{
try
{
object? o = null;
o.Equals(o).Should().BeTrue();
}
catch (NullReferenceException)
{
return;
}
Assert.False(true);
} This crashes the test runner! |
Superseded by #235, which allows |
This is a demonstration of what's involved with converting
Memory
into areadonly struct
, as discussed in (#219 (review)). As you can see this was almost no work. The bulk of the changes are fixing the tests.My only concern with this is that it is now possible to call things on a
default(Memory)
, which of course would have simply triggered a null reference exception before. I've checked through and I think it's safe in this case because everything usesstore.Context
which will trigger a null reference exception.Thoughts?