-
Notifications
You must be signed in to change notification settings - Fork 744
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
Support memory slicing #1151
base: dev
Are you sure you want to change the base?
Support memory slicing #1151
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.
Great idea!
|
||
return self.ql.mem.read(start, max(0, stop - start)) | ||
elif isinstance(key, int): | ||
return self.ql.mem.read(key, 1)[0] |
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.
This line returns an int
, not bytearray
, which is somewhat counterintuitive, inconsistent with the case where a slice is given as argument, and goes against the type annotation. I think you should remove the [0]
. Also, I'm not sure why this code uses self.ql.mem
instead of self
. In this class, they reference / point to the same thing, right?
return self.ql.mem.read(key, 1)[0] | |
return self.read(key, 1) |
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.
This line returns an
int
, notbytearray
, which is somewhat counterintuitive. I think you should remove the[0]
.
Because we (try to) provide the same interface as bytearray
, e.g.:
In [1]: a = bytearray(b"\x01\x02")
In [2]: type(a[0])
Out[2]: int
In [3]:
Also, I'm not sure why this code uses
self.ql.mem
instead ofself
. In this class, they reference / point to the same thing, right?
Good point.
Checklist
Which kind of PR do you create?
Coding convention?
Extra tests?
Changelog?
Target branch?
One last thing
This is one of several efforts to make the current wrapper more pythonic to fix unicorn-engine/unicorn#201.
This PR makes
ql.mem
support slicing.