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

Integers treated as signed 16-bit values in Serializer #14

Closed
thielema opened this issue Sep 16, 2023 · 4 comments
Closed

Integers treated as signed 16-bit values in Serializer #14

thielema opened this issue Sep 16, 2023 · 4 comments

Comments

@thielema
Copy link
Collaborator

I hit a limit of 32768 objects in a large generated PDF. With 32768 objects or more the /Size entry in the trailer becomes negative.
The culprit is Serializer.cshortToString.
First, the foreign import is wrong because it pretends the number parameter would be Int, where in reality the corresponding C type is short, thus the Haskell foreign import must use CShort. But this happens to work by accident on my machine (little endian).
Second, the bigger problem is the choice of the short type. This is 16 bit on my machine. Why this restriction? Why call C functions at all? Are they significantly faster than the Haskell formatting functions?

@thielema
Copy link
Collaborator Author

There is also a problem with convertFloat. It assumes at most 12 characters (minus one terminating null byte) in the formatted string. This can easily be exceeded using a sufficiently large Float number. However, the Haskell code must assume any maximum number of characters for allocating a buffer for the formatted number.
I think the best is to get rid of the C code completely.

@hsyl20
Copy link
Owner

hsyl20 commented Sep 18, 2023

It looks reasonable to get rid of C code. Could you update the PR? Thanks!

@thielema
Copy link
Collaborator Author

Removed C code. Checked that demo.pdf stays the same.

@hsyl20
Copy link
Owner

hsyl20 commented Sep 18, 2023

Thanks! It's merged and released https://hackage.haskell.org/package/HPDF-1.6.2

@hsyl20 hsyl20 closed this as completed Sep 18, 2023
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

No branches or pull requests

2 participants