Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Squelch a -Wcast-function-type warnings #137

Merged
merged 2 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ 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-implicit-fallthrough)
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)
Expand Down
27 changes: 20 additions & 7 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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];
Expand All @@ -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]);
Expand Down
4 changes: 3 additions & 1 deletion quickjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down