Skip to content

Commit

Permalink
Update WZ-applied QuickJS patches
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Mar 26, 2024
1 parent d47fdee commit d95a193
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 82 deletions.
2 changes: 1 addition & 1 deletion patches/001-add-extensions.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
diff --git a/quickjs.c b/quickjs.c
--- a/quickjs.c
+++ b/quickjs.c
@@ -55592,3 +55592,6 @@ void JS_AddIntrinsicTypedArrays(JSContext *ctx)
@@ -55901,3 +55901,6 @@ void JS_AddIntrinsicTypedArrays(JSContext *ctx)
JS_AddIntrinsicAtomics(ctx);
#endif
}
Expand Down
43 changes: 18 additions & 25 deletions patches/004-msvc-compatibility.patch
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ diff --git a/cutils.c b/cutils.c
diff --git a/cutils.h b/cutils.h
--- a/cutils.h
+++ b/cutils.h
@@ -28,14 +28,55 @@
#include <stdlib.h>
@@ -29,11 +29,48 @@
#include <string.h>
#include <inttypes.h>

-#define likely(x) __builtin_expect(!!(x), 1)
-#define unlikely(x) __builtin_expect(!!(x), 0)
-#define force_inline inline __attribute__((always_inline))
-#define no_inline __attribute__((noinline))
-#define __maybe_unused __attribute__((unused))
+#if defined(_MSC_VER)
+ #if !defined(NOMINMAX)
+ #define NOMINMAX // For windows.h
Expand All @@ -36,14 +41,6 @@ diff --git a/cutils.h b/cutils.h
+ #include <intrin.h>
+#endif
+
/* set if CPU is big endian */
#undef WORDS_BIGENDIAN

-#define likely(x) __builtin_expect(!!(x), 1)
-#define unlikely(x) __builtin_expect(!!(x), 0)
-#define force_inline inline __attribute__((always_inline))
-#define no_inline __attribute__((noinline))
-#define __maybe_unused __attribute__((unused))
+#if defined(__has_attribute)
+ #define QUICKJS_HAS_ATTRIBUTE(x) __has_attribute(x)
+#else
Expand Down Expand Up @@ -77,15 +74,11 @@ diff --git a/cutils.h b/cutils.h
+ #define __maybe_unused __attribute__((unused))
+#else
+ #define __maybe_unused /* not supported */
+#endif
+#if defined(_MSC_VER)
+ #include <BaseTsd.h>
+ typedef SSIZE_T ssize_t;
+#endif

#define xglue(x, y) x ## y
#define glue(x, y) xglue(x, y)
@@ -61,6 +102,10 @@ enum {
@@ -66,6 +103,10 @@ enum {
};
#endif

Expand All @@ -96,7 +89,7 @@ diff --git a/cutils.h b/cutils.h
void pstrcpy(char *buf, int buf_size, const char *str);
char *pstrcat(char *buf, int buf_size, const char *s);
int strstart(const char *str, const char *val, const char **ptr);
@@ -117,27 +162,91 @@ static inline int64_t min_int64(int64_t a, int64_t b)
@@ -128,27 +169,91 @@ static inline int64_t min_int64(int64_t a, int64_t b)
/* WARNING: undefined if a = 0 */
static inline int clz32(unsigned int a)
{
Expand Down Expand Up @@ -188,7 +181,7 @@ diff --git a/cutils.h b/cutils.h
struct __attribute__((packed)) packed_u64 {
uint64_t v;
};
@@ -149,6 +258,7 @@ struct __attribute__((packed)) packed_u32 {
@@ -160,6 +265,7 @@ struct __attribute__((packed)) packed_u32 {
struct __attribute__((packed)) packed_u16 {
uint16_t v;
};
Expand All @@ -199,7 +192,7 @@ diff --git a/cutils.h b/cutils.h
diff --git a/libregexp.c b/libregexp.c
--- a/libregexp.c
+++ b/libregexp.c
@@ -409,7 +409,7 @@ static int parse_digits(const uint8_t **pp, BOOL allow_overflow)
@@ -410,7 +410,7 @@ static int parse_digits(const uint8_t **pp, BOOL allow_overflow)
p++;
}
*pp = p;
Expand Down Expand Up @@ -235,7 +228,7 @@ diff --git a/quickjs.c b/quickjs.c
#define DIRECT_DISPATCH 0
#else
#define DIRECT_DISPATCH 1
@@ -1600,17 +1607,39 @@ static inline BOOL js_check_stack_overflow(JSRuntime *rt, size_t alloca_size)
@@ -1607,17 +1614,39 @@ static inline BOOL js_check_stack_overflow(JSRuntime *rt, size_t alloca_size)
return FALSE;
}
#else
Expand Down Expand Up @@ -275,7 +268,7 @@ diff --git a/quickjs.c b/quickjs.c
}
#endif

@@ -10279,7 +10308,11 @@ static JSValue js_atof(JSContext *ctx, const char *str, const char **pp,
@@ -10286,7 +10315,11 @@ static JSValue js_atof(JSContext *ctx, const char *str, const char **pp,
} else
#endif
{
Expand All @@ -287,7 +280,7 @@ diff --git a/quickjs.c b/quickjs.c
if (is_neg)
d = -d;
val = JS_NewFloat64(ctx, d);
@@ -42978,7 +43011,11 @@ static JSValue js_math_min_max(JSContext *ctx, JSValueConst this_val,
@@ -43090,7 +43123,11 @@ static JSValue js_math_min_max(JSContext *ctx, JSValueConst this_val,
uint32_t tag;

if (unlikely(argc == 0)) {
Expand All @@ -299,7 +292,7 @@ diff --git a/quickjs.c b/quickjs.c
}

tag = JS_VALUE_GET_TAG(argv[0]);
@@ -43150,6 +43187,13 @@ static JSValue js_math_random(JSContext *ctx, JSValueConst this_val,
@@ -43264,6 +43301,13 @@ static JSValue js_math_random(JSContext *ctx, JSValueConst this_val,
return __JS_NewFloat64(ctx, u.d - 1.0);
}

Expand All @@ -313,7 +306,7 @@ diff --git a/quickjs.c b/quickjs.c
static const JSCFunctionListEntry js_math_funcs[] = {
JS_CFUNC_MAGIC_DEF("min", 2, js_math_min_max, 0 ),
JS_CFUNC_MAGIC_DEF("max", 2, js_math_min_max, 1 ),
@@ -49301,7 +49345,11 @@ static const JSCFunctionListEntry js_global_funcs[] = {
@@ -49418,7 +49462,11 @@ static const JSCFunctionListEntry js_global_funcs[] = {
JS_CFUNC_MAGIC_DEF("encodeURIComponent", 1, js_global_encodeURI, 1 ),
JS_CFUNC_DEF("escape", 1, js_global_escape ),
JS_CFUNC_DEF("unescape", 1, js_global_unescape ),
Expand All @@ -324,7 +317,7 @@ diff --git a/quickjs.c b/quickjs.c
+#endif
JS_PROP_DOUBLE_DEF("NaN", NAN, 0 ),
JS_PROP_UNDEFINED_DEF("undefined", 0 ),
};
JS_PROP_STRING_DEF("[Symbol.toStringTag]", "global", JS_PROP_CONFIGURABLE ),
diff --git a/quickjs.h b/quickjs.h
--- a/quickjs.h
+++ b/quickjs.h
Expand All @@ -340,7 +333,7 @@ diff --git a/quickjs.h b/quickjs.h
#define __js_printf_like(a, b)
#endif

@@ -533,9 +537,9 @@ static js_force_inline JSValue JS_NewInt64(JSContext *ctx, int64_t val)
@@ -536,9 +540,9 @@ static js_force_inline JSValue JS_NewInt64(JSContext *ctx, int64_t val)
{
JSValue v;
if (val == (int32_t)val) {
Expand Down
34 changes: 17 additions & 17 deletions patches/005-msvc-compatibility-64bit.patch
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ diff --git a/quickjs.c b/quickjs.c
#endif

#include "cutils.h"
@@ -1618,7 +1620,7 @@ static inline uintptr_t js_get_stack_pointer(void)
@@ -1625,7 +1627,7 @@ static inline uintptr_t js_get_stack_pointer(void)
{
return (uintptr_t)__builtin_frame_address(0);
}
Expand All @@ -33,7 +33,7 @@ diff --git a/quickjs.c b/quickjs.c
static inline uintptr_t js_get_stack_pointer(void)
{
return (uintptr_t)_AddressOfReturnAddress();
@@ -7318,7 +7320,7 @@ static int JS_DefinePrivateField(JSContext *ctx, JSValueConst obj,
@@ -7331,7 +7333,7 @@ static int JS_DefinePrivateField(JSContext *ctx, JSValueConst obj,
JS_ThrowTypeErrorNotASymbol(ctx);
goto fail;
}
Expand All @@ -42,7 +42,7 @@ diff --git a/quickjs.c b/quickjs.c
p = JS_VALUE_GET_OBJ(obj);
prs = find_own_property(&pr, p, prop);
if (prs) {
@@ -7349,7 +7351,7 @@ static JSValue JS_GetPrivateField(JSContext *ctx, JSValueConst obj,
@@ -7362,7 +7364,7 @@ static JSValue JS_GetPrivateField(JSContext *ctx, JSValueConst obj,
/* safety check */
if (unlikely(JS_VALUE_GET_TAG(name) != JS_TAG_SYMBOL))
return JS_ThrowTypeErrorNotASymbol(ctx);
Expand All @@ -51,7 +51,7 @@ diff --git a/quickjs.c b/quickjs.c
p = JS_VALUE_GET_OBJ(obj);
prs = find_own_property(&pr, p, prop);
if (!prs) {
@@ -7376,7 +7378,7 @@ static int JS_SetPrivateField(JSContext *ctx, JSValueConst obj,
@@ -7389,7 +7391,7 @@ static int JS_SetPrivateField(JSContext *ctx, JSValueConst obj,
JS_ThrowTypeErrorNotASymbol(ctx);
goto fail;
}
Expand All @@ -60,7 +60,7 @@ diff --git a/quickjs.c b/quickjs.c
p = JS_VALUE_GET_OBJ(obj);
prs = find_own_property(&pr, p, prop);
if (!prs) {
@@ -7475,7 +7477,7 @@ static int JS_CheckBrand(JSContext *ctx, JSValueConst obj, JSValueConst func)
@@ -7488,7 +7490,7 @@ static int JS_CheckBrand(JSContext *ctx, JSValueConst obj, JSValueConst func)
return -1;
}
p = JS_VALUE_GET_OBJ(obj);
Expand All @@ -69,7 +69,7 @@ diff --git a/quickjs.c b/quickjs.c
return (prs != NULL);
}

@@ -9095,7 +9097,7 @@ int JS_DefineProperty(JSContext *ctx, JSValueConst this_obj,
@@ -9108,7 +9110,7 @@ int JS_DefineProperty(JSContext *ctx, JSValueConst this_obj,
return -1;
}
/* this code relies on the fact that Uint32 are never allocated */
Expand All @@ -78,7 +78,7 @@ diff --git a/quickjs.c b/quickjs.c
/* prs may have been modified */
prs = find_own_property(&pr, p, prop);
assert(prs != NULL);
@@ -15923,7 +15925,7 @@ static JSValue js_call_c_function(JSContext *ctx, JSValueConst func_obj,
@@ -16013,7 +16015,7 @@ static JSValue js_call_c_function(JSContext *ctx, JSValueConst func_obj,
#else
sf->js_mode = 0;
#endif
Expand All @@ -87,7 +87,7 @@ diff --git a/quickjs.c b/quickjs.c
sf->arg_count = argc;
arg_buf = argv;

@@ -16168,7 +16170,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
@@ -16258,7 +16260,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
sf->js_mode = b->js_mode;
arg_buf = argv;
sf->arg_count = argc;
Expand All @@ -96,7 +96,7 @@ diff --git a/quickjs.c b/quickjs.c
init_list_head(&sf->var_ref_list);
var_refs = p->u.func.var_refs;

@@ -40318,8 +40320,8 @@ static int64_t JS_FlattenIntoArray(JSContext *ctx, JSValueConst target,
@@ -40425,8 +40427,8 @@ static int64_t JS_FlattenIntoArray(JSContext *ctx, JSValueConst target,
if (!JS_IsUndefined(mapperFunction)) {
JSValueConst args[3] = { element, JS_NewInt64(ctx, sourceIndex), source };
element = JS_Call(ctx, mapperFunction, thisArg, 3, args);
Expand All @@ -107,7 +107,7 @@ diff --git a/quickjs.c b/quickjs.c
if (JS_IsException(element))
return -1;
}
@@ -41881,7 +41883,7 @@ static JSValue js_string_match(JSContext *ctx, JSValueConst this_val,
@@ -41992,7 +41994,7 @@ static JSValue js_string_match(JSContext *ctx, JSValueConst this_val,
str = JS_NewString(ctx, "g");
if (JS_IsException(str))
goto fail;
Expand All @@ -116,7 +116,7 @@ diff --git a/quickjs.c b/quickjs.c
}
rx = JS_CallConstructor(ctx, ctx->regexp_ctor, args_len, args);
JS_FreeValue(ctx, str);
@@ -47084,7 +47086,7 @@ static JSMapRecord *map_add_record(JSContext *ctx, JSMapState *s,
@@ -47202,7 +47204,7 @@ static JSMapRecord *map_add_record(JSContext *ctx, JSMapState *s,
} else {
JS_DupValue(ctx, key);
}
Expand All @@ -125,7 +125,7 @@ diff --git a/quickjs.c b/quickjs.c
h = map_hash_key(ctx, key) & (s->hash_size - 1);
list_add_tail(&mr->hash_link, &s->hash_table[h]);
list_add_tail(&mr->link, &s->records);
@@ -47306,7 +47308,7 @@ static JSValue js_map_forEach(JSContext *ctx, JSValueConst this_val,
@@ -47424,7 +47426,7 @@ static JSValue js_map_forEach(JSContext *ctx, JSValueConst this_val,
args[0] = args[1];
else
args[0] = JS_DupValue(ctx, mr->value);
Expand All @@ -134,7 +134,7 @@ diff --git a/quickjs.c b/quickjs.c
ret = JS_Call(ctx, func, this_arg, 3, (JSValueConst *)args);
JS_FreeValue(ctx, args[0]);
if (!magic)
@@ -48408,7 +48410,7 @@ static JSValue js_promise_all(JSContext *ctx, JSValueConst this_val,
@@ -48526,7 +48528,7 @@ static JSValue js_promise_all(JSContext *ctx, JSValueConst this_val,
goto fail_reject;
}
resolve_element_data[0] = JS_NewBool(ctx, FALSE);
Expand All @@ -143,7 +143,7 @@ diff --git a/quickjs.c b/quickjs.c
resolve_element_data[2] = values;
resolve_element_data[3] = resolving_funcs[is_promise_any];
resolve_element_data[4] = resolve_element_env;
@@ -48767,7 +48769,7 @@ static JSValue js_async_from_sync_iterator_unwrap_func_create(JSContext *ctx,
@@ -48885,7 +48887,7 @@ static JSValue js_async_from_sync_iterator_unwrap_func_create(JSContext *ctx,
{
JSValueConst func_data[1];

Expand All @@ -152,7 +152,7 @@ diff --git a/quickjs.c b/quickjs.c
return JS_NewCFunctionData(ctx, js_async_from_sync_iterator_unwrap,
1, 0, 1, func_data);
}
@@ -54336,8 +54338,8 @@ static int js_TA_cmp_generic(const void *a, const void *b, void *opaque) {
@@ -54649,8 +54651,8 @@ static int js_TA_cmp_generic(const void *a, const void *b, void *opaque) {
psc->exception = 2;
}
done:
Expand Down Expand Up @@ -193,7 +193,7 @@ diff --git a/quickjs.h b/quickjs.h

#define JS_VALUE_GET_TAG(v) ((int32_t)(v).tag)
/* same as JS_VALUE_GET_TAG, but return JS_TAG_FLOAT64 with NaN boxing */
@@ -682,7 +688,7 @@ static inline JSValue JS_DupValue(JSContext *ctx, JSValueConst v)
@@ -683,7 +689,7 @@ static inline JSValue JS_DupValue(JSContext *ctx, JSValueConst v)
JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
p->ref_count++;
}
Expand All @@ -202,7 +202,7 @@ diff --git a/quickjs.h b/quickjs.h
}

static inline JSValue JS_DupValueRT(JSRuntime *rt, JSValueConst v)
@@ -691,7 +697,7 @@ static inline JSValue JS_DupValueRT(JSRuntime *rt, JSValueConst v)
@@ -692,7 +698,7 @@ static inline JSValue JS_DupValueRT(JSRuntime *rt, JSValueConst v)
JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
p->ref_count++;
}
Expand Down
4 changes: 2 additions & 2 deletions patches/007-freeruntime2.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
diff --git a/quickjs.c b/quickjs.c
--- a/quickjs.c
+++ b/quickjs.c
@@ -1963,6 +1963,11 @@ void JS_SetRuntimeInfo(JSRuntime *rt, const char *s)
@@ -1970,6 +1970,11 @@ void JS_SetRuntimeInfo(JSRuntime *rt, const char *s)
}

void JS_FreeRuntime(JSRuntime *rt)
Expand All @@ -13,7 +13,7 @@ diff --git a/quickjs.c b/quickjs.c
{
struct list_head *el, *el1;
int i;
@@ -2018,7 +2023,11 @@ void JS_FreeRuntime(JSRuntime *rt)
@@ -2025,7 +2030,11 @@ void JS_FreeRuntime(JSRuntime *rt)
printf("Secondary object leaks: %d\n", count);
}
#endif
Expand Down
36 changes: 1 addition & 35 deletions patches/008-bsd-compile-fixes.patch
Original file line number Diff line number Diff line change
@@ -1,41 +1,7 @@
diff --git a/cutils.h b/cutils.h
--- a/cutils.h
+++ b/cutils.h
@@ -320,17 +320,22 @@ static inline void put_u8(uint8_t *tab, uint8_t val)
*tab = val;
}

+#if !defined(HAVE_BSWAP16)
static inline uint16_t bswap16(uint16_t x)
{
return (x >> 8) | (x << 8);
}
+#endif

+#if !defined(HAVE_BSWAP32)
static inline uint32_t bswap32(uint32_t v)
{
return ((v & 0xff000000) >> 24) | ((v & 0x00ff0000) >> 8) |
((v & 0x0000ff00) << 8) | ((v & 0x000000ff) << 24);
}
+#endif

+#if !defined(HAVE_BSWAP64)
static inline uint64_t bswap64(uint64_t v)
{
return ((v & ((uint64_t)0xff << (7 * 8))) >> (7 * 8)) |
@@ -342,6 +347,7 @@ static inline uint64_t bswap64(uint64_t v)
((v & ((uint64_t)0xff << (1 * 8))) << (5 * 8)) |
((v & ((uint64_t)0xff << (0 * 8))) << (7 * 8));
}
+#endif

/* XXX: should take an extra argument to pass slack information to the caller */
typedef void *DynBufReallocFunc(void *opaque, void *ptr, size_t size);
diff --git a/quickjs.c b/quickjs.c
--- a/quickjs.c
+++ b/quickjs.c
@@ -1729,7 +1729,7 @@ static size_t js_def_malloc_usable_size(const void *ptr)
@@ -1736,7 +1736,7 @@ static size_t js_def_malloc_usable_size(const void *ptr)
return malloc_size(ptr);
#elif defined(_WIN32)
return _msize((void *)ptr);
Expand Down
2 changes: 1 addition & 1 deletion patches/010-win32-gmtime-nullcheck.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
diff --git a/quickjs.c b/quickjs.c
--- a/quickjs.c
+++ b/quickjs.c
@@ -43305,6 +43305,8 @@ static int getTimezoneOffset(int64_t time)
@@ -43419,6 +43419,8 @@ static int getTimezoneOffset(int64_t time)
time_t gm_ti, loc_ti;

tm = gmtime(&ti);
Expand Down
2 changes: 1 addition & 1 deletion patches/011-fix-compile-without-bignum.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
diff --git a/libbf.c b/libbf.c
--- a/libbf.c
+++ b/libbf.c
@@ -3103,9 +3103,15 @@ static int bf_atof_internal(bf_t *r, slimb_t *pexponent,
@@ -3105,9 +3105,15 @@ static int bf_atof_internal(bf_t *r, slimb_t *pexponent,
expn = -expn;
}
if (is_dec) {
Expand Down

0 comments on commit d95a193

Please sign in to comment.