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

Allow to use java.util.zip in Windows #2361

Merged
merged 9 commits into from Sep 17, 2021

Conversation

WojciechMazur
Copy link
Contributor

@WojciechMazur WojciechMazur commented Sep 6, 2021

By default zlib on Unix uses different primitive types for its internal structs leading to undefined behaviour at runtime.
This PR adds conditional resolution of expected struct layout. Additionally, implicit ops were added to zlib structs allowing for usage of accessor methods instead of field indexes.

object zlibExt {
import zlib._

sealed trait z_stream
Copy link
Collaborator

Choose a reason for hiding this comment

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

The definition of z_stream here having the same name as type z_stream[UINT, ULONG] below is extremely confusing. It's basically impossible to tell which is which. Please use different names.

Furthermore, it seems that this z_stream is only used as a phantom type in an intersection Ptr[Byte with z_stream]. This is not guaranteed to keep working in Scala 3, since intersection types are commutative there. Do you really need a phantom type, here? If yes, use an uninstantiated abstract type member instead of a sealed trait.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The same issues exist with gz_header.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed the sealed trait z_stream the only reason for the usage of phantom was to increase type safety, however it's not really helping us with anything.
Now we define

type z_streamp = Ptr[z_stream[_, _]]
...
private[scalanative] type z_stream[UINT, ULONG] = CStruct14[...]

object z_stream {
def size: CSize = ???
} 

Is such naming fine or should I rename generic z_stream[_,_] to something else, eg. z_stream_impl[_,_]

@WojciechMazur WojciechMazur merged commit a3c99ed into scala-native:master Sep 17, 2021
@WojciechMazur WojciechMazur deleted the windows/04-zip branch December 24, 2021 05:17
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.

None yet

2 participants