Avoid CFFI for DataPointer conversions on C++
This commit is contained in:
@@ -6,11 +6,17 @@ import haxe.io.Bytes;
|
|||||||
import lime.system.CFFIPointer;
|
import lime.system.CFFIPointer;
|
||||||
import lime.utils.Bytes as LimeBytes;
|
import lime.utils.Bytes as LimeBytes;
|
||||||
|
|
||||||
|
#if cpp
|
||||||
|
import cpp.Pointer;
|
||||||
|
#end
|
||||||
|
|
||||||
#if (lime_cffi && !macro)
|
#if (lime_cffi && !macro)
|
||||||
import lime._internal.backend.native.NativeCFFI;
|
import lime._internal.backend.native.NativeCFFI;
|
||||||
@:access(lime._internal.backend.native.NativeCFFI)
|
@:access(lime._internal.backend.native.NativeCFFI)
|
||||||
#end
|
#end
|
||||||
|
|
||||||
|
@:access(haxe.io.Bytes)
|
||||||
|
|
||||||
|
|
||||||
abstract DataPointer(DataPointerType) to DataPointerType {
|
abstract DataPointer(DataPointerType) to DataPointerType {
|
||||||
|
|
||||||
@@ -49,9 +55,21 @@ abstract DataPointer(DataPointerType) to DataPointerType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if cpp
|
||||||
|
@:generic @:from @:noCompletion public static inline function fromPointer<T> (pointer:Pointer<T>):DataPointer {
|
||||||
|
|
||||||
|
return untyped __cpp__('(uintptr_t){0}', pointer.ptr);
|
||||||
|
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
|
|
||||||
@:from @:noCompletion public static function fromBytesPointer (pointer:BytePointer):DataPointer {
|
@:from @:noCompletion public static function fromBytesPointer (pointer:BytePointer):DataPointer {
|
||||||
|
|
||||||
#if (lime_cffi && !macro)
|
#if cpp
|
||||||
|
if (pointer == null || pointer.bytes == null) return cast 0;
|
||||||
|
return Pointer.arrayElem (pointer.bytes.b, 0).add (pointer.offset);
|
||||||
|
#elseif (lime_cffi && !macro)
|
||||||
if (pointer == null || pointer.bytes == null) return cast 0;
|
if (pointer == null || pointer.bytes == null) return cast 0;
|
||||||
var data:Float = NativeCFFI.lime_bytes_get_data_pointer_offset (pointer.bytes, pointer.offset);
|
var data:Float = NativeCFFI.lime_bytes_get_data_pointer_offset (pointer.bytes, pointer.offset);
|
||||||
return new DataPointer (data);
|
return new DataPointer (data);
|
||||||
@@ -66,7 +84,10 @@ abstract DataPointer(DataPointerType) to DataPointerType {
|
|||||||
|
|
||||||
@:from @:noCompletion public static function fromArrayBufferView (arrayBufferView:ArrayBufferView):DataPointer {
|
@:from @:noCompletion public static function fromArrayBufferView (arrayBufferView:ArrayBufferView):DataPointer {
|
||||||
|
|
||||||
#if (lime_cffi && !js && !macro)
|
#if cpp
|
||||||
|
if (arrayBufferView == null) return cast 0;
|
||||||
|
return Pointer.arrayElem (arrayBufferView.buffer.b, 0).add (arrayBufferView.byteOffset);
|
||||||
|
#elseif (lime_cffi && !js && !macro)
|
||||||
if (arrayBufferView == null) return cast 0;
|
if (arrayBufferView == null) return cast 0;
|
||||||
var data:Float = NativeCFFI.lime_bytes_get_data_pointer_offset (arrayBufferView.buffer, arrayBufferView.byteOffset);
|
var data:Float = NativeCFFI.lime_bytes_get_data_pointer_offset (arrayBufferView.buffer, arrayBufferView.byteOffset);
|
||||||
return new DataPointer (data);
|
return new DataPointer (data);
|
||||||
@@ -95,7 +116,10 @@ abstract DataPointer(DataPointerType) to DataPointerType {
|
|||||||
|
|
||||||
@:from @:noCompletion public static function fromBytes (bytes:Bytes):DataPointer {
|
@:from @:noCompletion public static function fromBytes (bytes:Bytes):DataPointer {
|
||||||
|
|
||||||
#if (lime_cffi && !macro)
|
#if cpp
|
||||||
|
if (bytes == null) return cast 0;
|
||||||
|
return Pointer.arrayElem (bytes.b, 0);
|
||||||
|
#elseif (lime_cffi && !macro)
|
||||||
if (bytes == null) return cast 0;
|
if (bytes == null) return cast 0;
|
||||||
var data:Float = NativeCFFI.lime_bytes_get_data_pointer (bytes);
|
var data:Float = NativeCFFI.lime_bytes_get_data_pointer (bytes);
|
||||||
return new DataPointer (data);
|
return new DataPointer (data);
|
||||||
|
|||||||
Reference in New Issue
Block a user