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

Make quickjs.h -Wall -Wextra -pedantic clean #628

Merged
merged 1 commit into from
Oct 26, 2024
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
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,14 @@ distclean:
stats: $(QJS)
$(QJS) -qd

# implicitly .PHONY because it doesn't generate output
cxxtest: CXXFLAGS+=-std=c++11 -fsyntax-only -Wall -Wextra -Werror -Wno-unused-parameter
# effectively .PHONY because it doesn't generate output
ctest: CFLAGS=-std=c11 -fsyntax-only -Wall -Wextra -Werror -pedantic
ctest: ctest.c quickjs.h
$(CC) $(CFLAGS) -DJS_NAN_BOXING=0 $<
$(CC) $(CFLAGS) -DJS_NAN_BOXING=1 $<

# effectively .PHONY because it doesn't generate output
cxxtest: CXXFLAGS=-std=c++11 -fsyntax-only -Wall -Wextra -Werror -pedantic
cxxtest: cxxtest.cc quickjs.h
$(CXX) $(CXXFLAGS) -DJS_NAN_BOXING=0 $<
$(CXX) $(CXXFLAGS) -DJS_NAN_BOXING=1 $<
Expand Down Expand Up @@ -116,4 +122,4 @@ unicode_gen: $(BUILD_DIR)
libunicode-table.h: unicode_gen
$(BUILD_DIR)/unicode_gen unicode $@

.PHONY: all cxxtest debug fuzz install clean codegen distclean stats test test262 test262-update test262-check microbench unicode_gen $(QJS) $(QJSC)
.PHONY: all ctest cxxtest debug fuzz install clean codegen distclean stats test test262 test262-update test262-check microbench unicode_gen $(QJS) $(QJSC)
17 changes: 17 additions & 0 deletions ctest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// note: file is not actually compiled, only checked for C syntax errors
#include "quickjs.h"

int main(void)
{
JSRuntime *rt = JS_NewRuntime();
JSContext *ctx = JS_NewContext(rt);
JS_FreeValue(ctx, JS_NAN);
JS_FreeValue(ctx, JS_UNDEFINED);
JS_FreeValue(ctx, JS_NewFloat64(ctx, 42));
// not a legal way of using JS_MKPTR but this is here
// to have the compiler syntax-check its definition
JS_FreeValue(ctx, JS_MKPTR(JS_TAG_UNINITIALIZED, 0));
JS_FreeContext(ctx);
JS_FreeRuntime(rt);
return 0;
}
17 changes: 1 addition & 16 deletions cxxtest.cc
Original file line number Diff line number Diff line change
@@ -1,17 +1,2 @@
// note: file is not actually compiled, only checked for C++ syntax errors
#include "quickjs.h"

int main(void)
{
JSRuntime *rt = JS_NewRuntime();
JSContext *ctx = JS_NewContext(rt);
JS_FreeValue(ctx, JS_NAN);
JS_FreeValue(ctx, JS_UNDEFINED);
JS_FreeValue(ctx, JS_NewFloat64(ctx, 42));
// not a legal way of using JS_MKPTR but this is here
// to have the compiler syntax-check its definition
JS_FreeValue(ctx, JS_MKPTR(JS_TAG_UNINITIALIZED, 0));
JS_FreeContext(ctx);
JS_FreeRuntime(rt);
return 0;
}
#include "ctest.c"
8 changes: 6 additions & 2 deletions quickjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -514,21 +514,25 @@ JS_EXTERN int JS_IsRegisteredClass(JSRuntime *rt, JSClassID class_id);

static js_force_inline JSValue JS_NewBool(JSContext *ctx, JS_BOOL val)
{
(void)&ctx;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the & necessary? I thought (void)ctx; would be enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not necessary here but it's a general precaution, in case the unused thing is a macro that evaluates to something non-addressable (because that probably indicates dead code, or a bug.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL!

return JS_MKVAL(JS_TAG_BOOL, (val != 0));
}

static js_force_inline JSValue JS_NewInt32(JSContext *ctx, int32_t val)
{
(void)&ctx;
return JS_MKVAL(JS_TAG_INT, val);
}

static js_force_inline JSValue JS_NewFloat64(JSContext *ctx, double val)
{
(void)&ctx;
return __JS_NewFloat64(val);
}

static js_force_inline JSValue JS_NewCatchOffset(JSContext *ctx, int32_t val)
{
(void)&ctx;
return JS_MKVAL(JS_TAG_CATCH_OFFSET, val);
}

Expand Down Expand Up @@ -566,8 +570,8 @@ static inline JS_BOOL JS_IsNumber(JSValue v)

static inline JS_BOOL JS_IsBigInt(JSContext *ctx, JSValue v)
{
int tag = JS_VALUE_GET_TAG(v);
return tag == JS_TAG_BIG_INT;
(void)&ctx;
return JS_VALUE_GET_TAG(v) == JS_TAG_BIG_INT;
}

static inline JS_BOOL JS_IsBool(JSValue v)
Expand Down
Loading