diff options
| author | ruki <[email protected]> | 2021-09-21 00:52:15 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-09-21 00:52:15 +0800 |
| commit | bce8f65cb9f619dfa30d7b4b1fa2da9fa56b58e1 (patch) | |
| tree | e05136ba9eaa706a2d2cabab6732a9410b05e297 /xmake/core/base | |
| parent | 4181bf780192cbf4be257fb7b658cfb390684a12 (diff) | |
improve bytes
Diffstat (limited to 'xmake/core/base')
| -rw-r--r-- | xmake/core/base/bytes.lua | 10 | ||||
| -rw-r--r-- | xmake/core/base/libc.lua | 14 |
2 files changed, 7 insertions, 17 deletions
diff --git a/xmake/core/base/bytes.lua b/xmake/core/base/bytes.lua index 300d2a073..9f7b6ca4f 100644 --- a/xmake/core/base/bytes.lua +++ b/xmake/core/base/bytes.lua @@ -96,7 +96,7 @@ function _instance.new(...) os.raise("incorrect bounds(%d-%d) for bytes(...)!", start, last) end instance._SIZE = last - start + 1 - instance._CDATA = libc.diffptr(b:cdata(), -1 + start) + instance._CDATA = b:cdata() -1 + start instance._REF = b -- keep lua ref for GC instance._MANAGED = false instance._READONLY = b:readonly() @@ -109,7 +109,7 @@ function _instance.new(...) instance._CDATA = libc.malloc(instance._SIZE, {gc = true}) local offset = 0 for _, b in ipairs(args) do - libc.memcpy(libc.diffptr(instance._CDATA, offset), b:cdata(), b:size()) + libc.memcpy(instance._CDATA + offset, b:cdata(), b:size()) offset = offset + b:size() end instance._MANAGED = true @@ -124,7 +124,7 @@ function _instance.new(...) instance._CDATA = libc.malloc(instance._SIZE, {gc = true}) local offset = 0 for _, b in ipairs(args) do - libc.memcpy(libc.diffptr(instance._CDATA, offset), b._CDATA, b:size()) + libc.memcpy(instance._CDATA + offset, b._CDATA, b:size()) offset = offset + b:size() end instance._MANAGED = true @@ -138,7 +138,7 @@ function _instance.new(...) os.raise("incorrect bounds(%d-%d)!", start, last) end instance._SIZE = last - start + 1 - instance._CDATA = libc.diffptr(b:cdata(), -1 + start) + instance._CDATA = b:cdata() -1 + start instance._REF = b -- keep lua ref for GC instance._MANAGED = false instance._READONLY = b:readonly() @@ -324,7 +324,7 @@ end -- convert bytes to string function _instance:str(i, j) local offset = i and i - 1 or 0 - return libc.strndup(libc.diffptr(self:cdata(), offset), (j or self:size()) - offset) + return libc.strndup(self:cdata() + offset, (j or self:size()) - offset) end -- get uint8 value diff --git a/xmake/core/base/libc.lua b/xmake/core/base/libc.lua index 6e69dd203..9aecb8af5 100644 --- a/xmake/core/base/libc.lua +++ b/xmake/core/base/libc.lua @@ -28,8 +28,6 @@ libc._memcpy = libc._memcpy or libc.memcpy libc._memset = libc._memset or libc.memset libc._strndup = libc._strndup or libc.strndup libc._dataptr = libc._dataptr or libc.dataptr -libc._ptraddr = libc._ptraddr or libc.ptraddr -libc._diffptr = libc._diffptr or libc.diffptr libc._byteof = libc._byteof or libc.byteof libc._setbyte = libc._setbyte or libc.setbyte @@ -112,14 +110,6 @@ function libc.setbyte(data, offset, value) end end -function libc.diffptr(data, offset) - if ffi then - return data + offset - else - return libc._diffptr(data, offset) - end -end - function libc.dataptr(data, opt) if ffi then if opt and opt.gc then @@ -128,7 +118,7 @@ function libc.dataptr(data, opt) return ffi.cast("unsigned char*", data) end else - return libc._dataptr(data) + return type(data) == "number" and data or libc._dataptr(data) end end @@ -136,7 +126,7 @@ function libc.ptraddr(data) if ffi then return tonumber(ffi.cast('unsigned long long', data)) else - return libc._ptraddr(data) + return data end end |
