mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
quickjs: update to the latest version
Also add patch to fix std.loadFile issue for reading proc and sysfs.
This commit is contained in:
parent
0e3291c267
commit
b179460524
4 changed files with 143 additions and 28 deletions
|
|
@ -5,8 +5,8 @@ PKG_RELEASE:=1
|
||||||
|
|
||||||
PKG_SOURCE_PROTO:=git
|
PKG_SOURCE_PROTO:=git
|
||||||
PKG_SOURCE_URL:=https://github.com/bellard/quickjs.git
|
PKG_SOURCE_URL:=https://github.com/bellard/quickjs.git
|
||||||
PKG_SOURCE_DATE:=2020-11-08
|
PKG_SOURCE_DATE:=2022-03-06
|
||||||
PKG_SOURCE_VERSION:=204682fb87ab9312f0cf81f959ecd181180457bc
|
PKG_SOURCE_VERSION:=2788d71e823b522b178db3b3660ce93689534e6d
|
||||||
PKG_MIRROR_HASH:=skip
|
PKG_MIRROR_HASH:=skip
|
||||||
PKG_LICENSE:=MIT
|
PKG_LICENSE:=MIT
|
||||||
|
|
||||||
|
|
@ -30,18 +30,16 @@ define Package/quickjs/description
|
||||||
generators, proxies and BigInt.
|
generators, proxies and BigInt.
|
||||||
endef
|
endef
|
||||||
|
|
||||||
MAKE_VARS += \
|
|
||||||
LIBS="-latomic"
|
|
||||||
|
|
||||||
MAKE_FLAGS = \
|
MAKE_FLAGS = \
|
||||||
prefix=/usr \
|
prefix=/usr \
|
||||||
CONFIG_SMALL=y \
|
CONFIG_SMALL=y \
|
||||||
|
EXTRA_LIBS="-latomic" \
|
||||||
CROSS_PREFIX="$(TARGET_CROSS)"
|
CROSS_PREFIX="$(TARGET_CROSS)"
|
||||||
|
|
||||||
define Build/InstallDev
|
define Build/InstallDev
|
||||||
$(INSTALL_DIR) $(1)/usr/lib/quickjs
|
$(INSTALL_DIR) $(1)/usr/lib/quickjs
|
||||||
$(CP) $(PKG_INSTALL_DIR)/usr/lib/quickjs/libquickjs.a $(1)/usr/lib/quickjs/
|
$(CP) $(PKG_INSTALL_DIR)/usr/lib/quickjs/libquickjs.a $(1)/usr/lib/
|
||||||
$(CP) $(PKG_INSTALL_DIR)/usr/lib/quickjs/libquickjs.lto.a $(1)/usr/lib/quickjs/
|
$(CP) $(PKG_INSTALL_DIR)/usr/lib/quickjs/libquickjs.lto.a $(1)/usr/lib/
|
||||||
$(INSTALL_DIR) $(1)/usr/include/quickjs
|
$(INSTALL_DIR) $(1)/usr/include/quickjs
|
||||||
$(CP) $(PKG_INSTALL_DIR)/usr/include/quickjs/quickjs.h $(1)/usr/include/quickjs/
|
$(CP) $(PKG_INSTALL_DIR)/usr/include/quickjs/quickjs.h $(1)/usr/include/quickjs/
|
||||||
$(CP) $(PKG_INSTALL_DIR)/usr/include/quickjs/quickjs-libc.h $(1)/usr/include/quickjs/
|
$(CP) $(PKG_INSTALL_DIR)/usr/include/quickjs/quickjs-libc.h $(1)/usr/include/quickjs/
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
diff --git a/Makefile b/Makefile
|
diff --git a/Makefile b/Makefile
|
||||||
index e6ae827..bbd3ce8 100644
|
index 49b1f6f..2c96eae 100644
|
||||||
--- a/Makefile
|
--- a/Makefile
|
||||||
+++ b/Makefile
|
+++ b/Makefile
|
||||||
@@ -33,6 +33,8 @@ CONFIG_LTO=y
|
@@ -33,6 +33,8 @@ CONFIG_LTO=y
|
||||||
|
|
@ -58,16 +58,7 @@ index e6ae827..bbd3ce8 100644
|
||||||
ifdef CONFIG_LTO
|
ifdef CONFIG_LTO
|
||||||
CFLAGS_SMALL+=-flto
|
CFLAGS_SMALL+=-flto
|
||||||
CFLAGS_OPT+=-flto
|
CFLAGS_OPT+=-flto
|
||||||
@@ -175,7 +188,7 @@ QJS_OBJS+=$(OBJDIR)/qjscalc.o
|
@@ -195,6 +208,8 @@ qjsc$(EXE): $(OBJDIR)/qjsc.o $(QJS_LIB_OBJS)
|
||||||
endif
|
|
||||||
|
|
||||||
HOST_LIBS=-lm -ldl -lpthread
|
|
||||||
-LIBS=-lm
|
|
||||||
+LIBS+=-lm
|
|
||||||
ifndef CONFIG_WIN32
|
|
||||||
LIBS+=-ldl -lpthread
|
|
||||||
endif
|
|
||||||
@@ -194,6 +207,8 @@ qjsc$(EXE): $(OBJDIR)/qjsc.o $(QJS_LIB_OBJS)
|
|
||||||
|
|
||||||
ifneq ($(CROSS_PREFIX),)
|
ifneq ($(CROSS_PREFIX),)
|
||||||
|
|
||||||
|
|
@ -76,7 +67,7 @@ index e6ae827..bbd3ce8 100644
|
||||||
$(QJSC): $(OBJDIR)/qjsc.host.o \
|
$(QJSC): $(OBJDIR)/qjsc.host.o \
|
||||||
$(patsubst %.o, %.host.o, $(QJS_LIB_OBJS))
|
$(patsubst %.o, %.host.o, $(QJS_LIB_OBJS))
|
||||||
$(HOST_CC) $(LDFLAGS) -o $@ $^ $(HOST_LIBS)
|
$(HOST_CC) $(LDFLAGS) -o $@ $^ $(HOST_LIBS)
|
||||||
@@ -261,6 +276,8 @@ run-test262-32: $(patsubst %.o, %.m32.o, $(OBJDIR)/run-test262.o $(QJS_LIB_OBJS)
|
@@ -262,6 +277,8 @@ run-test262-32: $(patsubst %.o, %.m32.o, $(OBJDIR)/run-test262.o $(QJS_LIB_OBJS)
|
||||||
$(OBJDIR)/%.o: %.c | $(OBJDIR)
|
$(OBJDIR)/%.o: %.c | $(OBJDIR)
|
||||||
$(CC) $(CFLAGS_OPT) -c -o $@ $<
|
$(CC) $(CFLAGS_OPT) -c -o $@ $<
|
||||||
|
|
||||||
|
|
@ -85,7 +76,7 @@ index e6ae827..bbd3ce8 100644
|
||||||
$(OBJDIR)/%.host.o: %.c | $(OBJDIR)
|
$(OBJDIR)/%.host.o: %.c | $(OBJDIR)
|
||||||
$(HOST_CC) $(CFLAGS_OPT) -c -o $@ $<
|
$(HOST_CC) $(CFLAGS_OPT) -c -o $@ $<
|
||||||
|
|
||||||
@@ -285,6 +302,8 @@ $(OBJDIR)/%.check.o: %.c | $(OBJDIR)
|
@@ -286,6 +303,8 @@ $(OBJDIR)/%.check.o: %.c | $(OBJDIR)
|
||||||
regexp_test: libregexp.c libunicode.c cutils.c
|
regexp_test: libregexp.c libunicode.c cutils.c
|
||||||
$(CC) $(LDFLAGS) $(CFLAGS) -DTEST -o $@ libregexp.c libunicode.c cutils.c $(LIBS)
|
$(CC) $(LDFLAGS) $(CFLAGS) -DTEST -o $@ libregexp.c libunicode.c cutils.c $(LIBS)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
diff --git a/quickjs.c b/quickjs.c
|
diff --git a/quickjs.c b/quickjs.c
|
||||||
index a39ff8f..635c506 100644
|
index 7916013..3936eec 100644
|
||||||
--- a/quickjs.c
|
--- a/quickjs.c
|
||||||
+++ b/quickjs.c
|
+++ b/quickjs.c
|
||||||
@@ -65,6 +65,16 @@
|
@@ -67,6 +67,16 @@
|
||||||
#define CONFIG_PRINTF_RNDN
|
#define CONFIG_PRINTF_RNDN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -19,7 +19,7 @@ index a39ff8f..635c506 100644
|
||||||
/* define to include Atomics.* operations which depend on the OS
|
/* define to include Atomics.* operations which depend on the OS
|
||||||
threads */
|
threads */
|
||||||
#if !defined(EMSCRIPTEN)
|
#if !defined(EMSCRIPTEN)
|
||||||
@@ -11253,6 +11263,11 @@ static char *i64toa(char *buf_end, int64_t n, unsigned int base)
|
@@ -11299,6 +11309,11 @@ static char *i64toa(char *buf_end, int64_t n, unsigned int base)
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,7 +31,7 @@ index a39ff8f..635c506 100644
|
||||||
/* buf1 contains the printf result */
|
/* buf1 contains the printf result */
|
||||||
static void js_ecvt1(double d, int n_digits, int *decpt, int *sign, char *buf,
|
static void js_ecvt1(double d, int n_digits, int *decpt, int *sign, char *buf,
|
||||||
int rounding_mode, char *buf1, int buf1_size)
|
int rounding_mode, char *buf1, int buf1_size)
|
||||||
@@ -11272,9 +11287,6 @@ static void js_ecvt1(double d, int n_digits, int *decpt, int *sign, char *buf,
|
@@ -11318,9 +11333,6 @@ static void js_ecvt1(double d, int n_digits, int *decpt, int *sign, char *buf,
|
||||||
*decpt = atoi(buf1 + n_digits + 2 + (n_digits > 1)) + 1;
|
*decpt = atoi(buf1 + n_digits + 2 + (n_digits > 1)) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,7 +41,7 @@ index a39ff8f..635c506 100644
|
||||||
/* needed because ecvt usually limits the number of digits to
|
/* needed because ecvt usually limits the number of digits to
|
||||||
17. Return the number of digits. */
|
17. Return the number of digits. */
|
||||||
static int js_ecvt(double d, int n_digits, int *decpt, int *sign, char *buf,
|
static int js_ecvt(double d, int n_digits, int *decpt, int *sign, char *buf,
|
||||||
@@ -11383,6 +11395,8 @@ static void js_fcvt(char *buf, int buf_size, double d, int n_digits)
|
@@ -11429,6 +11441,8 @@ static void js_fcvt(char *buf, int buf_size, double d, int n_digits)
|
||||||
js_fcvt1(buf, buf_size, d, n_digits, rounding_mode);
|
js_fcvt1(buf, buf_size, d, n_digits, rounding_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,7 +50,7 @@ index a39ff8f..635c506 100644
|
||||||
/* radix != 10 is only supported with flags = JS_DTOA_VAR_FORMAT */
|
/* radix != 10 is only supported with flags = JS_DTOA_VAR_FORMAT */
|
||||||
/* use as many digits as necessary */
|
/* use as many digits as necessary */
|
||||||
#define JS_DTOA_VAR_FORMAT (0 << 0)
|
#define JS_DTOA_VAR_FORMAT (0 << 0)
|
||||||
@@ -11396,8 +11410,10 @@ static void js_fcvt(char *buf, int buf_size, double d, int n_digits)
|
@@ -11442,8 +11456,10 @@ static void js_fcvt(char *buf, int buf_size, double d, int n_digits)
|
||||||
/* XXX: slow and maybe not fully correct. Use libbf when it is fast enough.
|
/* XXX: slow and maybe not fully correct. Use libbf when it is fast enough.
|
||||||
XXX: radix != 10 is only supported for small integers
|
XXX: radix != 10 is only supported for small integers
|
||||||
*/
|
*/
|
||||||
|
|
@ -62,7 +62,7 @@ index a39ff8f..635c506 100644
|
||||||
char *q;
|
char *q;
|
||||||
|
|
||||||
if (!isfinite(d)) {
|
if (!isfinite(d)) {
|
||||||
@@ -11419,6 +11435,25 @@ static void js_dtoa1(char *buf, double d, int radix, int n_digits, int flags)
|
@@ -11465,6 +11481,25 @@ static void js_dtoa1(char *buf, double d, int radix, int n_digits, int flags)
|
||||||
ptr = i64toa(buf1 + sizeof(buf1), i64, radix);
|
ptr = i64toa(buf1 + sizeof(buf1), i64, radix);
|
||||||
strcpy(buf, ptr);
|
strcpy(buf, ptr);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -88,7 +88,7 @@ index a39ff8f..635c506 100644
|
||||||
if (d == 0.0)
|
if (d == 0.0)
|
||||||
d = 0.0; /* convert -0 to 0 */
|
d = 0.0; /* convert -0 to 0 */
|
||||||
if (flags == JS_DTOA_FRAC_FORMAT) {
|
if (flags == JS_DTOA_FRAC_FORMAT) {
|
||||||
@@ -11482,14 +11517,8 @@ static void js_dtoa1(char *buf, double d, int radix, int n_digits, int flags)
|
@@ -11528,14 +11563,8 @@ static void js_dtoa1(char *buf, double d, int radix, int n_digits, int flags)
|
||||||
sprintf(q, "%d", p);
|
sprintf(q, "%d", p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
126
quickjs/patches/002-fix_std_loadFile.patch
Normal file
126
quickjs/patches/002-fix_std_loadFile.patch
Normal file
|
|
@ -0,0 +1,126 @@
|
||||||
|
diff --git a/quickjs-libc.c b/quickjs-libc.c
|
||||||
|
index e180dd0..76182d2 100644
|
||||||
|
--- a/quickjs-libc.c
|
||||||
|
+++ b/quickjs-libc.c
|
||||||
|
@@ -358,12 +358,89 @@ fail:
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
+// For reading files that are not seekable, per second answer from stackoverflow:
|
||||||
|
+// https://stackoverflow.com/questions/14002954/c-programming-how-to-read-the-whole-file-contents-into-a-buffer
|
||||||
|
+
|
||||||
|
+#define READALL_CHUNK 10*1024
|
||||||
|
+
|
||||||
|
+static int readall(FILE *f, JSContext *ctx, uint8_t **dataptr, size_t *sizeptr)
|
||||||
|
+{
|
||||||
|
+ uint8_t *data = NULL, *temp;
|
||||||
|
+ size_t size = 0;
|
||||||
|
+ size_t used = 0;
|
||||||
|
+ size_t n;
|
||||||
|
+
|
||||||
|
+ while (1) {
|
||||||
|
+ if (used + READALL_CHUNK + 1 > size) {
|
||||||
|
+ size = used + READALL_CHUNK + 1;
|
||||||
|
+
|
||||||
|
+ /* Overflow check. Some ANSI C compilers
|
||||||
|
+ may optimize this away, though. */
|
||||||
|
+ if (size <= used) {
|
||||||
|
+ if (ctx)
|
||||||
|
+ js_free(ctx, data);
|
||||||
|
+ else
|
||||||
|
+ free(data);
|
||||||
|
+ return -1;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (ctx)
|
||||||
|
+ temp = js_realloc(ctx, data, size);
|
||||||
|
+ else
|
||||||
|
+ temp = realloc(data, size);
|
||||||
|
+
|
||||||
|
+ if (temp == NULL) {
|
||||||
|
+ if (ctx)
|
||||||
|
+ js_free(ctx, data);
|
||||||
|
+ else
|
||||||
|
+ free(data);
|
||||||
|
+ return -1;
|
||||||
|
+ }
|
||||||
|
+ data = temp;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ n = fread(data + used, 1, READALL_CHUNK, f);
|
||||||
|
+ if (n == 0)
|
||||||
|
+ break;
|
||||||
|
+
|
||||||
|
+ used += n;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (ferror(f)) {
|
||||||
|
+ if (ctx)
|
||||||
|
+ js_free(ctx, data);
|
||||||
|
+ else
|
||||||
|
+ free(data);
|
||||||
|
+ return -1;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (ctx)
|
||||||
|
+ temp = js_realloc(ctx, data, used + 1);
|
||||||
|
+ else
|
||||||
|
+ temp = realloc(data, used + 1);
|
||||||
|
+
|
||||||
|
+ if (temp == NULL) {
|
||||||
|
+ if (ctx)
|
||||||
|
+ js_free(ctx, data);
|
||||||
|
+ else
|
||||||
|
+ free(data);
|
||||||
|
+ return -1;
|
||||||
|
+ }
|
||||||
|
+ data = temp;
|
||||||
|
+ data[used] = '\0';
|
||||||
|
+
|
||||||
|
+ *dataptr = data;
|
||||||
|
+ *sizeptr = used;
|
||||||
|
+
|
||||||
|
+ return 0;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
uint8_t *js_load_file(JSContext *ctx, size_t *pbuf_len, const char *filename)
|
||||||
|
{
|
||||||
|
FILE *f;
|
||||||
|
uint8_t *buf;
|
||||||
|
size_t buf_len;
|
||||||
|
- long lret;
|
||||||
|
+ long lret = 0;
|
||||||
|
|
||||||
|
f = fopen(filename, "rb");
|
||||||
|
if (!f)
|
||||||
|
@@ -371,7 +448,7 @@ uint8_t *js_load_file(JSContext *ctx, size_t *pbuf_len, const char *filename)
|
||||||
|
if (fseek(f, 0, SEEK_END) < 0)
|
||||||
|
goto fail;
|
||||||
|
lret = ftell(f);
|
||||||
|
- if (lret < 0)
|
||||||
|
+ if (lret <= 0)
|
||||||
|
goto fail;
|
||||||
|
/* XXX: on Linux, ftell() return LONG_MAX for directories */
|
||||||
|
if (lret == LONG_MAX) {
|
||||||
|
@@ -387,13 +464,19 @@ uint8_t *js_load_file(JSContext *ctx, size_t *pbuf_len, const char *filename)
|
||||||
|
buf = malloc(buf_len + 1);
|
||||||
|
if (!buf)
|
||||||
|
goto fail;
|
||||||
|
- if (fread(buf, 1, buf_len, f) != buf_len) {
|
||||||
|
- errno = EIO;
|
||||||
|
+ buf_len = fread(buf, 1, buf_len, f);
|
||||||
|
+ if (ferror(f)) {
|
||||||
|
if (ctx)
|
||||||
|
js_free(ctx, buf);
|
||||||
|
else
|
||||||
|
free(buf);
|
||||||
|
fail:
|
||||||
|
+ // Files in proc and sysfs may not be seekable or may falsely
|
||||||
|
+ // appear to be of zero size. Try to read them in another way.
|
||||||
|
+ if (lret == 0 && readall(f, ctx, &buf, pbuf_len) == 0) {
|
||||||
|
+ fclose(f);
|
||||||
|
+ return buf;
|
||||||
|
+ }
|
||||||
|
fclose(f);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue