Closed ExPixel closed 4 years ago
Makes sense. Added a test to make sure that cs_insn
and Insn
always have the same size and alignment. It also checks the conversion itself.
@ExPixel I want you to know that I haven't forgotten about this PR--I'm just trying to convince myself that this is actually safe.
Admittedly, the slice::from_raw_parts
might be unnecessary and I might be able to get away with a couple of (still unsafe) casts using as
instead. I think that might actually be the recommended way of doing what amounts to the same thing and it's less error prone. I'll do that instead and update the PR.
Admittedly, the
slice::from_raw_parts
might be unnecessary and I might be able to get away with a couple of (still unsafe) casts usingas
instead. I think that might actually be the recommended way of doing what amounts to the same thing and it's less error prone. I'll do that instead and update the PR.
Great--could you also rebase your changes onto master (you don' need to squash)? I fixed some of the Cirrus CI config that fixes the FreeBSD tests.
@ExPixel the more I think about this, the more I think we should rely on the Deref
impl to cover what we want for Instructions
. There's no point in defining an .iter()
method or InstructionIterator
.
If you want, you can try tackling the cleanup. Otherwise, I'll do it myself in a follow-up PR.
repr(transparent)
wasn't stable when this logic was first implemented, but we may as well take advantage. :smile:
I'll look into cleaning up the uses of InstructionsIterator as well. I'll probably make another pull request for that in the next couple of days :smile:
Merged as 4e07963
(I squashed/merged manually)
Makes Insn transparent so that cs_insn can be safely converted to it. This makes it possible to just make Instructions deref to a slice of Insn so that is can be passed around more easily without an extra layer of indirection on top of the slice.
This is a small quality of life improvement that allows things like this: