bellard / quickjs

Public repository of the QuickJS Javascript Engine.
https://bellard.org/quickjs
Other
8.51k stars 892 forks source link

Fix JSValue casting #307

Open metarutaiga opened 6 months ago

metarutaiga commented 6 months ago

I found MSVC Compatibility https://github.com/bellard/quickjs/pull/16 But it modified too many codes

And I tried MSVC 2022 to compile it today. It just needs to be modified the JSValue casting because it's not standard C code.

If I want to build it with MSVC 2022, I need to add -std:c11 -experimental:c11atomics option and https://github.com/metarutaiga/quickjs/commit/10f9f7c31c1bb10d9b673d4d4f46e921a56e5853 only.

Yeah, I dont like MSVC too.

saghul commented 6 months ago

It just needs to be modified the JSValue casting because it's not standard C code.

Can you clarify that is non-standard about it?

metarutaiga commented 6 months ago

It just needs to be modified the JSValue casting because it's not standard C code.

Can you clarify that is non-standard about it?

You can add -Wpedantic into Makefile.

 ifdef CONFIG_CLANG
   HOST_CC=clang
   CC=$(CROSS_PREFIX)clang
   CFLAGS+=-g -Wall -MMD -MF $(OBJDIR)/$(@F).d
+  CFLAGS += -Wpedantic
   CFLAGS += -Wextra
   CFLAGS += -Wno-sign-compare
   CFLAGS += -Wno-missing-field-initializers

Result:

./quickjs.h:675:12: warning: C99 forbids casting nonscalar type 'JSValue' (aka 'struct JSValue') to the same type [-Wpedantic]
    return (JSValue)v;
           ^        ~
./quickjs.h:684:12: warning: C99 forbids casting nonscalar type 'JSValue' (aka 'struct JSValue') to the same type [-Wpedantic]
    return (JSValue)v;
           ^        ~
saghul commented 6 months ago

Ah, right. Does MSVC choke on it? On QuickJS-ng we somehow didn't run into this...

metarutaiga commented 6 months ago

Ah, right. Does MSVC choke on it? On QuickJS-ng we somehow didn't run into this...

Maybe MSVC is use C89 default.