예제 #1
0
파일: util.go 프로젝트: vanadium/go.swift
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
}
예제 #2
0
파일: jni.go 프로젝트: vanadium/go.jni
//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))
}
예제 #3
0
파일: swift.go 프로젝트: vanadium/go.swift
//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))
}