Idris2 icon indicating copy to clipboard operation
Idris2 copied to clipboard

`String`s with zeros inside are inconsistent between refc and other backends

Open buzden opened this issue 1 year ago • 2 comments

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

buzden avatar Dec 05 '23 13:12 buzden

oh boy I was waiting for this to happen, exciting

andrevidela avatar Dec 05 '23 13:12 andrevidela

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.

seagull-kamome avatar Jan 31 '24 10:01 seagull-kamome