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

[WIP] Fix memset, memcpy, memmove calls on Pointer type. #4611

Closed
wants to merge 1 commit into from

Conversation

akzhan
Copy link
Contributor

@akzhan akzhan commented Jun 23, 2017

Just note that it's short fix for #4589 only.

No generic SizeT, OffsetT introduced here.

src/pointer.cr Outdated
size.to_u32
end
{% end %}

Copy link
Member

Choose a reason for hiding this comment

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

Not needed. LibC::SizeT.new

Copy link
Contributor Author

@akzhan akzhan Jun 23, 2017

Choose a reason for hiding this comment

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

No. Intrinsics method signatures are not associated to LibC::SizeT.

This PR is short one, without changing of rules of the game.

Copy link
Member

Choose a reason for hiding this comment

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

No idea what you're talking about. Why spray the definition of size_t all over the codebase when it already exists.
Use LibC::SizeT.new instead of to_size_t and you don't need this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we need to introduce generic SizeT and OffsetT types, or change Intrinsics contracts, but it should be discussed and introduced by another PR.

This PR just fixes contract implementation.

@@ -242,7 +242,7 @@ struct Pointer(T)
raise ArgumentError.new("Negative count") if count < 0

if self.class == source.class
Intrinsics.memcpy(self.as(Void*), source.as(Void*), (count * sizeof(T)).to_u32, 0_u32, false)
Intrinsics.memcpy(self.as(Void*), source.as(Void*), count * sizeof(T), 0_u32, false)
Copy link
Contributor

@RX14 RX14 Jun 23, 2017

Choose a reason for hiding this comment

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

I have no idea why the CI isn't broken but isn't this passing 32bit ints to something expecting a U64?

@zatherz
Copy link
Contributor

zatherz commented Jun 23, 2017

Dislike this as it actually returns a different type depending on the architecture. I'd prefer a SizeT.

@akzhan akzhan changed the title Fix memset, memcpy, memmove calls on Pointer type. [WIP] Fix memset, memcpy, memmove calls on Pointer type. Jun 23, 2017
@akzhan
Copy link
Contributor Author

akzhan commented Jun 23, 2017

This is a palliative. Will rework using SizeT and OffsetT.

@akzhan akzhan closed this Jun 25, 2017
@ysbaddaden
Copy link
Contributor

Sorry, that doesn't solve anything. It still relies on count type, which is likely an Int32, then multiply by another int (whatever its type) that may overflow.

@konovod
Copy link
Contributor

konovod commented Jun 25, 2017

So it should be SizeT.new(count) * sizeof(T) ? Then count is still 32-bit, and result is SizeT (or whatever type will be choosen that match intrinsic param).

@akzhan
Copy link
Contributor Author

akzhan commented Jun 26, 2017

@konovod thanks. was fixed with #4624.

@ysbaddaden thanks too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants