Exemple #1
0
func SwiftCancelableContext(ctx *context.T, cancelFunc context.CancelFunc) (C.GoCancelableContextHandle, error) {
	if cancelFunc == nil {
		return C.GoCancelableContextHandle(0), fmt.Errorf("Cannot create SwiftCancelableContext with nil cancel function")
	}
	ctx = context.WithValue(ctx, cancelFuncKey{}, cancelFunc)
	return C.GoCancelableContextHandle(SwiftContext(ctx)), nil
}
Exemple #2
0
//export Java_io_v_v23_context_VContext_nativeWithValue
func Java_io_v_v23_context_VContext_nativeWithValue(jenv *C.JNIEnv, jVContext C.jobject, goRef C.jlong, goCancelRef C.jlong, jKeySign C.jstring, jValue C.jobject) C.jobject {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	key := goContextKey(jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jKeySign)))))
	value, err := GoContextValue(env, jutil.Object(uintptr(unsafe.Pointer(jValue))))
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	ctx := context.WithValue((*context.T)(jutil.GoRefValue(jutil.Ref(goRef))), key, value)
	var cancel context.CancelFunc
	if goCancelRef != 0 {
		cancel = (*(*context.CancelFunc)(jutil.GoRefValue(jutil.Ref(goCancelRef))))
	}
	jCtx, err := JavaContext(env, ctx, cancel)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	return C.jobject(unsafe.Pointer(jCtx))
}
Exemple #3
0
//export swift_io_v_impl_google_rt_VRuntimeImpl_nativeInit
func swift_io_v_impl_google_rt_VRuntimeImpl_nativeInit() C.GoContextHandle {
	ctx, shutdownFunc := v23.Init()
	ctx = context.WithValue(ctx, shutdownKey{}, shutdownFunc)
	return C.GoContextHandle(scontext.SwiftContext(ctx))
}