mirror of
https://gitee.com/openharmony/commonlibrary_ets_utils
synced 2025-02-03 08:17:08 +00:00
!1103 modify the bug for buffer.
Merge pull request !1103 from yuqing_han/master
This commit is contained in:
commit
ed4d587880
@ -69,6 +69,23 @@ void Buffer::Init(uint8_t *buffer, unsigned int byteOffset, unsigned int length)
|
||||
this->needRelease_ = false;
|
||||
}
|
||||
|
||||
void Buffer::InitUintArray(uint8_t *buffer, unsigned int byteOffset, unsigned int length)
|
||||
{
|
||||
if (buffer != nullptr && length >= 0) {
|
||||
this->raw_ = reinterpret_cast<uint8_t *>(malloc(length));
|
||||
this->needRelease_ = true;
|
||||
if (raw_ == nullptr) {
|
||||
HILOG_FATAL("Buffer constructor malloc failed");
|
||||
} else {
|
||||
this->length_ = length;
|
||||
this->byteOffset_ = byteOffset;
|
||||
if (memcpy_s(this->raw_, this->length_, buffer, length) != EOK) {
|
||||
HILOG_FATAL("Buffer constructor memcpy_s failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Buffer::~Buffer()
|
||||
{
|
||||
if (raw_ != nullptr && needRelease_) {
|
||||
|
@ -34,6 +34,7 @@ public:
|
||||
void Init(Buffer *buffer);
|
||||
void Init(Buffer *pool, unsigned int poolOffset, unsigned int length);
|
||||
void Init(uint8_t *buffer, unsigned int byteOffset, unsigned int length);
|
||||
void InitUintArray(uint8_t *buffer, unsigned int byteOffset, unsigned int length);
|
||||
|
||||
unsigned int GetLength();
|
||||
void SetLength(unsigned int len);
|
||||
|
@ -43,6 +43,7 @@ void FinalizeBufferCallback(napi_env env, void *finalizeData, void *finalizeHint
|
||||
if (finalizeData != nullptr) {
|
||||
auto obj = reinterpret_cast<Buffer *>(finalizeData);
|
||||
delete obj;
|
||||
obj = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,6 +52,7 @@ void FinalizeBlobCallback(napi_env env, void *finalizeData, void *finalizeHint)
|
||||
if (finalizeData != nullptr) {
|
||||
auto obj = reinterpret_cast<Blob *>(finalizeData);
|
||||
delete obj;
|
||||
obj = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -323,7 +325,7 @@ static Buffer* BufferConstructorInner(napi_env env, size_t argc, napi_value* arg
|
||||
void *resultData = nullptr;
|
||||
napi_value resultBuffer = nullptr;
|
||||
NAPI_CALL(env, napi_get_typedarray_info(env, argv[1], &type, &aryLen, &resultData, &resultBuffer, &offset));
|
||||
buffer->Init(reinterpret_cast<uint8_t *>(resultData) - offset, offset, aryLen);
|
||||
buffer->InitUintArray(reinterpret_cast<uint8_t *>(resultData) - offset, offset, aryLen);
|
||||
} else if (paraType == ParaType::ARRAYBUFFER) {
|
||||
void *data = nullptr;
|
||||
size_t bufferSize = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user