Skip to content
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

Strings with zeros inside are inconsistent between refc and other backends #3158

Open
buzden opened this issue Dec 5, 2023 · 2 comments
Open
Labels
backend: refc C with reference counting backend implem: string status: confirmed bug Something isn't working

Comments

@buzden
Copy link
Contributor

buzden commented Dec 5, 2023

Steps to Reproduce

Consider the following program

main : IO ()
main = do
  printLn $ String.length "ab"
  printLn $ String.length "a\0b"

and run is with different backends:

$ IDRIS2_CG=chez idris2 --exec main Main.idr
$ IDRIS2_CG=racket idris2 --exec main Main.idr
$ IDRIS2_CG=refc idris2 --exec main Main.idr
$ IDRIS2_CG=node idris2 --exec main Main.idr

Expected Behavior

All backends would give a consistent output, presumably

2
3

Observed Behavior

chez, racket and node give

2
3

and refc gives

2
1
@andrevidela
Copy link
Collaborator

oh boy I was waiting for this to happen, exciting

@seagull-kamome
Copy link
Contributor

I have started experimenting with having the length information in the Value_String. The code can be found at https://github.com/seagull-kamome/Idris2/tree/issue3161.

I couldn't figure out a good way to preserve information such as length and memory ownership in FFI, so I used ugly method to handle fastPack, fastUnpack and fastConcat. At least, it seems to work as well, but I have no clue this method is always safe at all backends.
If we want to hide Value_String from the eyes of the C library and keep compatibility, we will need some way to switch the calling convention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: refc C with reference counting backend implem: string status: confirmed bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants