diff --git a/src/lime/utils/DataPointer.hx b/src/lime/utils/DataPointer.hx index 447aa8dee..c83dfdf5b 100644 --- a/src/lime/utils/DataPointer.hx +++ b/src/lime/utils/DataPointer.hx @@ -6,11 +6,17 @@ import haxe.io.Bytes; import lime.system.CFFIPointer; import lime.utils.Bytes as LimeBytes; +#if cpp +import cpp.Pointer; +#end + #if (lime_cffi && !macro) import lime._internal.backend.native.NativeCFFI; @:access(lime._internal.backend.native.NativeCFFI) #end +@:access(haxe.io.Bytes) + abstract DataPointer(DataPointerType) to DataPointerType { @@ -49,9 +55,21 @@ abstract DataPointer(DataPointerType) to DataPointerType { } + #if cpp + @:generic @:from @:noCompletion public static inline function fromPointer (pointer:Pointer):DataPointer { + + return untyped __cpp__('(uintptr_t){0}', pointer.ptr); + + } + #end + + @: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; var data:Float = NativeCFFI.lime_bytes_get_data_pointer_offset (pointer.bytes, pointer.offset); return new DataPointer (data); @@ -66,7 +84,10 @@ abstract DataPointer(DataPointerType) to DataPointerType { @: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; var data:Float = NativeCFFI.lime_bytes_get_data_pointer_offset (arrayBufferView.buffer, arrayBufferView.byteOffset); return new DataPointer (data); @@ -95,7 +116,10 @@ abstract DataPointer(DataPointerType) to DataPointerType { @: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; var data:Float = NativeCFFI.lime_bytes_get_data_pointer (bytes); return new DataPointer (data);