Squelch a -Wcast-function-type warnings

Ref: https://github.com/quickjs-ng/quickjs/issues/131
This commit is contained in:
Saúl Ibarra Corretgé 2023-11-25 23:09:47 +01:00
parent 7776cc3b75
commit d74b2e7ec1
3 changed files with 24 additions and 12 deletions

View file

@ -30,10 +30,7 @@ endmacro()
xcheck_add_c_compiler_flag(-Wall)
xcheck_add_c_compiler_flag(-Werror)
# -Wextra is too spartan on GCC
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang")
add_compile_options(-Wextra)
endif()
xcheck_add_c_compiler_flag(-Wextra)
xcheck_add_c_compiler_flag(-Wno-sign-compare)
xcheck_add_c_compiler_flag(-Wno-missing-field-initializers)
xcheck_add_c_compiler_flag(-Wno-unused-parameter)

View file

@ -13530,8 +13530,10 @@ static __exception int js_append_enumerate(JSContext *ctx, JSValue *sp)
iterator = JS_GetProperty(ctx, sp[-1], JS_ATOM_Symbol_iterator);
if (JS_IsException(iterator))
return -1;
/* Used to squelch a -Wcast-function-type warning. */
JSCFunctionType ft = { .generic_magic = js_create_array_iterator };
is_array_iterator = JS_IsCFunction(ctx, iterator,
(JSCFunction *)js_create_array_iterator,
ft.generic,
JS_ITERATOR_KIND_VALUE);
JS_FreeValue(ctx, iterator);
@ -13543,9 +13545,11 @@ static __exception int js_append_enumerate(JSContext *ctx, JSValue *sp)
JS_FreeValue(ctx, enumobj);
return -1;
}
/* Used to squelch a -Wcast-function-type warning. */
JSCFunctionType ft2 = { .iterator_next = js_array_iterator_next };
if (is_array_iterator
&& JS_IsCFunction(ctx, method, (JSCFunction *)js_array_iterator_next, 0)
&& js_get_fast_array(ctx, sp[-1], &arrp, &count32)) {
&& JS_IsCFunction(ctx, method, ft2.generic, 0)
&& js_get_fast_array(ctx, sp[-1], &arrp, &count32)) {
uint32_t len;
if (js_get_length32(ctx, &len, sp[-1]))
goto exception;
@ -45605,9 +45609,13 @@ void JS_AddIntrinsicPromise(JSContext *ctx)
JS_NewGlobalCConstructor2(ctx, obj1, "Promise",
ctx->class_proto[JS_CLASS_PROMISE]);
/* Used to squelch a -Wcast-function-type warning. */
JSCFunctionType ft;
/* AsyncFunction */
ctx->class_proto[JS_CLASS_ASYNC_FUNCTION] = JS_NewObjectProto(ctx, ctx->function_proto);
obj1 = JS_NewCFunction3(ctx, (JSCFunction *)js_function_constructor,
ft.generic_magic = js_function_constructor;
obj1 = JS_NewCFunction3(ctx, ft.generic,
"AsyncFunction", 1,
JS_CFUNC_constructor_or_func_magic, JS_FUNC_ASYNC,
ctx->function_ctor);
@ -45643,7 +45651,8 @@ void JS_AddIntrinsicPromise(JSContext *ctx)
/* AsyncGeneratorFunction */
ctx->class_proto[JS_CLASS_ASYNC_GENERATOR_FUNCTION] =
JS_NewObjectProto(ctx, ctx->function_proto);
obj1 = JS_NewCFunction3(ctx, (JSCFunction *)js_function_constructor,
ft.generic_magic = js_function_constructor;
obj1 = JS_NewCFunction3(ctx, ft.generic,
"AsyncGeneratorFunction", 1,
JS_CFUNC_constructor_or_func_magic,
JS_FUNC_ASYNC_GENERATOR,
@ -47180,11 +47189,13 @@ void JS_AddIntrinsicBaseObjects(JSContext *ctx)
JS_NewGlobalCConstructor2(ctx, obj1,
"Error", ctx->class_proto[JS_CLASS_ERROR]);
/* Used to squelch a -Wcast-function-type warning. */
JSCFunctionType ft = { .generic_magic = js_error_constructor };
for(i = 0; i < JS_NATIVE_ERROR_COUNT; i++) {
JSValue func_obj;
int n_args;
n_args = 1 + (i == JS_AGGREGATE_ERROR);
func_obj = JS_NewCFunction3(ctx, (JSCFunction *)js_error_constructor,
func_obj = JS_NewCFunction3(ctx, ft.generic,
native_error_name[i], n_args,
JS_CFUNC_constructor_or_func_magic, i, obj1);
JS_NewGlobalCConstructor2(ctx, func_obj, native_error_name[i],
@ -50344,6 +50355,8 @@ void JS_AddIntrinsicTypedArrays(JSContext *ctx)
countof(js_typed_array_base_funcs));
JS_SetConstructor(ctx, typed_array_base_func, typed_array_base_proto);
/* Used to squelch a -Wcast-function-type warning. */
JSCFunctionType ft = { .generic_magic = js_typed_array_constructor };
for(i = JS_CLASS_UINT8C_ARRAY; i < JS_CLASS_UINT8C_ARRAY + JS_TYPED_ARRAY_COUNT; i++) {
JSValue func_obj;
char buf[ATOM_GET_STR_BUF_SIZE];
@ -50356,7 +50369,7 @@ void JS_AddIntrinsicTypedArrays(JSContext *ctx)
0);
name = JS_AtomGetStr(ctx, buf, sizeof(buf),
JS_ATOM_Uint8ClampedArray + i - JS_CLASS_UINT8C_ARRAY);
func_obj = JS_NewCFunction3(ctx, (JSCFunction *)js_typed_array_constructor,
func_obj = JS_NewCFunction3(ctx, ft.generic,
name, 3, JS_CFUNC_constructor_magic, i,
typed_array_base_func);
JS_NewGlobalCConstructor2(ctx, func_obj, name, ctx->class_proto[i]);

View file

@ -916,7 +916,9 @@ static inline JSValue JS_NewCFunctionMagic(JSContext *ctx, JSCFunctionMagic *fun
const char *name,
int length, JSCFunctionEnum cproto, int magic)
{
return JS_NewCFunction2(ctx, (JSCFunction *)func, name, length, cproto, magic);
/* Used to squelch a -Wcast-function-type warning. */
JSCFunctionType ft = { .generic_magic = func };
return JS_NewCFunction2(ctx, ft.generic, name, length, cproto, magic);
}
void JS_SetConstructor(JSContext *ctx, JSValueConst func_obj,
JSValueConst proto);