summaryrefslogtreecommitdiff
path: root/xmake/core/base/bytes.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2021-09-21 00:33:49 +0800
committerruki <[email protected]>2021-09-21 00:33:49 +0800
commit6bd955fbacc03792d8b36dffa087967e9e056e31 (patch)
tree91c05b8f4a7c047add5f7d61c323e47361a8aef7 /xmake/core/base/bytes.lua
parent1e14751dcb53640e9592be678e3ebf6a46d611e1 (diff)
fix strndup
Diffstat (limited to 'xmake/core/base/bytes.lua')
-rw-r--r--xmake/core/base/bytes.lua9
1 files changed, 4 insertions, 5 deletions
diff --git a/xmake/core/base/bytes.lua b/xmake/core/base/bytes.lua
index 55c08e774..f35f20790 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 = b:cdata() - 1 + start
+ instance._CDATA = libc.diffptr(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(instance._CDATA + offset, b:cdata(), b:size())
+ libc.memcpy(libc.diffptr(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(instance._CDATA + offset, b._CDATA, b:size())
+ libc.memcpy(libc.diffptr(instance._CDATA, offset), b._CDATA, b:size())
offset = offset + b:size()
end
instance._MANAGED = true
@@ -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(self:cdata() + offset, (j or self:size()) - offset)
+ return libc.strndup(libc.diffptr(self:cdata(), offset), (j or self:size()) - offset)
end
-- get uint8 value
@@ -449,7 +449,6 @@ end
-- it's only called for lua runtime, because bytes is not userdata
function _instance:__gc()
- print("gc")
if self._MANAGED and self._CDATA then
libc.free(self._CDATA)
self._CDATA = nil