Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
skiko
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liuqiang
skiko
Commits
ec840591
Unverified
Commit
ec840591
authored
Nov 10, 2023
by
dima.avdeev
Committed by
GitHub
Nov 10, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix problem with conversion of Kotlin String to C char * (#827)
parent
b2149d98
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
5 deletions
+14
-5
RELEASE.md
skiko/RELEASE.md
+1
-0
Native.native.kt
...ativeMain/kotlin/org/jetbrains/skia/impl/Native.native.kt
+13
-5
No files found.
skiko/RELEASE.md
View file @
ec840591
...
@@ -21,6 +21,7 @@ build configuration.
...
@@ -21,6 +21,7 @@ build configuration.
```
bash
```
bash
./gradlew publishToMavenLocal
-Pskiko
.native.enabled
=
true
-Pskiko
.wasm.enabled
=
true
-Pskiko
.android.enabled
=
true
./gradlew publishToMavenLocal
-Pskiko
.native.enabled
=
true
-Pskiko
.wasm.enabled
=
true
-Pskiko
.android.enabled
=
true
```
```
Use flag
`-Pskiko.debug=true`
to build with debug build type.
##### Publish to `build/repo` directory
##### Publish to `build/repo` directory
```
bash
```
bash
...
...
skiko/src/nativeMain/kotlin/org/jetbrains/skia/impl/Native.native.kt
View file @
ec840591
...
@@ -66,10 +66,7 @@ internal actual inline fun <T> interopScope(block: InteropScope.() -> T): T {
...
@@ -66,10 +66,7 @@ internal actual inline fun <T> interopScope(block: InteropScope.() -> T): T {
internal
actual
class
InteropScope
actual
constructor
()
{
internal
actual
class
InteropScope
actual
constructor
()
{
actual
fun
toInterop
(
string
:
String
?):
InteropPointer
{
actual
fun
toInterop
(
string
:
String
?):
InteropPointer
{
return
if
(
string
!=
null
)
{
return
if
(
string
!=
null
)
{
// encodeToByteArray encodes to utf8
val
pinned
=
convertToZeroTerminatedString
(
string
).
pin
()
val
utf8
=
string
.
encodeToByteArray
()
// TODO Remove array copy, use `skString(data, length)` instead of `skString(data)`
val
pinned
=
utf8
.
copyOf
(
utf8
.
size
+
1
).
pin
()
elements
.
add
(
pinned
)
elements
.
add
(
pinned
)
val
result
=
pinned
.
addressOf
(
0
).
rawValue
val
result
=
pinned
.
addressOf
(
0
).
rawValue
result
result
...
@@ -186,7 +183,7 @@ internal actual class InteropScope actual constructor() {
...
@@ -186,7 +183,7 @@ internal actual class InteropScope actual constructor() {
if
(
stringArray
==
null
||
stringArray
.
isEmpty
())
return
NativePtr
.
NULL
if
(
stringArray
==
null
||
stringArray
.
isEmpty
())
return
NativePtr
.
NULL
val
pins
=
stringArray
.
toList
()
val
pins
=
stringArray
.
toList
()
.
map
{
it
.
encodeToByteArray
(
).
pin
()
}
.
map
{
convertToZeroTerminatedString
(
it
).
pin
()
}
val
nativePointerArray
=
NativePointerArray
(
stringArray
.
size
)
val
nativePointerArray
=
NativePointerArray
(
stringArray
.
size
)
pins
.
forEachIndexed
{
index
,
pin
->
pins
.
forEachIndexed
{
index
,
pin
->
...
@@ -284,3 +281,14 @@ private external fun initCallbacks(
...
@@ -284,3 +281,14 @@ private external fun initCallbacks(
callVoid
:
COpaquePointer
,
callVoid
:
COpaquePointer
,
dispose
:
COpaquePointer
dispose
:
COpaquePointer
)
)
/**
* Converts String to zero-terminated utf-8 byte array.
*/
private
fun
convertToZeroTerminatedString
(
string
:
String
):
ByteArray
{
// C++ needs char* with zero byte at the end. So we need to copy array with an extra zero byte.
val
utf8
=
string
.
encodeToByteArray
()
// encodeToByteArray encodes to utf8
// TODO Remove array copy, use `skString(data, length)` instead of `skString(data)`
return
utf8
.
copyOf
(
utf8
.
size
+
1
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment