diff options
| author | ruki <[email protected]> | 2021-09-20 22:54:29 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-09-20 22:54:29 +0800 |
| commit | ed1c24645198aa1451ee22c005a16fa7b8e4d5bc (patch) | |
| tree | ccb126d4087620e72a658531434e06be4b86a5d3 /xmake | |
| parent | 68f4ab938564a43656236de3a0eb67f9222bc876 (diff) | |
add libc.dataptr
Diffstat (limited to 'xmake')
| -rw-r--r-- | xmake/core/base/bytes.lua | 6 | ||||
| -rw-r--r-- | xmake/core/base/libc.lua | 17 |
2 files changed, 16 insertions, 7 deletions
diff --git a/xmake/core/base/bytes.lua b/xmake/core/base/bytes.lua index ba44d3403..a4a963762 100644 --- a/xmake/core/base/bytes.lua +++ b/xmake/core/base/bytes.lua @@ -60,10 +60,10 @@ function _instance.new(...) local ptr = arg2 local manage = arg3 if manage then - instance._CDATA = ffi.gc(ffi.cast("unsigned char*", ptr), ffi.C.free) + instance._CDATA = ffi.gc(libc.dataptr(ptr), ffi.C.free) instance._MANAGED = true else - instance._CDATA = ffi.cast("unsigned char*", ptr) + instance._CDATA = libc.dataptr(ptr) instance._MANAGED = false end else @@ -91,7 +91,7 @@ function _instance.new(...) -- bytes(str): mounts a buffer from the given string local str = arg1 instance._SIZE = #str - instance._CDATA = ffi.cast("unsigned char*", str) + instance._CDATA = libc.dataptr(str) instance._REF = str -- keep ref for GC instance._MANAGED = false instance._READONLY = true diff --git a/xmake/core/base/libc.lua b/xmake/core/base/libc.lua index cedabef1b..5a32e1180 100644 --- a/xmake/core/base/libc.lua +++ b/xmake/core/base/libc.lua @@ -22,10 +22,11 @@ local libc = libc or {} -- save original interfaces -libc._malloc = libc._malloc or libc.malloc -libc._free = libc._free or libc.free -libc._memcpy = libc._memcpy or libc.memcpy -libc._memset = libc._memset or libc.memset +libc._malloc = libc._malloc or libc.malloc +libc._free = libc._free or libc.free +libc._memcpy = libc._memcpy or libc.memcpy +libc._memset = libc._memset or libc.memset +libc._dataptr = libc._dataptr or libc.dataptr -- load modules local ffi = xmake._LUAJIT and require("ffi") @@ -79,5 +80,13 @@ function libc.memset(data, ch, size) end end +function libc.dataptr(data) + if ffi then + return ffi.cast("unsigned char*", data) + else + return libc._dataptr(data) + end +end + -- return module: libc return libc |
