Skip to content

Support nullptr testing - #1805

Merged
certik merged 6 commits into
lcompilers:mainfrom
Smit-create:i-1781
May 17, 2023
Merged

Support nullptr testing#1805
certik merged 6 commits into
lcompilers:mainfrom
Smit-create:i-1781

Conversation

@Smit-create

Copy link
Copy Markdown
Collaborator

Fixes#1781

@Smit-create
Smit-create requested a review from certikMay 13, 2023 10:50
Comment threadintegration_tests/bindc_01.py
Comment threadsrc/libasr/ASR.asdl
| 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
Copy Markdown
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
Copy Markdown
CollaboratorAuthor

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
Copy Markdown
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.

Comment threadintegration_tests/bindc_01.py
@Smit-create

Copy link
Copy Markdown
CollaboratorAuthor

@certik The current diff does work fine for C and LLVM but fails in CPython because of two object comparisons.

>>>importctypes>>>x=ctypes.c_void_p()
>>>y=ctypes.c_void_p()
>>>x==yFalse

@czgdp1807

Copy link
Copy Markdown
Collaborator

Here you go,

(lp) 18:59:02:~/lpython_project/lpython%pythonPython3.10.4|packagedbyconda-forge| (main, Mar242022, 17:39:37) [Clang12.0.1 ] ondarwinType"help", "copyright", "credits"or"license"formoreinformation.
>>>importctypes>>>x=ctypes.c_void_p()
>>>y=ctypes.c_void_p()
>>>x.value==y.valueTrue

@certik

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Collaborator

Done in 1b162b9.

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

Copy link
Copy Markdown
CollaboratorAuthor

Thanks @czgdp1807!

@certikcertik left a comment

Copy link
Copy Markdown
Contributor

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:mainMay 17, 2023
@Smit-create
Smit-create deleted the i-1781 branch May 17, 2023 03:24
@Smit-createSmit-create mentioned this pull request May 18, 2023
25 tasks
Sign up for freeto 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

@Smit-create@czgdp1807@certik