mirror of
https://github.com/Z3Prover/z3
synced 2026-05-06 02:15:16 +00:00
Fix unsafe.Pointer usage in Go propagator - use uintptr_t for cgo.Handle
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
This commit is contained in:
parent
0de7af9112
commit
d5030dfe30
3 changed files with 50 additions and 47 deletions
|
|
@ -1,56 +1,60 @@
|
|||
#include "z3.h"
|
||||
#include "_cgo_export.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/* Bridge functions that adapt C callback signatures to exported Go functions */
|
||||
/* Bridge functions that adapt C callback signatures to exported Go functions.
|
||||
* The user context (void*) is stored/received as uintptr_t to avoid unsafe pointer
|
||||
* conversion warnings in Go. */
|
||||
|
||||
static void propagator_push_bridge(void* ctx, Z3_solver_callback cb) {
|
||||
goPushCb(ctx, cb);
|
||||
goPushCb((uintptr_t)ctx, cb);
|
||||
}
|
||||
|
||||
static void propagator_pop_bridge(void* ctx, Z3_solver_callback cb, unsigned num_scopes) {
|
||||
goPopCb(ctx, cb, num_scopes);
|
||||
goPopCb((uintptr_t)ctx, cb, num_scopes);
|
||||
}
|
||||
|
||||
static void* propagator_fresh_bridge(void* ctx, Z3_context new_context) {
|
||||
return goFreshCb(ctx, new_context);
|
||||
return (void*)goFreshCb((uintptr_t)ctx, new_context);
|
||||
}
|
||||
|
||||
static void propagator_fixed_bridge(void* ctx, Z3_solver_callback cb, Z3_ast t, Z3_ast value) {
|
||||
goFixedCb(ctx, cb, t, value);
|
||||
goFixedCb((uintptr_t)ctx, cb, t, value);
|
||||
}
|
||||
|
||||
static void propagator_eq_bridge(void* ctx, Z3_solver_callback cb, Z3_ast s, Z3_ast t) {
|
||||
goEqCb(ctx, cb, s, t);
|
||||
goEqCb((uintptr_t)ctx, cb, s, t);
|
||||
}
|
||||
|
||||
static void propagator_diseq_bridge(void* ctx, Z3_solver_callback cb, Z3_ast s, Z3_ast t) {
|
||||
goDiseqCb(ctx, cb, s, t);
|
||||
goDiseqCb((uintptr_t)ctx, cb, s, t);
|
||||
}
|
||||
|
||||
static void propagator_final_bridge(void* ctx, Z3_solver_callback cb) {
|
||||
goFinalCb(ctx, cb);
|
||||
goFinalCb((uintptr_t)ctx, cb);
|
||||
}
|
||||
|
||||
static void propagator_created_bridge(void* ctx, Z3_solver_callback cb, Z3_ast t) {
|
||||
goCreatedCb(ctx, cb, t);
|
||||
goCreatedCb((uintptr_t)ctx, cb, t);
|
||||
}
|
||||
|
||||
static void propagator_decide_bridge(void* ctx, Z3_solver_callback cb, Z3_ast t, unsigned idx, bool phase) {
|
||||
goDecideCb(ctx, cb, t, idx, phase);
|
||||
goDecideCb((uintptr_t)ctx, cb, t, idx, phase);
|
||||
}
|
||||
|
||||
static bool propagator_on_binding_bridge(void* ctx, Z3_solver_callback cb, Z3_ast q, Z3_ast inst) {
|
||||
return goOnBindingCb(ctx, cb, q, inst);
|
||||
return goOnBindingCb((uintptr_t)ctx, cb, q, inst);
|
||||
}
|
||||
|
||||
static void on_clause_bridge(void* ctx, Z3_ast proof_hint, unsigned n, unsigned const* deps, Z3_ast_vector literals) {
|
||||
goOnClauseCb(ctx, proof_hint, n, (unsigned*)deps, literals);
|
||||
goOnClauseCb((uintptr_t)ctx, proof_hint, n, (unsigned*)deps, literals);
|
||||
}
|
||||
|
||||
/* C helper functions that Go calls to register callbacks */
|
||||
/* C helper functions that Go calls to register callbacks.
|
||||
* These take uintptr_t for the user context and cast it to void* internally. */
|
||||
|
||||
void z3go_solver_propagate_init(Z3_context ctx, Z3_solver s, void* user_ctx) {
|
||||
Z3_solver_propagate_init(ctx, s, user_ctx,
|
||||
void z3go_solver_propagate_init(Z3_context ctx, Z3_solver s, uintptr_t user_ctx) {
|
||||
Z3_solver_propagate_init(ctx, s, (void*)user_ctx,
|
||||
propagator_push_bridge,
|
||||
propagator_pop_bridge,
|
||||
propagator_fresh_bridge);
|
||||
|
|
@ -84,6 +88,6 @@ void z3go_solver_propagate_on_binding(Z3_context ctx, Z3_solver s) {
|
|||
Z3_solver_propagate_on_binding(ctx, s, propagator_on_binding_bridge);
|
||||
}
|
||||
|
||||
void z3go_solver_register_on_clause(Z3_context ctx, Z3_solver s, void* user_ctx) {
|
||||
Z3_solver_register_on_clause(ctx, s, user_ctx, on_clause_bridge);
|
||||
void z3go_solver_register_on_clause(Z3_context ctx, Z3_solver s, uintptr_t user_ctx) {
|
||||
Z3_solver_register_on_clause(ctx, s, (void*)user_ctx, on_clause_bridge);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue