Remove ssize_t (#10664)

This commit is contained in:
minggo
2022-04-07 17:17:18 +08:00
committed by GitHub
parent 4cf2a9c594
commit ef013fc8c3
25 changed files with 178 additions and 215 deletions
+9 -14
View File
@@ -33,19 +33,14 @@ namespace cc {
const Data Data::NULL_DATA;
Data::Data() : _bytes(nullptr),
_size(0) {
// CC_LOG_INFO("In the empty constructor of Data.");
}
Data::Data() = default;
Data::Data(Data &&other) noexcept : _bytes(nullptr),
_size(0) {
Data::Data(Data &&other) noexcept {
// CC_LOG_INFO("In the move constructor of Data.");
move(other);
}
Data::Data(const Data &other) : _bytes(nullptr),
_size(0) {
Data::Data(const Data &other) {
// CC_LOG_INFO("In the copy constructor of Data.");
copy(other._bytes, other._size);
}
@@ -83,15 +78,15 @@ bool Data::isNull() const {
return (_bytes == nullptr || _size == 0);
}
unsigned char *Data::getBytes() const {
uint8_t *Data::getBytes() const {
return _bytes;
}
ssize_t Data::getSize() const {
uint32_t Data::getSize() const {
return _size;
}
void Data::copy(const unsigned char *bytes, ssize_t size) {
void Data::copy(const unsigned char *bytes, uint32_t size) {
clear();
if (size > 0) {
@@ -101,13 +96,13 @@ void Data::copy(const unsigned char *bytes, ssize_t size) {
}
}
void Data::fastSet(unsigned char *bytes, ssize_t size) {
void Data::fastSet(unsigned char *bytes, uint32_t size) {
free(_bytes);
_bytes = bytes;
_size = size;
}
void Data::resize(ssize_t size) {
void Data::resize(uint32_t size) {
CC_ASSERT(size);
if (_size == size) {
return;
@@ -122,7 +117,7 @@ void Data::clear() {
_size = 0;
}
unsigned char *Data::takeBuffer(ssize_t *size) {
uint8_t *Data::takeBuffer(uint32_t *size) {
auto *buffer = getBytes();
if (size) {
*size = getSize();
+10 -18
View File
@@ -27,15 +27,8 @@
#pragma once
#include <cstdint> // for ssize_t on android
#include "base/Macros.h"
#include "base/std/container/string.h" // for ssize_t on linux
/**
* @addtogroup base
* @js NA
* @lua NA
*/
namespace cc {
class CC_DLL Data {
@@ -82,21 +75,21 @@ public:
*
* @return Pointer of bytes used internal in Data.
*/
unsigned char *getBytes() const;
uint8_t *getBytes() const;
/**
* Gets the size of the bytes.
*
* @return The size of bytes of Data.
*/
ssize_t getSize() const;
uint32_t getSize() const;
/** Copies the buffer pointer and its size.
* @note This method will copy the whole buffer.
* Developer should free the pointer after invoking this method.
* @see Data::fastSet
*/
void copy(const unsigned char *bytes, ssize_t size);
void copy(const unsigned char *bytes, uint32_t size);
/** Fast set the buffer pointer and its size. Please use it carefully.
* @param bytes The buffer pointer, note that it have to be allocated by 'malloc' or 'calloc',
@@ -105,9 +98,9 @@ public:
* 2. The pointer should not be used outside after it was passed to this method.
* @see Data::copy
*/
void fastSet(unsigned char *bytes, ssize_t size);
void fastSet(unsigned char *bytes, uint32_t size);
void resize(ssize_t size);
void resize(uint32_t size);
/**
* Clears data, free buffer and reset data size.
@@ -132,8 +125,8 @@ public:
* @code
* Data d;
* // ...
* ssize_t size;
* unsigned char* buffer = d.takeBuffer(&size);
* uint32_t size;
* uint8_t* buffer = d.takeBuffer(&size);
* // use buffer and size
* free(buffer);
* @endcode
@@ -141,14 +134,13 @@ public:
* @param size Will fill with the data buffer size in bytes, if you do not care buffer size, pass nullptr.
* @return the internal data buffer, free it after use.
*/
unsigned char *takeBuffer(ssize_t *size = nullptr);
unsigned char *takeBuffer(uint32_t *size = nullptr);
private:
void move(Data &other); //NOLINT
private:
unsigned char *_bytes;
ssize_t _size;
uint8_t *_bytes{nullptr};
uint32_t _size{0};
};
} // namespace cc
-14
View File
@@ -31,20 +31,6 @@
#include <cstdint>
#if (CC_PLATFORM == CC_PLATFORM_WINDOWS)
#include <BaseTsd.h>
#if !defined(__SSIZE_T) && !defined(_SSIZE_T_)
#define __SSIZE_T
typedef SSIZE_T ssize_t;
#ifndef _SSIZE_T_
#define _SSIZE_T_
#endif
#ifndef _SSIZE_T_DEFINED
#define _SSIZE_T_DEFINED
#endif
#endif // __SSIZE_T
#endif
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
#include <android/log.h>
#define CC_ASSERT(cond) \
+19 -21
View File
@@ -67,14 +67,12 @@ public:
const_iterator cend() const { return _data.cend(); }
/** Default constructor */
RefMap<K, V>()
: _data() {
RefMap<K, V>() {
static_assert(std::is_convertible<V, RefCounted *>::value, "Invalid Type for cc::Map<K, V>!");
}
/** Constructor with capacity. */
explicit RefMap<K, V>(ssize_t capacity)
: _data() {
explicit RefMap<K, V>(uint32_t capacity) {
static_assert(std::is_convertible<V, RefCounted *>::value, "Invalid Type for cc::Map<K, V>!");
_data.reserve(capacity);
}
@@ -101,28 +99,28 @@ public:
}
/** Sets capacity of the map. */
void reserve(ssize_t capacity) {
void reserve(uint32_t capacity) {
_data.reserve(capacity);
}
/** Returns the number of buckets in the Map container. */
ssize_t bucketCount() const {
return _data.bucket_count();
uint32_t bucketCount() const {
return static_cast<uint32_t>(_data.bucket_count());
}
/** Returns the number of elements in bucket n. */
ssize_t bucketSize(ssize_t n) const {
return _data.bucket_size(n);
uint32_t bucketSize(uint32_t n) const {
return static_cast<uint32_t>(_data.bucket_size(n));
}
/** Returns the bucket number where the element with key k is located. */
ssize_t bucket(const K &k) const {
uint32_t bucket(const K &k) const {
return _data.bucket(k);
}
/** The number of elements in the map. */
ssize_t size() const {
return _data.size();
uint32_t size() const {
return static_cast<uint32_t>(_data.size());
}
/**
@@ -141,8 +139,8 @@ public:
if (!_data.empty()) {
keys.reserve(_data.size());
for (auto iter = _data.cbegin(); iter != _data.cend(); ++iter) {
keys.push_back(iter->first);
for (const auto &element : _data) {
keys.push_back(element.first);
}
}
return keys;
@@ -155,9 +153,9 @@ public:
if (!_data.empty()) {
keys.reserve(_data.size() / 10);
for (auto iter = _data.cbegin(); iter != _data.cend(); ++iter) {
if (iter->second == object) {
keys.push_back(iter->first);
for (const auto &element : _data) {
if (element.second == object) {
keys.push_back(element.first);
}
}
}
@@ -258,8 +256,8 @@ public:
* leaving it with a size of 0.
*/
void clear() {
for (auto iter = _data.cbegin(); iter != _data.cend(); ++iter) {
iter->second->release();
for (const auto &element : _data) {
element.second->release();
}
_data.clear();
@@ -301,8 +299,8 @@ public:
private:
/** Retains all the objects in the map */
void addRefForAllObjects() {
for (auto iter = _data.begin(); iter != _data.end(); ++iter) {
iter->second->addRef();
for (const auto &element : _data) {
element.second->addRef();
}
}
+1 -1
View File
@@ -168,7 +168,7 @@ ccstd::string GzipedString::value() const { // NOLINT(readability-convert-member
uint8_t * outBase64{nullptr};
auto * input = reinterpret_cast<unsigned char *>(const_cast<char *>(_str.c_str()));
auto lenOfBase64 = base64Decode(input, static_cast<unsigned int>(_str.size()), &outBase64);
auto lenofUnzip = ZipUtils::inflateMemory(outBase64, static_cast<ssize_t>(lenOfBase64), &outGzip);
auto lenofUnzip = ZipUtils::inflateMemory(outBase64, static_cast<uint32_t>(lenOfBase64), &outGzip);
ccstd::string ret(outGzip, outGzip + lenofUnzip);
free(outGzip);
free(outBase64);
+20 -20
View File
@@ -63,7 +63,7 @@ bool ZipUtils::encryptionKeyIsValid = false;
// --------------------- ZipUtils ---------------------
inline void ZipUtils::decodeEncodedPvr(unsigned int *data, ssize_t len) {
inline void ZipUtils::decodeEncodedPvr(unsigned int *data, uint32_t len) {
const int enclen = 1024;
const int securelen = 512;
const int distance = 64;
@@ -126,7 +126,7 @@ inline void ZipUtils::decodeEncodedPvr(unsigned int *data, ssize_t len) {
}
}
inline unsigned int ZipUtils::checksumPvr(const unsigned int *data, ssize_t len) {
inline unsigned int ZipUtils::checksumPvr(const unsigned int *data, uint32_t len) {
unsigned int cs = 0;
const int cslen = 128;
@@ -143,11 +143,11 @@ inline unsigned int ZipUtils::checksumPvr(const unsigned int *data, ssize_t len)
// Should buffer factor be 1.5 instead of 2 ?
#define BUFFER_INC_FACTOR (2)
int ZipUtils::inflateMemoryWithHint(unsigned char *in, ssize_t inLength, unsigned char **out, ssize_t *outLength, ssize_t outLengthHint) {
int ZipUtils::inflateMemoryWithHint(unsigned char *in, uint32_t inLength, unsigned char **out, uint32_t *outLength, uint32_t outLengthHint) {
/* ret value */
int err = Z_OK;
ssize_t bufferSize = outLengthHint;
*out = static_cast<unsigned char *>(malloc(bufferSize));
int err = Z_OK;
uint32_t bufferSize = outLengthHint;
*out = static_cast<unsigned char *>(malloc(bufferSize));
z_stream descompressionStream; /* decompression stream */
descompressionStream.zalloc = static_cast<alloc_func>(nullptr);
@@ -155,9 +155,9 @@ int ZipUtils::inflateMemoryWithHint(unsigned char *in, ssize_t inLength, unsigne
descompressionStream.opaque = static_cast<voidpf>(nullptr);
descompressionStream.next_in = in;
descompressionStream.avail_in = static_cast<unsigned int>(inLength);
descompressionStream.avail_in = inLength;
descompressionStream.next_out = *out;
descompressionStream.avail_out = static_cast<unsigned int>(bufferSize);
descompressionStream.avail_out = bufferSize;
/* window size to hold 256k */
if ((err = inflateInit2(&descompressionStream, 15 + 32)) != Z_OK) {
@@ -202,9 +202,9 @@ int ZipUtils::inflateMemoryWithHint(unsigned char *in, ssize_t inLength, unsigne
return err;
}
ssize_t ZipUtils::inflateMemoryWithHint(unsigned char *in, ssize_t inLength, unsigned char **out, ssize_t outLengthHint) {
ssize_t outLength = 0;
int err = inflateMemoryWithHint(in, inLength, out, &outLength, outLengthHint);
uint32_t ZipUtils::inflateMemoryWithHint(unsigned char *in, uint32_t inLength, unsigned char **out, uint32_t outLengthHint) {
uint32_t outLength = 0;
int err = inflateMemoryWithHint(in, inLength, out, &outLength, outLengthHint);
if (err != Z_OK || *out == nullptr) {
if (err == Z_MEM_ERROR) {
@@ -227,7 +227,7 @@ ssize_t ZipUtils::inflateMemoryWithHint(unsigned char *in, ssize_t inLength, uns
return outLength;
}
ssize_t ZipUtils::inflateMemory(unsigned char *in, ssize_t inLength, unsigned char **out) {
uint32_t ZipUtils::inflateMemory(unsigned char *in, uint32_t inLength, unsigned char **out) {
// 256k for hint
return inflateMemoryWithHint(in, inLength, out, 256 * 1024);
}
@@ -307,8 +307,8 @@ bool ZipUtils::isCCZFile(const char *path) {
return isCCZBuffer(compressedData.getBytes(), compressedData.getSize());
}
bool ZipUtils::isCCZBuffer(const unsigned char *buffer, ssize_t len) {
if (static_cast<size_t>(len) < sizeof(struct CCZHeader)) {
bool ZipUtils::isCCZBuffer(const unsigned char *buffer, uint32_t len) {
if (len < sizeof(struct CCZHeader)) {
return false;
}
@@ -328,7 +328,7 @@ bool ZipUtils::isGZipFile(const char *path) {
return isGZipBuffer(compressedData.getBytes(), compressedData.getSize());
}
bool ZipUtils::isGZipBuffer(const unsigned char *buffer, ssize_t len) {
bool ZipUtils::isGZipBuffer(const unsigned char *buffer, uint32_t len) {
if (len < 2) {
return false;
}
@@ -336,7 +336,7 @@ bool ZipUtils::isGZipBuffer(const unsigned char *buffer, ssize_t len) {
return buffer[0] == 0x1F && buffer[1] == 0x8B;
}
int ZipUtils::inflateCCZBuffer(const unsigned char *buffer, ssize_t bufferLen, unsigned char **out) {
int ZipUtils::inflateCCZBuffer(const unsigned char *buffer, uint32_t bufferLen, unsigned char **out) {
const auto *header = reinterpret_cast<const struct CCZHeader *>(buffer);
// verify header
@@ -372,8 +372,8 @@ int ZipUtils::inflateCCZBuffer(const unsigned char *buffer, ssize_t bufferLen, u
#if CC_DEBUG > 0
// decrypt
auto * ints = reinterpret_cast<unsigned int *>(const_cast<unsigned char *>(buffer) + 12);
ssize_t enclen = (bufferLen - 12) / 4;
auto * ints = reinterpret_cast<unsigned int *>(const_cast<unsigned char *>(buffer) + 12);
uint32_t enclen = (bufferLen - 12) / 4;
decodeEncodedPvr(ints, enclen);
// verify checksum in debug mode
@@ -548,7 +548,7 @@ bool ZipFile::fileExists(const ccstd::string &fileName) const {
return ret;
}
unsigned char *ZipFile::getFileData(const ccstd::string &fileName, ssize_t *size) {
unsigned char *ZipFile::getFileData(const ccstd::string &fileName, uint32_t *size) {
unsigned char *buffer = nullptr;
if (size) {
*size = 0;
@@ -576,7 +576,7 @@ unsigned char *ZipFile::getFileData(const ccstd::string &fileName, ssize_t *size
CCASSERT(nSize == 0 || nSize == (int)fileInfo.uncompressed_size, "the file size is wrong");
if (size) {
*size = fileInfo.uncompressed_size;
*size = static_cast<uint32_t>(fileInfo.uncompressed_size);
}
unzCloseCurrentFile(*zipFile);
} while (false);
+9 -12
View File
@@ -33,9 +33,6 @@
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
#include "platform/android/FileUtils-android.h"
#elif (CC_PLATFORM == CC_PLATFORM_WINDOWS)
// for import ssize_t on win32 platform
#include "platform/StdC.h"
#endif
namespace cc {
@@ -68,7 +65,7 @@ public:
* @return The length of the deflated buffer.
* @since v0.8.1
*/
static ssize_t inflateMemory(unsigned char *in, ssize_t inLength, unsigned char **out);
static uint32_t inflateMemory(unsigned char *in, uint32_t inLength, unsigned char **out);
/**
* Inflates either zlib or gzip deflated memory. The inflated memory is expected to be freed by the caller.
@@ -78,7 +75,7 @@ public:
* @return The length of the deflated buffer.
* @since v1.0.0
*/
static ssize_t inflateMemoryWithHint(unsigned char *in, ssize_t inLength, unsigned char **out, ssize_t outLengthHint);
static uint32_t inflateMemoryWithHint(unsigned char *in, uint32_t inLength, unsigned char **out, uint32_t outLengthHint);
/**
* Inflates a GZip file into memory.
@@ -102,7 +99,7 @@ public:
* @return True is GZip format. false is not.
* @since v3.0
*/
static bool isGZipBuffer(const unsigned char *buffer, ssize_t len);
static bool isGZipBuffer(const unsigned char *buffer, uint32_t len);
/**
* Inflates a CCZ file into memory.
@@ -118,7 +115,7 @@ public:
* @return The length of the deflated buffer.
* @since v3.0
*/
static int inflateCCZBuffer(const unsigned char *buffer, ssize_t len, unsigned char **out);
static int inflateCCZBuffer(const unsigned char *buffer, uint32_t len, unsigned char **out);
/**
* Test a file is a CCZ format file or not.
@@ -134,7 +131,7 @@ public:
* @return True is CCZ format. false is not.
* @since v3.0
*/
static bool isCCZBuffer(const unsigned char *buffer, ssize_t len);
static bool isCCZBuffer(const unsigned char *buffer, uint32_t len);
/**
* Sets the pvr.ccz encryption key parts separately for added security.
@@ -187,9 +184,9 @@ public:
static void setPvrEncryptionKey(unsigned int keyPart1, unsigned int keyPart2, unsigned int keyPart3, unsigned int keyPart4);
private:
static int inflateMemoryWithHint(unsigned char *in, ssize_t inLength, unsigned char **out, ssize_t *outLength, ssize_t outLengthHint);
static inline void decodeEncodedPvr(unsigned int *data, ssize_t len);
static inline unsigned int checksumPvr(const unsigned int *data, ssize_t len);
static int inflateMemoryWithHint(unsigned char *in, uint32_t inLength, unsigned char **out, uint32_t *outLength, uint32_t outLengthHint);
static inline void decodeEncodedPvr(unsigned int *data, uint32_t len);
static inline unsigned int checksumPvr(const unsigned int *data, uint32_t len);
static unsigned int encryptedPvrKeyParts[4];
static unsigned int encryptionKey[1024];
@@ -252,7 +249,7 @@ public:
*
* @since v2.0.5
*/
unsigned char *getFileData(const ccstd::string &fileName, ssize_t *size);
unsigned char *getFileData(const ccstd::string &fileName, uint32_t *size);
/**
* Get resource file data from a zip file.
@@ -786,7 +786,7 @@ bool ScriptEngine::isValid() const {
return _isValid;
}
bool ScriptEngine::evalString(const char *script, ssize_t length /* = -1 */, Value *ret /* = nullptr */, const char *fileName /* = nullptr */) {
bool ScriptEngine::evalString(const char *script, uint32_t length /* = 0 */, Value *ret /* = nullptr */, const char *fileName /* = nullptr */) {
if (_engineThreadId != std::this_thread::get_id()) {
// `evalString` should run in main thread
assert(false);
@@ -794,8 +794,8 @@ bool ScriptEngine::evalString(const char *script, ssize_t length /* = -1 */, Val
}
assert(script != nullptr);
if (length < 0) {
length = static_cast<ssize_t>(strlen(script));
if (length == 0) {
length = static_cast<uint32_t>(strlen(script));
}
if (fileName == nullptr) {
@@ -1032,7 +1032,7 @@ bool ScriptEngine::runScript(const ccstd::string &path, Value *ret /* = nullptr
ccstd::string scriptBuffer = _fileOperationDelegate.onGetStringFromFile(path);
if (!scriptBuffer.empty()) {
return evalString(scriptBuffer.c_str(), static_cast<ssize_t>(scriptBuffer.length()), ret, path.c_str());
return evalString(scriptBuffer.c_str(), static_cast<uint32_t>(scriptBuffer.length()), ret, path.c_str());
}
SE_LOGE("ScriptEngine::runScript script %s, buffer is empty!\n", path.c_str());
@@ -171,12 +171,12 @@ public:
/**
* @brief Executes a utf-8 string buffer which contains JavaScript code.
* @param[in] script A utf-8 string buffer, if it isn't null-terminated, parameter `length` should be assigned and > 0.
* @param[in] length The length of parameter `scriptStr`, it will be set to string length internally if passing < 0 and parameter `scriptStr` is null-terminated.
* @param[in] length The length of parameter `scriptStr`, it will be set to string length internally if passing 0 and parameter `scriptStr` is null-terminated.
* @param[in] ret The se::Value that results from evaluating script. Passing nullptr if you don't care about the result.
* @param[in] fileName A string containing a URL for the script's source file. This is used by debuggers and when reporting exceptions. Pass NULL if you do not care to include source file information.
* @return true if succeed, otherwise false.
*/
bool evalString(const char *script, ssize_t length = -1, Value *ret = nullptr, const char *fileName = nullptr);
bool evalString(const char *script, uint32_t length = 0, Value *ret = nullptr, const char *fileName = nullptr);
/**
* @brief Compile script file into v8::ScriptCompiler::CachedData and save to file.
+7 -7
View File
@@ -924,13 +924,13 @@ static bool JSB_zipUtils_inflateMemory(se::State &s) { //NOLINT
unsigned char *arg2 = nullptr;
int32_t len = 0;
if (argc == 1) {
len = ZipUtils::inflateMemory(arg0, static_cast<ssize_t>(arg1), &arg2);
len = ZipUtils::inflateMemory(arg0, static_cast<uint32_t>(arg1), &arg2);
} else if (argc == 2) {
SE_PRECONDITION2(args[1].isNumber(), false, "outLengthHint is invalid!");
int32_t outLengthHint = 0;
uint32_t outLengthHint = 0;
if (!args[1].isUndefined()) {
outLengthHint = args[1].toInt32();
len = ZipUtils::inflateMemoryWithHint(arg0, static_cast<ssize_t>(arg1), &arg2, outLengthHint);
outLengthHint = args[1].toUint32();
len = ZipUtils::inflateMemoryWithHint(arg0, static_cast<uint32_t>(arg1), &arg2, outLengthHint);
} else {
ok = false;
}
@@ -1015,7 +1015,7 @@ static bool JSB_zipUtils_isGZipBuffer(se::State &s) { //NOLINT
ok = false;
}
SE_PRECONDITION2(ok, false, "args[0] is not in type of string | ArrayBuffer | TypedArray");
bool flag = ZipUtils::isGZipBuffer(arg0, static_cast<ssize_t>(arg1));
bool flag = ZipUtils::isGZipBuffer(arg0, static_cast<uint32_t>(arg1));
s.rval().setBoolean(flag);
return true;
}
@@ -1073,7 +1073,7 @@ static bool JSB_zipUtils_inflateCCZBuffer(se::State &s) { //NOLINT
}
SE_PRECONDITION2(ok, false, "args[0] is not in type of string | ArrayBuffer | TypedArray");
unsigned char * arg2 = nullptr;
int32_t len = ZipUtils::inflateCCZBuffer(arg0, static_cast<ssize_t>(arg1), &arg2);
int32_t len = ZipUtils::inflateCCZBuffer(arg0, static_cast<uint32_t>(arg1), &arg2);
se::HandleObject seObj(se::Object::createArrayBufferObject(arg2, len));
if (!seObj.isEmpty() && len > 0) {
s.rval().setObject(seObj);
@@ -1130,7 +1130,7 @@ static bool JSB_zipUtils_isCCZBuffer(se::State &s) { //NOLINT
ok = false;
}
SE_PRECONDITION2(ok, false, "args[0] is not in type of string | ArrayBuffer | TypedArray");
bool flag = ZipUtils::isCCZBuffer(arg0, static_cast<ssize_t>(arg1));
bool flag = ZipUtils::isCCZBuffer(arg0, static_cast<uint32_t>(arg1));
s.rval().setBoolean(flag);
return true;
}
@@ -102,7 +102,7 @@ void jsb_init_file_operation_delegate() { //NOLINT
if (FileUtils::getInstance()->isFileExist(byteCodePath)) {
fileData = FileUtils::getInstance()->getDataFromFile(byteCodePath);
size_t dataLen = 0;
uint32_t dataLen = 0;
uint8_t *data = xxtea_decrypt(fileData.getBytes(), static_cast<uint32_t>(fileData.getSize()),
const_cast<unsigned char *>(xxteaKey.data()),
static_cast<uint32_t>(xxteaKey.size()), reinterpret_cast<uint32_t *>(&dataLen));
@@ -114,7 +114,7 @@ void jsb_init_file_operation_delegate() { //NOLINT
if (ZipUtils::isGZipBuffer(data, dataLen)) {
uint8_t *unpackedData;
ssize_t unpackedLen = ZipUtils::inflateMemory(data, dataLen, &unpackedData);
uint32_t unpackedLen = ZipUtils::inflateMemory(data, dataLen, &unpackedData);
if (unpackedData == nullptr) {
SE_REPORT_ERROR("Can't decrypt code for %s", byteCodePath.c_str());
@@ -155,7 +155,7 @@ void jsb_init_file_operation_delegate() { //NOLINT
if (ZipUtils::isGZipBuffer(data, dataLen)) {
uint8_t *unpackedData;
ssize_t unpackedLen = ZipUtils::inflateMemory(data, dataLen, &unpackedData);
uint32_t unpackedLen = ZipUtils::inflateMemory(data, dataLen, &unpackedData);
if (unpackedData == nullptr) {
SE_REPORT_ERROR("Can't decrypt code for %s", byteCodePath.c_str());
return "";
@@ -440,7 +440,7 @@ void XMLHttpRequest::onResponse(HttpClient * /*client*/, HttpResponse *response)
if (_responseType == ResponseType::STRING || _responseType == ResponseType::JSON) {
_responseText.append(buffer->data(), buffer->size());
} else {
_responseData.copy(reinterpret_cast<unsigned char *>(buffer->data()), static_cast<ssize_t>(buffer->size()));
_responseData.copy(reinterpret_cast<unsigned char *>(buffer->data()), static_cast<uint32_t>(buffer->size()));
}
_status = statusCode;
@@ -693,7 +693,7 @@ static bool XMLHttpRequest_send(se::State &s) { //NOLINT(readability-identifier-
size_t len = 0;
if (obj->getTypedArrayData(&ptr, &len)) {
Data data;
data.copy(ptr, static_cast<ssize_t>(len));
data.copy(ptr, static_cast<uint32_t>(len));
request->sendBinary(data);
} else {
SE_REPORT_ERROR("Failed to get data of TypedArray!");
@@ -704,7 +704,7 @@ static bool XMLHttpRequest_send(se::State &s) { //NOLINT(readability-identifier-
size_t len = 0;
if (obj->getArrayBufferData(&ptr, &len)) {
Data data;
data.copy(ptr, static_cast<ssize_t>(len));
data.copy(ptr, static_cast<uint32_t>(len));
request->sendBinary(data);
} else {
SE_REPORT_ERROR("Failed to get data of ArrayBufferObject!");
+3 -3
View File
@@ -167,10 +167,10 @@ public:
/**
* Get the size of request data
*
* @return ssize_t the size of request data
* @return uint32_t the size of request data
*/
inline ssize_t getRequestDataSize() const {
return static_cast<ssize_t>(_requestData.size());
inline uint32_t getRequestDataSize() const {
return static_cast<uint32_t>(_requestData.size());
}
/**
+1 -3
View File
@@ -582,9 +582,7 @@ void SIOClientImpl::connectToEndpoint(const ccstd::string &endpoint) {
}
void SIOClientImpl::disconnectFromEndpoint(const ccstd::string &endpoint) {
size_t clientCount = _clients.size();
if (clientCount == 1 || endpoint == "/") {
if (_clients.size() == 1 || endpoint == "/") {
CC_LOG_INFO("SIOClientImpl::disconnectFromEndpoint out of endpoints, checking for disconnect");
if (_connected) {
+22 -25
View File
@@ -32,7 +32,9 @@
#error WebSocket must be compiled with ARC enabled
#endif
static ccstd::vector<cc::network::WebSocket *> *__websocketInstances = nullptr;
namespace {
ccstd::vector<cc::network::WebSocket *> websocketInstances;
}
@interface WebSocketImpl : NSObject <SRWebSocketDelegate> {
}
@@ -188,38 +190,33 @@ namespace cc {
namespace network {
void WebSocket::closeAllConnections() {
if (__websocketInstances != nullptr) {
ssize_t count = __websocketInstances->size();
for (ssize_t i = count - 1; i >= 0; i--) {
WebSocket *instance = __websocketInstances->at(i);
instance->close();
}
__websocketInstances->clear();
delete __websocketInstances;
__websocketInstances = nullptr;
if (websocketInstances.empty()) {
return;
}
for (auto iter = websocketInstances.cbegin(); iter != websocketInstances.cend(); ++iter) {
(*iter)->close();
++iter;
}
websocketInstances.clear();
}
WebSocket::WebSocket()
: _impl(nil) {
if (__websocketInstances == nullptr) {
__websocketInstances = new (std::nothrow) ccstd::vector<WebSocket *>();
}
__websocketInstances->push_back(this);
WebSocket::WebSocket() {
websocketInstances.push_back(this);
}
WebSocket::~WebSocket() {
// NSLog(@"In the destructor of WebSocket-apple (%p).", this);
if (websocketInstances.empty()) {
return;
}
if (__websocketInstances != nullptr) {
auto iter = std::find(__websocketInstances->begin(), __websocketInstances->end(), this);
if (iter != __websocketInstances->end()) {
__websocketInstances->erase(iter);
} else {
NSLog(@"ERROR: WebSocket instance wasn't added to the container which saves websocket instances!");
}
auto iter = std::find(websocketInstances.begin(), websocketInstances.end(), this);
if (iter != websocketInstances.end()) {
websocketInstances.erase(iter);
} else {
NSLog(@"ERROR: WebSocket instance wasn't added to the container which saves websocket instances!");
}
}
+10 -10
View File
@@ -87,11 +87,11 @@ public:
*/
struct Data {
Data() = default;
char * bytes{nullptr};
ssize_t len{0}, issued{0};
bool isBinary{false};
void * ext{nullptr};
ssize_t getRemain() const { return std::max(static_cast<ssize_t>(0), len - issued); }
char * bytes{nullptr};
uint32_t len{0}, issued{0};
bool isBinary{false};
void * ext{nullptr};
uint32_t getRemain() const { return std::max(static_cast<uint32_t>(0), len - issued); }
};
/**
@@ -126,7 +126,7 @@ public:
/**
* This function to be called after the client connection complete a handshake with the remote server.
* This means that the WebSocket connection is ready to send and receive data.
*
*
* @param ws The WebSocket object connected
*/
virtual void onOpen(WebSocket *ws) = 0;
@@ -173,7 +173,7 @@ public:
/**
* @brief Sends string data to websocket server.
*
*
* @param message string data.
* @lua sendstring
*/
@@ -181,7 +181,7 @@ public:
/**
* @brief Sends binary data to websocket server.
*
*
* @param binaryMsg binary string data.
* @param len the size of binary string data.
* @lua sendstring
@@ -197,7 +197,7 @@ public:
/**
* @brief Closes the connection to server asynchronously.
* @note It's an asynchronous method, it just notifies websocket thread to exit and returns directly,
* If using 'closeAsync' to close websocket connection,
* If using 'closeAsync' to close websocket connection,
* be careful of not using destructed variables in the callback of 'onClose'.
*/
void closeAsync();
@@ -241,7 +241,7 @@ public:
Delegate *getDelegate() const;
private:
WebSocketImpl *_impl;
WebSocketImpl *_impl{nullptr};
};
} // namespace network
+3 -3
View File
@@ -492,8 +492,8 @@ FileUtils::~FileUtils() = default;
bool FileUtils::writeStringToFile(const ccstd::string &dataStr, const ccstd::string &fullPath) {
Data data;
char *dataP = const_cast<char *>(dataStr.data());
data.fastSet(reinterpret_cast<unsigned char *>(dataP), dataStr.size());
auto *dataP = const_cast<char *>(dataStr.data());
data.fastSet(reinterpret_cast<unsigned char *>(dataP), static_cast<uint32_t>(dataStr.size()));
bool rv = writeDataToFile(data, fullPath);
@@ -587,7 +587,7 @@ FileUtils::Status FileUtils::getContents(const ccstd::string &filename, Resizabl
return Status::OK;
}
unsigned char *FileUtils::getFileDataFromZip(const ccstd::string &zipFilePath, const ccstd::string &filename, ssize_t *size) {
unsigned char *FileUtils::getFileDataFromZip(const ccstd::string &zipFilePath, const ccstd::string &filename, uint32_t *size) {
unsigned char *buffer = nullptr;
unzFile file = nullptr;
*size = 0;
+3 -3
View File
@@ -90,13 +90,13 @@ class ResizableBufferAdapter<Data> : public ResizableBuffer {
public:
explicit ResizableBufferAdapter(BufferType *buffer) : _buffer(buffer) {}
void resize(size_t size) override {
auto oldSize = static_cast<size_t>(_buffer->getSize());
size_t oldSize = _buffer->getSize();
if (oldSize != size) {
// need to take buffer ownership for outer memory control
auto *old = _buffer->takeBuffer();
void *buffer = realloc(old, size);
if (buffer) {
_buffer->fastSet(static_cast<unsigned char *>(buffer), size);
_buffer->fastSet(static_cast<unsigned char *>(buffer), static_cast<uint32_t>(size));
}
}
}
@@ -239,7 +239,7 @@ public:
* @return Upon success, a pointer to the data is returned, otherwise nullptr.
* @warning Recall: you are responsible for calling free() on any Non-nullptr pointer returned.
*/
virtual unsigned char *getFileDataFromZip(const ccstd::string &zipFilePath, const ccstd::string &filename, ssize_t *size);
virtual unsigned char *getFileDataFromZip(const ccstd::string &zipFilePath, const ccstd::string &filename, uint32_t *size);
/** Returns the fullpath for a given filename.
+22 -22
View File
@@ -243,7 +243,7 @@ using PVRv3TexHeader = struct {
namespace {
using tImageSource = struct {
const unsigned char *data;
ssize_t size;
uint32_t size;
int offset;
};
@@ -287,14 +287,14 @@ bool Image::initWithImageFile(const ccstd::string &path) {
return ret;
}
bool Image::initWithImageData(const unsigned char *data, ssize_t dataLen) {
bool Image::initWithImageData(const unsigned char *data, uint32_t dataLen) {
bool ret = false;
do {
CC_BREAK_IF(!data || dataLen <= 0);
unsigned char *unpackedData = nullptr;
ssize_t unpackedLen = 0;
uint32_t unpackedLen = 0;
//detect and unzip the compress file
if (ZipUtils::isCCZBuffer(data, dataLen)) {
@@ -342,7 +342,7 @@ bool Image::initWithImageData(const unsigned char *data, ssize_t dataLen) {
return ret;
}
bool Image::isPng(const unsigned char *data, ssize_t dataLen) {
bool Image::isPng(const unsigned char *data, uint32_t dataLen) {
if (dataLen <= 8) {
return false;
}
@@ -352,19 +352,19 @@ bool Image::isPng(const unsigned char *data, ssize_t dataLen) {
return memcmp(PNG_SIGNATURE, data, sizeof(PNG_SIGNATURE)) == 0;
}
bool Image::isEtc(const unsigned char *data, ssize_t /*dataLen*/) {
bool Image::isEtc(const unsigned char *data, uint32_t /*dataLen*/) {
return etc1_pkm_is_valid(const_cast<etc1_byte *>(data)) != 0;
}
bool Image::isEtc2(const unsigned char *data, ssize_t /*dataLen*/) {
bool Image::isEtc2(const unsigned char *data, uint32_t /*dataLen*/) {
return etc2_pkm_is_valid(const_cast<etc2_byte *>(data)) != 0;
}
bool Image::isASTC(const unsigned char *data, ssize_t /*dataLen*/) {
bool Image::isASTC(const unsigned char *data, uint32_t /*dataLen*/) {
return astcIsValid(const_cast<astc_byte *>(data));
}
bool Image::isJpg(const unsigned char *data, ssize_t dataLen) {
bool Image::isJpg(const unsigned char *data, uint32_t dataLen) {
if (dataLen <= 4) {
return false;
}
@@ -374,7 +374,7 @@ bool Image::isJpg(const unsigned char *data, ssize_t dataLen) {
return memcmp(data, JPG_SOI, 2) == 0;
}
bool Image::isWebp(const unsigned char *data, ssize_t dataLen) {
bool Image::isWebp(const unsigned char *data, uint32_t dataLen) {
if (dataLen <= 12) {
return false;
}
@@ -385,7 +385,7 @@ bool Image::isWebp(const unsigned char *data, ssize_t dataLen) {
return memcmp(data, webpRiff, 4) == 0 && memcmp(static_cast<const unsigned char *>(data) + 8, webpWebp, 4) == 0;
}
bool Image::isPvr(const unsigned char *data, ssize_t dataLen) {
bool Image::isPvr(const unsigned char *data, uint32_t dataLen) {
if (static_cast<size_t>(dataLen) < sizeof(PVRv2TexHeader) || static_cast<size_t>(dataLen) < sizeof(PVRv3TexHeader)) {
return false;
}
@@ -396,7 +396,7 @@ bool Image::isPvr(const unsigned char *data, ssize_t dataLen) {
return memcmp(&headerv2->pvrTag, G_PVR_TEX_IDENTIFIER, strlen(G_PVR_TEX_IDENTIFIER)) == 0 || CC_SWAP_INT32_BIG_TO_HOST(headerv3->version) == 0x50565203;
}
Image::Format Image::detectFormat(const unsigned char *data, ssize_t dataLen) {
Image::Format Image::detectFormat(const unsigned char *data, uint32_t dataLen) {
if (isPng(data, dataLen)) {
return Format::PNG;
}
@@ -504,7 +504,7 @@ void myErrorExit(j_common_ptr cinfo) {
#endif // CC_USE_JPEG
} // namespace
bool Image::initWithJpgData(const unsigned char *data, ssize_t dataLen) {
bool Image::initWithJpgData(const unsigned char *data, uint32_t dataLen) {
#if CC_USE_JPEG
/* these are standard libjpeg structures for reading(decompression) */
struct jpeg_decompress_struct cinfo;
@@ -586,7 +586,7 @@ bool Image::initWithJpgData(const unsigned char *data, ssize_t dataLen) {
#endif // CC_USE_JPEG
}
bool Image::initWithPngData(const unsigned char *data, ssize_t dataLen) {
bool Image::initWithPngData(const unsigned char *data, uint32_t dataLen) {
#if CC_USE_PNG
// length of bytes to check if it is a valid png file
#define PNGSIGSIZE 8
@@ -683,7 +683,7 @@ bool Image::initWithPngData(const unsigned char *data, ssize_t dataLen) {
rowbytes = png_get_rowbytes(pngPtr, infoPtr);
_dataLen = rowbytes * _height;
_dataLen = static_cast<uint32_t>(rowbytes * _height);
_data = static_cast<unsigned char *>(malloc(_dataLen * sizeof(unsigned char)));
if (!_data) {
if (rowPointers != nullptr) {
@@ -712,7 +712,7 @@ bool Image::initWithPngData(const unsigned char *data, ssize_t dataLen) {
#endif //CC_USE_PNG
}
bool Image::initWithPVRv2Data(const unsigned char *data, ssize_t dataLen) {
bool Image::initWithPVRv2Data(const unsigned char *data, uint32_t dataLen) {
int width = 0;
int height = 0;
@@ -757,7 +757,7 @@ bool Image::initWithPVRv2Data(const unsigned char *data, ssize_t dataLen) {
return true;
}
bool Image::initWithPVRv3Data(const unsigned char *data, ssize_t dataLen) {
bool Image::initWithPVRv3Data(const unsigned char *data, uint32_t dataLen) {
if (static_cast<size_t>(dataLen) < sizeof(PVRv3TexHeader)) {
return false;
}
@@ -800,7 +800,7 @@ bool Image::initWithPVRv3Data(const unsigned char *data, ssize_t dataLen) {
return true;
}
bool Image::initWithETCData(const unsigned char *data, ssize_t dataLen) {
bool Image::initWithETCData(const unsigned char *data, uint32_t dataLen) {
const auto *header = static_cast<const etc1_byte *>(data);
//check the data
@@ -823,7 +823,7 @@ bool Image::initWithETCData(const unsigned char *data, ssize_t dataLen) {
return true;
}
bool Image::initWithETC2Data(const unsigned char *data, ssize_t dataLen) {
bool Image::initWithETC2Data(const unsigned char *data, uint32_t dataLen) {
const auto *header = static_cast<const etc2_byte *>(data);
//check the data
@@ -852,7 +852,7 @@ bool Image::initWithETC2Data(const unsigned char *data, ssize_t dataLen) {
return true;
}
bool Image::initWithASTCData(const unsigned char *data, ssize_t dataLen) {
bool Image::initWithASTCData(const unsigned char *data, uint32_t dataLen) {
const auto *header = static_cast<const astc_byte *>(data);
//check the data
@@ -881,11 +881,11 @@ bool Image::initWithASTCData(const unsigned char *data, ssize_t dataLen) {
return true;
}
bool Image::initWithPVRData(const unsigned char *data, ssize_t dataLen) {
bool Image::initWithPVRData(const unsigned char *data, uint32_t dataLen) {
return initWithPVRv2Data(data, dataLen) || initWithPVRv3Data(data, dataLen);
}
bool Image::initWithWebpData(const unsigned char *data, ssize_t dataLen) {
bool Image::initWithWebpData(const unsigned char *data, uint32_t dataLen) {
#if CC_USE_WEBP
bool ret = false;
@@ -921,7 +921,7 @@ bool Image::initWithWebpData(const unsigned char *data, ssize_t dataLen) {
#endif // CC_USE_WEBP
}
bool Image::initWithRawData(const unsigned char *data, ssize_t /*dataLen*/, int width, int height, int /*bitsPerComponent*/, bool /*preMulti*/) {
bool Image::initWithRawData(const unsigned char *data, uint32_t /*dataLen*/, int width, int height, int /*bitsPerComponent*/, bool /*preMulti*/) {
bool ret = false;
do {
CC_BREAK_IF(0 == width || 0 == height);
+21 -21
View File
@@ -61,10 +61,10 @@ public:
};
bool initWithImageFile(const ccstd::string &path);
bool initWithImageData(const unsigned char *data, ssize_t dataLen);
bool initWithImageData(const unsigned char *data, uint32_t dataLen);
// @warning kFmtRawData only support RGBA8888
bool initWithRawData(const unsigned char *data, ssize_t dataLen, int width, int height, int bitsPerComponent, bool preMulti = false);
bool initWithRawData(const unsigned char *data, uint32_t dataLen, int width, int height, int bitsPerComponent, bool preMulti = false);
// data will be free outside.
inline void takeData(unsigned char **outData) {
@@ -74,7 +74,7 @@ public:
// Getters
inline unsigned char *getData() const { return _data; }
inline ssize_t getDataLen() const { return _dataLen; }
inline uint32_t getDataLen() const { return _dataLen; }
inline Format getFileType() const { return _fileType; }
inline gfx::Format getRenderFormat() const { return _renderFormat; }
inline int getWidth() const { return _width; }
@@ -84,18 +84,18 @@ public:
inline bool isCompressed() const { return _isCompressed; }
protected:
bool initWithJpgData(const unsigned char *data, ssize_t dataLen);
bool initWithPngData(const unsigned char *data, ssize_t dataLen);
bool initWithWebpData(const unsigned char *data, ssize_t dataLen);
bool initWithPVRData(const unsigned char *data, ssize_t dataLen);
bool initWithPVRv2Data(const unsigned char *data, ssize_t dataLen);
bool initWithPVRv3Data(const unsigned char *data, ssize_t dataLen);
bool initWithETCData(const unsigned char *data, ssize_t dataLen);
bool initWithETC2Data(const unsigned char *data, ssize_t dataLen);
bool initWithASTCData(const unsigned char *data, ssize_t dataLen);
bool initWithJpgData(const unsigned char *data, uint32_t dataLen);
bool initWithPngData(const unsigned char *data, uint32_t dataLen);
bool initWithWebpData(const unsigned char *data, uint32_t dataLen);
bool initWithPVRData(const unsigned char *data, uint32_t dataLen);
bool initWithPVRv2Data(const unsigned char *data, uint32_t dataLen);
bool initWithPVRv3Data(const unsigned char *data, uint32_t dataLen);
bool initWithETCData(const unsigned char *data, uint32_t dataLen);
bool initWithETC2Data(const unsigned char *data, uint32_t dataLen);
bool initWithASTCData(const unsigned char *data, uint32_t dataLen);
unsigned char *_data = nullptr;
ssize_t _dataLen = 0;
uint32_t _dataLen = 0;
int _width = 0;
int _height = 0;
Format _fileType = Format::UNKNOWN;
@@ -103,14 +103,14 @@ protected:
ccstd::string _filePath;
bool _isCompressed = false;
static Format detectFormat(const unsigned char *data, ssize_t dataLen);
static bool isPng(const unsigned char *data, ssize_t dataLen);
static bool isJpg(const unsigned char *data, ssize_t dataLen);
static bool isWebp(const unsigned char *data, ssize_t dataLen);
static bool isPvr(const unsigned char *data, ssize_t dataLen);
static bool isEtc(const unsigned char *data, ssize_t dataLen);
static bool isEtc2(const unsigned char *data, ssize_t dataLen);
static bool isASTC(const unsigned char *data, ssize_t detaLen);
static Format detectFormat(const unsigned char *data, uint32_t dataLen);
static bool isPng(const unsigned char *data, uint32_t dataLen);
static bool isJpg(const unsigned char *data, uint32_t dataLen);
static bool isWebp(const unsigned char *data, uint32_t dataLen);
static bool isPvr(const unsigned char *data, uint32_t dataLen);
static bool isEtc(const unsigned char *data, uint32_t dataLen);
static bool isEtc2(const unsigned char *data, uint32_t dataLen);
static bool isASTC(const unsigned char *data, uint32_t detaLen);
static gfx::Format getASTCFormat(const unsigned char *pHeader);
@@ -74,7 +74,7 @@ public:
private:
void fillData();
void unMultiplyAlpha(unsigned char *ptr, ssize_t size) const;
void unMultiplyAlpha(unsigned char *ptr, uint32_t size) const;
public:
private:
@@ -232,7 +232,7 @@
NSUInteger textureSize = width * height * 4;
unsigned char *data = (unsigned char *)malloc(sizeof(unsigned char) * textureSize);
memset(data, 0, textureSize);
_imageData.fastSet(data, textureSize);
_imageData.fastSet(data, static_cast<uint32_t>(textureSize));
if (_context != nil) {
CGContextRelease(_context);
@@ -632,7 +632,7 @@ void CanvasRenderingContext2DDelegate::fillData() {
}
#define CLAMP(V, HI) std::min((V), (HI))
void CanvasRenderingContext2DDelegate::unMultiplyAlpha(unsigned char *ptr, ssize_t size) const {
void CanvasRenderingContext2DDelegate::unMultiplyAlpha(unsigned char *ptr, uint32_t size) const {
float alpha;
for (int i = 0; i < size; i += 4) {
alpha = (float)ptr[i + 3];
@@ -279,7 +279,7 @@ void CanvasRenderingContext2DDelegate::updateData() {
}
}
void CanvasRenderingContext2DDelegate::unMultiplyAlpha(unsigned char *ptr, ssize_t size) { // NOLINT(readability-convert-member-functions-to-static)
void CanvasRenderingContext2DDelegate::unMultiplyAlpha(unsigned char *ptr, uint32_t size) { // NOLINT(readability-convert-member-functions-to-static)
// Android source data is not premultiplied alpha when API >= 19
// please refer CanvasRenderingContext2DImpl::recreateBuffer(float w, float h)
// in CanvasRenderingContext2DImpl.java
@@ -82,7 +82,7 @@ public:
void updateData() override;
private:
void unMultiplyAlpha(unsigned char *ptr, ssize_t size);
void unMultiplyAlpha(unsigned char *ptr, uint32_t size);
public:
private:
+1 -1
View File
@@ -27,7 +27,7 @@
#pragma once
#include <functional>
#include "base/std/container/string.h"
#include "base/Data.h"
#include "base/Macros.h"
#include "base/RefCounted.h"