diff options
| author | ruki <[email protected]> | 2020-02-03 23:04:09 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-02-07 22:45:56 +0800 |
| commit | 33797f692bfe78c58f82bafbf40f36640c6fdf13 (patch) | |
| tree | ca7a6ee38c67fd7964c1e765d52faa432b145508 /xmake/core/base/bytes.lua | |
| parent | 0320b5a0731fca04011d5149a0c7d956033e9140 (diff) | |
improve bytes
Diffstat (limited to 'xmake/core/base/bytes.lua')
| -rw-r--r-- | xmake/core/base/bytes.lua | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/xmake/core/base/bytes.lua b/xmake/core/base/bytes.lua index d1d6d8e36..6cf9747fe 100644 --- a/xmake/core/base/bytes.lua +++ b/xmake/core/base/bytes.lua @@ -44,6 +44,7 @@ ffi.cdef[[ -- bytes(bytes1, bytes2, bytes3, ...): allocates and concat buffer from list of byte buffers -- bytes(bytes): allocates a buffer from another one (strict replica, sharing memory) -- bytes({bytes1, bytes2, ...}): allocates and concat buffer from a list of byte buffers (table) +-- bytes({})/bytes(): allocate an empty buffer -- function _instance.new(...) local args = {...} @@ -134,7 +135,7 @@ function _instance.new(...) end instance._MANAGED = true instance._READONLY = false - elseif not arg2 and arg1:size() then + elseif not arg2 and arg1.size and arg1:size() > 0 then -- bytes(bytes): allocates a buffer from another one (strict replica, sharing memory) local b = arg1 local start = 1 @@ -147,9 +148,21 @@ function _instance.new(...) instance._REF = b -- keep lua ref for GC instance._MANAGED = false instance._READONLY = b:readonly() + else + -- bytes({}): allocate an empty buffer + instance._SIZE = 0 + instance._CDATA = nil + instance._MANAGED = false + instance._READONLY = true end + elseif arg1 == nil then + -- bytes(): allocate an empty buffer + instance._SIZE = 0 + instance._CDATA = nil + instance._MANAGED = false + instance._READONLY = true end - if instance:cdata() == nil then + if instance:size() == nil then os.raise("invalid arguments for bytes(...)!") end setmetatable(instance, _instance) |
