Skip to content
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

Fix ReadOnlySpanGetReferenceAndReadInteger on BigEndian #2 #86323

Merged
merged 1 commit into from
May 16, 2023

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented May 16, 2023

No description provided.

@ghost
Copy link

ghost commented May 16, 2023

Tagging subscribers to this area: @dotnet/area-system-memory
See info in area-owners.md if you want to be subscribed.

Issue Details

null

Author: EgorBo
Assignees: EgorBo
Labels:

area-System.Memory

Milestone: -

@EgorBo
Copy link
Member Author

EgorBo commented May 16, 2023

/azp run runtime-community

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@EgorBo
Copy link
Member Author

EgorBo commented May 16, 2023

@stephentoub @akoeplinger PTAL, I was too overconfident in my Big Endian skills in #85969 (comment)

runtime-community (Build linux-s390x Release AllSubsets_Mono) is green in this PR

@EgorBo EgorBo marked this pull request as ready for review May 16, 2023 14:56
ref MemoryMarshal.GetReference("hello world 1".AsSpan())), 0)));

Assert.Equal(BitConverter.IsLittleEndian ?
0x6F_00_6C_00_6C_00_65_00 :
0x00_65_00_6C_00_6C_00_6F,
Unsafe.As<byte, long>(ref Unsafe.Add(ref Unsafe.As<char, byte>(
0x68_00_65_00_6C_00_6C_00,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not clear on why this is the right answer. Can you explain?

Copy link
Member Author

@EgorBo EgorBo May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is this:

// "hello world 2"
// LE: 68_00_65_00_6C_00_6C_00_6F_00_20_00_77_00_6F_00_72_00_6C_00_64_00_20_00_32_00
//        6F_00_6C_00_6C_00_65_00 (we read 8 bytes with offset = 1 bytes)
// 
//
// BE: 00_68_00_65_00_6C_00_6C_00_6F_00_20_00_77_00_6F_00_72_00_6C_00_64_00_20_00_32
//        68_00_65_00_6C_00_6C_00 (we read 8 bytes with offset = 1 bytes)
//

Console.WriteLine(
    BitConverter.ToString(
        Encoding.Unicode.GetBytes("hello world 2")).Replace("-", "_"));

Copy link
Member Author

@EgorBo EgorBo May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same picture for the int case (that worked):

// "hello world 1"
// LE: 68_00_65_00_6C_00_6C_00_6F_00_20_00_77_00_6F_00_72_00_6C_00_64_00_20_00_31_00
//     00_65_00_68 (read 4 bytes)
// 
//
// BE: 00_68_00_65_00_6C_00_6C_00_6F_00_20_00_77_00_6F_00_72_00_6C_00_64_00_20_00_31
//     00_68_00_65 (read 4 bytes)

so chars here have swapped order ('h' is 68_00 on LE and 00_68 on BE)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Thanks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephentoub can you approve then? 🙂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub wasn't letting me. Now it is. Done.

@stephentoub stephentoub merged commit eb983f2 into dotnet:main May 16, 2023
@EgorBo EgorBo deleted the fix-be-issue-2 branch May 16, 2023 21:49
@ghost ghost locked as resolved and limited conversation to collaborators Jun 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants