| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Nice! I will keep this open for a day or two in case @JukkaL has some comments.
Sorry, something went wrong.
There was a problem hiding this comment.
On the second look I think I have some more questions.
Sorry, something went wrong.
| // int.to_bytes(length, byteorder, signed=False) | ||
| PyObject *CPyTagged_ToBytes(CPyTagged self, Py_ssize_t length, PyObject *byteorder, int signed_flag) { | ||
| PyObject *pyint = CPyTagged_StealAsObject(self); | ||
| if (!PyLong_Check(pyint)) { |
There was a problem hiding this comment.
On the second thought, all these type checks look unnecessary, normally Python wrappers should do them. You can probably verify this by adding some run tests with Anys in them.
Sorry, something went wrong.
There was a problem hiding this comment.
what, like this?
def f(x: Any) -> bytes:
return int.to_bytes(x)
Sorry, something went wrong.
Sorry, something went wrong.
There was a problem hiding this comment.
I think CPyTagged_StealAsObject is not correct there, since it will transfer the ownership of the parameter, and this can cause a double free. CPyTagged_AsObject will return a new reference which you can decref at the end of the function.
Sorry, something went wrong.
There was a problem hiding this comment.
what, like this?
First, not just the self, second I think you should try more something like this
def to_bytes(n: int, length: int, byteorder: str = "little", signed: bool = False) -> bytes:
return n.to_bytes(length, byteorder, signed=signed)
x: Any = "no"
bad: Any = "way"
to_bytes(x, bad)and check that a TypeError will be given even before getting to your specialized code.
Sorry, something went wrong.
There was a problem hiding this comment.
I could implement this test, but wouldn't we then just be testing the standard python-wrapper type validation functionality, as opposed to some specific functionality related to this PR?
I can still add the tests accordingly, I just want to make sure we have the same understanding of things before I proceed.
Sorry, something went wrong.
There was a problem hiding this comment.
I could implement this test, but wouldn't we then just be testing the standard python-wrapper type validation functionality, as opposed to some specific functionality related to this PR?
That's exactly my point. This whole thread started from me saying "On the second thought, all these type checks look unnecessary, normally Python wrappers should do them. You can probably verify this by adding some run tests with Anys in them."
Sorry, something went wrong.
There was a problem hiding this comment.
To be clear, you don't need to add the tests to the PR, but you can (if you want) to check that I am right by running such a test locally.
Sorry, something went wrong.
| assert to_bytes(255, 2, "big") == b'\x00\xff' | ||
| assert to_bytes(255, 2, "little") == b'\xff\x00' | ||
| assert to_bytes(-1, 2, "big", True) == b'\xff\xff' | ||
| assert to_bytes(0, 1, "big") == b'\x00' |
There was a problem hiding this comment.
Maybe also test calling to_bytes() function from interpreted code.
Sorry, something went wrong.
There was a problem hiding this comment.
@ilevkivskyi how would I implement that? Is there a good example I can look from?
Sorry, something went wrong.
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Okay, with the specializer this becomes a 9% improvement for all cases |
Sorry, something went wrong.
|
@BobTheBuidler just in case you didn't notice, some tests are failing now. |
Sorry, something went wrong.
|
@BobTheBuidler please ping me when this is ready for review/merge. |
Sorry, something went wrong.
@ilevkivskyi this open question is my only remaining blocker, unsure how to navigate this situation |
Sorry, something went wrong.
|
I don't know, maybe add some prints to specialize_int_to_bytes. For starter I think self is not included in CallExpr.args for methods, but maybe this is something else. |
Sorry, something went wrong.
* Fix int.to_bytes specialization arg handling * Restore specialize.py for to_bytes specialization fixes
There was a problem hiding this comment.
LG, thanks!
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This PR adds a new primitive for all arg combinations of int.to_bytes