Skip to content

Commit

Permalink
KTOR-6354 Revert 1.9.10 Kotlin update (#3785)
Browse files Browse the repository at this point in the history
  • Loading branch information
e5l committed Nov 3, 2023
1 parent 2d0ddda commit 89805f7
Show file tree
Hide file tree
Showing 103 changed files with 156 additions and 416 deletions.
15 changes: 5 additions & 10 deletions .idea/runConfigurations/All_Tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ apply(from = "gradle/compatibility.gradle")

plugins {
id("org.jetbrains.dokka") version "1.7.20" apply false
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.13.2"
id("kotlinx-atomicfu") version "0.22.0" apply false
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.12.1"
id("kotlinx-atomicfu") version "0.19.0" apply false
id("com.osacky.doctor") version "0.8.1"
}

Expand Down
4 changes: 2 additions & 2 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ sourceSets.main {
val ktor_version = "2.3.2"

dependencies {
implementation(kotlin("gradle-plugin", "1.9.10"))
implementation(kotlin("serialization", "1.9.10"))
implementation(kotlin("gradle-plugin", "1.8.22"))
implementation(kotlin("serialization", "1.8.22"))

val ktlint_version = libs.versions.ktlint.version.get()
implementation("org.jmailen.gradle:kotlinter-gradle:$ktlint_version")
Expand Down
12 changes: 0 additions & 12 deletions buildSrc/src/main/kotlin/Publication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,5 @@ fun Project.configurePublication() {
gpgAgentLock.unlock()
}
}

val publishLinuxX64PublicationToMavenRepository = tasks.findByName("publishLinuxX64PublicationToMavenRepository")
val signLinuxArm64Publication = tasks.findByName("signLinuxArm64Publication")
if (publishLinuxX64PublicationToMavenRepository != null && signLinuxArm64Publication != null) {
publishLinuxX64PublicationToMavenRepository.dependsOn(signLinuxArm64Publication)
}

val publishLinuxArm64PublicationToMavenRepository = tasks.findByName("publishLinuxArm64PublicationToMavenRepository")
val signLinuxX64Publication = tasks.findByName("signLinuxX64Publication")
if (publishLinuxArm64PublicationToMavenRepository != null && signLinuxX64Publication != null) {
publishLinuxArm64PublicationToMavenRepository.dependsOn(signLinuxX64Publication)
}
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ kotlin.native.binary.memoryModel=experimental

kotlin_version=1.8.22
coroutines_version=1.7.1
atomicfu_version=0.22.0
atomicfu_version=0.19.0
slf4j_version=1.7.36
junit_version=4.13.2
logback_version=1.2.11
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[versions]
kotlin-version = "1.8.22"
kotlinx-html-version = "0.9.1"
coroutines-version = "1.7.3"
atomicfu-version = "0.22.0"
coroutines-version = "1.7.1"
atomicfu-version = "0.19.0"
serialization-version = "1.5.1"
validator-version = "0.8.0"
ktlint-version = "3.15.0"
Expand Down
1 change: 0 additions & 1 deletion ktor-client/ktor-client-core/api/ktor-client-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ public final class io/ktor/client/engine/ProxyType : java/lang/Enum {
public static final field HTTP Lio/ktor/client/engine/ProxyType;
public static final field SOCKS Lio/ktor/client/engine/ProxyType;
public static final field UNKNOWN Lio/ktor/client/engine/ProxyType;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Lio/ktor/client/engine/ProxyType;
public static fun values ()[Lio/ktor/client/engine/ProxyType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import libcurl.*
@EagerInitialization
private val curlGlobalInitReturnCode = curlInitBridge()

@OptIn(ExperimentalForeignApi::class)
internal fun curlInitBridge(): Int = curl_global_init(CURL_GLOBAL_ALL.convert()).convert()

@OptIn(ExperimentalStdlibApi::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ internal class CurlProcessor(coroutineContext: CoroutineContext) {
}
}

@OptIn(ExperimentalForeignApi::class)
private suspend fun drainRequestQueue(api: CurlMultiApiHandler) {
while (true) {
val container = if (api.hasHandlers()) {
Expand Down Expand Up @@ -93,7 +92,6 @@ internal class CurlProcessor(coroutineContext: CoroutineContext) {
}
}

@OptIn(ExperimentalForeignApi::class)
private fun cancelRequest(easyHandle: EasyHandle, cause: Throwable) {
curlScope.launch {
curlApi!!.cancelRequest(easyHandle, cause)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,59 +14,50 @@ import libcurl.*

// These should have been CPointer<CURL> and CPointer<CURLM>, I suppose,
// but somehow cinterop tool makes them just opaque pointers.
@OptIn(ExperimentalForeignApi::class)

internal typealias EasyHandle = COpaquePointer

@OptIn(ExperimentalForeignApi::class)
internal typealias MultiHandle = COpaquePointer

@OptIn(ExperimentalForeignApi::class)
internal fun CURLMcode.verify() {
if (this != CURLM_OK) {
@Suppress("DEPRECATION")
throw CurlIllegalStateException("Unexpected curl verify: ${curl_multi_strerror(this)?.toKString()}")
}
}

@OptIn(ExperimentalForeignApi::class)
internal fun CURLcode.verify() {
if (this != CURLE_OK) {
@Suppress("DEPRECATION")
throw CurlIllegalStateException("Unexpected curl verify: ${curl_easy_strerror(this)?.toKString()}")
}
}

@OptIn(ExperimentalForeignApi::class)
internal fun EasyHandle.option(option: CURLoption, optionValue: Int) {
curl_easy_setopt(this, option, optionValue).verify()
}

@OptIn(ExperimentalForeignApi::class)
internal fun EasyHandle.option(option: CURLoption, optionValue: Long) {
curl_easy_setopt(this, option, optionValue).verify()
}

@OptIn(ExperimentalForeignApi::class)
internal fun EasyHandle.option(option: CURLoption, optionValue: CPointer<*>) {
curl_easy_setopt(this, option, optionValue).verify()
}

@OptIn(ExperimentalForeignApi::class)
internal fun EasyHandle.option(option: CURLoption, optionValue: CValuesRef<*>) {
curl_easy_setopt(this, option, optionValue).verify()
}

@OptIn(ExperimentalForeignApi::class)
internal fun EasyHandle.option(option: CURLoption, optionValue: String) {
curl_easy_setopt(this, option, optionValue).verify()
}

@OptIn(ExperimentalForeignApi::class)
internal fun EasyHandle.getInfo(info: CURLINFO, optionValue: CPointer<*>) {
curl_easy_getinfo(this, info, optionValue).verify()
}

@OptIn(InternalAPI::class, ExperimentalForeignApi::class)
@OptIn(InternalAPI::class)
internal fun HttpRequestData.headersToCurl(): CPointer<curl_slist> {
var result: CPointer<curl_slist>? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import libcurl.*
import platform.posix.*
import kotlin.coroutines.*

@OptIn(ExperimentalForeignApi::class)
internal fun onHeadersReceived(
buffer: CPointer<ByteVar>,
size: size_t,
Expand All @@ -27,7 +26,6 @@ internal fun onHeadersReceived(
}

@Suppress("DEPRECATION")
@OptIn(ExperimentalForeignApi::class)
internal fun onBodyChunkReceived(
buffer: CPointer<ByteVar>,
size: size_t,
Expand Down Expand Up @@ -74,7 +72,6 @@ internal fun onBodyChunkReceived(
}

@Suppress("DEPRECATION")
@OptIn(ExperimentalForeignApi::class)
internal fun onBodyChunkRequested(
buffer: CPointer<ByteVar>,
size: size_t,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,32 @@ import kotlinx.cinterop.*
import kotlinx.coroutines.*
import libcurl.*

private class RequestHolder @OptIn(ExperimentalForeignApi::class) constructor(
private class RequestHolder constructor(
val responseCompletable: CompletableDeferred<CurlSuccess>,
val requestWrapper: StableRef<CurlRequestBodyData>,
val responseWrapper: StableRef<CurlResponseBodyData>,
) {
@OptIn(ExperimentalForeignApi::class)

fun dispose() {
requestWrapper.dispose()
responseWrapper.dispose()
}
}

internal class CurlMultiApiHandler : Closeable {
@OptIn(ExperimentalForeignApi::class)

private val activeHandles = mutableMapOf<EasyHandle, RequestHolder>()

@OptIn(ExperimentalForeignApi::class)
private val cancelledHandles = mutableSetOf<Pair<EasyHandle, Throwable>>()

@OptIn(ExperimentalForeignApi::class)
@Suppress("DEPRECATION")
private val multiHandle: MultiHandle = curl_multi_init()
?: throw CurlRuntimeException("Could not initialize curl multi handle")

private val easyHandlesToUnpauseLock = SynchronizedObject()

@OptIn(ExperimentalForeignApi::class)
private val easyHandlesToUnpause = mutableListOf<EasyHandle>()

@OptIn(ExperimentalForeignApi::class)
override fun close() {
for ((handle, holder) in activeHandles) {
curl_multi_remove_handle(multiHandle, handle).verify()
Expand All @@ -53,7 +49,6 @@ internal class CurlMultiApiHandler : Closeable {
curl_multi_cleanup(multiHandle).verify()
}

@OptIn(ExperimentalForeignApi::class)
fun scheduleRequest(request: CurlRequestData, deferred: CompletableDeferred<CurlSuccess>): EasyHandle {
val easyHandle = curl_easy_init()
?: throw
Expand Down Expand Up @@ -129,13 +124,11 @@ internal class CurlMultiApiHandler : Closeable {
return easyHandle
}

@OptIn(ExperimentalForeignApi::class)
internal fun cancelRequest(easyHandle: EasyHandle, cause: Throwable) {
cancelledHandles += Pair(easyHandle, cause)
curl_multi_remove_handle(multiHandle, easyHandle).verify()
}

@OptIn(ExperimentalForeignApi::class)
internal fun perform() {
if (activeHandles.isEmpty()) return

Expand All @@ -160,10 +153,8 @@ internal class CurlMultiApiHandler : Closeable {
}
}

@OptIn(ExperimentalForeignApi::class)
internal fun hasHandlers(): Boolean = activeHandles.isNotEmpty()

@OptIn(ExperimentalForeignApi::class)
private fun setupMethod(
easyHandle: EasyHandle,
method: String,
Expand All @@ -187,7 +178,6 @@ internal class CurlMultiApiHandler : Closeable {
}
}

@OptIn(ExperimentalForeignApi::class)
private fun setupUploadContent(easyHandle: EasyHandle, request: CurlRequestData): COpaquePointer {
val requestPointer = CurlRequestBodyData(
body = request.content,
Expand All @@ -208,7 +198,6 @@ internal class CurlMultiApiHandler : Closeable {
return requestPointer
}

@OptIn(ExperimentalForeignApi::class)
private fun handleCompleted() {
for (cancellation in cancelledHandles) {
val cancelled = processCancelledEasyHandle(cancellation.first, cancellation.second)
Expand Down Expand Up @@ -246,7 +235,6 @@ internal class CurlMultiApiHandler : Closeable {
}
}

@OptIn(ExperimentalForeignApi::class)
private fun processCancelledEasyHandle(easyHandle: EasyHandle, cause: Throwable): CurlFail = memScoped {
try {
val responseDataRef = alloc<COpaquePointerVar>()
Expand All @@ -264,7 +252,6 @@ internal class CurlMultiApiHandler : Closeable {
}
}

@OptIn(ExperimentalForeignApi::class)
private fun processCompletedEasyHandle(
message: CURLMSG?,
easyHandle: EasyHandle,
Expand Down Expand Up @@ -293,7 +280,6 @@ internal class CurlMultiApiHandler : Closeable {
}
}

@OptIn(ExperimentalForeignApi::class)
private fun collectFailedResponse(
message: CURLMSG?,
request: CurlRequestData,
Expand Down Expand Up @@ -334,7 +320,6 @@ internal class CurlMultiApiHandler : Closeable {
)
}

@OptIn(ExperimentalForeignApi::class)
private fun collectSuccessResponse(easyHandle: EasyHandle): CurlSuccess? = memScoped {
val responseDataRef = alloc<COpaquePointerVar>()
val httpProtocolVersion = alloc<LongVar>()
Expand Down Expand Up @@ -363,7 +348,6 @@ internal class CurlMultiApiHandler : Closeable {
}
}

@OptIn(ExperimentalForeignApi::class)
fun wakeup() {
curl_multi_wakeup(multiHandle)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import kotlinx.coroutines.*
import libcurl.*
import kotlin.coroutines.*

@OptIn(ExperimentalForeignApi::class)
internal suspend fun HttpRequestData.toCurlRequest(config: CurlClientEngineConfig): CurlRequestData = CurlRequestData(
url = url.toString(),
method = method.value,
Expand All @@ -34,7 +33,7 @@ internal suspend fun HttpRequestData.toCurlRequest(config: CurlClientEngineConfi
caPath = config.caPath
)

internal class CurlRequestData @OptIn(ExperimentalForeignApi::class) constructor(
internal class CurlRequestData constructor(
val url: String,
val method: String,
val headers: CPointer<curl_slist>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ package io.ktor.client.engine.curl.internal
import kotlinx.cinterop.*
import platform.posix.*

@OptIn(ExperimentalForeignApi::class)
internal fun ByteArray.copyToBuffer(buffer: CPointer<ByteVar>, size: ULong, position: Int = 0) {
usePinned { pinned ->
memcpy(buffer, pinned.addressOf(position), size.convert())
}
}

@OptIn(ExperimentalForeignApi::class)
internal inline fun <T : Any> T.asStablePointer(): COpaquePointer = StableRef.create(this).asCPointer()

@OptIn(ExperimentalForeignApi::class)
internal inline fun <reified T : Any> COpaquePointer.fromCPointer(): T = asStableRef<T>().get()
Loading

0 comments on commit 89805f7

Please sign in to comment.