[K/N] Deprecate ImmutableBlob

As a part of stabilizing Native stdlib.

Merge-request: KT-MR-9310
Merged-by: Abduqodiri Qurbonzoda <abduqodiri.qurbonzoda@jetbrains.com>
This commit is contained in:
Abduqodiri Qurbonzoda
2023-04-01 17:55:57 +00:00
committed by Space Team
parent 8663239369
commit 2f8e4a9775
@@ -10,6 +10,8 @@ import kotlinx.cinterop.*
/**
* An immutable compile-time array of bytes.
*/
@Deprecated("Use ByteArray instead.")
@DeprecatedSinceKotlin(warningSince = "1.9")
public final class ImmutableBlob private constructor() {
public val size: Int
get() = getArrayLength()
@@ -27,6 +29,7 @@ public final class ImmutableBlob private constructor() {
}
}
@Suppress("DEPRECATION")
private class ImmutableBlobIteratorImpl(val blob: ImmutableBlob) : ByteIterator() {
var index : Int = 0
@@ -46,6 +49,9 @@ private class ImmutableBlobIteratorImpl(val blob: ImmutableBlob) : ByteIterator(
* @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default.
* @param endIndex the end (exclusive) of the subrange to copy, size of this blob by default.
*/
@Suppress("DEPRECATION")
@Deprecated("ImmutableBlob is deprecated. Use ByteArray instead.")
@DeprecatedSinceKotlin(warningSince = "1.9")
@GCUnsafeCall("Kotlin_ImmutableBlob_toByteArray")
public external fun ImmutableBlob.toByteArray(startIndex: Int = 0, endIndex: Int = size): ByteArray
@@ -55,6 +61,9 @@ public external fun ImmutableBlob.toByteArray(startIndex: Int = 0, endIndex: Int
* @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default.
* @param endIndex the end (exclusive) of the subrange to copy, size of this blob by default.
*/
@Suppress("DEPRECATION")
@Deprecated("ImmutableBlob is deprecated. Use ByteArray instead.")
@DeprecatedSinceKotlin(warningSince = "1.9")
@ExperimentalUnsignedTypes
@GCUnsafeCall("Kotlin_ImmutableBlob_toByteArray")
public external fun ImmutableBlob.toUByteArray(startIndex: Int = 0, endIndex: Int = size): UByteArray
@@ -62,14 +71,44 @@ public external fun ImmutableBlob.toUByteArray(startIndex: Int = 0, endIndex: In
/**
* Returns stable C pointer to data at certain [offset], useful as a way to pass resource
* to C APIs.
*
* `ImmutableBlob` is deprecated since Kotlin 1.9. It is recommended to use `ByteArray` instead.
* To get a stable C pointer to `ByteArray` data the array needs to be pinned first.
* ```
* byteArray.usePinned {
* val cpointer = it.addressOf(offset)
* // use the stable C pointer
* }
* ```
* @see kotlinx.cinterop.CPointer
*/
@Suppress("DEPRECATION")
@Deprecated("ImmutableBlob is deprecated. Use ByteArray instead. To get a stable C pointer to a `ByteArray`, pin it first.")
@DeprecatedSinceKotlin(warningSince = "1.9")
public fun ImmutableBlob.asCPointer(offset: Int = 0): CPointer<ByteVar> =
interpretCPointer<ByteVar>(asCPointerImpl(offset))!!
/**
* Returns stable C pointer to data at certain [offset], useful as a way to pass resource
* to C APIs.
*
* `ImmutableBlob` is deprecated since Kotlin 1.9. It is recommended to use `ByteArray` instead.
* To get a stable C pointer to `ByteArray` data the array needs to be pinned first.
* ```
* byteArray.usePinned {
* val cpointer = it.addressOf(offset)
* // use the stable C pointer
* }
* ```
* @see kotlinx.cinterop.CPointer
*/
@Suppress("DEPRECATION")
@Deprecated("ImmutableBlob is deprecated. Use ByteArray instead. To get a stable C pointer to a `ByteArray`, pin it first.")
@DeprecatedSinceKotlin(warningSince = "1.9")
public fun ImmutableBlob.asUCPointer(offset: Int = 0): CPointer<UByteVar> =
interpretCPointer<UByteVar>(asCPointerImpl(offset))!!
@Suppress("DEPRECATION")
@GCUnsafeCall("Kotlin_ImmutableBlob_asCPointerImpl")
private external fun ImmutableBlob.asCPointerImpl(offset: Int): kotlin.native.internal.NativePtr
@@ -81,5 +120,8 @@ private external fun ImmutableBlob.asCPointerImpl(offset: Int): kotlin.native.in
* One element still represent one byte in the output data.
* This is the only way to create ImmutableBlob for now.
*/
@Suppress("DEPRECATION")
@Deprecated("ImmutableBlob is deprecated. Use ByteArray instead.", ReplaceWith("byteArrayOf(*elements)"))
@DeprecatedSinceKotlin(warningSince = "1.9")
@TypedIntrinsic(IntrinsicType.IMMUTABLE_BLOB)
public external fun immutableBlobOf(vararg elements: Short): ImmutableBlob