-
Notifications
You must be signed in to change notification settings - Fork 172
Homogenize printf formatting #825
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,14 +39,30 @@ extern "C" { | |
|
||
#if defined(__GNUC__) || defined(__clang__) | ||
#define js_force_inline inline __attribute__((always_inline)) | ||
#define __js_printf_like(f, a) __attribute__((format(printf, f, a))) | ||
#define JS_EXTERN __attribute__((visibility("default"))) | ||
#else | ||
#define js_force_inline inline | ||
#define __js_printf_like(a, b) | ||
#define JS_EXTERN /* nothing */ | ||
#endif | ||
|
||
/* Borrowed from Folly */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a huge fan of having this duplicated, but I'm not sure how to avoid it... |
||
#ifndef JS_PRINTF_FORMAT | ||
#ifdef _MSC_VER | ||
#include <sal.h> | ||
#define JS_PRINTF_FORMAT _Printf_format_string_ | ||
#define JS_PRINTF_FORMAT_ATTR(format_param, dots_param) | ||
#else | ||
#define JS_PRINTF_FORMAT | ||
#if !defined(__clang__) && defined(__GNUC__) | ||
#define JS_PRINTF_FORMAT_ATTR(format_param, dots_param) \ | ||
__attribute__((format(gnu_printf, format_param, dots_param))) | ||
#else | ||
#define JS_PRINTF_FORMAT_ATTR(format_param, dots_param) \ | ||
__attribute__((format(printf, format_param, dots_param))) | ||
#endif | ||
#endif | ||
#endif | ||
|
||
Comment on lines
+49
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicating these definitions should definitely be avoided, but this would require either 2 separate public header files or including quickjs.h in places where we aim to avoid it. Neither approach is satisfying. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I agree. Since it's a small piece I went with duplication. I'm open to other ideas! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quick testing suggests including quickjs.h in cutils.h Just Works™ but I don't have a strong opinion on what approach is better. If you think duplication is best, go for it. |
||
typedef struct JSRuntime JSRuntime; | ||
typedef struct JSContext JSContext; | ||
typedef struct JSObject JSObject; | ||
|
@@ -624,12 +640,12 @@ JS_EXTERN void JS_ClearUncatchableError(JSContext *ctx, JSValue val); | |
// JS_Throw(ctx, exc); | ||
JS_EXTERN void JS_ResetUncatchableError(JSContext *ctx); | ||
JS_EXTERN JSValue JS_NewError(JSContext *ctx); | ||
JS_EXTERN JSValue __js_printf_like(2, 3) JS_ThrowPlainError(JSContext *ctx, const char *fmt, ...); | ||
JS_EXTERN JSValue __js_printf_like(2, 3) JS_ThrowSyntaxError(JSContext *ctx, const char *fmt, ...); | ||
JS_EXTERN JSValue __js_printf_like(2, 3) JS_ThrowTypeError(JSContext *ctx, const char *fmt, ...); | ||
JS_EXTERN JSValue __js_printf_like(2, 3) JS_ThrowReferenceError(JSContext *ctx, const char *fmt, ...); | ||
JS_EXTERN JSValue __js_printf_like(2, 3) JS_ThrowRangeError(JSContext *ctx, const char *fmt, ...); | ||
JS_EXTERN JSValue __js_printf_like(2, 3) JS_ThrowInternalError(JSContext *ctx, const char *fmt, ...); | ||
JS_EXTERN JSValue JS_PRINTF_FORMAT_ATTR(2, 3) JS_ThrowPlainError(JSContext *ctx, JS_PRINTF_FORMAT const char *fmt, ...); | ||
JS_EXTERN JSValue JS_PRINTF_FORMAT_ATTR(2, 3) JS_ThrowSyntaxError(JSContext *ctx, JS_PRINTF_FORMAT const char *fmt, ...); | ||
JS_EXTERN JSValue JS_PRINTF_FORMAT_ATTR(2, 3) JS_ThrowTypeError(JSContext *ctx, JS_PRINTF_FORMAT const char *fmt, ...); | ||
JS_EXTERN JSValue JS_PRINTF_FORMAT_ATTR(2, 3) JS_ThrowReferenceError(JSContext *ctx, JS_PRINTF_FORMAT const char *fmt, ...); | ||
JS_EXTERN JSValue JS_PRINTF_FORMAT_ATTR(2, 3) JS_ThrowRangeError(JSContext *ctx, JS_PRINTF_FORMAT const char *fmt, ...); | ||
JS_EXTERN JSValue JS_PRINTF_FORMAT_ATTR(2, 3) JS_ThrowInternalError(JSContext *ctx, JS_PRINTF_FORMAT const char *fmt, ...); | ||
JS_EXTERN JSValue JS_ThrowOutOfMemory(JSContext *ctx); | ||
JS_EXTERN void JS_FreeValue(JSContext *ctx, JSValue v); | ||
JS_EXTERN void JS_FreeValueRT(JSRuntime *rt, JSValue v); | ||
|
@@ -1075,7 +1091,6 @@ JS_EXTERN uintptr_t js_std_cmd(int cmd, ...); | |
|
||
#undef JS_EXTERN | ||
#undef js_force_inline | ||
#undef __js_printf_like | ||
|
||
#ifdef __cplusplus | ||
} /* extern "C" { */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about compilers that define neither
__clang__
nor__GNUC__
? Do you rely on the fact that__attribute__()
expands to nothing?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code assumes
__attribute__((format(printf
aka the "standard". will work. If when we find a compiler where that's not true, we can add an extra check.