Not planned
Description
Background:
- Only talking about 32bits targets, or more specific as x86 Windows. (JS_NAN_BOXING=1)
- Using
JS_NewCFunctionData
to expose a native function for javascript calling - In the callback of my native function, argv (uint64_t *) is always aligned to 8 in previous versions
I noticed that argv is no longer align to 8 but 4 after this commit.
I cannot find something special in this commit but if I modifies the new JS_FreeValue
from
void JS_FreeValueRT(JSRuntime *rt, JSValue v)
{
if (JS_VALUE_HAS_REF_COUNT(v)) {
JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
if (--p->ref_count <= 0) {
js_free_value_rt(rt, v);
}
}
}
void JS_FreeValue(JSContext *ctx, JSValue v)
{
JS_FreeValueRT(ctx->rt, v);
}
to
void JS_FreeValueRT(JSRuntime *rt, JSValue v)
{
if (JS_VALUE_HAS_REF_COUNT(v)) {
JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
if (--p->ref_count <= 0) {
js_free_value_rt(rt, v);
}
}
}
void JS_FreeValue(JSContext *ctx, JSValue v)
{
if (JS_VALUE_HAS_REF_COUNT(v)) {
JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
if (--p->ref_count <= 0) {
js_free_value_rt(ctx->rt, v);
}
}
}
argv is aligned to 8 back again.
And those are my questions:
- Should argv be aligned to 8? (when JSValue is uint64_t)
- If yes, is it a bug or something magic that causing this behaviour?
Activity
Icemic commentedon Jan 8, 2025
Not any custom function can reproduce this problem, I'm trying to make a minimal reproduction demo.
Icemic commentedon Jan 8, 2025
In this case, I get both align and non-align output randomly.
Icemic commentedon Jan 8, 2025
BTW, the magic "replacing JS_FreeValue body" not work on this case. It just works for my Rust version case...
saghul commentedon Jan 8, 2025
I'm not sure it was guaranteed to be aligned in the first place...
That said, I'm out of my depth so maybe @bnoordhuis has am idea here.
bnoordhuis commentedon Jan 8, 2025
See rust-lang/rust#112480 - tl;dr msvc quirk or, depending how you look at it, bug.
Are you running into a situation where C and Rust disagree on alignment or ...?
Icemic commentedon Jan 9, 2025
Yeah, I used to acquiring arguments by Rust's std::slice::from_raw_parts which needs the pointer to be aligned. It panics now so I find this issue.
This problem is easy to get around, but I think it's some kind unusual and may cause a little inefficiency, so I came to ask.
As it can be a bug (of MSVC though), will you fix it or just leave it for some time?
bnoordhuis commentedon Jan 9, 2025
I'll go ahead and close this because I don't think we can work around it if we wanted to, not robustly or reliably. That it used to align was just a happy accident. You'll have to take this up with either the MSVC or the Rust people.
Icemic commentedon Jan 9, 2025
Yeah, I'm afraid so.
Thanks for your help!
For someone encounters the same problem as me, there are two choices to get around it:
I've chosen 2.