mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-19 14:52:40 +08:00
Fixes for GCC compatibility and Linux platform warnings (#14511)
* fix compile error on linux * ignore more warnning * move StringPool & StringEqual into StringPool
This commit is contained in:
@@ -37,7 +37,7 @@ jobs:
|
||||
sudo apt install ninja-build -y
|
||||
- name: Compile
|
||||
env:
|
||||
COCOS_ENGINE_DEV: 0
|
||||
COCOS_ENGINE_DEV: 1
|
||||
run: |
|
||||
NATIVE_ROOT=$GITHUB_WORKSPACE/native
|
||||
echo "Compiling Linux ... "
|
||||
|
||||
@@ -116,7 +116,13 @@ if("$ENV{COCOS_ENGINE_DEV}" EQUAL "1")
|
||||
set(WERROR_FLAGS "-Werror -Werror=return-type") # -Wshorten-64-to-32 -Werror=return-type
|
||||
|
||||
if(APPLE)
|
||||
set(WERROR_FLAGS "${WERROR_FLAGS} -Wno-deprecated-declarations")
|
||||
set(WERROR_FLAGS " ${WERROR_FLAGS} -Wno-deprecated-declarations")
|
||||
elseif(LINUX)
|
||||
set(WERROR_FLAGS " ${WERROR_FLAGS} -Wno-nullability-completeness -Wno-deprecated-declarations")
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
set(WERROR_FLAGS " ${WERROR_FLAGS} -Wno-invalid-offsetof")
|
||||
endif()
|
||||
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace sf {
|
||||
// visible to clients
|
||||
using sf_count_t = int;
|
||||
|
||||
using SF_INFO = struct {
|
||||
struct SF_INFO {
|
||||
sf_count_t frames;
|
||||
int samplerate;
|
||||
int channels;
|
||||
@@ -55,7 +55,7 @@ using SNDFILE = struct SNDFILE_;
|
||||
#define SF_FORMAT_PCM_32 8
|
||||
#define SF_FORMAT_PCM_24 10
|
||||
|
||||
using snd_callbacks = struct {
|
||||
struct snd_callbacks {
|
||||
void *(*open)(const char *path, void *user);
|
||||
size_t (*read)(void *ptr, size_t size, size_t nmemb, void *datasource);
|
||||
int (*seek)(void *datasource, long offset, int whence); //NOLINT(google-runtime-int)
|
||||
|
||||
@@ -73,4 +73,4 @@
|
||||
if (!!(condition)) { \
|
||||
CC_LOG_DEBUG("(" QUOTEME(condition) ") failed, message: " fmt, ##__VA_ARGS__); \
|
||||
break; \
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,24 +35,23 @@
|
||||
|
||||
namespace cc {
|
||||
|
||||
namespace {
|
||||
class StringHasher final {
|
||||
public:
|
||||
ccstd::hash_t operator()(const char *str) const noexcept {
|
||||
return ccstd::hash_range(str, str + strlen(str));
|
||||
}
|
||||
};
|
||||
|
||||
class StringEqual final {
|
||||
public:
|
||||
bool operator()(const char *c1, const char *c2) const noexcept {
|
||||
return strcmp(c1, c2) == 0;
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
template <bool ThreadSafe>
|
||||
class StringPool final {
|
||||
private:
|
||||
class StringHasher final {
|
||||
public:
|
||||
ccstd::hash_t operator()(const char *str) const noexcept {
|
||||
return ccstd::hash_range(str, str + strlen(str));
|
||||
}
|
||||
};
|
||||
|
||||
class StringEqual final {
|
||||
public:
|
||||
bool operator()(const char *c1, const char *c2) const noexcept {
|
||||
return strcmp(c1, c2) == 0;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
StringPool() = default;
|
||||
~StringPool();
|
||||
|
||||
@@ -330,7 +330,7 @@ ResultType mapTupleArguments(se::Object *self, TupleIn &input, std::index_sequen
|
||||
using map_tuple = typename Mapping::mapping_list::tuple_type;
|
||||
using result_type = typename Mapping::result_types_tuple_mutable;
|
||||
static_assert(std::is_same<ResultType, result_type>::value, "result_type mismatch");
|
||||
//if constexpr (std::tuple_size<result_type>::value > 0) {
|
||||
// if constexpr (std::tuple_size<result_type>::value > 0) {
|
||||
return result_type(ArgumentFilter::forward<map_tuple, TupleIn, indexes>(self, input)...);
|
||||
//}
|
||||
// return result_type();
|
||||
@@ -465,40 +465,26 @@ struct StaticAttribute;
|
||||
template <typename T, typename... ARGS>
|
||||
struct Constructor<TypeList<T, ARGS...>> : ConstructorBase {
|
||||
// no `if constexpr`, more code is needed...
|
||||
template <bool MapArgs>
|
||||
struct ConstructFn;
|
||||
template <>
|
||||
struct ConstructFn<true> {
|
||||
template <typename Self, typename... ARGS2, size_t... indexes>
|
||||
static auto invoke(Self *self, se::Object *thisObj, std::tuple<ARGS2...> &args, std::index_sequence<indexes...> n) {
|
||||
using type_mapping = TypeMapping<TypeList<ARGS...>>;
|
||||
using map_list_type = typename type_mapping::mapping_list;
|
||||
using map_tuple_type = typename type_mapping::result_types_tuple_mutable;
|
||||
|
||||
static_assert(map_list_type::COUNT == sizeof...(ARGS), "type mapping incorrect");
|
||||
|
||||
map_tuple_type remapArgs = mapTupleArguments<map_tuple_type, type_mapping>(thisObj, args, std::make_index_sequence<type_mapping::FULL_ARGN>{});
|
||||
|
||||
return self->constructWithTuple(remapArgs, n);
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct ConstructFn<false> {
|
||||
template <typename Self, typename... ARGS2, size_t... indexes>
|
||||
static auto invoke(Self *self, se::Object * /*thisObj*/, std::tuple<ARGS2...> &args, std::index_sequence<indexes...> n) {
|
||||
return self->constructWithTupleValue(args, n);
|
||||
}
|
||||
};
|
||||
|
||||
bool construct(se::State &state) override {
|
||||
using type_mapping = TypeMapping<TypeList<ARGS...>>;
|
||||
using args_holder_type = typename MapTypeListToTuple<typename type_mapping::input_types>::tuple;
|
||||
constexpr auto indexes = std::make_index_sequence<type_mapping::FULL_ARGN>{};
|
||||
se::PrivateObjectBase *self{nullptr};
|
||||
se::Object *thisObj = state.thisObject();
|
||||
args_holder_type args{};
|
||||
const auto &jsArgs = state.args();
|
||||
convert_js_args_to_tuple(jsArgs, args, thisObj, std::make_index_sequence<type_mapping::NEW_ARGN>());
|
||||
self = ConstructFn<type_mapping::NEED_REMAP>::invoke(this, thisObj, args, std::make_index_sequence<type_mapping::FULL_ARGN>{});
|
||||
if constexpr (type_mapping::NEED_REMAP) {
|
||||
using type_mapping = TypeMapping<TypeList<ARGS...>>;
|
||||
using map_list_type = typename type_mapping::mapping_list;
|
||||
using map_tuple_type = typename type_mapping::result_types_tuple_mutable;
|
||||
static_assert(map_list_type::COUNT == sizeof...(ARGS), "type mapping incorrect");
|
||||
|
||||
map_tuple_type remapArgs = mapTupleArguments<map_tuple_type, type_mapping>(thisObj, args, std::make_index_sequence<type_mapping::FULL_ARGN>{});
|
||||
self = constructWithTuple(remapArgs, indexes);
|
||||
} else {
|
||||
self = constructWithTupleValue(args, indexes);
|
||||
}
|
||||
state.thisObject()->setPrivateObject(self);
|
||||
return true;
|
||||
}
|
||||
@@ -557,23 +543,6 @@ struct InstanceMethod<R (T::*)(ARGS...)> : InstanceMethodBase {
|
||||
|
||||
type func{nullptr};
|
||||
|
||||
template <bool>
|
||||
struct Invoker;
|
||||
template <>
|
||||
struct Invoker<true> {
|
||||
template <typename S, typename... ARGS2, size_t... indexes>
|
||||
static void invoke(S *method, T *self, se::State & /*state*/, std::tuple<ARGS2...> &args, std::index_sequence<indexes...> idx) {
|
||||
method->callWithTuple(self, args, idx);
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct Invoker<false> {
|
||||
template <typename S, typename... ARGS2, size_t... indexes>
|
||||
static void invoke(S *method, T *self, se::State &state, std::tuple<ARGS2...> &args, std::index_sequence<indexes...> idx) {
|
||||
nativevalue_to_se(method->callWithTuple(self, args, idx), state.rval(), state.thisObject());
|
||||
}
|
||||
};
|
||||
|
||||
template <typename... ARGS_HT, size_t... indexes>
|
||||
R callWithTuple(T *self, std::tuple<ARGS_HT...> &args, std::index_sequence<indexes...> /*unused*/) const {
|
||||
return ((reinterpret_cast<T *>(self))->*func)(std::get<indexes>(args).value()...);
|
||||
@@ -590,7 +559,11 @@ struct InstanceMethod<R (T::*)(ARGS...)> : InstanceMethodBase {
|
||||
}
|
||||
std::tuple<HolderType<ARGS, std::is_reference<ARGS>::value>...> args{};
|
||||
convert_js_args_to_tuple(jsArgs, args, thisObject, indexes);
|
||||
Invoker<RETURN_VOID>::invoke(this, self, state, args, indexes);
|
||||
if constexpr (RETURN_VOID) {
|
||||
callWithTuple(self, args, indexes);
|
||||
} else {
|
||||
nativevalue_to_se(callWithTuple(self, args, indexes), state.rval(), state.thisObject());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@@ -605,23 +578,6 @@ struct InstanceMethod<R (T::*)(ARGS...) const> : InstanceMethodBase {
|
||||
|
||||
type func{nullptr};
|
||||
|
||||
template <bool>
|
||||
struct Invoker;
|
||||
template <>
|
||||
struct Invoker<true> {
|
||||
template <typename S, typename... ARGS2, size_t... indexes>
|
||||
static void invoke(S *method, T *self, se::State & /*state*/, std::tuple<ARGS2...> &args, std::index_sequence<indexes...> idx) {
|
||||
method->callWithTuple(self, args, idx);
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct Invoker<false> {
|
||||
template <typename S, typename... ARGS2, size_t... indexes>
|
||||
static void invoke(S *method, T *self, se::State &state, std::tuple<ARGS2...> &args, std::index_sequence<indexes...> idx) {
|
||||
nativevalue_to_se(method->callWithTuple(self, args, idx), state.rval(), state.thisObject());
|
||||
}
|
||||
};
|
||||
|
||||
template <typename... ARGS_HT, size_t... indexes>
|
||||
R callWithTuple(T *self, std::tuple<ARGS_HT...> &args, std::index_sequence<indexes...> /*unused*/) const {
|
||||
return ((reinterpret_cast<T *>(self))->*func)(std::get<indexes>(args).value()...);
|
||||
@@ -638,7 +594,11 @@ struct InstanceMethod<R (T::*)(ARGS...) const> : InstanceMethodBase {
|
||||
}
|
||||
std::tuple<HolderType<ARGS, std::is_reference<ARGS>::value>...> args{};
|
||||
convert_js_args_to_tuple(jsArgs, args, thisObject, indexes);
|
||||
Invoker<RETURN_VOID>::invoke(this, self, state, args, indexes);
|
||||
if constexpr (RETURN_VOID) {
|
||||
callWithTuple(self, args, indexes);
|
||||
} else {
|
||||
nativevalue_to_se(callWithTuple(self, args, indexes), state.rval(), state.thisObject());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@@ -653,23 +613,6 @@ struct InstanceMethod<R (*)(T *, ARGS...)> : InstanceMethodBase {
|
||||
|
||||
type func{nullptr};
|
||||
|
||||
template <bool>
|
||||
struct Invoker;
|
||||
template <>
|
||||
struct Invoker<true> {
|
||||
template <typename S, typename... ARGS2, size_t... indexes>
|
||||
static void invoke(S *method, T *self, se::State & /*state*/, std::tuple<ARGS2...> &args, std::index_sequence<indexes...> idx) {
|
||||
method->callWithTuple(self, args, idx);
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct Invoker<false> {
|
||||
template <typename S, typename... ARGS2, size_t... indexes>
|
||||
static void invoke(S *method, T *self, se::State &state, std::tuple<ARGS2...> &args, std::index_sequence<indexes...> idx) {
|
||||
nativevalue_to_se(method->callWithTuple(self, args, idx), state.rval(), state.thisObject());
|
||||
}
|
||||
};
|
||||
|
||||
template <typename... ARGS_HT, size_t... indexes>
|
||||
R callWithTuple(T *self, std::tuple<ARGS_HT...> &args, std::index_sequence<indexes...> /*unused*/) const {
|
||||
return (*func)(reinterpret_cast<T *>(self), std::get<indexes>(args).value()...);
|
||||
@@ -686,7 +629,11 @@ struct InstanceMethod<R (*)(T *, ARGS...)> : InstanceMethodBase {
|
||||
}
|
||||
std::tuple<HolderType<ARGS, std::is_reference<ARGS>::value>...> args{};
|
||||
convert_js_args_to_tuple(jsArgs, args, thisObject, indexes);
|
||||
Invoker<RETURN_VOID>::invoke(this, self, state, args, indexes);
|
||||
if constexpr (RETURN_VOID) {
|
||||
callWithTuple(self, args, indexes);
|
||||
} else {
|
||||
nativevalue_to_se(callWithTuple(self, args, indexes), state.rval(), state.thisObject());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@@ -815,29 +762,15 @@ struct InstanceAttribute<AttributeAccessor<T, Getter, Setter>> : InstanceAttribu
|
||||
setter_type setterPtr;
|
||||
getter_type getterPtr;
|
||||
|
||||
template <bool>
|
||||
struct Invoker;
|
||||
|
||||
template <>
|
||||
struct Invoker<true> {
|
||||
static bool invoke(getter_type getterPtr, se::State &state) {
|
||||
bool get(se::State &state) const override {
|
||||
if constexpr (HAS_GETTER) {
|
||||
T *self = reinterpret_cast<T *>(state.nativeThisObject());
|
||||
se::Object *thisObject = state.thisObject();
|
||||
using func_type = FunctionWrapper<getter_type>;
|
||||
static_assert(!std::is_void<typename func_type::return_type>::value, "should return a value");
|
||||
return nativevalue_to_se(func_type::invoke(getterPtr, self), state.rval(), thisObject);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Invoker<false> {
|
||||
static bool invoke(getter_type /*getterPtr*/, se::State & /*state*/) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
bool get(se::State &state) const override {
|
||||
return Invoker<HAS_GETTER>::invoke(getterPtr, state);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool set(se::State &state) const override {
|
||||
@@ -865,23 +798,6 @@ struct StaticMethod<R (*)(ARGS...)> : StaticMethodBase {
|
||||
|
||||
type func{nullptr};
|
||||
|
||||
template <bool>
|
||||
struct Invoker;
|
||||
template <>
|
||||
struct Invoker<true> {
|
||||
template <typename T, typename... ARGS2, size_t... indexes>
|
||||
static void invoke(T *self, se::State & /*state*/, std::tuple<ARGS2...> &args, std::index_sequence<indexes...> idxs) {
|
||||
self->callWithTuple(args, idxs);
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct Invoker<false> {
|
||||
template <typename T, typename... ARGS2, size_t... indexes>
|
||||
static void invoke(T *self, se::State &state, std::tuple<ARGS2...> &args, std::index_sequence<indexes...> idxs) {
|
||||
nativevalue_to_se(self->callWithTuple(args, idxs), state.rval(), nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename... ARGS_HT, size_t... indexes>
|
||||
R callWithTuple(std::tuple<ARGS_HT...> &args, std::index_sequence<indexes...> /*unused*/) const {
|
||||
return (*func)(std::get<indexes>(args).value()...);
|
||||
@@ -896,7 +812,11 @@ struct StaticMethod<R (*)(ARGS...)> : StaticMethodBase {
|
||||
}
|
||||
std::tuple<HolderType<ARGS, std::is_reference<ARGS>::value>...> args{};
|
||||
convert_js_args_to_tuple(jsArgs, args, nullptr, indexes);
|
||||
Invoker<RETURN_VOID>::invoke(this, state, args, indexes);
|
||||
if constexpr (RETURN_VOID) {
|
||||
callWithTuple(args, indexes);
|
||||
} else {
|
||||
nativevalue_to_se(callWithTuple(args, indexes), state.rval(), nullptr);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@@ -975,27 +895,13 @@ struct StaticAttribute<SAttributeAccessor<T, Getter, Setter>> : StaticAttributeB
|
||||
setter_type setterPtr;
|
||||
getter_type getterPtr;
|
||||
|
||||
template <bool>
|
||||
struct Invoker;
|
||||
|
||||
template <>
|
||||
struct Invoker<true> {
|
||||
static bool invoke(getter_type getterPtr, se::State &state) {
|
||||
bool get(se::State &state) const override {
|
||||
if constexpr (HAS_GETTER) {
|
||||
using func_type = StaticFunctionWrapper<getter_type>;
|
||||
static_assert(!std::is_void<typename func_type::return_type>::value, "should return a value");
|
||||
return nativevalue_to_se(func_type::invoke(getterPtr), state.rval(), nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Invoker<false> {
|
||||
static bool invoke(getter_type /*getterPtr*/, se::State & /*state*/) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
bool get(se::State &state) const override {
|
||||
return Invoker<HAS_GETTER>::invoke(getterPtr, state);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool set(se::State &state) const override {
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "core/assets/Asset.h"
|
||||
#include "core/assets/AssetEnum.h"
|
||||
#include "renderer/gfx-base/GFXDef.h"
|
||||
#include "base/std/container/unordered_map.h"
|
||||
|
||||
#include "base/std/any.h"
|
||||
|
||||
@@ -55,19 +56,19 @@ public:
|
||||
* @en The pixel format enum.
|
||||
* @zh 像素格式枚举类型
|
||||
*/
|
||||
using PixelFormat = PixelFormat;
|
||||
using PixelFormat = cc::PixelFormat;
|
||||
|
||||
/**
|
||||
* @en The wrap mode enum.
|
||||
* @zh 环绕模式枚举类型
|
||||
*/
|
||||
using WrapMode = WrapMode;
|
||||
using WrapMode = cc::WrapMode;
|
||||
|
||||
/**
|
||||
* @en The texture filter mode enum
|
||||
* @zh 纹理过滤模式枚举类型
|
||||
*/
|
||||
using Filter = Filter;
|
||||
using Filter = cc::Filter;
|
||||
|
||||
TextureBase(); // NOTE: Editor needs to invoke 'new TextureBase' in JS, so we need to make the constructor public.
|
||||
~TextureBase() override;
|
||||
|
||||
@@ -51,18 +51,19 @@ struct EventParam : std::conditional<std::is_enum<T>::value, std::true_type, std
|
||||
using type = typename std::conditional<IS_ENUM, T, void>::type;
|
||||
};
|
||||
|
||||
template <bool>
|
||||
struct Char;
|
||||
template <>
|
||||
struct Char<true> {
|
||||
static constexpr char VALUE{'E'};
|
||||
};
|
||||
template <>
|
||||
struct Char<false> {
|
||||
static constexpr char VALUE{'?'};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct Signature {
|
||||
template <bool>
|
||||
struct Char;
|
||||
template <>
|
||||
struct Char<true> {
|
||||
static constexpr char VALUE{'E'};
|
||||
};
|
||||
template <>
|
||||
struct Char<false> {
|
||||
static constexpr char VALUE{'?'};
|
||||
};
|
||||
constexpr static char name() { return Char<std::is_enum<T>::value>::VALUE; }
|
||||
};
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
|
||||
set(APP_NAME "game" CACHE STRING "Project Name")
|
||||
set(CMAKE_C_COMPILER "/usr/bin/clang")
|
||||
set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
|
||||
#set(CMAKE_C_COMPILER "/usr/bin/clang")
|
||||
#set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
|
||||
|
||||
project(${APP_NAME} CXX)
|
||||
|
||||
@@ -16,4 +16,4 @@ set(EXECUTABLE_NAME ${APP_NAME})
|
||||
|
||||
cc_linux_before_target(${EXECUTABLE_NAME})
|
||||
add_executable(${EXECUTABLE_NAME} ${CC_ALL_SOURCES})
|
||||
cc_linux_after_target(${EXECUTABLE_NAME})
|
||||
cc_linux_after_target(${EXECUTABLE_NAME})
|
||||
|
||||
Reference in New Issue
Block a user