ReviewOS

also looking at this

craft-native/craft

fix(android): text going to the JVM is modified UTF-8, and was not being

#168
Merged chris wants to merge fix/android-modified-utf8 into main
12 files +326 -136
packages/zig/src/bridge_android_securestore.zigmodified+6-6
Changes to packages/zig/src/bridge_android_securestore.zig
@@ -78,7 +78,7 @@ fn apply(j: Jni, edit: jobject) !void {
7878 try j.callVoidMethodA(edit, try j.methodId(edit_cls, "apply", "()V"), &.{});
7979}
8080
81pub fn set(j: Jni, prefs: jobject, key: [*:0]const u8, value: [*:0]const u8) !void {
81pub fn set(j: Jni, allocator: std.mem.Allocator, prefs: jobject, key: []const u8, value: []const u8) !void {
8282 try j.pushLocalFrame(16);
8383 defer _ = j.popLocalFrame(null);
8484
@@ -92,12 +92,12 @@ pub fn set(j: Jni, prefs: jobject, key: [*:0]const u8, value: [*:0]const u8) !vo
9292 "putString",
9393 "(Ljava/lang/String;Ljava/lang/String;)Landroid/content/SharedPreferences$Editor;",
9494 ),
95 &.{ .{ .l = try j.newStringUtf(key) }, .{ .l = try j.newStringUtf(value) } },
95 &.{ .{ .l = try j.newStringUtf8(allocator, key) }, .{ .l = try j.newStringUtf8(allocator, value) } },
9696 );
9797 try apply(j, edit);
9898}
9999
100pub fn remove(j: Jni, prefs: jobject, key: [*:0]const u8) !void {
100pub fn remove(j: Jni, allocator: std.mem.Allocator, prefs: jobject, key: []const u8) !void {
101101 try j.pushLocalFrame(16);
102102 defer _ = j.popLocalFrame(null);
103103
@@ -107,7 +107,7 @@ pub fn remove(j: Jni, prefs: jobject, key: [*:0]const u8) !void {
107107 _ = try j.callObjectMethodA(
108108 edit,
109109 try j.methodId(edit_cls, "remove", "(Ljava/lang/String;)Landroid/content/SharedPreferences$Editor;"),
110 &.{.{ .l = try j.newStringUtf(key) }},
110 &.{.{ .l = try j.newStringUtf8(allocator, key) }},
111111 );
112112 try apply(j, edit);
113113}
@@ -147,7 +147,7 @@ pub fn renderRead(allocator: std.mem.Allocator, value: ?[]const u8) ![]u8 {
147147}
148148
149149/// `prefs.getString(key, null)`, as an owned optional. Caller frees.
150pub fn get(allocator: std.mem.Allocator, j: Jni, prefs: jobject, key: [*:0]const u8) !?[]u8 {
150pub fn get(allocator: std.mem.Allocator, j: Jni, prefs: jobject, key: []const u8) !?[]u8 {
151151 try j.pushLocalFrame(16);
152152 defer _ = j.popLocalFrame(null);
153153
@@ -161,7 +161,7 @@ pub fn get(allocator: std.mem.Allocator, j: Jni, prefs: jobject, key: [*:0]const
161161 ),
162162 // The default is null, which is what makes "absent" distinguishable
163163 // from a stored empty string.
164 &.{ .{ .l = try j.newStringUtf(key) }, .{ .l = null } },
164 &.{ .{ .l = try j.newStringUtf8(allocator, key) }, .{ .l = null } },
165165 );
166166 if (value == null) return null;
167167 return try j.stringToUtf8(allocator, value);