Skip to content
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
9 changes: 5 additions & 4 deletions libbf.c
Original file line number Diff line number Diff line change
Expand Up @@ -5365,19 +5365,20 @@ int bf_acos(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)
#if LIMB_BITS == 64

/* Note: we assume __int128 is available */
/* uint128_t defined in libbf.h */
#define muldq(r1, r0, a, b) \
do { \
unsigned __int128 __t; \
__t = (unsigned __int128)(a) * (unsigned __int128)(b); \
uint128_t __t; \
__t = (uint128_t)(a) * (uint128_t)(b); \
r0 = __t; \
r1 = __t >> 64; \
} while (0)

#define divdq(q, r, a1, a0, b) \
do { \
unsigned __int128 __t; \
uint128_t __t; \
limb_t __b = (b); \
__t = ((unsigned __int128)(a1) << 64) | (a0); \
__t = ((uint128_t)(a1) << 64) | (a0); \
Comment on lines +5368 to +5381
Copy link
Collaborator

Choose a reason for hiding this comment

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

This was definitely an oversight. Should have used uint128_t from day one.

q = __t / __b; \
r = __t % __b; \
} while (0)
Expand Down
6 changes: 4 additions & 2 deletions libbf.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
#define LIMB_BITS (1 << LIMB_LOG2_BITS)

#if LIMB_BITS == 64
typedef __int128 int128_t;
typedef unsigned __int128 uint128_t;
#ifndef INT128_MAX
__extension__ typedef __int128 int128_t;
__extension__ typedef unsigned __int128 uint128_t;
#endif
typedef int64_t slimb_t;
typedef uint64_t limb_t;
typedef uint128_t dlimb_t;
Expand Down
2 changes: 1 addition & 1 deletion libregexp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2064,7 +2064,7 @@ typedef struct REExecState {
size_t count; /* only used for RE_EXEC_STATE_GREEDY_QUANT */
const uint8_t *cptr;
const uint8_t *pc;
void *buf[0];
void *buf[];
Copy link
Collaborator

Choose a reason for hiding this comment

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

We did not use the standard flexible array syntax because it was not supported by older compilers on some targets, possibly in the embedded world. We do use compound literals so it is unlikely for the compiler to support this and not that. All targets in the CI seem happy so I would OK this change.
An alternative would be to use a macro FLEXIBLE defined as nothing on compliant targets and 0 or even 1 on those that do not support the standard syntax.

} REExecState;

typedef struct {
Expand Down
7 changes: 3 additions & 4 deletions quickjs-libc.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ static JSValue js_printf_internal(JSContext *ctx,
int64_t int64_arg;
double double_arg;
const char *string_arg;
/* Use indirect call to dbuf_printf to prevent gcc warning */
int (*dbuf_printf_fun)(DynBuf *s, const char *fmt, ...) = (void*)dbuf_printf;
int (*dbuf_printf_fun)(DynBuf *s, const char *fmt, ...) = dbuf_printf;

js_std_dbuf_init(ctx, &dbuf);

Expand Down Expand Up @@ -518,7 +517,7 @@ static JSModuleDef *js_module_loader_so(JSContext *ctx,
goto fail;
}

init = dlsym(hd, "js_init_module");
*(void **) (&init) = dlsym(hd, "js_init_module");
if (!init) {
JS_ThrowReferenceError(ctx, "could not load module filename '%s': js_init_module not found",
module_name);
Expand Down Expand Up @@ -3231,7 +3230,7 @@ typedef struct {

typedef struct {
int ref_count;
uint64_t buf[0];
uint64_t buf[];
} JSSABHeader;

static JSClassID js_worker_class_id;
Expand Down
24 changes: 11 additions & 13 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,6 @@ typedef enum {
JS_GC_PHASE_REMOVE_CYCLES,
} JSGCPhaseEnum;

typedef enum OPCodeEnum OPCodeEnum;

struct JSRuntime {
JSMallocFunctions mf;
JSMallocState malloc_state;
Expand Down Expand Up @@ -474,8 +472,8 @@ struct JSString {
struct list_head link; /* string list */
#endif
union {
uint8_t str8[0]; /* 8 bit strings will get an extra null terminator */
uint16_t str16[0];
__extension__ uint8_t str8[0]; /* 8 bit strings will get an extra null terminator */
__extension__ uint16_t str16[0];
} u;
};

Expand Down Expand Up @@ -664,7 +662,7 @@ typedef struct JSBoundFunction {
JSValue func_obj;
JSValue this_val;
int argc;
JSValue argv[0];
JSValue argv[];
} JSBoundFunction;

typedef enum JSIteratorKindEnum {
Expand Down Expand Up @@ -822,7 +820,7 @@ typedef struct JSJobEntry {
JSContext *ctx;
JSJobFunc *job_func;
int argc;
JSValue argv[0];
JSValue argv[];
} JSJobEntry;

typedef struct JSProperty {
Expand Down Expand Up @@ -871,7 +869,7 @@ struct JSShape {
int deleted_prop_count;
JSShape *shape_hash_next; /* in JSRuntime.shape_hash[h] list */
JSObject *proto;
JSShapeProperty prop[0]; /* prop_size elements */
JSShapeProperty prop[]; /* prop_size elements */
};

struct JSObject {
Expand Down Expand Up @@ -990,7 +988,7 @@ typedef enum OPCodeFormat {
#undef FMT
} OPCodeFormat;

enum OPCodeEnum {
typedef enum OPCodeEnum {
#define FMT(f)
#define DEF(id, size, n_pop, n_push, f) OP_ ## id,
#define def(id, size, n_pop, n_push, f)
Expand All @@ -1010,7 +1008,7 @@ enum OPCodeEnum {
#undef DEF
#undef FMT
OP_TEMP_END,
};
} OPCodeEnum;

static int JS_InitAtoms(JSRuntime *rt);
static JSAtom __JS_NewAtomInit(JSRuntime *rt, const char *str, int len,
Expand Down Expand Up @@ -5015,7 +5013,7 @@ typedef struct JSCFunctionDataRecord {
uint8_t length;
uint8_t data_len;
uint16_t magic;
JSValue data[0];
JSValue data[];
} JSCFunctionDataRecord;

static void js_c_function_data_finalizer(JSRuntime *rt, JSValue val)
Expand Down Expand Up @@ -14584,13 +14582,13 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
#define DEFAULT default
#define BREAK break
#else
static const void * const dispatch_table[256] = {
__extension__ static const void * const dispatch_table[256] = {
#define DEF(id, size, n_pop, n_push, f) && case_OP_ ## id,
#define def(id, size, n_pop, n_push, f)
#include "quickjs-opcode.h"
[ OP_COUNT ... 255 ] = &&case_default
};
#define SWITCH(pc) DUMP_BYTECODE_OR_DONT(pc) goto *dispatch_table[opcode = *pc++];
#define SWITCH(pc) DUMP_BYTECODE_OR_DONT(pc) __extension__ ({ goto *dispatch_table[opcode = *pc++]; });
#define CASE(op) case_ ## op
#define DEFAULT case_default
#define BREAK SWITCH(pc)
Expand Down Expand Up @@ -27371,7 +27369,7 @@ static int js_inner_module_evaluation(JSContext *ctx, JSModuleDef *m,
JSReqModuleEntry *rme = &m->req_module_entries[i];
m1 = rme->module;
index = js_inner_module_evaluation(ctx, m1, index, pstack_top, pvalue);
if (index < 0)
if (index < 0)
return -1;
assert(m1->status == JS_MODULE_STATUS_EVALUATING ||
m1->status == JS_MODULE_STATUS_EVALUATING_ASYNC ||
Expand Down