dreamlike-ocean / PanamaUring

使用panama api为java提供io_uring的绑定而无需使用jni绑定,同时统一文件IO和网络IO的模型,提供一套易用的异步IO API
MIT License
77 stars 12 forks source link

native call 返回指针时错误取值问题 #33

Closed dreamlike-ocean closed 9 months ago

dreamlike-ocean commented 9 months ago
if (returnPointer) {
            //先调整返回值类型对应的memorySegment长度
            methodHandle = MethodHandles.filterReturnValue(
                    methodHandle,
                    MethodHandles.insertArguments(
                            NativeGeneratorHelper.REINTERPRET_MH,
                            1,
                            returnLayout.byteSize()
                    )
            );

            //绑定当前的StructProxyGenerator
            //绑定的结果是 (MemorySegment) -> ${returnType}
            MethodHandle returnEnhance = StructProxyGenerator.ENHANCE_MH
                    .asType(StructProxyGenerator.ENHANCE_MH.type().changeReturnType(method.getReturnType()))
                    .bindTo(structProxyGenerator)
                    .bindTo(method.getReturnType());
            //来把MemorySegment返回值转换为java bean
            methodHandle = MethodHandles.filterReturnValue(
                    methodHandle,
                    returnEnhance
            );
        }

NativeGeneratorHelper.REINTERPRET_MH, 不应该直接REINTERPRET而是读出来地址值转化为MemorySegment 之后再REINTERPRET最后作为底层MemorySegment 绑定到proxy上

dreamlike-ocean commented 9 months ago

跟着 #32 一起修复