Skip to content

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

Merged
merged 6 commits into from
May 17, 2023
Merged

Support nullptr testing #1805

merged 6 commits into from
May 17, 2023

Conversation

Smit-create
Copy link
Collaborator

Fixes #1781

@Smit-create Smit-create requested a review from certik May 13, 2023 10:50
@@ -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)
Copy link
Contributor

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 !=.

Copy link
Collaborator Author

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.

Copy link
Contributor

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.

@Smit-create
Copy link
Collaborator Author

@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

@czgdp1807
Copy link
Collaborator

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

@certik
Copy link
Contributor

certik commented May 16, 2023

I see, we need to figure out a robust solution in CPython that will always work. If we have to do the .value trick, then maybe that's what is needed. Otherwise we can create our own wrapper for CPtr to handle == correctly.

@czgdp1807
Copy link
Collaborator

Done in 1b162b9.

@czgdp1807 czgdp1807 marked this pull request as ready for review May 16, 2023 13:42
@Smit-create
Copy link
Collaborator Author

Thanks @czgdp1807!

Copy link
Contributor

@certik certik left a comment

Choose a reason for hiding this comment

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

Thanks!

@certik certik merged commit 8d679fa into lcompilers:main May 17, 2023
@Smit-create Smit-create deleted the i-1781 branch May 17, 2023 03:24
@Smit-create Smit-create mentioned this pull request May 18, 2023
25 tasks
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.

Add a test for testing a pointer for nullptr
3 participants