From 9dbca009ed783363488d26bf1f461a85874cefac Mon Sep 17 00:00:00 2001 From: minggo Date: Tue, 12 Apr 2022 14:58:34 +0800 Subject: [PATCH] Treat warning as error for more codes (#10732) * fix some warnings * treat warning as error --- native/CMakeLists.txt | 84 ++++--- .../cocos/bindings/manual/jsb_conversions.h | 4 +- .../bindings/manual/jsb_extension_manual.cpp | 220 ------------------ .../bindings/manual/jsb_extension_manual.h | 32 --- native/cocos/bindings/manual/jsb_global.cpp | 2 +- 5 files changed, 44 insertions(+), 298 deletions(-) delete mode 100644 native/cocos/bindings/manual/jsb_extension_manual.cpp delete mode 100644 native/cocos/bindings/manual/jsb_extension_manual.h diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index 6bce6d1bd7..a29ff840a0 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -768,7 +768,7 @@ cocos_source_files( if(USE_SOCKET) cocos_source_files( cocos/network/WebSocket.h - NO_WERROR cocos/network/SocketIO.cpp + cocos/network/SocketIO.cpp cocos/network/SocketIO.h ) endif() @@ -776,7 +776,7 @@ endif() if(NOT IOS AND USE_WEBSOCKET_SERVER) cocos_source_files( cocos/network/WebSocketServer.h - NO_WERROR cocos/network/WebSocketServer.cpp + cocos/network/WebSocketServer.cpp ) endif() @@ -1971,13 +1971,13 @@ cocos_source_files(MODULE ccgeometry ##### script bindings ######## dop cocos_source_files( - NO_WERROR NO_UBUILD cocos/bindings/dop/BufferPool.cpp + NO_UBUILD cocos/bindings/dop/BufferPool.cpp cocos/bindings/dop/BufferPool.h - NO_WERROR NO_UBUILD cocos/bindings/dop/jsb_dop.cpp + NO_UBUILD cocos/bindings/dop/jsb_dop.cpp cocos/bindings/dop/jsb_dop.h cocos/bindings/dop/PoolType.h cocos/bindings/dop/BufferAllocator.h - NO_WERROR NO_UBUILD cocos/bindings/dop/BufferAllocator.cpp + NO_UBUILD cocos/bindings/dop/BufferAllocator.cpp ) ######## auto @@ -2320,48 +2320,46 @@ endif() ######## manual cocos_source_files( - NO_WERROR cocos/bindings/manual/jsb_classtype.cpp - cocos/bindings/manual/jsb_classtype.h - #NO_WERROR cocos/bindings/manual/jsb_extension_manual.cpp - #cocos/bindings/manual/jsb_extension_manual.h - NO_WERROR cocos/bindings/manual/jsb_cocos_manual.cpp - cocos/bindings/manual/jsb_cocos_manual.h - cocos/bindings/manual/jsb_conversions.h - NO_WERROR cocos/bindings/manual/jsb_conversions_spec.cpp - cocos/bindings/manual/jsb_conversions_spec.h - NO_WERROR cocos/bindings/manual/jsb_gfx_manual.cpp - cocos/bindings/manual/jsb_gfx_manual.h - NO_WERROR cocos/bindings/manual/jsb_global.cpp - cocos/bindings/manual/jsb_global.h - NO_WERROR cocos/bindings/manual/jsb_helper.cpp - cocos/bindings/manual/jsb_helper.h - cocos/bindings/manual/jsb_module_register.h - NO_WERROR cocos/bindings/manual/jsb_module_register.cpp - cocos/bindings/manual/jsb_platform.h - NO_WERROR cocos/bindings/manual/jsb_scene_manual.cpp - cocos/bindings/manual/jsb_scene_manual.h - NO_WERROR cocos/bindings/manual/jsb_assets_manual.cpp - cocos/bindings/manual/jsb_assets_manual.h - NO_WERROR cocos/bindings/manual/jsb_network_manual.cpp - cocos/bindings/manual/jsb_network_manual.h - NO_WERROR cocos/bindings/manual/jsb_xmlhttprequest.cpp - cocos/bindings/manual/jsb_xmlhttprequest.h - cocos/bindings/manual/jsb_pipeline_manual.h - NO_WERROR cocos/bindings/manual/jsb_pipeline_manual.cpp + cocos/bindings/manual/jsb_classtype.cpp + cocos/bindings/manual/jsb_classtype.h + cocos/bindings/manual/jsb_cocos_manual.cpp + cocos/bindings/manual/jsb_cocos_manual.h + cocos/bindings/manual/jsb_conversions.h + cocos/bindings/manual/jsb_conversions_spec.cpp + cocos/bindings/manual/jsb_conversions_spec.h + cocos/bindings/manual/jsb_gfx_manual.cpp + cocos/bindings/manual/jsb_gfx_manual.h + cocos/bindings/manual/jsb_global.cpp + cocos/bindings/manual/jsb_global.h + cocos/bindings/manual/jsb_helper.cpp + cocos/bindings/manual/jsb_helper.h + cocos/bindings/manual/jsb_module_register.h + cocos/bindings/manual/jsb_module_register.cpp + cocos/bindings/manual/jsb_platform.h + cocos/bindings/manual/jsb_scene_manual.cpp + cocos/bindings/manual/jsb_scene_manual.h + cocos/bindings/manual/jsb_assets_manual.cpp + cocos/bindings/manual/jsb_assets_manual.h + cocos/bindings/manual/jsb_network_manual.cpp + cocos/bindings/manual/jsb_network_manual.h + cocos/bindings/manual/jsb_xmlhttprequest.cpp + cocos/bindings/manual/jsb_xmlhttprequest.h + cocos/bindings/manual/jsb_pipeline_manual.h + cocos/bindings/manual/jsb_pipeline_manual.cpp ) if(USE_SOCKET) cocos_source_files( - NO_WERROR cocos/bindings/manual/jsb_socketio.cpp + cocos/bindings/manual/jsb_socketio.cpp cocos/bindings/manual/jsb_socketio.h - NO_WERROR cocos/bindings/manual/jsb_websocket.cpp + cocos/bindings/manual/jsb_websocket.cpp cocos/bindings/manual/jsb_websocket.h ) endif() if(NOT IOS AND USE_WEBSOCKET_SERVER) cocos_source_files( - NO_WERROR cocos/bindings/manual/jsb_websocket_server.cpp + cocos/bindings/manual/jsb_websocket_server.cpp cocos/bindings/manual/jsb_websocket_server.h ) endif() @@ -2414,10 +2412,10 @@ if(USE_SE_V8) cocos/bindings/jswrapper/v8/Object.h cocos/bindings/jswrapper/v8/ObjectWrap.cpp cocos/bindings/jswrapper/v8/ObjectWrap.h - NO_WERROR cocos/bindings/jswrapper/v8/ScriptEngine.cpp + cocos/bindings/jswrapper/v8/ScriptEngine.cpp cocos/bindings/jswrapper/v8/ScriptEngine.h cocos/bindings/jswrapper/v8/SeApi.h - NO_WERROR cocos/bindings/jswrapper/v8/Utils.cpp + cocos/bindings/jswrapper/v8/Utils.cpp cocos/bindings/jswrapper/v8/Utils.h cocos/bindings/jswrapper/v8/MissingSymbols.cpp cocos/bindings/jswrapper/v8/MissingSymbols.h @@ -2512,7 +2510,7 @@ cocos_source_files(MODULE ccbindings ) cocos_source_files( - NO_WERROR cocos/bindings/manual/jsb_global_init.cpp + cocos/bindings/manual/jsb_global_init.cpp cocos/bindings/manual/jsb_global_init.h ) @@ -2636,13 +2634,13 @@ endif() ##### extensions cocos_source_files( - NO_WERROR extensions/assets-manager/AssetsManagerEx.cpp + extensions/assets-manager/AssetsManagerEx.cpp extensions/assets-manager/AssetsManagerEx.h - NO_WERROR extensions/assets-manager/AsyncTaskPool.cpp + extensions/assets-manager/AsyncTaskPool.cpp extensions/assets-manager/AsyncTaskPool.h - NO_WERROR extensions/assets-manager/EventAssetsManagerEx.cpp + extensions/assets-manager/EventAssetsManagerEx.cpp extensions/assets-manager/EventAssetsManagerEx.h - NO_WERROR extensions/assets-manager/Manifest.cpp + extensions/assets-manager/Manifest.cpp extensions/assets-manager/Manifest.h extensions/cocos-ext.h extensions/ExtensionExport.h diff --git a/native/cocos/bindings/manual/jsb_conversions.h b/native/cocos/bindings/manual/jsb_conversions.h index eb7f8cc15e..bc16d9813d 100644 --- a/native/cocos/bindings/manual/jsb_conversions.h +++ b/native/cocos/bindings/manual/jsb_conversions.h @@ -1099,7 +1099,7 @@ bool sevalue_to_native(const se::Value &from, std::tuple *to, se::Objec bool result = true; se_for_each_tuple(*to, [&](auto i, auto ¶m) { se::Value tmp; - from.toObject()->getArrayElement(i, &tmp); + from.toObject()->getArrayElement(static_cast(i), &tmp); result &= sevalue_to_native(tmp, ¶m, ctx); }); return result; @@ -1508,7 +1508,7 @@ bool nativevalue_to_se(const std::tuple &from, se::Value &to, se::Objec se_for_each_tuple( from, [&](auto i, auto ¶m) { ok &= nativevalue_to_se(param, tmp, ctx); - array->setArrayElement(i, tmp); + array->setArrayElement(static_cast(i), tmp); }); to.setObject(array); return ok; diff --git a/native/cocos/bindings/manual/jsb_extension_manual.cpp b/native/cocos/bindings/manual/jsb_extension_manual.cpp deleted file mode 100644 index dff750a94d..0000000000 --- a/native/cocos/bindings/manual/jsb_extension_manual.cpp +++ /dev/null @@ -1,220 +0,0 @@ -/**************************************************************************** - Copyright (c) 2017-2022 Xiamen Yaji Software Co., Ltd. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated engine source code (the "Software"), a limited, - worldwide, royalty-free, non-assignable, revocable and non-exclusive license - to use Cocos Creator solely to develop games on your target platforms. You shall - not use Cocos Creator software for developing other software or tools that's - used for developing games. You are not granted to publish, distribute, - sublicense, and/or sell copies of Cocos Creator. - - The software or tools in this License Agreement are licensed, not sold. - Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -****************************************************************************/ - -#include "cocos/base/CCThreadPool.h" -#include "cocos/scripting/js-bindings/auto/jsb_cocos2dx_extension_auto.h" -#include "cocos/scripting/js-bindings/jswrapper/SeApi.h" -#include "cocos/scripting/js-bindings/manual/jsb_conversions.h" -#include "cocos/scripting/js-bindings/manual/jsb_global.h" -#include "jsb_cocos2dx_extension_manual.h" - -#include "cocos2d.h" -#include "extensions/cocos-ext.h" - -using namespace cc; -using namespace cc::extension; - -static bool js_cocos2dx_extension_loadRemoteImage(se::State &s) { - const auto &args = s.args(); - int argc = (int)args.size(); - - if (argc == 2) { - bool ok = false; - ccstd::string url; - ok = seval_to_std_string(args[0], &url); - SE_PRECONDITION2(ok, false, "Converting 'url' failed!"); - - se::Value func = args[1]; - assert(func.isObject() && func.toObject()->isFunction()); - - func.toObject()->root(); - - auto onSuccess = [func](Texture2D *tex) -> bool { - se::ScriptEngine::getInstance()->clearException(); - se::AutoHandleScope hs; - - se::ValueArray args; - args.resize(2); - - if (tex != nullptr) { - args[0].setBoolean(true); - bool ok = native_ptr_to_seval(tex, &args[1]); - SE_PRECONDITION2(ok, false, "Converting 'tex' argument failed!"); - } else { - args[0].setBoolean(false); - args[1].setNull(); - } - - return func.toObject()->call(args, nullptr); - }; - - auto onError = [func]() { - se::ScriptEngine::getInstance()->clearException(); - se::AutoHandleScope hs; - - se::ValueArray args; - args.resize(1); - args[0].setBoolean(false); - func.toObject()->call(args, nullptr); - }; - - Texture2D *texture = Director::getInstance()->getTextureCache()->getTextureForKey(url); - if (texture != nullptr) { - onSuccess(texture); - } else { - auto downloader = new (std::nothrow) cc::network::Downloader(); - downloader->onDataTaskSuccess = [downloader, url, onSuccess, onError](const cc::network::DownloadTask &task, ccstd::vector &data) { - Image * img = new (std::nothrow) Image(); - Texture2D *tex = nullptr; - do { - if (!img->initWithImageData(data.data(), data.size())) - break; - tex = Director::getInstance()->getTextureCache()->addImage(img, url); - } while (0); - - CC_SAFE_RELEASE(img); - - if (tex) { - onSuccess(tex); - } else { - onError(); - } - - // Downloader may use its member variables after this callback, - // therefore, we need to execute `delete` operation asynchronously, otherwise crash will be triggered. - Director::getInstance()->getScheduler()->performFunctionInCocosThread([downloader]() { - delete downloader; - }); - }; - - downloader->onTaskError = [downloader, onError](const cc::network::DownloadTask &task, int errorCode, int errorCodeInternal, const ccstd::string &errorStr) { - onError(); - - // Downloader may use its member variables after this callback, - // therefore, we need to execute `delete` operation asynchronously, otherwise crash will be triggered. - Director::getInstance()->getScheduler()->performFunctionInCocosThread([downloader]() { - delete downloader; - }); - }; - - downloader->createDownloadDataTask(url); - } - return true; - } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", argc, 2); - return false; -} -SE_BIND_FUNC(js_cocos2dx_extension_loadRemoteImage) - -static bool js_cocos2dx_extension_initRemoteImage(se::State &s) { - const auto &args = s.args(); - int argc = (int)args.size(); - if (argc != 3) { - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", argc, 3); - return false; - } - - bool ok = false; - - // get texture - cc::Texture2D *texture = nullptr; - ok = seval_to_native_ptr(args[0], &texture); - SE_PRECONDITION2(ok, false, "Converting 'texture' failed!"); - - // get url - ccstd::string url; - ok = seval_to_std_string(args[1], &url); - SE_PRECONDITION2(ok, false, "Converting 'url' failed!"); - - // get callback - se::Value func = args[2]; - assert(func.isObject() && func.toObject()->isFunction()); - func.toObject()->root(); - - auto onCallback = [=](bool success) { - se::ScriptEngine::getInstance()->clearException(); - se::AutoHandleScope hs; - - se::ValueArray args; - args.resize(1); - - args[0].setBoolean(success); - func.toObject()->call(args, nullptr); - }; - - auto downloader = new (std::nothrow) cc::network::Downloader(); - downloader->onDataTaskSuccess = [=](const cc::network::DownloadTask &task, ccstd::vector &data) { - bool success = false; - - Image *image = new (std::nothrow) Image(); - if (image->initWithImageData(data.data(), data.size())) { - if (texture->initWithImage(image)) { - success = true; - } else { - CC_LOG_ERROR("js_extension_loadRemoteImageOn: Failed to initWithImage."); - } - } - CC_SAFE_RELEASE_NULL(image); - - onCallback(success); - Director::getInstance()->getScheduler()->performFunctionInCocosThread([downloader]() { - delete downloader; - }); - }; - - downloader->onTaskError = [=](const cc::network::DownloadTask &task, int errorCode, int errorCodeInternal, const ccstd::string &errorStr) { - onCallback(false); - Director::getInstance()->getScheduler()->performFunctionInCocosThread([downloader]() { - delete downloader; - }); - }; - - downloader->createDownloadDataTask(url); - return true; -} -SE_BIND_FUNC(js_cocos2dx_extension_initRemoteImage) - -static ThreadPool * _threadPool = nullptr; -static EventListenerCustom *_resetThreadPoolListener = nullptr; -static ThreadPool * getThreadPool() { - if (_threadPool == nullptr) { - _threadPool = ThreadPool::newSingleThreadPool(); - _resetThreadPoolListener = Director::getInstance()->getEventDispatcher()->addCustomEventListener(Director::EVENT_RESET, [](cc::EventCustom *) { - CC_SAFE_DELETE(_threadPool); - cc::Director::getInstance()->getEventDispatcher()->removeEventListener(_resetThreadPoolListener); - _resetThreadPoolListener = nullptr; - }); - } - return _threadPool; -} - -bool register_all_cocos2dx_extension_manual(se::Object *obj) { - __jsbObj->defineFunction("loadRemoteImg", _SE(js_cocos2dx_extension_loadRemoteImage)); - __jsbObj->defineFunction("initRemoteImg", _SE(js_cocos2dx_extension_initRemoteImage)); - - se::ScriptEngine::getInstance()->clearException(); - - return true; -} diff --git a/native/cocos/bindings/manual/jsb_extension_manual.h b/native/cocos/bindings/manual/jsb_extension_manual.h deleted file mode 100644 index 3182338209..0000000000 --- a/native/cocos/bindings/manual/jsb_extension_manual.h +++ /dev/null @@ -1,32 +0,0 @@ -/**************************************************************************** - Copyright (c) 2017-2022 Xiamen Yaji Software Co., Ltd. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated engine source code (the "Software"), a limited, - worldwide, royalty-free, non-assignable, revocable and non-exclusive license - to use Cocos Creator solely to develop games on your target platforms. You shall - not use Cocos Creator software for developing other software or tools that's - used for developing games. You are not granted to publish, distribute, - sublicense, and/or sell copies of Cocos Creator. - - The software or tools in this License Agreement are licensed, not sold. - Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -****************************************************************************/ - -#pragma once - -namespace se { -class Object; -} - -bool register_all_cocos2dx_extension_manual(se::Object *obj); diff --git a/native/cocos/bindings/manual/jsb_global.cpp b/native/cocos/bindings/manual/jsb_global.cpp index ceba8f310c..d1b99faad1 100644 --- a/native/cocos/bindings/manual/jsb_global.cpp +++ b/native/cocos/bindings/manual/jsb_global.cpp @@ -210,7 +210,7 @@ static bool doModuleRequire(const ccstd::string &path, se::Value *ret, const ccs #endif auto se = se::ScriptEngine::getInstance(); - bool succeed = se->evalString(scriptBuffer.c_str(), scriptBuffer.length(), nullptr, reletivePath.c_str()); + bool succeed = se->evalString(scriptBuffer.c_str(), static_cast(scriptBuffer.length()), nullptr, reletivePath.c_str()); se::Value moduleVal; if (succeed && se->getGlobalObject()->getProperty("module", &moduleVal) && moduleVal.isObject()) { se::Value exportsVal;