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

Update to work with text >= 2.0.1 #16

Merged
merged 5 commits into from
Aug 14, 2022
Merged

Update to work with text >= 2.0.1 #16

merged 5 commits into from
Aug 14, 2022

Conversation

Mikolaj
Copy link
Collaborator

@Mikolaj Mikolaj commented Mar 21, 2022

This updates the package to compile with text-2.0, but with HEAD ghc-9.3.20220316 my test program (LambdaHack) segfaults, so I wasn't able to verify if it also works. If you do verify, please let me know.

Edit: of course this needs to be CPPd vs text-2.0.

src/SDL/Font.hs Outdated
@@ -244,14 +244,14 @@ blended (Font font) (V4 r g b a) text =

-- Analogous to Data.Text.Foreign.useAsPtr, just appends a null-byte.
-- FIXME: Is this even necessary?
withText :: Text -> (Ptr Word16 -> IO a) -> IO a
withText :: Text -> (Ptr Word8 -> IO a) -> IO a
Copy link
Member

Choose a reason for hiding this comment

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

That would be CString now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks a lot for the tips. Do you think we could just use Data.Text.Foreign.useAsPtr or something similar instead?

Copy link
Member

Choose a reason for hiding this comment

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

I have a similar issue with text-2 in dear-imgui. But I know from the code I need to append NUL in a few places here and there.

We need Data.Text.Foreign.useAsCString and there's haskell/text#254 already.

Copy link
Member

Choose a reason for hiding this comment

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

haskell/text#431 - it's on the books now.

Would it be reasonable to request text <2 || >= 2.1 and don't ship an own copy? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Amazing! Yes, procrastination works. :D

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I think it's reasonable to request text <2 || >= 2.1. I will do that myself. In dear-imgui, would that permit to change the condition in https://github.com/haskell-game/dear-imgui.hs/blob/main/src/DearImGui/Internal/Text.hs#L29-L50 to MIN_VERSION_text(2,0,1) and the first branch of the conditional to withCString = Data.Text.Foreign.withCString and then the second branch stays untouched?

src/SDL/Font.hs Outdated
withText text act =
allocaBytes len $ \ptr -> do
unsafeCopyToPtr text ptr
pokeByteOff ptr (len - 2) (0 :: CUShort)
pokeByteOff ptr (len - 2) (0 :: CChar)
Copy link
Member

Choose a reason for hiding this comment

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

len - 1

@dpwiz
Copy link
Member

dpwiz commented Mar 22, 2022

Also, you need to switch from renderUNICODE_XXX to renderUTF8_XXX to use text-2 data (in Haskell types and cbits/helpers.c).

@Mikolaj
Copy link
Collaborator Author

Mikolaj commented Aug 7, 2022

Also, you need to switch from renderUNICODE_XXX to renderUTF8_XXX to use text-2 data (in Haskell types and cbits/helpers.c).

Good catch. Actually cbits are fine, because they already include UTF8 as well.

… GHC 9.4.*"

This reverts commit d42d654.

We don't depend on text 2.1 in the end, 2.0.1 is enough and, while not
included in GHC 9.4 RC1, 2.0.1 can be taken from Hackage just fine,
to satisfy the constraint in .cabal.
@Mikolaj Mikolaj changed the title Update to work with text-2.0 Update to work with text >= 2.0.1 Aug 7, 2022
@Mikolaj
Copy link
Collaborator Author

Mikolaj commented Aug 14, 2022

No reviews with change requests, so I'm merging, :)

@Mikolaj Mikolaj merged commit 4a92a6a into master Aug 14, 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.

2 participants