-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
using int64 to pass cgo.Handle instead int #371
Conversation
You can cast pointer to double using math.Float64frombits to avoid performance loss |
I don't think using math.Float64frombits is good idea, cause float64 struct like this: and cgo.Handle is uint64(64-bit), and all bits are used to store unsigned integer value . |
It's not type cast, actually is reinterpret uint64 as float64, no actual bit changes |
Line 169 in 787d3db
here using ctx.Eval to call js function , and cause I did not check quickjs c code ,I'm not sure whether quickjs does conversion |
Number in quickjs is either int32 or double, so your argument probably won't be converted, just need convert that double back to uintptr in goProxy |
yeah, and I found quicks support BigUint64 , https://github.com/bellard/quickjs/blob/6e2e68fd0896957f92eb6c242a2e048c1ef3cae0/quickjs.h#L549. I should using it instead string |
It's not easy to convert back |
af651a1
to
f35b42d
Compare
I think the original implementation using ctx.Int64 to pass cgo.NewHandle is correct and safe. QuickJS's JS_NewInt64 function ensures that the full 64-bit integer value is preserved without any loss of precision or conversion to floating-point. This approach maintains the integrity of the handle value throughout the JavaScript-Go interaction. |
#370