diff --git a/cocos/2d/TGAlib.cpp b/cocos/2d/TGAlib.cpp index 9320b887ce..bd6c510e08 100644 --- a/cocos/2d/TGAlib.cpp +++ b/cocos/2d/TGAlib.cpp @@ -272,7 +272,7 @@ tImageTGA* tgaLoadBuffer(unsigned char* buffer, long size) // this is the function to call when we want to load an image tImageTGA * tgaLoad(const char *filename) { - long size = 0; + ssize_t size = 0; unsigned char* buffer = FileUtils::getInstance()->getFileData(filename, "rb", &size); if (buffer != nullptr) diff --git a/cocos/2d/ZipUtils.cpp b/cocos/2d/ZipUtils.cpp index 6ac9272f24..0a6be7e39b 100644 --- a/cocos/2d/ZipUtils.cpp +++ b/cocos/2d/ZipUtils.cpp @@ -306,7 +306,7 @@ bool ZipUtils::isCCZFile(const char *path) // load file into memory unsigned char* compressed = NULL; - long fileLen = 0; + ssize_t fileLen = 0; compressed = FileUtils::getInstance()->getFileData(path, "rb", &fileLen); if(compressed == NULL || fileLen == 0) @@ -321,7 +321,7 @@ bool ZipUtils::isCCZFile(const char *path) return ret; } -bool ZipUtils::isCCZBuffer(const unsigned char *buffer, long len) +bool ZipUtils::isCCZBuffer(const unsigned char *buffer, ssize_t len) { if (static_cast(len) < sizeof(struct CCZHeader)) { @@ -338,7 +338,7 @@ bool ZipUtils::isGZipFile(const char *path) // load file into memory unsigned char* compressed = NULL; - long fileLen = 0; + ssize_t fileLen = 0; compressed = FileUtils::getInstance()->getFileData(path, "rb", &fileLen); if(NULL == compressed || 0 == fileLen) @@ -352,7 +352,7 @@ bool ZipUtils::isGZipFile(const char *path) return ret; } -bool ZipUtils::isGZipBuffer(const unsigned char *buffer, long len) +bool ZipUtils::isGZipBuffer(const unsigned char *buffer, ssize_t len) { if (len < 2) { @@ -461,7 +461,7 @@ int ZipUtils::inflateCCZFile(const char *path, unsigned char **out) // load file into memory unsigned char* compressed = NULL; - long fileLen = 0; + ssize_t fileLen = 0; compressed = FileUtils::getInstance()->getFileData(path, "rb", &fileLen); if(NULL == compressed || 0 == fileLen) diff --git a/cocos/2d/ZipUtils.h b/cocos/2d/ZipUtils.h index 1d2275633b..da5ec54673 100644 --- a/cocos/2d/ZipUtils.h +++ b/cocos/2d/ZipUtils.h @@ -31,6 +31,9 @@ THE SOFTWARE. #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #include "platform/android/CCFileUtilsAndroid.h" +#elif(CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) +// for import ssize_t on win32 platform +#include "CCStdC.h" #endif namespace cocos2d diff --git a/cocos/2d/platform/win32/CCFileUtilsWin32.cpp b/cocos/2d/platform/win32/CCFileUtilsWin32.cpp index a417f34fa1..73e18f59a8 100644 --- a/cocos/2d/platform/win32/CCFileUtilsWin32.cpp +++ b/cocos/2d/platform/win32/CCFileUtilsWin32.cpp @@ -121,7 +121,7 @@ bool FileUtilsWin32::isAbsolutePath(const std::string& strPath) const return false; } -unsigned char* FileUtilsWin32::getFileData(const char* filename, const char* mode, long* size) +unsigned char* FileUtilsWin32::getFileData(const char* filename, const char* mode, ssize_t* size) { unsigned char * pBuffer = NULL; CCASSERT(filename != NULL && size != NULL && mode != NULL, "Invalid parameters."); diff --git a/cocos/2d/platform/win32/CCFileUtilsWin32.h b/cocos/2d/platform/win32/CCFileUtilsWin32.h index 5c88d97cf9..6eec9dd60e 100644 --- a/cocos/2d/platform/win32/CCFileUtilsWin32.h +++ b/cocos/2d/platform/win32/CCFileUtilsWin32.h @@ -58,7 +58,7 @@ protected: * @return Upon success, a pointer to the data is returned, otherwise NULL. * @warning Recall: you are responsible for calling delete[] on any Non-NULL pointer returned. */ - virtual unsigned char* getFileData(const char* filename, const char* mode, long * size) override; + virtual unsigned char* getFileData(const char* filename, const char* mode, ssize_t * size) override; /** * Gets full path for filename, resolution directory and search path. diff --git a/cocos/2d/platform/win32/CCStdC.h b/cocos/2d/platform/win32/CCStdC.h index 1090404d89..027c8bf3cb 100644 --- a/cocos/2d/platform/win32/CCStdC.h +++ b/cocos/2d/platform/win32/CCStdC.h @@ -25,6 +25,11 @@ THE SOFTWARE. #ifndef __CC_STD_C_H__ #define __CC_STD_C_H__ +//typedef SSIZE_T ssize_t; +// ssize_t was redefined as int in libwebsockets.h. +// Therefore, to avoid conflict, we needs the same definition. +typedef int ssize_t; + #include "CCPlatformMacros.h" #include diff --git a/cocos/base/CCAutoreleasePool.cpp b/cocos/base/CCAutoreleasePool.cpp index e55c8c9b97..8c32f4c42b 100644 --- a/cocos/base/CCAutoreleasePool.cpp +++ b/cocos/base/CCAutoreleasePool.cpp @@ -64,7 +64,7 @@ void AutoreleasePool::clear() int nIndex = _managedObjectArray.size() - 1; #endif - _managedObjectArray.forEachReverse([](Object* obj){ + _managedObjectArray.forEachReverse([&](Object* obj){ --(obj->_autoReleaseCount); //(*it)->release(); //delete (*it); diff --git a/cocos/base/CCVector.h b/cocos/base/CCVector.h index 292d70f47b..cddc02c25d 100644 --- a/cocos/base/CCVector.h +++ b/cocos/base/CCVector.h @@ -51,7 +51,7 @@ public: reserve(capacity); } - virtual ~Vector() + ~Vector() { CCLOGINFO("In the destructor of Vector."); clear(); diff --git a/cocos/editor-support/cocosbuilder/CCBReader.cpp b/cocos/editor-support/cocosbuilder/CCBReader.cpp index bd58dde191..db5733a19a 100644 --- a/cocos/editor-support/cocosbuilder/CCBReader.cpp +++ b/cocos/editor-support/cocosbuilder/CCBReader.cpp @@ -218,7 +218,7 @@ Node* CCBReader::readNodeGraphFromFile(const char *pCCBFileName, Object *pOwner, } std::string strPath = FileUtils::getInstance()->fullPathForFilename(strCCBFileName.c_str()); - long size = 0; + ssize_t size = 0; unsigned char * pBytes = FileUtils::getInstance()->getFileData(strPath.c_str(), "rb", &size); Data *data = new Data(pBytes, size); diff --git a/cocos/editor-support/cocosbuilder/CCNodeLoader.cpp b/cocos/editor-support/cocosbuilder/CCNodeLoader.cpp index 8d8d991aa9..3dceb6b7dc 100644 --- a/cocos/editor-support/cocosbuilder/CCNodeLoader.cpp +++ b/cocos/editor-support/cocosbuilder/CCNodeLoader.cpp @@ -923,7 +923,7 @@ Node * NodeLoader::parsePropTypeCCBFile(Node * pNode, Node * pParent, CCBReader // Load sub file std::string path = FileUtils::getInstance()->fullPathForFilename(ccbFileName.c_str()); - long size = 0; + ssize_t size = 0; unsigned char * pBytes = FileUtils::getInstance()->getFileData(path.c_str(), "rb", &size); CCBReader * reader = new CCBReader(pCCBReader); diff --git a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp index 00e1d7f3f4..b462ef72de 100644 --- a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp +++ b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp @@ -291,7 +291,7 @@ void DataReaderHelper::addDataFromFile(const char *filePath) size_t startPos = filePathStr.find_last_of("."); std::string str = &filePathStr[startPos]; - long size; + ssize_t size; std::string fullPath = CCFileUtils::getInstance()->fullPathForFilename(filePath); char *pFileContent = (char *)CCFileUtils::getInstance()->getFileData(fullPath.c_str() , "r", &size); @@ -391,7 +391,7 @@ void DataReaderHelper::addDataFromFileAsync(const char *imagePath, const char *p std::string str = &filePathStr[startPos]; std::string fullPath = CCFileUtils::getInstance()->fullPathForFilename(filePath); - long size; + ssize_t size; // XXX fileContent is being leaked data->fileContent = (char *)CCFileUtils::getInstance()->getFileData(fullPath.c_str() , "r", &size); diff --git a/cocos/editor-support/cocostudio/CCSGUIReader.cpp b/cocos/editor-support/cocostudio/CCSGUIReader.cpp index 9cc6348635..625627fff1 100644 --- a/cocos/editor-support/cocostudio/CCSGUIReader.cpp +++ b/cocos/editor-support/cocostudio/CCSGUIReader.cpp @@ -128,7 +128,7 @@ UIWidget* GUIReader::widgetFromJsonFile(const char *fileName) jsonpath = CCFileUtils::getInstance()->fullPathForFilename(fileName); int pos = jsonpath.find_last_of('/'); m_strFilePath = jsonpath.substr(0,pos+1); - long size = 0; + ssize_t size = 0; des = (char*)(CCFileUtils::getInstance()->getFileData(jsonpath.c_str(),"r" , &size)); if(nullptr == des || strcmp(des, "") == 0) { diff --git a/cocos/editor-support/cocostudio/CCSSceneReader.cpp b/cocos/editor-support/cocostudio/CCSSceneReader.cpp index 385c147e27..d682c504b7 100644 --- a/cocos/editor-support/cocostudio/CCSSceneReader.cpp +++ b/cocos/editor-support/cocostudio/CCSSceneReader.cpp @@ -47,7 +47,7 @@ namespace cocostudio { cocos2d::Node* SceneReader::createNodeWithSceneFile(const char* pszFileName) { - long size = 0; + ssize_t size = 0; char* pData = 0; cocos2d::Node *pNode = nullptr; do @@ -215,7 +215,7 @@ namespace cocostudio { { file_path = reDir.substr(0, pos+1); } - long size = 0; + ssize_t size = 0; char *des = (char*)(cocos2d::FileUtils::getInstance()->getFileData(pPath.c_str(),"r" , &size)); JsonDictionary *jsonDict = new JsonDictionary(); jsonDict->initWithDescription(des); @@ -285,7 +285,7 @@ namespace cocostudio { if (nResType == 0) { pAttribute = ComAttribute::create(); - long size = 0; + ssize_t size = 0; char* pData = 0; pData = (char*)(cocos2d::FileUtils::getInstance()->getFileData(pPath.c_str(), "r", &size)); if(pData != nullptr && strcmp(pData, "") != 0) diff --git a/cocos/editor-support/spine/extension.h b/cocos/editor-support/spine/extension.h index f5d1a2ac9b..a8f64b1b19 100644 --- a/cocos/editor-support/spine/extension.h +++ b/cocos/editor-support/spine/extension.h @@ -54,6 +54,11 @@ #ifndef SPINE_EXTENSION_H_ #define SPINE_EXTENSION_H_ +// for import ssize_t on win32 platform +#if defined(_MSC_VER) +#include "CCStdC.h" +#endif + /* All allocation uses these. */ #define MALLOC(TYPE,COUNT) ((TYPE*)_malloc(sizeof(TYPE) * COUNT)) #define CALLOC(TYPE,COUNT) ((TYPE*)_calloc(1, sizeof(TYPE) * COUNT)) diff --git a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj index cfd32fc8e8..b526f9588d 100644 --- a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj +++ b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj @@ -138,6 +138,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\websockets\prebuilt\win32\*.*" "$ + @@ -278,6 +279,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\websockets\prebuilt\win32\*.*" "$ + diff --git a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters index dafeb94a8f..c0fcb15592 100644 --- a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters +++ b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters @@ -304,6 +304,9 @@ {8e8124bd-adb2-4a8f-8727-9868a9c42d80} + + {709f8a27-ecc2-4fe2-abd2-f13da4b70fe8} + @@ -703,6 +706,9 @@ Classes\InputTest + + Classes\ConsoleTest + @@ -1294,5 +1300,8 @@ Classes\Box2DTestBed\Tests + + Classes\ConsoleTest + \ No newline at end of file