-
Notifications
You must be signed in to change notification settings - Fork 92
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
Conversation
4550490
to
707737c
Compare
System/Posix/Env/ByteString.hsc
Outdated
#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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this 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?
And fix free-bug in 'putEnv'. Fixes haskell#68
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") |
There was a problem hiding this comment.
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 print
s are necessary.
And fix free-bug in 'putEnv'. Fixes #68