Platform library for iconv.h on macos, ios and linux.

This commit is contained in:
Alexander Gorshenev
2018-03-13 14:24:51 +03:00
committed by alexander-gorshenev
parent f975c1d251
commit 18b7bb31fc
6 changed files with 57 additions and 1 deletions
+6
View File
@@ -2562,6 +2562,12 @@ task jsinterop_math(type: RunStandaloneKonanTest) {
flags = ["-r", "$buildDir", "-l", "jsmath"]
}
task interop_libiconv(type: RunStandaloneKonanTest) {
disabled = (isWindows() || (project.testTarget != null))
source = "interop/libiconv.kt"
goldValue = "72 72\n101 101\n108 108\n108 108\n111 111\n33 33\n"
}
task produce_dynamic(type: DynamicKonanTest) {
disabled = (project.testTarget != null && project.testTarget != project.hostName)
source = "produce_dynamic/simple/hello.kt"
+39
View File
@@ -0,0 +1,39 @@
import kotlinx.cinterop.*
import platform.iconv.*
import platform.posix.size_tVar
fun main(args: Array<String>) {
val sourceByteArray = "Hello!".toUtf8()
val golden = listOf(0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x21)
memScoped {
val sourceLength = alloc<size_tVar>()
val destLength = alloc<size_tVar>()
val sourceBytes = allocArrayOf(sourceByteArray)
val destBytes = allocArray<ByteVar>(golden.size)
val sourcePtr = alloc<CArrayPointerVar<ByteVar>>()
sourcePtr.value = sourceBytes
val destPtr = alloc<CArrayPointerVar<ByteVar>>()
destPtr.value = destBytes
sourceLength.value = sourceByteArray.size.signExtend();
destLength.value = golden.size.signExtend();
val conversion = iconv_open("UTF-8", "LATIN1")
iconv(conversion, sourcePtr.ptr, sourceLength.ptr, destPtr.ptr, destLength.ptr)
golden.forEachIndexed { index, it ->
println("$it ${destBytes[index]}")
it == destBytes[index].toInt()
}
iconv_close(conversion)
}
}
+4
View File
@@ -0,0 +1,4 @@
depends = posix
package = platform.iconv
headers = iconv.h
linkerOpts = -liconv
@@ -0,0 +1,3 @@
depends = posix
package = platform.iconv
headers = iconv.h
+1 -1
View File
@@ -3,7 +3,7 @@ headers = aio.h aliases.h a.out.h argp.h argz.h byteswap.h cpio.h crypt.h \
ctype.h elf.h endian.h envz.h error.h execinfo.h features.h fmtmsg.h \
fpu_control.h \
fstab.h _G_config.h gconv.h glob.h gnu-versions.h \
gshadow.h iconv.h ieee754.h ifaddrs.h langinfo.h lastlog.h \
gshadow.h ieee754.h ifaddrs.h langinfo.h lastlog.h \
libintl.h libio.h link.h malloc.h mcheck.h mntent.h \
monetary.h mqueue.h \
nl_types.h nss.h obstack.h \
+4
View File
@@ -0,0 +1,4 @@
depends = posix
package = platform.iconv
headers = iconv.h
linkerOpts = -liconv