Skip to content

Commit dc5e7bd

Browse files
authored
Make JSIteratorConcatData smaller (#1251)
The use of bitfields in JSIteratorConcatData used to cause tcc to miscompile quickjs but that seems to have been fixed upstream.
1 parent 5b7087e commit dc5e7bd

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

quickjs.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41746,11 +41746,11 @@ static JSValue js_iterator_constructor(JSContext *ctx, JSValueConst new_target,
4174641746
return js_create_from_ctor(ctx, new_target, JS_CLASS_ITERATOR);
4174741747
}
4174841748

41749-
// note: deliberately doesn't use space-saving bit fields for
41750-
// |index|, |count| and |running| because tcc miscompiles them
4175141749
typedef struct JSIteratorConcatData {
41752-
int index, count; // elements (not pairs!) in values[] array
41753-
bool running;
41750+
uint32_t index : 31; // elements (not pairs!) in values[] array
41751+
uint32_t unused : 1;
41752+
uint32_t count : 31;
41753+
uint32_t running : 1;
4175441754
JSValue iter, next, values[]; // array of (object, method) pairs
4175541755
} JSIteratorConcatData;
4175641756

@@ -41761,7 +41761,7 @@ static void js_iterator_concat_finalizer(JSRuntime *rt, JSValueConst val)
4176141761
if (it) {
4176241762
JS_FreeValueRT(rt, it->iter);
4176341763
JS_FreeValueRT(rt, it->next);
41764-
for (int i = it->index; i < it->count; i++)
41764+
for (uint32_t i = it->index; i < it->count; i++)
4176541765
JS_FreeValueRT(rt, it->values[i]);
4176641766
js_free_rt(rt, it);
4176741767
}
@@ -41775,7 +41775,7 @@ static void js_iterator_concat_mark(JSRuntime *rt, JSValueConst val,
4177541775
if (it) {
4177641776
JS_MarkValue(rt, it->iter, mark_func);
4177741777
JS_MarkValue(rt, it->next, mark_func);
41778-
for (int i = it->index; i < it->count; i++)
41778+
for (uint32_t i = it->index; i < it->count; i++)
4177941779
JS_MarkValue(rt, it->values[i], mark_func);
4178041780
}
4178141781
}
@@ -41950,7 +41950,7 @@ static JSValue js_iterator_concat(JSContext *ctx, JSValueConst this_val,
4195041950
JS_SetOpaqueInternal(obj, it);
4195141951
return obj;
4195241952
fail:
41953-
for (int i = 0; i < it->count; i++)
41953+
for (uint32_t i = 0; i < it->count; i++)
4195441954
JS_FreeValue(ctx, it->values[i]);
4195541955
js_free(ctx, it);
4195641956
return JS_EXCEPTION;

0 commit comments

Comments
 (0)