Skip to content

Synchronize ByteString and String modules #228

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 2 commits into from
Jul 17, 2022
Merged

Conversation

hasufell
Copy link
Member

And fix free-bug in 'putEnv'. Fixes #68

@hasufell hasufell requested review from Bodigrim and hs-viktor July 16, 2022 23:05
@hasufell hasufell added this to the 2.8.0.0 milestone Jul 16, 2022
@hasufell hasufell force-pushed the sync-bs branch 2 times, most recently from 4550490 to 707737c Compare July 17, 2022 00:12
#endif

-- |'putEnv' function takes an argument of the form @name=value@
-- and is equivalent to @setEnv(key,value,True{-overwrite-})@.

putEnv :: ByteString {- ^ "key=value" -} -> IO ()
putEnv keyvalue = B.useAsCString keyvalue $ \s ->
throwErrnoIfMinus1_ "putenv" (c_putenv s)
putEnv (PS fp _ l) = withForeignPtr fp $ \p -> do
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this code really going to be built against ancient bytestring versions that have PS instead of BS? And if it were, it would be very wrong to ignore the offset. Use BS instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

Using BS would require build-depends: bytestring >= 0.11. That's acceptable, but it's easy to be more conservative with

putEnv (PS fp o l) = withForeignPtr fp $ \p -> do ... (p `plusPtr` o)

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry... it was almost 2 am at night.

Copy link
Contributor

@Bodigrim Bodigrim left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this @hasufell, the bug looked grave. Would it be possible to add a regression test?

Comment on lines +18 to +32
test :: TestTree
test = testCase "putEnv" $ do
performMinorGC
env <- System.Posix.Env.ByteString.getEnv (fromString "foo")
performMinorGC
print env
env <- System.Posix.Env.ByteString.getEnv (fromString "foo")
performMinorGC
print env
env <- System.Posix.Env.ByteString.getEnv (fromString "foo")
performMinorGC
print env
env <- System.Posix.Env.ByteString.getEnv (fromString "foo")
print env
env @?= Just (fromString "bar")
Copy link
Member Author

Choose a reason for hiding this comment

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

The failure is a little hard to trigger... but this worked for me and the prints are necessary.

@hasufell hasufell requested a review from Bodigrim July 17, 2022 12:33
@Bodigrim Bodigrim merged commit 5fd5305 into haskell:master Jul 17, 2022
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.

String and ByteString implementations have desynchronized
3 participants