ReviewOS

also looking at this

craft-native/craft

feat(android): getCalendarEvents and createCalendarEvent in Zig — ratchet 86 → 84

#158
Merged glennmichael123 wants to merge feat/android-calendar-events into main
7 files +1167 -20
packages/zig/src/jni_runtime.zigmodified+47-4
Changes to packages/zig/src/jni_runtime.zig
@@ -642,6 +642,14 @@ pub const Jni = struct {
642642 return result != JNI_FALSE;
643643 }
644644
645 pub fn callLongMethodA(self: Self, obj: jobject, id: jmethodID, args: []const jvalue) JniError!jlong {
646 const call: *const fn (JNIEnv, jobject, jmethodID, [*]const jvalue) callconv(.c) jlong =
647 @ptrCast(self.table().CallLongMethodA orelse return JniError.NotFound);
648 const result = call(self.env, obj, id, args.ptr);
649 try self.check();
650 return result;
651 }
652
645653 pub fn callVoidMethodA(self: Self, obj: jobject, id: jmethodID, args: []const jvalue) JniError!void {
646654 const call: *const fn (JNIEnv, jobject, jmethodID, [*]const jvalue) callconv(.c) void =
647655 @ptrCast(self.table().CallVoidMethodA orelse return JniError.NotFound);
@@ -706,10 +714,14 @@ pub const Jni = struct {
706714
707715 // --- Arrays -----------------------------------------------------------
708716 //
709 // Only `long[]` so far, because only `VibrationEffect.createWaveform`
710 // needs one. `SetLongArrayRegion` copies from a Zig slice in one call
711 // rather than element by element, which is both faster and the only form
712 // that cannot leave a partially-filled array behind on an error.
717 // `long[]` for `VibrationEffect.createWaveform`, and `String[]` for the
718 // projection and selection arguments a `ContentResolver.query` takes.
719 //
720 // The two are shaped differently because JNI is: a primitive array can be
721 // filled from a Zig slice in one `SetLongArrayRegion` call, which is both
722 // faster and the only form that cannot leave a partially-filled array
723 // behind on an error. An object array has no region form and has to be
724 // written a slot at a time.
713725
714726 pub fn newLongArray(self: Self, values: []const jlong) JniError!jobject {
715727 const new: *const fn (JNIEnv, jsize) callconv(.c) jobject =
@@ -728,6 +740,29 @@ pub const Jni = struct {
728740 return array;
729741 }
730742
743 /// `new <element_class>[len]`, every slot null.
744 ///
745 /// `NewObjectArray` takes an initial element for every slot; null is what
746 /// the Kotlin's `arrayOf(...)` starts from before its entries are written,
747 /// and every caller here fills the array immediately.
748 pub fn newObjectArray(self: Self, len: usize, element_class: jclass) JniError!jobject {
749 const new: *const fn (JNIEnv, jsize, jclass, jobject) callconv(.c) jobject =
750 @ptrCast(self.table().NewObjectArray orelse return JniError.NotFound);
751 const array = new(self.env, @intCast(len), element_class, null) orelse {
752 try self.check();
753 return JniError.OutOfMemory;
754 };
755 try self.check();
756 return array;
757 }
758
759 pub fn setObjectArrayElement(self: Self, array: jobject, index: usize, value: jobject) JniError!void {
760 const set: *const fn (JNIEnv, jobject, jsize, jobject) callconv(.c) void =
761 @ptrCast(self.table().SetObjectArrayElement orelse return JniError.NotFound);
762 set(self.env, array, @intCast(index), value);
763 try self.check();
764 }
765
731766 /// Make a Java `String` from UTF-8.
732767 ///
733768 /// The JVM wants *modified* UTF-8 here, the same encoding `stringToUtf8`
@@ -783,6 +818,14 @@ pub const Jni = struct {
783818 return result;
784819 }
785820
821 pub fn callStaticLongMethodA(self: Self, cls: jclass, id: jmethodID, args: []const jvalue) JniError!jlong {
822 const call: *const fn (JNIEnv, jclass, jmethodID, [*]const jvalue) callconv(.c) jlong =
823 @ptrCast(self.table().CallStaticLongMethodA orelse return JniError.NotFound);
824 const result = call(self.env, cls, id, args.ptr);
825 try self.check();
826 return result;
827 }
828
786829 pub fn callStaticVoidMethodA(self: Self, cls: jclass, id: jmethodID, args: []const jvalue) JniError!void {
787830 const call: *const fn (JNIEnv, jclass, jmethodID, [*]const jvalue) callconv(.c) void =
788831 @ptrCast(self.table().CallStaticVoidMethodA orelse return JniError.NotFound);