-
Notifications
You must be signed in to change notification settings - Fork 170
Support nullptr testing #1805
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 nullptr testing #1805
Conversation
@@ -277,6 +277,8 @@ expr | |||
| StringOrd(expr arg, ttype type, expr? value) | |||
| StringChr(expr arg, ttype type, expr? value) | |||
|
|||
| CPtrCompare(expr left, cmpop op, expr right, ttype type, expr? value) |
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.
The cmpop
has various things like >
. What does that mean for CPtr
? I think we only want ==
and !=
.
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.
C has pointer comparisons for different cmpop
as seen here.
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.
I see. We can allow it in ASR, since eventually we want to have a C frontend too. But in LPython I would mainly support ==
and !=
for now for CPtr. The other ones we can, but don't have to right now.
@certik The current diff does work fine for C and LLVM but fails in CPython because of two object comparisons. >>> import ctypes
>>> x = ctypes.c_void_p()
>>> y = ctypes.c_void_p()
>>> x == y
False |
Here you go, (lp) 18:59:02:~/lpython_project/lpython % python
Python 3.10.4 | packaged by conda-forge | (main, Mar 24 2022, 17:39:37) [Clang 12.0.1 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>> x = ctypes.c_void_p()
>>> y = ctypes.c_void_p()
>>> x.value == y.value
True |
I see, we need to figure out a robust solution in CPython that will always work. If we have to do the |
Done in 1b162b9. |
Thanks @czgdp1807! |
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.
Thanks!
Fixes #1781