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

Do expect/actual for shared code in Deflater #1434

Merged
merged 7 commits into from
Feb 18, 2024

Conversation

swankjesse
Copy link
Member

No description provided.

@swankjesse swankjesse marked this pull request as draft February 15, 2024 03:34
@swankjesse swankjesse changed the title Do expect/actual for shared code in Deflater WIP: Do expect/actual for shared code in Deflater Feb 15, 2024
@@ -13,8 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@file:JvmName("-DeflaterSinkExtensions")
Copy link
Member Author

Choose a reason for hiding this comment

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

extension moved to the multiplatform zlibMain source set

else -> null
}
zStream.avail_in = sourceByteCount.toUInt()
internal val dataProcessor: DataProcessor = object : DataProcessor() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Super annoying; I can’t extend DataProcessor in Kotlin/Native because that doesn’t match the inheritance hierarchy in Kotlin/JVM.

closed = true
actual constructor() : this(false)

@OptIn(UnsafeNumber::class)
Copy link
Member Author

Choose a reason for hiding this comment

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

These should be safe in practice! We don’t expose target-specific numbers in our public API

@swankjesse swankjesse changed the title WIP: Do expect/actual for shared code in Deflater Do expect/actual for shared code in Deflater Feb 15, 2024
@swankjesse swankjesse marked this pull request as ready for review February 15, 2024 04:20
* This class does not offer any partial flush mechanism. For best performance,
* only call [flush] when application behavior requires it.
*/
expect class DeflaterSink
Copy link
Member

Choose a reason for hiding this comment

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

Any reason to make these public? The JVM ones have to remain public for compatibility, but these don't expose any API on top of the underlying Sink.

Copy link
Member Author

Choose a reason for hiding this comment

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

This API is handy to implement web sockets, SPDY/3, and PNG. We might use it in a future multiplatform Paparazzi!

Copy link
Member

Choose a reason for hiding this comment

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

I'm referring specifically to the class. The extension below already provides access to the functionality (although its return type should probably be just Sink).

Copy link
Member Author

Choose a reason for hiding this comment

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

I’d like for it to remain public so we keep the option of having APIs like finishDeflate() public. Or APIs to supply a Dictionary mid-compression if that exotic feature is used.

}

private fun Deflater(nowrap: Boolean) = Deflater(Z_BEST_COMPRESSION, nowrap)
Copy link
Member

Choose a reason for hiding this comment

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

No way to put this default value onto the expect so you don't need to define this function?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not as far as I know.

> Task :okio:compileKotlinJvm FAILED
e: file:///Volumes/Development/okio/okio/src/jvmMain/kotlin/okio/-JvmPlatform.kt:45:1 Default argument values inside expect declaration 'Deflater' are not allowed if it is actualized via typealias. Possible fix is to remove default argument values in members:
    public constructor Deflater(level: Int = ..., nowrap: Boolean = ...)

@swankjesse swankjesse merged commit e941f18 into master Feb 18, 2024
11 checks passed
@swankjesse swankjesse deleted the jwilson.0214.deflate_expect_actual branch February 18, 2024 21:53
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